MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
flowRateExact.C
Go to the documentation of this file.
1 
45 #include <stdio.h>
46 #include <math.h>
47 #include <iostream>
48 #include <fstream>
49 
50 using namespace std;
51 
52 
53 double flowRate
54 (
55  const double D,
56  const double rho0,
57  const double p0,
58  const double p2Byp0
59 )
60 {
61  const double p2 = p0*p2Byp0;
62  const double kappa = 1.4;
63 
64  const double etac = pow(2.0/(kappa+1.0), kappa/(kappa-1.0));
65 
66  double p1 = etac*p0;
67  if(p2 > p1)
68  {
69  p1 = p2;
70  }
71 
72  // for a nozzle
73  const double Cd0 = 0.84;
74  const double Cd1 = 0.66;
75  // Not 100% sure this is correct - eqn. (10) in Lbd 5 uses misleading
76  // nomenclature
77  const double Cdg =
78  Cd0 - Cd1*pow(p1/p0, 2.0) + (2*Cd1-Cd0)*pow(p1/p0, 3.0);
79 
80  const double Phi =
81  sqrt
82  (
83  kappa/(kappa-1.0)
84  *(pow(p1/p0, 2.0/kappa) - pow(p1/p0, (kappa+1.0)/kappa))
85  );
86 
87  return M_PI*pow(D, 2.0)*Cdg*Phi*sqrt(2.0*rho0*p0);
88 }
89 
90 
91 int
92 main (int argc, char *argv[])
93 {
94  ifstream fi;
95  fi.open ("in.txt");
96  if(!fi.is_open())
97  {
98  cerr << "Could not open in.txt!" << endl;
99  return 1;
100  }
101 
102  double D, rho0, p0, p1Byp0;
103  fi >> D >> rho0 >> p0 >> p1Byp0;
104 
105  double mdot = flowRate(D, rho0, p0, p1Byp0);
106 
107  double p1 = p0*p1Byp0;
108 
109  cout << "D = " << D
110  << " rho0 = " << rho0
111  << " p0 = " << p0
112  << " p1/p0 = " << p1Byp0
113  << " p1 = " << p1
114  << " mdot = " << mdot
115  << endl;
116 
117  ofstream fo;
118  fo.open ("out.txt");
119 
120  fo << mdot << endl;
121 
122  fi.close();
123  fo.close();
124 }
125 
int main(int argc, char *argv[])
Reads parameters. Creates struts and walls. Saves foam morphology to a file.
Definition: foams.cc:23