Memosa-FVM  0.2
LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag > Class Template Reference

#include <LinearizeInterfaceJumpUnconnected.h>

Collaboration diagram for LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >:

Public Types

typedef NumTypeTraits< X >
::T_Scalar 
T_Scalar
 
typedef CRMatrix< Diag,
OffDiag, X > 
CCMatrix
 
typedef CCMatrix::DiagArray DiagArray
 
typedef Array< T_ScalarTArray
 
typedef Array< X > XArray
 
typedef Vector< T_Scalar, 3 > VectorT3
 
typedef Array< VectorT3VectorT3Array
 
typedef SquareTensor< T_Scalar, 2 > SquareTensorT2
 

Public Member Functions

 LinearizeInterfaceJumpUnconnected (const T_Scalar A_coeff, const X B_coeff, Field &varField)
 
void discretize (const Mesh &mesh, const Mesh &parentMesh, const Mesh &otherMesh, MultiFieldMatrix &mfmatrix, MultiField &xField, MultiField &rField, LinearSystem &lsShell)
 

Private Attributes

Field_varField
 
const T_Scalar _A_coeff
 
const X _B_coeff
 

Detailed Description

template<class X, class Diag, class OffDiag>
class LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >

Definition at line 24 of file LinearizeInterfaceJumpUnconnected.h.

Member Typedef Documentation

template<class X, class Diag, class OffDiag>
typedef CRMatrix<Diag,OffDiag,X> LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::CCMatrix

Definition at line 28 of file LinearizeInterfaceJumpUnconnected.h.

template<class X, class Diag, class OffDiag>
typedef CCMatrix::DiagArray LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::DiagArray

Definition at line 29 of file LinearizeInterfaceJumpUnconnected.h.

template<class X, class Diag, class OffDiag>
typedef SquareTensor<T_Scalar,2> LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::SquareTensorT2

Definition at line 34 of file LinearizeInterfaceJumpUnconnected.h.

template<class X, class Diag, class OffDiag>
typedef NumTypeTraits<X>::T_Scalar LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::T_Scalar

Definition at line 27 of file LinearizeInterfaceJumpUnconnected.h.

template<class X, class Diag, class OffDiag>
typedef Array<T_Scalar> LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::TArray

Definition at line 30 of file LinearizeInterfaceJumpUnconnected.h.

template<class X, class Diag, class OffDiag>
typedef Vector<T_Scalar,3> LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::VectorT3

Definition at line 32 of file LinearizeInterfaceJumpUnconnected.h.

template<class X, class Diag, class OffDiag>
typedef Array<VectorT3> LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::VectorT3Array

Definition at line 33 of file LinearizeInterfaceJumpUnconnected.h.

template<class X, class Diag, class OffDiag>
typedef Array<X> LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::XArray

Definition at line 31 of file LinearizeInterfaceJumpUnconnected.h.

Constructor & Destructor Documentation

template<class X, class Diag, class OffDiag>
LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::LinearizeInterfaceJumpUnconnected ( const T_Scalar  A_coeff,
const X  B_coeff,
Field varField 
)
inline

Member Function Documentation

template<class X, class Diag, class OffDiag>
void LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::discretize ( const Mesh mesh,
const Mesh parentMesh,
const Mesh otherMesh,
MultiFieldMatrix mfmatrix,
MultiField xField,
MultiField rField,
LinearSystem lsShell 
)
inline

Definition at line 46 of file LinearizeInterfaceJumpUnconnected.h.

References LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::_A_coeff, LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::_B_coeff, LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::_varField, LinearSystem::getB(), Mesh::getCellCells(), Mesh::getCells(), CRMatrix< T_Diag, T_OffDiag, X >::getCoeff(), StorageSite::getCount(), CRMatrix< T_Diag, T_OffDiag, X >::getDiag(), Mesh::getFaceCells(), LinearSystem::getMatrix(), MultiFieldMatrix::getMatrix(), Mesh::getOtherFaceGroupSite(), Mesh::getParentFaceGroupSite(), StorageSite::getSelfCount(), and LinearSystem::getX().

Referenced by BatteryModel< T >::Impl::linearizeSpecies().

49  {
50  cout << "LINERIZEINTERFACEJUMPUNCONNECTED" << endl;
51 
52  const StorageSite& cells = mesh.getCells();
53  const StorageSite& faces = mesh.getParentFaceGroupSite();
54  const CRConnectivity& cellCells = mesh.getCellCells();
55  XArray& varCell = dynamic_cast<XArray&>(_varField[cells]);
56 
57  //lsShell info
58  const MultiField::ArrayIndex cVarIndex(&_varField,&cells);
59  CCMatrix& matrix = dynamic_cast<CCMatrix&>((lsShell.getMatrix()).getMatrix(cVarIndex,cVarIndex));
60  const XArray& xCell = dynamic_cast<const XArray&>((lsShell.getX())[cVarIndex]);
61  XArray& rCell = dynamic_cast<XArray&>((lsShell.getB())[cVarIndex]);
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  const XArray& varCellParent = dynamic_cast<const XArray&>(_varField[parentCells]);
76 
77 
78  // other mesh info
79  const StorageSite& otherFaces = mesh.getOtherFaceGroupSite();
80  const CRConnectivity& otherFaceCells = otherMesh.getFaceCells(otherFaces);
81  const StorageSite& otherCells = otherMesh.getCells();
82  const MultiField::ArrayIndex cVarIndexOther(&_varField,&otherCells);
83  XArray& rOtherCell = dynamic_cast<XArray&>(rField[cVarIndexOther]);
84  CCMatrix& othermatrix = dynamic_cast<CCMatrix&>(mfmatrix.getMatrix(cVarIndexOther,cVarIndexOther));
85  DiagArray& otherdiag = othermatrix.getDiag();
86  const XArray& varCellOther = dynamic_cast<const XArray&>(_varField[otherCells]);
87 
88 
89  for (int f=0; f<faces.getCount(); f++)
90  {
91  //get parent mesh fluxes and coeffs
92  int c0p = parentFaceCells(f,0);
93  int c1p = parentFaceCells(f,1);
94  if (c1p < parentCells.getSelfCount())
95  {
96  // c0 is ghost cell and c1 is boundry cell, so swap cell numbers
97  // so that c1p refers to the ghost cell in the following
98  int temp = c0p;
99  c0p = c1p;
100  c1p = temp;
101  }
102 
103  const X leftFlux = rParentCell[c1p]; // inward shell flux on the left
104  const OffDiag dRC0dXC3 = parentmatrix.getCoeff(c1p, c0p);
105  const Diag dRC0dXC0 = parentdiag[c1p];
106 
107  //get other mesh fluxes and coeffs
108  int c0o = otherFaceCells(f,0);
109  int c1o = otherFaceCells(f,1);
110  if (c1o < otherCells.getSelfCount())
111  {
112  // c0 is ghost cell and c1 is boundry cell, so swap cell numbers
113  // so that c1o refers to the ghost cell in the following
114  int temp = c0o;
115  c0o = c1o;
116  c1o = temp;
117  }
118 
119  const X rightFlux = rOtherCell[c1o]; // inward shell flux on the right
120  const OffDiag dRC0dXC2 = othermatrix.getCoeff(c1o, c0o);
121  const OffDiag dRC0dXC1 = otherdiag[c1o];
122 
123  //now put flux information from meshes into shell cells
124  const int c0 = f;
125  const int c1 = cellCells(f,0);
126  const int c2 = cellCells(f,1);
127  const int c3 = cellCells(f,2);
128 
129  // copy sln varialbe values from interior cells of meshes to ghost cells of shell mesh
130  varCell[c3] = varCellParent[c0p];
131  varCell[c2] = varCellOther[c0o];
132 
133  // calculate residuals and jacobian values for R_1 equation
134  const X r0 = -1*(rightFlux + leftFlux);
135  const X r1 = -1*(_A_coeff*varCell[c0] + _B_coeff - varCell[c1]);
136  const OffDiag dRC1dXC2 = NumTypeTraits<OffDiag>::getZero();
137  const Diag dRC1dXC1 = NumTypeTraits<Diag>::getNegativeUnity();
138  const OffDiag dRC1dXC3 = NumTypeTraits<OffDiag>::getZero();
139  const OffDiag dRC1dXC0 = _A_coeff*NumTypeTraits<OffDiag>::getUnity();
140 
141  // set variables to match hand written derivation for ease of coding
142  const OffDiag A = dRC1dXC0; // A_coeff // 1
143  const Diag B = dRC1dXC1; // -1
144  const OffDiag C = dRC1dXC2; // 0
145  const OffDiag D = dRC1dXC3; // 0
146  const X E = _B_coeff; // 0
147  const Diag F = dRC0dXC0;
148  const OffDiag G = dRC0dXC1;
149  const OffDiag H = dRC0dXC2;
150  const OffDiag J = dRC0dXC3;
151  const X K = NumTypeTraits<X>::getZero(); // 0
152 
153  // manipulate parent matrix R and coeffs to incorporate above
154  OffDiag& offDiagParentC0_C1 = parentmatrix.getCoeff(c0p, c1p);
155  Diag& diagParentC0 = parentdiag[c0p];
156  X& parentR0 = rParentCell[c0p];
157 
158  if (f==0)
159  {
160  cout << "orignialParentOffDiag " << offDiagParentC0_C1 << endl;
161  cout << "originalDiagparent" << diagParentC0 << endl;
162  }
163  const OffDiag originalParentOffDiag = offDiagParentC0_C1;
164  offDiagParentC0_C1 = originalParentOffDiag*(B*H-G*C)/(A*G-B*F);
165  diagParentC0 += originalParentOffDiag*(B*J-D*G)/(A*G-B*F);
166  //parentR0 += originalParentOffDiag*(G*r1 - B*r0 + B*K - E*G)/(A*G-B*F);
167  parentR0 += originalParentOffDiag*(G*r1 - B*r0)/(A*G-B*F);
168  if (f==0)
169  {
170  cout << A << " " << B << " " << C << " " << D << " " << E << " " << F << " " << G << " " << H << " " << J << " " << K << " " << originalParentOffDiag << " " << r0 << " " << r1 << endl;
171  cout << (B*H-G*C) << " " << (B*J-D*G) << " " << (A*G-B*F) << endl;
172  cout << offDiagParentC0_C1 << " " << diagParentC0 << endl;
173  }
174 
175  // manipulate other matrix R and coeffs to incorporate above
176  OffDiag& offDiagOtherC0_C1 = othermatrix.getCoeff(c0o, c1o);
177  Diag& diagOtherC0 = otherdiag[c0o];
178  X& otherR0 = rOtherCell[c0o];
179 
180  const OffDiag originalOtherOffDiag = offDiagOtherC0_C1;
181  offDiagOtherC0_C1 = originalOtherOffDiag*(D*F-A*J)/(A*G-B*F);
182  diagOtherC0 += originalOtherOffDiag*(C*F-A*H)/(A*G-B*F);
183  //otherR0 += originalOtherOffDiag*(A*r0 - F*r1 + E*F - A*K)/(A*G-B*F);
184  otherR0 += originalOtherOffDiag*(A*r0 - F*r1)/(A*G-B*F);
185 
186  //editing ghost cells (not sure if I need to, seems not to matter as expected)
187  // but makes looking for differences easier, so keep for now.
188  // should also affect interface flux calculation
189  //parent
190 
191  OffDiag& offDiagParentC1_C0 = parentmatrix.getCoeff(c1p, c0p);
192  Diag& diagParentC1 = parentdiag[c1p];
193  X& parentR1 = rParentCell[c1p];
194 
195  const Diag originalParentDiagC1 = diagParentC1;//offDiagParentC0_C1;
196  offDiagParentC1_C0 += diagParentC1*(B*J-D*G)/(A*G-B*F);
197  diagParentC1 *= (B*H-G*C)/(A*G-B*F);
198  parentR1 += originalParentDiagC1*(G*r1 - B*r0)/(A*G-B*F);
199 
200  //other
201  OffDiag& offDiagOtherC1_C0 = othermatrix.getCoeff(c1o, c0o);
202  Diag& diagOtherC1 = otherdiag[c1o];
203  X& otherR1 = rOtherCell[c1o];
204 
205  const Diag originalOtherDiagC1 = diagOtherC1; //offDiagOtherC0_C1;
206  offDiagOtherC1_C0 += diagOtherC1*(C*F-A*H)/(A*G-B*F);
207  diagOtherC1 *= (D*F-A*J)/(A*G-B*F);
208  otherR1 += originalOtherDiagC1*(A*r0 - F*r1)/(A*G-B*F);
209 
210 
211 
212 
213  //now put flux information from meshes into shell cells
214  // left shell cell
215  OffDiag& offdiagC0_C1 = matrix.getCoeff(c0, c1);
216  OffDiag& offdiagC0_C2 = matrix.getCoeff(c0, c2);
217  OffDiag& offdiagC0_C3 = matrix.getCoeff(c0, c3);
218 
219  rCell[c0] = -r0;
220  offdiagC0_C1 = dRC0dXC1;
221  offdiagC0_C3 = dRC0dXC3;
222  offdiagC0_C2 = dRC0dXC2;
223  diag[c0] = dRC0dXC0;
224 
225  // right shell cell
226  OffDiag& offdiagC1_C0 = matrix.getCoeff(c1, c0);
227  OffDiag& offdiagC1_C2 = matrix.getCoeff(c1, c2);
228  OffDiag& offdiagC1_C3 = matrix.getCoeff(c1, c3);
229 
230  rCell[c1] = -r1;
231  offdiagC1_C0 = dRC1dXC0;
232  offdiagC1_C2 = dRC1dXC2;
233  offdiagC1_C3 = dRC1dXC3;
234  diag[c1] = dRC1dXC1;
235 
236  if (c0==0)
237  {
238  cout << xCell[c0] << " " << xCell[c1] << " " << xCell[c2] << " " << xCell[c3] << endl;
239  }
240 
241  }
242 
243  }
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
int getSelfCount() const
Definition: StorageSite.h:40
const StorageSite & getParentFaceGroupSite() const
Definition: Mesh.h:329
const StorageSite & getOtherFaceGroupSite() const
Definition: Mesh.h:332
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
const CRConnectivity & getCellCells() const
Definition: Mesh.cpp:480
const StorageSite & getCells() const
Definition: Mesh.h:109
const CRConnectivity & getFaceCells(const StorageSite &site) const
Definition: Mesh.cpp:388
int getCount() const
Definition: StorageSite.h:39
MultiField & getB()
Definition: LinearSystem.h:33
MultiField & getX()
Definition: LinearSystem.h:32
MultiFieldMatrix & getMatrix()
Definition: LinearSystem.h:37

Member Data Documentation

template<class X, class Diag, class OffDiag>
const T_Scalar LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::_A_coeff
private
template<class X, class Diag, class OffDiag>
const X LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::_B_coeff
private
template<class X, class Diag, class OffDiag>
Field& LinearizeInterfaceJumpUnconnected< X, Diag, OffDiag >::_varField
private

The documentation for this class was generated from the following file: