v0.14.0
field_evaluator.cpp

test segments distance

/** \file field_evaluator.cpp
* \example field_evaluator.cpp
* \brief test segments distance
*
* \ingroup field_evaluator
*/
#include <MoFEM.hpp>
using namespace MoFEM;
static char help[] = "testing field evaluator\n\n";
/**
* @brief Operator used to check consistency between local coordinates
* and global cooridnates for integrated points and evaluated points
*
*/
template <typename OP> struct MyOp : public OP {
MatrixShallowArrayAdaptor<double> evalPoints;
MyOp(std::array<double, 12> &eval_points)
: OP("FIELD1", OP::OPROW),
evalPoints(
getMatrixAdaptor(eval_points.data(), eval_points.size() / 3, 3)) {}
MoFEMErrorCode doWork(int side, EntityType type,
if (type == MBVERTEX) {
MOFEM_LOG("SELF", Sev::inform) << "FE " << OP::getFEEntityHandle();
MOFEM_LOG("SELF", Sev::inform) << "Integration pts" << std::endl;
MOFEM_LOG("SELF", Sev::inform) << OP::getGaussPts() << endl;
MOFEM_LOG("SELF", Sev::inform) << "Global coordinates " << endl;
MOFEM_LOG("SELF", Sev::inform) << OP::getCoordsAtGaussPts() << std::endl;
for (int gg = 0; gg != OP::getCoordsAtGaussPts().size1(); ++gg) {
int pt_number = OP::getGaussPts()(OP::getGaussPts().size1() - 1, gg);
MOFEM_LOG("SELF", Sev::inform) << "gg " << gg << std::endl;
MOFEM_LOG("SELF", Sev::inform) << "pt " << pt_number << std::endl;
ublas::matrix_row<MatrixDouble> coord_at_gauss_pt(
OP::getCoordsAtGaussPts(), gg);
ublas::matrix_row<MatrixShallowArrayAdaptor<double>> eval_coord(
evalPoints, pt_number);
MOFEM_LOG("SELF", Sev::inform) << "coord_at_gauss_pt ";
MOFEM_LOG("SELF", Sev::inform) << coord_at_gauss_pt << std::endl;
MOFEM_LOG("SELF", Sev::inform) << "eval_coord ";
MOFEM_LOG("SELF", Sev::inform) << eval_coord << std::endl;
double error = norm_2(coord_at_gauss_pt - eval_coord);
if (error > 1e-12)
SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
"Difference at %d error = %3.4e", pt_number, error);
}
}
}
};
// Lambda function is used to set integration rule to -1, that indicates
// that finite element instace will use non-standard integration points.
auto get_rule = [](int order_row, int order_col, int order_data) {
return -1;
};
int main(int argc, char *argv[]) {
MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
try {
// Read mesh and create moab and mofem data structures
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
MoFEM::Core core(moab, PETSC_COMM_WORLD);
MoFEM::Interface &m_field = core;
// Register DM Manager
DMType dm_name = "DMMOFEM";
// Simple interface
Simple *simple_interface;
CHKERR m_field.getInterface(simple_interface);
{
// get options from command line
CHKERR simple_interface->getOptions();
// load mesh file
CHKERR simple_interface->loadFile();
// add fields
CHKERR simple_interface->addDomainField("FIELD1", H1,
// set fields order
CHKERR simple_interface->setFieldOrder("FIELD1", 1);
// setup problem
CHKERR simple_interface->setUp();
FieldEvaluatorInterface *field_eval_ptr;
CHKERR m_field.getInterface(field_eval_ptr);
auto dm = simple_interface->getDM();
const MoFEM::Problem *prb_ptr;
if (simple_interface->getDim() == 3) {
std::array<double, 3> point = {0, 0, 0};
const double dist = 0.1;
std::array<double, 12> eval_points = {0.0, 0.0, 0.0, 0.0, 0.01, 0.0,
-0.1, 0.0, 0.0, 0.1, 0.0, 0.0};
// Get pointer of FieldEvaluator data. Note finite element and method
// set integrating points is destroyed when this pointer is releases
auto data = field_eval_ptr->getData<VolEle>();
// Set operators and integration rule
if (auto fe_method = data->feMethodPtr.lock()) {
fe_method->getRuleHook = get_rule;
fe_method->getOpPtrVector().push_back(new MyOp<VolOp>(eval_points));
} else
SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
"Pointer to element does not exists");
// Build tree for particular element
CHKERR field_eval_ptr->buildTree3D(data,
simple_interface->getDomainFEName());
// Set points to set on finite elements
data->setEvalPoints(eval_points.data(), eval_points.size() / 3);
// Evaluate points on finite elements
CHKERR field_eval_ptr->evalFEAtThePoint3D(
&point[0], dist, prb_ptr->getName(),
simple_interface->getDomainFEName(), data, m_field.get_comm_rank(),
m_field.get_comm_rank(), nullptr, MF_EXIST, VERY_NOISY);
}
if (simple_interface->getDim() == 2) {
std::array<double, 3> point = {0, 0, 0};
const double dist = 0.1;
std::array<double, 12> eval_points = {
0.0, 0.0, 0.0,
0.0, 0.01, 0.0,
-0.1, 0.0, 0.0,
0.1, 0.0, 0.0};
// Get pointer of FieldEvaluator data. Note finite element and method
// set integrating points is destroyed when this pointer is releases
auto data = field_eval_ptr->getData<FaceEle>();
// Set operators and integration rule
if (auto fe_method = data->feMethodPtr.lock()) {
fe_method->getRuleHook = get_rule;
fe_method->getOpPtrVector().push_back(new MyOp<FaceOp>(eval_points));
} else
SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
"Pointer to element does not exists");
// Build tree for particular element
CHKERR field_eval_ptr->buildTree2D(data,
simple_interface->getDomainFEName());
// Set points to set on finite elements
data->setEvalPoints(eval_points.data(), eval_points.size() / 3);
// Evaluate points on finite elements
CHKERR field_eval_ptr->evalFEAtThePoint2D(
&point[0], dist, prb_ptr->getName(),
simple_interface->getDomainFEName(), data, m_field.get_comm_rank(),
m_field.get_comm_rank(), nullptr, MF_EXIST, VERY_NOISY);
}
}
}
return 0;
}
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
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
H1
@ H1
continuous field
Definition: definitions.h:85
help
static char help[]
Definition: field_evaluator.cpp:14
MoFEM::ForcesAndSourcesCore::getRuleHook
RuleHookFun getRuleHook
Hook to get rule.
Definition: ForcesAndSourcesCore.hpp:42
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
VERY_NOISY
@ VERY_NOISY
Definition: definitions.h:212
MoFEM::CoreInterface::get_comm_rank
virtual int get_comm_rank() const =0
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
MoFEM.hpp
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::Simple
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
MoFEM::Simple::getOptions
MoFEMErrorCode getOptions()
get options
Definition: Simple.cpp:180
MoFEM::FieldEvaluatorInterface::buildTree3D
MoFEMErrorCode buildTree3D(boost::shared_ptr< SetPtsData > spd_ptr, const std::string finite_element)
Build spatial tree.
Definition: FieldEvaluator.cpp:57
MoFEM::Simple::getDM
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition: Simple.cpp:667
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::FaceElementForcesAndSourcesCore::UserDataOperator
friend class UserDataOperator
Definition: FaceElementForcesAndSourcesCore.hpp:86
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::FieldEvaluatorInterface::buildTree2D
MoFEMErrorCode buildTree2D(boost::shared_ptr< SetPtsData > spd_ptr, const std::string finite_element)
Build spatial tree.
Definition: FieldEvaluator.cpp:63
MoFEM::FaceElementForcesAndSourcesCore::UserDataOperator
default operator for TRI element
Definition: FaceElementForcesAndSourcesCore.hpp:94
MoFEM::FieldEvaluatorInterface
Field evaluator interface.
Definition: FieldEvaluator.hpp:21
convert.type
type
Definition: convert.py:64
MoFEM::FieldEvaluatorInterface::evalFEAtThePoint3D
MoFEMErrorCode evalFEAtThePoint3D(const double *const point, const double distance, const std::string problem, const std::string finite_element, boost::shared_ptr< SetPtsData > data_ptr, int lower_rank, int upper_rank, boost::shared_ptr< CacheTuple > cache_ptr, MoFEMTypes bh=MF_EXIST, VERBOSITY_LEVELS verb=QUIET)
Evaluate field at artbitray position.
Definition: FieldEvaluator.cpp:364
MoFEM::VolumeElementForcesAndSourcesCore::UserDataOperator
friend class UserDataOperator
Definition: VolumeElementForcesAndSourcesCore.hpp:105
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::DMRegister_MoFEM
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMoFEM.cpp:47
MoFEM::getMatrixAdaptor
auto getMatrixAdaptor(T1 ptr, const size_t n, const size_t m)
Get Matrix adaptor.
Definition: Templates.hpp:57
MoFEM::Simple::getDomainFEName
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition: Simple.hpp:341
MoFEM::FaceElementForcesAndSourcesCore
Face finite element.
Definition: FaceElementForcesAndSourcesCore.hpp:23
MoFEM::VolumeElementForcesAndSourcesCore
Volume finite element base.
Definition: VolumeElementForcesAndSourcesCore.hpp:26
MoFEM::FieldEvaluatorInterface::getData
boost::shared_ptr< SPD > getData(const double *ptr=nullptr, const int nb_eval_points=0, const double eps=1e-12, VERBOSITY_LEVELS verb=QUIET)
Get the Data object.
Definition: FieldEvaluator.hpp:107
MoFEM::VolumeElementForcesAndSourcesCore::UserDataOperator
Definition: VolumeElementForcesAndSourcesCore.hpp:108
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::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_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
MyOp
Operator used to check consistency between local coordinates and global cooridnates for integrated po...
Definition: field_evaluator.cpp:21
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::DMMoFEMGetProblemPtr
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition: DMMoFEM.cpp:430
MoFEM::Simple::getDim
int getDim() const
Get the problem dimension.
Definition: Simple.hpp:285
get_rule
auto get_rule
Definition: field_evaluator.cpp:73
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
MoFEM::Problem
keeps basic data about problem
Definition: ProblemsMultiIndices.hpp:54
MoFEM::FieldEvaluatorInterface::evalFEAtThePoint2D
MoFEMErrorCode evalFEAtThePoint2D(const double *const point, const double distance, const std::string problem, const std::string finite_element, boost::shared_ptr< SetPtsData > data_ptr, int lower_rank, int upper_rank, boost::shared_ptr< CacheTuple > cache_ptr, MoFEMTypes bh=MF_EXIST, VERBOSITY_LEVELS verb=QUIET)
Evaluate field at artbitray position.
Definition: FieldEvaluator.cpp:373
main
int main(int argc, char *argv[])
Definition: field_evaluator.cpp:77
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
OP
MF_EXIST
@ MF_EXIST
Definition: definitions.h:100
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