v0.14.0
read_med.cpp
Go to the documentation of this file.
1 /** \file reading_med.cpp
2 
3  \brief Reading 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  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
16 
17  try {
18 
19  moab::Core mb_instance;
20  moab::Interface &moab = mb_instance;
21  ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
22  if (pcomm == NULL)
23  pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
24 
25  // Create MoFEM database
26  MoFEM::Core core(moab);
27  MoFEM::Interface &m_field = core;
28 
29  char mesh_out_file[255] = "out.h5m";
30 
31  int time_step = 0;
32  CHKERR PetscOptionsBegin(m_field.get_comm(), "", "Read MED tool", "none");
33  CHKERR PetscOptionsInt("-med_time_step", "time step", "", time_step,
34  &time_step, PETSC_NULL);
35  CHKERR PetscOptionsString("-output_file", "output mesh file name", "",
36  "out.h5m", mesh_out_file, 255, PETSC_NULL);
37  ierr = PetscOptionsEnd();
38  CHKERRQ(ierr);
39 
40  MedInterface *med_interface_ptr;
41  CHKERR m_field.getInterface(med_interface_ptr);
42  CHKERR med_interface_ptr->readMed();
43  CHKERR med_interface_ptr->medGetFieldNames();
44 
45  for (std::map<std::string, MedInterface::FieldData>::iterator fit =
46  med_interface_ptr->fieldNames.begin();
47  fit != med_interface_ptr->fieldNames.end(); fit++) {
48  CHKERR med_interface_ptr->readFields(med_interface_ptr->medFileName,
49  fit->first, false, time_step);
50  }
51 
52  // Add meshsets if config file provided
53  MeshsetsManager *meshsets_interface_ptr;
54  CHKERR m_field.getInterface(meshsets_interface_ptr);
55  CHKERR meshsets_interface_ptr->setMeshsetFromFile();
56 
57  MOFEM_LOG_CHANNEL("WORLD");
58  MOFEM_LOG_TAG("WORLD", "read_med")
59  MOFEM_LOG("WORLD", Sev::inform)
60  << "Print all meshsets (old and added from meshsets "
61  "configurational file)";
62  for (auto cit = meshsets_interface_ptr->getBegin();
63  cit != meshsets_interface_ptr->getEnd(); cit++)
64  MOFEM_LOG("WORLD", Sev::inform) << *cit;
65 
66  CHKERR moab.write_file(mesh_out_file);
67  }
69 
71 
72  return 0;
73 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MYPCOMM_INDEX
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:228
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
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
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::MeshsetsManager::getEnd
CubitMeshSet_multiIndex::iterator getEnd() const
get begin iterator of cubit mehset of given type (instead you can use IT_CUBITMESHSETS_TYPE_FOR_LOOP(...
Definition: MeshsetsManager.hpp:257
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::MeshsetsManager::getBegin
CubitMeshSet_multiIndex::iterator getBegin() const
get begin iterator of cubit mehset of given type (instead you can use IT_CUBITMESHSETS_TYPE_FOR_LOOP(...
Definition: MeshsetsManager.hpp:243
MoFEM::MeshsetsManager::setMeshsetFromFile
MoFEMErrorCode setMeshsetFromFile(const string file_name, const bool clean_file_options=true)
add blocksets reading config file
Definition: MeshsetsManager.cpp:791
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:1015
main
int main(int argc, char *argv[])
Definition: read_med.cpp:14
MOFEM_LOG_TAG
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
Definition: LogManager.hpp:339
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
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
help
static char help[]
Definition: read_med.cpp:12
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
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