Memosa-FVM  0.2
TimeDerivativePlateDiscretization.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 _TIMEDERIVATIVEPLATEDISCRETIZATION_H_
7 #define _TIMEDERIVATIVEPLATEDISCRETIZATION_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;
29 
30 
32  const GeomFields& geomFields,
33  Field& varField,
34  Field& varN1Field,
35  Field& varN2Field,
36  Field& varN3Field,
37  const Field& densityField,
38  const Field& thicknessField,
39  Field& accelerationField,
40  const Field& volume0Field,
41  const bool& variableTimeStep,
42  const T_Scalar dT,
43  const T_Scalar dTN1,
44  const T_Scalar dTN2) :
45  Discretization(meshes),
46  _geomFields(geomFields),
47  _varField(varField),
48  _varN1Field(varN1Field),
49  _varN2Field(varN2Field),
50  _varN3Field(varN3Field),
51  _densityField(densityField),
52  _thicknessField(thicknessField),
53  _accelerationField(accelerationField),
54  _volume0Field(volume0Field),
55  _variableTimeStep(variableTimeStep),
56  _dT(dT),
57  _dTN1(dTN1),
58  _dTN2(dTN2)
59  {}
60 
61  void discretize(const Mesh& mesh, MultiFieldMatrix& mfmatrix,
62  MultiField& xField, MultiField& rField)
63  {
64 
65  const StorageSite& cells = mesh.getCells();
66 
67  const TArray& density =
68  dynamic_cast<const TArray&>(_densityField[cells]);
69 
70  const TArray& thickness =
71  dynamic_cast<const TArray&>(_thicknessField[cells]);
72 
73  //const TArray& cellVolume =
74  // dynamic_cast<const TArray&>(_geomFields.volume[cells]);
75 
76  const TArray& cellVolume0 =
77  dynamic_cast<const TArray&>(_volume0Field[cells]);
78 
79  const MultiField::ArrayIndex cVarIndex(&_varField,&cells);
80  CCMatrix& matrix =
81  dynamic_cast<CCMatrix&>(mfmatrix.getMatrix(cVarIndex,cVarIndex));
82 
83  DiagArray& diag = matrix.getDiag();
84 
85  const XArray& x = dynamic_cast<const XArray&>(_varField[cells]);
86  const XArray& xN1 = dynamic_cast<const XArray&>(_varN1Field[cells]);
87 
88  XArray& rCell = dynamic_cast<XArray&>(rField[cVarIndex]);
89 
90  TArray& acceleration =
91  dynamic_cast<TArray&>(_accelerationField[cells]);
92 
93  const int nCells = cells.getSelfCount();
94 
95 
96  // second order
97  const XArray& xN2 = dynamic_cast<const XArray&>(_varN2Field[cells]);
98 
99  T_Scalar two(2.0);
100  T_Scalar three(3.0);
101  T_Scalar twelve(12.0);
102  const T_Scalar _dT2 = _dT*_dT;
103 
104  if(!_variableTimeStep)
105  {
106  if (_varN3Field.hasArray(cells))
107  {
108  const XArray& xN3 = dynamic_cast<const XArray&>(_varN3Field[cells]);
109  T_Scalar five(5.0);
110  T_Scalar four(4.0);
111  for(int c=0; c<nCells; c++)
112  {
113  const T_Scalar rhoVHbydT2 = density[c]*cellVolume0[c]*thickness[c]/_dT2;
114  const T_Scalar rhobydT2 = density[c]/_dT2;
115  const T_Scalar rhoVH3by12dT2 = density[c]*cellVolume0[c]*
116  pow(thickness[c],three)/(twelve*_dT2);
117  rCell[c][0] += rhoVH3by12dT2*(two*x[c][0] - five*xN1[c][0] + four*xN2[c][0]
118  - xN3[c][0]);
119  (diag[c])(0,0) += two*rhoVH3by12dT2;
120  rCell[c][1] += rhoVH3by12dT2*(two*x[c][1] - five*xN1[c][1] + four*xN2[c][1]
121  - xN3[c][1]);
122  (diag[c])(1,1) += two*rhoVH3by12dT2;
123  rCell[c][2] += rhoVHbydT2*(two*x[c][2] - five*xN1[c][2] + four*xN2[c][2]
124  - xN3[c][2]);
125  (diag[c])(2,2) += two*rhoVHbydT2;
126  //acceleration[c] = rhobydT2*(two*x[c][2] - five*xN1[c][2] + four*xN2[c][2]
127  // - xN3[c][2]);
128  }
129  }
130  else
131  {
132  for(int c=0; c<nCells; c++)
133  {
134  const T_Scalar rhoVHbydT2 = density[c]*cellVolume0[c]*thickness[c]/_dT2;
135  const T_Scalar rhobydT2 = density[c]/_dT2;
136  const T_Scalar rhoVH3by12dT2 = density[c]*cellVolume0[c]*
137  pow(thickness[c],three)/(twelve*_dT2);
138 
139  rCell[c][0] += rhoVH3by12dT2*(x[c][0]- two*xN1[c][0]
140  + xN2[c][0]);
141  (diag[c])(0,0) += rhoVH3by12dT2;
142  rCell[c][1] += rhoVH3by12dT2*(x[c][1]- two*xN1[c][1]
143  + xN2[c][1]);
144  (diag[c])(1,1) += rhoVH3by12dT2;
145 
146  rCell[c][2] += rhoVHbydT2*(x[c][2]- two*xN1[c][2]
147  + xN2[c][2]);
148  (diag[c])(2,2) += rhoVHbydT2;
149  //acceleration[c] = rhobydT2*(x[c][2]- two*xN1[c][2]
150  // + xN2[c][2]);
151  }
152  }
153  }
154  else
155  {
156  T_Scalar a = (_dT + _dTN1)/_dT;
157  T_Scalar b = (_dT + _dTN1 + _dTN2)/_dT;
158  T_Scalar one(1.0);
159  if (_varN3Field.hasArray(cells))
160  {
161  T_Scalar c1 = (two*a*b*(pow(a,two)-pow(b,two))+two*b*(pow(b,two)-one)-two*a*(pow(a,two)-one))/
162  (a*b*(a-one)*(b-one)*(a-b));
163  T_Scalar c2 = -two*(a+b)/((a-1)*(b-1));
164  T_Scalar c3 = -two*(b+one)/(a*(a-b)*(a-one));
165  T_Scalar c4 = two*(a+one)/(b*(a-b)*(b-one));
166  const XArray& xN3 = dynamic_cast<const XArray&>(_varN3Field[cells]);
167  for(int c=0; c<nCells; c++)
168  {
169  const T_Scalar rhoVHbydT2 = density[c]*cellVolume0[c]*thickness[c]/_dT2;
170  const T_Scalar rhobydT2 = density[c]/_dT2;
171  const T_Scalar rhoVH3by12dT2 = density[c]*cellVolume0[c]*
172  pow(thickness[c],three)/(twelve*_dT2);
173  rCell[c][0] += rhoVH3by12dT2*(c1*x[c][0] + c2*xN1[c][0] + c3*xN2[c][0]
174  + c4*xN3[c][0]);
175  (diag[c])(0,0) += c1*rhoVH3by12dT2;
176  rCell[c][1] += rhoVH3by12dT2*(c1*x[c][1] + c2*xN1[c][1] + c3*xN2[c][1]
177  + c4*xN3[c][1]);
178  (diag[c])(1,1) += c1*rhoVH3by12dT2;
179  rCell[c][2] += rhoVHbydT2*(c1*x[c][2] + c2*xN1[c][2] + c3*xN2[c][2]
180  + c4*xN3[c][2]);
181  (diag[c])(2,2) += c1*rhoVHbydT2;
182  //acceleration[c] = rhobydT2*(c1*x[c][2] + c2*xN1[c][2] + c3*xN2[c][2]
183  // + c4*xN3[c][2]);
184  }
185  }
186  else
187  {
188  T_Scalar c1 = two/a;
189  T_Scalar c2 = -two/(a-one);
190  T_Scalar c3 = two/(a*(a-one));
191  for(int c=0; c<nCells; c++)
192  {
193  const T_Scalar rhoVHbydT2 = density[c]*cellVolume0[c]*thickness[c]/_dT2;
194  const T_Scalar rhobydT2 = density[c]/_dT2;
195  const T_Scalar rhoVH3by12dT2 = density[c]*cellVolume0[c]*
196  pow(thickness[c],three)/(twelve*_dT2);
197 
198  rCell[c][0] += rhoVH3by12dT2*(c1*x[c][0] + c2*xN1[c][0]
199  + c3*xN2[c][0]);
200  (diag[c])(0,0) += c1*rhoVH3by12dT2;
201  rCell[c][1] += rhoVH3by12dT2*(c1*x[c][1] + c2*xN1[c][1]
202  + c3*xN2[c][1]);
203  (diag[c])(1,1) += c1*rhoVH3by12dT2;
204 
205  rCell[c][2] += rhoVHbydT2*(c1*x[c][2] + c2*xN1[c][2]
206  + c3*xN2[c][2]);
207  (diag[c])(2,2) += c1*rhoVHbydT2;
208  //acceleration[c] = rhobydT2*(c1*x[c][2] + c2*xN1[c][2]
209  // + c3*xN2[c][2]);
210  }
211  }
212  }
213  }
214 private:
216  const Field& _varField;
224  const bool _variableTimeStep;
225  const T_Scalar _dT;
228 };
229 
230 #endif
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
TimeDerivativePlateDiscretization(const MeshList &meshes, const GeomFields &geomFields, Field &varField, Field &varN1Field, Field &varN2Field, Field &varN3Field, const Field &densityField, const Field &thicknessField, Field &accelerationField, const Field &volume0Field, const bool &variableTimeStep, const T_Scalar dT, const T_Scalar dTN1, const T_Scalar dTN2)
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)
const StorageSite & getCells() const
Definition: Mesh.h:109
vector< Mesh * > MeshList
Definition: Mesh.h:439