v0.15.0
Loading...
Searching...
No Matches
mofem/atom_tests/build_composite_problem.cpp

Atom test for building composite problems.

Atom test for building composite problems

/** \file build_composite_problems.cpp
\example mofem/atom_tests/build_composite_problem.cpp
\brief Atom test for building composite problems
*/
#include <MoFEM.hpp>
using namespace MoFEM;
static char help[] = "...\n\n";
int main(int argc, char *argv[]) {
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_NULLPTR, "", "-my_file", mesh_file_name,
255, &flg);
#else
CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR, "-my_file",
mesh_file_name, 255, &flg);
#endif
if (flg != PETSC_TRUE) {
SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
}
// read mesh and create moab and mofem data structures
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
const char *option;
option = "";
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();
Range tets;
CHKERR moab.get_entities_by_type(root_set, MBTET, tets, false);
ProblemsManager *prb_mng_ptr = m_field.getInterface<ProblemsManager>();
CommInterface *comm_interface_ptr = m_field.getInterface<CommInterface>();
CHKERR comm_interface_ptr->partitionMesh(
tets, 3, 2, m_field.get_comm_size(), NULL, NULL, NULL);
EntityHandle part_set;
CHKERR moab.create_meshset(MESHSET_SET, part_set);
ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
if (pcomm == NULL)
SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
"Communicator should be allocated");
Tag part_tag = pcomm->part_tag();
Range proc_ents;
Range tagged_sets;
CHKERR m_field.get_moab().get_entities_by_type_and_tag(
0, MBENTITYSET, &part_tag, NULL, 1, tagged_sets,
moab::Interface::UNION);
for (Range::iterator mit = tagged_sets.begin(); mit != tagged_sets.end();
mit++) {
int part;
CHKERR moab.tag_get_data(part_tag, &*mit, 1, &part);
if (part == m_field.get_comm_rank()) {
// pcomm->partition_sets().insert(*mit);
CHKERR moab.get_entities_by_type(*mit, MBTET, proc_ents, true);
CHKERR moab.add_entities(part_set, proc_ents);
}
}
Skinner skin(&m_field.get_moab());
Range tets_skin;
CHKERR skin.find_skin(0, tets, false, tets_skin);
Range proc_ents_skin[4];
proc_ents_skin[3] = proc_ents;
CHKERR skin.find_skin(0, proc_ents, false, proc_ents_skin[2]);
proc_ents_skin[2] = subtract(proc_ents_skin[2], tets_skin);
CHKERR moab.get_adjacencies(proc_ents_skin[2], 1, false, proc_ents_skin[1],
moab::Interface::UNION);
CHKERR moab.get_connectivity(proc_ents_skin[1], proc_ents_skin[0], true);
for (int dd = 0; dd != 3; dd++) {
CHKERR moab.add_entities(part_set, proc_ents_skin[dd]);
}
if (0) {
std::ostringstream file_skin;
file_skin << "out_skin_" << m_field.get_comm_rank() << ".vtk";
EntityHandle meshset_skin;
CHKERR moab.create_meshset(MESHSET_SET, meshset_skin);
CHKERR moab.add_entities(meshset_skin, proc_ents_skin[2]);
CHKERR moab.add_entities(meshset_skin, proc_ents_skin[1]);
CHKERR moab.add_entities(meshset_skin, proc_ents_skin[0]);
CHKERR moab.write_file(file_skin.str().c_str(), "VTK", "", &meshset_skin,
1);
}
CHKERR pcomm->resolve_shared_ents(0, proc_ents, 3, -1, proc_ents_skin);
Range owned_tets = proc_ents;
if (0) {
std::ostringstream file_owned;
file_owned << "out_owned_" << m_field.get_comm_rank() << ".vtk";
EntityHandle meshset_owned;
CHKERR moab.create_meshset(MESHSET_SET, meshset_owned);
CHKERR moab.add_entities(meshset_owned, owned_tets);
CHKERR moab.write_file(file_owned.str().c_str(), "VTK", "",
&meshset_owned, 1);
}
Range shared_ents;
// Get entities shared with all other processors
CHKERR pcomm->get_shared_entities(-1, shared_ents);
if (0) {
std::ostringstream file_shared_owned;
file_shared_owned << "out_shared_owned_" << m_field.get_comm_rank()
<< ".vtk";
EntityHandle meshset_shared_owned;
CHKERR moab.create_meshset(MESHSET_SET, meshset_shared_owned);
CHKERR moab.add_entities(meshset_shared_owned, shared_ents);
CHKERR moab.write_file(file_shared_owned.str().c_str(), "VTK", "",
&meshset_shared_owned, 1);
}
// set entities bit level
BitRefLevel bit_level0;
bit_level0.set(0);
CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
part_set, 3, bit_level0);
// Fields
// add entities to field
CHKERR m_field.add_ents_to_field_by_type(part_set, MBTET, "F1");
CHKERR m_field.add_ents_to_field_by_type(part_set, MBTET, "F2");
int order = 4;
CHKERR m_field.set_field_order(part_set, MBTET, "F1", order);
CHKERR m_field.set_field_order(part_set, MBTRI, "F1", order);
CHKERR m_field.set_field_order(part_set, MBEDGE, "F1", order);
CHKERR m_field.set_field_order(part_set, MBVERTEX, "F1", 1);
CHKERR m_field.set_field_order(part_set, MBTET, "F2", order);
CHKERR m_field.set_field_order(part_set, MBTRI, "F2", order);
CHKERR m_field.set_field_order(part_set, MBEDGE, "F2", order);
CHKERR m_field.set_field_order(part_set, MBVERTEX, "F2", 1);
CHKERR m_field.build_fields();
// Elements
CHKERR m_field.add_finite_element("E1");
CHKERR m_field.add_finite_element("E2");
CHKERR m_field.add_ents_to_finite_element_by_type(part_set, MBTET, "E1");
CHKERR m_field.add_ents_to_finite_element_by_type(part_set, MBTET, "E2");
CHKERR m_field.build_adjacencies(bit_level0);
// Problems
CHKERR m_field.add_problem("P1");
CHKERR m_field.add_problem("P2");
// set refinement level for problem
CHKERR m_field.modify_problem_ref_level_add_bit("P1", bit_level0);
CHKERR m_field.modify_problem_ref_level_add_bit("P2", bit_level0);
// Build problems
CHKERR prb_mng_ptr->buildProblemOnDistributedMesh("P1", true, 1);
CHKERR prb_mng_ptr->buildProblemOnDistributedMesh("P2", true, 1);
CHKERR prb_mng_ptr->partitionFiniteElements("P1", true, 0,
m_field.get_comm_size(), 1);
CHKERR prb_mng_ptr->partitionGhostDofs("P1", 1);
CHKERR prb_mng_ptr->partitionFiniteElements("P2", true, 0,
m_field.get_comm_size(), 1);
CHKERR prb_mng_ptr->partitionGhostDofs("P2", 1);
if (0) {
->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>("P1", m);
MatView(m, PETSC_VIEWER_DRAW_WORLD);
std::string wait;
std::cin >> wait;
}
->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("P1", -1, -1,
1);
->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("P2", -1, -1,
1);
// register new dm type, i.e. mofem
DMType dm_name = "MOFEM";
CHKERR DMRegister_MoFEM(dm_name);
// create dm instance
auto dm = createDM(m_field.get_comm(), dm_name);
CHKERR DMMoFEMCreateMoFEM(dm, &m_field, "COMP", bit_level0);
CHKERR DMSetFromOptions(dm);
CHKERR DMMoFEMSetIsPartitioned(dm, PETSC_TRUE);
CHKERR DMMoFEMAddElement(dm, "E1");
CHKERR DMMoFEMAddElement(dm, "E2");
CHKERR DMMoFEMAddRowCompositeProblem(dm, "P1");
CHKERR DMMoFEMAddRowCompositeProblem(dm, "P2");
CHKERR DMSetUp(dm);
if (0) {
->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>("COMP", m);
MatView(m, PETSC_VIEWER_DRAW_WORLD);
std::string wait;
std::cin >> wait;
}
->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("COMP", -1,
-1, 1);
}
// Finish work cleaning memory, getting statistics, etc.
return 0;
}
static char help[]
int main()
#define CATCH_ERRORS
Catch errors.
@ 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
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define CHKERR
Inline error check.
constexpr int order
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 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 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_row(const std::string &fe_name, const std::string name_row)=0
set field row 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.
MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures, assuming that mesh is distributed (collective)
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode partitionMesh(const Range &ents, const int dim, const int adj_dim, const int n_parts, Tag *th_vertex_weights=nullptr, Tag *th_edge_weights=nullptr, Tag *th_part_weights=nullptr, int verb=VERBOSE, const bool debug=false)
Set partition tag to each finite element in the problem.
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elements
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
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
char mesh_file_name[255]
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 Common.hpp:10
FTensor::Index< 'm', 3 > m
Managing BitRefLevels.
Managing BitRefLevels.
virtual int get_comm_size() const =0
virtual moab::Interface & get_moab()=0
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 MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
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:118
Deprecated interface functions.
Matrix manager is used to build and partition problems.
Problem manager is used to build and partition problems.
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.