5 #ifndef _GRADIENTMODEL_H_
6 #define _GRADIENTMODEL_H_
25 const T g0_dot_en_x2 = T(2.0)*(g0*en);
26 for(
int i=0; i<3; i++)
27 gr[i] = g0[i] - g0_dot_en_x2*en[i];
32 template<
class T,
int N>
37 for(
int k=0; k<N; k++)
39 const T g0_dot_en_x2 = T(2.0)*(g0[0][k]*en[0] + g0[1][k]*en[1] + g0[2][k]*en[2]);
40 for(
int i=0; i<3; i++)
41 gr[i][k] = g0[i][k] - g0_dot_en_x2*en[i];
55 for(
int i=0; i<3; i++)
57 gr[i][0] = g0[i][0] - g0_dot_en_x2[0]*en[i];
58 gr[i][1] = g0[i][1] - g0_dot_en_x2[1]*en[i];
70 for(
int j=0; j<3; j++)
73 R(i,j) = 1.0 - 2*en[i]*en[j];
75 R(i,j) = - 2*en[i]*en[j];
83 for(
int j=0; j<3; j++)
127 shared_ptr<GradientMatrixBase>
154 const TArray& cellVolume =
164 isDegenerate =
false;
166 for(
int f=0; f<faceCount; f++)
168 const int c0 = faceCells(f,0);
169 const int c1 = faceCells(f,1);
170 VectorT3 ds = cellCentroid[c1]-cellCentroid[c0];
180 ds = faceCentroid[f]-cellCentroid[c0];
184 ds = cellCentroid[c1]-faceCentroid[f];
195 for(
int nc=0; nc<cellCount; nc++)
200 for(
int inb=row[nc]; inb<row[nc+1]; inb++)
212 const T_Scalar det = Ixx*(Iyy*Izz-Iyz*Iyz) -Ixy*(Ixy*Izz-Iyz*Ixz)
213 + Ixz*(Ixy*Iyz-Iyy*Ixz);
217 const T_Scalar Kxx = (Iyy*Izz-Iyz*Iyz)/det;
218 const T_Scalar Kxy = -(Ixy*Izz-Iyz*Ixz)/det;
219 const T_Scalar Kxz = (Ixy*Iyz-Iyy*Ixz)/det;
220 const T_Scalar Kyy = (Ixx*Izz-Ixz*Ixz)/det;
221 const T_Scalar Kyz = -(Ixx*Iyz-Ixy*Ixz)/det;
222 const T_Scalar Kzz = (Ixx*Iyy-Ixy*Ixy)/det;
223 for(
int inb=row[nc]; inb<row[nc+1]; inb++)
229 coeffs[inb][0] = (Kxx*ds[0] + Kxy*ds[1] + Kxz*ds[2]);
230 coeffs[inb][1] = (Kxy*ds[0] + Kyy*ds[1] + Kyz*ds[2]);
231 coeffs[inb][2] = (Kxz*ds[0] + Kyz*ds[1] + Kzz*ds[2]);
236 isDegenerate[nc] =
true;
240 for(
int f=0; f<faceCount; f++)
242 const int c0 = faceCells(f,0);
243 const int c1 = faceCells(f,1);
244 VectorT3 ds = cellCentroid[c1]-cellCentroid[c0];
254 ds = faceCentroid[f]-cellCentroid[c0];
258 ds = cellCentroid[c1]-faceCentroid[f];
267 for(
int f=0; f<faceCount; f++)
269 const int c0 = faceCells(f,0);
270 const int c1 = faceCells(f,1);
271 if (isDegenerate[c0])
275 if (isDegenerate[c1])
281 return shared_ptr<GradientMatrixBase>(gMPtr);
285 shared_ptr<GradientMatrixBase>
314 const TArray& cellVolume =
324 isDegenerate =
false;
326 for(
int f=0; f<faceCount; f++)
328 const int c0 = faceCells(f,0);
329 const int c1 = faceCells(f,1);
330 VectorT3 ds = cellCentroid[c1]-cellCentroid[c0];
340 ds = faceCentroid[f]-cellCentroid[c0];
344 ds = cellCentroid[c1]-faceCentroid[f];
355 for(
int nc=0; nc<cellCount; nc++)
360 for(
int inb=row[nc]; inb<row[nc+1]; inb++)
368 const T_Scalar det = Ixx*Iyy-Ixy*Ixy;
375 for(
int inb=row[nc]; inb<row[nc+1]; inb++)
383 coeffs[inb][0] = (Kxx*ds[0] + Kxy*ds[1]);
384 coeffs[inb][1] = (Kxy*ds[0] + Kyy*ds[1]);
390 isDegenerate[nc] =
true;
394 for(
int f=0; f<faceCount; f++)
396 const int c0 = faceCells(f,0);
397 const int c1 = faceCells(f,1);
398 VectorT3 ds = cellCentroid[c1]-cellCentroid[c0];
408 ds = faceCentroid[f]-cellCentroid[c0];
412 ds = cellCentroid[c1]-faceCentroid[f];
420 for(
int f=0; f<faceCount; f++)
422 const int c0 = faceCells(f,0);
423 const int c1 = faceCells(f,1);
424 if (isDegenerate[c0])
428 if (isDegenerate[c1])
435 return shared_ptr<GradientMatrixBase>(gMPtr);
475 const int numMeshes =
_meshes.size();
477 for (
int n=0; n<numMeshes; n++)
488 shared_ptr<GradArray> gradPtr = gradMatrix.
getGradient(var);
495 const int nIBFaces = ibFaces.
getCount();
511 for (
int nf=0; nf<nIBFaces; nf++)
513 const int f = ibFaceList[nf];
514 const int c0 = faceCells(f,0);
515 const int c1 = faceCells(f,1);
519 (*gradPtr)[c0].accumulate(assembler.
getCoeff01(f),
524 (*gradPtr)[c1].accumulate(assembler.
getCoeff10(f),
537 const int faceCount = faces.
getCount();
539 && (fg.
groupType!=
"dielectric interface"))
545 const TArray& faceAreaMag =
547 for(
int f=0; f<faceCount; f++)
549 const int c0 = faceCells(f,0);
550 const int c1 = faceCells(f,1);
551 const VectorT3 en = faceArea[f]/faceAreaMag[f];
557 for(
int f=0; f<faceCount; f++)
559 const int c0 = faceCells(f,0);
560 const int c1 = faceCells(f,1);
562 (*gradPtr)[c1] = (*gradPtr)[c0];
572 for (
int n=0; n<numMeshes; n++ ){
584 for (
int n=0; n<numMeshes; n++ ){
595 typedef map<const Mesh*, shared_ptr<GradientMatrixBase> > gradType;
const Array< int > & getRow() const
shared_ptr< FaceGroup > FaceGroupPtr
const StorageSite & getIBFaces() const
Array< GradType > GradArray
Coord & getCoeff01(const int np)
const FaceGroupList & getAllFaceGroups() const
void reflectGradient(Gradient< T > &gr, const Gradient< T > &g0, const Vector< T, 3 > &en)
Vector< T_Scalar, 3 > VectorT3
const GeomFields & _geomFields
Coord & getCoeff10(const int np)
static shared_ptr< GradientMatrixBase > getLeastSquaresGradientMatrix2D(const Mesh &mesh, const GeomFields &geomFields)
GradientModel(const MeshList &meshes, const Field &varField, Field &gradientField, const GeomFields &geomFields)
const Array< int > & getIBFaceList() const
T mag(const Vector< T, 3 > &a)
PairWiseAssembler & getPairWiseAssembler(const CRConnectivity &pairs)
const CRConnectivity & getAllFaceCells() const
Array< Coord > & getCoeffs()
const CRConnectivity & getConnectivity() const
GradMatrixType::PairWiseAssembler GradientMatrixAssembler
const StorageSite & getFaces() const
const StorageSite & getCells() const
static void clearGradientMatrix(const Mesh &mesh)
static map< const Mesh *, shared_ptr< GradientMatrixBase > > _gradientMatricesMap
void addArray(const StorageSite &, shared_ptr< ArrayBase > a)
const CRConnectivity & getFaceCells(const StorageSite &site) const
static GradMatrixType & getGradientMatrix(const Mesh &mesh, const GeomFields &geomFields)
shared_ptr< Array< Gradient< X > > > getGradient(const Array< X > &x) const
void recvScatterGatherValuesBufferLocal()
static shared_ptr< GradientMatrixBase > getLeastSquaresGradientMatrix3D(const Mesh &mesh, const GeomFields &geomFields)
NumTypeTraits< X >::T_Scalar T_Scalar
GradientMatrix< T_Scalar > GradMatrixType
GradientModelBase(const MeshList &meshes)
Array< VectorT3 > VectorT3Array
vector< Mesh * > MeshList
void createScatterGatherValuesBuffer()