aboutsummaryrefslogtreecommitdiff
path: root/Source/Utils/write_atomic_data_cpp.py
diff options
context:
space:
mode:
authorGravatar Axel Huebl <axel.huebl@plasma.ninja> 2019-09-11 18:04:38 -0700
committerGravatar Axel Huebl <axel.huebl@plasma.ninja> 2019-09-13 15:24:31 -0700
commit473fa9b859cb23381cc45d612e06da75f6ef9e35 (patch)
tree792f56164b5a6a4788080acce31b362ff04b78a6 /Source/Utils/write_atomic_data_cpp.py
parent6232f62665f4b5897ff6e779824e2ea4565054b8 (diff)
downloadWarpX-473fa9b859cb23381cc45d612e06da75f6ef9e35.tar.gz
WarpX-473fa9b859cb23381cc45d612e06da75f6ef9e35.tar.zst
WarpX-473fa9b859cb23381cc45d612e06da75f6ef9e35.zip
Ionization Energies Script: no EOL
Avoid writing EOL whitspaces in ionization energies script.
Diffstat (limited to 'Source/Utils/write_atomic_data_cpp.py')
-rw-r--r--Source/Utils/write_atomic_data_cpp.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/Source/Utils/write_atomic_data_cpp.py b/Source/Utils/write_atomic_data_cpp.py
index 1c85fa32c..35baf2cdf 100644
--- a/Source/Utils/write_atomic_data_cpp.py
+++ b/Source/Utils/write_atomic_data_cpp.py
@@ -21,11 +21,12 @@ ion_names = list(dict.fromkeys( [x[1] for x in list_of_tuples] ))
ion_offsets = np.concatenate(([0], np.cumsum(np.array(ion_atom_numbers)[:-1])), axis=0)
# Head of CPP file
-cpp_string = ''
-cpp_string += '#include <map>\n'
-cpp_string += '#include <AMReX_AmrCore.H>\n\n'
+cpp_string = '// This script was automatically generated!\n'
+cpp_string += '// Edit dev/Source/Utils/write_atomic_data_cpp.py instead!\n'
cpp_string += '#ifndef WARPX_IONIZATION_TABLE_H_\n'
cpp_string += '#define WARPX_IONIZATION_TABLE_H_\n\n'
+cpp_string += '#include <AMReX_AmrCore.H>\n'
+cpp_string += '#include <map>\n\n'
# Map each element to ID in table
cpp_string += 'std::map<std::string, int> ion_map_ids = {'
@@ -36,17 +37,17 @@ cpp_string += ' };\n\n'
# Atomic number of each species
cpp_string += 'const int nelements = ' + str(len(ion_names)) + ';\n\n'
-cpp_string += 'const int ion_atomic_numbers[nelements] = {'
+cpp_string += 'const int ion_atomic_numbers[nelements] = {\n '
for count, atom_num in enumerate(ion_atom_numbers):
- if count%10==0: cpp_string += '\n '
+ if count%10==0 and count>0: cpp_string = cpp_string[:-2] + ',\n '
cpp_string += str(atom_num) + ', '
cpp_string = cpp_string[:-2]
cpp_string += '};\n\n'
# Offset of each element in table of ionization energies
-cpp_string += 'const int ion_energy_offsets[nelements] = {'
+cpp_string += 'const int ion_energy_offsets[nelements] = {\n '
for count, offset in enumerate(ion_offsets):
- if count%10==0: cpp_string += '\n '
+ if count%10==0 and count>0: cpp_string = cpp_string[:-2] + ',\n '
cpp_string += str(offset) + ', '
cpp_string = cpp_string[:-2]
cpp_string += '};\n\n'
@@ -55,16 +56,17 @@ cpp_string += '};\n\n'
cpp_string += 'const int energies_tab_length = ' + str(len(list_of_tuples)) + ';\n\n'
cpp_string += 'const amrex::Real table_ionization_energies[energies_tab_length]{'
for element in ion_names:
- cpp_string += '\n // ' + element
+ cpp_string += '\n // ' + element + '\n '
regex_command = \
'\n\s+(\d+)\s+\|\s+%s\s+\w+\s+\|\s+\+*(\d+)\s+\|\s+\(*\[*(\d+\.*\d*)' \
%element
list_of_tuples = re.findall( regex_command, text_data )
for count, energy in enumerate([x[2] for x in list_of_tuples]):
- if count%7==0: cpp_string += '\n '
+ if count%7==0 and count>0: cpp_string = cpp_string[:-2] + ',\n '
cpp_string += energy + ', '
-cpp_string = cpp_string[:-2]
-cpp_string += ' };\n\n'
+ cpp_string = cpp_string[:-1]
+cpp_string = cpp_string[:-1]
+cpp_string += '\n};\n\n'
# Write the string to file
cpp_string += '#endif // #ifndef WARPX_IONIZATION_TABLE_H_\n'