v0.14.0
SCL-4: Nonlinear Poisson's equation
Note
Prerequisite of this tutorial is SCL-3: Poisson's equation (Lagrange multiplier)


Note
Intended learning outcome:
  • solving a nonlinear problem in MoFEM
  • usage of PETSc SNES solver to solve nonlinear equations

Introduction

Plain program

The plain program for both the implementation of the UDOs (*.hpp) and the main program (*.cpp) are as follows

Implementation of User Data Operators (*.hpp)

#ifndef __NONLINEARPOISSON2D_HPP__
#define __NONLINEARPOISSON2D_HPP__
#include <stdlib.h>
typedef boost::function<double(const double, const double, const double)>
struct DataAtGaussPoints {
// This struct is for data required for the update of Newton's iteration
};
public:
std::string row_field_name, std::string col_field_name,
boost::shared_ptr<DataAtGaussPoints> &common_data,
boost::shared_ptr<std::vector<unsigned char>> boundary_marker = nullptr)
: OpFaceEle(row_field_name, col_field_name, OpFaceEle::OPROWCOL),
commonData(common_data), boundaryMarker(boundary_marker) {
sYmm = false;
}
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type,
EntityType col_type, EntData &row_data,
EntData &col_data) {
const int nb_row_dofs = row_data.getIndices().size();
const int nb_col_dofs = col_data.getIndices().size();
if (nb_row_dofs && nb_col_dofs) {
locLhs.resize(nb_row_dofs, nb_col_dofs, false);
locLhs.clear();
// get element area
const double area = getMeasure();
// get number of integration points
const int nb_integration_points = getGaussPts().size2();
// get integration weights
// get solution (field value) at integration points
auto t_field = getFTensor0FromVec(commonData->fieldValue);
// get gradient of field at integration points
auto t_field_grad = getFTensor1FromMat<2>(commonData->fieldGrad);
// get base functions on row
auto t_row_base = row_data.getFTensor0N();
// get derivatives of base functions on row
auto t_row_diff_base = row_data.getFTensor1DiffN<2>();
// START THE LOOP OVER INTEGRATION POINTS TO CALCULATE LOCAL MATRIX
for (int gg = 0; gg != nb_integration_points; gg++) {
const double a = t_w * area;
for (int rr = 0; rr != nb_row_dofs; ++rr) {
// get base functions on column
auto t_col_base = col_data.getFTensor0N(gg, 0);
// get derivatives of base functions on column
auto t_col_diff_base = col_data.getFTensor1DiffN<2>(gg, 0);
for (int cc = 0; cc != nb_col_dofs; cc++) {
locLhs(rr, cc) += (((1 + t_field * t_field) * t_row_diff_base(i) *
t_col_diff_base(i)) +
(2.0 * t_field * t_field_grad(i) *
t_row_diff_base(i) * t_col_base)) *
a;
// move to the next base functions on column
++t_col_base;
// move to the derivatives of the next base function on column
++t_col_diff_base;
}
// move to the next base function on row
++t_row_base;
// move to the derivatives of the next base function on row
++t_row_diff_base;
}
// move to the weight of the next integration point
++t_w;
// move to the solution (field value) at the next integration point
++t_field;
// move to the gradient of field value at the next integration point
++t_field_grad;
}
// FILL VALUES OF LOCAL MATRIX ENTRIES TO THE GLOBAL MATRIX
// store original row indices
auto row_indices = row_data.getIndices();
// mark the boundary DOFs (as -1) and fill only domain DOFs
for (int r = 0; r != row_data.getIndices().size(); ++r) {
if ((*boundaryMarker)[row_data.getLocalIndices()[r]]) {
row_data.getIndices()[r] = -1;
}
}
}
// fill value to local stiffness matrix ignoring boundary DOFs
CHKERR MatSetValues(getSNESB(), row_data, col_data, &locLhs(0, 0),
ADD_VALUES);
// revert back row indices to the original
row_data.getIndices().swap(row_indices);
}
}
private:
boost::shared_ptr<DataAtGaussPoints> commonData;
boost::shared_ptr<std::vector<unsigned char>> boundaryMarker;
};
public:
std::string field_name, ScalarFunc source_term_function,
boost::shared_ptr<DataAtGaussPoints> &common_data,
boost::shared_ptr<std::vector<unsigned char>> boundary_marker = nullptr)
sourceTermFunc(source_term_function), commonData(common_data),
boundaryMarker(boundary_marker) {}
MoFEMErrorCode doWork(int side, EntityType type, EntData &data) {
const int nb_dofs = data.getIndices().size();
if (nb_dofs) {
locRhs.resize(nb_dofs, false);
locRhs.clear();
// get element area
const double area = getMeasure();
// get number of integration points
const int nb_integration_points = getGaussPts().size2();
// get integration weights
// get coordinates of the integration point
auto t_coords = getFTensor1CoordsAtGaussPts();
// get solution (field value) at integration point
auto t_field = getFTensor0FromVec(commonData->fieldValue);
// get gradient of field value of integration point
auto t_field_grad = getFTensor1FromMat<2>(commonData->fieldGrad);
// get base function
auto t_base = data.getFTensor0N();
// get derivatives of base function
auto t_grad_base = data.getFTensor1DiffN<2>();
// START THE LOOP OVER INTEGRATION POINTS TO CALCULATE LOCAL VECTOR
for (int gg = 0; gg != nb_integration_points; gg++) {
const double a = t_w * area;
double body_source =
sourceTermFunc(t_coords(0), t_coords(1), t_coords(2));
// calculate the local vector
for (int rr = 0; rr != nb_dofs; rr++) {
locRhs[rr] -=
(t_base * body_source -
t_grad_base(i) * t_field_grad(i) * (1 + t_field * t_field)) *
a;
// move to the next base function
++t_base;
// move to the derivatives of the next base function
++t_grad_base;
}
// move to the weight of the next integration point
++t_w;
// move to the coordinates of the next integration point
++t_coords;
// move to the solution (field value) at the next integration point
++t_field;
// move to the gradient of field value at the next integration point
++t_field_grad;
}
// FILL VALUES OF LOCAL VECTOR ENTRIES TO THE GLOBAL VECTOR
// store original row indices
auto row_indices = data.getIndices();
// mark the boundary DOFs (as -1) and fill only domain DOFs
for (int r = 0; r != data.getIndices().size(); ++r) {
if ((*boundaryMarker)[data.getLocalIndices()[r]]) {
data.getIndices()[r] = -1;
}
}
}
// fill value to local vector ignoring boundary DOFs
CHKERR VecSetOption(getSNESf(), VEC_IGNORE_NEGATIVE_INDICES, PETSC_TRUE);
CHKERR VecSetValues(getSNESf(), data, &*locRhs.begin(), ADD_VALUES);
// revert back the indices
data.getIndices().swap(row_indices);
}
}
private:
boost::shared_ptr<DataAtGaussPoints> commonData;
boost::shared_ptr<std::vector<unsigned char>> boundaryMarker;
};
struct OpBoundaryTangentMatrix : public OpEdgeEle {
public:
OpBoundaryTangentMatrix(std::string row_field_name,
std::string col_field_name)
: OpEdgeEle(row_field_name, col_field_name, OpEdgeEle::OPROWCOL) {
sYmm = true;
}
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type,
EntityType col_type, EntData &row_data,
EntData &col_data) {
const int nb_row_dofs = row_data.getIndices().size();
const int nb_col_dofs = col_data.getIndices().size();
// cerr << nb_row_dofs;
if (nb_row_dofs && nb_col_dofs) {
locBoundaryLhs.resize(nb_row_dofs, nb_col_dofs, false);
locBoundaryLhs.clear();
// get (boundary) element length
const double edge = getMeasure();
// get number of integration points
const int nb_integration_points = getGaussPts().size2();
// get integration weights
// get base function on row
auto t_row_base = row_data.getFTensor0N();
// START THE LOOP OVER INTEGRATION POINTS TO CALCULATE LOCAL MATRIX
for (int gg = 0; gg != nb_integration_points; gg++) {
const double a = t_w * edge;
for (int rr = 0; rr != nb_row_dofs; ++rr) {
// get base function on column
auto t_col_base = col_data.getFTensor0N(gg, 0);
for (int cc = 0; cc != nb_col_dofs; cc++) {
locBoundaryLhs(rr, cc) += t_row_base * t_col_base * a;
// move to the next base function on column
++t_col_base;
}
// move to the next base function on row
++t_row_base;
}
// move to the weight of the next integration point
++t_w;
}
// FILL VALUES OF LOCAL MATRIX ENTRIES TO THE GLOBAL MATRIX
CHKERR MatSetValues(getSNESB(), row_data, col_data, &locBoundaryLhs(0, 0),
ADD_VALUES);
if (row_side != col_side || row_type != col_type) {
transLocBoundaryLhs.resize(nb_col_dofs, nb_row_dofs, false);
CHKERR MatSetValues(getSNESB(), col_data, row_data,
&transLocBoundaryLhs(0, 0), ADD_VALUES);
}
// cerr << locBoundaryLhs << endl;
// cerr << transLocBoundaryLhs << endl;
}
}
private:
};
struct OpBoundaryResidualVector : public OpEdgeEle {
public:
OpBoundaryResidualVector(std::string field_name, ScalarFunc boundary_function,
boost::shared_ptr<DataAtGaussPoints> &common_data)
boundaryFunc(boundary_function), commonData(common_data) {}
MoFEMErrorCode doWork(int side, EntityType type, EntData &data) {
const int nb_dofs = data.getIndices().size();
if (nb_dofs) {
locBoundaryRhs.resize(nb_dofs, false);
locBoundaryRhs.clear();
// get (boundary) element length
const double edge = getMeasure();
// get number of integration points
const int nb_integration_points = getGaussPts().size2();
// get integration weights
// get coordinates at integration point
auto t_coords = getFTensor1CoordsAtGaussPts();
// get solution (field value) at integration point
auto t_field = getFTensor0FromVec(commonData->fieldValue);
// get base function
auto t_base = data.getFTensor0N();
// START THE LOOP OVER INTEGRATION POINTS TO CALCULATE LOCAL VECTOR
for (int gg = 0; gg != nb_integration_points; gg++) {
const double a = t_w * edge;
double boundary_term =
boundaryFunc(t_coords(0), t_coords(1), t_coords(2));
// calculate the local vector
for (int rr = 0; rr != nb_dofs; rr++) {
locBoundaryRhs[rr] -= t_base * (boundary_term - t_field) * a;
// move to the next base function
++t_base;
}
// move to the weight of the next integration point
++t_w;
// move to the coordinates of the next integration point
++t_coords;
// move to the solution (field value) at the next integration point
++t_field;
}
// FILL VALUES OF LOCAL VECTOR ENTRIES TO THE GLOBAL VECTOR
ADD_VALUES);
}
}
private:
boost::shared_ptr<DataAtGaussPoints> commonData;
};
}; // namespace NonlinearPoissonOps
#endif //__NONLINEARPOISSON2D_HPP__

Implementation of the main program (*.cpp)

#include <stdlib.h>
using namespace MoFEM;
using namespace NonlinearPoissonOps;
static char help[] = "...\n\n";
public:
// Declaration of the main function to run analysis
MoFEMErrorCode runProgram();
private:
// Declaration of other main functions called in runProgram()
MoFEMErrorCode readMesh();
MoFEMErrorCode setupProblem();
MoFEMErrorCode setIntegrationRules();
MoFEMErrorCode boundaryCondition();
MoFEMErrorCode assembleSystem();
MoFEMErrorCode solveSystem();
MoFEMErrorCode outputResults();
// Function to calculate the Source term
static double sourceTermFunction(const double x, const double y,
const double z) {
return 200 * sin(x * 10.) * cos(y * 10.);
// return 1;
}
// Function to calculate the Boundary term
static double boundaryFunction(const double x, const double y,
const double z) {
return sin(x * 10.) * cos(y * 10.);
// return 0;
}
// Main interfaces
Simple *simpleInterface;
// mpi parallel communicator
MPI_Comm mpiComm;
// Number of processors
const int mpiRank;
// Discrete Manager and nonliner SNES solver using SmartPetscObj
SmartPetscObj<SNES> snesSolver;
// Field name and approximation order
std::string domainField;
int order;
// Object to mark boundary entities for the assembling of domain elements
boost::shared_ptr<std::vector<unsigned char>> boundaryMarker;
// MoFEM working Pipelines for LHS and RHS of domain and boundary
boost::shared_ptr<FaceEle> domainTangentMatrixPipeline;
boost::shared_ptr<FaceEle> domainResidualVectorPipeline;
boost::shared_ptr<EdgeEle> boundaryTangentMatrixPipeline;
boost::shared_ptr<EdgeEle> boundaryResidualVectorPipeline;
// Objects needed for solution updates in Newton's method
boost::shared_ptr<DataAtGaussPoints> previousUpdate;
boost::shared_ptr<VectorDouble> fieldValuePtr;
boost::shared_ptr<MatrixDouble> fieldGradPtr;
// Object needed for postprocessing
boost::shared_ptr<PostProcEle> postProc;
// Boundary entities marked for fieldsplit (block) solver - optional
Range boundaryEntitiesForFieldsplit;
};
: domainField("U"), mField(m_field), mpiComm(mField.get_comm()),
mpiRank(mField.get_comm_rank()) {
domainTangentMatrixPipeline = boost::shared_ptr<FaceEle>(new FaceEle(mField));
domainResidualVectorPipeline =
boost::shared_ptr<FaceEle>(new FaceEle(mField));
boundaryTangentMatrixPipeline =
boost::shared_ptr<EdgeEle>(new EdgeEle(mField));
boundaryResidualVectorPipeline =
boost::shared_ptr<EdgeEle>(new EdgeEle(mField));
previousUpdate =
boost::shared_ptr<DataAtGaussPoints>(new DataAtGaussPoints());
fieldValuePtr = boost::shared_ptr<VectorDouble>(previousUpdate,
&previousUpdate->fieldValue);
fieldGradPtr = boost::shared_ptr<MatrixDouble>(previousUpdate,
&previousUpdate->fieldGrad);
}
}
}
int order = 3;
CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-order", &order, PETSC_NULL);
}
auto domain_rule_lhs = [](int, int, int p) -> int { return 2 * (p + 1); };
auto domain_rule_rhs = [](int, int, int p) -> int { return 2 * (p + 1); };
domainTangentMatrixPipeline->getRuleHook = domain_rule_lhs;
domainResidualVectorPipeline->getRuleHook = domain_rule_rhs;
auto boundary_rule_lhs = [](int, int, int p) -> int { return 2 * p + 1; };
auto boundary_rule_rhs = [](int, int, int p) -> int { return 2 * p + 1; };
boundaryTangentMatrixPipeline->getRuleHook = boundary_rule_lhs;
boundaryResidualVectorPipeline->getRuleHook = boundary_rule_rhs;
}
// Get boundary edges marked in block named "BOUNDARY_CONDITION"
auto get_ents_on_mesh_skin = [&]() {
Range boundary_entities;
std::string entity_name = it->getName();
if (entity_name.compare(0, 18, "BOUNDARY_CONDITION") == 0) {
CHKERR it->getMeshsetIdEntitiesByDimension(mField.get_moab(), 1,
boundary_entities, true);
}
}
// Add vertices to boundary entities
Range boundary_vertices;
CHKERR mField.get_moab().get_connectivity(boundary_entities,
boundary_vertices, true);
boundary_entities.merge(boundary_vertices);
// Store entities for fieldsplit (block) solver
boundaryEntitiesForFieldsplit = boundary_entities;
return boundary_entities;
};
auto mark_boundary_dofs = [&](Range &&skin_edges) {
auto problem_manager = mField.getInterface<ProblemsManager>();
auto marker_ptr = boost::make_shared<std::vector<unsigned char>>();
skin_edges, *marker_ptr);
return marker_ptr;
};
// Get global local vector of marked DOFs. Is global, since is set for all
// DOFs on processor. Is local since only DOFs on processor are in the
// vector. To access DOFs use local indices.
boundaryMarker = mark_boundary_dofs(get_ents_on_mesh_skin());
}
auto det_ptr = boost::make_shared<VectorDouble>();
auto jac_ptr = boost::make_shared<MatrixDouble>();
auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
{ // Push operators to the Pipeline that is responsible for calculating the
// domain tangent matrix (LHS)
// Add default operators to calculate inverse of Jacobian (needed for
// implementation of 2D problem but not 3D ones)
domainTangentMatrixPipeline->getOpPtrVector().push_back(
new OpCalculateHOJac<2>(jac_ptr));
domainTangentMatrixPipeline->getOpPtrVector().push_back(
new OpInvertMatrix<2>(jac_ptr, det_ptr, inv_jac_ptr));
domainTangentMatrixPipeline->getOpPtrVector().push_back(
new OpSetHOInvJacToScalarBases<2>(H1, inv_jac_ptr));
domainTangentMatrixPipeline->getOpPtrVector().push_back(
// Add default operator to calculate field values at integration points
domainTangentMatrixPipeline->getOpPtrVector().push_back(
// Add default operator to calculate field gradient at integration points
domainTangentMatrixPipeline->getOpPtrVector().push_back(
// Push operators for domain tangent matrix (LHS)
domainTangentMatrixPipeline->getOpPtrVector().push_back(
}
{ // Push operators to the Pipeline that is responsible for calculating the
// domain residual vector (RHS)
// Add default operators to calculate inverse of Jacobian (needed for
// implementation of 2D problem but not 3D ones)
domainResidualVectorPipeline->getOpPtrVector().push_back(
new OpCalculateHOJac<2>(jac_ptr));
domainResidualVectorPipeline->getOpPtrVector().push_back(
new OpInvertMatrix<2>(jac_ptr, det_ptr, inv_jac_ptr));
domainResidualVectorPipeline->getOpPtrVector().push_back(
new OpSetHOInvJacToScalarBases<2>(H1, inv_jac_ptr));
domainResidualVectorPipeline->getOpPtrVector().push_back(
// Add default operator to calculate field values at integration points
domainResidualVectorPipeline->getOpPtrVector().push_back(
// Add default operator to calculate field gradient at integration points
domainResidualVectorPipeline->getOpPtrVector().push_back(
domainResidualVectorPipeline->getOpPtrVector().push_back(
}
{ // Push operators to the Pipeline that is responsible for calculating the
// boundary tangent matrix (LHS)
boundaryTangentMatrixPipeline->getOpPtrVector().push_back(
}
{ // Push operators to the Pipeline that is responsible for calculating
// boundary residual vector (RHS)
// Add default operator to calculate field values at integration points
boundaryResidualVectorPipeline->getOpPtrVector().push_back(
boundaryResidualVectorPipeline->getOpPtrVector().push_back(
}
// get Discrete Manager (SmartPetscObj)
{ // Set operators for nonlinear equations solver (SNES) from MoFEM Pipelines
// Set operators for calculation of LHS and RHS of domain elements
boost::shared_ptr<FaceEle> null_face;
null_face);
null_face);
// Set operators for calculation of LHS and RHS of boundary elements
boost::shared_ptr<EdgeEle> null_edge;
null_edge);
null_edge);
}
}
// Create RHS and solution vectors
SmartPetscObj<Vec> global_rhs, global_solution;
global_solution = vectorDuplicate(global_rhs);
// Create nonlinear solver (SNES)
CHKERR SNESSetFromOptions(snesSolver);
// Fieldsplit block solver: yes/no
if (1) {
KSP ksp_solver;
CHKERR SNESGetKSP(snesSolver, &ksp_solver);
PC pc;
CHKERR KSPGetPC(ksp_solver, &pc);
PetscBool is_pcfs = PETSC_FALSE;
PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &is_pcfs);
// Set up FIELDSPLIT, only when option used -pc_type fieldsplit
if (is_pcfs == PETSC_TRUE) {
IS is_boundary;
const MoFEM::Problem *problem_ptr;
CHKERR DMMoFEMGetProblemPtr(dM, &problem_ptr);
CHKERR mField.getInterface<ISManager>()->isCreateProblemFieldAndRank(
problem_ptr->getName(), ROW, domainField, 0, 1, &is_boundary,
// CHKERR ISView(is_boundary, PETSC_VIEWER_STDOUT_SELF);
CHKERR PCFieldSplitSetIS(pc, NULL, is_boundary);
CHKERR ISDestroy(&is_boundary);
}
}
CHKERR SNESSetDM(snesSolver, dM);
CHKERR SNESSetUp(snesSolver);
// Solve the system
CHKERR SNESSolve(snesSolver, global_rhs, global_solution);
// VecView(global_rhs, PETSC_VIEWER_STDOUT_SELF);
// Scatter result data on the mesh
CHKERR DMoFEMMeshToGlobalVector(dM, global_solution, INSERT_VALUES,
SCATTER_REVERSE);
}
postProc = boost::make_shared<PostProcEle>(mField);
auto u_ptr = boost::make_shared<VectorDouble>();
postProc->getOpPtrVector().push_back(
postProc->getOpPtrVector().push_back(
new OpPPMap(postProc->getPostProcMesh(), postProc->getMapGaussPts(),
{{"U", u_ptr}},
{}, {}, {}
)
);
dM, simpleInterface->getDomainFEName(),
boost::dynamic_pointer_cast<FEMethod>(postProc));
CHKERR postProc->writeFile("out_result.h5m");
}
int main(int argc, char *argv[]) {
// Initialisation of MoFEM/PETSc and MOAB data structures
const char param_file[] = "param_file.petsc";
MoFEM::Core::Initialize(&argc, &argv, param_file, help);
// Error handling
try {
// Register MoFEM discrete manager in PETSc
DMType dm_name = "DMMOFEM";
// Create MOAB instance
moab::Core mb_instance; // mesh database
moab::Interface &moab = mb_instance; // mesh database interface
// Create MoFEM instance
MoFEM::Core core(moab); // finite element database
MoFEM::Interface &m_field = core; // finite element interface
// Run the main analysis
NonlinearPoisson poisson_problem(m_field);
CHKERR poisson_problem.runProgram();
}
// Finish work: cleaning memory, getting statistics, etc.
return 0;
}
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::EdgeElementForcesAndSourcesCore
Edge finite element.
Definition: EdgeElementForcesAndSourcesCore.hpp:30
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:127
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
NonlinearPoisson::outputResults
MoFEMErrorCode outputResults()
Definition: nonlinear_poisson_2d.cpp:357
H1
@ H1
continuous field
Definition: definitions.h:85
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
NonlinearPoisson::NonlinearPoisson
NonlinearPoisson(MoFEM::Interface &m_field)
Definition: nonlinear_poisson_2d.cpp:81
OpDomainTangentMatrix
Integrate the domain tangent matrix (LHS)
Definition: minimal_surface_equation.cpp:40
NonlinearPoissonOps::OpDomainResidualVector::OpDomainResidualVector
OpDomainResidualVector(std::string field_name, ScalarFunc source_term_function, boost::shared_ptr< DataAtGaussPoints > &common_data, boost::shared_ptr< std::vector< unsigned char >> boundary_marker=nullptr)
Definition: nonlinear_poisson_2d.hpp:137
MoFEM::ProblemsManager
Problem manager is used to build and partition problems.
Definition: ProblemsManager.hpp:21
NonlinearPoisson::fieldValuePtr
boost::shared_ptr< VectorDouble > fieldValuePtr
Definition: nonlinear_poisson_2d.cpp:69
NonlinearPoisson::boundaryFunction
static double boundaryFunction(const double x, const double y, const double z)
Definition: nonlinear_poisson_2d.cpp:35
NonlinearPoissonOps::OpBoundaryResidualVector::boundaryFunc
ScalarFunc boundaryFunc
Definition: nonlinear_poisson_2d.hpp:370
MoFEM::ForcesAndSourcesCore::UserDataOperator::getSNESf
Vec getSNESf() const
Definition: ForcesAndSourcesCore.hpp:1111
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
MoFEM::EntitiesFieldData::EntData::getLocalIndices
const VectorInt & getLocalIndices() const
get local indices of dofs on entity
Definition: EntitiesFieldData.hpp:1216
MoFEM::createSNES
auto createSNES(MPI_Comm comm)
Definition: PetscSmartObj.hpp:251
NonlinearPoisson::boundaryCondition
MoFEMErrorCode boundaryCondition()
Definition: nonlinear_poisson_2d.cpp:157
NonlinearPoisson::sourceTermFunction
static double sourceTermFunction(const double x, const double y, const double z)
Definition: nonlinear_poisson_2d.cpp:28
NonlinearPoisson::order
int order
Definition: nonlinear_poisson_2d.cpp:56
help
static char help[]
Definition: activate_deactivate_dofs.cpp:13
OpDomainResidualVector
Integrate the domain residual vector (RHS)
Definition: minimal_surface_equation.cpp:118
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
MoFEM::OpSetHOInvJacToScalarBases< 2 >
Definition: HODataOperators.hpp:78
NonlinearPoissonOps::OpBoundaryResidualVector::locBoundaryRhs
VectorDouble locBoundaryRhs
Definition: nonlinear_poisson_2d.hpp:372
MoFEM::Simple::loadFile
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
Definition: Simple.cpp:194
NonlinearPoissonOps
Definition: nonlinear_poisson_2d.hpp:15
NonlinearPoisson
Definition: nonlinear_poisson_2d.cpp:10
BasicFiniteElements.hpp
NonlinearPoissonOps::DataAtGaussPoints
Definition: nonlinear_poisson_2d.hpp:22
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
NonlinearPoissonOps::OpDomainResidualVector::boundaryMarker
boost::shared_ptr< std::vector< unsigned char > > boundaryMarker
Definition: nonlinear_poisson_2d.hpp:227
nonlinear_poisson_2d.hpp
MoFEM::Simple
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
NonlinearPoissonOps::OpDomainResidualVector::doWork
MoFEMErrorCode doWork(int side, EntityType type, EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Definition: nonlinear_poisson_2d.hpp:145
MoFEM::ForcesAndSourcesCore::UserDataOperator::OPROWCOL
@ OPROWCOL
operator doWork is executed on FE rows &columns
Definition: ForcesAndSourcesCore.hpp:569
MoFEM::VecSetValues
MoFEMErrorCode VecSetValues(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Assemble PETSc vector.
Definition: EntitiesFieldData.hpp:1576
NonlinearPoisson::previousUpdate
boost::shared_ptr< DataAtGaussPoints > previousUpdate
Definition: nonlinear_poisson_2d.cpp:68
sdf.r
int r
Definition: sdf.py:8
order
constexpr int order
Definition: dg_projection.cpp:18
MoFEM::OpCalculateHOJac< 2 >
Definition: HODataOperators.hpp:273
NonlinearPoisson::boundaryTangentMatrixPipeline
boost::shared_ptr< EdgeEle > boundaryTangentMatrixPipeline
Definition: nonlinear_poisson_2d.cpp:64
MoFEM::ForcesAndSourcesCore::UserDataOperator::getFTensor0IntegrationWeight
auto getFTensor0IntegrationWeight()
Get integration weights.
Definition: ForcesAndSourcesCore.hpp:1239
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::ForcesAndSourcesCore::UserDataOperator::getMeasure
double getMeasure() const
get measure of element
Definition: ForcesAndSourcesCore.hpp:1274
NonlinearPoissonOps::OpDomainResidualVector::sourceTermFunc
ScalarFunc sourceTermFunc
Definition: nonlinear_poisson_2d.hpp:225
NonlinearPoisson::domainField
std::string domainField
Definition: nonlinear_poisson_2d.cpp:55
MoFEM::OpCalculateScalarFieldGradient
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
Definition: UserDataOperators.hpp:1294
ROW
@ ROW
Definition: definitions.h:123
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
MoFEM::ForcesAndSourcesCore::UserDataOperator::getGaussPts
MatrixDouble & getGaussPts()
matrix of integration (Gauss) points for Volume Element
Definition: ForcesAndSourcesCore.hpp:1235
MoFEM::EntitiesFieldData::EntData::getFTensor0N
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0N(const FieldApproximationBase base)
Get base function as Tensor0.
Definition: EntitiesFieldData.hpp:1489
MoFEM::DMCreateGlobalVector_MoFEM
PetscErrorCode DMCreateGlobalVector_MoFEM(DM dm, Vec *g)
DMShellSetCreateGlobalVector.
Definition: DMMoFEM.cpp:1171
MoFEM::Simple::getOptions
MoFEMErrorCode getOptions()
get options
Definition: Simple.cpp:180
MoFEM::PostProcBrokenMeshInMoab
Definition: PostProcBrokenMeshInMoabBase.hpp:667
NonlinearPoisson::setIntegrationRules
MoFEMErrorCode setIntegrationRules()
Definition: nonlinear_poisson_2d.cpp:141
MoFEM::Simple::getDM
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition: Simple.cpp:667
NonlinearPoissonOps::OpDomainTangentMatrix
Definition: nonlinear_poisson_2d.hpp:29
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::FaceElementForcesAndSourcesCore::UserDataOperator
friend class UserDataOperator
Definition: FaceElementForcesAndSourcesCore.hpp:86
NonlinearPoisson::boundaryMarker
boost::shared_ptr< std::vector< unsigned char > > boundaryMarker
Definition: nonlinear_poisson_2d.cpp:59
MoFEM::CoreInterface::get_moab
virtual moab::Interface & get_moab()=0
NonlinearPoissonOps::OpBoundaryResidualVector::OpBoundaryResidualVector
OpBoundaryResidualVector(std::string field_name, ScalarFunc boundary_function, boost::shared_ptr< DataAtGaussPoints > &common_data)
Definition: nonlinear_poisson_2d.hpp:309
NonlinearPoisson::assembleSystem
MoFEMErrorCode assembleSystem()
Definition: nonlinear_poisson_2d.cpp:198
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
NonlinearPoisson::simpleInterface
Simple * simpleInterface
Definition: nonlinear_poisson_2d.cpp:43
MoFEM::ISManager
Section manager is used to create indexes and sections.
Definition: ISManager.hpp:23
a
constexpr double a
Definition: approx_sphere.cpp:30
NonlinearPoisson::domainResidualVectorPipeline
boost::shared_ptr< FaceEle > domainResidualVectorPipeline
Definition: nonlinear_poisson_2d.cpp:63
NonlinearPoissonOps::OpBoundaryTangentMatrix::doWork
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type, EntityType col_type, EntData &row_data, EntData &col_data)
Operator for bi-linear form, usually to calculate values on left hand side.
Definition: nonlinear_poisson_2d.hpp:239
NonlinearPoisson::snesSolver
SmartPetscObj< SNES > snesSolver
Definition: nonlinear_poisson_2d.cpp:52
NonlinearPoissonOps::OpDomainTangentMatrix::commonData
boost::shared_ptr< DataAtGaussPoints > commonData
Definition: nonlinear_poisson_2d.hpp:130
NonlinearPoissonOps::OpDomainResidualVector
Definition: nonlinear_poisson_2d.hpp:135
MoFEM::FaceElementForcesAndSourcesCore::UserDataOperator
default operator for TRI element
Definition: FaceElementForcesAndSourcesCore.hpp:94
EdgeEle
MoFEM::EdgeElementForcesAndSourcesCore EdgeEle
Definition: continuity_check_on_skeleton_with_simple_2d_for_h1.cpp:18
NonlinearPoisson::solveSystem
MoFEMErrorCode solveSystem()
Definition: nonlinear_poisson_2d.cpp:305
double
convert.type
type
Definition: convert.py:64
OpPPMap
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
Definition: photon_diffusion.cpp:29
Poisson2DHomogeneousOperators::body_source
const double body_source
Definition: poisson_2d_homogeneous.hpp:36
MoFEM::getFTensor0FromVec
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
Definition: Templates.hpp:135
NonlinearPoissonOps::i
FTensor::Index< 'i', 2 > i
Definition: nonlinear_poisson_2d.hpp:17
NonlinearPoissonOps::OpBoundaryTangentMatrix
Definition: nonlinear_poisson_2d.hpp:231
MoFEM::DMoFEMMeshToGlobalVector
PetscErrorCode DMoFEMMeshToGlobalVector(DM dm, Vec g, InsertMode mode, ScatterMode scatter_mode)
set ghosted vector values on all existing mesh entities
Definition: DMMoFEM.cpp:539
MoFEM::OpCalculateScalarFieldValues
Get value at integration points for scalar field.
Definition: UserDataOperators.hpp:82
MoFEM::Simple::addDomainField
MoFEMErrorCode addDomainField(const std::string &name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on domain.
Definition: Simple.cpp:264
MoFEM::EntitiesFieldData::EntData::getIndices
const VectorInt & getIndices() const
Get global indices of dofs on entity.
Definition: EntitiesFieldData.hpp:1201
MoFEM::DMRegister_MoFEM
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMoFEM.cpp:47
NonlinearPoissonOps::OpDomainResidualVector::locRhs
VectorDouble locRhs
Definition: nonlinear_poisson_2d.hpp:228
NonlinearPoissonOps::OpBoundaryTangentMatrix::transLocBoundaryLhs
MatrixDouble transLocBoundaryLhs
Definition: nonlinear_poisson_2d.hpp:304
MoFEM::Simple::getDomainFEName
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition: Simple.hpp:341
MoFEM::OpSetHOWeightsOnFace
Modify integration weights on face to take in account higher-order geometry.
Definition: HODataOperators.hpp:122
MoFEM::ProblemsManager::markDofs
MoFEMErrorCode markDofs(const std::string problem_name, RowColData rc, const enum MarkOP op, const Range ents, std::vector< unsigned char > &marker) const
Create vector with marked indices.
Definition: ProblemsManager.cpp:3196
MoFEM::FaceElementForcesAndSourcesCore
Face finite element.
Definition: FaceElementForcesAndSourcesCore.hpp:23
MoFEM::DMMoFEMSNESSetJacobian
PetscErrorCode DMMoFEMSNESSetJacobian(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES Jacobian evaluation function
Definition: DMMoFEM.cpp:763
NonlinearPoisson::fieldGradPtr
boost::shared_ptr< MatrixDouble > fieldGradPtr
Definition: nonlinear_poisson_2d.cpp:70
MoFEM::ForcesAndSourcesCore::UserDataOperator
friend class UserDataOperator
Definition: ForcesAndSourcesCore.hpp:482
NonlinearPoissonOps::OpBoundaryResidualVector::commonData
boost::shared_ptr< DataAtGaussPoints > commonData
Definition: nonlinear_poisson_2d.hpp:371
MoFEM::ForcesAndSourcesCore::UserDataOperator::getSNESB
Mat getSNESB() const
Definition: ForcesAndSourcesCore.hpp:1135
main
int main(int argc, char *argv[])
Definition: activate_deactivate_dofs.cpp:15
NonlinearPoisson::runProgram
MoFEMErrorCode runProgram()
Definition: nonlinear_poisson_2d.cpp:100
NonlinearPoisson::mField
MoFEM::Interface & mField
Definition: nonlinear_poisson_2d.cpp:42
NonlinearPoissonOps::OpDomainTangentMatrix::doWork
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type, EntityType col_type, EntData &row_data, EntData &col_data)
Operator for bi-linear form, usually to calculate values on left hand side.
Definition: nonlinear_poisson_2d.hpp:40
EntData
EntitiesFieldData::EntData EntData
Definition: child_and_parent.cpp:37
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
FTensor::Index< 'i', 2 >
AINSWORTH_BERNSTEIN_BEZIER_BASE
@ AINSWORTH_BERNSTEIN_BEZIER_BASE
Definition: definitions.h:64
MoFEM::Simple::setFieldOrder
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition: Simple.cpp:473
MoFEM::EdgeElementForcesAndSourcesCore::UserDataOperator
default operator for EDGE element
Definition: EdgeElementForcesAndSourcesCore.hpp:68
NonlinearPoissonOps::OpBoundaryTangentMatrix::locBoundaryLhs
MatrixDouble locBoundaryLhs
Definition: nonlinear_poisson_2d.hpp:304
FaceEle
MoFEM::FaceElementForcesAndSourcesCore FaceEle
Definition: boundary_marker.cpp:16
NonlinearPoissonOps::OpDomainTangentMatrix::locLhs
MatrixDouble locLhs
Definition: nonlinear_poisson_2d.hpp:132
Range
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
MoFEM::EntitiesFieldData::EntData::getFTensor1DiffN
FTensor::Tensor1< FTensor::PackPtr< double *, Tensor_Dim >, Tensor_Dim > getFTensor1DiffN(const FieldApproximationBase base)
Get derivatives of base functions.
Definition: EntitiesFieldData.cpp:526
MoFEM::vectorDuplicate
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
Definition: PetscSmartObj.hpp:217
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
_IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
Definition: MeshsetsManager.hpp:71
NonlinearPoissonOps::OpBoundaryTangentMatrix::OpBoundaryTangentMatrix
OpBoundaryTangentMatrix(std::string row_field_name, std::string col_field_name)
Definition: nonlinear_poisson_2d.hpp:233
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
NonlinearPoissonOps::OpDomainTangentMatrix::boundaryMarker
boost::shared_ptr< std::vector< unsigned char > > boundaryMarker
Definition: nonlinear_poisson_2d.hpp:131
BLOCKSET
@ BLOCKSET
Definition: definitions.h:148
NonlinearPoissonOps::DataAtGaussPoints::fieldValue
VectorDouble fieldValue
Definition: nonlinear_poisson_2d.hpp:25
MoFEM::Simple::getBoundaryFEName
const std::string getBoundaryFEName() const
Get the Boundary FE Name.
Definition: Simple.hpp:348
MoFEM::DMMoFEMGetProblemPtr
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition: DMMoFEM.cpp:430
MoFEM::OpInvertMatrix
Definition: UserDataOperators.hpp:3254
NonlinearPoisson::domainTangentMatrixPipeline
boost::shared_ptr< FaceEle > domainTangentMatrixPipeline
Definition: nonlinear_poisson_2d.cpp:62
NonlinearPoissonOps::OpDomainTangentMatrix::OpDomainTangentMatrix
OpDomainTangentMatrix(std::string row_field_name, std::string col_field_name, boost::shared_ptr< DataAtGaussPoints > &common_data, boost::shared_ptr< std::vector< unsigned char >> boundary_marker=nullptr)
Definition: nonlinear_poisson_2d.hpp:31
MoFEM::Types::VectorDouble
UBlasVector< double > VectorDouble
Definition: Types.hpp:68
MoFEM::Simple::addBoundaryField
MoFEMErrorCode addBoundaryField(const std::string &name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on boundary.
Definition: Simple.cpp:282
NonlinearPoissonOps::DataAtGaussPoints::fieldGrad
MatrixDouble fieldGrad
Definition: nonlinear_poisson_2d.hpp:26
NonlinearPoisson::setupProblem
MoFEMErrorCode setupProblem()
Definition: nonlinear_poisson_2d.cpp:124
NonlinearPoissonOps::OpDomainResidualVector::commonData
boost::shared_ptr< DataAtGaussPoints > commonData
Definition: nonlinear_poisson_2d.hpp:226
MoFEM::Problem
keeps basic data about problem
Definition: ProblemsMultiIndices.hpp:54
NonlinearPoisson::boundaryResidualVectorPipeline
boost::shared_ptr< EdgeEle > boundaryResidualVectorPipeline
Definition: nonlinear_poisson_2d.cpp:65
MoFEM::SmartPetscObj< DM >
NonlinearPoissonOps::OpBoundaryResidualVector::doWork
MoFEMErrorCode doWork(int side, EntityType type, EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Definition: nonlinear_poisson_2d.hpp:314
MoFEM::Simple::setUp
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition: Simple.cpp:611
MoFEM::Problem::getName
auto getName() const
Definition: ProblemsMultiIndices.hpp:372
MoFEM::Simple::getProblemName
const std::string getProblemName() const
Get the Problem Name.
Definition: Simple.hpp:362
NonlinearPoissonOps::ScalarFunc
boost::function< double(const double, const double, const double)> ScalarFunc
Definition: nonlinear_poisson_2d.hpp:20
MoFEM::DMoFEMLoopFiniteElements
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition: DMMoFEM.cpp:590
MoFEM::DataOperator::sYmm
bool sYmm
If true assume that matrix is symmetric structure.
Definition: DataOperators.hpp:82
convert.int
int
Definition: convert.py:64
MoFEM::PetscOptionsGetInt
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
Definition: DeprecatedPetsc.hpp:142
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
NonlinearPoissonOps::OpBoundaryResidualVector
Definition: nonlinear_poisson_2d.hpp:307
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
MoFEM::ForcesAndSourcesCore::UserDataOperator::getFTensor1CoordsAtGaussPts
auto getFTensor1CoordsAtGaussPts()
Get coordinates at integration points assuming linear geometry.
Definition: ForcesAndSourcesCore.hpp:1268
NonlinearPoisson::postProc
boost::shared_ptr< PostProcEle > postProc
Definition: nonlinear_poisson_2d.cpp:75
NonlinearPoisson::readMesh
MoFEMErrorCode readMesh()
Definition: nonlinear_poisson_2d.cpp:114
NonlinearPoisson::boundaryEntitiesForFieldsplit
Range boundaryEntitiesForFieldsplit
Definition: nonlinear_poisson_2d.cpp:78
NonlinearPoisson::dM
SmartPetscObj< DM > dM
Definition: nonlinear_poisson_2d.cpp:51
MoFEM::ForcesAndSourcesCore::UserDataOperator::OPROW
@ OPROW
operator doWork function is executed on FE rows
Definition: ForcesAndSourcesCore.hpp:567
MoFEM::DMMoFEMSNESSetFunction
PetscErrorCode DMMoFEMSNESSetFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES residual evaluation function
Definition: DMMoFEM.cpp:722
MoFEM::OpPostProcMapInMoab
Post post-proc data at points from hash maps.
Definition: PostProcBrokenMeshInMoabBase.hpp:698