v0.13.1
partition_mesh.cpp

Atom testing mesh partitioning.

Atom testing mesh partitioning

/** \file partition_mesh.cpp
\example partition_mesh.cpp
\brief Atom testing mesh partitioning
*/
#include <MoFEM.hpp>
using namespace MoFEM;
static char help[] = "...\n\n";
int main(int argc, char *argv[]) {
// initialize petsc
MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
int nb_vertices;
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)");
// read mesh and create moab and mofem datastrutures
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;
CHKERR moab.get_number_entities_by_dimension(0, 0, nb_vertices, true);
EntityHandle root_set = moab.get_root_set();
Range tets;
moab.get_entities_by_type(root_set, MBTET, tets, false);
Tag th_vertex_weight;
int def_val = 1;
CHKERR moab.tag_get_handle("VERTEX_WEIGHT", 1, MB_TYPE_INTEGER,
th_vertex_weight, MB_TAG_CREAT | MB_TAG_DENSE,
&def_val);
CommInterface *comm_interafce_ptr = m_field.getInterface<CommInterface>();
CHKERR comm_interafce_ptr->partitionMesh(
tets, 3, 2, m_field.get_comm_size(), &th_vertex_weight, NULL, NULL,
VERBOSE, false);
if (!m_field.get_comm_rank()) {
CHKERR moab.write_file("partitioned_mesh.h5m");
}
}
PetscBarrier(PETSC_NULL);
try {
moab::Core mb_instance2;
moab::Interface &moab2 = mb_instance2;
MoFEM::CoreTmp<1> core(moab2);
MoFEM::Interface &m_field = core;
// Register DM Manager
DMType dm_name = "DMMOFEM";
// Test build simple problem
const char *option = "DEBUG_IO;"
"PARALLEL=READ_PART;"
"PARALLEL_RESOLVE_SHARED_ENTS;"
"PARTITION=PARALLEL_PARTITION;";
CHKERR m_field.getInterface<Simple>()->getOptions();
CHKERR m_field.getInterface<Simple>()->loadFile(option,
"partitioned_mesh.h5m");
CHKERR m_field.getInterface<Simple>()->addDomainField(
CHKERR m_field.getInterface<Simple>()->setFieldOrder("U", 1);
CHKERR m_field.getInterface<Simple>()->setUp();
auto dm = m_field.getInterface<Simple>()->getDM();
const MoFEM::Problem *problem_ptr;
CHKERR DMMoFEMGetProblemPtr(dm, &problem_ptr);
if(problem_ptr->nbDofsRow != nb_vertices)
SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
"Number of vertices and DOFs is inconstent");
MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "Atom test")
<< "All is good in this test";
}
return 0;
}
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
Definition: LogManager.hpp:345
@ VERBOSE
Definition: definitions.h:209
#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
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
#define CHKERR
Inline error check.
Definition: definitions.h:535
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition: DMMMoFEM.cpp:373
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMMoFEM.cpp:47
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:277
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.
char mesh_file_name[255]
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
int main(int argc, char *argv[])
static char help[]
Managing BitRefLevels.
virtual int get_comm_size() 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:112
Deprecated interface functions.
keeps basic data about problem
DofIdx nbDofsRow
Global number of DOFs in row.
Simple interface for fast problem set-up.
Definition: Simple.hpp:26
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.