|
| v0.14.0
|
Go to the documentation of this file.
7 inline double sqr(
double x) {
return x * x; }
20 PETSC>::LinearForm<GAUSS>::OpSource<1, 1>;
22 static 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));
79 enum VecElements { ERROR_L2_NORM = 0, ERROR_H1_SEMINORM, LAST_ELEMENT };
89 boost::shared_ptr<CommonData> &common_data_ptr,
92 commonDataPtr(common_data_ptr), mField(m_field) {
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); };
204 CHKERR pipeline_mng->setDomainLhsIntegrationRule(domain_rule_lhs);
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");
326 int main(
int argc,
char *argv[]) {
329 const char param_file[] =
"param_file.petsc";
333 auto core_log = logging::core::get();
335 LogManager::createSink(LogManager::getStrmWorld(),
"EXAMPLE"));
336 LogManager::setLog(
"EXAMPLE");
342 DMType dm_name =
"DMMOFEM";
369 const int nb_integration_pts = getGaussPts().size2();
370 const double area = getMeasure();
371 auto t_w = getFTensor0IntegrationWeight();
373 auto t_val_grad = getFTensor1FromMat<2>(*(
commonDataPtr->approxValsGrad));
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));
390 auto t_fun_grad = getFTensor1FromArray<2, 2>(vec);
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;
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
boost::shared_ptr< CommonData > commonDataPtr
MoFEMErrorCode runProgram()
Data on single entity (This is passed as argument to DataOperator::doWork)
boost::shared_ptr< FEMethod > & getDomainRhsFE()
boost::shared_ptr< MatrixDouble > approxValsGrad
static VectorDouble analyticalFunctionGrad(const double x, const double y, const double z)
[Analytical function]
boost::shared_ptr< VectorDouble > approxVals
virtual MPI_Comm & get_comm() const =0
MoFEMErrorCode loopFiniteElements(SmartPetscObj< DM > dm=nullptr)
Iterate finite elements.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
[OpError]
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
boost::ptr_deque< UserDataOperator > & getOpDomainRhsPipeline()
Get the Op Domain Rhs Pipeline object.
virtual int get_comm_rank() const =0
constexpr auto domainField
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
PipelineManager interface.
boost::shared_ptr< std::vector< unsigned char > > boundaryMarker
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Simple interface for fast problem set-up.
int main(int argc, char *argv[])
MoFEMErrorCode VecSetValues(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Assemble PETSc vector.
Deprecated interface functions.
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
DeprecatedCoreInterface Interface
MoFEMErrorCode getOptions()
get options
MoFEMErrorCode getDM(DM *dm)
Get DM.
#define CHKERR
Inline error check.
auto createDMVector(DM dm)
Get smart vector from DM.
auto createGhostVector(MPI_Comm comm, PetscInt n, PetscInt N, PetscInt nghost, const PetscInt ghosts[])
Create smart ghost vector.
implementation of Data Operators for Forces and Sources
MoFEM::Interface & mField
Simple interface for fast problem set-up.
Range boundaryEntitiesForFieldsplit
MoFEMErrorCode setupProblem()
MoFEM::FaceElementForcesAndSourcesCore FaceEle
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
Get value at integration points for scalar field.
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.
SmartPetscObj< KSP > createKSP(SmartPetscObj< DM > dm=nullptr)
Create KSP (linear) solver.
static double sourceFunction(const double x, const double y, const double z)
[Analytical function gradient]
MoFEMErrorCode readMesh()
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
StandardPoisson(MoFEM::Interface &m_field)
MoFEMErrorCode outputResults()
[Check error]
SmartPetscObj< Vec > petscVec
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
FTensor::Index< 'i', SPACE_DIM > i
MoFEMErrorCode setIntegrationRules()
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Add operators pushing bases from local to physical configuration.
MoFEMErrorCode checkError()
[Check error]
OpError(std::string domain_field, boost::shared_ptr< CommonData > &common_data_ptr, MoFEM::Interface &m_field)
boost::shared_ptr< FEMethod > & getDomainLhsFE()
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
#define MOFEM_LOG(channel, severity)
Log.
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpGradGrad< 1, 1, SPACE_DIM > OpDomainGradGrad
boost::shared_ptr< CommonData > commonDataPtr
#define CATCH_ERRORS
Catch errors.
ForcesAndSourcesCore::UserDataOperator UserDataOperator
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
MoFEMErrorCode solveSystem()
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpGradGrad< 1, 1, SPACE_DIM > OpDomainGradGrad
UBlasVector< double > VectorDouble
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.
const double D
diffusivity
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< 1, FIELD_DIM > OpDomainSource
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
MoFEM::Interface & mField
const std::string getProblemName() const
Get the Problem Name.
MoFEMErrorCode assembleSystem()
[Create common data]
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
MoFEMErrorCode createCommonData()
[Create common data]
MoFEMErrorCode boundaryCondition()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< 1, 1 > OpDomainSource
Post post-proc data at points from hash maps.
static double analyticalFunction(const double x, const double y, const double z)
[Analytical function]