5 from numpy
import loadtxt
6 from modena
import SurrogateModel
8 "print usage of the module" 9 print(
'Usage: prep_init_foamConductivity v')
11 print(
"0 - try to initialize with points so that foamConductivity "+
12 "does not go out of range")
13 print(
'1 - initialize with points from foamAging.json')
14 print(
'2 - initialize with points from foamAging.json except for gas ' 15 +
'composition - foamConductivity should not go out of range in ' 16 +
'foamAging simulation')
25 "eps": [0.9,0.0,0.96,0.99,0.7,0.5],
26 "dcell": [200e-6,0.0,300e-6,100e-6,1e-2,200e-6],
27 "fstrut": [0.0,1.0,0.7,0.6,0.0,0.9],
28 "T": [280,549,300,350,330,300],
29 "x[CO2]": [1,0,0,0,1,0],
30 "x[CyP]": [0,1,0,0,0,1],
31 "x[O2]": [0,0,1,0,0,0],
32 "x[N2]": [0,0,0,1,0,0]
34 with open(
"./inputs/init_foamConductivity.json",
"w")
as fl:
35 json.dump(ini,fl,indent=4,sort_keys=
True)
38 "creates a list with small perturbation around the input value" 50 def setIP_fractions(a0):
51 "creates a list with small perturbation around the input value" 67 def get_rho(inputs, results):
68 if inputs[
'sourceOfProperty'][
'foamDensity']==
'DirectInput':
69 rho0=inputs[
'morphology'][
'foamDensity']
70 elif inputs[
'sourceOfProperty'][
'foamDensity']==
'BubbleGrowth':
71 with open(results+
"/bubbleGrowth/after_foaming.txt")
as fl2:
72 rho0,dcell,xCyP,xCO2=loadtxt(fl2,skiprows=1,unpack=
True)
73 elif inputs[
'sourceOfProperty'][
'foamDensity']==
'Qmom0D':
74 with open(results+
"/CFD0D/after_foaming.txt")
as fl2:
75 rho0,dcell,var,xCyP,xCO2=loadtxt(fl2,skiprows=1,unpack=
True)
76 elif inputs[
'sourceOfProperty'][
'foamDensity']==
'Qmom3D':
77 with open(results+
"/CFD3D/after_foaming.txt")
as fl2:
78 rho0,dcell,xCyP,xCO2=loadtxt(fl2,skiprows=1,unpack=
True)
80 raise Exception(
"unknown source for foam density")
82 def get_dcell(inputs, results):
83 if inputs[
'sourceOfProperty'][
'cellSize']==
'DirectInput':
84 dcell0=inputs[
'morphology'][
'cellSize']
85 elif inputs[
'sourceOfProperty'][
'cellSize']==
'BubbleGrowth':
86 with open(results+
"/bubbleGrowth/after_foaming.txt")
as fl2:
87 rho,dcell0,xCyP,xCO2=loadtxt(fl2,skiprows=1,unpack=
True)
88 elif inputs[
'sourceOfProperty'][
'cellSize']==
'Qmom0D':
89 with open(results+
"/CFD0D/after_foaming.txt")
as fl2:
90 rho,dcell0,var,xCyP,xCO2=loadtxt(fl2,skiprows=1,unpack=
True)
91 elif inputs[
'sourceOfProperty'][
'cellSize']==
'Qmom3D':
92 with open(results+
"/CFD3D/after_foaming.txt")
as fl2:
93 rho,dcell0,xCyP,xCO2=loadtxt(fl2,skiprows=1,unpack=
True)
95 raise Exception(
"unknown source for cell size")
97 def get_gas_comp(inputs, results):
98 if inputs[
'sourceOfProperty'][
'gasComposition']==
'DirectInput':
99 xO20=inputs[
'foamCondition'][
'initialComposition'][
'O2']
100 xN20=inputs[
'foamCondition'][
'initialComposition'][
'N2']
101 xCO20=inputs[
'foamCondition'][
'initialComposition'][
'CO2']
102 xCyP0=inputs[
'foamCondition'][
'initialComposition'][
'Cyclopentane']
103 elif inputs[
'sourceOfProperty'][
'gasComposition']==
'BubbleGrowth':
104 with open(results+
"/bubbleGrowth/after_foaming.txt")
as fl2:
105 rho,dcell,xCyP0,xCO20=loadtxt(fl2,skiprows=1,unpack=
True)
107 elif inputs[
'sourceOfProperty'][
'gasComposition']==
'Qmom0D':
108 with open(results+
"/CFD0D/after_foaming.txt")
as fl2:
109 rho,dcell,var,xCyP0,xCO20=loadtxt(fl2,skiprows=1,unpack=
True)
111 elif inputs[
'sourceOfProperty'][
'gasComposition']==
'Qmom3D':
112 with open(results+
"/CFD3D/after_foaming.txt")
as fl2:
113 rho,dcell,xCyP0,xCO20=loadtxt(fl2,skiprows=1,unpack=
True)
116 raise Exception(
"unknown source for gas composition")
117 return xO20,xN20,xCO20,xCyP0
118 def get_fstrut(inputs, results):
119 if inputs[
'sourceOfProperty'][
'strutContent']==
'DirectInput':
120 fstrut0=inputs[
'morphology'][
'strutContent']
121 elif inputs[
'sourceOfProperty'][
'strutContent']==
'StrutContent':
122 inputs = {
'rho': rho0}
123 model=SurrogateModel.load(
'strutContent')
124 outputs=model.callModel(inputs)
125 fstrut0=outputs[
'fs']
127 raise Exception(
"unknown source for strut content")
130 "create initial points from foamAging.json" 131 if os.getcwd().split(os.path.sep)[-1] !=
'foamAging':
132 raise Exception(
"you can initialize for foamAging only from foamAging " 134 results=
'../foamExpansion/results/' 135 with open(
"./inputs/foamAging.json")
as fl:
137 T0=inputs[
'foamCondition'][
'conductivityTemperature']
138 rhop=inputs[
'physicalProperties'][
'polymerDensity']
139 rho0=get_rho(inputs, results)
140 dcell0=get_dcell(inputs, results)
141 xO20,xN20,xCO20,xCyP0=get_gas_comp(inputs, results)
142 fstrut0=get_fstrut(inputs, results)
143 s=xO20+xN20+xCO20+xCyP0
152 'dcell': setIP(dcell0),
153 'fstrut': setIP(fstrut0),
155 'x[CO2]': setIP_fractions(xCO20),
156 'x[CyP]': setIP_fractions(xCyP0),
157 'x[O2]': setIP_fractions(xO20),
158 'x[N2]': setIP_fractions(xN20),
163 'dcell': setIP(dcell0),
164 'fstrut': setIP(fstrut0),
171 with open(
"./inputs/init_foamConductivity.json",
"w")
as fl:
172 json.dump(ini,fl,indent=4,sort_keys=
True)
174 if __name__==
'__main__':
179 elif sys.argv[1]==
'1':
181 elif sys.argv[1]==
'2':
MoDeNa Module definition of the Foam aging model.