Memosa-FVM  0.2
BatteryPCTimeDerivativeDiscretization.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 
6 #ifndef _BATTERYPCTIMEDERIVATIVEDISCRETIZATION_H_
7 #define _BATTERYPCTIMEDERIVATIVEDISCRETIZATION_H_
8 
9 #include "CRMatrix.h"
10 #include "Field.h"
11 #include "MultiField.h"
12 #include "MultiFieldMatrix.h"
13 #include "Mesh.h"
14 #include "Discretization.h"
15 #include "StorageSite.h"
16 
17 template<class X, class Diag, class OffDiag>
19 {
20 public:
22 
24  typedef typename CCMatrix::DiagArray DiagArray;
26 
27  typedef Array<X> XArray;
30 
32  const GeomFields& geomFields,
33  Field& varField,
34  Field& varN1Field,
35  Field& varN2Field,
36  Field& rhoCpField,
37  const bool thermalModel,
38  const T_Scalar dT) :
39  Discretization(meshes),
40  _geomFields(geomFields),
41  _varField(varField),
42  _varN1Field(varN1Field),
43  _varN2Field(varN2Field),
44  _rhoCpField(rhoCpField),
45  _thermalModel(thermalModel),
46  _dT(dT)
47  {}
48 
49  void discretize(const Mesh& mesh, MultiFieldMatrix& mfmatrix,
50  MultiField& xField, MultiField& rField)
51  {
52 
53  const StorageSite& cells = mesh.getCells();
54 
55  const TArray& cellVolume =
56  dynamic_cast<const TArray&>(_geomFields.volume[cells]);
57 
58  const TArray& rhoCp = dynamic_cast<const TArray&>(_rhoCpField[cells]);
59 
60  const MultiField::ArrayIndex cVarIndex(&_varField,&cells);
61  CCMatrix& matrix =
62  dynamic_cast<CCMatrix&>(mfmatrix.getMatrix(cVarIndex,cVarIndex));
63 
64  DiagArray& diag = matrix.getDiag();
65 
66  const XArray& x = dynamic_cast<const XArray&>(_varField[cells]);
67  const XArray& xN1 = dynamic_cast<const XArray&>(_varN1Field[cells]);
68 
69  XArray& rCell = dynamic_cast<XArray&>(rField[cVarIndex]);
70 
71  const int nCells = cells.getSelfCount();
72 
73  if (_varN2Field.hasArray(cells))
74  {
75 
76  // second order
77  const XArray& xN2 = dynamic_cast<const XArray&>(_varN2Field[cells]);
78 
79  T_Scalar onePointFive(1.5);
80  T_Scalar two(2.0);
81  T_Scalar pointFive(0.5);
82 
83  if (_geomFields.volumeN1.hasArray(cells))
84  {
85  //Moving Mesh
86  /*const TArray& cellVolumeN1 =
87  dynamic_cast<const TArray&>(_geomFields.volumeN1[cells]);
88  const TArray& cellVolumeN2 =
89  dynamic_cast<const TArray&>(_geomFields.volumeN2[cells]);
90  for(int c=0; c<nCells; c++)
91  {
92  const T_Scalar rhoVbydT = density[c]*cellVolume[c]/_dT;
93  const T_Scalar rhobydT = density[c]/_dT;
94  const T_Scalar term1 = onePointFive*cellVolume[c];
95  const T_Scalar term2 = two*cellVolumeN1[c];
96  const T_Scalar term3 = pointFive*cellVolumeN2[c];
97  rCell[c] -= rhobydT*(term1*x[c]- term2*xN1[c]
98  + term3*xN2[c]);
99  diag[c] -= rhoVbydT*onePointFive;
100  }*/
101  }
102  else
103  {
104 
105  for(int c=0; c<nCells; c++)
106  {
107  const T_Scalar rhoVbydT_species = cellVolume[c]/_dT;
108  (rCell[c])[1] -= rhoVbydT_species*(onePointFive*(x[c])[1] - two*(xN1[c])[1] + pointFive*(xN2[c])[1]);
109  (diag[c])[1] -= rhoVbydT_species*onePointFive;
110 
111  if (_thermalModel)
112  {
113  const T_Scalar rhoVbydT_temp = rhoCp[c]*cellVolume[c]/_dT;
114  (rCell[c])[2] -= rhoVbydT_temp*(onePointFive*(x[c])[2] - two*(xN1[c])[2] + pointFive*(xN2[c])[2]);
115  (diag[c])[2] -= rhoVbydT_temp*onePointFive;
116  }
117  }
118  }
119  }
120  else
121  {
122  if (_geomFields.volumeN1.hasArray(cells))
123  {
124  //Moving Mesh
125  /*
126  const TArray& cellVolumeN1 =
127  dynamic_cast<const TArray&>(_geomFields.volumeN1[cells]);
128  for(int c=0; c<nCells; c++)
129  {
130  const T_Scalar rhoVbydT = density[c]*cellVolume[c]/_dT;
131  const T_Scalar rhobydT = density[c]/_dT;
132  rCell[c] -= rhobydT*(cellVolume[c]*x[c]
133  - cellVolumeN1[c]*xN1[c]);
134 
135  diag[c] -= rhoVbydT;
136 
137  }*/
138  }
139  else if (_geomFields.ibTypeN1.hasArray(cells))
140  {
141  //IBM
142  /*
143 
144  const IntArray& ibTypeN1 =
145  dynamic_cast<const IntArray&>(_geomFields.ibTypeN1[cells]);
146  const IntArray& ibType =
147  dynamic_cast<const IntArray&>(_geomFields.ibType[cells]);
148  for(int c=0; c<nCells; c++)
149  {
150  const T_Scalar rhoVbydT = density[c]*cellVolume[c]/_dT;
151 
152  if (ibTypeN1[c] == Mesh::IBTYPE_FLUID &&
153  (ibType[c] == Mesh::IBTYPE_FLUID))
154  rCell[c] -= rhoVbydT*(x[c] - xN1[c]);
155  else if (ibType[c] == Mesh::IBTYPE_FLUID)
156  rCell[c] -= rhoVbydT*(x[c] );
157  diag[c] -= rhoVbydT;
158  }*/
159  }
160  else
161  {
162  // only apply unsteady terms for species equation and temp, not potential
163  // first order
164  for(int c=0; c<nCells; c++)
165  {
166  const T_Scalar rhoVbydT_species = cellVolume[c]/_dT;
167  (rCell[c])[1] -= rhoVbydT_species*((x[c])[1]- (xN1[c])[1]);
168  (diag[c])[1] -= rhoVbydT_species;
169 
170  if (_thermalModel)
171  {
172  const T_Scalar rhoVbydT_temp = rhoCp[c]*cellVolume[c]/_dT;
173  (rCell[c])[2] -= rhoVbydT_temp*((x[c])[2]- (xN1[c])[2]);
174  (diag[c])[2] -= rhoVbydT_temp;
175  }
176  }
177 
178  }
179  }
180 
181  }
182 
183 
184 
185 private:
187  const Field& _varField;
191  const bool _thermalModel;
192  const T_Scalar _dT;
193 };
194 
195 #endif
Field ibTypeN1
Definition: GeomFields.h:39
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
int getSelfCount() const
Definition: StorageSite.h:40
bool hasArray(const StorageSite &s) const
Definition: Field.cpp:37
Definition: Field.h:14
BatteryPCTimeDerivativeDiscretization(const MeshList &meshes, const GeomFields &geomFields, Field &varField, Field &varN1Field, Field &varN2Field, Field &rhoCpField, const bool thermalModel, const T_Scalar dT)
Definition: Mesh.h:49
Array< Diag > & getDiag()
Definition: CRMatrix.h:856
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
void discretize(const Mesh &mesh, MultiFieldMatrix &mfmatrix, MultiField &xField, MultiField &rField)
Field volumeN1
Definition: GeomFields.h:27
const StorageSite & getCells() const
Definition: Mesh.h:109
Field volume
Definition: GeomFields.h:26
vector< Mesh * > MeshList
Definition: Mesh.h:439