Memosa-FVM  0.2
GenericPhononBCS.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 _GENERICPHONONBCS_H_
6 #define _GENERICPHONONBCS_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  MultiFieldMatrix& matrix,
51  MultiField& xField, MultiField& rField) :
52  _faces(faces),
53  _cells(mesh.getCells()),
54  _ibType(dynamic_cast<const IntArray&>(geomFields.ibType[_cells])),
55  _faceCells(mesh.getFaceCells(_faces)),
56  _varField(varField),
58  _dRdX(dynamic_cast<CCMatrix&>(matrix.getMatrix(_xIndex,_xIndex))),
59  _assembler(_dRdX.getPairWiseAssembler(_faceCells)),
60  _dRdXDiag(_dRdX.getDiag()),
61  _x(dynamic_cast<XArray&>(xField[_xIndex])),
62  _r(dynamic_cast<XArray&>(rField[_xIndex])),
63  _areaMagField(geomFields.areaMag),
64  _faceAreaMag(dynamic_cast<const TArray&>(_areaMagField[_faces])),
65  _areaField(geomFields.area),
66  _faceArea(dynamic_cast<const VectorT3Array&>(_areaField[_faces]))
67  {}
68 
69  void applyDirichletBC(int f, const X& bValue) const
70  {
71  const int c0 = _faceCells(f,0);
72  const int c1 = _faceCells(f,1);
73 
74  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
75  return;
76 
77  const OffDiag dRC0dXC1 = _assembler.getCoeff01(f);
78 
79  // since we know the boundary value, compute the boundary
80  // x correction and it's contribution to the residual for c0; we
81  // can then eliminate the coefficient to the boundary cell
82 
83  const X dXC1 = bValue - _x[c1];
84  const X dRC0 = dRC0dXC1*dXC1;
85  _r[c0] += dRC0;
86 
88 
89  // set the boundary value and make its correction equation an
90  // identity
91  _x[c1] = bValue;
95 
96  }
97 
98  void applyDirichletBC(const X& bValue) const
99  {
100  for(int i=0; i<_faces.getCount(); i++)
101  applyDirichletBC(i,bValue);
102  }
103 
104  void applyDirichletBC(const FloatValEvaluator<X>& bValue) const
105  {
106  for(int i=0; i<_faces.getCount(); i++)
107  applyDirichletBC(i,bValue[i]);
108  }
109 
110 
111  void applyExtrapolationBC() const
112  {
113  for(int i=0; i<_faces.getCount(); i++)
115  }
116 
117  // boundary value = cell value, flux as defined by interior discretization
118 
119  void applyExtrapolationBC(const int f) const
120  {
121  const int c0 = _faceCells(f,0);
122  const int c1 = _faceCells(f,1);
123 
124  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
125  return;
126 
127  // the current value of flux and its Jacobians
128  const Diag dFluxdXC1 = -_dRdXDiag[c1];
129 
130  const X xc0mxc1 = _x[c0]-_x[c1];
131 
132  // eliminate boundary dependency from cell equation
133  _dRdXDiag[c0] += dFluxdXC1;
134  _r[c0] += dFluxdXC1*xc0mxc1;
135  _assembler.getCoeff01(f) = 0;
136 
137  // boundary value equation
140  _r[c1] = xc0mxc1;
141  _dRdX.setBoundary(c1);
142 
143  }
144 
145 
146  void applyInterfaceBC() const
147  {
148  for(int i=0; i<_faces.getCount(); i++)
149  applyInterfaceBC(i);
150  }
151 
152  void applyFlowBC(const TArray& convFlux, const X& bValue) const
153  {
154  for(int f=0; f<_faces.getCount(); f++)
155  if (convFlux[f] < 0)
156  applyDirichletBC(f,bValue);
157  else
159  }
160 
161  void applyNonzeroDiagBC() const
162  {
163  for(int i=0; i<_faces.getCount(); i++)
165  }
166 
167  void applyNonzeroDiagBC(int f) const
168  {
169  const int c0 = _faceCells(f,0);
170  const int c1 = _faceCells(f,1);
171 
172  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
173  return;
174 
175  _dRdXDiag[c1][0] = T_Scalar(-1.0);
176  }
177 
178 
179 protected:
184  const Field& _varField;
195 };
196 
197 #endif
198 
const Field & _areaField
void applyInterfaceBC() const
NumTypeTraits< X >::T_Scalar T_Scalar
FluxJacobianMatrix< Diag, X > FMatrix
Definition: Field.h:14
DiagonalMatrix< Diag, X > BBMatrix
CCMatrix::PairWiseAssembler CCAssembler
void applyDirichletBC(const FloatValEvaluator< X > &bValue) const
Definition: Mesh.h:49
OffDiag & getCoeff10(const int np)
Definition: CRMatrix.h:131
const StorageSite & _faces
Array< T_Scalar > TArray
CCAssembler & _assembler
void applyDirichletBC(int f, const X &bValue) const
Array< VectorT3 > VectorT3Array
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
void applyExtrapolationBC() const
Vector< T_Scalar, 3 > VectorT3
void applyNonzeroDiagBC() const
const IntArray & _ibType
const VectorT3Array & _faceArea
const TArray & _faceAreaMag
OffDiag & getCoeff01(const int np)
Definition: CRMatrix.h:126
const Field & _areaMagField
Definition: Array.h:14
void setBoundary(const int nr)
Definition: CRMatrix.h:1056
void applyNonzeroDiagBC(int f) const
const StorageSite & _cells
void applyExtrapolationBC(const int f) const
const CRConnectivity & _faceCells
const MultiField::ArrayIndex _xIndex
int getCount() const
Definition: StorageSite.h:39
Array< OffDiag > OffDiagArray
void applyDirichletBC(const X &bValue) const
Array< Diag > DiagArray
CRMatrix< Diag, OffDiag, X > CCMatrix
void applyFlowBC(const TArray &convFlux, const X &bValue) const
BaseGenericPhononBCS(const StorageSite &faces, const Mesh &mesh, const GeomFields &geomFields, Field &varField, MultiFieldMatrix &matrix, MultiField &xField, MultiField &rField)