Memosa-FVM  0.2
GenericKineticBCS.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 _GENERICKINETICBCS_H_
6 #define _GENERICKINETICBCS_H_
7 
8 #include "Mesh.h"
9 
10 #include "NumType.h"
11 #include "Array.h"
12 #include "Vector.h"
13 #include "Field.h"
14 #include "CRConnectivity.h"
15 #include "StorageSite.h"
16 #include "MultiFieldMatrix.h"
17 #include "CRMatrix.h"
18 #include "FluxJacobianMatrix.h"
19 #include "DiagonalMatrix.h"
20 
21 template<class X, class Diag, class OffDiag>
23 {
24 public:
25 
27 
30 
32 
35 
38 
41 
42  typedef Array<X> XArray;
44 
45 
47  const Mesh& mesh,
48  const GeomFields& geomFields,
49  Field& varField,
50  // Field& fluxField,
51  MultiFieldMatrix& matrix,
52  MultiField& xField, MultiField& rField) :
53  _faces(faces),
54  _cells(mesh.getCells()),
55  _ibType(dynamic_cast<const IntArray&>(geomFields.ibType[_cells])),
56  _faceCells(mesh.getFaceCells(_faces)),
57  _varField(varField),
58  //_fluxField(fluxField),
60  // _fluxIndex(&_fluxField,&_faces),
61  _dRdX(dynamic_cast<CCMatrix&>(matrix.getMatrix(_xIndex,_xIndex))),
62  //_dFluxdX(dynamic_cast<FMatrix&>(matrix.getMatrix(_fluxIndex,_xIndex))),
63  //_dFluxdFlux(dynamic_cast<BBMatrix&>(matrix.getMatrix(_fluxIndex,_fluxIndex))),
64  _assembler(_dRdX.getPairWiseAssembler(_faceCells)),
65  _dRdXDiag(_dRdX.getDiag()),
66  _x(dynamic_cast<XArray&>(xField[_xIndex])),
67  _r(dynamic_cast<XArray&>(rField[_xIndex])),
68  // _flux(dynamic_cast<XArray&>(xField[_fluxIndex])),
69  // _rFlux(dynamic_cast<XArray&>(rField[_fluxIndex])),
70  _areaMagField(geomFields.areaMag),
71  _faceAreaMag(dynamic_cast<const TArray&>(_areaMagField[_faces])),
72  _areaField(geomFields.area),
73  _faceArea(dynamic_cast<const VectorT3Array&>(_areaField[_faces]))
74  {}
75 
76  void applyDirichletBC(int f, const X& bValue) const
77  {
78  const int c0 = _faceCells(f,0);
79  const int c1 = _faceCells(f,1);
80 
81  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
82  return;
83 
84  // the current value of flux and its Jacobians
85  // const X fluxB = -_r[c1];
86  //const OffDiag dFluxdXC0 = -_assembler.getCoeff10(f);
87  // const Diag dFluxdXC1 = -_dRdXDiag[c1];
88  const OffDiag dRC0dXC1 = _assembler.getCoeff01(f);
89 
90  // since we know the boundary value, compute the boundary
91  // x correction and it's contribution to the residual for c0; we
92  // can then eliminate the coefficient to the boundary cell
93 
94  const X dXC1 = bValue - _x[c1];
95  // const X dFlux = dFluxdXC1*dXC1;
96  const X dRC0 = dRC0dXC1*dXC1;
97  _r[c0] += dRC0;
98 
100 
101  // set the boundary value and make its correction equation an
102  // identity
103  _x[c1] = bValue;
107 
108  /*
109  //setup the equation for the boundary flux correction
110  _dFluxdX.setCoeffL(f,dFluxdXC0);
111  _dFluxdX.setCoeffR(f,NumTypeTraits<OffDiag>::getZero());
112  _flux[f] = fluxB;
113  _rFlux[f] = dFlux;
114  _dFluxdFlux[f] = NumTypeTraits<Diag>::getNegativeUnity();
115  */
116  }
117 
118  void applyDirichletBC(const X& bValue) const
119  {
120  for(int i=0; i<_faces.getCount(); i++)
121  applyDirichletBC(i,bValue);
122  }
123 
124  void applyDirichletBC(const FloatValEvaluator<X>& bValue) const
125  {
126  for(int i=0; i<_faces.getCount(); i++)
127  applyDirichletBC(i,bValue[i]);
128  }
129 
130 
131  void applyExtrapolationBC() const
132  {
133  for(int i=0; i<_faces.getCount(); i++)
135  }
136 
137  // boundary value = cell value, flux as defined by interior discretization
138 
139  void applyExtrapolationBC(const int f) const
140  {
141  const int c0 = _faceCells(f,0);
142  const int c1 = _faceCells(f,1);
143 
144  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
145  return;
146 
147  // the current value of flux and its Jacobians
148  //const X fluxB = -_r[c1];
149  // const OffDiag dFluxdXC0 = -_assembler.getCoeff10(f);
150  const Diag dFluxdXC1 = -_dRdXDiag[c1];
151 
152  const X xc0mxc1 = _x[c0]-_x[c1];
153 
154  // eliminate boundary dependency from cell equation
155  _dRdXDiag[c0] += dFluxdXC1;
156  _r[c0] += dFluxdXC1*xc0mxc1;
157  _assembler.getCoeff01(f) = 0;
158 
159  // boundary value equation
162  _r[c1] = xc0mxc1;
163  _dRdX.setBoundary(c1);
164 
165  /*
166  //setup the equation for the boundary flux correction
167  _dFluxdX.setCoeffL(f,dFluxdXC0);
168  _dFluxdX.setCoeffR(f,dFluxdXC0); // should really be dFluxdXC1
169  _flux[f] = fluxB;
170  _rFlux[f] = T_Scalar(0);
171  _dFluxdFlux[f] = NumTypeTraits<Diag>::getNegativeUnity();
172  */
173  }
174 
175  void applyInterfaceBC(const int f) const
176  {
177  // the boundary cell could be either c0 or c1 at an interface
178  int cb = _faceCells(f,1);
180  if (cb < _cells.getSelfCount())
181  {
182  cb = _faceCells(f,0);
183  sign *= -1.0;
184  }
185 
186 
187  // the current value of flux and its Jacobians
188  // const X fluxInterior = -_r[cb];
189  //const OffDiag dFluxdXC0 = -sign*_assembler.getCoeff10(f);
190  //const OffDiag dFluxdXC1 = sign*_assembler.getCoeff01(f);
191 
192 
193  _r[cb] = T_Scalar(0);
194 
195  if (sign>0)
197  else
199 
200  //setup the equation for the boundary flux correction
201  /*
202  _dFluxdX.setCoeffL(f,dFluxdXC0);
203  _dFluxdX.setCoeffR(f,dFluxdXC1);
204  _flux[f] = fluxInterior;
205  _rFlux[f] = T_Scalar(0);
206  _dFluxdFlux[f] = NumTypeTraits<Diag>::getNegativeUnity();
207  */
208  }
209  void applyInterfaceBC() const
210  {
211  for(int i=0; i<_faces.getCount(); i++)
212  applyInterfaceBC(i);
213  }
214 
215  void applyFlowBC(const TArray& convFlux, const X& bValue) const
216  {
217  for(int f=0; f<_faces.getCount(); f++)
218  if (convFlux[f] < 0)
219  applyDirichletBC(f,bValue);
220  else
222  }
223 
224  void applyNonzeroDiagBC() const
225  {
226  for(int i=0; i<_faces.getCount(); i++)
228  }
229 
230  void applyNonzeroDiagBC(int f) const
231  {
232  const int c0 = _faceCells(f,0);
233  const int c1 = _faceCells(f,1);
234 
235  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
236  return;
237 
238  _dRdXDiag[c1][0] = T_Scalar(-1.0);
239  }
240 
241 
242 protected:
247  const Field& _varField;
248  // const Field& _fluxField;
250 // const MultiField::ArrayIndex _fluxIndex;
252  // FMatrix& _dFluxdX;
253  //BBMatrix& _dFluxdFlux;
258  // XArray& _flux;
259  // XArray& _rFlux;
264 };
265 
266 #endif
267 
void applyDirichletBC(const FloatValEvaluator< X > &bValue) const
int getSelfCount() const
Definition: StorageSite.h:40
void applyDirichletBC(const X &bValue) const
void applyDirichletBC(int f, const X &bValue) const
Vector< T_Scalar, 3 > VectorT3
Array< T_Scalar > TArray
void applyInterfaceBC(const int f) const
Definition: Field.h:14
void applyExtrapolationBC() const
Definition: Mesh.h:49
OffDiag & getCoeff10(const int np)
Definition: CRMatrix.h:131
void applyNonzeroDiagBC(int f) const
const VectorT3Array & _faceArea
NumTypeTraits< X >::T_Scalar T_Scalar
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
const IntArray & _ibType
CRMatrix< Diag, OffDiag, X > CCMatrix
const StorageSite & _faces
BaseGenericKineticBCS(const StorageSite &faces, const Mesh &mesh, const GeomFields &geomFields, Field &varField, MultiFieldMatrix &matrix, MultiField &xField, MultiField &rField)
const MultiField::ArrayIndex _xIndex
void applyNonzeroDiagBC() const
OffDiag & getCoeff01(const int np)
Definition: CRMatrix.h:126
const StorageSite & _cells
CCMatrix::PairWiseAssembler CCAssembler
Definition: Array.h:14
void applyFlowBC(const TArray &convFlux, const X &bValue) const
void setBoundary(const int nr)
Definition: CRMatrix.h:1056
Array< OffDiag > OffDiagArray
int getCount() const
Definition: StorageSite.h:39
DiagonalMatrix< Diag, X > BBMatrix
const CRConnectivity & _faceCells
void applyInterfaceBC() const
FluxJacobianMatrix< Diag, X > FMatrix
const TArray & _faceAreaMag
Array< VectorT3 > VectorT3Array
void applyExtrapolationBC(const int f) const