42 from os
import getcwd, makedirs, remove, system, symlink, walk
43 from os.path
import abspath, dirname, isfile, join, relpath
44 from shutil
import copy2
48 from numpy.linalg
import pinv
49 from numpy
import sin, cos, pi, matrix, array, dot
53 import polymerViscosity
54 from modena
import ForwardMappingModel, BackwardMappingModel, SurrogateModel, CFunction, ModenaFireTask
57 from fireworks.utilities.fw_utilities
import explicit_serialize
58 from jinja2
import Template
61 from math
import pi,sqrt
65 MODULE_DIR = dirname(abspath(__file__))
66 EXECUTION_DIR = getcwd()
68 with open(getcwd()+
'/inputs/unifiedInput.json')
as jsonfile:
69 inputs=json.load(jsonfile)
70 X_gel=inputs[
'kinetics'][
'gelPoint']
79 for dirpath,_,filenames
in walk(src):
80 dstpth = join(dst, dirpath[len(src)+1:])
81 relpth = relpath(dirpath, dstpth)
95 with open(join(dirpath,
".filesToCopy"))
as FILE:
96 lines = FILE.read().splitlines()
101 if any(fnmatch.fnmatch(fn, gl)
for gl
in lines):
102 dstfn = join(dstpth, fn)
103 srcfn = join(dirpath, fn)
104 if not isfile(dstfn):
108 dstfn = join(dstpth, fn)
109 srcfn = join(relpth, fn)
110 if not isfile(dstfn):
112 symlink(srcfn, dstfn)
124 INPUT_FILE =
'RheologyExact.in' 125 OUTPUT_FILE =
'RheologyExact.out' 126 APPLICATION_CMD = join(MODULE_DIR ,
'src/rheologyexactdummy')
128 def task(self, fw_spec):
131 Template(
'''{{ s['point']['T'] }} 132 {{ s['point']['shear'] }} 133 {{ s['point']['X'] }} 134 {{ s['point']['m0'] }} 135 {{ s['point']['m1'] }} 136 {{ s['point']['mu'] }} 137 {{ s['point']['ST'] * 0,001 }}'''.strip()).stream(s=self).dump(self.INPUT_FILE)
141 ret = system(self.APPLICATION_CMD)
143 self.handleReturnCode(ret)
146 with open(self.OUTPUT_FILE,
'r') as FILE: self['point'][
'mu_car'] = float(FILE.readline())
148 remove(self.INPUT_FILE)
149 remove(self.OUTPUT_FILE)
159 void rheology_dummy_SM 161 const modena_model_t* model, 162 const double* inputs, 166 {% block variables %}{% endblock %} 168 const double lambda = parameters[0]; 169 const double alpha = parameters[1]; 170 const double n_rh = parameters[2]; 172 const double A_mu = 0.0387; // could be loaded from some library for consistence 173 const double E_mu = 10000; 174 const double R_rh = 8.314; 175 const double mu_a = 1.5; 176 const double mu_b = 1; 177 const double mu_c = 0; 178 const double mu_d = 0.001; 179 const double X_gel = '''+str(X_gel)+
'''; 180 const double mu_0_const = 0.195; 181 const double mu_inf_const = 0.266; 187 mu_0 = (log(X+mu_d) - log(mu_d) + pow(X_gel / ( X_gel - X ), mu_a + X*mu_b + mu_c*pow(X,2))) * mu_0_const; 188 mu_inf = (log(X+mu_d) - log(mu_d) + pow(X_gel / ( X_gel - X ), mu_a + X*mu_b + mu_c*pow(X,2)))* mu_inf_const; 190 mu_car = (mu_inf + (mu_0 - mu_inf)*pow(1 + pow(lambda*shear,alpha), (n_rh - 1) / alpha)); 194 // printf("apparent viscosity car %f", mu_car); 200 'T': {
'min': 0,
'max': 550 },
201 'shear': {
'min': 0,
'max': 9e99 },
202 'X': {
'min': 0,
'max': 1 },
203 'm0': {
'min': 0,
'max': 9e99 },
204 'm1': {
'min': 0,
'max': 9e99 },
205 'mu': {
'min': 0,
'max': 1000 },
206 'ST': {
'min': 0,
'max': 100 },
209 'mu_car': {
'min': 0,
'max': 9e99,
'argPos': 0 },
212 'lamdba': {
'min': 1.35,
'max': 21.35,
'argPos': 0 },
213 'alpha': {
'min': 0,
'max': 2,
'argPos': 1 },
214 'n_rh': {
'min': 0,
'max': 2,
'argPos': 2 },
225 inputTemplate = Template(
'''{{ s['point']['T'] }} 226 {{ s['point']['shear'] }} 227 {{ s['point']['X'] }} 228 {{ s['point']['mu'] }} 229 {{ s['point']['ST'] * 0.001 }} 230 {{ s['point']['m0'] }} 231 {{ s['point']['m1'] }}'''.strip())
237 fname = glob(
"bulk_stress_*.out")
238 print "Reading output file: %s" %(fname)
240 fc = tuple(open(fname[0],
'r'))# Read file 241 DATA = [[float(n) for n
in re.findall(
r'-?\d+.?\d+',l)]
for l
in fc]
245 header = (
'strain',
'omega',
'dt',
'eta_p',
'Gamma',
'r') 246 params = { k: v for (k, v)
in zip(header, DATA.pop(0)) }
250 Tc = 2*pi/params[
'omega']/params[
'dt']
255 DATA = zip(*DATA[tc:te])
261 Y = np.matrix( DATA[2] ).transpose()
263 si = params[
'strain']*np.sin(params[
'omega']*np.array(DATA[0]) )
264 co = params[
'strain']*np.cos(params[
'omega']*np.array(DATA[0]) )
265 X = np.matrix( zip(*[si, co]) )
270 b = np.linalg.pinv(X)*Y
273 bsum = np.dot( b.T, b ).A1[0]
274 eta = sqrt( bsum )/params[
'omega']
283 return system(MODULE_DIR+
'/src/rheology')
289 fin=
"RheologyExact.in" 308 void rheology_tFEM_SM 310 const modena_model_t* model, 311 const double* inputs, 315 {% block variables %}{% endblock %} 317 const double lambda = parameters[0]; 318 const double alpha = parameters[1]; 319 const double n_rh = parameters[2]; 321 const double A_mu = 0.0387; // could be loaded from some library for consistence 322 const double E_mu = 10000; 323 const double R_rh = 8.314; 324 const double mu_a = 1.5; 325 const double mu_b = 1; 326 const double mu_c = 0; 327 const double mu_d = 0.001; 328 const double X_gel = 0.615; 329 const double mu_0_const = 0.195; 330 const double mu_inf_const = 0.266; 331 // const double lambda = 11.35 ; 332 // const double alpha = 2; 333 // const double n_rh = 0.2; 335 double mu_0, mu_inf, f_t; 338 mu_0 = (log(X+mu_d) - log(mu_d) + pow(X_gel / ( X_gel - X ), mu_a + X*mu_b + mu_c*pow(X,2))) * mu_0_const; 339 mu_inf = (log(X+mu_d) - log(mu_d) + pow(X_gel / ( X_gel - X ), mu_a + X*mu_b + mu_c*pow(X,2)))* mu_inf_const; 340 f_t = A_mu * exp(E_mu / R_rh / T ); 342 mu_car = (mu_inf + (mu_0 - mu_inf)*pow(1 + pow(lambda*shear,alpha), (n_rh - 1) / alpha)) * f_t; 343 //printf("apparent viscosity %f", mu_ap); 349 'T': {
'min': 0,
'max': 550 },
350 'shear': {
'min': 0,
'max': 9e99 },
351 'X': {
'min': 0,
'max': 1 },
352 'm0' : {
'min': 0,
'max' : 9e99},
353 'm1' : {
'min': 0,
'max' : 9e99},
354 'mu': {
'min': 0,
'max': 1000 },
355 'ST': {
'min': 0,
'max': 100 },
358 'mu_car': {
'min': 0,
'max': 9e99,
'argPos': 0 },
361 'lamdba': {
'min': 1.35,
'max': 21.35,
'argPos': 0 },
362 'alpha': {
'min': 0,
'max': 2,
'argPos': 1 },
363 'n_rh': {
'min': 0,
'max': 2,
'argPos': 2 },
369 m = BackwardMappingModel(
371 surrogateFunction= f_dummy,
375 substituteModels= [ polymerViscosity.m_polymerViscosity, SurfaceTension.m],
376 initialisationStrategy= Strategy.InitialPoints(
382 'm0': [ 2.5e10, 1.1e10],
386 outOfBoundsStrategy= Strategy.ExtendSpaceStochasticSampling(
389 parameterFittingStrategy= Strategy.NonLinFitWithErrorContol(
390 testDataPercentage= 0.2,
392 improveErrorStrategy= Strategy.StochasticSampling(
399
def execute_simulation(self)
Method executing the detailed model.
def post_processing(self, fname="RheologyExact.out")
Analyse output.
def link_files(src, dst)
Function symlinking all files and directories from directory "src" sto the directory "dst"...
A FireTask that starts a microscopic code and updates the database.
def task(self, fw_spec)
Method executed by FireWorks.
A FireTask that starts a microscopic code and updates the database.