v0.13.1
dm_create_subdm.cpp

Atom test for Data Manager Interface and create sub-problem.

Atom test for Data Manager Interface and create sub-problem

/** \file dm_create_subdm.cpp
\example dm_create_subdm.cpp
\brief Atom test for Data Manager Interface and create sub-problem
*/
#include <MoFEM.hpp>
using namespace MoFEM;
static char help[] = "...\n\n";
static const bool debug = false;
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";
DMType dm_name_sub = "DMSUB";
CHKERR DMRegister_MoFEM(dm_name_sub);
// craete dm instance
DM dm;
CHKERR DMCreate(PETSC_COMM_WORLD, &dm);
CHKERR DMSetType(dm, dm_name);
DM subdm0, subdm1;
CHKERR DMCreate(PETSC_COMM_WORLD, &subdm0);
CHKERR DMSetType(subdm0, dm_name_sub);
CHKERR DMCreate(PETSC_COMM_WORLD, &subdm1);
CHKERR DMSetType(subdm1, dm_name_sub);
// 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);
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
const int field_rank = 1;
CHKERR m_field.add_field("FIELD0", H1, AINSWORTH_LEGENDRE_BASE, field_rank);
// add entities to field
CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "FIELD0");
// set app. order
CHKERR m_field.set_field_order(root_set, MBVERTEX, "FIELD0", 1);
CHKERR m_field.add_field("FIELD1", H1, AINSWORTH_LEGENDRE_BASE, field_rank);
// add entities to field
CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "FIELD1");
// set app. order
CHKERR m_field.set_field_order(root_set, MBVERTEX, "FIELD1", 1);
CHKERR m_field.set_field_order(root_set, MBEDGE, "FIELD1", 2);
// build data structures for fields
CHKERR m_field.build_fields();
// define & build finite elements
CHKERR m_field.add_finite_element("FE00");
// Define rows/cols and element data
CHKERR m_field.modify_finite_element_add_field_row("FE00", "FIELD0");
CHKERR m_field.modify_finite_element_add_field_col("FE00", "FIELD0");
CHKERR m_field.modify_finite_element_add_field_data("FE00", "FIELD0");
// add entities to finite element
CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "FE00");
// define & build finite elements
CHKERR m_field.add_finite_element("FE11");
// Define rows/cols and element data
CHKERR m_field.modify_finite_element_add_field_row("FE11", "FIELD1");
CHKERR m_field.modify_finite_element_add_field_col("FE11", "FIELD1");
CHKERR m_field.modify_finite_element_add_field_data("FE11", "FIELD1");
// add entities to finite element
CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "FE11");
// define & build finite elements
CHKERR m_field.add_finite_element("FE01");
// Define rows/cols and element data
CHKERR m_field.modify_finite_element_add_field_row("FE01", "FIELD0");
CHKERR m_field.modify_finite_element_add_field_col("FE01", "FIELD1");
CHKERR m_field.modify_finite_element_add_field_data("FE01", "FIELD0");
CHKERR m_field.modify_finite_element_add_field_data("FE01", "FIELD1");
// add entities to finite element
CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "FE01");
// 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, "MAIN_PROBLEM", bit_level0);
CHKERR DMSetFromOptions(dm);
CHKERR DMSetUp(dm);
->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>(
"MAIN_PROBLEM", -1, -1, 1);
int nf;
char **field_names;
IS *fields;
CHKERR DMCreateFieldIS(dm, &nf, &field_names, &fields);
for (int f = 0; f != nf; f++) {
PetscPrintf(PETSC_COMM_WORLD, "%d field %s\n", f, field_names[f]);
CHKERR PetscFree(field_names[f]);
CHKERR ISDestroy(&(fields[f]));
}
CHKERR PetscFree(field_names);
CHKERR PetscFree(fields);
CHKERR DMMoFEMCreateSubDM(subdm0, dm, "SUB0");
CHKERR DMMoFEMSetSquareProblem(subdm0, PETSC_TRUE);
CHKERR DMMoFEMAddElement(subdm0, "FE11");
CHKERR DMMoFEMAddSubFieldRow(subdm0, "FIELD1", MBVERTEX, MBVERTEX);
CHKERR DMMoFEMAddSubFieldCol(subdm0, "FIELD1", MBVERTEX, MBVERTEX);
CHKERR DMSetUp(subdm0);
->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("SUB0", -1,
-1, 1);
if (debug) {
Mat A;
CHKERR DMCreateMatrix(subdm0, &A);
MatView(A, PETSC_VIEWER_DRAW_WORLD);
std::string wait;
std::cin >> wait;
CHKERR MatDestroy(&A);
}
CHKERR DMMoFEMCreateSubDM(subdm1, dm, "SUB1");
CHKERR DMMoFEMSetSquareProblem(subdm1, PETSC_FALSE);
CHKERR DMMoFEMAddElement(subdm1, "FE01");
CHKERR DMMoFEMAddSubFieldRow(subdm1, "FIELD0");
CHKERR DMMoFEMAddSubFieldCol(subdm1, "FIELD1");
CHKERR DMSetUp(subdm1);
->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("SUB1", -1,
-1, 1);
if (debug) {
Mat B;
CHKERR DMCreateMatrix(subdm1, &B);
MatView(B, PETSC_VIEWER_DRAW_WORLD);
std::string wait;
std::cin >> wait;
CHKERR MatDestroy(&B);
}
// destry dm
CHKERR DMDestroy(&dm);
CHKERR DMDestroy(&subdm0);
CHKERR DMDestroy(&subdm1);
}
// finish work cleaning memory, getting statistics, ect.
return 0;
}
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
@ H1
continuous field
Definition: definitions.h:85
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:215
#define CHKERR
Inline error check.
Definition: definitions.h:535
int main(int argc, char *argv[])
static char help[]
static const bool debug
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
Definition: DMMMoFEM.cpp:201
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
Definition: DMMMoFEM.cpp:403
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[], EntityType lo_type=MBVERTEX, EntityType hi_type=MBMAXTYPE)
Definition: DMMMoFEM.cpp:223
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:118
PetscErrorCode DMMoFEMAddElement(DM dm, const char fe_name[])
add element to dm
Definition: DMMMoFEM.cpp:450
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[], EntityType lo_type=MBVERTEX, EntityType hi_type=MBMAXTYPE)
Definition: DMMMoFEM.cpp:246
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMMoFEM.cpp:47
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.
char mesh_file_name[255]
auto f
Definition: HenckyOps.hpp:5
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
implementation of Data Operators for Forces and Sources
Definition: MoFEM.hpp:24
CoreTmp< 0 > Core
Definition: Core.hpp:1086
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1955
double A
Managing BitRefLevels.
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.
Core (interface) class.
Definition: Core.hpp:82
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
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
Deprecated interface functions.
Matrix manager is used to build and partition problems.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.