44 from modena
import ForwardMappingModel,BackwardMappingModel,SurrogateModel,CFunction,IndexSet,ModenaFireTask
46 from fireworks.user_objects.firetasks.script_task
import FireTaskBase, ScriptTask
47 from fireworks
import Firework, Workflow, FWAction
48 from fireworks.utilities.fw_utilities
import explicit_serialize
49 from blessings
import Terminal
50 from jinja2
import Template
56 blowing_agents = IndexSet(
57 name=
'blowing_agents',
58 names= [
'air',
'CO2']
63 names = [
'PU',
'THF',
'hexane',
'surfactant']
73 class DensityExactSim(ModenaFireTask):
75 def task(self, fw_spec):
77 self.generate_inputfile()
80 ret = os.system(os.path.dirname(os.path.abspath(__file__))+
'/src/PCSAFT_Density')
83 self.handleReturnCode(ret)
92 def generate_inputfile(self):
95 Write inputs to the template, one per line. 97 {% for k,v in s['point'].iteritems() %} 101 The number of species, one integer. 103 {{ s['indices'].__len__() }} 105 Write the species (lower case) one per line. 107 {% for k,v in s['indices'].iteritems() %} 111 Set initial feed molar fractions to zero. 113 {% for k,v in s['indices'].iteritems() %} 116 """, trim_blocks=
True,
117 lstrip_blocks=
True).stream(s=self).dump(
'in.txt')
120 with open(
'out.txt',
'w+')
as FILE:
128 def analyse_output(self):
129 with open(
'out.txt',
'r') as FILE: self['point'][
'rho'] = float(FILE.readline())
139 const modena_model_t* model, 140 const double* inputs, 145 {% block variables %}{% endblock %} 147 const double P0 = parameters[0]; 148 const double P1 = parameters[1]; 149 const double P2 = parameters[2]; 151 const double expo = 1.0 + (1.0 - T/P2); 152 const double pwr = pow(P1,expo); 154 outputs[0] = P0 / pwr; 155 //outputs[0] = P0 + T*P1 + P2*T*T; 160 'T': {
'min': 270.0,
'max': 550.0},
163 'rho': {
'min': 9e99,
'max': -9e99,
'argPos': 0 },
166 'param0': {
'min': -1E10,
'max': 1E10+2,
'argPos': 0 },
167 'param1': {
'min': -1E10,
'max': 1E10+2,
'argPos': 1 },
168 'param2': {
'min': -1E10,
'max': 1E10+2,
'argPos': 2 },
171 'A' : blowing_agents,
176 m = BackwardMappingModel(
177 _id=
'PolymerDensity[A=AIR,B=PU]',
178 surrogateFunction= f,
179 exactTask= DensityExactSim(),
180 substituteModels= [ ],
181 initialisationStrategy= Strategy.InitialPoints(
184 'T': [270.0, 300.0, 350.0, 400, 450, 500, 550],
187 outOfBoundsStrategy= Strategy.ExtendSpaceStochasticSampling(
190 parameterFittingStrategy= Strategy.NonLinFitWithErrorContol(
191 testDataPercentage= 0.2,
193 improveErrorStrategy= Strategy.StochasticSampling(