MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
twoTanksFullProblem.C
1 /*
2 
3  ooo ooooo oooooooooo. ooooo ooo
4  `88. .888' `888' `Y8b `888b. `8'
5  888b d'888 .ooooo. 888 888 .ooooo. 8 `88b. 8 .oooo.
6  8 Y88. .P 888 d88' `88b 888 888 d88' `88b 8 `88b. 8 `P )88b
7  8 `888' 888 888 888 888 888 888ooo888 8 `88b.8 .oP"888
8  8 Y 888 888 888 888 d88' 888 .o 8 `888 d8( 888
9  o8o o888o `Y8bod8P' o888bood8P' `Y8bod8P' o8o `8 `Y888""8o
10 
11 Copyright
12  2014-2016 MoDeNa Consortium, All rights reserved.
13 
14 License
15  This file is part of Modena.
16 
17  Modena is free software; you can redistribute it and/or modify it under
18  the terms of the GNU General Public License as published by the Free
19  Software Foundation, either version 3 of the License, or (at your option)
20  any later version.
21 
22  Modena is distributed in the hope that it will be useful, but WITHOUT ANY
23  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24  FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  for more details.
26 
27  You should have received a copy of the GNU General Public License along
28  with Modena. If not, see <http://www.gnu.org/licenses/>.
29 
30 Description
31  Solving the two tank problem the fully integrated way.
32 
33 Authors
34  Henrik Rusche
35 
36 Contributors
37 */
38 
39 #include <stdio.h>
40 #include <math.h>
41 #include <iostream>
42 
43 using namespace std;
44 
45 double flowRate
46 (
47  const double D,
48  const double rho0,
49  const double p0,
50  const double p2
51 )
52 {
53  // from VDI Waermeatlas Lbd 4
54  const double kappa = 1.4;
55 
56  const double etac = pow(2.0/(kappa+1.0), kappa/(kappa-1.0));
57 
58  double p1 = etac*p0;
59  if(p2 > p1)
60  {
61  p1 = p2;
62  }
63 
64  // for a nozzle
65  const double Cd0 = 0.84;
66  const double Cd1 = 0.66;
67  // Not 100% sure this is correct - eqn. (10) in Lbd 5 uses misleading
68  // nomenclature
69  const double Cdg =
70  Cd0 - Cd1*pow(p1/p0, 2.0) + (2*Cd1-Cd0)*pow(p1/p0, 3.0);
71 
72  const double Phi =
73  sqrt
74  (
75  kappa/(kappa-1.0)
76  *(pow(p1/p0, 2.0/kappa) - pow(p1/p0, (kappa+1.0)/kappa))
77  );
78 
79  return M_PI*pow(D, 2.0)*Cdg*Phi*sqrt(2.0*rho0*p0);
80 }
81 
82 
83 int
84 main (int argc, char *argv[])
85 {
86  const double D = 0.01;
87 
88  double p0 = 3e5;
89  double p1 = 10000;
90  double V0 = 0.1;
91  double V1 = 1;
92  double T = 300;
93 
94  double t = 0.0;
95  const double deltat = 1e-3;
96  const double tend = 5.5;
97 
98  double m0 = p0*V0/287.1/T;
99  double m1 = p1*V1/287.1/T;
100 
101  double rho0 = m0/V0;
102 
103  while(t + deltat < tend + 1e-10)
104  {
105  t += deltat;
106 
107  if(p0 > p1)
108  {
109  double mdot = flowRate(D, rho0, p0, p1);
110  m0 -= mdot*deltat;
111  m1 += mdot*deltat;
112  }
113  else
114  {
115  double mdot = flowRate(D, rho0, p1, p0);
116  m0 += mdot*deltat;
117  m1 -= mdot*deltat;
118  }
119 
120  rho0 = m0/V0;
121  p0 = m0/V0*287.1*T;
122  p1 = m1/V1*287.1*T;
123 
124  cout << "t = " << t << " p0 = " << p0 << " p1 = " << p1 << endl;
125  }
126 
127  return 0;
128 }
int main(int argc, char *argv[])
Reads parameters. Creates struts and walls. Saves foam morphology to a file.
Definition: foams.cc:23
double tend
end time, s