MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
write_kinetics.h
Go to the documentation of this file.
1 
10 void write_kinetics( const state_type &y , const double t );
11 
12 void write_kinetics( const state_type &y , const double t )
13 {
14 // write_kinetics - write the results into text files
15 // @param - const state_type &y - vector of all the variables
16 // @param - const double t - time
17  int n;
18  n = y.size();
19 
20  ofstream out[n];
21  out[0].open("./XW1.txt", std::ios::app);
22  out[1].open("./XOH1.txt", std::ios::app);
23  out[2].open("./T1.txt", std::ios::app);
24  out[3].open("./L_l1.txt", std::ios::app);
25  out[4].open("./L_g1.txt", std::ios::app);
26  out[5].open("./CO2_l1.txt", std::ios::app);
27  out[6].open("./CO2_g1.txt", std::ios::app);
28  out[7].open("./m01.txt", std::ios::app);
29  out[8].open("./m11.txt", std::ios::app);
30  out[9].open("./m21.txt", std::ios::app);
31  out[10].open("./m31.txt", std::ios::app);
32  // out[11].open("./EG_XNCO1.txt", std::ios::app);
33  // out[12].open("./EG_XOH1.txt", std::ios::app);
34  // out[13].open("./XH2O1.txt", std::ios::app);
35  // out[14].open("./CO21.txt", std::ios::app);
36  // out[15].open("./PENTANE1.txt", std::ios::app);
37  // out[16].open("./POLYMER1.txt", std::ios::app);
38  // out[17].open("./POLYMERBLOW1.txt", std::ios::app);
39  // out[18].open("./UREA1.txt", std::ios::app);
40  // out[19].open("./R_1_temp1.txt", std::ios::app);
41 
42  for (int i = 0; i < n; i++)
43  {
44  if(i == 11)
45  {
46  out[i] << t << '\t' << (1.0-y[i]/5.0) << '\n';
47  }
48  else if (i == 12)
49  {
50  out[i] << t << '\t' << (1.0-y[i]/5.0) << '\n';
51  }
52  else if (i == 13)
53  {
54  out[i] << t << '\t' << (1.0-y[i]/0.2) << '\n';
55  }
56  else
57  {
58  out[i] << t << '\t' << y[i] << '\n';
59  }
60  out[i].close();
61  }
62 
63  double rhoPolySurrgate;
64  switch (denMod) {
65  case 1: {
66  // Calling the model for density reaction mixture
67  size_t T_denpos = modena_model_inputs_argPos(density_reaction_mixturemodel, "T");
68  size_t XOH_denpos = modena_model_inputs_argPos(density_reaction_mixturemodel, "XOH");
69  modena_model_argPos_check(density_reaction_mixturemodel);
70  // set input vector
71  modena_inputs_set(inputs_den, T_denpos, y[2]);
72  modena_inputs_set(inputs_den, XOH_denpos, y[1]);
73  // call the model
74  int ret_den = modena_model_call (density_reaction_mixturemodel, inputs_den, outputs_den);
75  // terminate, if requested
76  if(ret_den != 0)
77  {
78  modena_inputs_destroy (inputs_den);
79  modena_outputs_destroy (outputs_den);
80  modena_model_destroy (density_reaction_mixturemodel);
81  exit(ret_den);
82  }
83  rhoPolySurrgate = modena_outputs_get(outputs_den, 0);
84  break;
85  }
86  case 2:
87  rhoPolySurrgate = rhoPoly;
88  break;
89  case 3:
90  {
91  // Calling the PCSAFT model for density reaction mixture
92  size_t T_denpos = modena_model_inputs_argPos(density_reaction_mixturemodel, "T");
93  modena_model_argPos_check(density_reaction_mixturemodel);
94  modena_inputs_set(inputs_den, T_denpos, y[2]);
95  // // call the model
96  int ret_den = modena_model_call (density_reaction_mixturemodel, inputs_den, outputs_den);
97  if (ret_den != 0)
98  {
99  modena_inputs_destroy (inputs_den);
100  modena_outputs_destroy (outputs_den);
101  modena_model_destroy (density_reaction_mixturemodel);
102  exit(ret_den);
103  }
104  rhoPolySurrgate = modena_outputs_get(outputs_den, 0);
105  break;
106  }
107  default:
108  cerr << "Invalid density model" << endl;
109  exit(1);
110  }
111 
112  double p1,p2;
113  p1 = partialPressureBA(y);
114  p2 = partialPressureCO2(y);
115  double rho_bubble = ((p1+p2)/(RR*y[2]))*(y[6]*M_CO2 + y[4]*M_B)/(fmax((1000.0*(y[6] + y[4])),1.0e-8));
116  // double rho_foam = (rho_bubble*(y[8]/(1.0+y[8])) + (1.0+L0)*rhoPolySurrgate*(1.0 - (y[8]/(1.0+y[8]))));
117  double rho_foam = (rho_bubble*(y[8]/(1.0+y[8])) + rhoPolySurrgate*(1.0 - (y[8]/(1.0+y[8]))));
118 
119  // print out the strut content
120  // set input vector
121  modena_inputs_set(inputs_strutContent, rho_foam_Pos, rho_foam);
122 
123  // call the model
124  int ret_strutContent = modena_model_call (strutContentmodel, inputs_strutContent, outputs_strutContent);
125  if ((tend - t) < 2)
126  {
127  cout << "final foam density: " << rho_foam << endl;
128  cout << "strut content: " << modena_outputs_get(outputs_strutContent, 0) << endl;
129  }
130 
131  double thermalConductivity;
132  if (rho_foam > 48.0)
133  {
134  thermalConductivity = 8.7006e-8*rho_foam*rho_foam + 8.4674e-5*rho_foam
135  + 1.16e-2;
136  }
137  else
138  {
139  thermalConductivity = 9.3738e-6*rho_foam*rho_foam - 7.3511e-4*rho_foam
140  + 2.956e-2;
141  }
142  // surrogate model for thermal conductivity
143  modena_inputs_set(inputs_thermalConductivity, porosity_Pos, (1.0 - rho_foam/rhoPolySurrgate));
144  double R = bubbleRadius(y[7], y[8]);
145  modena_inputs_set(inputs_thermalConductivity, cell_size_Pos, (2.0*R));
146  modena_inputs_set(inputs_thermalConductivity, temp_Pos, y[2]);
147  modena_inputs_set(inputs_thermalConductivity, X_CO2_Pos, (p2/(p1+p2)));
148  modena_inputs_set(inputs_thermalConductivity, X_O2_Pos, 0.0);
149  modena_inputs_set(inputs_thermalConductivity, X_N2_Pos, 0.0);
150  modena_inputs_set(inputs_thermalConductivity, X_Cyp_Pos, (p1/(p1+p2)));
151  double st_c;
152  st_c = modena_outputs_get(outputs_strutContent, 0);
153  modena_inputs_set(inputs_thermalConductivity, strut_c_Pos, st_c);
154  int ret_thermalConductivitymodel = modena_model_call (thermalConductivitymodel, inputs_thermalConductivity, outputs_thermalConductivity);
155  if(modena_error_occurred())
156  {
157  exit(modena_error());
158  }
159  double the_con;
160  the_con = modena_outputs_get(outputs_thermalConductivity, 0);
161  ofstream thermalOut;
162  thermalOut.open("./thermalConductivity.txt", std::ios::app);
163  thermalOut << the_con << '\t' << thermalConductivity << '\t' << rho_foam << '\n';
164  thermalOut.close();
165 
166 
167  ofstream rho_bubbleout;
168  rho_bubbleout.open("./rho_bubble.txt", std::ios::app);
169  rho_bubbleout << t << '\t' << rho_bubble << '\n';
170  rho_bubbleout.close();
171 
172  ofstream rho_foamout;
173  rho_foamout.open("./rho_foam.txt", std::ios::app);
174  rho_foamout << t << '\t' << rho_foam << '\n';
175  rho_foamout.close();
176 
177  ofstream R_bubble;
178  R_bubble.open("./R_bubble.txt", std::ios::app);
179  R_bubble << t << '\t' << R << '\n';
180  R_bubble.close();
181 
182  momentsConverter(y,t);
183 
184  double p_1 = partialPressureBA(y);
185  ofstream p1out;
186  p1out.open("./p_1.txt", std::ios::app);
187  p1out << t << '\t' << p_1 << '\n';
188  p1out.close();
189 
190  double p_2 = partialPressureCO2(y);
191  ofstream p2out;
192  p2out.open("./p_2.txt", std::ios::app);
193  p2out << t << '\t' << p_2 << '\n';
194  p2out.close();
195 }
size_t modena_model_inputs_argPos(const modena_model_t *self, const char *name)
Function determining position of an argument in the input vector.
Definition: model.c:366
size_t X_CO2_Pos
memory allocation for the partial pressure of CO2 as the input of thermal conductivity surrogate mode...
Definition: modenaData.H:194
real(dp), dimension(:), allocatable y
state variables
Definition: globals.f90:106
size_t temp_Pos
memory allocation for the temperature as the input of thermal conductivity surrogate model ...
Definition: modenaData.H:191
size_t porosity_Pos
memory allocation for the gas volume fraction as the input of thermal conductivity surrogate model ...
Definition: modenaData.H:182
size_t X_N2_Pos
memory allocation for the partial pressure of N2 as the input of thermal conductivity surrogate model...
Definition: modenaData.H:203
size_t cell_size_Pos
memory allocation for the bubble size as the input of thermal conductivity surrogate model ...
Definition: modenaData.H:185
modena_model_t * thermalConductivitymodel
pointer to the surrogate model for thermal conductivity
Definition: modenaData.H:22
int denMod
density mode, 1 = modena, 2 = constant
size_t X_Cyp_Pos
memory allocation for the partial pressure of cyclo-pentane as the input of thermal conductivity surr...
Definition: modenaData.H:197
double partialPressureCO2(const state_type &y)
partial pressure of CO2
double M_CO2
Molecular mass of carbon dioxide, kg/kmol.
int modena_model_call(modena_model_t *self, modena_inputs_t *inputs, modena_outputs_t *outputs)
Function calling the surrogate model and checking for errors.
Definition: model.c:553
double RR
ideal gas constant, J/mol K
double bubbleRadius(const double m0, const double m1)
radius of bubbles based on the moments
Definition: bubbleRadius.h:28
size_t rho_foam_Pos
memory allocation for the foam density as the input of thermal conductivity surrogate model ...
Definition: modenaData.H:179
double rhoPoly
density of the liquid polymer, kg/m3
void modena_model_destroy(modena_model_t *self)
Function deallocating the memory allocated for the surrogate model.
Definition: model.c:665
void write_kinetics(const state_type &y, const double t)
double M_B
Molecular mass of blowing agent, kg/kmol.
void momentsConverter(const state_type &y, const double t)
double partialPressureBA(const state_type &y)
partial pressure of the physical blowing agent
size_t strut_c_Pos
memory allocation for the strut content as the input of thermal conductivity surrogate model ...
Definition: modenaData.H:188
size_t X_O2_Pos
memory allocation for the partial pressure of O2 as the input of thermal conductivity surrogate model...
Definition: modenaData.H:200
double tend
end time, s
void modena_model_argPos_check(const modena_model_t *self)
Function checking that the user has queried all input positions.
Definition: model.c:408