/** \file forces_and_sources_testing_flat_prism_element.cpp
* \brief test for flat prism element
* \example forces_and_sources_testing_flat_prism_element.cpp
/* This file is part of MoFEM.
* MoFEM is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
* MoFEM is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
#include <MoFEM.hpp>
namespace bio = boost::iostreams;
using bio::stream;
using bio::tee_device;
using namespace MoFEM;
static char help[] = "...\n\n";
int main(int argc, char *argv[]) {
MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
try {
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
if (pcomm == NULL)
pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
PetscBool flg = PETSC_TRUE;
char mesh_file_name[255];
#if PETSC_VERSION_GE(3, 6, 4)
CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
255, &flg);
CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
mesh_file_name, 255, &flg);
if (flg != PETSC_TRUE) {
const char *option;
option = ""; //"PARALLEL=BCAST;";//;DEBUG_IO";
CHKERR moab.load_file(mesh_file_name, 0, option);
// Create MoFEM (Joseph) database
MoFEM::Core core(moab);
MoFEM::Interface &m_field = core;
PrismInterface *interface;
CHKERR m_field.getInterface(interface);
// set entitities bit level
CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
0, 3, BitRefLevel().set(0));
std::vector<BitRefLevel> bit_levels;
int ll = 1;
// {
CHKERR PetscPrintf(PETSC_COMM_WORLD, "Insert Interface %d\n",
EntityHandle cubit_meshset = cit->getMeshset();
// get tet enties form back bit_level
EntityHandle ref_level_meshset = 0;
CHKERR moab.create_meshset(MESHSET_SET, ref_level_meshset);
CHKERR m_field.getInterface<BitRefManager>()
BitRefLevel().set(), MBTET,
CHKERR m_field.getInterface<BitRefManager>()
BitRefLevel().set(), MBPRISM,
Range ref_level_tets;
CHKERR moab.get_entities_by_handle(ref_level_meshset, ref_level_tets,
// get faces and test to split
CHKERR interface->getSides(cubit_meshset, bit_levels.back(), true, 0);
// set new bit level
// split faces and
CHKERR interface->splitSides(ref_level_meshset, bit_levels.back(),
cubit_meshset, true, true, 0);
// clean meshsets
CHKERR moab.delete_entities(&ref_level_meshset, 1);
// update cubit meshsets
for (_IT_CUBITMESHSETS_FOR_LOOP_(m_field, ciit)) {
EntityHandle cubit_meshset = ciit->meshset;
CHKERR m_field.getInterface<BitRefManager>()
->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
cubit_meshset, MBVERTEX, true);
CHKERR m_field.getInterface<BitRefManager>()
->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
cubit_meshset, MBEDGE, true);
CHKERR m_field.getInterface<BitRefManager>()
->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
cubit_meshset, MBTRI, true);
CHKERR m_field.getInterface<BitRefManager>()
->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
cubit_meshset, MBTET, true);
// Fields
CHKERR m_field.add_field("FIELD1", H1, AINSWORTH_LEGENDRE_BASE, 3);
CHKERR m_field.add_field("FIELD2", NOFIELD, NOBASE, 3);
// Creating and adding no field entities.
const double coords[] = {0, 0, 0};
EntityHandle no_field_vertex;
CHKERR m_field.get_moab().create_vertex(coords, no_field_vertex);
Range range_no_field_vertex;
CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevel(
range_no_field_vertex, BitRefLevel().set());
EntityHandle meshset = m_field.get_field_meshset("FIELD2");
CHKERR m_field.get_moab().add_entities(meshset, range_no_field_vertex);
// FE
CHKERR m_field.add_finite_element("TEST_FE1");
CHKERR m_field.add_finite_element("TEST_FE2");
// Define rows/cols and element data
CHKERR m_field.modify_finite_element_add_field_row("TEST_FE1", "FIELD1");
CHKERR m_field.modify_finite_element_add_field_col("TEST_FE1", "FIELD1");
CHKERR m_field.modify_finite_element_add_field_data("TEST_FE1", "FIELD1");
CHKERR m_field.modify_finite_element_add_field_row("TEST_FE2", "FIELD1");
// CHKERR m_field.modify_finite_element_add_field_row("TEST_FE2","FIELD2");
// CHKERR m_field.modify_finite_element_add_field_col("TEST_FE2","FIELD1");
CHKERR m_field.modify_finite_element_add_field_col("TEST_FE2", "FIELD2");
CHKERR m_field.modify_finite_element_add_field_data("TEST_FE2", "FIELD1");
CHKERR m_field.modify_finite_element_add_field_data("TEST_FE2", "FIELD2");
// Problem
CHKERR m_field.add_problem("TEST_PROBLEM");
// set finite elements for problem
CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM",
CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM",
// set refinement level for problem
CHKERR m_field.modify_problem_ref_level_add_bit("TEST_PROBLEM",
// meshset consisting all entities in mesh
EntityHandle root_set = moab.get_root_set();
// add entities to field
CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "FIELD1");
CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET,
// add entities to finite element
CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBPRISM,
"TEST_FE1", 10);
CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBPRISM,
"TEST_FE2", 10);
// set app. order
// see Hierarchic Finite Element Bases on Unstructured Tetrahedral Meshes
// (Mark Ainsworth & Joe Coyle)
int order = 3;
CHKERR m_field.set_field_order(root_set, MBTET, "FIELD1", order);
CHKERR m_field.set_field_order(root_set, MBTRI, "FIELD1", order);
CHKERR m_field.set_field_order(root_set, MBEDGE, "FIELD1", order);
CHKERR m_field.set_field_order(root_set, MBVERTEX, "FIELD1", 1);
CHKERR m_field.set_field_order(root_set, MBTET, "MESH_NODE_POSITIONS", 2);
CHKERR m_field.set_field_order(root_set, MBTRI, "MESH_NODE_POSITIONS", 2);
CHKERR m_field.set_field_order(root_set, MBEDGE, "MESH_NODE_POSITIONS", 2);
CHKERR m_field.set_field_order(root_set, MBVERTEX, "MESH_NODE_POSITIONS",
// build database
// build field
CHKERR m_field.build_fields();
// set FIELD1 from positions of 10 node tets
Projection10NodeCoordsOnField ent_method_field1(m_field, "FIELD1");
CHKERR m_field.loop_dofs("FIELD1", ent_method_field1);
Projection10NodeCoordsOnField ent_method_mesh_positions(
CHKERR m_field.loop_dofs("MESH_NODE_POSITIONS", ent_method_mesh_positions);
// build finite elemnts
// build adjacencies
CHKERR m_field.build_adjacencies(bit_levels.back());
// build problem
ProblemsManager *prb_mng_ptr;
CHKERR m_field.getInterface(prb_mng_ptr);
CHKERR prb_mng_ptr->buildProblem("TEST_PROBLEM", false);
// mesh partitioning
// partition
CHKERR prb_mng_ptr->partitionSimpleProblem("TEST_PROBLEM");
CHKERR prb_mng_ptr->partitionFiniteElements("TEST_PROBLEM");
// what are ghost nodes, see Petsc Manual
CHKERR prb_mng_ptr->partitionGhostDofs("TEST_PROBLEM");
typedef tee_device<std::ostream, std::ofstream> TeeDevice;
typedef stream<TeeDevice> TeeStream;
std::ofstream ofs("forces_and_sources_testing_flat_prism_element.txt");
TeeDevice my_tee(std::cout, ofs);
TeeStream my_split(my_tee);
struct MyOp
TeeStream &mySplit;
MyOp(TeeStream &mySplit, const char type)
"FIELD1", "FIELD1", type),
mySplit(mySplit) {}
MoFEMErrorCode doWork(int side, EntityType type,
if (data.getFieldData().empty())
const double eps = 1e-4;
for (DoubleAllocator::iterator it = getNormal().data().begin();
it != getNormal().data().end(); it++) {
*it = fabs(*it) < eps ? 0.0 : *it;
for (DoubleAllocator::iterator it =
it != getNormalsAtGaussPtF3().data().end(); it++) {
*it = fabs(*it) < eps ? 0.0 : *it;
for (DoubleAllocator::iterator it =
it != getTangent1AtGaussPtF3().data().end(); it++) {
*it = fabs(*it) < eps ? 0.0 : *it;
for (DoubleAllocator::iterator it =
it != getTangent2AtGaussPtF3().data().end(); it++) {
*it = fabs(*it) < eps ? 0.0 : *it;
for (DoubleAllocator::iterator it =
it != getNormalsAtGaussPtF4().data().end(); it++) {
*it = fabs(*it) < eps ? 0.0 : *it;
for (DoubleAllocator::iterator it =
it != getTangent1AtGaussPtF4().data().end(); it++) {
*it = fabs(*it) < eps ? 0.0 : *it;
for (DoubleAllocator::iterator it =
it != getTangent2AtGaussPtF4().data().end(); it++) {
*it = fabs(*it) < eps ? 0.0 : *it;
mySplit << "NH1" << std::endl;
mySplit << "side: " << side << " type: " << type << std::endl;
mySplit << data << std::endl;
mySplit << std::setprecision(3) << getCoords() << std::endl;
mySplit << std::setprecision(3) << getCoordsAtGaussPts() << std::endl;
mySplit << std::setprecision(3) << getArea(0) << std::endl;
mySplit << std::setprecision(3) << getArea(1) << std::endl;
mySplit << std::setprecision(3) << "normal F3 " << getNormalF3()
<< std::endl;
mySplit << std::setprecision(3) << "normal F4 " << getNormalF4()
<< std::endl;
mySplit << std::setprecision(3) << "normal at Gauss pt F3 "
<< getNormalsAtGaussPtF3() << std::endl;
mySplit << std::setprecision(3) << getTangent1AtGaussPtF3()
<< std::endl;
mySplit << std::setprecision(3) << getTangent2AtGaussPtF3()
<< std::endl;
mySplit << std::setprecision(3) << "normal at Gauss pt F4 "
<< getNormalsAtGaussPtF4() << std::endl;
mySplit << std::setprecision(3) << getTangent1AtGaussPtF4()
<< std::endl;
mySplit << std::setprecision(3) << getTangent2AtGaussPtF4()
<< std::endl;
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type,
EntityType col_type,
if (row_data.getFieldData().empty())
mySplit << "NH1NH1" << std::endl;
mySplit << "row side: " << row_side << " row_type: " << row_type
<< std::endl;
mySplit << row_data << std::endl;
mySplit << "NH1NH1" << std::endl;
mySplit << "col side: " << col_side << " col_type: " << col_type
<< std::endl;
mySplit << row_data << std::endl;
struct MyOp2
TeeStream &mySplit;
MyOp2(TeeStream &my_split, const char type)
"FIELD1", "FIELD2", type),
mySplit(my_split) {}
MoFEMErrorCode doWork(int side, EntityType type,
if (type != MBENTITYSET)
mySplit << "NPFIELD" << std::endl;
mySplit << "side: " << side << " type: " << type << std::endl;
mySplit << data << std::endl;
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type,
EntityType col_type,
if (col_type != MBENTITYSET)
mySplit << "NOFILEDH1" << std::endl;
mySplit << "row side: " << row_side << " row_type: " << row_type
<< std::endl;
mySplit << row_data << std::endl;
mySplit << "col side: " << col_side << " col_type: " << col_type
<< std::endl;
mySplit << col_data << std::endl;
FlatPrismElementForcesAndSourcesCore fe1(m_field);
CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "TEST_FE1", fe1);
FlatPrismElementForcesAndSourcesCore fe2(m_field);
CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "TEST_FE2", fe2);
return 0;
Catch errors.
Definition: definitions.h:441
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:152
Definition: definitions.h:151
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:516
scalar or vector of scalars describe (no true field)
Definition: definitions.h:176
@ H1
continuous field
Definition: definitions.h:177
default communicator number PCOMM
Definition: definitions.h:292
Definition: definitions.h:216
#define CHKERR
Inline error check.
Definition: definitions.h:604
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:509
tee_device< std::ostream, std::ofstream > TeeDevice
int main(int argc, char *argv[])
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string &name_row)=0
set field row which finite element use
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string &name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string &name_filed)=0
set finite element field data
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string &name_row)=0
set field col which finite element use
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
Iterator that loops over all the Cubit MeshSets in a moFEM field.
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
virtual MoFEMErrorCode modify_problem_add_finite_element(const std::string &name_problem, const std::string &fe_name)=0
add finite element to problem, this add entities assigned to finite element to a particular problem
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
char mesh_file_name[255]
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
CoreTmp< 0 > Core
Definition: Core.hpp:1129
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1943
DataForcesAndSourcesCore::EntData EntData
virtual EntityHandle get_field_meshset(const std::string name) const =0
get field meshset
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
virtual MoFEMErrorCode add_field(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_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
virtual moab::Interface & get_moab()=0
Core (interface) class.
Definition: Core.hpp:77
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:60
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:100
Deprecated interface functions.
DEPRECATED MoFEMErrorCode loop_finite_elements(const Problem *problem_ptr, const std::string &fe_name, FEMethod &method, int lower_rank, int upper_rank, MoFEMTypes bh, int verb=DEFAULT_VERBOSITY)
MoFEMErrorCode getInterface(const MOFEMuuid &uuid, IFACE *&iface) const
Get interface by uuid and return reference to pointer of interface.