35 unsigned id, type, region;
37 std::vector<size_type> nodes;
41 pgt = bgeot::simplex_geotrans(1,1);
44 pgt = bgeot::simplex_geotrans(2,1);
47 pgt = bgeot::parallelepiped_geotrans(2,1);
50 pgt = bgeot::simplex_geotrans(3,1);
53 pgt = bgeot::parallelepiped_geotrans(3,1);
56 pgt = bgeot::prism_geotrans(3,1);
59 pgt = bgeot::pyramid_QK_geotrans(1);
62 pgt = bgeot::simplex_geotrans(1,2);
65 pgt = bgeot::simplex_geotrans(2,2);
68 pgt = bgeot::parallelepiped_geotrans(2,2);
71 pgt = bgeot::simplex_geotrans(3,2);
74 pgt = bgeot::parallelepiped_geotrans(3,2);
77 GMM_WARNING2(
"ignoring point element");
80 pgt = bgeot::Q2_incomplete_geotrans(2);
83 pgt = bgeot::Q2_incomplete_geotrans(3);
86 pgt = bgeot::simplex_geotrans(1,3);
89 pgt = bgeot::simplex_geotrans(2,3);
92 pgt = bgeot::simplex_geotrans(2, 4);
95 pgt = bgeot::simplex_geotrans(1, 4);
99 GMM_ASSERT1(
false,
"gmsh element type " << type <<
" is unknown.");
104 void set_nb_nodes() {
166 GMM_ASSERT1(
false,
"the gmsh element type " << type <<
" is unknown..");
171 bool operator<(
const gmsh_cv_info& other)
const {
172 unsigned this_dim = (type == 15) ? 0 : pgt->dim();
173 unsigned other_dim = (other.type == 15) ? 0 : other.pgt->dim();
174 if (this_dim == other_dim)
return region < other.region;
175 return this_dim > other_dim;
181 std::map<std::string, size_type> region_map;
182 bgeot::read_until(f,
"$PhysicalNames");
186 std::string region_name;
187 for (
size_type region_cnt=0; region_cnt < nb_regions; ++ region_cnt) {
189 std::getline(f, region_name);
191 size_t pos = region_name.find_first_of(
"\"");
192 if (pos != region_name.npos) {
193 region_name.erase(0, pos+1);
194 pos = region_name.find_last_of(
"\"");
195 region_name.erase(pos);
197 region_map[region_name] = ri;
223 static void import_gmsh_mesh_file
224 (std::istream& f, mesh& m,
int deprecate=0,
225 std::map<std::string, size_type> *region_map=NULL,
226 std::set<size_type> *lower_dim_convex_rg=NULL,
227 bool add_all_element_type =
false,
228 bool remove_last_dimension =
true,
229 std::map<
size_type, std::set<size_type>> *nodal_map = NULL,
230 bool remove_duplicated_nodes =
true) {
231 gmm::stream_standard_locale sl(f);
237 GMM_WARNING4(
"" << endl
238 <<
" deprecate: " << endl
239 <<
" static void" << endl
240 <<
" import_gmsh_mesh_file(std::istream& f,"
241 <<
" mesh& , int version)" << endl
242 <<
" replace with:" << endl
243 <<
" static void" << endl
244 <<
" import_gmsh_mesh_file(std::istream& f,"
252 if (bgeot::casecmp(header,
"$MeshFormat")==0)
254 else if (bgeot::casecmp(header,
"$NOD")==0)
257 GMM_ASSERT1(
false,
"can't read Gmsh format: " << header);
260 if (region_map != NULL) {
267 bgeot::read_until(f,
"$Nodes");
272 if (version >= 4.05) {
273 f >> nb_block >> nb_node; bgeot::read_until(f,
"\n");
274 }
else if (version >= 4.) {
275 f >> nb_block >> nb_node;
282 std::map<size_type, size_type> msh_node_2_getfem_node;
283 std::vector<size_type> inds(nb_node);
284 for (
size_type block=0; block < nb_block; ++block) {
286 f >> dummy >> dummy >> dummy >> nb_node;
289 inds.resize(nb_node);
290 if (version >= 4.05) {
291 for (
size_type node_cnt=0; node_cnt < nb_node; ++node_cnt)
295 for (
size_type node_cnt=0; node_cnt < nb_node; ++node_cnt) {
298 if (version < 4.05) f >> node_id;
else node_id = inds[node_cnt];
300 f >> n[0] >> n[1] >> n[2];
301 msh_node_2_getfem_node[node_id]
302 = m.add_point(n, remove_duplicated_nodes ? 0. : -1.);
307 bgeot::read_until(f,
"$Endnodes");
309 bgeot::read_until(f,
"$ENDNOD");
313 bgeot::read_until(f,
"$Elements");
315 bgeot::read_until(f,
"$ELM");
318 if (version >= 4.05) {
319 f >> nb_block >> nb_cv; bgeot::read_until(f,
"\n");
320 }
else if (version >= 4.) {
321 f >> nb_block >> nb_cv;
328 std::vector<gmsh_cv_info> cvlst; cvlst.reserve(nb_cv);
330 for (
size_type block=0; block < nb_block; ++block) {
331 unsigned dimr, type, region;
333 f >> dimr >> region >> type >> nb_cv;
334 if (reg.is_in(region)) {
335 GMM_WARNING2(
"Two regions share the same number, "
336 "the region numbering is modified");
337 while (reg.is_in(region)) region += 5;
343 cvlst.push_back(gmsh_cv_info());
344 gmsh_cv_info &ci = cvlst.back();
348 unsigned cv_nb_nodes;
350 if (
int(version) == 2) {
353 GMM_ASSERT1(nbtags > 0 && nbtags <= 3,
354 "Number of tags " << nbtags <<
" is not managed.");
356 if (nbtags > 1) f >> dummy;
357 if (nbtags > 2) f >> dummy;
361 cv_nb_nodes = unsigned(ci.nodes.size());
362 }
else if (
int(version) == 1) {
363 f >> type >> region >> dummy >> cv_nb_nodes;
365 ci.nodes.resize(cv_nb_nodes);
371 for (
size_type i=0; i < cv_nb_nodes; ++i) {
374 const auto it = msh_node_2_getfem_node.find(j);
375 GMM_ASSERT1(it != msh_node_2_getfem_node.end(),
376 "Invalid node ID " << j <<
" in gmsh element "
378 ci.nodes[i] = it->second;
384 std::vector<size_type> tmp_nodes(ci.nodes);
387 ci.nodes[2] = tmp_nodes[3];
388 ci.nodes[3] = tmp_nodes[2];
393 ci.nodes[2] = tmp_nodes[3];
394 ci.nodes[3] = tmp_nodes[2];
397 ci.nodes[6] = tmp_nodes[7];
398 ci.nodes[7] = tmp_nodes[6];
402 ci.nodes[1] = tmp_nodes[2];
403 ci.nodes[2] = tmp_nodes[1];
409 ci.nodes[1] = tmp_nodes[2];
410 ci.nodes[2] = tmp_nodes[1];
414 ci.nodes[1] = tmp_nodes[3];
415 ci.nodes[2] = tmp_nodes[1];
416 ci.nodes[3] = tmp_nodes[5];
418 ci.nodes[5] = tmp_nodes[2];
422 ci.nodes[1] = tmp_nodes[4];
423 ci.nodes[2] = tmp_nodes[1];
424 ci.nodes[3] = tmp_nodes[7];
425 ci.nodes[4] = tmp_nodes[8];
427 ci.nodes[6] = tmp_nodes[3];
428 ci.nodes[7] = tmp_nodes[6];
429 ci.nodes[8] = tmp_nodes[2];
433 ci.nodes[1] = tmp_nodes[4];
434 ci.nodes[2] = tmp_nodes[1];
435 ci.nodes[3] = tmp_nodes[6];
436 ci.nodes[4] = tmp_nodes[5];
437 ci.nodes[5] = tmp_nodes[2];
438 ci.nodes[6] = tmp_nodes[7];
439 ci.nodes[7] = tmp_nodes[9];
441 ci.nodes[9] = tmp_nodes[3];
445 ci.nodes[1] = tmp_nodes[8];
446 ci.nodes[2] = tmp_nodes[1];
447 ci.nodes[3] = tmp_nodes[9];
448 ci.nodes[4] = tmp_nodes[20];
449 ci.nodes[5] = tmp_nodes[11];
450 ci.nodes[6] = tmp_nodes[3];
451 ci.nodes[7] = tmp_nodes[13];
452 ci.nodes[8] = tmp_nodes[2];
453 ci.nodes[9] = tmp_nodes[10];
454 ci.nodes[10] = tmp_nodes[21];
455 ci.nodes[11] = tmp_nodes[12];
456 ci.nodes[12] = tmp_nodes[22];
457 ci.nodes[13] = tmp_nodes[26];
458 ci.nodes[14] = tmp_nodes[23];
460 ci.nodes[16] = tmp_nodes[24];
461 ci.nodes[17] = tmp_nodes[14];
462 ci.nodes[18] = tmp_nodes[4];
463 ci.nodes[19] = tmp_nodes[16];
464 ci.nodes[20] = tmp_nodes[5];
465 ci.nodes[21] = tmp_nodes[17];
466 ci.nodes[22] = tmp_nodes[25];
467 ci.nodes[23] = tmp_nodes[18];
468 ci.nodes[24] = tmp_nodes[7];
469 ci.nodes[25] = tmp_nodes[19];
470 ci.nodes[26] = tmp_nodes[6];
474 ci.nodes[1] = tmp_nodes[4];
475 ci.nodes[2] = tmp_nodes[1];
476 ci.nodes[3] = tmp_nodes[7];
477 ci.nodes[4] = tmp_nodes[5];
478 ci.nodes[5] = tmp_nodes[3];
479 ci.nodes[6] = tmp_nodes[6];
480 ci.nodes[7] = tmp_nodes[2];
484 ci.nodes[1] = tmp_nodes[8];
485 ci.nodes[2] = tmp_nodes[1];
486 ci.nodes[3] = tmp_nodes[9];
487 ci.nodes[4] = tmp_nodes[11];
488 ci.nodes[5] = tmp_nodes[3];
489 ci.nodes[6] = tmp_nodes[13];
490 ci.nodes[7] = tmp_nodes[2];
491 ci.nodes[8] = tmp_nodes[10];
492 ci.nodes[9] = tmp_nodes[12];
493 ci.nodes[10] = tmp_nodes[15];
494 ci.nodes[11] = tmp_nodes[14];
495 ci.nodes[12] = tmp_nodes[4];
496 ci.nodes[13] = tmp_nodes[16];
497 ci.nodes[14] = tmp_nodes[5];
498 ci.nodes[15] = tmp_nodes[17];
499 ci.nodes[16] = tmp_nodes[18];
500 ci.nodes[17] = tmp_nodes[7];
501 ci.nodes[18] = tmp_nodes[19];
502 ci.nodes[19] = tmp_nodes[6];
506 ci.nodes[1] = tmp_nodes[2];
507 ci.nodes[2] = tmp_nodes[3];
508 ci.nodes[3] = tmp_nodes[1];
512 ci.nodes[1] = tmp_nodes[3];
513 ci.nodes[2] = tmp_nodes[4];
514 ci.nodes[3] = tmp_nodes[1];
515 ci.nodes[4] = tmp_nodes[8];
516 ci.nodes[5] = tmp_nodes[9];
517 ci.nodes[6] = tmp_nodes[5];
519 ci.nodes[8] = tmp_nodes[6];
520 ci.nodes[9] = tmp_nodes[2];
524 ci.nodes[1] = tmp_nodes[3];
525 ci.nodes[2] = tmp_nodes[4];
526 ci.nodes[3] = tmp_nodes[5];
527 ci.nodes[4] = tmp_nodes[1];
528 ci.nodes[5] = tmp_nodes[11];
529 ci.nodes[6] = tmp_nodes[12];
530 ci.nodes[7] = tmp_nodes[13];
531 ci.nodes[8] = tmp_nodes[6];
532 ci.nodes[9] = tmp_nodes[10];
533 ci.nodes[10] = tmp_nodes[14];
534 ci.nodes[11] = tmp_nodes[7];
535 ci.nodes[12] = tmp_nodes[9];
536 ci.nodes[13] = tmp_nodes[8];
537 ci.nodes[14] = tmp_nodes[2];
541 ci.nodes[1] = tmp_nodes[2];
542 ci.nodes[2] = tmp_nodes[3];
543 ci.nodes[3] = tmp_nodes[4];
544 ci.nodes[4] = tmp_nodes[1];
550 nb_cv = cvlst.size();
552 std::sort(cvlst.begin(), cvlst.end());
553 if (cvlst.front().type == 15) {
554 GMM_WARNING2(
"Only nodes defined in the mesh! No elements are added.");
558 unsigned N = cvlst.front().pgt->dim();
561 gmsh_cv_info &ci = cvlst[cv];
562 bool is_node = (ci.type == 15);
563 unsigned ci_dim = (is_node) ? 0 : ci.pgt->dim();
569 size_type ic = m.add_convex(ci.pgt, ci.nodes.begin());
571 m.region(ci.region).add(ic);
578 if (lower_dim_convex_rg != NULL &&
579 lower_dim_convex_rg->find(ci.region) != lower_dim_convex_rg->end()
581 size_type ic = m.add_convex(ci.pgt, ci.nodes.begin());
582 cvok =
true; m.region(ci.region).add(ic);
586 bgeot::mesh_structure::ind_cv_ct ct=m.convex_to_point(ci.nodes[0]);
587 for (bgeot::mesh_structure::ind_cv_ct::const_iterator
588 it = ct.begin(); it != ct.end(); ++it) {
589 if (m.structure_of_convex(*it)->dim() == ci_dim + 1) {
591 face < m.structure_of_convex(*it)->nb_faces(); ++face) {
592 if (m.is_convex_face_having_points(*it, face,
595 m.region(ci.region).add(*it,face);
601 if (is_node && (nodal_map != NULL)) {
602 for (
auto i : ci.nodes) (*nodal_map)[ci.region].insert(i);
607 if (nodal_map == NULL){
608 GMM_WARNING2(
"gmsh import ignored a node id: "
609 << ci.id <<
" region :" << ci.region <<
610 " point is not added explicitly as an element.");
613 else if (add_all_element_type) {
614 size_type ic = m.add_convex(ci.pgt, ci.nodes.begin());
615 m.region(ci.region).add(ic);
618 GMM_WARNING2(
"gmsh import ignored an element of type "
620 " as it does not belong to the face of another element");
634 static void import_gid_mesh_file(std::istream& f, mesh& m) {
635 gmm::stream_standard_locale sl(f);
638 enum { LIN,TRI,QUAD,TETR, PRISM, HEX,BADELTYPE } eltype=BADELTYPE;
640 std::map<size_type, size_type> msh_node_2_getfem_node;
641 std::vector<size_type> cv_nodes, getfem_cv_nodes;
642 bool nodes_done =
false;
644 if (!f.eof()) f >> std::ws;
645 if (f.eof() || !bgeot::read_until(f,
"MESH"))
break;
646 std::string selemtype;
647 f >> bgeot::skip(
"DIMENSION") >> dim
648 >> bgeot::skip(
"ELEMTYPE") >> std::ws
650 >> bgeot::skip(
"NNODE") >> nnode;
651 if (bgeot::casecmp(selemtype,
"linear")==0) { eltype = LIN; }
652 else if (bgeot::casecmp(selemtype,
"triangle")==0) { eltype = TRI; }
653 else if (bgeot::casecmp(selemtype,
"quadrilateral")==0) { eltype = QUAD; }
654 else if (bgeot::casecmp(selemtype,
"tetrahedra")==0) { eltype = TETR; }
655 else if (bgeot::casecmp(selemtype,
"prisma")==0) { eltype = PRISM; }
656 else if (bgeot::casecmp(selemtype,
"hexahedra")==0) { eltype = HEX; }
657 else GMM_ASSERT1(
false,
"unknown element type '"<< selemtype <<
"'");
658 GMM_ASSERT1(!f.eof(),
"File ended before coordinates");
659 f >> bgeot::skip(
"COORDINATES");
662 dal::bit_vector gid_nodes_used;
668 if (bgeot::casecmp(ls,
"END COORDINATES", 15)==0)
break;
669 std::stringstream s; s << ls;
673 gid_nodes[id].resize(dim); gid_nodes_used.add(
id);
674 for (
size_type i=0; i < dim; ++i) s >> gid_nodes[id][i];
678 GMM_ASSERT1(gid_nodes_used.card() != 0,
"no nodes in the mesh!");
681 std::vector<bool> direction_useless(3,
true);
682 base_node first_pt = gid_nodes[gid_nodes_used.first()];
683 for (dal::bv_visitor ip(gid_nodes_used); !ip.finished(); ++ip) {
684 for (
size_type j=0; j < first_pt.size(); ++j) {
685 if (direction_useless[j] && (gmm::abs(gid_nodes[ip][j]-first_pt[j]) > 1e-13))
686 direction_useless[j] =
false;
690 for (
size_type j=0; j < dim; ++j)
if (!direction_useless[j]) dim2++;
691 for (dal::bv_visitor ip(gid_nodes_used); !ip.finished(); ++ip) {
693 for (
size_type j=0, cnt=0; j < dim; ++j)
if (!direction_useless[j]) n[cnt++]=gid_nodes[ip][j];
694 msh_node_2_getfem_node[ip] = m.add_point(n);
698 bgeot::read_until(f,
"ELEMENTS");
700 std::vector<size_type> order(nnode);
701 for (
size_type i=0; i < nnode; ++i) order[i]=i;
705 if (nnode == 2) pgt = bgeot::simplex_geotrans(1,1);
706 else if (nnode == 3) {
707 pgt = bgeot::simplex_geotrans(1,2);
708 std::swap(order[1],order[2]);
712 if (nnode == 3) pgt = bgeot::simplex_geotrans(2,1);
713 else if (nnode == 6) {
714 static size_type lorder[6] = {0,3,1,5,4,2};
715 pgt = bgeot::simplex_geotrans(2,2);
716 std::copy(lorder,lorder+nnode,order.begin());
720 if (nnode == 4) pgt = bgeot::parallelepiped_geotrans(2,1);
721 else if (nnode == 9) {
722 static size_type lorder[9] = {0,4,1, 7,8,5, 3,6,2};
723 pgt = bgeot::parallelepiped_geotrans(2,2);
724 std::copy(lorder,lorder+nnode,order.begin());
728 if (nnode == 4) pgt = bgeot::simplex_geotrans(3,1);
729 else if (nnode == 10) {
730 static size_type lorder[10] = {0,4,1, 7,8, 3, 6, 5, 9, 2};
731 pgt = bgeot::simplex_geotrans(3,2);
732 std::copy(lorder,lorder+nnode,order.begin());
736 if (nnode == 6) pgt = bgeot::prism_geotrans(3,1);
739 if (nnode == 8) pgt = bgeot::parallelepiped_geotrans(3,1);
740 else if (nnode == 27) {
741 static size_type lorder[27] = {0,8,1, 12,21,13, 4,16,5,
742 11,20,9, 22,26,24, 19,25,17,
743 3,10,2, 15,23,14, 7,18,6};
744 pgt = bgeot::parallelepiped_geotrans(3,2);
745 std::copy(lorder,lorder+nnode,order.begin());
748 default: GMM_ASSERT1(
false,
"");
break;
750 GMM_ASSERT1(pgt != NULL,
"unknown element type " << selemtype
751 <<
" with " << nnode <<
"nodes");
756 if (bgeot::casecmp(ls,
"END ELEMENTS", 12)==0)
break;
757 std::stringstream s; s << ls;
760 cv_nodes.resize(nnode);
764 std::map<size_type, size_type>::iterator
765 it = msh_node_2_getfem_node.find(j);
766 GMM_ASSERT1(it != msh_node_2_getfem_node.end(),
767 "Invalid node ID " << j <<
" in GiD element " << cv_id);
768 cv_nodes[i] = it->second;
770 getfem_cv_nodes.resize(nnode);
772 getfem_cv_nodes[i] = cv_nodes[order[i]];
778 m.add_convex(pgt, getfem_cv_nodes.begin());
790 static void import_cdb_mesh_file(std::istream& f, mesh& m,
793 std::map<size_type, size_type> cdb_node_2_getfem_node;
794 std::vector<size_type> getfem_cv_nodes;
795 std::vector<std::string> elt_types;
796 std::vector<size_type> elt_cnt;
797 std::vector<dal::bit_vector> regions;
802 std::getline(f,line);
803 pos = line.find_first_not_of(
" ");
804 if (bgeot::casecmp(line.substr(pos,2),
"ET") == 0) {
806 std::string type_name;
807 pos = line.find_first_of(
",")+1;
808 pos2 = line.find_first_of(
",", pos);
809 itype = std::stol(line.substr(pos, pos2-pos));
810 pos = line.find_first_not_of(
" ,\n\r\t", pos2);
811 pos2 = line.find_first_of(
" ,\n\r\t", pos);
812 type_name = line.substr(pos, pos2-pos);
814 = (type_name.find_first_not_of(
"0123456789") == std::string::npos);
815 for (
auto&& c : type_name) c = char(std::toupper(c));
817 if (elt_types.size() < itype+1)
818 elt_types.resize(itype+1);
820 elt_types[itype] =
"";
822 size_type type_num = std::stol(type_name);
823 if (type_num == 42 || type_num == 82 ||
824 type_num == 182 || type_num == 183)
825 elt_types[itype] =
"PLANE";
826 else if (type_num == 45 || type_num == 73 || type_num == 87 ||
827 type_num == 90 || type_num == 92 || type_num == 95 ||
828 type_num == 162 || type_num == 185 || type_num == 186 ||
829 type_num == 187 || type_num == 191)
830 elt_types[itype] =
"SOLID";
831 else if (type_num == 89)
832 elt_types[itype] =
"VISCO";
834 elt_types[itype].append(type_name);
836 else if (bgeot::casecmp(line.substr(pos,5),
"KEYOP") == 0) {
838 pos = line.find_first_of(
",")+1;
839 pos2 = line.find_first_of(
",", pos);
840 itype = std::stol(line.substr(pos, pos2-pos));
842 pos2 = line.find_first_of(
",", pos);
843 knum = std::stol(line.substr(pos, pos2-pos));
844 keyval = std::stol(line.substr(pos2+1));
845 if (knum == 1 && itype < elt_types.size() &&
846 elt_types[itype].size() == 7 &&
847 bgeot::casecmp(elt_types[itype].substr(0,7),
"MESH200") == 0) {
848 std::stringstream ss;
849 ss <<
"MESH200_" << keyval;
850 elt_types[itype] = ss.str();
853 else if (bgeot::casecmp(line.substr(pos,6),
"NBLOCK") == 0)
858 elt_cnt.resize(elt_types.size());
861 size_type fields1, fieldwidth1, fields2, fieldwidth2;
863 std::string fortran_fmt;
864 std::getline(f,fortran_fmt);
865 pos = fortran_fmt.find_first_of(
"(")+1;
866 pos2 = fortran_fmt.find_first_of(
"iI", pos);
867 fields1 = std::stol(fortran_fmt.substr(pos, pos2-pos));
869 pos2 = fortran_fmt.find_first_of(
",", pos);
870 fieldwidth1 = std::stol(fortran_fmt.substr(pos, pos2-pos));
872 pos2 = fortran_fmt.find_first_of(
"eE", pos);
873 fields2 = std::stol(fortran_fmt.substr(pos, pos2-pos));
875 pos2 = fortran_fmt.find_first_of(
".", pos);
876 fieldwidth2 = std::stol(fortran_fmt.substr(pos, pos2-pos));
877 GMM_ASSERT1(fields1 >= 1 && fields2 >= 3 ,
878 "Ansys mesh import routine requires NBLOCK entries with at least "
879 "1 integer field and 3 float number fields");
885 std::getline(f,line);
886 if (line.compare(0,1,
"N") == 0 || line.compare(0,1,
"!") == 0)
889 nodeid = std::stol(line.substr(0, fieldwidth1));
890 pos = fields1*fieldwidth1;
891 for (
size_type j=0; j < 3; ++j, pos += fieldwidth2)
892 if (pos < line.length())
893 pt[j] = std::stod(line.substr(pos, fieldwidth2));
897 cdb_node_2_getfem_node[nodeid] = m.add_point(pt, -1.);
900 while (bgeot::casecmp(line.substr(0,6),
"EBLOCK") != 0) {
903 std::getline(f,line);
910 std::string fortran_fmt;
911 std::getline(f,fortran_fmt);
913 pos = fortran_fmt.find_first_of(
"(")+1;
914 pos2 = fortran_fmt.find_first_of(
"iI", pos);
915 fieldsno = std::stol(fortran_fmt.substr(pos, pos2-pos));
917 pos2 = fortran_fmt.find_first_of(
")\n", pos);
918 fieldwidth = std::stol(fortran_fmt.substr(pos, pos2-pos));
919 GMM_ASSERT1(fieldsno == 19,
"Ansys mesh import routine requires EBLOCK "
920 "entries with 19 fields");
923 size_type II,JJ,KK,LL,MM,NN,OO,PP,QQ,RR,SS,TT,UU,VV,WW,XX,YY,ZZ,AA,BB;
925 GMM_ASSERT1(!f.eof(),
"File ended before all elements could be read");
927 std::getline(f,line);
929 long int ii = std::stol(line.substr(0,fieldwidth));
935 itype = std::stol(line.substr(fieldwidth,fieldwidth));
936 nodesno = std::stol(line.substr(8*fieldwidth,fieldwidth));
937 line = line.substr(11*fieldwidth);
939 if (imat_filt !=
size_type(-1) && imat != imat_filt) {
941 std::getline(f,line);
945 if (nodesno >= 1) II = std::stol(line.substr(0,fieldwidth));
946 if (nodesno >= 2) JJ = std::stol(line.substr(1*fieldwidth,fieldwidth));
947 if (nodesno >= 3) KK = std::stol(line.substr(2*fieldwidth,fieldwidth));
948 if (nodesno >= 4) LL = std::stol(line.substr(3*fieldwidth,fieldwidth));
949 if (nodesno >= 5) MM = std::stol(line.substr(4*fieldwidth,fieldwidth));
950 if (nodesno >= 6) NN = std::stol(line.substr(5*fieldwidth,fieldwidth));
951 if (nodesno >= 7) OO = std::stol(line.substr(6*fieldwidth,fieldwidth));
952 if (nodesno >= 8) PP = std::stol(line.substr(7*fieldwidth,fieldwidth));
954 std::getline(f,line);
955 if (nodesno >= 9) QQ = std::stol(line.substr(0,fieldwidth));
956 if (nodesno >= 10) RR = std::stol(line.substr(1*fieldwidth,fieldwidth));
957 if (nodesno >= 11) SS = std::stol(line.substr(2*fieldwidth,fieldwidth));
958 if (nodesno >= 12) TT = std::stol(line.substr(3*fieldwidth,fieldwidth));
959 if (nodesno >= 13) UU = std::stol(line.substr(4*fieldwidth,fieldwidth));
960 if (nodesno >= 14) VV = std::stol(line.substr(5*fieldwidth,fieldwidth));
961 if (nodesno >= 15) WW = std::stol(line.substr(6*fieldwidth,fieldwidth));
962 if (nodesno >= 16) XX = std::stol(line.substr(7*fieldwidth,fieldwidth));
963 if (nodesno >= 17) YY = std::stol(line.substr(8*fieldwidth,fieldwidth));
964 if (nodesno >= 18) ZZ = std::stol(line.substr(9*fieldwidth,fieldwidth));
965 if (nodesno >= 19) AA = std::stol(line.substr(10*fieldwidth,fieldwidth));
966 if (nodesno >= 20) BB = std::stol(line.substr(11*fieldwidth,fieldwidth));
969 if (imat+1 > regions.size())
970 regions.resize(imat+1);
974 std::string eltname(
"MESH200_4");
975 if (elt_types.size() > itype && elt_types[itype].size() > 0)
976 eltname = elt_types[itype];
978 if (eltname.compare(
"MESH200_4") == 0) {
979 getfem_cv_nodes.resize(3);
980 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
981 getfem_cv_nodes[1] = cdb_node_2_getfem_node[JJ];
982 getfem_cv_nodes[2] = cdb_node_2_getfem_node[KK];
983 regions[imat].add(m.add_convex(bgeot::simplex_geotrans(2,1),
984 getfem_cv_nodes.begin()));
985 if (itype < elt_cnt.size())
989 GMM_WARNING2(
"Ignoring ANSYS element " << eltname
990 <<
". Import not supported yet.");
993 else if (nodesno == 4) {
996 std::string eltname(
"MESH200_6");
997 if (elt_types.size() > itype && elt_types[itype].size() > 0)
998 eltname = elt_types[itype];
1000 if (eltname.compare(
"MESH200_6") == 0 ||
1001 eltname.compare(
"PLANE42") == 0 ||
1002 eltname.compare(
"PLANE182") == 0) {
1003 getfem_cv_nodes.resize(4);
1004 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1005 getfem_cv_nodes[1] = cdb_node_2_getfem_node[JJ];
1006 getfem_cv_nodes[2] = cdb_node_2_getfem_node[LL];
1007 getfem_cv_nodes[3] = cdb_node_2_getfem_node[KK];
1008 regions[imat].add(m.add_convex(bgeot::parallelepiped_geotrans(2,1),
1009 getfem_cv_nodes.begin()));
1010 if (itype < elt_cnt.size())
1011 elt_cnt[itype] += 1;
1013 else if (eltname.compare(
"MESH200_8") == 0 ||
1014 eltname.compare(
"SOLID72") == 0) {
1015 getfem_cv_nodes.resize(4);
1016 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1017 getfem_cv_nodes[1] = cdb_node_2_getfem_node[JJ];
1018 getfem_cv_nodes[2] = cdb_node_2_getfem_node[KK];
1019 getfem_cv_nodes[3] = cdb_node_2_getfem_node[LL];
1020 regions[imat].add(m.add_convex(bgeot::simplex_geotrans(3,1),
1021 getfem_cv_nodes.begin()));
1022 if (itype < elt_cnt.size())
1023 elt_cnt[itype] += 1;
1026 else if (nodesno == 6) {
1028 std::string eltname(
"MESH200_5");
1029 if (elt_types.size() > itype && elt_types[itype].size() > 0)
1030 eltname = elt_types[itype];
1031 if (eltname.compare(
"MESH200_5") == 0 ||
1032 eltname.compare(
"PLANE183") == 0) {
1033 getfem_cv_nodes.resize(6);
1034 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1035 getfem_cv_nodes[1] = cdb_node_2_getfem_node[LL];
1036 getfem_cv_nodes[2] = cdb_node_2_getfem_node[JJ];
1037 getfem_cv_nodes[3] = cdb_node_2_getfem_node[NN];
1038 getfem_cv_nodes[4] = cdb_node_2_getfem_node[MM];
1039 getfem_cv_nodes[5] = cdb_node_2_getfem_node[KK];
1040 regions[imat].add(m.add_convex(bgeot::simplex_geotrans(2,2),
1041 getfem_cv_nodes.begin()));
1042 if (itype < elt_cnt.size())
1043 elt_cnt[itype] += 1;
1046 else if (nodesno == 8) {
1049 std::string eltname(
"MESH200_10");
1050 if (elt_types.size() > itype && elt_types[itype].size() > 0)
1051 eltname = elt_types[itype];
1053 if (eltname.compare(
"MESH200_7") == 0 ||
1054 eltname.compare(
"PLANE82") == 0 ||
1055 eltname.compare(
"PLANE183") == 0) {
1056 if (KK == LL && KK == OO) {
1057 getfem_cv_nodes.resize(6);
1058 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1059 getfem_cv_nodes[1] = cdb_node_2_getfem_node[MM];
1060 getfem_cv_nodes[2] = cdb_node_2_getfem_node[JJ];
1061 getfem_cv_nodes[3] = cdb_node_2_getfem_node[PP];
1062 getfem_cv_nodes[4] = cdb_node_2_getfem_node[NN];
1063 getfem_cv_nodes[5] = cdb_node_2_getfem_node[KK];
1064 regions[imat].add(m.add_convex(bgeot::simplex_geotrans(2,2),
1065 getfem_cv_nodes.begin()));
1067 getfem_cv_nodes.resize(8);
1068 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1069 getfem_cv_nodes[1] = cdb_node_2_getfem_node[MM];
1070 getfem_cv_nodes[2] = cdb_node_2_getfem_node[JJ];
1071 getfem_cv_nodes[3] = cdb_node_2_getfem_node[PP];
1072 getfem_cv_nodes[4] = cdb_node_2_getfem_node[NN];
1073 getfem_cv_nodes[5] = cdb_node_2_getfem_node[LL];
1074 getfem_cv_nodes[6] = cdb_node_2_getfem_node[OO];
1075 getfem_cv_nodes[7] = cdb_node_2_getfem_node[KK];
1076 regions[imat].add(m.add_convex(bgeot::Q2_incomplete_geotrans(2),
1077 getfem_cv_nodes.begin()));
1079 if (itype < elt_cnt.size())
1080 elt_cnt[itype] += 1;
1082 else if (eltname.compare(
"MESH200_10") == 0 ||
1083 eltname.compare(
"SOLID45") == 0 ||
1084 eltname.compare(
"SOLID185") == 0) {
1085 if (KK == LL && OO == PP) {
1086 if (MM == NN && NN == OO) {
1087 getfem_cv_nodes.resize(4);
1088 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1089 getfem_cv_nodes[1] = cdb_node_2_getfem_node[JJ];
1090 getfem_cv_nodes[2] = cdb_node_2_getfem_node[KK];
1091 getfem_cv_nodes[3] = cdb_node_2_getfem_node[MM];
1092 regions[imat].add(m.add_convex(bgeot::simplex_geotrans(3,1),
1093 getfem_cv_nodes.begin()));
1096 getfem_cv_nodes.resize(6);
1097 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1098 getfem_cv_nodes[1] = cdb_node_2_getfem_node[JJ];
1099 getfem_cv_nodes[2] = cdb_node_2_getfem_node[KK];
1100 getfem_cv_nodes[3] = cdb_node_2_getfem_node[MM];
1101 getfem_cv_nodes[4] = cdb_node_2_getfem_node[NN];
1102 getfem_cv_nodes[5] = cdb_node_2_getfem_node[OO];
1103 regions[imat].add(m.add_convex(bgeot::prism_geotrans(3,1),
1104 getfem_cv_nodes.begin()));
1108 getfem_cv_nodes.resize(8);
1109 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1110 getfem_cv_nodes[1] = cdb_node_2_getfem_node[JJ];
1111 getfem_cv_nodes[2] = cdb_node_2_getfem_node[LL];
1112 getfem_cv_nodes[3] = cdb_node_2_getfem_node[KK];
1113 getfem_cv_nodes[4] = cdb_node_2_getfem_node[MM];
1114 getfem_cv_nodes[5] = cdb_node_2_getfem_node[NN];
1115 getfem_cv_nodes[6] = cdb_node_2_getfem_node[PP];
1116 getfem_cv_nodes[7] = cdb_node_2_getfem_node[OO];
1117 regions[imat].add(m.add_convex(bgeot::parallelepiped_geotrans(3,1),
1118 getfem_cv_nodes.begin()));
1120 if (itype < elt_cnt.size())
1121 elt_cnt[itype] += 1;
1124 else if (nodesno == 10) {
1127 std::string eltname(
"MESH200_9");
1128 if (elt_types.size() > itype && elt_types[itype].size() > 0)
1129 eltname = elt_types[itype];
1131 if (eltname.compare(
"MESH200_9") == 0 ||
1132 eltname.compare(
"SOLID87") == 0 ||
1133 eltname.compare(
"SOLID92") == 0 ||
1134 eltname.compare(
"SOLID162") == 0 ||
1135 eltname.compare(
"SOLID187") == 0) {
1136 getfem_cv_nodes.resize(10);
1137 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1138 getfem_cv_nodes[1] = cdb_node_2_getfem_node[MM];
1139 getfem_cv_nodes[2] = cdb_node_2_getfem_node[JJ];
1140 getfem_cv_nodes[3] = cdb_node_2_getfem_node[OO];
1141 getfem_cv_nodes[4] = cdb_node_2_getfem_node[NN];
1142 getfem_cv_nodes[5] = cdb_node_2_getfem_node[KK];
1143 getfem_cv_nodes[6] = cdb_node_2_getfem_node[PP];
1144 getfem_cv_nodes[7] = cdb_node_2_getfem_node[QQ];
1145 getfem_cv_nodes[8] = cdb_node_2_getfem_node[RR];
1146 getfem_cv_nodes[9] = cdb_node_2_getfem_node[LL];
1147 regions[imat].add(m.add_convex(bgeot::simplex_geotrans(3,2),
1148 getfem_cv_nodes.begin()));
1149 if (itype < elt_cnt.size())
1150 elt_cnt[itype] += 1;
1153 else if (nodesno == 20) {
1156 std::string eltname(
"MESH200_11");
1157 if (elt_types.size() > itype && elt_types[itype].size() > 0)
1158 eltname = elt_types[itype];
1160 if (eltname.compare(
"MESH200_11") == 0 ||
1161 eltname.compare(
"VISCO89") == 0 ||
1162 eltname.compare(
"SOLID90") == 0 ||
1163 eltname.compare(
"SOLID95") == 0 ||
1164 eltname.compare(
"SOLID186") == 0 ||
1165 eltname.compare(
"SOLID191") == 0) {
1166 if (KK == LL && MM == NN && NN == OO && OO == PP) {
1167 getfem_cv_nodes.resize(10);
1168 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1169 getfem_cv_nodes[1] = cdb_node_2_getfem_node[QQ];
1170 getfem_cv_nodes[2] = cdb_node_2_getfem_node[JJ];
1171 getfem_cv_nodes[3] = cdb_node_2_getfem_node[TT];
1172 getfem_cv_nodes[4] = cdb_node_2_getfem_node[RR];
1173 getfem_cv_nodes[5] = cdb_node_2_getfem_node[KK];
1174 getfem_cv_nodes[6] = cdb_node_2_getfem_node[YY];
1175 getfem_cv_nodes[7] = cdb_node_2_getfem_node[ZZ];
1176 getfem_cv_nodes[8] = cdb_node_2_getfem_node[AA];
1177 getfem_cv_nodes[9] = cdb_node_2_getfem_node[MM];
1178 regions[imat].add(m.add_convex(bgeot::simplex_geotrans(3,2),
1179 getfem_cv_nodes.begin()));
1180 if (itype < elt_cnt.size())
1181 elt_cnt[itype] += 1;
1182 }
else if (MM == NN && NN == OO && OO == PP) {
1183 getfem_cv_nodes.resize(13);
1184 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1185 getfem_cv_nodes[1] = cdb_node_2_getfem_node[QQ];
1186 getfem_cv_nodes[2] = cdb_node_2_getfem_node[JJ];
1187 getfem_cv_nodes[3] = cdb_node_2_getfem_node[TT];
1188 getfem_cv_nodes[4] = cdb_node_2_getfem_node[RR];
1189 getfem_cv_nodes[5] = cdb_node_2_getfem_node[LL];
1190 getfem_cv_nodes[6] = cdb_node_2_getfem_node[SS];
1191 getfem_cv_nodes[7] = cdb_node_2_getfem_node[KK];
1192 getfem_cv_nodes[8] = cdb_node_2_getfem_node[YY];
1193 getfem_cv_nodes[9] = cdb_node_2_getfem_node[ZZ];
1194 getfem_cv_nodes[10] = cdb_node_2_getfem_node[BB];
1195 getfem_cv_nodes[11] = cdb_node_2_getfem_node[AA];
1196 getfem_cv_nodes[12] = cdb_node_2_getfem_node[MM];
1197 regions[imat].add(m.add_convex(bgeot::pyramid_Q2_incomplete_geotrans(),
1198 getfem_cv_nodes.begin()));
1199 if (itype < elt_cnt.size())
1200 elt_cnt[itype] += 1;
1202 }
else if (KK == LL && OO == PP) {
1203 getfem_cv_nodes.resize(15);
1204 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1205 getfem_cv_nodes[1] = cdb_node_2_getfem_node[QQ];
1206 getfem_cv_nodes[2] = cdb_node_2_getfem_node[JJ];
1207 getfem_cv_nodes[3] = cdb_node_2_getfem_node[TT];
1208 getfem_cv_nodes[4] = cdb_node_2_getfem_node[RR];
1209 getfem_cv_nodes[5] = cdb_node_2_getfem_node[LL];
1210 getfem_cv_nodes[6] = cdb_node_2_getfem_node[YY];
1211 getfem_cv_nodes[7] = cdb_node_2_getfem_node[ZZ];
1212 getfem_cv_nodes[8] = cdb_node_2_getfem_node[AA];
1213 getfem_cv_nodes[9] = cdb_node_2_getfem_node[MM];
1214 getfem_cv_nodes[10] = cdb_node_2_getfem_node[UU];
1215 getfem_cv_nodes[11] = cdb_node_2_getfem_node[NN];
1216 getfem_cv_nodes[12] = cdb_node_2_getfem_node[XX];
1217 getfem_cv_nodes[13] = cdb_node_2_getfem_node[VV];
1218 getfem_cv_nodes[14] = cdb_node_2_getfem_node[OO];
1219 regions[imat].add(m.add_convex
1220 (bgeot::prism_incomplete_P2_geotrans(),
1221 getfem_cv_nodes.begin()));
1222 if (itype < elt_cnt.size())
1223 elt_cnt[itype] += 1;
1225 getfem_cv_nodes.resize(20);
1226 getfem_cv_nodes[0] = cdb_node_2_getfem_node[II];
1227 getfem_cv_nodes[1] = cdb_node_2_getfem_node[QQ];
1228 getfem_cv_nodes[2] = cdb_node_2_getfem_node[JJ];
1229 getfem_cv_nodes[3] = cdb_node_2_getfem_node[TT];
1230 getfem_cv_nodes[4] = cdb_node_2_getfem_node[RR];
1231 getfem_cv_nodes[5] = cdb_node_2_getfem_node[LL];
1232 getfem_cv_nodes[6] = cdb_node_2_getfem_node[SS];
1233 getfem_cv_nodes[7] = cdb_node_2_getfem_node[KK];
1234 getfem_cv_nodes[8] = cdb_node_2_getfem_node[YY];
1235 getfem_cv_nodes[9] = cdb_node_2_getfem_node[ZZ];
1236 getfem_cv_nodes[10] = cdb_node_2_getfem_node[BB];
1237 getfem_cv_nodes[11] = cdb_node_2_getfem_node[AA];
1238 getfem_cv_nodes[12] = cdb_node_2_getfem_node[MM];
1239 getfem_cv_nodes[13] = cdb_node_2_getfem_node[UU];
1240 getfem_cv_nodes[14] = cdb_node_2_getfem_node[NN];
1241 getfem_cv_nodes[15] = cdb_node_2_getfem_node[XX];
1242 getfem_cv_nodes[16] = cdb_node_2_getfem_node[VV];
1243 getfem_cv_nodes[17] = cdb_node_2_getfem_node[PP];
1244 getfem_cv_nodes[18] = cdb_node_2_getfem_node[WW];
1245 getfem_cv_nodes[19] = cdb_node_2_getfem_node[OO];
1246 regions[imat].add(m.add_convex(bgeot::Q2_incomplete_geotrans(3),
1247 getfem_cv_nodes.begin()));
1248 if (itype < elt_cnt.size())
1249 elt_cnt[itype] += 1;
1255 int nonempty_regions=0;
1256 for (
size_type i=0; i < regions.size(); ++i)
1257 if (regions[i].card() > 0)
1260 if (nonempty_regions > 1)
1261 for (
size_type i=0; i < regions.size(); ++i)
1262 if (regions[i].card() > 0)
1263 m.region(i).add(regions[i]);
1265 for (
size_type i=1; i < elt_types.size(); ++i)
1267 cout <<
"Imported " << elt_cnt[i] <<
" " << elt_types[i] <<
" elements." << endl;
1268 cout <<
"Imported " << m.convex_index().card() <<
" elements in total." << endl;
1273 static double round_to_nth_significant_number(
double x,
int ndec) {
1275 double s = (x < 0 ? -1 : 1);
1276 double pdec = pow(10.,
double(ndec));
1277 if (x == 0)
return 0.;
1279 while (x > 1) { x /= 10.0; p*=10; }
1280 while (x < 0.1) { x *= 10.0; p/=10; }
1282 x = s * (floor(x * pdec + 0.5) / pdec) * p;
1288 static void import_noboite_mesh_file(std::istream& f, mesh& m) {
1290 using namespace std;
1291 gmm::stream_standard_locale sl(f);
1293 ofstream fichier_GiD(
"noboite_to_GiD.gid", ios::out | ios::trunc );
1295 fichier_GiD <<
"MESH dimension 3 ElemType Tetrahedra Nnode 4"<<endl;
1298 int i,NE,NP,ligne_debut_NP;
1306 ligne_debut_NP=NE*4/6+3;
1311 for (i=1; i<=ligne_debut_NP; i++){
1312 getline(f, contenu);
1319 fichier_GiD <<
"Coordinates" <<endl;
1321 for (i=1; i<=NP; i++){
1322 float coor_x,coor_y,coor_z;
1324 fichier_GiD << i<<
" ";
1326 f>>coor_x >>coor_y >>coor_z;
1327 fichier_GiD<<coor_x<<
" " <<coor_y <<
" "<<coor_z <<endl;
1331 fichier_GiD <<
"end coordinates" <<endl<<endl;
1338 f.seekg(0, ios::beg);
1339 for (i=1; i<=3; i++){
1340 getline(f, contenu);
1344 fichier_GiD <<
"Elements" <<endl;
1346 for (i=1; i<=NE; i++){
1347 float elem_1,elem_2,elem_3,elem_4;
1349 fichier_GiD << i<<
" ";
1350 f>>elem_1>>elem_2>>elem_3>>elem_4;
1351 fichier_GiD<<elem_1<<
" " <<elem_2 <<
" "<<elem_3<<
" "<<elem_4<<
" 1"<<endl;
1354 fichier_GiD <<
"end elements" <<endl<<endl;
1359 fichier_GiD.close();
1362 cerr <<
"Erreur à l'ouverture !" << endl;
1370 cerr <<
"Erreur à l'ouverture !" << endl;
1374 ifstream fichier1_GiD(
"noboite_to_GiD.gid", ios::in);
1375 import_gid_mesh_file(fichier1_GiD, m);
1384 static void import_am_fmt_mesh_file(std::istream& f, mesh& m) {
1385 gmm::stream_standard_locale sl(f);
1387 std::vector<size_type> tri;
1390 f >> nbs >> nbt; bgeot::read_until(f,
"\n");
1392 for (
size_type i=0; i < nbt*3; ++i) f >> tri[i];
1396 P[0]=round_to_nth_significant_number(P[0],6);
1397 P[1]=round_to_nth_significant_number(P[1],6);
1399 GMM_ASSERT1(jj == j,
"ouch");
1402 m.add_triangle(tri[i]-1,tri[i+1]-1,tri[i+2]-1);
1409 static void import_emc2_mesh_file(std::istream& f, mesh& m) {
1410 gmm::stream_standard_locale sl(f);
1412 std::vector<size_type> tri;
1415 bgeot::read_until(f,
"Vertices");
1418 f >> P[0] >> P[1] >> dummy;
1420 GMM_ASSERT1(jj == j,
"ouch");
1426 if (ls.find(
"Triangles")+1) {
1429 f >> ip[0] >> ip[1] >> ip[2] >> dummy; ip[0]--; ip[1]--; ip[2]--;
1430 m.add_triangle(ip[0],ip[1],ip[2]);
1432 }
else if (ls.find(
"Quadrangles")+1) {
1435 f >> ip[0] >> ip[1] >> ip[2] >> ip[3] >> dummy; ip[0]--; ip[1]--; ip[2]--; ip[3]--;
1436 m.add_parallelepiped(2, &ip[0]);
1438 }
else if (ls.find(
"End")+1)
break;
1442 void import_mesh(
const std::string& filename,
const std::string& format,
1447 if (bgeot::casecmp(format,
"structured")==0)
1449 else if (bgeot::casecmp(format,
"structured_ball")==0)
1451 else if (bgeot::casecmp(format,
"structured_ball_shell")==0)
1454 std::ifstream f(filename.c_str());
1455 GMM_ASSERT1(f.good(),
"can't open file " << filename);
1457 f.exceptions(std::ifstream::badbit | std::ifstream::failbit);
1461 catch (std::logic_error& exc) {
1465 catch (std::ios_base::failure& exc) {
1467 GMM_ASSERT1(
false,
"error while importing " << format
1468 <<
" mesh file \"" << filename <<
"\" : " << exc.what());
1470 catch (std::runtime_error& exc) {
1477 std::map<std::string, size_type> ®ion_map,
1478 bool remove_last_dimension,
1479 std::map<
size_type, std::set<size_type>> *nodal_map,
1480 bool remove_duplicated_nodes)
1482 import_gmsh_mesh_file(f, m, 0, ®ion_map,
nullptr,
false, remove_last_dimension, nodal_map,
1483 remove_duplicated_nodes);
1487 bool add_all_element_type,
1488 std::set<size_type> *lower_dim_convex_rg,
1489 std::map<std::string, size_type> *region_map,
1490 bool remove_last_dimension,
1491 std::map<
size_type, std::set<size_type>> *nodal_map,
1492 bool remove_duplicated_nodes)
1494 import_gmsh_mesh_file(f, m, 0, region_map, lower_dim_convex_rg, add_all_element_type,
1495 remove_last_dimension, nodal_map, remove_duplicated_nodes);
1499 bool add_all_element_type,
1500 std::set<size_type> *lower_dim_convex_rg,
1501 std::map<std::string, size_type> *region_map,
1502 bool remove_last_dimension,
1503 std::map<
size_type, std::set<size_type>> *nodal_map,
1504 bool remove_duplicated_nodes)
1508 std::ifstream f(filename.c_str());
1509 GMM_ASSERT1(f.good(),
"can't open file " << filename);
1511 f.exceptions(std::ifstream::badbit | std::ifstream::failbit);
1512 import_gmsh_mesh_file(f, m, 0, region_map, lower_dim_convex_rg, add_all_element_type,
1513 remove_last_dimension, nodal_map, remove_duplicated_nodes);
1516 catch (std::logic_error& exc) {
1520 catch (std::ios_base::failure& exc) {
1522 GMM_ASSERT1(
false,
"error while importing " <<
"gmsh"
1523 <<
" mesh file \"" << filename <<
"\" : " << exc.what());
1525 catch (std::runtime_error& exc) {
1532 mesh& m, std::map<std::string, size_type> ®ion_map,
1533 bool remove_last_dimension,
1534 std::map<
size_type, std::set<size_type>> *nodal_map,
1535 bool remove_duplicated_nodes) {
1536 import_mesh_gmsh(filename, m,
false, NULL, ®ion_map, remove_last_dimension, nodal_map,
1537 remove_duplicated_nodes);
1540 void import_mesh(std::istream& f,
const std::string& format,
1542 if (bgeot::casecmp(format,
"gmsh")==0)
1543 import_gmsh_mesh_file(f,m);
1544 else if (bgeot::casecmp(format,
"gmsh_with_lower_dim_elt")==0)
1545 import_gmsh_mesh_file(f,m,0,NULL,NULL,
true);
1546 else if (bgeot::casecmp(format,
"gmshv2")==0)
1547 import_gmsh_mesh_file(f,m,2);
1548 else if (bgeot::casecmp(format,
"gid")==0)
1549 import_gid_mesh_file(f,m);
1550 else if (bgeot::casecmp(format,
"noboite")==0)
1551 import_noboite_mesh_file(f,m);
1552 else if (bgeot::casecmp(format,
"am_fmt")==0)
1553 import_am_fmt_mesh_file(f,m);
1554 else if (bgeot::casecmp(format,
"emc2_mesh")==0)
1555 import_emc2_mesh_file(f,m);
1556 else if (bgeot::casecmp(format,
"cdb")==0)
1557 import_cdb_mesh_file(f,m);
1558 else if (bgeot::casecmp(format.substr(0,4),
"cdb:")==0) {
1563 imat = std::stol(format.substr(4), &sz);
1564 success = (sz == format.substr(4).size() && imat !=
size_type(-1));
1565 }
catch (
const std::invalid_argument&) {
1567 }
catch (
const std::out_of_range&) {
1571 import_cdb_mesh_file(f,m,imat);
1572 else GMM_ASSERT1(
false,
"cannot import "
1573 << format <<
" mesh type : wrong cdb mesh type input");
1575 else GMM_ASSERT1(
false,
"cannot import "
1576 << format <<
" mesh type : unknown mesh type");
1579 void import_mesh(
const std::string& filename, mesh& msh) {
1580 size_type pos = filename.find_last_of(
":");
1581 if (pos != std::string::npos)
1584 msh.read_from_file(filename);
1588 bool is_flat =
true;
1589 unsigned N = m.dim();
if (N < 1)
return;
1590 for (dal::bv_visitor i(m.points().index()); !i.finished(); ++i)
1591 if (m.points()[i][N-1] != 0) is_flat = 0;
1593 base_matrix M(N-1,N);
1594 for (
unsigned i=0; i < N-1; ++i) M(i,i) = 1;