8 #ifndef DENDRO_5_0_FEMATRIX_H 9 #define DENDRO_5_0_FEMATRIX_H 14 void fem_eMatTogMat(
ot::MatRecord *eMat,
const T *Imat_p2c,
unsigned int pOrder,
unsigned int dof=1) {
15 const unsigned int n = (pOrder + 1);
16 const unsigned int nPe = n * n * n;
17 const unsigned int N = nPe * dof;
18 const unsigned int dof2=dof*dof;
21 T * IT_Ke_I =
new T[N * N];
23 for(
unsigned int di =0; di< dof; di++)
24 for(
unsigned int dj=0; dj< dof; dj++)
26 const unsigned int offset = (di*dof + dj)*nPe*nPe;
27 for (
unsigned int i = 0; i < nPe; i++)
28 for(
unsigned int j=0; j < nPe; j++)
31 for(
unsigned int k=0;k< nPe; k++)
33 val += (eMat[offset + i*nPe +k].
getMatVal() * Imat_p2c[k * nPe + j]);
35 IT_Ke_I[offset + i*nPe +j] = val;
39 for(
unsigned int di =0; di< dof; di++)
40 for(
unsigned int dj=0; dj< dof; dj++)
42 const unsigned int offset = (di*dof + dj)*nPe*nPe;
44 for (
unsigned int i = 0; i < nPe; i++)
45 for(
unsigned int j=0; j < nPe; j++)
47 eMat[offset + i*nPe +j].
setMatValue(IT_Ke_I[offset + i*nPe +j]);
52 for(
unsigned int di =0; di< dof; di++)
53 for(
unsigned int dj =0; dj< dof; dj++)
55 const unsigned int offset = (di*dof + dj)*nPe*nPe;
56 for (
unsigned int i = 0; i < nPe; i++)
57 for(
unsigned int j=0; j < nPe; j++)
60 for(
unsigned int k=0;k< nPe; k++)
62 val += ( Imat_p2c[k * nPe + i] * eMat[offset + k*nPe +j].
getMatVal());
64 IT_Ke_I[offset + i*nPe + j] = val;
68 for(
unsigned int di =0; di< dof; di++)
69 for(
unsigned int dj=0; dj< dof; dj++)
71 const unsigned int offset = (di*dof + dj)*nPe*nPe;
72 for (
unsigned int i = 0; i < nPe; i++)
73 for(
unsigned int j=0; j < nPe; j++)
75 eMat[offset + i*nPe + j].
setMatValue(IT_Ke_I[offset + i*nPe + j]);
96 VECType *m_uiEleVecOut;
115 virtual void matVec(
const VECType *in, VECType *out,
double scale = 1.0);
123 virtual void elementalMatVec(
const VECType *in, VECType *out,
double *coords = NULL,
double scale = 1.0) = 0;
126 #ifdef BUILD_WITH_PETSC 133 virtual void matVec(
const Vec &in, Vec &out,
double scale = 1.0);
141 virtual bool getAssembledMatrix(Mat *J, MatType mtype);
147 T &
asLeaf() {
return static_cast<T &
>(*this); }
157 bool preMatVec(
const VECType *in, VECType *out,
double scale = 1.0) {
158 return asLeaf().preMatVec(in, out, scale);
168 bool postMatVec(
const VECType *in, VECType *out,
double scale = 1.0) {
169 return asLeaf().postMatVec(in, out, scale);
179 return asLeaf().postMat();
190 return asLeaf().getElementalMatrix(eleID, records, coords);
201 m_uiEleVecOut =
new VECType[
m_uiDof * nPe];
210 delete[] m_uiEleVecOut;
214 m_uiEleVecOut = NULL;
223 VECType *_out = NULL;
234 VECType *val =
new VECType[
m_uiDof];
235 for (
unsigned int var = 0; var <
m_uiDof; var++)
236 val[var] = (VECType) 0;
244 double * qMat =
new double[nPe*nPe];
245 const unsigned int * e2n_cg = &(*(pMesh->
getE2NMapping().begin()));
260 for (
unsigned int dof = 0; dof <
m_uiDof; dof++) {
261 for (
unsigned int i = 0; i < nPe; i++) {
262 VECType ss = (VECType) 0;
263 for (
unsigned int j = 0; j < nPe; j++) {
264 ss += qMat[j * nPe + i] * m_uiEleVecOut[dof*nPe + j];
266 _out[dof*totalNodalSize + e2n_cg[currentId * nPe + i]] += (VECType) ss;
276 const unsigned int eleLocalEnd = pMesh -> getElementLocalEnd();
290 for (
unsigned int dof = 0; dof <
m_uiDof; dof++) {
291 for (
unsigned int i = 0; i < nPe; i++) {
292 VECType ss = (VECType) 0;
293 for (
unsigned int j = 0; j < nPe; j++) {
294 ss += qMat[j * nPe + i] * m_uiEleVecOut[dof*nPe + j];
296 _out[dof*totalNodalSize + e2n_cg[currentId * nPe + i]] += (VECType) ss;
322 #ifdef BUILD_WITH_PETSC 327 const PetscScalar *inArry = NULL;
328 PetscScalar *outArry = NULL;
330 VecGetArrayRead(in, &inArry);
331 VecGetArray(out, &outArry);
333 matVec(inArry, outArry, scale);
335 VecRestoreArrayRead(in, &inArry);
336 VecRestoreArray(out, &outArry);
348 std::vector<ot::MatRecord> records;
351 const unsigned int npe_1d = eleOrder + 1;
352 const unsigned int npe_2d = (eleOrder + 1) * (eleOrder + 1);
353 const unsigned int nPe = (eleOrder + 1) * (eleOrder + 1) * (eleOrder + 1);
358 DendroScalar *p2cEleMat =
new DendroScalar[nPe * nPe];
361 unsigned int nCount = 0;
363 double *coords =
new double[m_uiDim * nPe];
365 bool faceHang[NUM_FACES];
366 bool edgeHang[NUM_EDGES];
367 unsigned int cnumFace[NUM_FACES];
368 unsigned int cnumEdge[NUM_EDGES];
370 const unsigned int * e2n_cg = &(*(pMesh->
getE2NMapping().begin()));
372 const unsigned int * e2e = &(*(pMesh->
getE2EMapping().begin()));
375 const unsigned int eleLocalEnd = pMesh -> getElementLocalEnd();
382 const unsigned int cnum = allElements[currentId].getMortonIndex();
388 fem_eMatTogMat(&(*(records.begin() + nCount)), p2cEleMat, eleOrder,
m_uiDof);
390 if (records.size() > 500) {
401 MatAssemblyBegin(*J, MAT_FINAL_ASSEMBLY);
402 MatAssemblyEnd(*J, MAT_FINAL_ASSEMBLY);
407 PetscFunctionReturn(0);
417 #endif //DENDRO_5_0_FEMATRIX_H bool postMat()
executed after the matrix assembly
Definition: feMatrix.h:178
unsigned int getNumNodesPerElement() const
get number of nodes per element
Definition: oda.h:257
DendroScalar getMatVal() const
returns the entry value
Definition: matRecord.h:133
void getElementQMat(unsigned int currentId, double *&qMat, bool isAllocated=true) const
: Compute the elemental interpolation matrix.
Definition: mesh.cpp:9436
virtual void elementalMatVec(const VECType *in, VECType *out, double *coords=NULL, double scale=1.0)=0
Computes the elemental matvec.
bool postMatVec(const VECType *in, VECType *out, double scale=1.0)
executed just after the matVec loop in matvec function
Definition: feMatrix.h:168
Abstract class for stiffness matrix computation.
Definition: feMat.h:18
VECType * m_uiEleVecIn
element nodal vec in
Definition: feMatrix.h:93
A class to manage octants.
Definition: TreeNode.h:35
T & asLeaf()
static cast to the leaf node of the inheritance
Definition: feMatrix.h:147
void readFromGhostEnd(T *vec, unsigned int dof=1)
Sync the ghost element exchange.
unsigned int end()
Returns if the current element has reached end or not.
void next()
: increment it to the next element.
void getElementalMatrix(unsigned int eleID, std::vector< ot::MatRecord > &records, double *coords)
Compute the elemental Matrix.
Definition: feMatrix.h:189
void getElementNodalValues(const T *in, T *eleVecOut, unsigned int eleID, unsigned int dof=1) const
computes the element nodal values using interpolation if needed.
void ghostedNodalToNodalVec(const T *gVec, T *&local, bool isAllocated=false, unsigned int dof=1) const
convert ghosted nodal vector to local vector (without ghosting)
void readFromGhostBegin(T *vec, unsigned int dof=1)
Initiate the ghost nodal value exchange.
const std::vector< unsigned int > & getE2NMapping_DG() const
Definition: mesh.h:1082
void nodalVecToGhostedNodal(const T *in, T *&out, bool isAllocated=false, unsigned int dof=1) const
convert nodal local vector with ghosted buffer regions.
unsigned int getElementLocalBegin() const
return the begin location of element local
Definition: mesh.h:1030
void setMatValue(DendroScalar value)
sets matrix value
Definition: matRecord.h:136
unsigned int m_uiDof
number of dof
Definition: feMatrix.h:90
void destroyVector(T *&local) const
deallocates the memory allocated for a vector
Definition: matRecord.h:26
const std::vector< ot::TreeNode > & getAllElements() const
returns the pointer to All elements array.
Definition: mesh.h:1058
unsigned int getNumNodesPerElement() const
return the number of nodes per element.
Definition: mesh.h:1090
ot::DA * m_uiOctDA
: pointer to OCT DA
Definition: feMat.h:23
bool preMat()
executed before the matrix assembly
Definition: feMatrix.h:173
feMatrix(ot::DA *da, unsigned int dof=1)
constructs an FEM stiffness matrix class.
Definition: feMatrix.h:197
double * m_uiEleCoords
Definition: feMatrix.h:99
unsigned int curr()
get the current elmenent in the iteration
unsigned int getElementOrder() const
get element order
Definition: oda.h:260
const std::vector< unsigned int > & getE2NMapping() const
Definition: mesh.h:1073
virtual void matVec(const VECType *in, VECType *out, double scale=1.0)
Computes the LHS of the weak formulation, normally the stifness matrix times a given vector...
Definition: feMatrix.h:220
void writeToGhostsEnd(T *vec, DA_FLAGS::WriteMode mode, unsigned int dof=1)
Sync accumilation across ghost elements.
void getElementalCoords(unsigned int eleID, double *coords) const
computes the elementCoordinates (based on the nodal placement)
Definition: oda.cpp:264
bool isActive() const
see if the current DA is active
Definition: oda.h:254
int createVector(T *&local, bool isElemental=false, bool isGhosted=false, unsigned int dof=1) const
Creates a ODA vector.
const std::vector< unsigned int > & getE2EMapping() const
returns const e2e mapping instance.
Definition: mesh.h:1070
void setVectorByScalar(T *local, const T *value, bool isElemental=false, bool isGhosted=false, unsigned int dof=1) const
initialize a variable vector to a function depends on spatial coords.
void writeToGhostsBegin(T *vec, unsigned int dof=1)
Initiate accumilation across ghost elements.
const ot::Mesh * getMesh() const
returns the mesh
Definition: oda.h:269
unsigned int getTotalNodalSz() const
returns the total nodal size (this includes the ghosted region as well.)
Definition: oda.h:245
Definition: feMatrix.h:85
void init()
initialize the loop counters.
bool preMatVec(const VECType *in, VECType *out, double scale=1.0)
executed just before the matVec loop in matvec function
Definition: feMatrix.h:157