-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_species_param.py
More file actions
37 lines (30 loc) · 1.3 KB
/
set_species_param.py
File metadata and controls
37 lines (30 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import f90nml
import numpy
import os
def calc_species_param(species_list,species_filename,norm_filename):
norm_file = f90nml.read(norm_filename)
eBar = norm_file["normalizationParameters"]["eBar"]
mBar = norm_file["normalizationParameters"]["mBar"]
species_file = f90nml.read(species_filename)
Z=numpy.array([species_file["speciesCharge"][x] for x in species_list])/eBar
mHat=numpy.array([species_file["speciesMass"][x] for x in species_list])/mBar
return [Z,mHat]
def list_to_str(l,delim=' '):
#Not used, as this is now built into the PERFECT input class
ret=''
for entry in l:
ret=ret+str(entry)+delim
#remove last delimiter
return ret.rsplit(delim,1)[0]
def set_species_param(species_list,species_filename,norm_filename,simulation):
[Z,mHat]=calc_species_param(species_list,species_filename,norm_filename)
simulation.inputs.charges=Z
simulation.inputs.masses=mHat
def species_Z(species_list,species_filename="species_database.namelist"):
species_filename= os.path.join(os.path.dirname(__file__), species_filename)
species_file = f90nml.read(species_filename)
Z=numpy.array([species_file["speciesZ"][x] for x in species_list])
return Z
if __name__=="__main__":
print list_to_str(['a','b',1])
print list_to_str([2,'c','dddd'],'-')