MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
flowRateExact.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 for more
25  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  This code calculates the flowRate through a nozzle as a function of the
32  diameter, density and pressure upstream and pressure downstream. It uses
33  expressions from VDI Waermeatlas Lbd 4
34 
35  In the simple twoTank example, this piece of code stands for a complex
36  microscopic code - such as full 3D CFD simulation.
37 
38 Authors
39  Henrik Rusche
40 
41 Contributors
42 */
43 
44 #include <stdio.h>
45 #include <math.h>
46 #include <iostream>
47 #include <fstream>
48 
49 using namespace std;
50 
51 
52 double flowRate
53 (
54  const double D,
55  const double rho0,
56  const double p0,
57  const double p2Byp0
58 )
59 {
60  const double p2 = p0*p2Byp0;
61  const double kappa = 1.4;
62 
63  const double etac = pow(2.0/(kappa+1.0), kappa/(kappa-1.0));
64 
65  double p1 = etac*p0;
66  if(p2 > p1)
67  {
68  p1 = p2;
69  }
70 
71  // for a nozzle
72  const double Cd0 = 0.84;
73  const double Cd1 = 0.66;
74  // Not 100% sure this is correct - eqn. (10) in Lbd 5 uses misleading
75  // nomenclature
76  const double Cdg =
77  Cd0 - Cd1*pow(p1/p0, 2.0) + (2*Cd1-Cd0)*pow(p1/p0, 3.0);
78 
79  const double Phi =
80  sqrt
81  (
82  kappa/(kappa-1.0)
83  *(pow(p1/p0, 2.0/kappa) - pow(p1/p0, (kappa+1.0)/kappa))
84  );
85 
86  return M_PI*pow(D, 2.0)*Cdg*Phi*sqrt(2.0*rho0*p0);
87 }
88 
89 
90 int
91 main (int argc, char *argv[])
92 {
93  ifstream fi;
94  fi.open ("in.txt");
95  if(!fi.is_open())
96  {
97  cerr << "Could not open in.txt!" << endl;
98  return 1;
99  }
100 
101  double D, rho0, p0, p1Byp0;
102  fi >> D >> rho0 >> p0 >> p1Byp0;
103 
104  double mdot = flowRate(D, rho0, p0, p1Byp0);
105 
106  double p1 = p0*p1Byp0;
107 
108  cout << "D = " << D
109  << " rho0 = " << rho0
110  << " p0 = " << p0
111  << " p1/p0 = " << p1Byp0
112  << " p1 = " << p1
113  << " mdot = " << mdot
114  << endl;
115 
116  ofstream fo;
117  fo.open ("out.txt");
118 
119  fo << mdot << endl;
120 
121  fi.close();
122  fo.close();
123 }
124 
int main(int argc, char *argv[])
Reads parameters. Creates struts and walls. Saves foam morphology to a file.
Definition: foams.cc:23