v0.15.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PoissonExample::OpK Struct Reference

Calculate the grad-grad operator and assemble matrix. More...

#include "tutorials/cor-2to5/src/PoissonOperators.hpp"

Inheritance diagram for PoissonExample::OpK:
[legend]
Collaboration diagram for PoissonExample::OpK:
[legend]

Public Member Functions

 OpK (bool symm=true)
 
MoFEMErrorCode doWork (int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
 Do calculations for give operator.
 

Protected Member Functions

virtual MoFEMErrorCode iNtegrate (EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
 Integrate grad-grad operator.
 
virtual MoFEMErrorCode aSsemble (EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
 Assemble local entity block matrix.
 

Protected Attributes

int nbRows
 < error code
 
int nbCols
 number if dof on column
 
int nbIntegrationPts
 number of integration points
 
bool isDiag
 true if this block is on diagonal
 
FTensor::Index< 'i', 3 > i
 summit Index
 
MatrixDouble locMat
 local entity block matrix
 

Detailed Description

Calculate the grad-grad operator and assemble matrix.

Calculate

\[ \mathbf{K}=\int_\Omega \nabla \boldsymbol\phi \cdot \nabla \boldsymbol\phi \textrm{d}\Omega \]

and assemble to global matrix.

This operator is executed on element for each unique combination of entities.

Definition at line 28 of file PoissonOperators.hpp.

Constructor & Destructor Documentation

◆ OpK()

PoissonExample::OpK::OpK ( bool  symm = true)
inline

Definition at line 30 of file PoissonOperators.hpp.

31 : VolumeElementForcesAndSourcesCore::UserDataOperator("U", "U", OPROWCOL,
32 symm) {}

Member Function Documentation

◆ aSsemble()

virtual MoFEMErrorCode PoissonExample::OpK::aSsemble ( EntitiesFieldData::EntData row_data,
EntitiesFieldData::EntData col_data 
)
inlineprotectedvirtual

Assemble local entity block matrix.

Parameters
row_datarow data (consist base functions on row entity)
col_datacolumn data (consist base functions on column entity)
Returns
error code
Examples
mofem/tutorials/cor-2to5/src/PoissonOperators.hpp.

Definition at line 137 of file PoissonOperators.hpp.

138 {
140 // get pointer to first global index on row
141 const int *row_indices = &*row_data.getIndices().data().begin();
142 // get pointer to first global index on column
143 const int *col_indices = &*col_data.getIndices().data().begin();
144 Mat B = getFEMethod()->ksp_B != PETSC_NULLPTR ? getFEMethod()->ksp_B
145 : getFEMethod()->snes_B;
146 // assemble local matrix
147 CHKERR MatSetValues(B, nbRows, row_indices, nbCols, col_indices,
148 &*locMat.data().begin(), ADD_VALUES);
149
150 if (!isDiag && sYmm) {
151 // if not diagonal term and since global matrix is symmetric assemble
152 // transpose term.
153 locMat = trans(locMat);
154 CHKERR MatSetValues(B, nbCols, col_indices, nbRows, row_indices,
155 &*locMat.data().begin(), ADD_VALUES);
156 }
158 }
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
MoFEMErrorCode MatSetValues(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const double *ptr, InsertMode iora)
Assemble PETSc matrix.
const VectorInt & getIndices() const
Get global indices of degrees of freedom on entity.
int nbCols
number if dof on column
bool isDiag
true if this block is on diagonal
MatrixDouble locMat
local entity block matrix

◆ doWork()

MoFEMErrorCode PoissonExample::OpK::doWork ( int  row_side,
int  col_side,
EntityType  row_type,
EntityType  col_type,
EntitiesFieldData::EntData row_data,
EntitiesFieldData::EntData col_data 
)
inline

Do calculations for give operator.

Parameters
row_siderow side number (local number) of entity on element
col_sidecolumn side number (local number) of entity on element
row_typetype of row entity MBVERTEX, MBEDGE, MBTRI or MBTET
col_typetype of column entity MBVERTEX, MBEDGE, MBTRI or MBTET
row_datadata for row
col_datadata for column
Returns
error code
Examples
mofem/tutorials/cor-2to5/src/PoissonOperators.hpp.

Definition at line 44 of file PoissonOperators.hpp.

47 {
49 // get number of dofs on row
50 nbRows = row_data.getIndices().size();
51 // if no dofs on row, exit that work, nothing to do here
52 if (!nbRows)
54 // get number of dofs on column
55 nbCols = col_data.getIndices().size();
56 // if no dofs on Columbia, exit nothing to do here
57 if (!nbCols)
59 // get number of integration points
60 nbIntegrationPts = getGaussPts().size2();
61 // check if entity block is on matrix diagonal
62 if (row_side == col_side && row_type == col_type) {
63 isDiag = true; // yes, it is
64 } else {
65 isDiag = false;
66 }
67 // integrate local matrix for entity block
68 CHKERR iNtegrate(row_data, col_data);
69 // assemble local matrix
70 CHKERR aSsemble(row_data, col_data);
72 }
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
virtual MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
Integrate grad-grad operator.
int nbIntegrationPts
number of integration points
virtual MoFEMErrorCode aSsemble(EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
Assemble local entity block matrix.

◆ iNtegrate()

virtual MoFEMErrorCode PoissonExample::OpK::iNtegrate ( EntitiesFieldData::EntData row_data,
EntitiesFieldData::EntData col_data 
)
inlineprotectedvirtual

Integrate grad-grad operator.

Parameters
row_datarow data (consist base functions on row entity)
col_datacolumn data (consist base functions on column entity)
Returns
error code

Reimplemented in PoissonExample::OpKt.

Examples
mofem/tutorials/cor-2to5/src/PoissonOperators.hpp.

Definition at line 91 of file PoissonOperators.hpp.

92 {
94 // set size of local entity bock
95 locMat.resize(nbRows, nbCols, false);
96 // clear matrix
97 locMat.clear();
98 // get element volume
99 double vol = getVolume();
100 // get integration weights
101 auto t_w = getFTensor0IntegrationWeight();
102 // get base function gradient on rows
103 auto t_row_grad = row_data.getFTensor1DiffN<3>();
104 // loop over integration points
105 for (int gg = 0; gg != nbIntegrationPts; gg++) {
106 // take into account Jacobean
107 const double alpha = t_w * vol;
108 // noalias(locMat) +=
109 // alpha*prod(row_data.getDiffN(gg),trans(col_data.getDiffN(gg))); take
110 // fist element to local matrix
111 FTensor::Tensor0<double *> a(&*locMat.data().begin());
112 // loop over rows base functions
113 for (int rr = 0; rr != nbRows; rr++) {
114 // get column base functions gradient at gauss point gg
115 auto t_col_grad = col_data.getFTensor1DiffN<3>(gg, 0);
116 // loop over columns
117 for (int cc = 0; cc != nbCols; cc++) {
118 // calculate element of local matrix
119 a += alpha * (t_row_grad(i) * t_col_grad(i));
120 ++t_col_grad; // move to another gradient of base function on column
121 ++a; // move to another element of local matrix in column
122 }
123 ++t_row_grad; // move to another element of gradient of base function on
124 // row
125 }
126 ++t_w; // move to another integration weight
127 }
129 }
constexpr double a
FTensor::Tensor1< FTensor::PackPtr< double *, Tensor_Dim >, Tensor_Dim > getFTensor1DiffN(const FieldApproximationBase base)
Get derivatives of base functions.
FTensor::Index< 'i', 3 > i
summit Index

Member Data Documentation

◆ i

FTensor::Index<'i', 3> PoissonExample::OpK::i
protected

◆ isDiag

bool PoissonExample::OpK::isDiag
protected

true if this block is on diagonal

Examples
mofem/tutorials/cor-2to5/src/PoissonOperators.hpp.

Definition at line 80 of file PoissonOperators.hpp.

◆ locMat

MatrixDouble PoissonExample::OpK::locMat
protected

local entity block matrix

Examples
mofem/tutorials/cor-2to5/src/PoissonOperators.hpp.

Definition at line 83 of file PoissonOperators.hpp.

◆ nbCols

int PoissonExample::OpK::nbCols
protected

number if dof on column

Examples
mofem/tutorials/cor-2to5/src/PoissonOperators.hpp.

Definition at line 78 of file PoissonOperators.hpp.

◆ nbIntegrationPts

int PoissonExample::OpK::nbIntegrationPts
protected

number of integration points

Examples
mofem/tutorials/cor-2to5/src/PoissonOperators.hpp.

Definition at line 79 of file PoissonOperators.hpp.

◆ nbRows

int PoissonExample::OpK::nbRows
protected

< error code

number of dofs on rows

Examples
mofem/tutorials/cor-2to5/src/PoissonOperators.hpp.

Definition at line 77 of file PoissonOperators.hpp.


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