69 from modena
import ForwardMappingModel,BackwardMappingModel,SurrogateModel,\
72 from fireworks.user_objects.firetasks.script_task
import FireTaskBase, ScriptTask
73 from fireworks
import Firework, Workflow, FWAction
74 from fireworks.utilities.fw_utilities
import explicit_serialize
75 from blessings
import Terminal
76 from jinja2
import Template
82 name=
'solubility_pol_species',
83 names= [
'Air',
'CO2',
'CyP',
'O2',
'N2' ]
86 name=
'solubility_num_of_components',
104 def task(self, fw_spec):
106 ff = open(
'in.txt',
'w')
107 Tstr = str(self[
'point'][
'T'])
108 ff.write(
'%s \n' %(Tstr))
109 if (self[
'indices'][
'B']==
'2'):
111 if (self[
'indices'][
'A']==
'CO2'):
113 elif (self[
'indices'][
'A']==
'Air'):
115 elif (self[
'indices'][
'A']==
'CyP'):
116 ff.write(
'cyclopentane \n')
117 elif (self[
'indices'][
'A']==
'O2'):
119 elif (self[
'indices'][
'A']==
'N2'):
122 x1l_str = str(self[
'point'][
'xl1'])
123 x2l_str = str(self[
'point'][
'xl2'])
124 ff.write(
'%s \n' %(x1l_str))
125 ff.write(
'%s \n' %(x2l_str))
126 elif (self[
'indices'][
'B']==
'3'):
128 if (self[
'indices'][
'A']==
'CO2'):
130 elif (self[
'indices'][
'A']==
'Air'):
132 elif (self[
'indices'][
'A']==
'CyP'):
133 ff.write(
'cyclopentane \n')
134 elif (self[
'indices'][
'A']==
'O2'):
136 elif (self[
'indices'][
'A']==
'N2'):
139 x1l_str = str(self[
'point'][
'xl1'])
140 x2l_str = str(self[
'point'][
'xl2'])
141 x3l_str = str(self[
'point'][
'xl3'])
142 ff.write(
'%s \n' %(x1l_str))
143 ff.write(
'%s \n' %(x2l_str))
144 ff.write(
'%s \n' %(x3l_str))
148 fff = open(
'out.txt',
'w+')
154 ret = os.system(os.path.dirname(os.path.abspath(__file__))+\
157 self.handleReturnCode(ret)
161 FILE = open(os.getcwd()+
'/out.txt',
'r') except IOError:
162 raise IOError(
"File not found")
163 self[
'point'][
'H'] = float(FILE.readline())
176 void surroSolubility2 178 const modena_model_t* model, 179 const double* inputs, 183 {% block variables %}{% endblock %} 185 const double P0 = parameters[0]; 186 const double P1 = parameters[1]; 187 const double P2 = parameters[2]; 189 const double term1 = P1*(1/T - 1/P2); 190 const double term2 = exp(term1); 192 outputs[0] = P0*term2; 194 outputs[0] = P0 + T*P1 + P2*T*T; 201 void surroSolubility3 203 const modena_model_t* model, 204 const double* inputs, 208 {% block variables %}{% endblock %} 210 const double P0 = parameters[0]; 211 const double P1 = parameters[1]; 212 const double P2 = parameters[2]; 213 const double P3 = parameters[3]; 215 const double term1 = P1*(1/T - 1/P2); 216 const double term2 = exp(term1); 218 outputs[0] = P0*term2; 220 outputs[0] = P0 + T*P1 + P2*T*T; 222 outputs[0] = P0+P1*exp(-pow((T-P2),2)/P3); 226 'H': {
'min': 9e99,
'max': -9e99,
'argPos': 0 }
229 'param0': {
'min': 1e-12,
'max': 1E1,
'argPos': 0 },
230 'param1': {
'min': -1e-1,
'max': 1e-1,
'argPos': 1 },
231 'param2': {
'min': -1e-1,
'max': 1e-1,
'argPos': 2 },
234 'param0': {
'min': -9e9,
'max': 9e9+2*1.42885440e-04,
'argPos': 0 },
235 'param1': {
'min': -9e9,
'max': 9e9+2*1.22132172e+00,
'argPos': 1 },
236 'param2': {
'min': -9e9,
'max': 9e9+2*-7.97789449e+02,
'argPos': 2 },
237 'param3': {
'min': -9e9,
'max': 9e9+2*1.33835999e+05,
'argPos': 3 },
244 'T': {
'min': 200.0,
'max': 550.0},
245 'xl1': {
'min': 0.0,
'max': 1.0 },
246 'xl2': {
'min': 0.0,
'max': 1.0 },
249 'T': {
'min': 200.0,
'max': 550.0},
250 'xl1': {
'min': 0.0,
'max': 1.0 },
251 'xl2': {
'min': 0.0,
'max': 1.0 },
252 'xl3': {
'min': 0.0,
'max': 1.0 },
254 f2 = CFunction(Ccode=Ccode2,
257 parameters=parameters,
260 f3 = CFunction(Ccode=Ccode3,
263 parameters=parameters4,
267 outOfBoundsStrategy=Strategy.ExtendSpaceStochasticSampling(
270 parameterFittingStrategy=Strategy.NonLinFitWithErrorContol(
271 testDataPercentage=0.2,
273 improveErrorStrategy=Strategy.StochasticSampling(
278 m_solubilityCO2PU = BackwardMappingModel(
279 _id=
'Solubility[A=CO2,B=2]',
280 surrogateFunction=f2,
283 initialisationStrategy=Strategy.InitialPoints(
285 'T': [290, 320, 350, 380],
286 'xl1': [1.1e-3, 1.0e-3, 1.0e-3, 1.0e-4],
287 'xl2': [0.9989, 0.999, 0.999, 0.9999],
290 outOfBoundsStrategy=outOfBoundsStrategy,
291 parameterFittingStrategy=parameterFittingStrategy
293 m_solubilityAirPU = BackwardMappingModel(
294 _id=
'Solubility[A=Air,B=2]',
295 surrogateFunction=f2,
298 initialisationStrategy=Strategy.InitialPoints(
300 'T': [290, 320, 350, 380],
301 'xl1': [1.1e-3, 1.0e-3, 1.0e-3, 1.0e-4],
302 'xl2': [0.9989, 0.999, 0.999, 0.9999],
305 outOfBoundsStrategy=outOfBoundsStrategy,
306 parameterFittingStrategy=parameterFittingStrategy
308 m_solubilityCyclopentanePU = BackwardMappingModel(
309 _id=
'Solubility[A=CyP,B=2]',
310 surrogateFunction=f2,
313 initialisationStrategy=Strategy.InitialPoints(
315 'T': [290, 320, 350, 380],
316 'xl1': [1.1e-3, 1.0e-3, 1.0e-3, 1.0e-4],
317 'xl2': [0.9989, 0.999, 0.999, 0.9999],
320 outOfBoundsStrategy=outOfBoundsStrategy,
321 parameterFittingStrategy=parameterFittingStrategy
323 m_solubilityO2PU = BackwardMappingModel(
324 _id=
'Solubility[A=O2,B=2]',
325 surrogateFunction=f2,
328 initialisationStrategy=Strategy.InitialPoints(
330 'T': [290, 320, 350, 380],
331 'xl1': [1.1e-3, 1.0e-3, 1.0e-3, 1.0e-4],
332 'xl2': [0.9989, 0.999, 0.999, 0.9999],
335 outOfBoundsStrategy=outOfBoundsStrategy,
336 parameterFittingStrategy=parameterFittingStrategy
338 m_solubilityN2PU = BackwardMappingModel(
339 _id=
'Solubility[A=N2,B=2]',
340 surrogateFunction=f2,
343 initialisationStrategy=Strategy.InitialPoints(
345 'T': [290, 320, 350, 380],
346 'xl1': [1.1e-3, 1.0e-3, 1.0e-3, 1.0e-4],
347 'xl2': [0.9989, 0.999, 0.999, 0.9999],
350 outOfBoundsStrategy=outOfBoundsStrategy,
351 parameterFittingStrategy=parameterFittingStrategy
354 m_solubilityCO2 = BackwardMappingModel(
355 _id=
'Solubility[A=CO2,B=3]',
356 surrogateFunction=f3,
359 initialisationStrategy=Strategy.InitialPoints(
361 'T': [290, 350, 450, 550],
362 'xl1': [0.9e-4, 1.1e-4, 1e-4, 1e-4],
363 'xl2': [0.51, 0.49, 0.5, 0.5],
364 'xl3': [0.49, 0.51, 0.5, 0.5],
367 outOfBoundsStrategy=outOfBoundsStrategy,
368 parameterFittingStrategy=parameterFittingStrategy
370 m_solubilityAir = BackwardMappingModel(
371 _id=
'Solubility[A=Air,B=3]',
372 surrogateFunction=f3,
375 initialisationStrategy=Strategy.InitialPoints(
377 'T': [290, 350, 450, 550],
378 'xl1': [0.9e-4, 1.1e-4, 1e-4, 1e-4],
379 'xl2': [0.51, 0.49, 0.5, 0.5],
380 'xl3': [0.49, 0.51, 0.5, 0.5],
383 outOfBoundsStrategy=outOfBoundsStrategy,
384 parameterFittingStrategy=parameterFittingStrategy
386 m_solubilityCyclopentane = BackwardMappingModel(
387 _id=
'Solubility[A=CyP,B=3]',
388 surrogateFunction=f3,
391 initialisationStrategy=Strategy.InitialPoints(
393 'T': [290, 350, 450, 550],
394 'xl1': [0.9e-4, 1.1e-4, 1e-4, 1e-4],
395 'xl2': [0.51, 0.49, 0.5, 0.5],
396 'xl3': [0.49, 0.51, 0.5, 0.5],
399 outOfBoundsStrategy=outOfBoundsStrategy,
400 parameterFittingStrategy=parameterFittingStrategy
405 'T': {
'min': 200.0,
'max': 550.0}
411 void surroSolubilityR11Baser 413 const modena_model_t* model, 414 const double* inputs, 418 {% block variables %}{% endblock %} 420 const double P0 = parameters[0]; 421 const double P1 = parameters[1]; 422 const double P2 = parameters[2]; 423 const double P3 = parameters[3]; 425 outputs[0] = (P0 + P1*exp(-pow(T-P2,2)/(2*P3*P3)))*1100.0/137.37e-3/101e3; 429 'param0': {
'min': 1e-12,
'max': 1E1,
'argPos': 0 },
430 'param1': {
'min': -1e-1,
'max': 1e-1,
'argPos': 1 },
431 'param2': {
'min': -1e-1,
'max': 1e-1,
'argPos': 2 },
432 'param3': {
'min': -1e-1,
'max': 1e-1,
'argPos': 3 },
434 fR11Baser = CFunction(Ccode=CcodeR11Baser,
437 parameters=parameters4
440 parR11Baser = [1e-7, 4.2934, 203.3556, 40.016]
441 m_solubilityR11Baser = ForwardMappingModel(
442 _id=
'SolubilityR11Baser',
443 surrogateFunction=fR11Baser,
445 parameters=parR11Baser,
453 void surroSolubilityCO2Baser 455 const modena_model_t* model, 456 const double* inputs, 460 {% block variables %}{% endblock %} 462 const double P0 = parameters[0]; 468 'param0': {
'min': 1e-12,
'max': 1E1,
'argPos': 0 },
470 if 'argPos' in inputsExp[
'T']:
471 inputsExp[
'T'].pop(
'argPos')
472 fCO2Baser = CFunction(Ccode=CcodeCO2Baser,
475 parameters=parameters1
478 parCO2Baser = [1.1e-4]
479 m_solubilityCO2Baser = ForwardMappingModel(
480 _id=
'SolubilityCO2Baser',
481 surrogateFunction=fCO2Baser,
483 parameters=parCO2Baser,
491 void surroSolubilityPentGupta 493 const modena_model_t* model, 494 const double* inputs, 498 {% block variables %}{% endblock %} 500 const double P0 = parameters[0]; 501 const double P1 = parameters[1]; 502 const double P2 = parameters[2]; 503 const double P3 = parameters[3]; 504 const double P4 = parameters[4]; 506 outputs[0] = P0/(exp((P1-P2*T)/(P3-T))-P4)*1100.0/72.15e-3/101e3; 510 'param0': {
'min': 1e-12,
'max': 1E1,
'argPos': 0 },
511 'param1': {
'min': -1e-1,
'max': 1e-1,
'argPos': 1 },
512 'param2': {
'min': -1e-1,
'max': 1e-1,
'argPos': 2 },
513 'param3': {
'min': -1e-1,
'max': 1e-1,
'argPos': 3 },
514 'param4': {
'min': -1e-1,
'max': 1e-1,
'argPos': 4 },
516 if 'argPos' in inputsExp[
'T']:
517 inputsExp[
'T'].pop(
'argPos')
518 fPentGupta = CFunction(Ccode=CcodePentGupta,
521 parameters=parameters5
524 parPentGupta = [-3.3e-4, 2.09e4, 67.5, 8.69e4, 1.01]
525 m_solubilityPentGupta = ForwardMappingModel(
526 _id=
'SolubilityPentGupta',
527 surrogateFunction=fPentGupta,
529 parameters=parPentGupta,
537 void surroSolubilityPentWinkler 539 const modena_model_t* model, 540 const double* inputs, 544 {% block variables %}{% endblock %} 546 const double P0 = parameters[0]; 547 const double P1 = parameters[1]; 548 const double P2 = parameters[2]; 549 const double P3 = parameters[3]; 551 outputs[0] = (P0 + P1*exp(-pow(T-P2,2)/(2*P3*P3)))*1100.0/72.15e-3/101e3; 554 if 'argPos' in inputsExp[
'T']:
555 inputsExp[
'T'].pop(
'argPos')
556 fPentWinkler = CFunction(Ccode=CcodePentWinkler,
559 parameters=parameters5
562 parPentWinkler = [0.0064,0.0551,298.0,17.8]
563 m_solubilityPentWinkler = ForwardMappingModel(
564 _id=
'SolubilityPentWinkler',
565 surrogateFunction=fPentWinkler,
567 parameters=parPentWinkler,
571 This FireTask controls the execution of the detailed model of the Solubility model.