14 #if (MED_MAJOR_NUM >= 3)
19 #define med_geometrie_element med_geometry_type
20 #define med_entite_maillage med_entity_type
21 #define med_type_champ med_field_type
22 #define MED_LECTURE MED_ACC_RDONLY
23 #define MED_LECTURE_AJOUT MED_ACC_RDEXT
24 #define MED_NOEUD MED_NODE
25 #define MED_MAILLE MED_CELL
26 #define MED_NOEUD_MAILLE MED_NODE_ELEMENT
27 #define MED_NOPFL MED_NO_PROFILE
28 #define MEDouvrir MEDfileOpen
29 #define MEDfermer MEDfileClose
30 #define MEDnChamp MEDfieldnComponent
31 #define MEDnValProfil MEDprofileSizeByName
32 #define MEDfichDesEcr MEDfileCommentWr
33 #define MED_ARETE MED_EDGE
34 #define MED_FACETTE MED_FACE
36 #error "MED file is not MED_MAJOR_NUM == 3"
40 #include <unordered_set>
52 : cOre(const_cast<
Core &>(core)), flgFile(PETSC_FALSE) {
55 auto core_log = logging::core::get();
62 MOFEM_LOG(
"MEDWORLD", Sev::noisy) <<
"Mashset manager created";
69 ierr = PetscOptionsBegin(m_field.
get_comm(),
"",
"MED Interface",
"none");
71 ierr = PetscOptionsString(
"-med_file",
"med file name",
"",
"mesh.med",
74 ierr = PetscOptionsEnd();
87 med_idt fid = MEDfileOpen(file.c_str(), MED_ACC_RDONLY);
90 "Unable to open file '%s'", file.c_str());
92 med_int num_fields = MEDnField(fid);
93 for (
int index = 0; index < num_fields; index++) {
95 med_int num_comp = MEDfieldnComponent(fid, index + 1);
98 "Could not get number of components for MED field");
101 char name[MED_NAME_SIZE + 1], mesh_name[MED_NAME_SIZE + 1];
102 char dt_unit[MED_SNAME_SIZE + 1];
103 std::vector<char> comp_name(num_comp * MED_SNAME_SIZE + 1);
104 std::vector<char> comp_unit(num_comp * MED_SNAME_SIZE + 1);
105 med_int num_steps = 0;
108 if (MEDfieldInfo(fid, index + 1, name, mesh_name, &local_mesh, &
type,
109 &comp_name[0], &comp_unit[0], dt_unit, &num_steps) < 0) {
111 "Could not get MED field info");
119 for (
int ff = 0; ff != num_comp; ff++) {
121 std::string(&comp_name[ff * MED_SNAME_SIZE], MED_SNAME_SIZE));
123 std::string(&comp_unit[ff * MED_SNAME_SIZE], MED_SNAME_SIZE));
131 if (MEDfileClose(fid) < 0) {
133 "Unable to close file '%s'", file.c_str());
151 med_idt fid = MEDfileOpen(file.c_str(), MED_ACC_RDONLY);
154 "Unable to open file '%s'", file.c_str());
158 MEDlibraryNumVersion(&
v[0], &
v[1], &
v[2]);
159 MEDfileNumVersionRd(fid, &vf[0], &vf[1], &vf[2]);
163 "Reading MED file V%d.%d.%d using MED library V%d.%d.%d", vf[0],
164 vf[1], vf[2],
v[0],
v[1],
v[2]);
166 if (vf[0] < 2 || (vf[0] == 2 && vf[1] < 2)) {
168 "Cannot read MED file older than V2.2");
171 for (
int i = 0;
i < MEDnMesh(fid);
i++) {
172 char mesh_name[MED_NAME_SIZE + 1], mesh_desc[MED_COMMENT_SIZE + 1];
173 bzero(mesh_name, MED_NAME_SIZE);
174 bzero(mesh_desc, MED_COMMENT_SIZE);
176 med_mesh_type mesh_type;
177 med_int mesh_dim, n_step;
178 char dt_unit[MED_SNAME_SIZE + 1];
179 char axis_name[3 * MED_SNAME_SIZE + 1], axis_unit[3 * MED_SNAME_SIZE + 1];
180 med_sorting_type sorting_type;
181 med_axis_type axis_type;
182 if (MEDmeshInfo(fid,
i + 1, mesh_name, &space_dim, &mesh_dim, &mesh_type,
183 mesh_desc, dt_unit, &sorting_type, &n_step, &axis_type,
184 axis_name, axis_unit) < 0) {
186 "Unable to read mesh information");
188 meshNames.push_back(std::string(mesh_name));
190 MOFEM_LOG_C(
"MEDWORLD", Sev::inform,
"Check mesh %s nsteps %d", mesh_name,
195 std::map<int, Range> family_elem_map;
196 std::map<string, Range> group_elem_map;
198 for (
unsigned int ii = 0; ii !=
meshNames.size(); ii++) {
204 if (MEDfileClose(fid) < 0) {
206 "Unable to close file '%s'", file.c_str());
212 static std::vector<med_geometrie_element>
215 std::vector<med_geometrie_element> types;
219 types.push_back(MED_SEG2);
220 types.push_back(MED_SEG3);
223 types.push_back(MED_TRIA3);
224 types.push_back(MED_TRIA6);
227 types.push_back(MED_QUAD4);
230 types.push_back(MED_TETRA4);
231 types.push_back(MED_TETRA10);
234 types.push_back(MED_HEXA8);
237 types.push_back(MED_PENTA6);
240 types.push_back(MED_PYRA5);
254 std::map<int, Range> &family_elem_map,
260 med_idt fid = MEDfileOpen(file.c_str(), MED_ACC_RDONLY);
263 "Unable to open file '%s'", file.c_str());
266 MEDlibraryNumVersion(&
v[0], &
v[1], &
v[2]);
267 MEDfileNumVersionRd(fid, &vf[0], &vf[1], &vf[2]);
270 "Reading MED file V%d.%d.%d using MED library V%d.%d.%d", vf[0],
271 vf[1], vf[2],
v[0],
v[1],
v[2]);
273 if (vf[0] < 2 || (vf[0] == 2 && vf[1] < 2)) {
275 "Cannot read MED file older than V2.2");
278 char mesh_name[MED_NAME_SIZE + 1], mesh_desc[MED_COMMENT_SIZE + 1];
279 bzero(mesh_name, MED_NAME_SIZE + 1);
280 bzero(mesh_desc, MED_COMMENT_SIZE + 1);
282 med_mesh_type mesh_type;
283 med_int mesh_dim, n_step;
284 char dt_unit[MED_SNAME_SIZE + 1];
285 char axis_name[3 * MED_SNAME_SIZE + 1], axis_unit[3 * MED_SNAME_SIZE + 1];
286 med_sorting_type sorting_type;
287 med_axis_type axis_type;
288 if (MEDmeshInfo(fid, index + 1, mesh_name, &space_dim, &mesh_dim, &mesh_type,
289 mesh_desc, dt_unit, &sorting_type, &n_step, &axis_type,
290 axis_name, axis_unit) < 0) {
292 "Unable to read mesh information");
295 MOFEM_LOG_C(
"MEDWORLD", Sev::inform,
"Reading mesh %s nsteps %d", mesh_name,
302 case MED_CYLINDRICAL:
305 "Curvilinear coordinate system implemented");
309 "Not implemented for space dim %d", space_dim);
318 max_id = (max_id < cit->getMeshsetId()) ? cit->getMeshsetId() : max_id;
322 std::string(mesh_name));
323 CubitMeshSet_multiIndex::index<
330 mesh_meshset = cit->getMeshset();
334 med_bool change_of_coord, geo_transform;
335 med_int num_nodes = MEDmeshnEntity(
336 fid, mesh_name, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE,
337 MED_COORDINATE, MED_NO_CMODE, &change_of_coord, &geo_transform);
340 "Could not read number of MED nodes");
342 if (num_nodes == 0) {
344 "No nodes in MED mesh");
347 MOFEM_LOG_C(
"MEDWORLD", Sev::inform,
"Read number of nodes %d", num_nodes);
349 std::vector<med_float> coord_med(space_dim * num_nodes);
350 if (MEDmeshNodeCoordinateRd(fid, mesh_name, MED_NO_DT, MED_NO_IT,
351 MED_NO_INTERLACE, &coord_med[0]) < 0) {
353 "Could not read MED node coordinates");
357 ReadUtilIface *iface;
358 vector<double *> arrays_coord;
361 CHKERR iface->get_node_coords(3, num_nodes, 0, startv, arrays_coord);
362 Range verts(startv, startv + num_nodes - 1);
363 std::copy(&coord_med[0 * num_nodes], &coord_med[1 * num_nodes],
365 std::copy(&coord_med[1 * num_nodes], &coord_med[2 * num_nodes],
367 if (space_dim == 2) {
368 std::fill(arrays_coord[2], &arrays_coord[2][num_nodes], 0.);
370 std::copy(&coord_med[2 * num_nodes], &coord_med[3 * num_nodes],
374 family_elem_map.clear();
378 std::vector<med_int> nodes_tags(num_nodes, 0);
379 if (MEDmeshEntityFamilyNumberRd(fid, mesh_name, MED_NO_DT, MED_NO_IT,
380 MED_NODE, MED_NO_GEOTYPE,
381 &nodes_tags[0]) < 0) {
389 for (
int i = 0;
i < num_nodes;
i++) {
392 family_elem_map[nodes_tags.empty() ?
i : nodes_tags[
i]].insert(verts[
i]);
397 for (EntityType ent_type = MBVERTEX; ent_type < MBMAXTYPE; ent_type++) {
401 for (
auto type : types) {
404 med_bool change_of_coord;
405 med_bool geo_transform;
406 med_int num_ele = MEDmeshnEntity(
407 fid, mesh_name, MED_NO_DT, MED_NO_IT, MED_CELL,
type,
408 MED_CONNECTIVITY, MED_NODAL, &change_of_coord, &geo_transform);
414 int num_nod_per_ele =
type % 100;
417 <<
"Reading elements " << num_ele <<
" of type "
418 << moab::CN::EntityTypeName(ent_type) <<
" number of nodes "
421 std::vector<med_int> conn_med(num_ele * num_nod_per_ele);
422 if (MEDmeshElementConnectivityRd(fid, mesh_name, MED_NO_DT, MED_NO_IT,
423 MED_CELL,
type, MED_NODAL,
424 MED_FULL_INTERLACE, &conn_med[0]) < 0) {
426 "Could not read MED elements");
434 if (ent_type != MBVERTEX) {
437 CHKERR iface->get_element_connect(num_ele, num_nod_per_ele, ent_type, 0,
443 for (
int ee = 0; ee != num_ele; ee++) {
445 for (
int nn = 0; nn != num_nod_per_ele; nn++) {
447 n[nn] = verts[conn_med[ii + nn] - 1];
450 std::array<int, 10> nodes_map{
459 for (
int nn = 0; nn != num_nod_per_ele; nn++, ii++) {
460 conn_moab[ii] =
n[nodes_map[nn]];
466 for (
int ee = 0; ee != num_ele; ee++) {
467 for (
int nn = 0; nn != num_nod_per_ele; nn++, ii++) {
469 conn_moab[ii] = verts[conn_med[ii] - 1];
475 CHKERR iface->update_adjacencies(starte, num_ele, num_nod_per_ele,
477 ents =
Range(starte, starte + num_ele - 1);
481 std::vector<EntityHandle> conn_moab(num_ele * num_nod_per_ele);
482 for (
int ee = 0; ee != num_ele; ++ee)
483 for (
int nn = 0; nn != num_nod_per_ele; ++nn, ++ii)
484 conn_moab[ii] = verts[conn_med[ii] - 1];
485 ents.insert_list(conn_moab.begin(), conn_moab.end());
493 std::vector<med_int> fam(num_ele, 0);
494 if (MEDmeshEntityFamilyNumberRd(fid, mesh_name, MED_NO_DT, MED_NO_IT,
495 MED_CELL,
type, &fam[0]) < 0) {
497 "No family number for elements: using 0 as default family "
506 for (
int j = 0;
j < num_ele;
j++) {
508 family_elem_map[fam[
j]].insert(ents[
j]);
514 if (MEDfileClose(fid) < 0) {
516 "Unable to close file '%s'", file.c_str());
524 const std::map<int, Range> &family_elem_map,
525 std::map<string, Range> &group_elem_map,
int verb) {
530 med_idt fid = MEDfileOpen(file.c_str(), MED_ACC_RDONLY);
533 "Unable to open file '%s'", file.c_str());
536 MEDlibraryNumVersion(&
v[0], &
v[1], &
v[2]);
537 MEDfileNumVersionRd(fid, &vf[0], &vf[1], &vf[2]);
541 "Reading MED file V%d.%d.%d using MED library V%d.%d.%d", vf[0],
542 vf[1], vf[2],
v[0],
v[1],
v[2]);
544 if (vf[0] < 2 || (vf[0] == 2 && vf[1] < 2)) {
546 "Cannot read MED file older than V2.2");
550 group_elem_map.clear();
552 med_int num_families = MEDnFamily(fid,
meshNames[index].c_str());
553 if (num_families < 0) {
555 "Could not read MED families");
557 for (
int i = 0;
i < num_families;
i++) {
560 ? MEDnFamily23Attribute(fid,
meshNames[index].c_str(),
i + 1)
562 med_int num_groups = MEDnFamilyGroup(fid,
meshNames[index].c_str(),
i + 1);
563 if (num_attrib < 0 || num_groups < 0) {
565 "Could not read MED groups or attributes");
568 std::vector<med_int> attribId(num_attrib + 1);
569 std::vector<med_int> attrib_val(num_attrib + 1);
570 std::vector<char> attrib_des(MED_COMMENT_SIZE * num_attrib + 1);
571 std::vector<char> group_names(MED_LNAME_SIZE * num_groups + 1);
572 char family_name[MED_NAME_SIZE + 1];
576 if (MEDfamily23Info(fid,
meshNames[index].c_str(),
i + 1, family_name,
577 &attribId[0], &attrib_val[0], &attrib_des[0],
578 &family_num, &group_names[0]) < 0) {
580 "Could not read info for MED2 family %d",
i + 1);
583 if (MEDfamilyInfo(fid,
meshNames[index].c_str(),
i + 1, family_name,
584 &family_num, &group_names[0]) < 0) {
586 "Could not read info for MED3 family %d",
i + 1);
591 for (
int g = 0;
g != num_groups;
g++) {
593 std::string(&group_names[MED_LNAME_SIZE *
g], MED_LNAME_SIZE - 1);
594 name.resize(NAME_TAG_SIZE - 1);
595 if (family_elem_map.find(family_num) == family_elem_map.end()) {
597 "MEDWORLD", Sev::warning,
598 "Family %d not read, likely type of element is not added "
599 "to moab database. Currently only triangle, quad, tetrahedral and "
600 "hexahedral elements are read to moab database",
603 group_elem_map[name].merge(family_elem_map.at(family_num));
609 if (MEDfileClose(fid) < 0) {
611 "Unable to close file '%s'", file.c_str());
628 max_id = (max_id < cit->getMeshsetId()) ? cit->getMeshsetId() : max_id;
632 for (std::map<string, Range>::const_iterator git = group_elem_map.begin();
633 git != group_elem_map.end(); git++) {
635 CubitMeshSet_multiIndex::index<
642 if (!git->second.empty()) {
649 MOFEM_LOG(
"MEDWORLD", Sev::verbose) << *cit;
664 boost::shared_ptr<std::vector<const CubitMeshSets *>> &meshsets_ptr) {
670 std::vector<const CubitMeshSets *> meshsets;
672 for (
auto &
m : meshsets_idx) {
673 meshsets.push_back(&
m);
676 std::sort(meshsets.begin(), meshsets.end(),
678 return a->getMeshsetId() < b->getMeshsetId();
682 boost::make_shared<std::vector<const CubitMeshSets *>>(meshsets);
694 boost::shared_ptr<std::vector<const CubitMeshSets *>> meshsets_ptr;
703 boost::shared_ptr<std::vector<const CubitMeshSets *>> meshsets_ptr,
704 boost::shared_ptr<Range> write_range_ptr,
int verb) {
711 <<
"WRITE_MED IS EXPERIMENTAL, MAY CONTAIN BUGS, ALWAYS CHECK THE OUTPUT "
715 MEDfileVersionOpen((
char *)file.c_str(), MED_ACC_CREAT, MED_MAJOR_NUM,
716 MED_MINOR_NUM, MED_RELEASE_NUM);
720 "Cannot create MED file");
725 CHKERR MEDfichDesEcr(fid, (
char *)
"MED file generated by MoFEM");
728 char dtUnit[MED_SNAME_SIZE + 1] =
"";
729 char axisName[3 * MED_SNAME_SIZE + 1] =
"";
730 char axisUnit[3 * MED_SNAME_SIZE + 1] =
"";
732 PetscBool is_cubit_meshset = PETSC_TRUE;
733 int med_mesh_name_id = 0;
736 char mesh_name_char[255];
737 std::string mesh_name =
"Mesh";
740 CHKERR PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"MED mesh options",
"");
741 CHKERR PetscOptionsString(
"-med_mesh_name",
"get med mesh name",
"",
742 mesh_name.c_str(), mesh_name_char, 255, PETSC_NULL);
743 ierr = PetscOptionsEnd();
746 mesh_name = mesh_name_char;
749 for (
auto &
m : *meshsets_ptr) {
750 if (
m->getName() == mesh_name) {
751 med_mesh_name_id =
m->getMeshsetId();
752 is_cubit_meshset = PETSC_FALSE;
759 for (
auto &
m : *meshsets_ptr) {
760 if (
m->getMeshsetId() == med_mesh_name_id)
761 mesh_name =
m->getName();
762 max_id = (max_id <
m->getMeshsetId()) ?
m->getMeshsetId() : max_id;
766 CHKERR MEDmeshCr(fid, mesh_name.c_str(), 3, 3, MED_UNSTRUCTURED_MESH,
767 "Mesh created", dtUnit, MED_SORT_DTIT, MED_CARTESIAN,
771 med_int family_id = 0;
772 std::map<std::vector<std::string>, std::tuple<med_int, std::vector<int>>>
774 std::map<EntityHandle, med_int> entityHandle_family_map;
777 shared_meshsets_map[std::vector<string>()] =
778 std::make_tuple(family_id, std::vector<int>());
782 std::string bc_type_name;
783 if (iit->getBcTypeULong() &
BLOCKSET) {
785 bc_type_name = iit->getName();
786 if (bc_type_name ==
"NoNameSet") {
787 bc_type_name =
"BLOCKSET_";
788 bc_type_name += std::to_string(iit->getMeshsetId());
791 }
else if (iit->getBcTypeULong() &
SIDESET ||
792 iit->getBcTypeULong() &
NODESET) {
799 if ((iit->getBcType() & jj_bc_type).any()) {
801 std::string temp_bc_type_name = string(
CubitBCNames[jj + 1]);
802 if (temp_bc_type_name.length() > 10) {
803 temp_bc_type_name = temp_bc_type_name.substr(0, 4);
805 bc_type_name += temp_bc_type_name;
810 bc_type_name += std::to_string(iit->getMeshsetId());
812 bc_type_name =
"UnknownSet";
822 for (
auto &entity : *write_range_ptr) {
824 std::vector<int> shared_meshsets;
825 std::vector<string> shared_names;
828 auto add_shared_meshset = [&](
auto &other_meshset) {
829 std::string other_name = get_set_name(other_meshset);
830 if (std::find(shared_names.begin(), shared_names.end(), other_name) ==
831 shared_names.end()) {
832 shared_meshsets.push_back(other_meshset->getMeshsetId());
833 shared_names.push_back(other_name);
838 for (
auto &other_meshset : *meshsets_ptr) {
840 if (med_mesh_name_id == other_meshset->getMeshsetId())
843 Range other_entities;
845 moab.get_entities_by_handle(other_set, other_entities);
846 if (other_entities.empty())
850 EntityType ent_type = moab.type_from_handle(entity);
852 bool is_in_meshset = moab.contains_entities(other_set, &entity, 1);
855 add_shared_meshset(other_meshset);
860 auto it = shared_meshsets_map.find(shared_names);
861 if (it == shared_meshsets_map.end()) {
865 it = shared_meshsets_map
867 {shared_names, std::make_tuple(family_id, shared_meshsets)})
871 entityHandle_family_map[entity] = std::get<0>(it->second);
875 for (
const auto &it : shared_meshsets_map) {
877 std::string family_name =
"F_";
878 const auto &[family_id, shared_meshsets] = it.second;
879 family_name += std::to_string(family_id);
881 const auto &shared_meshset_names = it.first;
882 std::string group_name;
883 for (
const auto &name : shared_meshset_names) {
885 std::string meshset_name = name;
886 meshset_name.resize(MED_LNAME_SIZE,
' ');
887 group_name += meshset_name;
891 CHKERR MEDfamilyCr(fid, mesh_name.c_str(), family_name.c_str(), family_id,
892 shared_meshset_names.size(), group_name.c_str());
895 <<
"Creating family " << family_name <<
" with id " << family_id
896 <<
" and " << shared_meshset_names.size() <<
" groups " << std::endl;
901 verts = write_range_ptr->subset_by_type(MBVERTEX);
904 std::vector<med_float> coord_med(3 * verts.size());
905 std::vector<med_int> fam;
906 std::vector<med_int> tags;
907 std::map<EntityHandle, med_int> entityHandle_tag_map;
908 med_int med_node_num = 1;
911 for (Range::iterator it = verts.begin(); it != verts.end(); ++it) {
913 moab.get_coords(&(*it), 1, coords);
914 coord_med[3 * (it - verts.begin())] = coords[0];
915 coord_med[3 * (it - verts.begin()) + 1] = coords[1];
916 coord_med[3 * (it - verts.begin()) + 2] = coords[2];
917 fam.push_back(entityHandle_family_map[*it]);
920 entityHandle_tag_map[*it] = med_node_num;
924 CHKERR MEDmeshNodeWr(fid, mesh_name.c_str(), MED_NO_DT, MED_NO_IT,
925 MED_UNDEF_DT, MED_FULL_INTERLACE, verts.size(),
926 &coord_med[0], MED_FALSE,
"", MED_TRUE, &tags[0],
930 double last_tag = tags.back();
932 for (EntityType ent_type = MBVERTEX; ent_type < MBMAXTYPE; ent_type++) {
935 moab.get_entities_by_type(0, ent_type, entities,
true);
937 ents_to_write = intersect(entities, *write_range_ptr);
939 if (ents_to_write.empty())
943 std::vector<med_int> tag_number;
944 std::vector<med_int> family_number;
945 std::vector<med_int> connectivity;
948 for (
auto &entity : ents_to_write) {
949 if (ent_type != MBVERTEX) {
952 family_number.push_back(entityHandle_family_map[entity]);
954 tag_number.push_back(last_tag);
956 std::vector<EntityHandle> conn;
957 moab.get_connectivity(&entity, 1, conn);
959 for (
auto &
c : conn) {
960 connectivity.push_back(entityHandle_tag_map[
c]);
967 auto get_med_element_type = [](EntityType ent_type) {
968 med_geometrie_element
type;
995 med_geometrie_element med_type = get_med_element_type(ent_type);
996 if (ent_type == MBENTITYSET) {
999 CHKERR MEDmeshElementWr(fid, mesh_name.c_str(), MED_NO_DT, MED_NO_IT, 0.,
1000 MED_CELL, med_type, MED_NODAL, MED_FULL_INTERLACE,
1001 family_number.size(), &connectivity[0], MED_FALSE,
1002 nullptr, MED_TRUE, &tag_number[0], MED_TRUE,
1005 MOFEM_LOG_C(
"MEDWORLD", Sev::inform,
"Writing %i elements of type %i (%s) ",
1006 family_number.size(), med_type,
1007 moab::CN::EntityTypeName(ent_type));
1017 const bool load_series,
1018 const int only_step,
int verb) {
1022 med_idt fid = MEDfileOpen((
char *)file_name.c_str(), MED_LECTURE);
1025 "Unable to open file '%s'", file_name.c_str());
1028 med_int num_comp = MEDfieldnComponentByName(fid,
field_name.c_str());
1029 if (num_comp <= 0) {
1031 "Could not get number of components for MED field");
1034 char meshName[MED_NAME_SIZE + 1];
1035 char dtUnit[MED_SNAME_SIZE + 1];
1036 std::vector<char> compName(num_comp * MED_SNAME_SIZE + 1);
1037 std::vector<char> compUnit(num_comp * MED_SNAME_SIZE + 1);
1038 med_int numSteps = 0;
1039 med_type_champ
type;
1041 if (MEDfieldInfoByName(fid,
field_name.c_str(), meshName, &localMesh, &
type,
1042 &compName[0], &compUnit[0], dtUnit, &numSteps) < 0) {
1044 "Could not get MED field info");
1057 int num_comp_msh = (num_comp <= 1) ? 1
1058 : (num_comp <= 3) ? 3
1059 : (num_comp <= 9) ? 9
1067 std::vector<double> def_val(num_comp_msh, 0);
1069 tag_name.c_str(), num_comp_msh, MB_TYPE_DOUBLE,
th,
1070 MB_TAG_CREAT | MB_TAG_SPARSE, &def_val[0]);
1077 const med_entity_type entType[] = {MED_NODE, MED_CELL, MED_NODE_ELEMENT};
1078 const med_geometrie_element eleType[] = {
1079 MED_NONE, MED_SEG2, MED_TRIA3, MED_QUAD4, MED_TETRA4, MED_HEXA8,
1080 MED_PENTA6, MED_PYRA5, MED_SEG3, MED_TRIA6, MED_QUAD9, MED_TETRA10,
1081 MED_HEXA27, MED_POINT1, MED_QUAD8, MED_HEXA20, MED_PENTA15, MED_PYRA13};
1085 std::vector<std::pair<int, int>> pairs;
1086 for (
unsigned int i = 0;
i <
sizeof(entType) /
sizeof(entType[0]);
i++) {
1087 for (
unsigned int j = 0;
j <
sizeof(eleType) /
sizeof(eleType[0]);
j++) {
1088 if ((!
i && !
j) ||
j) {
1089 med_int
n = numSteps;
1091 pairs.push_back(std::pair<int, int>(
i,
j));
1092 numSteps = std::max(numSteps,
n);
1100 if (numSteps < 1 || pairs.empty()) {
1102 "Nothing to import from MED file");
1109 for (
int step = (only_step == -1) ? 0 : only_step; step < numSteps; step++) {
1111 if (!load_series && only_step != step)
1121 for (
unsigned int pair = 0; pair < pairs.size(); pair++) {
1124 med_entite_maillage ent = entType[pairs[pair].first];
1125 med_geometrie_element ele = eleType[pairs[pair].second];
1126 med_int numdt, numit, ngauss;
1128 if (MEDfieldComputingStepInfo(fid,
field_name.c_str(), step + 1, &numdt,
1131 "Could not read step info");
1134 char locName[MED_NAME_SIZE + 1], profileName[MED_NAME_SIZE + 1];
1139 med_int profileSize;
1140 med_int numVal = MEDfieldnValueWithProfile(
1141 fid,
field_name.c_str(), numdt, numit, ent, ele, 1,
1142 MED_COMPACT_STMODE, profileName, &profileSize, locName, &ngauss);
1157 std::vector<double> val(numVal * num_comp);
1158 if (MEDfieldValueWithProfileRd(fid,
field_name.c_str(), numdt, numit, ent,
1159 ele, MED_COMPACT_STMODE, profileName,
1160 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
1161 (
unsigned char *)&val[0]) < 0) {
1163 "Could not read field values");
1176 EntityType ent_type = MBMAXTYPE;
1187 "Not yet implemented for this cell %d", ele);
1189 if (ent_type != MBMAXTYPE) {
1192 CHKERR m_field.
get_moab().get_entities_by_type(meshset, ent_type,
1194 double e_vals[num_comp_msh];
1195 bzero(e_vals,
sizeof(
double) * num_comp_msh);
1196 std::vector<double>::iterator vit = val.begin();
1197 for (Range::iterator eit = ents.begin(); eit != ents.end(); eit++) {
1198 for (
int ii = 0; ii != num_comp; ii++, vit++) {
1205 CHKERR m_field.
get_moab().get_entities_by_type(meshset, ent_type,
1207 if (ents.size() * ngauss * num_comp != val.size()) {
1209 "data inconsistency");
1212 double e_vals[num_comp_msh];
1213 std::vector<double>::iterator vit = val.begin();
1214 for (Range::iterator eit = ents.begin(); eit != ents.end(); eit++) {
1215 bzero(e_vals,
sizeof(
double) * num_comp_msh);
1216 for (
int gg = 0; gg != ngauss; gg++) {
1217 for (
int ii = 0; ii != num_comp; ii++, vit++) {
1218 e_vals[ii] += *vit / ngauss;
1233 case MED_NODE_ELEMENT: {
1234 EntityType ent_type = MBVERTEX;
1236 CHKERR m_field.
get_moab().get_entities_by_type(meshset, ent_type, ents,
1238 double e_vals[num_comp_msh];
1239 bzero(e_vals,
sizeof(
double) * num_comp_msh);
1240 std::vector<double>::iterator vit = val.begin();
1241 for (Range::iterator eit = ents.begin(); eit != ents.end(); eit++) {
1242 for (
int ii = 0; ii != num_comp; ii++, vit++) {
1249 MOFEM_LOG_C(
"MEDWORLD", Sev::inform,
"Entity type %d not implemented",
1260 os <<
"field name: " << field_data.
fieldName;
1261 os <<
" mesh name: " << field_data.
meshName;
1262 os <<
" local mesh: " << ((field_data.
localMesh) ?
"true" :
"false");
1271 os <<
" componentNames:";
1272 for (
unsigned int ff = 0; ff != field_data.
componentNames.size(); ff++) {
1276 os <<
" componentUnits:";
1277 for (
unsigned int ff = 0; ff != field_data.
componentUnits.size(); ff++) {
1281 os <<
" dtUnit: " << field_data.
dtUnit << endl;
1282 os <<
" number of steps: " << field_data.
ncSteps;