No Matches
/** \file field_to_vertices.cpp
\brief Field to vertices
\example field_to_vertices.cpp
#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 {
// global variables
char mesh_file_name[255];
PetscBool flg_file = PETSC_FALSE;
char field_name_param[255] = "RHO";
CHKERR PetscOptionsBegin(PETSC_COMM_WORLD, "", "Field to vertices options", "none");
CHKERR PetscOptionsString("-my_file", "mesh file name", "", "mesh.h5m",
mesh_file_name, 255, &flg_file);
CHKERR PetscOptionsString("-my_field", "field name", "", "FIELD",
field_name_param, 255, PETSC_NULL);
ierr = PetscOptionsEnd(); CHKERRG(ierr);
std::string field_name(field_name_param);
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);
const char *option;
option = "";
CHKERR moab.load_file(mesh_file_name, 0, option);
// Create MoFEM database
MoFEM::Core core(moab);
MoFEM::Interface &m_field = core;
if (flg_file != PETSC_TRUE) {
"*** ERROR -my_file (MESH FILE NEEDED)");
BitRefLevel bit_level0;
CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
0, 3, bit_level0);
CHKERR m_field.build_fields();
bool field_flg = false;
auto fields_ptr = m_field.get_fields();
for(auto field : (*fields_ptr)) {
bool check_space = field->getSpace() == H1;
if(field->getName() == field_name && check_space) field_flg = true;
if (!field_flg) {
"*** ERROR -my_field (FIELD (in H1 space) is NOT FOUND)");
SaveVertexDofOnTag ent_method(m_field, field_name.c_str());
CHKERR m_field.loop_dofs(field_name.c_str(),ent_method);
PetscPrintf(PETSC_COMM_WORLD, "\nDone. Saving files... \n");
//TODO: Higher order field mapping
CHKERR m_field.getInterface<BitRefManager>()->writeBitLevelByType(
bit_level0, BitRefLevel().set(), MBTET, "out_mesh.vtk", "VTK", "");
CHKERR moab.write_file("out.h5m");
return 0;
static char help[]
int main()
Definition: adol-c_atom.cpp:46
static PetscErrorCode ierr
Catch errors.
Definition: definitions.h:372
@ H1
continuous field
Definition: definitions.h:85
default communicator number PCOMM
Definition: definitions.h:215
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:483
Definition: definitions.h:36
#define CHKERR
Inline error check.
Definition: definitions.h:535
virtual const Field_multiIndex * get_fields() const =0
Get the fields object.
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
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.
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
constexpr auto field_name
Managing BitRefLevels.
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.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.