72 from fireworks.utilities.fw_utilities
import explicit_serialize
73 from jinja2
import Template
85 blowing_agents = IndexSet(
86 name=
'blowing_agents',
87 names= [
'AIR',
'CO2']
102 names = [
'PU',
'THF',
'HEXANE']
115 surfactant = IndexSet(
117 names = [
'surfactant',
'no_surfactant']
151 def task(self, fw_spec):
154 self.generate_inputfile()
157 run_command = os.path.dirname(os.path.abspath(__file__))+
'/src/PCSAFT_SurfaceTension -snes_monitor_short -ksp_monitor_short \ 158 -nx 800 -rc 9.0 -box 300 -erel 1e-08 -init_pert 0 \ 159 -snes_type newtonls -snes_converged_reason \ 160 -snes_atol 1e-07 -snes_rtol 1e-07 -snes_stol 1e-07 -snes_max_it 20 \ 161 -ksp_max_it 15 -ksp_gmres_restart 50 \ 162 -snes_linesearch_type l2 -snes_linesearch_damping 0.3 -snes_linesearch_monitor \ 163 -snes_max_fail 1 -snes_max_linear_solve_fail 100 \ 164 -ksp_gmres_cgs_refinement_type refine_always \ 165 -snes_ksp_ew -snes_ksp_ew_version 1 -snes_ksp_ew_rtol0 0.5 -snes_ksp_ew_rtolmax 0.9 -snes_ksp_ew_threshold 0.1 \ 166 -jac 0 -pc_type none > log' 169 ret = os.system(run_command)
171 self.handleReturnCode(ret)
174 self.analyse_output()
180 def generate_inputfile(self):
181 with open(
'in.txt',
'w')
as f:
182 f.write(
"{}\n".format(self[
'point'][
'T']))
183 if self[
'indices'][
'C']==
'no_surfactant':
185 f.write(
"{}\n".format(ncomp))
186 f.write(
"{}\n".format(self[
'indices'][
'A'].lower()))
187 f.write(
"{}\n".format(self[
'indices'][
'B'].lower()))
190 f.write(
"{}\n".format(ncomp))
191 f.write(
"{}\n".format(self[
'indices'][
'A'].lower()))
192 f.write(
"{}\n".format(self[
'indices'][
'B'].lower()))
193 f.write(
"{}\n".format(self[
'indices'][
'C'].lower()))
194 for i
in range(ncomp):
195 f.write(
"{}\n".format(0.0))
196 with open(
'out.txt',
'w+')
as FILE:
203 def analyse_output(self):
204 with open(
'out.txt',
'r') as FILE: self['point'][
'ST'] = float(FILE.readline())
232 void surroSurfaceTension 234 const modena_model_t* model, 235 const double* inputs, 239 {% block variables %}{% endblock %} 241 const double P0 = parameters[0]; 242 const double P1 = parameters[1]; 243 const double P2 = parameters[2]; 245 outputs[0] = P0 + T*P1 + P2*T*T; 249 'T': {
'min': 270.0,
'max': 550.0 },
252 'ST': {
'min': 9e99,
'max': -9e99,
'argPos': 0 },
255 'param0': {
'min': -1E10,
'max': 1E10,
'argPos': 0 },
256 'param1': {
'min': -1E10,
'max': 1E10,
'argPos': 1 },
257 'param2': {
'min': -1E10,
'max': 1E10,
'argPos': 2 },
260 'A' : blowing_agents,
282 m = BackwardMappingModel(
283 _id=
'SurfaceTension[A=AIR,B=PU,C=surfactant]',
284 surrogateFunction= f,
286 substituteModels= [ ],
287 initialisationStrategy= Strategy.InitialPoints(
290 'T': [290.0, 300.0, 350.0, 500.0],
293 outOfBoundsStrategy= Strategy.ExtendSpaceStochasticSampling(
296 parameterFittingStrategy= Strategy.NonLinFitWithErrorContol(
297 testDataPercentage= 0.2,
299 improveErrorStrategy= Strategy.StochasticSampling(
319 m2 = BackwardMappingModel(
320 _id=
'SurfaceTension[A=AIR,B=PU,C=no_surfactant]',
321 surrogateFunction= f,
323 substituteModels= [ ],
324 initialisationStrategy= Strategy.InitialPoints(
327 'T': [290.0, 300.0, 350.0, 500.0],
330 outOfBoundsStrategy= Strategy.ExtendSpaceStochasticSampling(
333 parameterFittingStrategy= Strategy.NonLinFitWithErrorContol(
334 testDataPercentage= 0.2,
336 improveErrorStrategy= Strategy.StochasticSampling(
342 Recipe for PCSAFT Surface Tension Application.