5 #ifndef _STRUCTURESOURCEDISCRETIZATION_H_
6 #define _STRUCTURESOURCEDISCRETIZATION_H_
20 template<
class T,
class Diag,
class OffDiag>
42 const Field& lambdaField,
43 const Field& alphaField,
44 const Field& varGradientField,
45 const Field& temperatureField,
46 const T& referenceTemperature,
47 const T& residualXXStress,
48 const T& residualYYStress,
49 const T& residualZZStress,
51 const bool& residualStress,
52 bool fullLinearization=
true) :
104 const bool isBoundary,
const bool isSymmetry)
113 const TArray& faceAreaMag =
123 const TArray& cellVolume =
137 const TArray& lambdaCell =
143 const TArray& temperatureCell =
152 const int nFaces = faces.
getCount();
164 for(
int f=0; f<nFaces; f++)
166 const int c0 = faceCells(f,0);
167 const int c1 = faceCells(f,1);
170 const VectorT3 en = Af/faceAreaMag[f];
172 VectorT3 ds=cellCentroid[c1]-cellCentroid[c0];
174 T vol0 = cellVolume[c0];
175 T vol1 = cellVolume[c1];
177 T wt0 = vol0/(vol0+vol1);
178 T wt1 = vol1/(vol0+vol1);
180 if (isBoundary && !isSymmetry)
189 T faceTemperature(1.0);
191 Diag& a00 = diag[c0];
192 Diag& a11 = diag[c1];
199 faceLambda = lambdaCell[c1];
200 faceAlpha = alphaCell[c1];
201 faceTemperature = temperatureCell[c1];
206 faceLambda = lambdaCell[c0];
207 faceAlpha = alphaCell[c0];
208 faceTemperature = temperatureCell[c0];
215 faceTemperature =
harmonicAverage(temperatureCell[c0],temperatureCell[c1]);
218 faceMu = muCell[c0]*wt0 + muCell[c1]*wt1;
219 faceLambda = lambdaCell[c0]*wt0 + lambdaCell[c1]*wt1;
220 faceAlpha = alphaCell[c0]*wt0 + alphaCell[c1]*wt1;
221 faceTemperature = temperatureCell[c0]*wt0 + temperatureCell[c1]*wt1;
223 const VGradType gradF = (vGradCell[c0]*wt0 + vGradCell[c1]*wt1);
228 const T divU = (gradF[0][0] + gradF[1][1] + gradF[2][2]);
230 const T diffMetric = faceAreaMag[f]*faceAreaMag[f]/
dot(faceArea[f],ds);
231 const VectorT3 secondaryCoeff = faceMu*(faceArea[f]-ds*diffMetric);
234 source[0] = faceMu*(gradF[0][0]*Af[0] + gradF[0][1]*Af[1] + gradF[0][2]*Af[2])
235 + faceLambda*divU*Af[0];
237 source[1] = faceMu*(gradF[1][0]*Af[0] + gradF[1][1]*Af[1] + gradF[1][2]*Af[2])
238 + faceLambda*divU*Af[1];
240 source[2] = faceMu*(gradF[2][0]*Af[0] + gradF[2][1]*Af[1] + gradF[2][2]*Af[2])
241 + faceLambda*divU*Af[2];
263 for(
int nnb = ccRow[c0]; nnb<ccRow[c0+1]; nnb++)
265 const int nb = ccCol[nnb];
273 const T gnb_dot_nx2 = T(2.0)*
dot(en,g_nb);
274 g_nb = gnb_dot_nx2*en;
279 for(
int i=0; i<3; i++)
281 for(
int j=0; j<3; j++)
283 coeff(i,j) = wt0*(faceMu*Af[j]*g_nb[i]
284 + faceLambda*Af[i]*g_nb[j]
288 for(
int k=0; k<3; k++)
289 coeff(i,i) += wt0*secondaryCoeff[k]*g_nb[k];
297 for(
int j=0; j<3; j++)
300 R(i,j) = 1.0 - 2*en[i]*en[j];
302 R(i,j) = - 2*en[i]*en[j];
305 Diag coeff1(R*coeff*R);
310 OffDiag& a0_nb = matrix.
getCoeff(c0,nb);
323 OffDiag& a1_nb = matrix.
getCoeff(c1,nb);
334 for(
int nnb = ccRow[c1]; nnb<ccRow[c1+1]; nnb++)
336 const int nb = ccCol[nnb];
341 for(
int i=0; i<3; i++)
343 for(
int j=0; j<3; j++)
345 coeff(i,j) = wt1*(faceMu*Af[j]*g_nb[i]
346 + faceLambda*Af[i]*g_nb[j]
350 for(
int k=0; k<3; k++)
351 coeff(i,i) += wt1*secondaryCoeff[k]*g_nb[k];
357 OffDiag& a1_nb = matrix.
getCoeff(c1,nb);
366 OffDiag& a0_nb = matrix.
getCoeff(c0,nb);
380 source += faceMu*diffMetric*(xCell[c1]-xCell[c0]);
385 source += gradF*secondaryCoeff;
392 rCell[c0] += thermalSource;
393 rCell[c1] -= thermalSource;
396 rCell[c0] += residualSource;
397 rCell[c1] -= residualSource;
401 const T faceDiffusivity = faceMu;
402 const T diffCoeff = faceDiffusivity*diffMetric;
const Array< int > & getCol() const
const Array< int > & getRow() const
const FaceGroup & getInteriorFaceGroup() const
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
shared_ptr< FaceGroup > FaceGroupPtr
const Field & _lambdaField
T harmonicAverage(const T &x0, const T &x1)
Array< VectorT3 > VectorT3Array
StructureSourceDiscretization(const MeshList &meshes, const GeomFields &geomFields, Field &varField, const Field &muField, const Field &lambdaField, const Field &alphaField, const Field &varGradientField, const Field &temperatureField, const T &referenceTemperature, const T &residualXXStress, const T &residualYYStress, const T &residualZZStress, const bool &thermo, const bool &residualStress, bool fullLinearization=true)
GradientModel< VectorT3 > VGradModelType
const FaceGroupList & getAllFaceGroups() const
const Field & _alphaField
const bool _residualStress
OffDiag & getCoeff(const int i, const int j)
bool hasCoeff(const int i, const int j)
OffDiag & getCoeff10(const int np)
Coord & getCoeff(const int i, const int j)
Gradient< VectorT3 > VGradType
const Field & _temperatureField
Array< Diag > & getDiag()
CCMatrix::PairWiseAssembler CCAssembler
void discretizeFaces(const Mesh &mesh, const StorageSite &faces, MultiFieldMatrix &mfmatrix, MultiField &xField, MultiField &rField, const bool isBoundary, const bool isSymmetry)
const Field & _varGradientField
const GeomFields & _geomFields
const CRConnectivity & getConnectivity() const
pair< const Field *, const StorageSite * > ArrayIndex
const T _residualZZStress
void discretize(const Mesh &mesh, MultiFieldMatrix &mfmatrix, MultiField &xField, MultiField &rField)
const T _residualYYStress
VGradModelType::GradMatrixType VGradMatrix
const StorageSite & getCells() const
const bool _fullLinearization
OffDiag & getCoeff01(const int np)
Array< Gradient< VectorT3 > > VGradArray
const CRConnectivity & getFaceCells(const StorageSite &site) const
static GradMatrixType & getGradientMatrix(const Mesh &mesh, const GeomFields &geomFields)
CCMatrix::DiagArray DiagArray
const T _referenceTemperature
const T _residualXXStress
CRMatrix< Diag, OffDiag, VectorT3 > CCMatrix
PairWiseAssembler & getPairWiseAssembler(const CRConnectivity &pairs)
T dot(const Vector< T, 3 > &a, const Vector< T, 3 > &b)
vector< Mesh * > MeshList