42 from modena
import ForwardMappingModel, BackwardMappingModel, SurrogateModel, CFunction, ModenaFireTask
44 from fireworks
import Firework, Workflow, FWAction
45 from fireworks.utilities.fw_utilities
import explicit_serialize
46 from blessings
import Terminal
47 from jinja2
import Template
57 class FlowRateExactSim(ModenaFireTask):
59 def task(self, fw_spec):
65 {{ s['point']['rho0'] }} 66 {{ s['point']['p0'] }} 67 {{ s['point']['p1Byp0'] }} 68 '''.strip()).stream(s=self).dump(
'in.txt')
74 ret = os.system(os.path.dirname(os.path.abspath(__file__))+
'/src/flowRateExact')
77 self.handleReturnCode(ret)
80 f = open(
'out.txt',
'r') self['point'][
'flowRate'] = float(f.readline())
89 void two_tank_flowRate 91 const modena_model_t* model, 96 {% block variables %}{% endblock %} 98 const double D = inputs[0]; 99 const double rho0 = inputs[1]; 100 const double p0 = inputs[2]; 101 const double p1 = p0*inputs[3]; 103 const double P0 = parameters[0]; 104 const double P1 = parameters[1]; 106 outputs[0] = M_PI*pow(D, 2.0)*P1*sqrt(P0*rho0*p0); 111 'D': {
'min': 0,
'max': 9e99 },
112 'T0': {
'min': 0,
'max': 9e99 },
113 'p0': {
'min': 0,
'max': 9e99 },
114 'p1Byp0': {
'min': 0,
'max': 1.0 },
117 'flowRate': {
'min': 9e99,
'max': -9e99,
'argPos': 0 },
120 'param0': {
'min': 0.0,
'max': 10.0,
'argPos': 0 },
121 'param1': {
'min': 0.0,
'max': 10.0,
'argPos': 1 },
125 m = BackwardMappingModel(
127 surrogateFunction= f,
128 exactTask= FlowRateExactSim(),
129 substituteModels= [ idealGas.m ],
130 initialisationStrategy= Strategy.InitialPoints(
133 'D': [0.01, 0.01, 0.01, 0.01],
134 'T0': [300, 300, 300, 300],
135 'p0': [2.8e5, 3.2e5, 2.8e5, 3.2e5],
136 'p1Byp0': [0.03, 0.03, 0.04, 0.04],
139 outOfBoundsStrategy= Strategy.ExtendSpaceStochasticSampling(
142 parameterFittingStrategy= Strategy.NonLinFitWithErrorContol(
143 testDataPercentage= 0.2,
145 improveErrorStrategy= Strategy.StochasticSampling(