62 from fireworks.utilities.fw_utilities
import explicit_serialize
63 from jinja2
import Template
65 import polymerConductivity
66 import gasConductivity
67 import gasMixtureConductivity
70 json.encoder.FLOAT_REPR =
lambda o: format(o,
'.12g')
95 def task(self, fw_spec):
96 eps = self[
'point'][
'eps']
97 dcell = self[
'point'][
'dcell']
98 fstrut = self[
'point'][
'fstrut']
99 temp = self[
'point'][
'T']
100 xCO2 = self[
'point'][
'x[CO2]']
101 xCyP = self[
'point'][
'x[CyP]']
102 xO2 = self[
'point'][
'x[O2]']
103 xN2 = self[
'point'][
'x[N2]']
105 inputs={
"upperBoundary": {
"temperature": temp+1,
"emittance": 0.9}}
106 inputs[
"lowerBoundary"]={
"temperature": temp-1,
"emittance": 0.9}
107 inputs[
"gasComposition"]={
113 inputs[
"gasDensity"]=1.2
114 inputs[
"solidDensity"]=1.1e3
115 inputs[
"sourceOfProperty"]={
116 "porosity":
"DirectInput",
117 "cellSize":
"DirectInput",
118 "gasComposition":
"DirectInput",
119 "strutContent":
"DirectInput",
120 "wallThickness":
"DirectInput" 122 inputs[
"porosity"]=eps
123 inputs[
"cellSize"]=dcell
124 inputs[
"morphologyInput"]=
"strutContent" 125 inputs[
"wallThickness"]=0.5e-6
126 inputs[
"strutContent"]=fstrut
127 inputs[
"strutSize"]=1e-6
128 inputs[
"foamThickness"]=3e-2
129 inputs[
"spatialDiscretization"]=200
130 inputs[
"useWallThicknessDistribution"]=
True 131 inputs[
"wallThicknessStandardDeviation"]=0.2
132 inputs[
"numberOfGrayBoxes"]=10
133 inputs[
"numericalEffectiveConductivity"]=
False 135 inputs[
"testMode"]=
False 136 with open(
'foamConductivity.json',
'w')
as f:
137 json.dump(inputs, f, indent=4)
139 os.rename(
'foamConductivity.json',
'inputs/foamConductivity.json')
143 ret = os.system(os.path.dirname(os.path.abspath(__file__))+
'/src/kfoam')
145 self.handleReturnCode(ret)
149 FILE = open(os.getcwd()+
'/foamConductivity.out',
'r') except IOError:
150 raise IOError(
"File not found")
152 self[
'point'][
'kfoam'] = float(FILE.readline())
161 f_foamConductivity = CFunction(
168 const modena_model_t* model, 169 const double* inputs, 173 {% block variables %}{% endblock %} 175 const double alpha = parameters[1]; 176 const double beta = parameters[0]; 178 const double sigma=5.67e-8; 180 double fs,Xs,Xw,X,kappa,kr; 182 double kgas=gasMixtureConductivity; 183 double kpol=polymer_thermal_conductivity; 186 Xs=(1+4*kgas/(kgas+kpol))/3.0; 187 Xw=2*(1+kgas/(2*kpol))/3.0; 189 kappa=4.09*sqrt(1-eps)/dcell; 190 kr=16*sigma*pow(T,3)/(3*kappa); 191 kfoam = (kgas*eps+kpol*X*(1-eps))/(eps+(1-eps)*X)+beta*kr; 198 'eps': {
'min': 0,
'max': 0.995},
199 'dcell': {
'min': 0,
'max': 1e-1},
200 'fstrut': {
'min': 0,
'max': 1},
201 'gasMixtureConductivity': {
'min': 0,
'max': 1e-1},
202 'polymer_thermal_conductivity': {
'min': 0,
'max': 1e0},
203 'T': {
'min': 273,
'max': 550},
204 'x': {
'index': gasConductivity.species,
'min': 0,
'max': 1},
207 'kfoam': {
'min': 0,
'max': 1e0,
'argPos': 0},
210 'param1': {
'min': -1e9,
'max': 1e9 + 2,
'argPos': 0},
211 'param2': {
'min': -1e9,
'max': 1e9 + 2,
'argPos': 1},
216 with open(
"./inputs/init_foamConductivity.json")
as fl:
217 foaming_ini=json.load(fl)
219 with open(
"../inputs/init_foamConductivity.json")
as fl:
220 foaming_ini=json.load(fl)
226 m_foamConductivity = BackwardMappingModel(
227 _id=
'foamConductivity',
228 surrogateFunction=f_foamConductivity,
231 gasMixtureConductivity.m_gasMixtureConductivity,\
232 polymerConductivity.m_polymer_thermal_conductivity\
234 initialisationStrategy=Strategy.InitialPoints(
235 initialPoints=foaming_ini,
237 outOfBoundsStrategy=Strategy.ExtendSpaceStochasticSampling(
240 parameterFittingStrategy=Strategy.NonLinFitWithErrorContol(
241 testDataPercentage=0.2,
243 improveErrorStrategy=Strategy.StochasticSampling(
254 m_simulation = Strategy.BackwardMappingScriptTask(
255 script=os.path.dirname(os.path.abspath(__file__))+
'/src/kfoam' +
256 ' && cp foamConductivity.out ../results/foamConductivity' +
257 ' && cp hahtf.out ../results/foamConductivity' 259 Recipe for Foam conductivity application.