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);
243 types.push_back(MED_POINT1);
252 std::map<int, Range> &family_elem_map,
258 med_idt fid = MEDfileOpen(file.c_str(), MED_ACC_RDONLY);
261 "Unable to open file '%s'", file.c_str());
264 MEDlibraryNumVersion(&
v[0], &
v[1], &
v[2]);
265 MEDfileNumVersionRd(fid, &vf[0], &vf[1], &vf[2]);
268 "Reading MED file V%d.%d.%d using MED library V%d.%d.%d", vf[0],
269 vf[1], vf[2],
v[0],
v[1],
v[2]);
271 if (vf[0] < 2 || (vf[0] == 2 && vf[1] < 2)) {
273 "Cannot read MED file older than V2.2");
276 char mesh_name[MED_NAME_SIZE + 1], mesh_desc[MED_COMMENT_SIZE + 1];
277 bzero(mesh_name, MED_NAME_SIZE + 1);
278 bzero(mesh_desc, MED_COMMENT_SIZE + 1);
280 med_mesh_type mesh_type;
281 med_int mesh_dim, n_step;
282 char dt_unit[MED_SNAME_SIZE + 1];
283 char axis_name[3 * MED_SNAME_SIZE + 1], axis_unit[3 * MED_SNAME_SIZE + 1];
284 med_sorting_type sorting_type;
285 med_axis_type axis_type;
286 if (MEDmeshInfo(fid, index + 1, mesh_name, &space_dim, &mesh_dim, &mesh_type,
287 mesh_desc, dt_unit, &sorting_type, &n_step, &axis_type,
288 axis_name, axis_unit) < 0) {
290 "Unable to read mesh information");
293 MOFEM_LOG_C(
"MEDWORLD", Sev::inform,
"Reading mesh %s nsteps %d", mesh_name,
300 case MED_CYLINDRICAL:
303 "Curvilinear coordinate system implemented");
307 "Not implemented for space dim %d", space_dim);
316 max_id = (max_id < cit->getMeshsetId()) ? cit->getMeshsetId() : max_id;
320 std::string(mesh_name));
321 CubitMeshSet_multiIndex::index<
328 mesh_meshset = cit->getMeshset();
332 med_bool change_of_coord, geo_transform;
333 med_int num_nodes = MEDmeshnEntity(
334 fid, mesh_name, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE,
335 MED_COORDINATE, MED_NO_CMODE, &change_of_coord, &geo_transform);
338 "Could not read number of MED nodes");
340 if (num_nodes == 0) {
342 "No nodes in MED mesh");
345 MOFEM_LOG_C(
"MEDWORLD", Sev::inform,
"Read number of nodes %d", num_nodes);
347 std::vector<med_float> coord_med(space_dim * num_nodes);
348 if (MEDmeshNodeCoordinateRd(fid, mesh_name, MED_NO_DT, MED_NO_IT,
349 MED_NO_INTERLACE, &coord_med[0]) < 0) {
351 "Could not read MED node coordinates");
355 ReadUtilIface *iface;
356 vector<double *> arrays_coord;
359 CHKERR iface->get_node_coords(3, num_nodes, 0, startv, arrays_coord);
360 Range verts(startv, startv + num_nodes - 1);
361 std::copy(&coord_med[0 * num_nodes], &coord_med[1 * num_nodes],
363 std::copy(&coord_med[1 * num_nodes], &coord_med[2 * num_nodes],
365 if (space_dim == 2) {
366 std::fill(arrays_coord[2], &arrays_coord[2][num_nodes], 0.);
368 std::copy(&coord_med[2 * num_nodes], &coord_med[3 * num_nodes],
372 family_elem_map.clear();
376 std::vector<med_int> nodes_tags(num_nodes, 0);
377 if (MEDmeshEntityFamilyNumberRd(fid, mesh_name, MED_NO_DT, MED_NO_IT,
378 MED_NODE, MED_NO_GEOTYPE,
379 &nodes_tags[0]) < 0) {
387 for (
int i = 0;
i < num_nodes;
i++) {
390 family_elem_map[nodes_tags.empty() ?
i : nodes_tags[
i]].insert(verts[
i]);
395 for (EntityType ent_type = MBVERTEX; ent_type < MBMAXTYPE; ent_type++) {
399 for (
auto type : types) {
402 med_bool change_of_coord;
403 med_bool geo_transform;
404 med_int num_ele = MEDmeshnEntity(
405 fid, mesh_name, MED_NO_DT, MED_NO_IT, MED_CELL,
type,
406 MED_CONNECTIVITY, MED_NODAL, &change_of_coord, &geo_transform);
412 int num_nod_per_ele =
type % 100;
415 <<
"Reading elements " << num_ele <<
" of type "
416 << moab::CN::EntityTypeName(ent_type) <<
" number of nodes "
419 std::vector<med_int> conn_med(num_ele * num_nod_per_ele);
420 if (MEDmeshElementConnectivityRd(fid, mesh_name, MED_NO_DT, MED_NO_IT,
421 MED_CELL,
type, MED_NODAL,
422 MED_FULL_INTERLACE, &conn_med[0]) < 0) {
424 "Could not read MED elements");
432 if (ent_type != MBVERTEX) {
435 CHKERR iface->get_element_connect(num_ele, num_nod_per_ele, ent_type, 0,
441 for (
int ee = 0; ee != num_ele; ee++) {
443 for (
int nn = 0; nn != num_nod_per_ele; nn++) {
445 n[nn] = verts[conn_med[ii + nn] - 1];
448 std::array<int, 10> nodes_map{
457 for (
int nn = 0; nn != num_nod_per_ele; nn++, ii++) {
458 conn_moab[ii] =
n[nodes_map[nn]];
464 for (
int ee = 0; ee != num_ele; ee++) {
465 for (
int nn = 0; nn != num_nod_per_ele; nn++, ii++) {
467 conn_moab[ii] = verts[conn_med[ii] - 1];
473 CHKERR iface->update_adjacencies(starte, num_ele, num_nod_per_ele,
475 ents =
Range(starte, starte + num_ele - 1);
479 std::vector<EntityHandle> conn_moab(num_ele * num_nod_per_ele);
480 for (
int ee = 0; ee != num_ele; ++ee)
481 for (
int nn = 0; nn != num_nod_per_ele; ++nn, ++ii)
482 conn_moab[ii] = verts[conn_med[ii] - 1];
483 ents.insert_list(conn_moab.begin(), conn_moab.end());
491 std::vector<med_int> fam(num_ele, 0);
492 if (MEDmeshEntityFamilyNumberRd(fid, mesh_name, MED_NO_DT, MED_NO_IT,
493 MED_CELL,
type, &fam[0]) < 0) {
495 "No family number for elements: using 0 as default family "
504 for (
int j = 0;
j < num_ele;
j++) {
506 family_elem_map[fam[
j]].insert(ents[
j]);
512 if (MEDfileClose(fid) < 0) {
514 "Unable to close file '%s'", file.c_str());
522 const std::map<int, Range> &family_elem_map,
523 std::map<string, Range> &group_elem_map,
int verb) {
528 med_idt fid = MEDfileOpen(file.c_str(), MED_ACC_RDONLY);
531 "Unable to open file '%s'", file.c_str());
534 MEDlibraryNumVersion(&
v[0], &
v[1], &
v[2]);
535 MEDfileNumVersionRd(fid, &vf[0], &vf[1], &vf[2]);
539 "Reading MED file V%d.%d.%d using MED library V%d.%d.%d", vf[0],
540 vf[1], vf[2],
v[0],
v[1],
v[2]);
542 if (vf[0] < 2 || (vf[0] == 2 && vf[1] < 2)) {
544 "Cannot read MED file older than V2.2");
548 group_elem_map.clear();
550 med_int num_families = MEDnFamily(fid,
meshNames[index].c_str());
551 if (num_families < 0) {
553 "Could not read MED families");
555 for (
int i = 0;
i < num_families;
i++) {
558 ? MEDnFamily23Attribute(fid,
meshNames[index].c_str(),
i + 1)
560 med_int num_groups = MEDnFamilyGroup(fid,
meshNames[index].c_str(),
i + 1);
561 if (num_attrib < 0 || num_groups < 0) {
563 "Could not read MED groups or attributes");
566 std::vector<med_int> attribId(num_attrib + 1);
567 std::vector<med_int> attrib_val(num_attrib + 1);
568 std::vector<char> attrib_des(MED_COMMENT_SIZE * num_attrib + 1);
569 std::vector<char> group_names(MED_LNAME_SIZE * num_groups + 1);
570 char family_name[MED_NAME_SIZE + 1];
574 if (MEDfamily23Info(fid,
meshNames[index].c_str(),
i + 1, family_name,
575 &attribId[0], &attrib_val[0], &attrib_des[0],
576 &family_num, &group_names[0]) < 0) {
578 "Could not read info for MED2 family %d",
i + 1);
581 if (MEDfamilyInfo(fid,
meshNames[index].c_str(),
i + 1, family_name,
582 &family_num, &group_names[0]) < 0) {
584 "Could not read info for MED3 family %d",
i + 1);
589 for (
int g = 0;
g != num_groups;
g++) {
591 std::string(&group_names[MED_LNAME_SIZE *
g], MED_LNAME_SIZE - 1);
592 name.resize(NAME_TAG_SIZE - 1);
593 if (family_elem_map.find(family_num) == family_elem_map.end()) {
595 "MEDWORLD", Sev::warning,
596 "Family %d not read, likely type of element is not added "
597 "to moab database. Currently only triangle, quad, tetrahedral and "
598 "hexahedral elements are read to moab database",
601 group_elem_map[name].merge(family_elem_map.at(family_num));
607 if (MEDfileClose(fid) < 0) {
609 "Unable to close file '%s'", file.c_str());
626 max_id = (max_id < cit->getMeshsetId()) ? cit->getMeshsetId() : max_id;
630 for (std::map<string, Range>::const_iterator git = group_elem_map.begin();
631 git != group_elem_map.end(); git++) {
633 CubitMeshSet_multiIndex::index<
640 if (!git->second.empty()) {
647 MOFEM_LOG(
"MEDWORLD", Sev::verbose) << *cit;
662 boost::shared_ptr<std::vector<const CubitMeshSets *>> &meshsets_ptr) {
668 std::vector<const CubitMeshSets *> meshsets;
670 for (
auto &
m : meshsets_idx) {
671 meshsets.push_back(&
m);
674 std::sort(meshsets.begin(), meshsets.end(),
676 return a->getMeshsetId() < b->getMeshsetId();
680 boost::make_shared<std::vector<const CubitMeshSets *>>(meshsets);
692 boost::shared_ptr<std::vector<const CubitMeshSets *>> meshsets_ptr;
701 boost::shared_ptr<std::vector<const CubitMeshSets *>> meshsets_ptr,
702 boost::shared_ptr<Range> write_range_ptr,
int verb) {
709 <<
"WRITE_MED IS EXPERIMENTAL, MAY CONTAIN BUGS, ALWAYS CHECK THE OUTPUT "
713 MEDfileVersionOpen((
char *)file.c_str(), MED_ACC_CREAT, MED_MAJOR_NUM,
714 MED_MINOR_NUM, MED_RELEASE_NUM);
718 "Cannot create MED file");
723 CHKERR MEDfichDesEcr(fid, (
char *)
"MED file generated by MoFEM");
726 char dtUnit[MED_SNAME_SIZE + 1] =
"";
727 char axisName[3 * MED_SNAME_SIZE + 1] =
"";
728 char axisUnit[3 * MED_SNAME_SIZE + 1] =
"";
730 PetscBool is_cubit_meshset = PETSC_TRUE;
731 int med_mesh_name_id = 0;
734 char mesh_name_char[255];
735 std::string mesh_name =
"Mesh";
738 CHKERR PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"MED mesh options",
"");
739 CHKERR PetscOptionsString(
"-med_mesh_name",
"get med mesh name",
"",
740 mesh_name.c_str(), mesh_name_char, 255, PETSC_NULL);
741 ierr = PetscOptionsEnd();
744 mesh_name = mesh_name_char;
747 for (
auto &
m : *meshsets_ptr) {
748 if (
m->getName() == mesh_name) {
749 med_mesh_name_id =
m->getMeshsetId();
750 is_cubit_meshset = PETSC_FALSE;
757 for (
auto &
m : *meshsets_ptr) {
758 if (
m->getMeshsetId() == med_mesh_name_id)
759 mesh_name =
m->getName();
760 max_id = (max_id <
m->getMeshsetId()) ?
m->getMeshsetId() : max_id;
764 CHKERR MEDmeshCr(fid, mesh_name.c_str(), 3, 3, MED_UNSTRUCTURED_MESH,
765 "Mesh created", dtUnit, MED_SORT_DTIT, MED_CARTESIAN,
769 med_int family_id = 0;
770 std::map<std::vector<std::string>, std::tuple<med_int, std::vector<int>>>
772 std::map<EntityHandle, med_int> entityHandle_family_map;
775 shared_meshsets_map[std::vector<string>()] =
776 std::make_tuple(family_id, std::vector<int>());
780 std::string bc_type_name;
781 if (iit->getBcTypeULong() &
BLOCKSET) {
783 bc_type_name = iit->getName();
784 if (bc_type_name ==
"NoNameSet") {
785 bc_type_name =
"BLOCKSET_NoNameSet_";
786 bc_type_name += std::to_string(iit->getMeshsetId());
789 }
else if (iit->getBcTypeULong() &
SIDESET ||
790 iit->getBcTypeULong() &
NODESET) {
797 if ((iit->getBcType() & jj_bc_type).any()) {
804 bc_type_name += std::to_string(iit->getMeshsetId());
806 bc_type_name =
"UnknownSet";
816 for (
auto &entity : *write_range_ptr) {
818 std::vector<int> shared_meshsets;
819 std::vector<string> shared_names;
822 auto add_shared_meshset = [&](
auto &other_meshset) {
823 std::string other_name = get_set_name(other_meshset);
824 if (std::find(shared_names.begin(), shared_names.end(), other_name) ==
825 shared_names.end()) {
826 shared_meshsets.push_back(other_meshset->getMeshsetId());
827 shared_names.push_back(other_name);
832 for (
auto &other_meshset : *meshsets_ptr) {
834 if (med_mesh_name_id == other_meshset->getMeshsetId())
837 Range other_entities;
839 CHKERR moab.get_entities_by_handle(other_set, other_entities);
842 EntityType ent_type = moab.type_from_handle(entity);
844 bool is_in_meshset = moab.contains_entities(other_set, &entity, 1);
846 if (ent_type == MBVERTEX) {
849 bool is_in_higher_dim =
false;
850 Range entities_in_higher_dim;
851 for (
int i = 1;
i < 4;
i++) {
852 CHKERR moab.get_entities_by_dimension(other_set,
i,
853 entities_in_higher_dim);
854 if (!entities_in_higher_dim.empty()) {
855 is_in_higher_dim =
true;
859 if (is_in_higher_dim) {
863 add_shared_meshset(other_meshset);
866 add_shared_meshset(other_meshset);
872 auto it = shared_meshsets_map.find(shared_names);
873 if (it == shared_meshsets_map.end()) {
877 it = shared_meshsets_map
879 {shared_names, std::make_tuple(family_id, shared_meshsets)})
883 entityHandle_family_map[entity] = std::get<0>(it->second);
887 for (
const auto &it : shared_meshsets_map) {
889 std::string family_name =
"F_";
890 const auto &[family_id, shared_meshsets] = it.second;
891 family_name += std::to_string(family_id);
893 const auto &shared_meshset_names = it.first;
894 std::string group_name;
895 for (
const auto &name : shared_meshset_names) {
897 std::string meshset_name = name;
898 meshset_name.resize(MED_LNAME_SIZE,
' ');
899 group_name += meshset_name;
903 CHKERR MEDfamilyCr(fid, mesh_name.c_str(), family_name.c_str(), family_id,
904 shared_meshset_names.size(), group_name.c_str());
907 <<
"Creating family " << family_name <<
" with id " << family_id
908 <<
" and " << shared_meshset_names.size() <<
" groups " << std::endl;
913 moab.get_entities_by_type(0, MBVERTEX, verts);
915 std::vector<med_float> coord_med(3 * verts.size());
916 std::vector<med_int> fam;
917 std::vector<med_int> tags;
920 for (Range::iterator it = verts.begin(); it != verts.end(); ++it) {
922 moab.get_coords(&(*it), 1, coords);
923 coord_med[3 * (it - verts.begin())] = coords[0];
924 coord_med[3 * (it - verts.begin()) + 1] = coords[1];
925 coord_med[3 * (it - verts.begin()) + 2] = coords[2];
926 fam.push_back(entityHandle_family_map[*it]);
930 CHKERR MEDmeshNodeWr(fid, mesh_name.c_str(), MED_NO_DT, MED_NO_IT,
931 MED_UNDEF_DT, MED_FULL_INTERLACE, verts.size(),
932 &coord_med[0], MED_FALSE,
"", MED_TRUE, &tags[0],
936 for (EntityType ent_type = MBVERTEX; ent_type < MBMAXTYPE; ent_type++) {
939 moab.get_entities_by_type(0, ent_type, entities,
true);
941 ents_to_write = intersect(entities, *write_range_ptr);
943 if (ents_to_write.empty())
947 std::vector<med_int> tag_number;
948 std::vector<med_int> family_number;
949 std::vector<med_int> connectivity;
952 for (
auto &entity : ents_to_write) {
953 if (ent_type != MBVERTEX) {
955 family_number.push_back(entityHandle_family_map[entity]);
957 tag_number.push_back(entity);
959 std::vector<EntityHandle> conn;
960 moab.get_connectivity(&entity, 1, conn);
961 for (
auto &
c : conn) {
962 connectivity.push_back(
c);
969 auto get_med_element_type = [](EntityType ent_type) {
970 med_geometrie_element
type;
997 med_geometrie_element med_type = get_med_element_type(ent_type);
998 if (ent_type == MBENTITYSET) {
1001 CHKERR MEDmeshElementWr(fid, mesh_name.c_str(), MED_NO_DT, MED_NO_IT, 0.,
1002 MED_CELL, med_type, MED_NODAL, MED_FULL_INTERLACE,
1003 family_number.size(), &connectivity[0], MED_FALSE,
1004 nullptr, MED_TRUE, &tag_number[0], MED_TRUE,
1007 MOFEM_LOG_C(
"MEDWORLD", Sev::inform,
"Writing %i elements of type %i (%s) ",
1008 family_number.size(), med_type,
1009 moab::CN::EntityTypeName(ent_type));
1019 const bool load_series,
1020 const int only_step,
int verb) {
1024 med_idt fid = MEDfileOpen((
char *)file_name.c_str(), MED_LECTURE);
1027 "Unable to open file '%s'", file_name.c_str());
1030 med_int num_comp = MEDfieldnComponentByName(fid,
field_name.c_str());
1031 if (num_comp <= 0) {
1033 "Could not get number of components for MED field");
1036 char meshName[MED_NAME_SIZE + 1];
1037 char dtUnit[MED_SNAME_SIZE + 1];
1038 std::vector<char> compName(num_comp * MED_SNAME_SIZE + 1);
1039 std::vector<char> compUnit(num_comp * MED_SNAME_SIZE + 1);
1040 med_int numSteps = 0;
1041 med_type_champ
type;
1043 if (MEDfieldInfoByName(fid,
field_name.c_str(), meshName, &localMesh, &
type,
1044 &compName[0], &compUnit[0], dtUnit, &numSteps) < 0) {
1046 "Could not get MED field info");
1059 int num_comp_msh = (num_comp <= 1) ? 1
1060 : (num_comp <= 3) ? 3
1061 : (num_comp <= 9) ? 9
1069 std::vector<double> def_val(num_comp_msh, 0);
1071 tag_name.c_str(), num_comp_msh, MB_TYPE_DOUBLE,
th,
1072 MB_TAG_CREAT | MB_TAG_SPARSE, &def_val[0]);
1079 const med_entity_type entType[] = {MED_NODE, MED_CELL, MED_NODE_ELEMENT};
1080 const med_geometrie_element eleType[] = {
1081 MED_NONE, MED_SEG2, MED_TRIA3, MED_QUAD4, MED_TETRA4, MED_HEXA8,
1082 MED_PENTA6, MED_PYRA5, MED_SEG3, MED_TRIA6, MED_QUAD9, MED_TETRA10,
1083 MED_HEXA27, MED_POINT1, MED_QUAD8, MED_HEXA20, MED_PENTA15, MED_PYRA13};
1087 std::vector<std::pair<int, int>> pairs;
1088 for (
unsigned int i = 0;
i <
sizeof(entType) /
sizeof(entType[0]);
i++) {
1089 for (
unsigned int j = 0;
j <
sizeof(eleType) /
sizeof(eleType[0]);
j++) {
1090 if ((!
i && !
j) ||
j) {
1091 med_int
n = numSteps;
1093 pairs.push_back(std::pair<int, int>(
i,
j));
1094 numSteps = std::max(numSteps,
n);
1102 if (numSteps < 1 || pairs.empty()) {
1104 "Nothing to import from MED file");
1111 for (
int step = (only_step == -1) ? 0 : only_step; step < numSteps; step++) {
1113 if (!load_series && only_step != step)
1123 for (
unsigned int pair = 0; pair < pairs.size(); pair++) {
1126 med_entite_maillage ent = entType[pairs[pair].first];
1127 med_geometrie_element ele = eleType[pairs[pair].second];
1128 med_int numdt, numit, ngauss;
1130 if (MEDfieldComputingStepInfo(fid,
field_name.c_str(), step + 1, &numdt,
1133 "Could not read step info");
1136 char locName[MED_NAME_SIZE + 1], profileName[MED_NAME_SIZE + 1];
1141 med_int profileSize;
1142 med_int numVal = MEDfieldnValueWithProfile(
1143 fid,
field_name.c_str(), numdt, numit, ent, ele, 1,
1144 MED_COMPACT_STMODE, profileName, &profileSize, locName, &ngauss);
1159 std::vector<double> val(numVal * num_comp);
1160 if (MEDfieldValueWithProfileRd(fid,
field_name.c_str(), numdt, numit, ent,
1161 ele, MED_COMPACT_STMODE, profileName,
1162 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
1163 (
unsigned char *)&val[0]) < 0) {
1165 "Could not read field values");
1178 EntityType ent_type = MBMAXTYPE;
1189 "Not yet implemented for this cell %d", ele);
1191 if (ent_type != MBMAXTYPE) {
1194 CHKERR m_field.
get_moab().get_entities_by_type(meshset, ent_type,
1196 double e_vals[num_comp_msh];
1197 bzero(e_vals,
sizeof(
double) * num_comp_msh);
1198 std::vector<double>::iterator vit = val.begin();
1199 for (Range::iterator eit = ents.begin(); eit != ents.end(); eit++) {
1200 for (
int ii = 0; ii != num_comp; ii++, vit++) {
1207 CHKERR m_field.
get_moab().get_entities_by_type(meshset, ent_type,
1209 if (ents.size() * ngauss * num_comp != val.size()) {
1211 "data inconsistency");
1214 double e_vals[num_comp_msh];
1215 std::vector<double>::iterator vit = val.begin();
1216 for (Range::iterator eit = ents.begin(); eit != ents.end(); eit++) {
1217 bzero(e_vals,
sizeof(
double) * num_comp_msh);
1218 for (
int gg = 0; gg != ngauss; gg++) {
1219 for (
int ii = 0; ii != num_comp; ii++, vit++) {
1220 e_vals[ii] += *vit / ngauss;
1235 case MED_NODE_ELEMENT: {
1236 EntityType ent_type = MBVERTEX;
1238 CHKERR m_field.
get_moab().get_entities_by_type(meshset, ent_type, ents,
1240 double e_vals[num_comp_msh];
1241 bzero(e_vals,
sizeof(
double) * num_comp_msh);
1242 std::vector<double>::iterator vit = val.begin();
1243 for (Range::iterator eit = ents.begin(); eit != ents.end(); eit++) {
1244 for (
int ii = 0; ii != num_comp; ii++, vit++) {
1251 MOFEM_LOG_C(
"MEDWORLD", Sev::inform,
"Entity type %d not implemented",
1262 os <<
"field name: " << field_data.
fieldName;
1263 os <<
" mesh name: " << field_data.
meshName;
1264 os <<
" local mesh: " << ((field_data.
localMesh) ?
"true" :
"false");
1273 os <<
" componentNames:";
1274 for (
unsigned int ff = 0; ff != field_data.
componentNames.size(); ff++) {
1278 os <<
" componentUnits:";
1279 for (
unsigned int ff = 0; ff != field_data.
componentUnits.size(); ff++) {
1283 os <<
" dtUnit: " << field_data.
dtUnit << endl;
1284 os <<
" number of steps: " << field_data.
ncSteps;