v0.14.0
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 <users_modules/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. More...
 

Protected Member Functions

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

Protected Attributes

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

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 25 of file PoissonOperators.hpp.

Constructor & Destructor Documentation

◆ OpK()

PoissonExample::OpK::OpK ( bool  symm = true)
inline
Examples
PoissonOperators.hpp.

Definition at line 27 of file PoissonOperators.hpp.

29  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
PoissonOperators.hpp.

Definition at line 134 of file PoissonOperators.hpp.

135  {
137  // get pointer to first global index on row
138  const int *row_indices = &*row_data.getIndices().data().begin();
139  // get pointer to first global index on column
140  const int *col_indices = &*col_data.getIndices().data().begin();
141  Mat B = getFEMethod()->ksp_B != PETSC_NULL ? getFEMethod()->ksp_B
142  : getFEMethod()->snes_B;
143  // assemble local matrix
144  CHKERR MatSetValues(B, nbRows, row_indices, nbCols, col_indices,
145  &*locMat.data().begin(), ADD_VALUES);
146 
147  if (!isDiag && sYmm) {
148  // if not diagonal term and since global matrix is symmetric assemble
149  // transpose term.
150  locMat = trans(locMat);
151  CHKERR MatSetValues(B, nbCols, col_indices, nbRows, row_indices,
152  &*locMat.data().begin(), ADD_VALUES);
153  }
155  }

◆ 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
PoissonOperators.hpp.

Definition at line 41 of file PoissonOperators.hpp.

44  {
46  // get number of dofs on row
47  nbRows = row_data.getIndices().size();
48  // if no dofs on row, exit that work, nothing to do here
49  if (!nbRows)
51  // get number of dofs on column
52  nbCols = col_data.getIndices().size();
53  // if no dofs on Columbia, exit nothing to do here
54  if (!nbCols)
56  // get number of integration points
57  nbIntegrationPts = getGaussPts().size2();
58  // check if entity block is on matrix diagonal
59  if (row_side == col_side && row_type == col_type) {
60  isDiag = true; // yes, it is
61  } else {
62  isDiag = false;
63  }
64  // integrate local matrix for entity block
65  CHKERR iNtegrate(row_data, col_data);
66  // assemble local matrix
67  CHKERR aSsemble(row_data, col_data);
69  }

◆ 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
PoissonOperators.hpp.

Definition at line 88 of file PoissonOperators.hpp.

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

Member Data Documentation

◆ i

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

summit Index

Examples
PoissonOperators.hpp.

Definition at line 79 of file PoissonOperators.hpp.

◆ isDiag

bool PoissonExample::OpK::isDiag
protected

true if this block is on diagonal

Examples
PoissonOperators.hpp.

Definition at line 77 of file PoissonOperators.hpp.

◆ locMat

MatrixDouble PoissonExample::OpK::locMat
protected

local entity block matrix

Examples
PoissonOperators.hpp.

Definition at line 80 of file PoissonOperators.hpp.

◆ nbCols

int PoissonExample::OpK::nbCols
protected

number if dof on column

Examples
PoissonOperators.hpp.

Definition at line 75 of file PoissonOperators.hpp.

◆ nbIntegrationPts

int PoissonExample::OpK::nbIntegrationPts
protected

number of integration points

Examples
PoissonOperators.hpp.

Definition at line 76 of file PoissonOperators.hpp.

◆ nbRows

int PoissonExample::OpK::nbRows
protected

< error code

number of dofs on rows

Examples
PoissonOperators.hpp.

Definition at line 74 of file PoissonOperators.hpp.


The documentation for this struct was generated from the following file:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
MoFEM::MatSetValues
MoFEMErrorCode MatSetValues(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const double *ptr, InsertMode iora)
Assemble PETSc matrix.
Definition: EntitiesFieldData.hpp:1631
PoissonExample::OpK::nbIntegrationPts
int nbIntegrationPts
number of integration points
Definition: PoissonOperators.hpp:76
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
a
constexpr double a
Definition: approx_sphere.cpp:30
PoissonExample::OpK::locMat
MatrixDouble locMat
local entity block matrix
Definition: PoissonOperators.hpp:80
PoissonExample::OpK::nbCols
int nbCols
number if dof on column
Definition: PoissonOperators.hpp:75
PoissonExample::OpK::i
FTensor::Index< 'i', 3 > i
summit Index
Definition: PoissonOperators.hpp:79
PoissonExample::OpK::nbRows
int nbRows
< error code
Definition: PoissonOperators.hpp:74
PoissonExample::OpK::aSsemble
virtual MoFEMErrorCode aSsemble(EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
Assemble local entity block matrix.
Definition: PoissonOperators.hpp:134
FTensor::Tensor0
Definition: Tensor0.hpp:16
UserDataOperator
ForcesAndSourcesCore::UserDataOperator UserDataOperator
Definition: HookeElement.hpp:75
PoissonExample::OpK::isDiag
bool isDiag
true if this block is on diagonal
Definition: PoissonOperators.hpp:77
PoissonExample::OpK::iNtegrate
virtual MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
Integrate grad-grad operator.
Definition: PoissonOperators.hpp:88
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346