v0.9.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/basic_finite_elements/poisson/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, DataForcesAndSourcesCore::EntData &row_data, DataForcesAndSourcesCore::EntData &col_data)
 Do calculations for give operator. More...
 

Protected Member Functions

virtual MoFEMErrorCode iNtegrate (DataForcesAndSourcesCore::EntData &row_data, DataForcesAndSourcesCore::EntData &col_data)
 Integrate grad-grad operator. More...
 
virtual MoFEMErrorCode aSsemble (DataForcesAndSourcesCore::EntData &row_data, DataForcesAndSourcesCore::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 37 of file PoissonOperators.hpp.

Constructor & Destructor Documentation

◆ OpK()

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

Definition at line 39 of file PoissonOperators.hpp.

41  symm) {}
ForcesAndSourcesCore::UserDataOperator UserDataOperator

Member Function Documentation

◆ aSsemble()

virtual MoFEMErrorCode PoissonExample::OpK::aSsemble ( DataForcesAndSourcesCore::EntData row_data,
DataForcesAndSourcesCore::EntData col_data 
)
protectedvirtual

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

148  {
150  // get pointer to first global index on row
151  const int *row_indices = &*row_data.getIndices().data().begin();
152  // get pointer to first global index on column
153  const int *col_indices = &*col_data.getIndices().data().begin();
154  Mat B = getFEMethod()->ksp_B != PETSC_NULL ? getFEMethod()->ksp_B
155  : getFEMethod()->snes_B;
156  // assemble local matrix
157  CHKERR MatSetValues(B, nbRows, row_indices, nbCols, col_indices,
158  &*locMat.data().begin(), ADD_VALUES);
159 
160  if (!isDiag && sYmm) {
161  // if not diagonal term and since global matrix is symmetric assemble
162  // transpose term.
163  locMat = trans(locMat);
164  CHKERR MatSetValues(B, nbCols, col_indices, nbRows, row_indices,
165  &*locMat.data().begin(), ADD_VALUES);
166  }
168  }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
int nbCols
number if dof on column
bool isDiag
true if this block is on diagonal
MoFEMErrorCode MatSetValues(Mat M, const DataForcesAndSourcesCore::EntData &row_data, const DataForcesAndSourcesCore::EntData &col_data, const double *ptr, InsertMode iora)
Assemble PETSc matrix.
#define CHKERR
Inline error check.
Definition: definitions.h:596
MatrixDouble locMat
local entity block matrix
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407
int nbRows
< error code

◆ doWork()

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

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

56  {
58  // get number of dofs on row
59  nbRows = row_data.getIndices().size();
60  // if no dofs on row, exit that work, nothing to do here
61  if (!nbRows)
63  // get number of dofs on column
64  nbCols = col_data.getIndices().size();
65  // if no dofs on Columbia, exit nothing to do here
66  if (!nbCols)
68  // get number of integration points
69  nbIntegrationPts = getGaussPts().size2();
70  // check if entity block is on matrix diagonal
71  if (row_side == col_side && row_type == col_type) {
72  isDiag = true; // yes, it is
73  } else {
74  isDiag = false;
75  }
76  // integrate local matrix for entity block
77  CHKERR iNtegrate(row_data, col_data);
78  // assemble local matrix
79  CHKERR aSsemble(row_data, col_data);
81  }
int nbIntegrationPts
number of integration points
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
int nbCols
number if dof on column
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:508
bool isDiag
true if this block is on diagonal
virtual MoFEMErrorCode aSsemble(DataForcesAndSourcesCore::EntData &row_data, DataForcesAndSourcesCore::EntData &col_data)
Assemble local entity block matrix.
virtual MoFEMErrorCode iNtegrate(DataForcesAndSourcesCore::EntData &row_data, DataForcesAndSourcesCore::EntData &col_data)
Integrate grad-grad operator.
#define CHKERR
Inline error check.
Definition: definitions.h:596
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407
int nbRows
< error code

◆ iNtegrate()

virtual MoFEMErrorCode PoissonExample::OpK::iNtegrate ( DataForcesAndSourcesCore::EntData row_data,
DataForcesAndSourcesCore::EntData col_data 
)
protectedvirtual

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

102  {
104  // set size of local entity bock
105  locMat.resize(nbRows, nbCols, false);
106  // clear matrix
107  locMat.clear();
108  // get element volume
109  double vol = getVolume();
110  // get integration weights
111  auto t_w = getFTensor0IntegrationWeight();
112  // get base function gradient on rows
113  auto t_row_grad = row_data.getFTensor1DiffN<3>();
114  // loop over integration points
115  for (int gg = 0; gg != nbIntegrationPts; gg++) {
116  // take into account Jacobean
117  const double alpha = t_w * vol;
118  // noalias(locMat) +=
119  // alpha*prod(row_data.getDiffN(gg),trans(col_data.getDiffN(gg))); take
120  // fist element to local matrix
121  FTensor::Tensor0<double *> a(&*locMat.data().begin());
122  // loop over rows base functions
123  for (int rr = 0; rr != nbRows; rr++) {
124  // get column base functions gradient at gauss point gg
125  auto t_col_grad = col_data.getFTensor1DiffN<3>(gg, 0);
126  // loop over columns
127  for (int cc = 0; cc != nbCols; cc++) {
128  // calculate element of local matrix
129  a += alpha * (t_row_grad(i) * t_col_grad(i));
130  ++t_col_grad; // move to another gradient of base function on column
131  ++a; // move to another element of local matrix in column
132  }
133  ++t_row_grad; // move to another element of gradient of base function on
134  // row
135  }
136  ++t_w; // move to another integration weight
137  }
139  }
int nbIntegrationPts
number of integration points
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
int nbCols
number if dof on column
FTensor::Index< 'i', 3 > i
summit Index
MatrixDouble locMat
local entity block matrix
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407
int nbRows
< error code

Member Data Documentation

◆ i

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

summit Index

Examples
PoissonOperators.hpp.

Definition at line 91 of file PoissonOperators.hpp.

◆ isDiag

bool PoissonExample::OpK::isDiag
protected

true if this block is on diagonal

Examples
PoissonOperators.hpp.

Definition at line 89 of file PoissonOperators.hpp.

◆ locMat

MatrixDouble PoissonExample::OpK::locMat
protected

local entity block matrix

Examples
PoissonOperators.hpp.

Definition at line 92 of file PoissonOperators.hpp.

◆ nbCols

int PoissonExample::OpK::nbCols
protected

number if dof on column

Examples
PoissonOperators.hpp.

Definition at line 87 of file PoissonOperators.hpp.

◆ nbIntegrationPts

int PoissonExample::OpK::nbIntegrationPts
protected

number of integration points

Examples
PoissonOperators.hpp.

Definition at line 88 of file PoissonOperators.hpp.

◆ nbRows

int PoissonExample::OpK::nbRows
protected

< error code

number of dofs on rows

Examples
PoissonOperators.hpp.

Definition at line 86 of file PoissonOperators.hpp.


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