v0.9.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 /*
12  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15  * License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
19  */
20 
21 #ifdef WITH_MED
22 
23 #ifndef __MED_INTERFACE_HPP__
24 #define __MED_INTERFACE_HPP__
25 
26 namespace MoFEM {
27 
30 
31 /** \brief Interface for load MED files
32 
33  * \ingroup mofem_med_files
34 
35 */
36 struct MedInterface : public UnknownInterface {
37 
39  UnknownInterface **iface) const;
40 
41  MedInterface(const MoFEM::Core &core);
42 
43  /**
44  * \brief Get MED file name from command line
45  * @param verb verbosity level
46  * @return error code
47  */
49 
50  /** \brief Check if file name is given in command line
51  */
52  inline PetscBool getFlgFile() const { return flgFile; }
53 
54  /**
55  * \brief Get field names in MED file
56  * @param file file name
57  * @param verb verbosity level
58  * @return error code
59  */
60  MoFEMErrorCode medGetFieldNames(const string &file, int verb = 1);
61 
62  /**
63  * \brief get field names in MED file
64  *
65  * File name is get form command line
66  *
67  * @param verb verbosity level
68  * @return error code
69  */
70  MoFEMErrorCode medGetFieldNames(int verb = 1);
71 
72  /**
73  * \brief read MED file
74  * @param file filed name
75  * @param verb verbosity level
76  * @return error code
77  */
78  MoFEMErrorCode readMed(const string &file, int verb = 1);
79 
80  /**
81  * \brief read MED file
82  *
83  * File name is form command line
84  *
85  * @param verb verbosity level
86  * @return error code
87  */
88  MoFEMErrorCode readMed(int verb = 1);
89 
90  /**
91  * \brief write MED file
92  * @param file file name
93  * @param verb verbosity level
94  * @return error code
95  */
96  MoFEMErrorCode writeMed(const string &file, int verb = 1);
97 
98  /**
99  * Read fields
100  * @param file_name file name
101  * @param file_index mesh index
102  * @param loadSeries load field into series
103  * @param onlyStep read only one step
104  * @return error code
105  */
106  MoFEMErrorCode readFields(const std::string &file_name,
107  const std::string &field_name,
108  const bool load_series = false,
109  const int only_step = -1, int verb = 1);
110 
111  struct FieldData {
112  std::string fieldName;
113  std::string meshName;
114  bool localMesh;
115  // Med_field_type fieldType;
116  std::vector<std::string> componentNames;
117  std::vector<std::string> componentUnits;
118  std::string dtUnit;
119  int ncSteps;
120  };
121 
122  std::vector<std::string> meshNames; ///< list of meshes in MED file
123  std::vector<EntityHandle> meshMeshsets; ///< meshset for each mesh
124  std::map<std::string, FieldData> fieldNames;
125  std::string medFileName; ///< MED file name
126 
127 private:
128  MoFEM::Core &cOre; ///< core database
129  // std::vector<std::string> fieldNames; ///< list of fields in MED file
130  PetscBool flgFile; ///< true if file name given in command line
131 
132  /**
133  * \brief read mesh from MED file
134  * @param file file name
135  * @param index index of mesh
136  * @param family_elem_map map of families and elements
137  * @param verb verbosity level
138  * @return error code
139  */
140  MoFEMErrorCode readMesh(const string &file, const int index,
141  std::map<int, Range> &family_elem_map, int verb = 1);
142 
143  /**
144  * \brief read family and groups
145  * @param file file name
146  * @param index mesh index
147  * @param family_elem_mapint map of families and elements
148  * @param group_elem_map map of groups and elements
149  * @param verb verbosity level
150  * @return error code
151  */
152  MoFEMErrorCode readFamily(const string &file, const int index,
153  const std::map<int, Range> &family_elem_mapint,
154  std::map<string, Range> &group_elem_map,
155  int verb = 1);
156 
157  /**
158  * \brief make from groups meshsets
159  * @param group_elem_map map of groups and elements
160  * @param verb verbosity level
161  * @return error code
162  */
163  MoFEMErrorCode makeBlockSets(const std::map<string, Range> &group_elem_map,
164  int verb = 1);
165 };
166 
167 std::ostream &operator<<(std::ostream &os,
168  const MedInterface::FieldData &field_data);
169 
170 } // namespace MoFEM
171 
172 #endif // __MED_INTERFACE_HPP__
173 #endif // WITH_MED
174 
175 /***************************************************************************/ /**
176 * \defgroup mofem_med_files Reading and writing med files
177 * \ingroup mofem
178 *
179 * \brief Interface for reading and writing med files
180 ******************************************************************************/
MoFEM interface unique ID.
MoFEMErrorCode makeBlockSets(const std::map< string, Range > &group_elem_map, int verb=1)
make from groups meshsets
MoFEMErrorCode readMesh(const string &file, const int index, std::map< int, Range > &family_elem_map, int verb=1)
read mesh from MED file
std::map< std::string, FieldData > fieldNames
MoFEM::Core & cOre
core database
base class for all interface classes
Core (interface) class.
Definition: Core.hpp:50
std::vector< std::string > componentNames
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
std::bitset< BITINTERFACEUID_SIZE > BitIntefaceId
Definition: Types.hpp:56
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
Interface for load MED files.
std::ostream & operator<<(std::ostream &os, const DataForcesAndSourcesCore::EntData &e)
PetscBool flgFile
true if file name given in command line
MoFEMErrorCode getFileNameFromCommandLine(int verb=1)
Get MED file name from command line.
MoFEMErrorCode readMed(const string &file, int verb=1)
read MED file
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
MedInterface(const MoFEM::Core &core)
std::vector< EntityHandle > meshMeshsets
meshset for each mesh
std::vector< std::string > meshNames
list of meshes in MED file
std::vector< std::string > componentUnits
PetscBool getFlgFile() const
Check if file name is given in command line.
MoFEMErrorCode query_interface(const MOFEMuuid &uuid, UnknownInterface **iface) const
MoFEMErrorCode writeMed(const string &file, int verb=1)
write MED file
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)
static const MOFEMuuid IDD_MOFEMMedInterface
MoFEMErrorCode medGetFieldNames(const string &file, int verb=1)
Get field names in MED file.
std::string medFileName
MED file name.