Memosa-FVM  0.2
MomentumPressureGradientDiscretization.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 _MOMENTUMPRESSUREGRADIENTDISCRETIZATION_H_
6 #define _MOMENTUMPRESSUREGRADIENTDISCRETIZATION_H_
7 
8 #include "Field.h"
9 #include "MultiField.h"
10 #include "MultiFieldMatrix.h"
11 #include "Mesh.h"
12 #include "Discretization.h"
13 #include "StorageSite.h"
14 #include "GeomFields.h"
15 #include "FlowFields.h"
16 #include "DiagonalMatrix.h"
17 #include "Gradient.h"
18 #include "GradientMatrix.h"
19 #ifdef PV_COUPLED
20 #include "CRMatrixRect.h"
21 #endif
22 
23 #include "GradientModel.h"
24 
25 template<class X>
27 {
28 public:
29 
31 
33 
34  typedef Gradient<X> XGrad;
36  typedef typename GradMatrix::Coord VPCoeff;
37 
38  typedef Array<X> XArray;
42 
44 
45 #ifdef PV_COUPLED
46  typedef CRMatrixRect<VPCoeff,X,VectorT3> VPMatrix;
47 #endif
48 
50  const GeomFields& geomFields,
51  FlowFields& flowFields,
52  GradientModel<X>& pressureGradientModel) :
53  Discretization(meshes),
54  _geomFields(geomFields),
55  _flowFields(flowFields),
56  _pressureGradientModel(pressureGradientModel)
57  {}
58 
59 
60  void discretize(const Mesh& mesh, MultiFieldMatrix& mfmatrix,
61  MultiField&, MultiField& rField)
62  {
63  const StorageSite& cells = mesh.getCells();
64 
65  const TArray& cellVolume = dynamic_cast<const TArray&>(_geomFields.volume[cells]);
66 
67  const MultiField::ArrayIndex vIndex(&_flowFields.velocity,&cells);
68  VectorT3Array& rCell = dynamic_cast<VectorT3Array&>(rField[vIndex]);
69  GradArray& pGradCell = dynamic_cast<GradArray&>(_flowFields.pressureGradient[cells]);
70 
71  const int nCells = cells.getSelfCount();
72 
73 
74  const StorageSite& faces = mesh.getFaces();
75  const CRConnectivity& faceCells = mesh.getAllFaceCells();
76  const VectorT3Array& faceArea =
77  dynamic_cast<const VectorT3Array&>(_geomFields.area[faces]);
78  const TArray& facePressure = dynamic_cast<const TArray&>(_flowFields.pressure[faces]);
79 
80  pGradCell.zero();
81 
82  const int nFaces = faces.getCount();
83  for(int f=0; f<nFaces; f++)
84  {
85  const int c0 = faceCells(f,0);
86  const int c1 = faceCells(f,1);
87  pGradCell[c0].accumulate(faceArea[f],facePressure[f]);
88  pGradCell[c1].accumulate(faceArea[f],-facePressure[f]);
89  }
90 
91  for(int c=0; c<nCells; c++)
92  pGradCell[c] /= cellVolume[c];
93 
94  // copy boundary values from adjacent cells
95  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
96  {
97  const FaceGroup& fg = *fgPtr;
98  const StorageSite& faces = fg.site;
99  const CRConnectivity& faceCells = mesh.getFaceCells(faces);
100  const int faceCount = faces.getCount();
101 
102  if (fg.groupType == "symmetry")
103  {
104  const VectorT3Array& faceArea =
105  dynamic_cast<const VectorT3Array&>(_geomFields.area[faces]);
106  const TArray& faceAreaMag =
107  dynamic_cast<const TArray&>(_geomFields.areaMag[faces]);
108  for(int f=0; f<faceCount; f++)
109  {
110  const int c0 = faceCells(f,0);
111  const int c1 = faceCells(f,1);
112  const VectorT3 en = faceArea[f]/faceAreaMag[f];
113  reflectGradient(pGradCell[c1], pGradCell[c0], en);
114  }
115  }
116  else
117  {
118  for(int f=0; f<faceCount; f++)
119  {
120  const int c0 = faceCells(f,0);
121  const int c1 = faceCells(f,1);
122 
123  pGradCell[c1] = pGradCell[c0];
124  }
125  }
126  }
127 
128 
129  for(int c=0; c<nCells; c++)
130  {
131  rCell[c][0] -= cellVolume[c]*pGradCell[c][0];
132  rCell[c][1] -= cellVolume[c]*pGradCell[c][1];
133  rCell[c][2] -= cellVolume[c]*pGradCell[c][2];
134 
135  }
136 
137 
138 #ifdef PV_COUPLED
139  const MultiField::ArrayIndex pIndex(&_flowFields.pressure,&cells);
140  if (mfmatrix.hasMatrix(vIndex,pIndex))
141  {
142  VPMatrix& vpMatrix =
143  dynamic_cast<VPMatrix&>(mfmatrix.getMatrix(vIndex,pIndex));
144 
145  const GradientMatrix<X>& gradMatrix =
146  _pressureGradientModel.getGradientMatrix(mesh, _geomFields);
147 
148  const Array<VPCoeff>& gradMatrixCoeffs = gradMatrix.getCoeffs();
149  Array<VPCoeff>& vpDiag = vpMatrix.getDiag();
150  Array<VPCoeff>& vpOffDiag = vpMatrix.getOffDiag();
151 
152  const CRConnectivity& conn = vpMatrix.getConnectivity();
153  const Array<int>& row = conn.getRow();
154 
155  // all of this assumes that the connectivity of the gradient
156  // matrix and vp matrix is the same
157  for(int c=0; c<nCells; c++)
158  {
159  for(int nnb=row[c]; nnb<row[c+1]; nnb++)
160  {
161  const VPCoeff& coeff = gradMatrixCoeffs[nnb];
162  vpDiag[c] += coeff*cellVolume[c];
163  vpOffDiag[nnb] -= coeff*cellVolume[c];
164  }
165  }
166  }
167 #endif
168  }
169 
170 private:
174 };
175 
176 #endif
const FaceGroupList & getBoundaryFaceGroups() const
Definition: Mesh.h:187
Field pressure
Definition: FlowFields.h:16
virtual void zero()
Definition: Array.h:281
const Array< int > & getRow() const
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
shared_ptr< FaceGroup > FaceGroupPtr
Definition: Mesh.h:46
int getSelfCount() const
Definition: StorageSite.h:40
Definition: Mesh.h:28
void reflectGradient(Gradient< T > &gr, const Gradient< T > &g0, const Vector< T, 3 > &en)
Definition: GradientModel.h:23
bool hasMatrix(const Index &rowIndex, const Index &colIndex) const
Definition: Mesh.h:49
MomentumPressureGradientDiscretization(const MeshList &meshes, const GeomFields &geomFields, FlowFields &flowFields, GradientModel< X > &pressureGradientModel)
string groupType
Definition: Mesh.h:42
const CRConnectivity & getAllFaceCells() const
Definition: Mesh.cpp:378
Array< Coord > & getCoeffs()
Field pressureGradient
Definition: FlowFields.h:19
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
Field volume
Definition: GeomFields.h:26
void discretize(const Mesh &mesh, MultiFieldMatrix &mfmatrix, MultiField &, MultiField &rField)
const CRConnectivity & getFaceCells(const StorageSite &site) const
Definition: Mesh.cpp:388
int getCount() const
Definition: StorageSite.h:39
Field area
Definition: GeomFields.h:23
Field areaMag
Definition: GeomFields.h:25
vector< Mesh * > MeshList
Definition: Mesh.h:439
Field velocity
Definition: FlowFields.h:15
StorageSite site
Definition: Mesh.h:40