Memosa-FVM  0.2
IdealGasDensityModel_impl.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #include "Mesh.h"
6 
7 #include "NumType.h"
8 #include "Array.h"
9 #include "Field.h"
10 #include "StorageSite.h"
11 
12 template<class T>
14 {
15 public:
16  typedef Array<T> TArray;
17 
18  Impl(const GeomFields& geomFields,
19  FlowFields& flowFields,
20  const MeshList& meshes) :
21  _meshes(meshes),
22  _geomFields(geomFields),
23  _flowFields(flowFields)
24  {
25  const int numMeshes = _meshes.size();
26  for (int n=0; n<numMeshes; n++)
27  {
28  const Mesh& mesh = *_meshes[n];
29 
30  IdealGasVC<T> *vc(new IdealGasVC<T>());
31  _vcMap[mesh.getID()] = vc;
32  }
33  }
34 
35  VCMap& getVCMap() {return _vcMap;}
36 
37  void init() { advance(1,true); }
38 
39  bool advance(const int niter, bool init = false)
40  {
41  const int numMeshes = _meshes.size();
42  for (int n=0; n<numMeshes; n++)
43  {
44  const Mesh& mesh = *_meshes[n];
45 
46  const IdealGasVC<T>& vc = *_vcMap[mesh.getID()];
47 
48  const StorageSite& cells = mesh.getCells();
49 
50  TArray& density = dynamic_cast<TArray&>(_flowFields.density[cells]);
51 
52  FloatValEvaluator<T> cellP(vc.getVal("pressure"),cells);
53  FloatValEvaluator<T> cellT(vc.getVal("temperature"),cells);
54 
55  const T operatingPressure = vc["operatingPressure"];
56  const T molWt = vc["molecularWeight"];
57 
58  const T Rgas = 8314.472/molWt;
59  const int nCells = cells.getCount();
60 
61  const T pMin(1000);
62  const T TMin(1);
63  const T urf = init ? T(1) : T(vc["urf"]);
64 
65  for(int c=0; c<nCells; c++)
66  {
67  T absP = (cellP[c] + operatingPressure);
68  T temp = cellT[c];
69  if (absP < pMin) absP = pMin;
70  if (temp < TMin) temp = TMin;
71 
72  if (init)
73  density[c] = absP/(Rgas*temp);
74  else
75  density[c] = urf*absP/(Rgas*temp) + (1.0-urf)*density[c];
76  }
77  }
78  return true;
79  }
80 
81 
82 private:
86 
88 };
89 
90 template<class T>
92  FlowFields& flowFields,
93  const MeshList& meshes) :
94  Model(meshes),
95  _impl(new Impl(geomFields,flowFields,meshes))
96 {
97  logCtor();
98 }
99 
100 
101 template<class T>
103 {
104  logDtor();
105 }
106 
107 template<class T>
108 void
110 {
111  _impl->init();
112 }
113 
114 template<class T>
116 IdealGasDensityModel<T>::getVCMap() {return _impl->getVCMap();}
117 
118 
119 template<class T>
120 bool
122 {
123  return _impl->advance(niter);
124 }
125 
std::map< int, IdealGasVC< T > * > VCMap
Definition: Mesh.h:49
#define logCtor()
Definition: RLogInterface.h:26
FloatVal< T > getVal(const string varName) const
Definition: FloatVarDict.h:85
const MeshList _meshes
Definition: Model.h:29
Definition: Model.h:13
const StorageSite & getCells() const
Definition: Mesh.h:109
Impl(const GeomFields &geomFields, FlowFields &flowFields, const MeshList &meshes)
#define logDtor()
Definition: RLogInterface.h:33
Definition: Array.h:14
int getCount() const
Definition: StorageSite.h:39
bool advance(const int niter, bool init=false)
IdealGasDensityModel(const GeomFields &geomFields, FlowFields &thermalFields, const MeshList &meshes)
int getID() const
Definition: Mesh.h:106
bool advance(const int niter)
vector< Mesh * > MeshList
Definition: Mesh.h:439