Memosa-FVM  0.2
PhononConvectionDiscretization.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 #ifndef _PHONONCONVECTIONDISCRETIZATION_H_
6 #define _PHONONCONVECTIONDISCRETIZATION_H_
7 
8 #include "CRMatrix.h"
9 #include "Field.h"
10 #include "MultiField.h"
11 #include "MultiFieldMatrix.h"
12 #include "Mesh.h"
13 #include "Discretization.h"
14 #include "StorageSite.h"
15 #include "Gradient.h"
16 
17 template<class X, class Diag, class OffDiag>
19 {
20 public:
22 
24  typedef typename CCMatrix::DiagArray DiagArray;
26 
27  typedef Gradient<X> XGrad;
28 
30  typedef Array<X> XArray;
34 
36 
38  const GeomFields& geomFields,
39  Field& varField,
40  const VectorT3 groupvel,
41  const bool useCentralDifference=false) :
42 
43  Discretization(meshes),
44  _geomFields(geomFields),
45  _varField(varField),
46  _groupvel(groupvel),
47  _useCentralDifference(useCentralDifference)
48  {}
49 
50  void discretize(const Mesh& mesh, MultiFieldMatrix& mfmatrix,
51  MultiField& xField, MultiField& rField)
52  {
53 
54  const StorageSite& cells = mesh.getCells();
55  const StorageSite& faces = mesh.getFaces();
56 
57 
58  // should there be some other checks ?
59  //if (!_convectingFluxField.hasArray(faces))
60 
61 
62  const MultiField::ArrayIndex cVarIndex(&_varField,&cells);
63  CCMatrix& matrix =
64  dynamic_cast<CCMatrix&>(mfmatrix.getMatrix(cVarIndex,cVarIndex));
65 
66  const CRConnectivity& faceCells = mesh.getAllFaceCells();
67 
68  CCAssembler& assembler = matrix.getPairWiseAssembler(faceCells);
69  DiagArray& diag = matrix.getDiag();
70 
71  const XArray& xCell = dynamic_cast<const XArray&>(xField[cVarIndex]);
72  XArray& rCell = dynamic_cast<XArray&>(rField[cVarIndex]);
73 
74  //const GradArray& xGradCell = dynamic_cast<GradArray>(_varGradientField[cells]);
75 
76  const IntArray& ibType = dynamic_cast<const IntArray&>(_geomFields.ibType[cells]);
77 
78  const int nFaces = faces.getCount();
79 
80  const VectorT3Array& faceArea = dynamic_cast<const VectorT3Array&>(_geomFields.area[faces]);
81 
82  if (_geomFields.gridFlux.hasArray(faces))
83  {
84  shared_ptr<TArray> gridFluxPtr(new TArray(nFaces));
85  TArray& gridFlux = *gridFluxPtr;
86  gridFlux = dynamic_cast<const TArray&>(_geomFields.gridFlux[faces]);
87 
88  for(int f=0; f<nFaces; f++)
89  {
90  const int c0 = faceCells(f,0);
91  const int c1 = faceCells(f,1);
92  //const T_Scalar faceCFlux = convectingFlux[f] - gridFlux[f];
93  const T_Scalar faceCFlux = faceArea[f][0]*_groupvel[0]
94  +faceArea[f][1]*_groupvel[1]+faceArea[f][2]*_groupvel[2] - gridFlux[f];
95 
96  X varFlux;
97  if (faceCFlux > T_Scalar(0))
98  {
99  varFlux = faceCFlux*xCell[c0];
100  diag[c0] -= faceCFlux;
101  assembler.getCoeff10(f) += faceCFlux;
102  }
103  else
104  {
105  varFlux = faceCFlux*xCell[c1];
106  diag[c1] += faceCFlux;
107  assembler.getCoeff01(f)-= faceCFlux;
108  }
109 
110  rCell[c0] -= varFlux;
111  rCell[c1] += varFlux;
112  }
113  }
114  else
115  {
117  for(int f=0; f<nFaces; f++)
118  {
119  const int c0 = faceCells(f,0);
120  const int c1 = faceCells(f,1);
121  const T_Scalar faceCFlux = faceArea[f][0]*_groupvel[0]
122  +faceArea[f][1]*_groupvel[1]+faceArea[f][2]*_groupvel[2];
123 
124  bool isIBFace = (((ibType[c0] == Mesh::IBTYPE_FLUID)
125  && (ibType[c1] == Mesh::IBTYPE_BOUNDARY)) ||
126  ((ibType[c1] == Mesh::IBTYPE_FLUID)
127  && (ibType[c0] == Mesh::IBTYPE_BOUNDARY)));
128 
129 
130  X varFlux =0.5*faceCFlux*(xCell[c0] + xCell[c0]);
131 
132  rCell[c0] -= varFlux;
133  rCell[c1] += varFlux;
134 
135  if (isIBFace)
136  {
137  // linearize the actual flux as calculated
138  // above. this will ensure that the Ib
139  // discretization will be able to fix the value
140  // correctly using the ib face value
141 
142  diag[c0] -= 0.5*faceCFlux;
143  assembler.getCoeff10(f) -= 0.5*faceCFlux;
144  diag[c1] += 0.5*faceCFlux;
145  assembler.getCoeff01(f) += 0.5*faceCFlux;
146  }
147  else
148  {
149  // linearize as upwind flux so that linear system
150  // remains diagonally dominant
151  if (faceCFlux > T_Scalar(0))
152  {
153  diag[c0] -= faceCFlux;
154  assembler.getCoeff10(f) += faceCFlux;
155  }
156  else
157  {
158  diag[c1] += faceCFlux;
159  assembler.getCoeff01(f)-= faceCFlux;
160  }
161  }
162  }
163  }
164  else
165  for(int f=0; f<nFaces; f++)
166  {
167  const int c0 = faceCells(f,0);
168  const int c1 = faceCells(f,1);
169 
170  const T_Scalar faceCFlux = faceArea[f][0]*_groupvel[0]
171  +faceArea[f][1]*_groupvel[1]+faceArea[f][2]*_groupvel[2];
172 
173  X varFlux;
174 
175  if (faceCFlux > T_Scalar(0))
176  {
177  varFlux = faceCFlux*xCell[c0];
178  diag[c0] -= faceCFlux;
179  assembler.getCoeff10(f) += faceCFlux;
180  }
181  else
182  {
183  varFlux = faceCFlux*xCell[c1];
184  diag[c1] += faceCFlux;
185  assembler.getCoeff01(f)-= faceCFlux;
186  }
187 
188  rCell[c0] -= varFlux;
189  rCell[c1] += varFlux;
190  }
191  }
192 
193  //const int nCells = cells.getSelfCount();
194  //for(int c=0;c<nCells;c++)
195  //{
196  // const T_Scalar cImb = continuityResidual[c];
197  // diag[c] += cImb;
198  //}
199 
200  }
201 private:
203  const Field& _varField;
206 };
207 
208 #endif
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
bool hasArray(const StorageSite &s) const
Definition: Field.cpp:37
PhononConvectionDiscretization(const MeshList &meshes, const GeomFields &geomFields, Field &varField, const VectorT3 groupvel, const bool useCentralDifference=false)
Definition: Field.h:14
Definition: Mesh.h:49
OffDiag & getCoeff10(const int np)
Definition: CRMatrix.h:131
Field gridFlux
Definition: GeomFields.h:31
Array< Diag > & getDiag()
Definition: CRMatrix.h:856
void discretize(const Mesh &mesh, MultiFieldMatrix &mfmatrix, MultiField &xField, MultiField &rField)
Field ibType
Definition: GeomFields.h:38
const CRConnectivity & getAllFaceCells() const
Definition: Mesh.cpp:378
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
const StorageSite & getFaces() const
Definition: Mesh.h:108
const StorageSite & getCells() const
Definition: Mesh.h:109
OffDiag & getCoeff01(const int np)
Definition: CRMatrix.h:126
int getCount() const
Definition: StorageSite.h:39
Field area
Definition: GeomFields.h:23
PairWiseAssembler & getPairWiseAssembler(const CRConnectivity &pairs)
Definition: CRMatrix.h:867
vector< Mesh * > MeshList
Definition: Mesh.h:439