7inline double sqr(
double x) {
return x * x; }
22static char help[] =
"...\n\n";
46 return exp(-100. * (
sqr(x) +
sqr(y))) * cos(M_PI * x) * cos(M_PI * y);
55 res[0] = -exp(-100. * (
sqr(x) +
sqr(y))) *
56 (200. * x * cos(M_PI * x) + M_PI * sin(M_PI * x)) * cos(M_PI * y);
57 res[1] = -exp(-100. * (
sqr(x) +
sqr(y))) *
58 (200. * y * cos(M_PI * y) + M_PI * sin(M_PI * y)) * cos(M_PI * x);
64 static double sourceFunction(
const double x,
const double y,
const double z) {
65 return -exp(-100. * (
sqr(x) +
sqr(y))) *
67 (x * cos(M_PI * y) * sin(M_PI * x) +
68 y * cos(M_PI * x) * sin(M_PI * y)) +
69 2. * (20000. * (
sqr(x) +
sqr(y)) - 200. -
sqr(M_PI)) *
70 cos(M_PI * x) * cos(M_PI * y));
89 boost::shared_ptr<CommonData> &common_data_ptr,
93 std::fill(&doEntities[MBVERTEX], &doEntities[MBMAXTYPE],
false);
94 doEntities[MBTRI] = doEntities[MBQUAD] =
true;
162 PetscInt ghosts[2] = {0, 1};
169 commonDataPtr->approxVals = boost::make_shared<VectorDouble>();
170 commonDataPtr->approxValsGrad = boost::make_shared<MatrixDouble>();
184 pipeline_mng->getOpDomainLhsPipeline().push_back(
190 pipeline_mng->getOpDomainRhsPipeline().push_back(
202 auto domain_rule_lhs = [](int, int,
int p) ->
int {
return 2 * (p - 1); };
203 auto domain_rule_rhs = [](int, int,
int p) ->
int {
return 2 * (p - 1); };
205 CHKERR pipeline_mng->setDomainRhsIntegrationRule(domain_rule_rhs);
207 auto boundary_rule_lhs = [](int, int,
int p) ->
int {
return 2 * p; };
208 auto boundary_rule_rhs = [](int, int,
int p) ->
int {
return 2 * p; };
209 CHKERR pipeline_mng->setBoundaryLhsIntegrationRule(boundary_rule_lhs);
210 CHKERR pipeline_mng->setBoundaryLhsIntegrationRule(boundary_rule_rhs);
220 auto ksp_solver = pipeline_mng->
createKSP();
221 CHKERR KSPSetFromOptions(ksp_solver);
228 CHKERR KSPSetUp(ksp_solver);
234 CHKERR VecGhostUpdateBegin(
D, INSERT_VALUES, SCATTER_FORWARD);
235 CHKERR VecGhostUpdateEnd(
D, INSERT_VALUES, SCATTER_FORWARD);
268 <<
"Global error L2 norm: " << std::sqrt(array[0]);
270 <<
"Global error H1 seminorm: " << std::sqrt(array[1]);
282 pipeline_mng->getBoundaryLhsFE().reset();
283 pipeline_mng->getDomainRhsFE().reset();
284 pipeline_mng->getBoundaryRhsFE().reset();
288 auto post_proc_fe = boost::make_shared<PostProcFaceEle>(
mField);
292 post_proc_fe->getOpPtrVector().push_back(
294 post_proc_fe->getOpPtrVector().push_back(
298 post_proc_fe->getOpPtrVector().push_back(
new OpPPMap(
299 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
300 {{domainField, commonDataPtr->approxVals}},
301 {{
domainField +
"_GRAD", commonDataPtr->approxValsGrad}}, {}, {}));
302 pipeline_mng->getDomainRhsFE() = post_proc_fe;
304 CHKERR pipeline_mng->loopFiniteElements();
305 CHKERR post_proc_fe->writeFile(
"out_result.h5m");
326int main(
int argc,
char *argv[]) {
329 const char param_file[] =
"param_file.petsc";
333 auto core_log = logging::core::get();
342 DMType dm_name =
"DMMOFEM";
346 moab::Core mb_instance;
347 moab::Interface &moab = mb_instance;
369 const int nb_integration_pts = getGaussPts().size2();
370 const double area = getMeasure();
371 auto t_w = getFTensor0IntegrationWeight();
374 auto t_coords = getFTensor1CoordsAtGaussPts();
381 for (
int gg = 0; gg != nb_integration_pts; ++gg) {
382 const double alpha = t_w * area;
385 t_coords(0), t_coords(1), t_coords(2));
386 error_l2 += alpha *
sqr(diff);
389 t_coords(0), t_coords(1), t_coords(2));
391 t_diff(
i) = t_val_grad(
i) - t_fun_grad(
i);
393 error_h1 += alpha * t_diff(
i) * t_diff(
i);
404 std::array<double, 2> values;
405 values[0] = error_l2;
406 values[1] = error_h1;
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< 1, FIELD_DIM > OpDomainSource
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
[Define dimension]
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base nme:nme847.
#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.
constexpr auto domainField
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
auto createDMVector(DM dm)
Get smart vector from DM.
MoFEMErrorCode loopFiniteElements(SmartPetscObj< DM > dm=nullptr)
Iterate finite elements.
SmartPetscObj< KSP > createKSP(SmartPetscObj< DM > dm=nullptr)
Create KSP (linear) solver.
boost::ptr_deque< UserDataOperator > & getOpDomainRhsPipeline()
Get the Op Domain Rhs Pipeline object.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
FTensor::Index< 'i', SPACE_DIM > i
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpGradGrad< 1, 1, SPACE_DIM > OpDomainGradGrad
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
FTensor::Tensor1< FTensor::PackPtr< T *, S >, Tensor_Dim > getFTensor1FromMat(ublas::matrix< T, L, A > &data)
Get tensor rank 1 (vector) form data matrix.
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
auto createGhostVector(MPI_Comm comm, PetscInt n, PetscInt N, PetscInt nghost, const PetscInt ghosts[])
Create smart ghost vector.
MoFEMErrorCode VecSetValues(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Assemble PETSc vector.
auto getFTensor1FromArray(VectorDouble &data)
Get FTensor1 from array.
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< 1, 1 > OpDomainSource
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpGradGrad< 1, 1, SPACE_DIM > OpDomainGradGrad
Add operators pushing bases from local to physical configuration.
Simple interface for fast problem set-up.
MoFEMErrorCode removeBlockDOFsOnEntities(const std::string problem_name, const std::string block_name, const std::string field_name, int lo, int hi, bool get_low_dim_ents=true, bool is_distributed_mesh=true)
Remove DOFs from problem.
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.
Data on single entity (This is passed as argument to DataOperator::doWork)
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
Get value at integration points for scalar field.
Post post-proc data at points from hash maps.
PipelineManager interface.
boost::shared_ptr< FEMethod > & getDomainRhsFE()
boost::shared_ptr< FEMethod > & getDomainLhsFE()
MoFEM::FaceElementForcesAndSourcesCore FaceEle
MoFEMErrorCode setDomainLhsIntegrationRule(RuleHookFun rule)
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.
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
boost::shared_ptr< VectorDouble > approxVals
SmartPetscObj< Vec > petscVec
boost::shared_ptr< MatrixDouble > approxValsGrad
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
[OpError]
boost::shared_ptr< CommonData > commonDataPtr
MoFEM::Interface & mField
OpError(std::string domain_field, boost::shared_ptr< CommonData > &common_data_ptr, MoFEM::Interface &m_field)
MoFEMErrorCode outputResults()
[Check error]
MoFEMErrorCode setIntegrationRules()
static double analyticalFunction(const double x, const double y, const double z)
[Analytical function]
boost::shared_ptr< CommonData > commonDataPtr
StandardPoisson(MoFEM::Interface &m_field)
static double sourceFunction(const double x, const double y, const double z)
[Analytical function gradient]
MoFEMErrorCode createCommonData()
[Create common data]
MoFEMErrorCode checkError()
[Check error]
MoFEMErrorCode runProgram()
MoFEMErrorCode solveSystem()
MoFEMErrorCode assembleSystem()
[Create common data]
Range boundaryEntitiesForFieldsplit
MoFEMErrorCode setupProblem()
MoFEMErrorCode boundaryCondition()
MoFEMErrorCode readMesh()
boost::shared_ptr< std::vector< unsigned char > > boundaryMarker
MoFEM::Interface & mField
static VectorDouble analyticalFunctionGrad(const double x, const double y, const double z)
[Analytical function]