v0.14.0
reading_med_file.cpp
Go to the documentation of this file.
1 /** \file reading_med_file.cpp
2 
3  \brief Testing interface for reading and writing med files
4 
5 */
6 
7 
8 
9 #include <MoFEM.hpp>
10 using namespace MoFEM;
11 
12 static char help[] = "...\n\n";
13 
14 int main(int argc, char *argv[]) {
15 
16  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
17 
18  try {
19 
20  moab::Core mb_instance;
21  moab::Interface &moab = mb_instance;
22 
23  // Create MoFEM (Joseph) database
24  MoFEM::Core core(moab);
25  MoFEM::Interface &m_field = core;
26 
27  MedInterface *med_interface_ptr;
28  CHKERR m_field.getInterface(med_interface_ptr);
29 
30  CHKERR med_interface_ptr->readMed();
31  CHKERR med_interface_ptr->medGetFieldNames();
32 
33  // read field tags
34  for (std::map<std::string, MedInterface::FieldData>::iterator fit =
35  med_interface_ptr->fieldNames.begin();
36  fit != med_interface_ptr->fieldNames.end(); fit++) {
37  CHKERR med_interface_ptr->readFields(med_interface_ptr->medFileName,
38  fit->first, false, 1);
39  }
40 
41  PetscBool check = PETSC_TRUE;
42  CHKERR PetscOptionsGetBool(PETSC_NULL, "", "-check", &check, PETSC_NULL);
43 
44  int ii = 0;
45  const int check_list[] = {2163, 624, 65, 104};
47  EntityHandle meshset = cit->getMeshset();
48  int nb_ents;
49  CHKERR moab.get_number_entities_by_handle(meshset, nb_ents, true);
50  CHKERR PetscPrintf(PETSC_COMM_WORLD, "Nb of ents in %s %d\n",
51  cit->getName().c_str(), nb_ents);
52  CHKERRG(ierr);
53  if (check && nb_ents != check_list[ii]) {
54  SETERRQ2(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
55  "Wrong numbers of entities in meshset %d != %d", nb_ents,
56  check_list[ii]);
57  }
58  ii++;
59  }
60 
61  MeshsetsManager *meshset_manager_ptr;
62  CHKERR m_field.getInterface(meshset_manager_ptr);
63  for (_IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_((*meshset_manager_ptr),
64  BLOCKSET, mit)) {
65  EntityHandle meshset = mit->getMeshset();
66  std::string name = mit->getName();
67  PetscPrintf(m_field.get_comm(), "Write mesh %s\n", name.c_str());
68  CHKERR moab.write_file(("out_" + mit->getName() + ".vtk").c_str(), NULL,
69  NULL, &meshset, 1);
70  }
71  }
73 
75 
76  return 0;
77 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
EntityHandle
MoFEM::MedInterface
Interface for load MED files.
Definition: MedInterface.hpp:23
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
MoFEM::MedInterface::medFileName
std::string medFileName
MED file name.
Definition: MedInterface.hpp:133
MoFEM::MedInterface::readMed
MoFEMErrorCode readMed(const string &file, int verb=1)
read MED file
Definition: MedInterface.cpp:147
MoFEM::MedInterface::fieldNames
std::map< std::string, FieldData > fieldNames
Definition: MedInterface.hpp:132
MoFEM.hpp
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
main
int main(int argc, char *argv[])
Definition: reading_med_file.cpp:14
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::MedInterface::medGetFieldNames
MoFEMErrorCode medGetFieldNames(const string &file, int verb=1)
Get field names in MED file.
Definition: MedInterface.cpp:84
MoFEM::MedInterface::readFields
MoFEMErrorCode readFields(const std::string &file_name, const std::string &field_name, const bool load_series=false, const int only_step=-1, int verb=1)
Definition: MedInterface.cpp:1017
MoFEM::CoreTmp< 0 >::Initialize
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
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
_IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
Definition: MeshsetsManager.hpp:71
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
BLOCKSET
@ BLOCKSET
Definition: definitions.h:161
MoFEM::Exceptions::ierr
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
MoFEM::MeshsetsManager
Interface for managing meshsets containing materials and boundary conditions.
Definition: MeshsetsManager.hpp:104
help
static char help[]
Definition: reading_med_file.cpp:12
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
CHKERRG
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:496
MoFEM::PetscOptionsGetBool
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:182