#ifndef __NONLINEARPOISSON2D_HPP__
#define __NONLINEARPOISSON2D_HPP__
#include <stdlib.h>
typedef boost::function<
double(
const double,
const double,
const double)>
public:
std::string row_field_name, std::string col_field_name,
boost::shared_ptr<VectorDouble> field_vec,
boost::shared_ptr<MatrixDouble> field_grad_mat)
auto &locLhs = AssemblyDomainEleOp::locMat;
const int nb_row_dofs = row_data.
getIndices().size();
const int nb_col_dofs = col_data.
getIndices().size();
const double area = getMeasure();
const int nb_integration_points = getGaussPts().size2();
auto t_w = getFTensor0IntegrationWeight();
auto t_field = getFTensor0FromVec(*
fieldVec);
for (int gg = 0; gg != nb_integration_points; gg++) {
const double a = t_w * area;
for (int rr = 0; rr != nb_row_dofs; ++rr) {
for (int cc = 0; cc != nb_col_dofs; cc++) {
locLhs(rr, cc) += (((1 + t_field * t_field) * t_row_diff_base(
i) *
(2.0 * t_field * t_field_grad(
i) *
t_row_diff_base(
i) * t_col_base)) *
++t_col_base;
++t_col_diff_base;
}
++t_row_base;
++t_row_diff_base;
}
++t_w;
++t_field;
++t_field_grad;
}
}
private:
boost::shared_ptr<VectorDouble>
fieldVec;
};
public:
boost::shared_ptr<VectorDouble> field_vec,
boost::shared_ptr<MatrixDouble> field_grad_mat)
auto &nf = AssemblyDomainEleOp::locF;
const double area = getMeasure();
const int nb_integration_points = getGaussPts().size2();
auto t_w = getFTensor0IntegrationWeight();
auto t_coords = getFTensor1CoordsAtGaussPts();
auto t_field = getFTensor0FromVec(*
fieldVec);
for (int gg = 0; gg != nb_integration_points; gg++) {
const double a = t_w * area;
double body_source =
for (int rr = 0; rr != AssemblyDomainEleOp::nbRows; rr++) {
nf[rr] +=
(-t_base * body_source +
t_grad_base(
i) * t_field_grad(
i) * (1 + t_field * t_field)) *
++t_base;
++t_grad_base;
}
++t_w;
++t_coords;
++t_field;
++t_field_grad;
}
}
private:
boost::shared_ptr<VectorDouble>
fieldVec;
};
};
#endif
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
[Define dimension]
#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()
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
FTensor::Index< 'i', 2 > i
boost::function< double(const double, const double, const double)> ScalarFunc
FormsIntegrators< BoundaryEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< 1, 1 > OpBoundaryRhsSource
FormsIntegrators< BoundaryEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpBaseTimesScalar< 1 > OpBoundaryRhs
FormsIntegrators< BoundaryEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, 1 > OpBoundaryLhs
constexpr auto field_name
OpBaseImpl< PETSC, EdgeEleOp > OpBase
Data on single entity (This is passed as argument to DataOperator::doWork)
FTensor::Tensor1< FTensor::PackPtr< double *, Tensor_Dim >, Tensor_Dim > getFTensor1DiffN(const FieldApproximationBase base)
Get derivatives of base functions.
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0N(const FieldApproximationBase base)
Get base function as Tensor0.
const VectorInt & getIndices() const
Get global indices of dofs on entity.
boost::shared_ptr< VectorDouble > fieldVec
boost::shared_ptr< MatrixDouble > fieldGradMat
MoFEMErrorCode iNtegrate(EntData &row_data, EntData &col_data)
OpDomainLhs(std::string row_field_name, std::string col_field_name, boost::shared_ptr< VectorDouble > field_vec, boost::shared_ptr< MatrixDouble > field_grad_mat)
boost::shared_ptr< VectorDouble > fieldVec
MoFEMErrorCode iNtegrate(EntData &data)
OpDomainRhs(std::string field_name, ScalarFunc source_term_function, boost::shared_ptr< VectorDouble > field_vec, boost::shared_ptr< MatrixDouble > field_grad_mat)
ScalarFunc sourceTermFunc
boost::shared_ptr< MatrixDouble > fieldGradMat
FormsIntegrators< BoundaryEleOp >::Assembly< A >::OpBase AssemblyBoundaryEleOp
FormsIntegrators< DomainEleOp >::Assembly< A >::OpBase AssemblyDomainEleOp
#include <stdlib.h>
static char help[] =
"...\n\n";
inline double sqr(
const double x) {
return x * x; }
inline double cube(
const double x) {
return x * x * x; }
public:
private:
const double z) {
return 2 * M_PI * M_PI *
(cos(M_PI * x) * cos(M_PI * y) +
cube(cos(M_PI * x)) *
cube(cos(M_PI * y)) -
cos(M_PI * x) * cos(M_PI * y) *
(
sqr(sin(M_PI * x)) *
sqr(cos(M_PI * y)) +
sqr(sin(M_PI * y)) *
sqr(cos(M_PI * x))));
}
const double z) {
return -cos(M_PI * x) *
cos(M_PI * y);
}
boost::shared_ptr<PostProcEle>
postProc;
};
: mField(m_field) {}
}
}
true);
auto get_ents_by_dim = [&](const auto dim) {
return domain_ents;
} else {
if (dim == 0)
else
return ents;
}
};
auto get_base = [&]() {
auto domain_ents = get_ents_by_dim(
SPACE_DIM);
if (domain_ents.empty())
switch (type) {
case MBQUAD:
case MBHEX:
case MBTRI:
case MBTET:
default:
}
};
auto base = get_base();
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; };
auto boundary_rule_lhs = [](int, int, int p) -> int { return 2 * p; };
auto boundary_rule_rhs = [](int, int, int p) -> int { return 2 * p; };
CHKERR pipeline_mng->setDomainLhsIntegrationRule(domain_rule_rhs);
CHKERR pipeline_mng->setBoundaryLhsIntegrationRule(boundary_rule_lhs);
CHKERR pipeline_mng->setBoundaryRhsIntegrationRule(boundary_rule_rhs);
}
auto get_ents_on_mesh_skin = [&]() {
std::string entity_name = it->getName();
if (entity_name.compare(0, 18, "BOUNDARY_CONDITION") == 0) {
boundary_entities, true);
}
}
boundary_vertices, true);
boundary_entities.merge(boundary_vertices);
return boundary_entities;
};
auto mark_boundary_dofs = [&](
Range &&skin_edges) {
auto marker_ptr = boost::make_shared<std::vector<unsigned char>>();
ProblemsManager::OR, skin_edges, *marker_ptr);
return marker_ptr;
};
}
auto add_domain_lhs_ops = [&](auto &pipeline) {
auto data_u_at_gauss_pts = boost::make_shared<VectorDouble>();
auto grad_u_at_gauss_pts = boost::make_shared<MatrixDouble>();
pipeline.push_back(
};
auto add_domain_rhs_ops = [&](auto &pipeline) {
auto data_u_at_gauss_pts = boost::make_shared<VectorDouble>();
auto grad_u_at_gauss_pts = boost::make_shared<MatrixDouble>();
pipeline.push_back(
data_u_at_gauss_pts,
grad_u_at_gauss_pts));
};
auto add_boundary_lhs_ops = [&](auto &pipeline) {
[](const double, const double, const double) { return 1; }));
};
auto add_boundary_rhs_ops = [&](auto &pipeline) {
auto u_at_gauss_pts = boost::make_shared<VectorDouble>();
pipeline.push_back(
[](const double, const double, const double) { return 1; }));
};
add_domain_lhs_ops(pipeline_mng->getOpDomainLhsPipeline());
add_domain_rhs_ops(pipeline_mng->getOpDomainRhsPipeline());
add_boundary_lhs_ops(pipeline_mng->getOpBoundaryLhsPipeline());
add_boundary_rhs_ops(pipeline_mng->getOpBoundaryRhsPipeline());
}
auto set_fieldsplit_preconditioner = [&](auto snes) {
KSP ksp;
CHKERR SNESGetKSP(snes, &ksp);
PC pc;
PetscBool is_pcfs = PETSC_FALSE;
PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &is_pcfs);
if (is_pcfs == PETSC_TRUE) {
auto name_prb =
simple->getProblemName();
int is_all_bc_size;
CHKERR ISGetSize(is_all_bc, &is_all_bc_size);
<< "Field split block size " << is_all_bc_size;
CHKERR PCFieldSplitSetIS(pc, PETSC_NULL,
is_all_bc);
}
};
CHKERR SNESSetFromOptions(solver);
CHKERR set_fieldsplit_preconditioner(solver);
CHKERR SNESSolve(solver, global_rhs, global_solution);
SCATTER_REVERSE);
}
auto post_proc = boost::make_shared<PostProcEle>(
mField);
auto u_ptr = boost::make_shared<VectorDouble>();
post_proc->getOpPtrVector().push_back(
post_proc->getOpPtrVector().push_back(
new OpPPMap(post_proc->getPostProcMesh(), post_proc->getMapGaussPts(),
{{domainField, u_ptr}},
{}, {}, {}
)
);
CHKERR post_proc->writeFile(
"out_result.h5m");
}
auto check_result_fe_ptr = boost::make_shared<DomainEle>(
mField);
check_result_fe_ptr->getOpPtrVector(), {H1})),
"Apply transform");
check_result_fe_ptr->getRuleHook = [](int, int, int p) { return p; };
auto analyticalFunction = [&](double x, double y, double z) {
return cos(M_PI * x) * cos(M_PI * y);
};
auto u_ptr = boost::make_shared<VectorDouble>();
check_result_fe_ptr->getOpPtrVector().push_back(
auto mValFuncPtr = boost::make_shared<VectorDouble>();
check_result_fe_ptr->getOpPtrVector().push_back(
check_result_fe_ptr->getOpPtrVector().push_back(
check_result_fe_ptr->getOpPtrVector().push_back(
check_result_fe_ptr);
const double *L2_norms;
const double *Ex_norms;
<<
"L2_NORM: " << std::sqrt(L2_norms[
NORM]);
<< "NORMALISED_ERROR: "
<< (std::sqrt(L2_norms[
NORM]) / std::sqrt(Ex_norms[
EX_NORM]));
}
const double *L2_norms;
const double *Ex_norms;
double ref_percentage = 4.4e-04;
double normalised_error;
case 1:
normalised_error = std::sqrt(L2_norms[0]) / std::sqrt(Ex_norms[0]);
break;
default:
"atom test %d does not exist",
atomTest);
}
if (normalised_error > ref_percentage) {
"atom test %d failed! Calculated Norm %3.16e is greater than "
"reference Norm %3.16e",
atomTest, normalised_error, ref_percentage);
}
}
}
int main(
int argc,
char *argv[]) {
const char param_file[] = "param_file.petsc";
auto core_log = logging::core::get();
core_log->add_sink(
LogManager::createSink(LogManager::getStrmWorld(), "EXAMPLE"));
LogManager::setLog("EXAMPLE");
try {
DMType dm_name = "DMMOFEM";
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
CHKERR poisson_problem.runProgram();
}
return 0;
}
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
void simple(double P1[], double P2[], double P3[], double c[], const int N)
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base nme:nme847.
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ MOFEM_ATOM_TEST_INVALID
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
PetscErrorCode DMCreateGlobalVector_MoFEM(DM dm, Vec *g)
DMShellSetCreateGlobalVector.
PetscErrorCode DMoFEMMeshToGlobalVector(DM dm, Vec g, InsertMode mode, ScatterMode scatter_mode)
set ghosted vector values on all existing mesh entities
SmartPetscObj< SNES > createSNES(SmartPetscObj< DM > dm=nullptr)
Create SNES (nonlinear) solver.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
#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.
auto type_from_handle(const EntityHandle h)
get type from entity handle
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
double sqr(const double x)
double cube(const double x)
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
Section manager is used to create indexes and sections.
Get norm of input VectorDouble for Tensor0.
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
Get value at integration points for scalar field.
Get values from scalar function at integration points and save them to VectorDouble for Tensor0.
Post post-proc data at points from hash maps.
Set indices on entities on finite element.
PipelineManager interface.
MoFEMErrorCode setDomainRhsIntegrationRule(RuleHookFun rule)
Problem manager is used to build and partition problems.
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.
Simple interface for fast problem set-up.
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.
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
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.
MoFEMErrorCode getOptions()
get options
MoFEMErrorCode getDM(DM *dm)
Get DM.
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
const std::string getProblemName() const
Get the Problem Name.
const std::string getDomainFEName() const
Get the Domain FE Name.
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
MoFEMErrorCode outputResults()
MoFEMErrorCode boundaryCondition()
static double boundaryFunction(const double x, const double y, const double z)
MoFEMErrorCode solveSystem()
SmartPetscObj< Vec > errorVec
static double sourceTermFunction(const double x, const double y, const double z)
MoFEMErrorCode checkResults()
[Check]
MoFEMErrorCode readMesh()
SmartPetscObj< Vec > exactVec
MoFEM::Interface & mField
MoFEMErrorCode assembleSystem()
NonlinearPoisson(MoFEM::Interface &m_field)
MoFEMErrorCode setIntegrationRules()
boost::shared_ptr< std::vector< unsigned char > > boundaryMarker
boost::shared_ptr< PostProcEle > postProc
MoFEMErrorCode runProgram()
MoFEMErrorCode setupProblem()
Range boundaryEntitiesForFieldsplit