MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
twoTanksMacroscopicProblemCxx.C
Go to the documentation of this file.
1 
41 #include <stdio.h>
42 #include <iostream>
43 #include "modenaModel.H"
44 
45 using namespace std;
46 
47 int
48 main(int argc, char *argv[])
49 {
50  const double D = 0.01;
51 
52  double p0 = 3e5;
53  double p1 = 10000;
54  double V0 = 0.1;
55  double V1 = 1;
56  double T = 300;
57 
58  double t = 0.0;
59  const double deltat = 1e-3;
60  const double tend = 5.5;
61 
62  double m0 = p0*V0/287.1/T;
63  double m1 = p1*V1/287.1/T;
64 
65  double rho0 = m0/V0;
66  double rho1 = m1/V1;
67 
68  try
69  {
70  // Instantiate a model
71  Modena::modenaModel model("flowRate");
72 
73  cout << "inputs:" << endl;
74  std::vector<std::string> iNames = model.inputs_names();
75  for(int i=0; i<model.inputs_size(); i++)
76  {
77  cout << iNames[i] << endl;
78  }
79 
80  cout << "outputs:" << endl;
81  std::vector<std::string> oNames = model.outputs_names();
82  for(int i=0; i<model.outputs_size(); i++)
83  {
84  cout << oNames[i] << endl;
85  }
86 
87  cout << "parameters:" << endl;
88  std::vector<std::string> pNames = model.parameters_names();
89  for(int i=0; i<model.parameters_size(); i++)
90  {
91  cout << pNames[i] << endl;
92  }
93 
94  size_t Dpos = model.inputs_argPos("D");
95  size_t rho0Pos = model.inputs_argPos("rho0");
96  size_t p0Pos = model.inputs_argPos("p0");
97  size_t p1Byp0Pos = model.inputs_argPos("p1Byp0");
98 
99  model.argPos_check();
100 
101  while(t + deltat < tend + 1e-10)
102  {
103  t += deltat;
104 
105  if(p0 > p1)
106  {
107  // Set input vector
108  model.inputs_set(Dpos, D);
109  model.inputs_set(rho0Pos, rho0);
110  model.inputs_set(p0Pos, p0);
111  model.inputs_set(p1Byp0Pos, p1/p0);
112 
113  // Call the model
114  model.call();
115 
116  // Fetch result
117  double mdot = model.outputs_get(0);
118 
119  m0 -= mdot*deltat;
120  m1 += mdot*deltat;
121  }
122  else
123  {
124  // Set input vector
125  model.inputs_set(Dpos, D);
126  model.inputs_set(rho0Pos, rho1);
127  model.inputs_set(p0Pos, p1);
128  model.inputs_set(p1Byp0Pos, p0/p1);
129 
130  // Call the model
131  model.call();
132 
133  // Fetch result
134  double mdot = model.outputs_get(0);
135 
136  m0 += mdot*deltat;
137  m1 -= mdot*deltat;
138  }
139 
140  rho0 = m0/V0;
141  rho1 = m1/V1;
142  p0 = m0/V0*287.1*T;
143  p1 = m1/V1*287.1*T;
144 
145  cout << "t = " << t << " rho0 = " << rho0 << " p0 = " << p0 << " p1 = " << p1 << endl;
146  }
147  }
148  catch(const Modena::modenaException& e)
149  {
150  return e.errorCode();
151  }
152 
153  return 0;
154 }
int main(int argc, char *argv[])
Reads parameters. Creates struts and walls. Saves foam morphology to a file.
Definition: foams.cc:23
Definition: model.f90:7
double tend
end time, s