Memosa-FVM  0.2
LinearizeInterfaceJump.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 _LINEARIZEINTERFACEJUMP_H_
6 #define _LINEARIZEINTERFACEJUMP_H_
7 
8 #include "Mesh.h"
9 #include "NumType.h"
10 #include "Array.h"
11 #include "Vector.h"
12 #include "Field.h"
13 #include "CRConnectivity.h"
14 #include "StorageSite.h"
15 #include "MultiFieldMatrix.h"
16 #include "CRMatrix.h"
17 #include "FluxJacobianMatrix.h"
18 #include "DiagonalMatrix.h"
19 
20 
21 
22 
23 template<class X, class Diag, class OffDiag>
25 {
26  public:
29  typedef typename CCMatrix::DiagArray DiagArray;
31  typedef Array<X> XArray;
35 
36 
38  const X B_coeff,
39  Field& varField):
40  _varField(varField),
41  _A_coeff(A_coeff),
42  _B_coeff(B_coeff)
43  {}
44 
45 
46  void discretize(const Mesh& mesh, const Mesh& parentMesh,
47  const Mesh& otherMesh, MultiFieldMatrix& mfmatrix,
48  MultiField& xField, MultiField& rField)
49  {
50  const StorageSite& cells = mesh.getCells();
51  const StorageSite& faces = mesh.getParentFaceGroupSite();
52  const MultiField::ArrayIndex cVarIndex(&_varField,&cells);
53 
54  CCMatrix& matrix = dynamic_cast<CCMatrix&>(mfmatrix.getMatrix(cVarIndex,cVarIndex));
55 
56  const XArray& xCell = dynamic_cast<const XArray&>(xField[cVarIndex]);
57 
58  const CRConnectivity& cellCells = mesh.getCellCells();
59 
60  XArray& rCell = dynamic_cast<XArray&>(rField[cVarIndex]);
61 
62  DiagArray& diag = matrix.getDiag();
63 
64  // In the following, parent is assumed to be on the left, and
65  // the other mesh is assumed to be on the right when implimenting
66  // the (Phi_R = A*Phi_L + B) equation
67 
68  // parent mesh info
69  const CRConnectivity& parentFaceCells = parentMesh.getFaceCells(faces);
70  const StorageSite& parentCells = parentMesh.getCells();
71  const MultiField::ArrayIndex cVarIndexParent(&_varField,&parentCells);
72  XArray& rParentCell = dynamic_cast<XArray&>(rField[cVarIndexParent]);
73  CCMatrix& parentmatrix = dynamic_cast<CCMatrix&>(mfmatrix.getMatrix(cVarIndexParent,cVarIndexParent));
74  DiagArray& parentdiag = parentmatrix.getDiag();
75 
76  // other mesh info
77  const StorageSite& otherFaces = mesh.getOtherFaceGroupSite();
78  const CRConnectivity& otherFaceCells = otherMesh.getFaceCells(otherFaces);
79  const StorageSite& otherCells = otherMesh.getCells();
80  const MultiField::ArrayIndex cVarIndexOther(&_varField,&otherCells);
81  XArray& rOtherCell = dynamic_cast<XArray&>(rField[cVarIndexOther]);
82  CCMatrix& othermatrix = dynamic_cast<CCMatrix&>(mfmatrix.getMatrix(cVarIndexOther,cVarIndexOther));
83  DiagArray& otherdiag = othermatrix.getDiag();
84 
85  for (int f=0; f<faces.getCount(); f++)
86  {
87  //get parent mesh fluxes and coeffs
88  int c0p = parentFaceCells(f,0);
89  int c1p = parentFaceCells(f,1);
90  if (c1p < parentCells.getSelfCount())
91  {
92  // c0 is ghost cell and c1 is boundry cell, so swap cell numbers
93  // so that c1p refers to the ghost cell in the following
94  int temp = c0p;
95  c0p = c1p;
96  c1p = temp;
97  }
98 
99  const X leftFlux = rParentCell[c1p]; // inward shell flux on the left
100  const OffDiag dRC0dXC3 = parentmatrix.getCoeff(c1p, c0p);
101  const Diag dRC0dXC0 = parentdiag[c1p];
102 
103  //get other mesh fluxes and coeffs
104  int c0o = otherFaceCells(f,0);
105  int c1o = otherFaceCells(f,1);
106  if (c1o < otherCells.getSelfCount())
107  {
108  // c0 is ghost cell and c1 is boundry cell, so swap cell numbers
109  // so that c1o refers to the ghost cell in the following
110  int temp = c0o;
111  c0o = c1o;
112  c1o = temp;
113  }
114 
115  const X rightFlux = rOtherCell[c1o]; // inward shell flux on the right
116  const OffDiag dRC0dXC2 = othermatrix.getCoeff(c1o, c0o);
117  const OffDiag dRC0dXC1 = otherdiag[c1o];
118 
119 
120  //now put flux information from meshes into shell cells
121  const int c0 = f;
122  const int c1 = cellCells(f,0);
123  const int c2 = cellCells(f,1);
124  const int c3 = cellCells(f,2);
125 
126  // left shell cell - 3 neighbors
127  OffDiag& offdiagC0_C1 = matrix.getCoeff(c0, c1);
128  OffDiag& offdiagC0_C2 = matrix.getCoeff(c0, c2);
129  OffDiag& offdiagC0_C3 = matrix.getCoeff(c0, c3);
130 
131  rCell[c0] = rightFlux + leftFlux;
132  offdiagC0_C1 = dRC0dXC1;
133  offdiagC0_C3 = dRC0dXC3;
134  offdiagC0_C2 = dRC0dXC2;
135  diag[c0] = dRC0dXC0;
136 
137  // right shell cell - 1 neighbor
138  OffDiag& offdiagC1_C0 = matrix.getCoeff(c1, c0);
139 
140  rCell[c1] = _A_coeff*xCell[c0] + _B_coeff - xCell[c1];
143 
144  // set other coeffs to zero for right shell cell
145  OffDiag& offdiagC1_C2 = matrix.getCoeff(c1, c2);
146  OffDiag& offdiagC1_C3 = matrix.getCoeff(c1, c3);
147  offdiagC1_C2 = NumTypeTraits<OffDiag>::getZero();
148  offdiagC1_C3 = NumTypeTraits<OffDiag>::getZero();
149 
150  if (c0==0)
151  {
152  cout << xCell[c0] << " " << xCell[c1] << " " << xCell[c2] << " " << xCell[c3] << endl;
153  }
154 
155  }
156 
157  }
158 private:
159 
162  const X _B_coeff;
163 
164 };
165 
166 #endif
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
int getSelfCount() const
Definition: StorageSite.h:40
const StorageSite & getParentFaceGroupSite() const
Definition: Mesh.h:329
LinearizeInterfaceJump(const T_Scalar A_coeff, const X B_coeff, Field &varField)
Definition: Field.h:14
OffDiag & getCoeff(const int i, const int j)
Definition: CRMatrix.h:836
Array< VectorT3 > VectorT3Array
CCMatrix::DiagArray DiagArray
Definition: Mesh.h:49
Array< Diag > & getDiag()
Definition: CRMatrix.h:856
const StorageSite & getOtherFaceGroupSite() const
Definition: Mesh.h:332
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
CRMatrix< Diag, OffDiag, X > CCMatrix
const CRConnectivity & getCellCells() const
Definition: Mesh.cpp:480
const StorageSite & getCells() const
Definition: Mesh.h:109
Vector< T_Scalar, 3 > VectorT3
SquareTensor< T_Scalar, 2 > SquareTensorT2
const CRConnectivity & getFaceCells(const StorageSite &site) const
Definition: Mesh.cpp:388
NumTypeTraits< X >::T_Scalar T_Scalar
int getCount() const
Definition: StorageSite.h:39
void discretize(const Mesh &mesh, const Mesh &parentMesh, const Mesh &otherMesh, MultiFieldMatrix &mfmatrix, MultiField &xField, MultiField &rField)