From 4aa95133b11a42313cac555103a872ab64635e5a Mon Sep 17 00:00:00 2001 From: dvezinet Date: Thu, 27 Aug 2026 20:13:25 +0000 Subject: [PATCH 1/8] [#1170] Added cfsem as an option, but not tested --- .../electrons/emission/_xray_thin_target.py | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/tofu/physics_tools/electrons/emission/_xray_thin_target.py b/tofu/physics_tools/electrons/emission/_xray_thin_target.py index f9f4e4dc2..69547d3c3 100644 --- a/tofu/physics_tools/electrons/emission/_xray_thin_target.py +++ b/tofu/physics_tools/electrons/emission/_xray_thin_target.py @@ -1506,6 +1506,16 @@ def _hyp2F1( aa[ind], bb[ind], cc[ind], zz[ind], ) + # ---------------- + # source = cfsem + # ---------------- + + elif source == 'cfsem': + + out = dfunc['mpmath'].hyp2f1( + aa, bb, cc, zz, + ) + # ---------------- # source = 1/z or z/(z-1) # ---------------- @@ -1681,18 +1691,24 @@ def _hyp2f1_check(specfunc_dir=None): dfunc['specfunc'] = specfunc # -------- - # mpmath + # mpmath and cfsem # -------- - try: - import mpmath - dfunc['mpmath'] = mpmath - except Exception: - msg = ( - "\n_hyp2F1: mpmath not available\n" - "See https://pypi.org/project/mpmath/\n" - ) - dwarn['mpmath'] = msg + ls = ['mpmath', 'cfsem'] + + for ss in ls: + try: + if ss == 'mpmath': + import mpmath as sour + else: + import cfsem as sour + dfunc[ss] = sour + except Exception: + msg = ( + f"\n_hyp2F1: {ss} not available\n" + "See https://pypi.org/project/{ss}/\n" + ) + dwarn[ss] = msg # -------- # lok @@ -1701,6 +1717,8 @@ def _hyp2f1_check(specfunc_dir=None): lok = ['z/(z-1)', '1/z'] if dwarn.get('specfunc') is None: lok.insert(0, 'specfunc') + if dwarn.get('cfsem') is None: + lok.insert(0, 'cfsem') if dwarn.get('mpmath') is None: lok.insert(0, 'mpmath') From 12c2c96eab1112dc71c24e5e7db6aadafb01cd76 Mon Sep 17 00:00:00 2001 From: dvezinet Date: Fri, 28 Aug 2026 15:35:00 +0000 Subject: [PATCH 2/8] [#1170] cfsem.hyp2f1() validated for cross-section --- .../electrons/emission/_xray_thin_target.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tofu/physics_tools/electrons/emission/_xray_thin_target.py b/tofu/physics_tools/electrons/emission/_xray_thin_target.py index 69547d3c3..419b929d6 100644 --- a/tofu/physics_tools/electrons/emission/_xray_thin_target.py +++ b/tofu/physics_tools/electrons/emission/_xray_thin_target.py @@ -1512,8 +1512,11 @@ def _hyp2F1( elif source == 'cfsem': - out = dfunc['mpmath'].hyp2f1( - aa, bb, cc, zz, + out = dfunc['cfsem'].hyp2f1( + aa.astype('complex128'), + bb.astype('complex128'), + cc.astype('complex128'), + zz.astype('complex128'), ) # ---------------- @@ -1717,10 +1720,10 @@ def _hyp2f1_check(specfunc_dir=None): lok = ['z/(z-1)', '1/z'] if dwarn.get('specfunc') is None: lok.insert(0, 'specfunc') - if dwarn.get('cfsem') is None: - lok.insert(0, 'cfsem') if dwarn.get('mpmath') is None: lok.insert(0, 'mpmath') + if dwarn.get('cfsem') is None: + lok.insert(0, 'cfsem') return lok, dwarn, dfunc From 74d1a6040722dcc6e9733fd3a69f4e29413f1435 Mon Sep 17 00:00:00 2001 From: dvezinet Date: Fri, 28 Aug 2026 15:52:38 +0000 Subject: [PATCH 3/8] [#1170] updated pbs job for d2cross --- tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs | 8 ++++---- tofu/physics_tools/electrons/emission/_pbs_d2cross.py | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs b/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs index 087b994ab..24983f96f 100644 --- a/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs +++ b/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs @@ -4,9 +4,9 @@ #PBS -l instance_type=c7i.8xlarge #PBS -l walltime=1500:00:00 #PBS -P sparc-design -#PBS -N d2cross_61x160x161_EH -#PBS -o d2cross_61x160x161_EH.out -#PBS -e d2cross_61x160x161_EH.err +#PBS -N d2cross_61x80x81_EH +#PBS -o d2cross_61x80x81_EH.out +#PBS -e d2cross_61x80x81_EH.err #PBS -m abe #PBS -l base_os=ubuntu2404 #PBS -l instance_ami=ami-0d63a2e021bce724d @@ -17,4 +17,4 @@ source ~/.bashrc # Beware: PBS does not expand the tilde ~/ => full explicit path needed export PBS_O_WORKDIR="/data/home/dvezinet/projects/tofu/tofu/physics_tools/electrons/emission" cd ${PBS_O_WORKDIR}/ -python _pbs_d2cross.py -nEph 161 -nEe0 160 -ntheta 61 -v EH +python _pbs_d2cross.py -nEph 81 -nEe0 80 -ntheta 61 -v EH diff --git a/tofu/physics_tools/electrons/emission/_pbs_d2cross.py b/tofu/physics_tools/electrons/emission/_pbs_d2cross.py index aa7838af3..584f01e72 100644 --- a/tofu/physics_tools/electrons/emission/_pbs_d2cross.py +++ b/tofu/physics_tools/electrons/emission/_pbs_d2cross.py @@ -75,6 +75,7 @@ def main( save=True, verb=2, version=version, + source='cfsem', ) # ------------------ From 28faf0167bc2ed73f51ad11a081ebdefc86f4f5d Mon Sep 17 00:00:00 2001 From: dvezinet Date: Fri, 28 Aug 2026 16:27:54 +0000 Subject: [PATCH 4/8] [#1170] updated pbs 2cross for 91x240x241 --- tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs b/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs index 24983f96f..2226769ab 100644 --- a/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs +++ b/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs @@ -4,9 +4,9 @@ #PBS -l instance_type=c7i.8xlarge #PBS -l walltime=1500:00:00 #PBS -P sparc-design -#PBS -N d2cross_61x80x81_EH -#PBS -o d2cross_61x80x81_EH.out -#PBS -e d2cross_61x80x81_EH.err +#PBS -N d2cross_91x240x241_EH +#PBS -o d2cross_91x240x241_EH.out +#PBS -e d2cross_91x240x241_EH.err #PBS -m abe #PBS -l base_os=ubuntu2404 #PBS -l instance_ami=ami-0d63a2e021bce724d @@ -17,4 +17,4 @@ source ~/.bashrc # Beware: PBS does not expand the tilde ~/ => full explicit path needed export PBS_O_WORKDIR="/data/home/dvezinet/projects/tofu/tofu/physics_tools/electrons/emission" cd ${PBS_O_WORKDIR}/ -python _pbs_d2cross.py -nEph 81 -nEe0 80 -ntheta 61 -v EH +python _pbs_d2cross.py -nEph 241 -nEe0 240 -ntheta 91 -v EH From 2573f390158adfa2fa401ffbac7fef79e2fb258e Mon Sep 17 00:00:00 2001 From: dvezinet Date: Fri, 28 Aug 2026 18:38:15 +0000 Subject: [PATCH 5/8] [#1170] pbs d2cross 181x400x401 --- tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs b/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs index 2226769ab..119b6f74b 100644 --- a/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs +++ b/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs @@ -4,9 +4,9 @@ #PBS -l instance_type=c7i.8xlarge #PBS -l walltime=1500:00:00 #PBS -P sparc-design -#PBS -N d2cross_91x240x241_EH -#PBS -o d2cross_91x240x241_EH.out -#PBS -e d2cross_91x240x241_EH.err +#PBS -N d2cross_181x400x401_EH +#PBS -o d2cross_181x400x401_EH.out +#PBS -e d2cross_181x400x401_EH.err #PBS -m abe #PBS -l base_os=ubuntu2404 #PBS -l instance_ami=ami-0d63a2e021bce724d @@ -17,4 +17,4 @@ source ~/.bashrc # Beware: PBS does not expand the tilde ~/ => full explicit path needed export PBS_O_WORKDIR="/data/home/dvezinet/projects/tofu/tofu/physics_tools/electrons/emission" cd ${PBS_O_WORKDIR}/ -python _pbs_d2cross.py -nEph 241 -nEe0 240 -ntheta 91 -v EH +python _pbs_d2cross.py -nEph 401 -nEe0 400 -ntheta 181 -v EH From 1b6ad25d636b1db0377bd2a976a2d275ecb6f82d Mon Sep 17 00:00:00 2001 From: dvezinet Date: Fri, 28 Aug 2026 18:56:33 +0000 Subject: [PATCH 6/8] [#1170] Corrected nthetae and ndphi --- tofu/physics_tools/electrons/emission/_pbs_d2cross.py | 2 ++ .../electrons/emission/_xray_thin_target_integrated.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tofu/physics_tools/electrons/emission/_pbs_d2cross.py b/tofu/physics_tools/electrons/emission/_pbs_d2cross.py index 584f01e72..da7d96a69 100644 --- a/tofu/physics_tools/electrons/emission/_pbs_d2cross.py +++ b/tofu/physics_tools/electrons/emission/_pbs_d2cross.py @@ -72,6 +72,8 @@ def main( E_e0_eV=E_e0_eV[None, :, None], E_ph_eV=E_ph_eV[None, None, :], theta_ph=theta_ph[:, None, None], + nthetae=theta_ph.size, + ndphi=2*theta_ph.size+1, save=True, verb=2, version=version, diff --git a/tofu/physics_tools/electrons/emission/_xray_thin_target_integrated.py b/tofu/physics_tools/electrons/emission/_xray_thin_target_integrated.py index 047ed221e..24ef6ce10 100644 --- a/tofu/physics_tools/electrons/emission/_xray_thin_target_integrated.py +++ b/tofu/physics_tools/electrons/emission/_xray_thin_target_integrated.py @@ -35,11 +35,11 @@ # Integration -_NTHETAE = 31 -_NDPHI = 51 +_NTHETAE = 91 +_NDPHI = 181 # VERSION -_VERSION = 'BHE' # good compromise +_VERSION = 'EH' # best with cfsem.hyp2f1() # Default naming From b435a7975e41c3070993374851bb4a270e6c955b Mon Sep 17 00:00:00 2001 From: dvezinet Date: Fri, 28 Aug 2026 19:03:24 +0000 Subject: [PATCH 7/8] [#1170] Better default nthetae and ndphi --- .../electrons/emission/_pbs_d2cross.pbs | 8 ++++---- .../emission/_xray_thin_target_integrated.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs b/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs index 119b6f74b..2226769ab 100644 --- a/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs +++ b/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs @@ -4,9 +4,9 @@ #PBS -l instance_type=c7i.8xlarge #PBS -l walltime=1500:00:00 #PBS -P sparc-design -#PBS -N d2cross_181x400x401_EH -#PBS -o d2cross_181x400x401_EH.out -#PBS -e d2cross_181x400x401_EH.err +#PBS -N d2cross_91x240x241_EH +#PBS -o d2cross_91x240x241_EH.out +#PBS -e d2cross_91x240x241_EH.err #PBS -m abe #PBS -l base_os=ubuntu2404 #PBS -l instance_ami=ami-0d63a2e021bce724d @@ -17,4 +17,4 @@ source ~/.bashrc # Beware: PBS does not expand the tilde ~/ => full explicit path needed export PBS_O_WORKDIR="/data/home/dvezinet/projects/tofu/tofu/physics_tools/electrons/emission" cd ${PBS_O_WORKDIR}/ -python _pbs_d2cross.py -nEph 401 -nEe0 400 -ntheta 181 -v EH +python _pbs_d2cross.py -nEph 241 -nEe0 240 -ntheta 91 -v EH diff --git a/tofu/physics_tools/electrons/emission/_xray_thin_target_integrated.py b/tofu/physics_tools/electrons/emission/_xray_thin_target_integrated.py index 24ef6ce10..65fd77d26 100644 --- a/tofu/physics_tools/electrons/emission/_xray_thin_target_integrated.py +++ b/tofu/physics_tools/electrons/emission/_xray_thin_target_integrated.py @@ -229,12 +229,20 @@ def _check( # integers # ----------- + # nthetae_def and ndphi_def + if theta_ph.size == np.prod(theta_ph.shape): + nthetae_def = theta_ph.size + ndphi_def = 2*(theta_ph.size - 1) + 1 + else: + nthetae_def = _NTHETAE + ndphi_def = _NDPHI + # nthetae nthetae = ds._generic_check._check_var( nthetae, 'nthetae', types=int, sign='>0', - default=_NTHETAE, + default=nthetae_def, ) # ndphi @@ -242,7 +250,7 @@ def _check( ndphi, 'ndphi', types=int, sign='>0', - default=_NDPHI, + default=ndphi_def, ) # ------------ From fb913a7ce2aadfaf68f7a4e4d4df56978b673ea9 Mon Sep 17 00:00:00 2001 From: dvezinet Date: Mon, 31 Aug 2026 12:46:16 +0000 Subject: [PATCH 8/8] [#1170] _pbs_d2cross.py now takes nthetae and ndphi --- .../electrons/emission/_pbs_d2cross.pbs | 8 +++--- .../electrons/emission/_pbs_d2cross.py | 28 +++++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs b/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs index 2226769ab..00ec3e47a 100644 --- a/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs +++ b/tofu/physics_tools/electrons/emission/_pbs_d2cross.pbs @@ -4,9 +4,9 @@ #PBS -l instance_type=c7i.8xlarge #PBS -l walltime=1500:00:00 #PBS -P sparc-design -#PBS -N d2cross_91x240x241_EH -#PBS -o d2cross_91x240x241_EH.out -#PBS -e d2cross_91x240x241_EH.err +#PBS -N d2cross_91x160x161_EH +#PBS -o d2cross_91x160x161_EH.out +#PBS -e d2cross_91x160x161_EH.err #PBS -m abe #PBS -l base_os=ubuntu2404 #PBS -l instance_ami=ami-0d63a2e021bce724d @@ -17,4 +17,4 @@ source ~/.bashrc # Beware: PBS does not expand the tilde ~/ => full explicit path needed export PBS_O_WORKDIR="/data/home/dvezinet/projects/tofu/tofu/physics_tools/electrons/emission" cd ${PBS_O_WORKDIR}/ -python _pbs_d2cross.py -nEph 241 -nEe0 240 -ntheta 91 -v EH +python _pbs_d2cross.py -nEph 161 -nEe0 160 -ntheta 91 -nthetae 51 -ndphi 91 -v EH diff --git a/tofu/physics_tools/electrons/emission/_pbs_d2cross.py b/tofu/physics_tools/electrons/emission/_pbs_d2cross.py index da7d96a69..2e6673b1a 100644 --- a/tofu/physics_tools/electrons/emission/_pbs_d2cross.py +++ b/tofu/physics_tools/electrons/emission/_pbs_d2cross.py @@ -27,6 +27,8 @@ def main( nEph=None, nEe0=None, ntheta=None, + nthetae=None, + ndphi=None, version=None, ddef=None, ): @@ -72,8 +74,8 @@ def main( E_e0_eV=E_e0_eV[None, :, None], E_ph_eV=E_ph_eV[None, None, :], theta_ph=theta_ph[:, None, None], - nthetae=theta_ph.size, - ndphi=2*theta_ph.size+1, + nthetae=nthetae, + ndphi=ndphi, save=True, verb=2, version=version, @@ -110,6 +112,8 @@ def main( 'nEph': 401, 'nEe0': 400, 'ntheta': 181, + 'nthetae': None, + 'ndphi': None, 'version': 'EH', } @@ -150,6 +154,26 @@ def main( default=ddef['ntheta'], ) + # nthetae + parser.add_argument( + '-nthetae', + '--nthetae', + type=int, + help='Number of np.linspace(0, np.pi, nthetae) (rad)', + required=False, + default=ddef['nthetae'], + ) + + # ndphi + parser.add_argument( + '-ndphi', + '--ndphi', + type=int, + help='Number of np.linspace(-np.pi, np.pi, ndphi) (rad)', + required=False, + default=ddef['ndphi'], + ) + # version parser.add_argument( '-v',