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
56 class FlowRateExactSim(ModenaFireTask):
58 def task(self, fw_spec):
64 {{ s['point']['rho0'] }} 65 {{ s['point']['p0'] }} 66 {{ s['point']['p1Byp0'] }} 67 '''.strip()).stream(s=self).dump(
'in.txt')
73 ret = os.system(os.path.dirname(os.path.abspath(__file__))+
'/src/flowRateExact')
76 self.handleReturnCode(ret)
79 f = open(
'out.txt',
'r') self['point'][
'flowRate'] = float(f.readline())
88 void two_tank_flowRate 90 const modena_model_t* model, 95 {% block variables %}{% endblock %} 97 const double p1 = p0*inputs[3]; 99 const double P0 = parameters[0]; 100 const double P1 = parameters[1]; 102 outputs[0] = M_PI*pow(D, 2.0)*P1*sqrt(P0*rho0*p0); 107 'D': {
'min': 0,
'max': 9e99 },
108 'rho0': {
'min': 0,
'max': 9e99 },
109 'p0': {
'min': 0,
'max': 9e99 },
110 'p1Byp0': {
'min': 0,
'max': 1.0 },
113 'flowRate': {
'min': 9e99,
'max': -9e99,
'argPos': 0 },
116 'param0': {
'min': 0.0,
'max': 10.0,
'argPos': 0 },
117 'param1': {
'min': 0.0,
'max': 10.0,
'argPos': 1 },
121 m = BackwardMappingModel(
123 surrogateFunction= f,
124 exactTask= FlowRateExactSim(),
125 substituteModels= [ ],
126 initialisationStrategy= Strategy.InitialPoints(
129 'D': [0.01, 0.01, 0.01, 0.01],
130 'rho0': [3.4, 3.5, 3.4, 3.5],
131 'p0': [2.8e5, 3.2e5, 2.8e5, 3.2e5],
132 'p1Byp0': [0.03, 0.03, 0.04, 0.04],
135 outOfBoundsStrategy= Strategy.ExtendSpaceStochasticSampling(
138 parameterFittingStrategy= Strategy.NonLinFitWithErrorContol(
139 testDataPercentage= 0.2,
141 improveErrorStrategy= Strategy.StochasticSampling(