v0.14.0
MedInterface.hpp
Go to the documentation of this file.
1 /** \file MedInterface.hpp
2  * \brief Med file interface interface
3  *
4  * Interface loading mesh and data on mesh directly to mofem & moab
5  *
6  * \todo Reading higher order entities
7  * \todo Reading fields data
8  *
9  */
10 
11 #ifdef WITH_MED
12 
13 #ifndef __MED_INTERFACE_HPP__
14 #define __MED_INTERFACE_HPP__
15 
16 namespace MoFEM {
17 
18 /** \brief Interface for load MED files
19 
20  * \ingroup mofem_med_files
21 
22 */
23 struct MedInterface : public UnknownInterface {
24 
25  MoFEMErrorCode query_interface(boost::typeindex::type_index type_index,
26  UnknownInterface **iface) const;
27 
28  MedInterface(const MoFEM::Core &core);
29 
30  /**
31  * \brief Get MED file name from command line
32  * @param verb verbosity level
33  * @return error code
34  */
36 
37  /** \brief Check if file name is given in command line
38  */
39  inline PetscBool getFlgFile() const { return flgFile; }
40 
41  /**
42  * \brief Get field names in MED file
43  * @param file file name
44  * @param verb verbosity level
45  * @return error code
46  */
47  MoFEMErrorCode medGetFieldNames(const string &file, int verb = 1);
48 
49  /**
50  * \brief get field names in MED file
51  *
52  * File name is get form command line
53  *
54  * @param verb verbosity level
55  * @return error code
56  */
57  MoFEMErrorCode medGetFieldNames(int verb = 1);
58 
59  /**
60  * \brief read MED file
61  * @param file filed name
62  * @param verb verbosity level
63  * @return error code
64  */
65  MoFEMErrorCode readMed(const string &file, int verb = 1);
66 
67  /**
68  * \brief read MED file
69  *
70  * File name is form command line
71  * ////
72  *
73  * @param verb verbosity level
74  * @return error code
75  */
76  MoFEMErrorCode readMed(int verb = 1);
77 
78  /**
79  * \brief write MED file
80  *
81  * File name is form command line
82  *
83  * @param verb verbosity level
84  * @return error code
85  */
86  MoFEMErrorCode writeMed(boost::shared_ptr<Range> range_ptr = nullptr, int verb = 1);
87 
88  /**
89  * Retrieves the meshsets
90  *
91  * @param meshsets_ptr A pointer to a vector of const CubitMeshSets objects. If provided, the retrieved meshsets will be stored in this vector.
92  * @return A MoFEMErrorCode indicating the success or failure of the operation.
93  */
94  MoFEMErrorCode getMeshsets(boost::shared_ptr<std::vector< const CubitMeshSets * >> &meshsets_ptr);
95  /**
96  * \brief write MED file
97  * @param file file name
98  * @param meshsets_ptr meshsets
99  * @param verb verbosity level
100  * @return error code
101  */
102  MoFEMErrorCode writeMed(const string &file,
103  boost::shared_ptr<std::vector<const CubitMeshSets *>> meshsets_ptr,
104  boost::shared_ptr<Range> range_ptr = nullptr, int verb = 1);
105 
106  /**
107  * Read fields
108  * @param file_name file name
109  * @param file_index mesh index
110  * @param loadSeries load field into series
111  * @param onlyStep read only one step
112  * @return error code
113  */
114  MoFEMErrorCode readFields(const std::string &file_name,
115  const std::string &field_name,
116  const bool load_series = false,
117  const int only_step = -1, int verb = 1);
118 
119  struct FieldData {
120  std::string fieldName;
121  std::string meshName;
122  bool localMesh;
123  // Med_field_type fieldType;
124  std::vector<std::string> componentNames;
125  std::vector<std::string> componentUnits;
126  std::string dtUnit;
127  int ncSteps;
128  };
129 
130  std::vector<std::string> meshNames; ///< list of meshes in MED file
131  std::vector<EntityHandle> meshMeshsets; ///< meshset for each mesh
132  std::map<std::string, FieldData> fieldNames;
133  std::string medFileName; ///< MED file name
134 
135 private:
136  MoFEM::Core &cOre; ///< core database
137  // std::vector<std::string> fieldNames; ///< list of fields in MED file
138  PetscBool flgFile; ///< true if file name given in command line
139  // cubit
141 
142  /**
143  * \brief read mesh from MED file
144  * @param file file name
145  * @param index index of mesh
146  * @param family_elem_map map of families and elements
147  * @param verb verbosity level
148  * @return error code
149  */
150  MoFEMErrorCode readMesh(const string &file, const int index,
151  std::map<int, Range> &family_elem_map, int verb = 1);
152 
153  /**
154  * \brief read family and groups
155  * @param file file name
156  * @param index mesh index
157  * @param family_elem_mapint map of families and elements
158  * @param group_elem_map map of groups and elements
159  * @param verb verbosity level
160  * @return error code
161  */
162  MoFEMErrorCode readFamily(const string &file, const int index,
163  const std::map<int, Range> &family_elem_mapint,
164  std::map<string, Range> &group_elem_map,
165  int verb = 1);
166 
167  /**
168  * \brief make from groups meshsets
169  * @param group_elem_map map of groups and elements
170  * @param verb verbosity level
171  * @return error code
172  */
173  MoFEMErrorCode makeBlockSets(const std::map<string, Range> &group_elem_map,
174  int verb = 1);
175 };
176 
177 std::ostream &operator<<(std::ostream &os,
178  const MedInterface::FieldData &field_data);
179 
180 } // namespace MoFEM
181 
182 #endif // __MED_INTERFACE_HPP__
183 #endif // WITH_MED
184 
185 /***************************************************************************/ /**
186 * \defgroup mofem_med_files Reading and writing med files
187 * \ingroup mofem
188 *
189 * \brief Interface for reading and writing med files
190 ******************************************************************************/
MoFEM::MedInterface::query_interface
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Definition: MedInterface.cpp:45
MoFEM::operator<<
std::ostream & operator<<(std::ostream &os, const EntitiesFieldData::EntData &e)
Definition: EntitiesFieldData.cpp:240
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
MoFEM::MedInterface::getMeshsets
MoFEMErrorCode getMeshsets(boost::shared_ptr< std::vector< const CubitMeshSets * >> &meshsets_ptr)
Definition: MedInterface.cpp:661
MoFEM::MedInterface
Interface for load MED files.
Definition: MedInterface.hpp:23
MoFEM::MedInterface::makeBlockSets
MoFEMErrorCode makeBlockSets(const std::map< string, Range > &group_elem_map, int verb=1)
make from groups meshsets
Definition: MedInterface.cpp:616
MoFEM::MedInterface::medFileName
std::string medFileName
MED file name.
Definition: MedInterface.hpp:133
MoFEM::CubitMeshSet_multiIndex
multi_index_container< CubitMeshSets, indexed_by< hashed_unique< tag< Meshset_mi_tag >, member< CubitMeshSets, EntityHandle, &CubitMeshSets::meshset > >, ordered_non_unique< tag< CubitMeshsetType_mi_tag >, const_mem_fun< CubitMeshSets, unsigned long int, &CubitMeshSets::getBcTypeULong > >, ordered_non_unique< tag< CubitMeshsetMaskedType_mi_tag >, const_mem_fun< CubitMeshSets, unsigned long int, &CubitMeshSets::getMaskedBcTypeULong > >, ordered_non_unique< tag< CubitMeshsets_name >, const_mem_fun< CubitMeshSets, std::string, &CubitMeshSets::getName > >, hashed_unique< tag< Composite_Cubit_msId_And_MeshsetType_mi_tag >, composite_key< CubitMeshSets, const_mem_fun< CubitMeshSets, int, &CubitMeshSets::getMeshsetId >, const_mem_fun< CubitMeshSets, unsigned long int, &CubitMeshSets::getMaskedBcTypeULong > > > > > CubitMeshSet_multiIndex
Stores data about meshsets (see CubitMeshSets) storing data about boundary conditions,...
Definition: BCMultiIndices.hpp:388
MoFEM::MedInterface::meshNames
std::vector< std::string > meshNames
list of meshes in MED file
Definition: MedInterface.hpp:130
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::MedInterface::FieldData::ncSteps
int ncSteps
Definition: MedInterface.hpp:127
MoFEM::MedInterface::readFamily
MoFEMErrorCode readFamily(const string &file, const int index, const std::map< int, Range > &family_elem_mapint, std::map< string, Range > &group_elem_map, int verb=1)
read family and groups
Definition: MedInterface.cpp:521
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::MedInterface::getFlgFile
PetscBool getFlgFile() const
Check if file name is given in command line.
Definition: MedInterface.hpp:39
MoFEM::MedInterface::FieldData::localMesh
bool localMesh
Definition: MedInterface.hpp:122
MoFEM::MedInterface::FieldData
Definition: MedInterface.hpp:119
MoFEM::MedInterface::writeMed
MoFEMErrorCode writeMed(boost::shared_ptr< Range > range_ptr=nullptr, int verb=1)
write MED file
Definition: MedInterface.cpp:684
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::MedInterface::FieldData::dtUnit
std::string dtUnit
Definition: MedInterface.hpp:126
MoFEM::MedInterface::flgFile
PetscBool flgFile
true if file name given in command line
Definition: MedInterface.hpp:138
MoFEM::MedInterface::medGetFieldNames
MoFEMErrorCode medGetFieldNames(const string &file, int verb=1)
Get field names in MED file.
Definition: MedInterface.cpp:84
MoFEM::MedInterface::getFileNameFromCommandLine
MoFEMErrorCode getFileNameFromCommandLine(int verb=1)
Get MED file name from command line.
Definition: MedInterface.cpp:65
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::MedInterface::meshMeshsets
std::vector< EntityHandle > meshMeshsets
meshset for each mesh
Definition: MedInterface.hpp:131
MoFEM::MedInterface::FieldData::fieldName
std::string fieldName
Definition: MedInterface.hpp:120
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
MoFEM::UnknownInterface
base class for all interface classes
Definition: UnknownInterface.hpp:34
MoFEM::MedInterface::readMesh
MoFEMErrorCode readMesh(const string &file, const int index, std::map< int, Range > &family_elem_map, int verb=1)
read mesh from MED file
Definition: MedInterface.cpp:251
MoFEM::MedInterface::MedInterface
MedInterface(const MoFEM::Core &core)
Definition: MedInterface.cpp:51
MoFEM::MedInterface::FieldData::componentNames
std::vector< std::string > componentNames
Definition: MedInterface.hpp:124
MoFEM::MedInterface::FieldData::componentUnits
std::vector< std::string > componentUnits
Definition: MedInterface.hpp:125
MoFEM::MedInterface::cOre
MoFEM::Core & cOre
core database
Definition: MedInterface.hpp:136
MoFEM::MedInterface::FieldData::meshName
std::string meshName
Definition: MedInterface.hpp:121
MoFEM::MedInterface::cubitMeshsets
CubitMeshSet_multiIndex cubitMeshsets
cubit meshsets
Definition: MedInterface.hpp:140