v0.13.0
dm_build_partitioned_mesh.cpp

Testing problem for partitioned mesh

/** \file dm_build_partitioned_mesh.cpp
\example dm_build_partitioned_mesh.cpp
\brief Testing problem for partitioned mesh
*/
/* 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
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* 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>
using namespace MoFEM;
static char help[] = "...\n\n";
struct CountUp : FEMethod {
CountUp(int &counter) : FEMethod(), cOunter(counter) {}
MoFEMErrorCode preProcess() { return 0; }
MoFEMErrorCode operator()() {
++cOunter;
return 0;
}
MoFEMErrorCode postProcess() { return 0; }
private:
int &cOunter;
};
struct CountDown : FEMethod {
CountDown(int &counter) : FEMethod(), cOunter(counter) {}
MoFEMErrorCode preProcess() { return 0; }
MoFEMErrorCode operator()() {
--cOunter;
return 0;
}
MoFEMErrorCode postProcess() { return 0; }
private:
int &cOunter;
};
int main(int argc, char *argv[]) {
// initialize petsc
MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
try {
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);
#else
CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
mesh_file_name, 255, &flg);
#endif
if (flg != PETSC_TRUE) {
SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
}
// register new dm type, i.e. mofem
DMType dm_name = "DMMOFEM";
// create dm instance
DM dm;
CHKERR DMCreate(PETSC_COMM_WORLD, &dm);
CHKERR DMSetType(dm, dm_name);
// read mesh and create moab and mofem data structures
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
auto moab_comm_wrap =
boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD, false);
if (pcomm == NULL)
pcomm = new ParallelComm(&moab, moab_comm_wrap->get_comm());
const char *option;
option = "PARALLEL=BCAST_DELETE;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION="
"PARALLEL_PARTITION;";
CHKERR moab.load_file(mesh_file_name, 0, option);
MoFEM::Core core(moab, PETSC_COMM_WORLD);
MoFEM::Interface &m_field = core;
EntityHandle root_set = moab.get_root_set();
// add all entities to database, all of them will be used
BitRefLevel bit_level0;
bit_level0.set(0);
CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
root_set, 3, bit_level0);
// define & build field
int field_rank = 3;
#if PETSC_VERSION_GE(3, 6, 4)
CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-my_field_rank", &field_rank,
&flg);
#else
CHKERR PetscOptionsGetInt(PETSC_NULL, PETSC_NULL, "-my_field_rank",
&field_rank, &flg);
#endif
CHKERR m_field.add_field("FIELD1", H1, AINSWORTH_LEGENDRE_BASE, field_rank);
CHKERR m_field.add_field("FIELD2", L2, AINSWORTH_LEGENDRE_BASE, 1);
// 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, "FIELD2");
// set app. order
int order = 4;
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, "FIELD2", order);
// build data structures for fields
CHKERR m_field.build_fields();
// define & build finite elements
CHKERR m_field.add_finite_element("FE");
// Define rows/cols and element data
// Only data
CHKERR m_field.add_finite_element("FE_ONLY_DATA");
"FIELD1");
"FIELD2");
// Add entities to finite element
CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "FE");
CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET,
"FE_ONLY_DATA");
// build finite elemnts
// build adjacencies
CHKERR m_field.build_adjacencies(bit_level0);
// set dm data structure which created mofem data structures
CHKERR DMMoFEMCreateMoFEM(dm, &m_field, "TEST_PROBLEM", bit_level0);
dm, PETSC_FALSE); // this is for testing (this problem has the same rows
// and cols)
CHKERR DMSetFromOptions(dm);
CHKERR DMMoFEMAddElement(dm, "FE_ONLY_DATA");
CHKERR DMSetUp(dm);
// dump data to file, just to check if something was changed
SmartPetscObj<Mat> m;
CHKERR m_field.getInterface<MatrixManager>()
->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>(
"TEST_PROBLEM", -1, -1, 1);
CHKERR m_field.getInterface<MatrixManager>()
->checkMPIAIJMatrixFillIn<PetscGlobalIdx_mi_tag>("TEST_PROBLEM", -1, -1,
1);
std::vector<std::string> fields_list;
fields_list.push_back("FIELD1");
// PetscSection section;
PetscSection section;
CHKERR m_field.getInterface<ISManager>()->sectionCreate("TEST_PROBLEM",
&section);
CHKERR PetscSectionView(section, PETSC_VIEWER_STDOUT_WORLD);
CHKERR DMSetSection(dm, section);
CHKERR PetscSectionDestroy(&section);
PetscBool save_file = PETSC_TRUE;
#if PETSC_VERSION_GE(3, 6, 4)
CHKERR PetscOptionsGetBool(PETSC_NULL, "", "-my_save_file", &save_file,
&flg);
#else
CHKERR PetscOptionsGetBool(PETSC_NULL, PETSC_NULL, "-my_save_file",
&save_file, &flg);
#endif
if (save_file) {
PetscViewer viewer;
CHKERR PetscViewerASCIIOpen(PETSC_COMM_WORLD,
"dm_build_partitioned_mesh.txt", &viewer);
CHKERR PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_INFO);
MatView(m, viewer);
CHKERR PetscViewerDestroy(&viewer);
}
int count = 0;
boost::make_shared<CountUp>(count));
CHKERR DMoFEMLoopFiniteElements(dm, "FE_ONLY_DATA",
boost::make_shared<CountDown>(count));
if (count)
SETERRQ1(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID, "Should be zero %d",
count);
auto check_consistency_of_uids = [&]() {
auto field_ents_ptr = m_field.get_field_ents();
for (auto &fe : *field_ents_ptr) {
if (fe->getOwnerProc() !=
(FieldEntity::getOwnerFromUniqueId(fe->getGlobalUniqueId()))) {
MOFEM_LOG("SELF", Sev::error) << *fe;
MOFEM_LOG("SELF", Sev::error)
<< "UId owner proc "
<< FieldEntity::getOwnerFromUniqueId(fe->getGlobalUniqueId());
MOFEM_LOG("SELF", Sev::error)
<< "Entity owner proc " << fe->getOwnerProc();
SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
"UId and entity handle inconsistency");
}
if (fe->getEnt() !=
FieldEntity::getHandleFromUniqueId(fe->getLocalUniqueId())) {
MOFEM_LOG("SELF", Sev::error) << *fe;
MOFEM_LOG("SELF", Sev::error)
<< "UId handle "
<< FieldEntity::getHandleFromUniqueId(fe->getLocalUniqueId());
MOFEM_LOG("SELF", Sev::error) << "Entity handle " << fe->getEnt();
SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
"UId and entity handle inconsistency");
}
const auto field_bit_number_from_uid =
if (fe->getBitNumber() != field_bit_number_from_uid) {
MOFEM_LOG("SELF", Sev::error) << *fe;
MOFEM_LOG("SELF", Sev::error)
<< "UId field bit " << field_bit_number_from_uid;
MOFEM_LOG("SELF", Sev::error)
<< "Entity owner proc " << fe->getBitNumber();
SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
"UId and entity handle inconsistency");
}
if (fe->getName() != m_field.get_field_name(BitFieldId().set(
field_bit_number_from_uid - 1))) {
MOFEM_LOG("SELF", Sev::error) << *fe;
MOFEM_LOG("SELF", Sev::error)
<< "UId field bit "
<< m_field.get_field_name(
BitFieldId().set(field_bit_number_from_uid - 1));
MOFEM_LOG("SELF", Sev::error)
<< "Entity owner proc " << fe->getName();
SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
"UId and entity handle inconsistency");
}
}
};
CHKERR check_consistency_of_uids();
// destry dm
CHKERR DMDestroy(&dm);
}
// finish work cleaning memory, getting statistics, ect.
return 0;
}
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:73
@ L2
field with C-1 continuity
Definition: definitions.h:101
@ H1
continuous field
Definition: definitions.h:98
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:228
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:53
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:44
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
#define CHKERR
Inline error check.
Definition: definitions.h:548
int main(int argc, char *argv[])
static char help[]
PetscErrorCode DMMoFEMSetIsPartitioned(DM dm, PetscBool is_partitioned)
Definition: DMMMoFEM.cpp:1061
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
Definition: DMMMoFEM.cpp:414
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
Definition: DMMMoFEM.cpp:130
PetscErrorCode DMMoFEMAddElement(DM dm, const char fe_name[])
add element to dm
Definition: DMMMoFEM.cpp:461
PetscErrorCode DMCreateMatrix_MoFEM(DM dm, Mat *M)
Definition: DMMMoFEM.cpp:1135
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMMoFEM.cpp:59
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition: DMMMoFEM.cpp:544
virtual const FieldEntity_multiIndex * get_field_ents() const =0
Get the field ents object.
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.
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:311
char mesh_file_name[255]
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
std::bitset< BITFIELDID_SIZE > BitFieldId
Field Id.
Definition: Types.hpp:53
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
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
CoreTmp< 0 > Core
Definition: Core.hpp:1096
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1965
FTensor::Index< 'm', 3 > m
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
virtual std::string get_field_name(const BitFieldId id) const =0
get field name from id
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.
Core (interface) class.
Definition: Core.hpp:92
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:85
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:125
Deprecated interface functions.
static auto getHandleFromUniqueId(const UId uid)
static auto getFieldBitNumberFromUniqueId(const UId uid)
static auto getOwnerFromUniqueId(const UId uid)
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.