38 #ifdef LIBMESH_HAVE_GMV 61 struct ElementDefinition {
66 std::vector<unsigned> node_map;
74 std::map<ElemType, ElementDefinition> eletypes;
77 void add_eletype_entry(
ElemType libmesh_elem_type,
78 const unsigned * node_map,
79 const std::string & gmv_label,
83 ElementDefinition & map_entry = eletypes[libmesh_elem_type];
86 map_entry.label = gmv_label;
91 std::vector<unsigned int>(node_map,
92 node_map+nodes_size).
swap(map_entry.node_map);
100 if (eletypes.empty())
109 const unsigned int node_map[] = {0,1};
110 add_eletype_entry(
EDGE2, node_map,
"line 2", 2);
115 const unsigned int node_map[] = {0,1,2};
116 add_eletype_entry(
EDGE3, node_map,
"3line 3", 3);
121 const unsigned int node_map[] = {0,1,2};
122 add_eletype_entry(
TRI3, node_map,
"tri3 3", 3);
127 const unsigned int node_map[] = {0,1,2,3,4,5};
128 add_eletype_entry(
TRI6, node_map,
"6tri 6", 6);
133 const unsigned int node_map[] = {0,1,2,3};
134 add_eletype_entry(
QUAD4, node_map,
"quad 4", 4);
139 const unsigned int node_map[] = {0,1,2,3,4,5,6,7};
140 add_eletype_entry(
QUAD8, node_map,
"8quad 8", 8);
148 const unsigned int node_map[] = {0,1,2,3,4,5,6,7};
149 add_eletype_entry(
HEX8, node_map,
"phex8 8", 8);
155 const unsigned int node_map[] = {0,1,2,3,4,5,6,7,8,9,10,11,16,17,18,19,12,13,14,15};
156 add_eletype_entry(
HEX20, node_map,
"phex20 20", 20);
166 const unsigned node_map[] = {0,2,1,3};
167 add_eletype_entry(
TET4, node_map,
"tet 4", 4);
172 const unsigned int node_map[] = {0,1,2,3,4,5,6,7,8,9};
173 add_eletype_entry(
TET10, node_map,
"ptet10 10", 10);
178 const unsigned int node_map[] = {0,1,2,3,4,5};
179 add_eletype_entry(
PRISM6, node_map,
"pprism6 6", 6);
185 const unsigned int node_map[] = {0,1,2,3,4,5,6,7,8,12,13,14, 9,10,11};
186 add_eletype_entry(
PRISM15, node_map,
"pprism15 15", 15);
209 std::map<std::string, ElemType> ret;
221 ret[
"phex20"] =
HEX20;
222 ret[
"phex27"] =
HEX27;
224 ret[
"ptet10"] =
TET10;
226 ret[
"8quad"] =
QUAD8;
227 ret[
"3line"] =
EDGE3;
243 _discontinuous (false),
244 _partitioning (true),
245 _write_subdomain_id_as_material (false),
246 _subdivide_second_order (true),
258 _discontinuous (false),
259 _partitioning (true),
260 _write_subdomain_id_as_material (false),
261 _subdivide_second_order (true),
280 const std::vector<Number> & soln,
281 const std::vector<std::string> & names)
283 LOG_SCOPE(
"write_nodal_data()",
"GMVIO");
294 const std::vector<Number> * v,
295 const std::vector<std::string> * solution_names)
297 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 299 libMesh::err <<
"WARNING: GMVIO::write_ascii_new_impl() not infinite-element aware!" 318 std::ofstream out_stream (fname.c_str());
323 if (!out_stream.good())
324 libmesh_file_error(fname.c_str());
326 unsigned int mesh_max_p_level = 0;
330 out_stream <<
"gmvinput ascii\n\n";
342 out_stream << 0. <<
" ";
350 out_stream << 0. <<
" ";
352 out_stream <<
"\n\n";
357 out_stream <<
"cells " << n_active_elem <<
"\n";
364 mesh_max_p_level =
std::max(mesh_max_p_level,
369 libmesh_assert (eletypes.count(elem->type()));
371 const ElementDefinition & ele = eletypes[elem->type()];
375 libmesh_assert_less_equal (ele.node_map.size(), elem->n_nodes());
377 out_stream << ele.label <<
"\n";
378 for (std::size_t i=0; i < ele.node_map.size(); i++)
379 out_stream << elem->node_id(ele.node_map[i])+1 <<
" ";
389 libmesh_error_msg(
"Not yet supported in GMVIO::write_ascii_new_impl");
393 out_stream <<
"material " 408 out_stream <<
"proc_" << proc <<
"\n";
412 out_stream << elem->processor_id()+1 <<
"\n";
421 bool write_variable =
false;
424 if (this->
p_levels() && mesh_max_p_level)
425 write_variable =
true;
428 if ((solution_names !=
nullptr) && (v !=
nullptr))
429 write_variable =
true;
433 write_variable =
true;
436 out_stream <<
"variable\n";
443 if (this->
p_levels() && mesh_max_p_level)
445 out_stream <<
"p_level 0\n";
449 const ElementDefinition & ele = eletypes[elem->type()];
453 libmesh_assert_less_equal (ele.node_map.size(), elem->n_nodes());
455 for (std::size_t i=0; i < ele.node_map.size(); i++)
456 out_stream << elem->p_level() <<
" ";
458 out_stream <<
"\n\n";
468 out_stream << pr.first <<
" 0\n";
470 const std::vector<Real> * the_array = pr.second;
478 libmesh_assert_less (elem->id(), the_array->size());
479 const Real the_value = the_array->operator[](elem->id());
482 for (
unsigned int se=0; se < elem->n_sub_elem(); se++)
483 out_stream << the_value <<
" ";
485 out_stream << the_value <<
" ";
488 out_stream <<
"\n\n";
494 if ((solution_names !=
nullptr) && (v !=
nullptr))
496 const unsigned int n_vars = solution_names->size();
507 for (
unsigned int c=0; c<
n_vars; c++)
510 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 516 out_stream <<
"r_" << (*solution_names)[c] <<
" 1\n";
519 out_stream << (*v)[n*
n_vars + c].real() <<
" ";
521 out_stream <<
"\n\n";
524 out_stream <<
"i_" << (*solution_names)[c] <<
" 1\n";
527 out_stream << (*v)[n*
n_vars + c].imag() <<
" ";
529 out_stream <<
"\n\n";
532 out_stream <<
"a_" << (*solution_names)[c] <<
" 1\n";
536 out_stream <<
"\n\n";
540 out_stream << (*solution_names)[c] <<
" 1\n";
543 out_stream << (*v)[n*
n_vars + c] <<
" ";
545 out_stream <<
"\n\n";
554 out_stream <<
"endvars\n";
558 out_stream <<
"\nendgmv\n";
569 const std::vector<Number> * v,
570 const std::vector<std::string> * solution_names)
590 std::ofstream out_stream (fname.c_str());
596 if (!out_stream.good())
597 libmesh_file_error(fname.c_str());
611 unsigned int mesh_max_p_level = 0;
621 out_stream <<
"gmvinput ascii\n\n";
632 out_stream << 0. <<
" ";
641 out_stream << 0. <<
" ";
644 out_stream <<
'\n' <<
'\n';
652 out_stream <<
"cells ";
654 out_stream << n_active_sub_elem;
656 out_stream << n_active_elem;
660 std::vector<dof_id_type> conn;
664 mesh_max_p_level =
std::max(mesh_max_p_level,
672 for (
unsigned int se=0; se<elem->n_sub_elem(); se++)
674 out_stream <<
"line 2\n";
675 elem->connectivity(se,
TECPLOT, conn);
676 for (std::size_t i=0; i<conn.size(); i++)
677 out_stream << conn[i] <<
" ";
683 out_stream <<
"line 2\n";
684 if (elem->default_order() ==
FIRST)
685 elem->connectivity(0,
TECPLOT, conn);
689 for (
unsigned int i = 0; i != lo_elem->n_nodes(); ++i)
690 lo_elem->set_node(i) = elem->node_ptr(i);
691 lo_elem->connectivity(0,
TECPLOT, conn);
693 for (std::size_t i=0; i<conn.size(); i++)
694 out_stream << conn[i] <<
" ";
705 for (
unsigned int se=0; se<elem->n_sub_elem(); se++)
708 if ((elem->type() ==
QUAD4) ||
709 (elem->type() ==
QUAD8) ||
712 (elem->type() ==
QUAD9)
713 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
719 out_stream <<
"quad 4\n";
720 elem->connectivity(se,
TECPLOT, conn);
721 for (std::size_t i=0; i<conn.size(); i++)
722 out_stream << conn[i] <<
" ";
726 else if ((elem->type() ==
TRI3) ||
727 (elem->type() ==
TRI6))
729 out_stream <<
"tri 3\n";
730 elem->connectivity(se,
TECPLOT, conn);
731 for (
unsigned int i=0; i<3; i++)
732 out_stream << conn[i] <<
" ";
740 if ((elem->type() ==
QUAD4)
741 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
746 elem->connectivity(0,
TECPLOT, conn);
747 out_stream <<
"quad 4\n";
748 for (std::size_t i=0; i<conn.size(); i++)
749 out_stream << conn[i] <<
" ";
751 else if ((elem->type() ==
QUAD8) ||
752 (elem->type() ==
QUAD9)
753 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
759 for (
unsigned int i = 0; i != lo_elem->n_nodes(); ++i)
760 lo_elem->set_node(i) = elem->node_ptr(i);
761 lo_elem->connectivity(0,
TECPLOT, conn);
762 out_stream <<
"quad 4\n";
763 for (std::size_t i=0; i<conn.size(); i++)
764 out_stream << conn[i] <<
" ";
766 else if (elem->type() ==
TRI3)
768 elem->connectivity(0,
TECPLOT, conn);
769 out_stream <<
"tri 3\n";
770 for (
unsigned int i=0; i<3; i++)
771 out_stream << conn[i] <<
" ";
773 else if (elem->type() ==
TRI6)
776 for (
unsigned int i = 0; i != lo_elem->n_nodes(); ++i)
777 lo_elem->set_node(i) = elem->node_ptr(i);
778 lo_elem->connectivity(0,
TECPLOT, conn);
779 out_stream <<
"tri 3\n";
780 for (
unsigned int i=0; i<3; i++)
781 out_stream << conn[i] <<
" ";
793 for (
unsigned int se=0; se<elem->n_sub_elem(); se++)
796 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS 797 if ((elem->type() ==
HEX8) ||
798 (elem->type() ==
HEX27))
800 out_stream <<
"phex8 8\n";
801 elem->connectivity(se,
TECPLOT, conn);
802 for (std::size_t i=0; i<conn.size(); i++)
803 out_stream << conn[i] <<
" ";
806 else if (elem->type() ==
HEX20)
808 out_stream <<
"phex20 20\n";
809 out_stream << elem->node_id(0)+1 <<
" " 810 << elem->node_id(1)+1 <<
" " 811 << elem->node_id(2)+1 <<
" " 812 << elem->node_id(3)+1 <<
" " 813 << elem->node_id(4)+1 <<
" " 814 << elem->node_id(5)+1 <<
" " 815 << elem->node_id(6)+1 <<
" " 816 << elem->node_id(7)+1 <<
" " 817 << elem->node_id(8)+1 <<
" " 818 << elem->node_id(9)+1 <<
" " 819 << elem->node_id(10)+1 <<
" " 820 << elem->node_id(11)+1 <<
" " 821 << elem->node_id(16)+1 <<
" " 822 << elem->node_id(17)+1 <<
" " 823 << elem->node_id(18)+1 <<
" " 824 << elem->node_id(19)+1 <<
" " 825 << elem->node_id(12)+1 <<
" " 826 << elem->node_id(13)+1 <<
" " 827 << elem->node_id(14)+1 <<
" " 828 << elem->node_id(15)+1 <<
" ";
883 #else // LIBMESH_ENABLE_INFINITE_ELEMENTS 888 if ((elem->type() ==
HEX8) ||
889 (elem->type() ==
HEX27) ||
893 (elem->type() ==
HEX20))
895 out_stream <<
"phex8 8\n";
896 elem->connectivity(se,
TECPLOT, conn);
897 for (std::size_t i=0; i<conn.size(); i++)
898 out_stream << conn[i] <<
" ";
902 else if ((elem->type() ==
TET4) ||
903 (elem->type() ==
TET10))
905 out_stream <<
"tet 4\n";
910 elem->connectivity(se,
TECPLOT, conn);
911 out_stream << conn[0] <<
" " 916 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS 917 else if ((elem->type() ==
PRISM6) ||
922 else if ((elem->type() ==
PRISM6) ||
932 out_stream <<
"phex8 8\n";
933 elem->connectivity(se,
TECPLOT, conn);
934 for (std::size_t i=0; i<conn.size(); i++)
935 out_stream << conn[i] <<
" ";
939 libmesh_error_msg(
"Encountered an unrecognized element " \
940 <<
"type: " << elem->type() \
941 <<
"\nPossibly a dim-1 dimensional " \
942 <<
"element? Aborting...");
949 for (
unsigned int i = 0; i != lo_elem->n_nodes(); ++i)
950 lo_elem->set_node(i) = elem->node_ptr(i);
951 if ((lo_elem->type() ==
HEX8)
952 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
953 || (lo_elem->type() ==
HEX27)
957 out_stream <<
"phex8 8\n";
958 lo_elem->connectivity(0,
TECPLOT, conn);
959 for (std::size_t i=0; i<conn.size(); i++)
960 out_stream << conn[i] <<
" ";
963 else if (lo_elem->type() ==
TET4)
965 out_stream <<
"tet 4\n";
966 lo_elem->connectivity(0,
TECPLOT, conn);
967 out_stream << conn[0] <<
" " 972 else if ((lo_elem->type() ==
PRISM6)
973 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
980 out_stream <<
"phex8 8\n";
981 lo_elem->connectivity(0,
TECPLOT, conn);
982 for (std::size_t i=0; i<conn.size(); i++)
983 out_stream << conn[i] <<
" ";
987 libmesh_error_msg(
"Encountered an unrecognized element " \
988 <<
"type. Possibly a dim-1 dimensional " \
989 <<
"element? Aborting...");
998 libmesh_error_msg(
"Unsupported element dimension: " <<
1021 std::map<subdomain_id_type, unsigned> sbdid_map;
1025 sbdid_map.insert(std::make_pair(elem->subdomain_id(), 0));
1031 for (
auto & pr : sbdid_map)
1035 out_stream <<
"material " 1039 for (std::size_t sbdid=0; sbdid<sbdid_map.size(); sbdid++)
1040 out_stream <<
"proc_" << sbdid <<
"\n";
1045 auto map_iter = sbdid_map.find(elem->subdomain_id());
1047 libmesh_assert_msg(map_iter != sbdid_map.end(),
"Entry for subdomain " << elem->subdomain_id() <<
" not found.");
1049 unsigned gmv_mat_number = (*map_iter).second;
1052 for (
unsigned int se=0; se<elem->n_sub_elem(); se++)
1053 out_stream << gmv_mat_number+1 <<
'\n';
1055 out_stream << gmv_mat_number+1 <<
"\n";
1062 out_stream <<
"material " 1067 out_stream <<
"proc_" << proc <<
'\n';
1071 for (
unsigned int se=0; se<elem->n_sub_elem(); se++)
1072 out_stream << elem->processor_id()+1 <<
'\n';
1074 out_stream << elem->processor_id()+1 <<
'\n';
1085 bool write_variable =
false;
1088 if (this->
p_levels() && mesh_max_p_level)
1089 write_variable =
true;
1092 if ((solution_names !=
nullptr) && (v !=
nullptr))
1093 write_variable =
true;
1097 write_variable =
true;
1100 out_stream <<
"variable\n";
1104 if (this->
p_levels() && mesh_max_p_level)
1106 out_stream <<
"p_level 0\n";
1110 for (
unsigned int se=0; se<elem->n_sub_elem(); se++)
1111 out_stream << elem->p_level() <<
" ";
1113 out_stream << elem->p_level() <<
" ";
1114 out_stream <<
"\n\n";
1126 out_stream << pr.first <<
" 0\n";
1128 const std::vector<Real> * the_array = pr.second;
1136 libmesh_assert_less (elem->id(), the_array->size());
1137 const Real the_value = (*the_array)[elem->id()];
1140 for (
unsigned int se=0; se < elem->n_sub_elem(); se++)
1141 out_stream << the_value <<
" ";
1143 out_stream << the_value <<
" ";
1146 out_stream <<
"\n\n";
1154 if ((solution_names !=
nullptr) &&
1157 const unsigned int n_vars =
1158 cast_int<unsigned int>(solution_names->size());
1169 for (
unsigned int c=0; c<
n_vars; c++)
1172 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 1178 out_stream <<
"r_" << (*solution_names)[c] <<
" 1\n";
1181 out_stream << (*v)[n*
n_vars + c].real() <<
" ";
1183 out_stream <<
'\n' <<
'\n';
1187 out_stream <<
"i_" << (*solution_names)[c] <<
" 1\n";
1190 out_stream << (*v)[n*
n_vars + c].imag() <<
" ";
1192 out_stream <<
'\n' <<
'\n';
1195 out_stream <<
"a_" << (*solution_names)[c] <<
" 1\n";
1199 out_stream <<
'\n' <<
'\n';
1203 out_stream << (*solution_names)[c] <<
" 1\n";
1206 out_stream << (*v)[n*
n_vars + c] <<
" ";
1208 out_stream <<
'\n' <<
'\n';
1217 out_stream <<
"endvars\n";
1221 out_stream <<
"\nendgmv\n";
1231 const std::vector<Number> * vec,
1232 const std::vector<std::string> * solution_names)
1247 std::ofstream out_stream (fname.c_str());
1249 libmesh_assert (out_stream.good());
1251 unsigned int mesh_max_p_level = 0;
1258 buffer =
"gmvinput";
1259 out_stream.write(buffer.c_str(), buffer.size());
1261 buffer =
"ieeei4r4";
1262 out_stream.write(buffer.c_str(), buffer.size());
1270 out_stream.write(buffer.c_str(), buffer.size());
1273 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1278 temp[v] = static_cast<float>(
mesh.
point(v)(0));
1279 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1285 temp[v] =
static_cast<float>(
mesh.
point(v)(1));
1290 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1296 temp[v] =
static_cast<float>(
mesh.
point(v)(2));
1301 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1308 out_stream.write(buffer.c_str(), buffer.size());
1310 unsigned int tempint = n_active_elem;
1311 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1315 mesh_max_p_level =
std::max(mesh_max_p_level,
1321 const ElementDefinition & ed = eletypes[elem->type()];
1330 buffer.erase(buffer.find_first_of(
' '), std::string::npos);
1333 while (buffer.size() < 8)
1334 buffer.insert(buffer.end(),
' ');
1337 out_stream.write(buffer.c_str(), buffer.size());
1344 tempint = cast_int<unsigned int>(ed.node_map.size());
1345 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1348 for (std::size_t i=0; i<ed.node_map.size(); i++)
1350 dof_id_type id = elem->node_id(ed.node_map[i]) + 1;
1351 out_stream.write(reinterpret_cast<char *>(&
id),
sizeof(
dof_id_type));
1362 libmesh_error_msg(
"Not yet supported in GMVIO::write_binary");
1366 buffer =
"material";
1367 out_stream.write(buffer.c_str(), buffer.size());
1370 out_stream.write(reinterpret_cast<char *>(&tmpint),
sizeof(
unsigned int));
1373 out_stream.write(reinterpret_cast<char *>(&tmpint),
sizeof(
unsigned int));
1380 std::ostringstream oss;
1381 oss <<
"proc_" << std::setw(3) << std::left << proc;
1382 out_stream.write(oss.str().c_str(), oss.str().size());
1385 std::vector<unsigned int> proc_id (n_active_elem);
1392 proc_id[n++] = elem->processor_id() + 1;
1394 out_stream.write(reinterpret_cast<char *>(proc_id.data()),
1395 sizeof(
unsigned int)*proc_id.size());
1403 bool write_variable =
false;
1406 if (this->
p_levels() && mesh_max_p_level)
1407 write_variable =
true;
1410 if ((solution_names !=
nullptr) && (vec !=
nullptr))
1411 write_variable =
true;
1419 buffer =
"variable";
1420 out_stream.write(buffer.c_str(), buffer.size());
1424 if (this->
p_levels() && mesh_max_p_level)
1426 unsigned int n_floats = n_active_elem;
1430 std::vector<float> temp(n_floats);
1433 out_stream.write(buffer.c_str(), buffer.size());
1435 unsigned int tempint = 0;
1436 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1440 for (
unsigned int se=0; se<elem->n_sub_elem(); se++)
1441 temp[n++] = static_cast<float>( elem->p_level() );
1443 out_stream.write(reinterpret_cast<char *>(temp.data()),
1444 sizeof(
float)*n_floats);
1450 libMesh::err <<
"Cell-centered data not (yet) supported in binary I/O mode!" << std::endl;
1456 if ((solution_names !=
nullptr) &&
1461 const unsigned int n_vars =
1462 cast_int<unsigned int>(solution_names->size());
1464 for (
unsigned int c=0; c<
n_vars; c++)
1467 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 1473 out_stream.write(buffer.c_str(), buffer.size());
1475 buffer = (*solution_names)[c];
1476 out_stream.write(buffer.c_str(), buffer.size());
1478 unsigned int tempint = 1;
1479 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1482 temp[n] = static_cast<float>( (*vec)[n*
n_vars + c].real() );
1484 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1489 out_stream.write(buffer.c_str(), buffer.size());
1491 buffer = (*solution_names)[c];
1492 out_stream.write(buffer.c_str(), buffer.size());
1494 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1497 temp[n] = static_cast<float>( (*vec)[n*
n_vars + c].imag() );
1499 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1503 out_stream.write(buffer.c_str(), buffer.size());
1504 buffer = (*solution_names)[c];
1505 out_stream.write(buffer.c_str(), buffer.size());
1507 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1512 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1516 buffer = (*solution_names)[c];
1517 out_stream.write(buffer.c_str(), buffer.size());
1519 unsigned int tempint = 1;
1520 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1523 temp[n] = static_cast<float>((*vec)[n*
n_vars + c]);
1525 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1534 buffer =
"endvars ";
1535 out_stream.write(buffer.c_str(), buffer.size());
1540 out_stream.write(buffer.c_str(), buffer.size());
1553 const bool write_partitioning,
1554 const std::set<std::string> * system_names)
const 1556 std::vector<std::string> solution_names;
1557 std::vector<Number> v;
1571 std::ofstream out_stream(
name.c_str());
1573 libmesh_assert (out_stream.good());
1579 out_stream <<
"gmvinput ascii" << std::endl << std::endl;
1586 tw += elem->n_nodes();
1588 out_stream <<
"nodes " << tw << std::endl;
1596 for (
unsigned int n=0; n<elem->n_nodes(); n++)
1597 out_stream << elem->point(n)(0) <<
" ";
1599 out_stream << std::endl;
1606 for (
unsigned int n=0; n<elem->n_nodes(); n++)
1608 out_stream << elem->point(n)(1) <<
" ";
1610 out_stream << 0. <<
" ";
1613 out_stream << std::endl;
1620 for (
unsigned int n=0; n<elem->n_nodes(); n++)
1622 out_stream << elem->point(n)(2) <<
" ";
1624 out_stream << 0. <<
" ";
1627 out_stream << std::endl << std::endl;
1636 out_stream <<
"cells " << n_active_elem << std::endl;
1645 for (
unsigned int se=0; se<elem->n_sub_elem(); se++)
1647 if ((elem->type() ==
EDGE2) ||
1648 (elem->type() ==
EDGE3) ||
1649 (elem->type() ==
EDGE4)
1650 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1655 out_stream <<
"line 2" << std::endl;
1656 for (
unsigned int i=0; i<elem->n_nodes(); i++)
1657 out_stream << nn++ <<
" ";
1663 out_stream << std::endl;
1672 for (
unsigned int se=0; se<elem->n_sub_elem(); se++)
1674 if ((elem->type() ==
QUAD4) ||
1675 (elem->type() ==
QUAD8) ||
1678 (elem->type() ==
QUAD9)
1679 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1685 out_stream <<
"quad 4" << std::endl;
1686 for (
unsigned int i=0; i<elem->n_nodes(); i++)
1687 out_stream << nn++ <<
" ";
1690 else if ((elem->type() ==
TRI3) ||
1691 (elem->type() ==
TRI6))
1693 out_stream <<
"tri 3" << std::endl;
1694 for (
unsigned int i=0; i<elem->n_nodes(); i++)
1695 out_stream << nn++ <<
" ";
1701 out_stream << std::endl;
1711 for (
unsigned int se=0; se<elem->n_sub_elem(); se++)
1713 if ((elem->type() ==
HEX8) ||
1714 (elem->type() ==
HEX20) ||
1715 (elem->type() ==
HEX27)
1716 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1723 out_stream <<
"phex8 8" << std::endl;
1724 for (
unsigned int i=0; i<elem->n_nodes(); i++)
1725 out_stream << nn++ <<
" ";
1727 else if ((elem->type() ==
PRISM6) ||
1730 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1736 out_stream <<
"pprism6 6" << std::endl;
1737 for (
unsigned int i=0; i<elem->n_nodes(); i++)
1738 out_stream << nn++ <<
" ";
1740 else if ((elem->type() ==
TET4) ||
1741 (elem->type() ==
TET10))
1743 out_stream <<
"tet 4" << std::endl;
1744 for (
unsigned int i=0; i<elem->n_nodes(); i++)
1745 out_stream << nn++ <<
" ";
1750 out_stream << std::endl;
1760 out_stream << std::endl;
1766 if (write_partitioning)
1769 libmesh_error_msg(
"Not yet supported in GMVIO::write_discontinuous_gmv");
1773 out_stream <<
"material " 1775 <<
" 0"<< std::endl;
1778 out_stream <<
"proc_" << proc << std::endl;
1781 out_stream << elem->processor_id()+1 << std::endl;
1783 out_stream << std::endl;
1791 libMesh::err <<
"Cell-centered data not (yet) supported for discontinuous GMV files!" << std::endl;
1798 const unsigned int n_vars =
1799 cast_int<unsigned int>(solution_names.size());
1803 out_stream <<
"variable" << std::endl;
1806 for (
unsigned int c=0; c<
n_vars; c++)
1809 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 1815 out_stream <<
"r_" << solution_names[c] <<
" 1" << std::endl;
1817 for (
unsigned int n=0; n<elem->n_nodes(); n++)
1818 out_stream << v[(n++)*
n_vars + c].real() <<
" ";
1819 out_stream << std::endl << std::endl;
1823 out_stream <<
"i_" << solution_names[c] <<
" 1" << std::endl;
1825 for (
unsigned int n=0; n<elem->n_nodes(); n++)
1826 out_stream << v[(n++)*
n_vars + c].imag() <<
" ";
1827 out_stream << std::endl << std::endl;
1830 out_stream <<
"a_" << solution_names[c] <<
" 1" << std::endl;
1832 for (
unsigned int n=0; n<elem->n_nodes(); n++)
1834 out_stream << std::endl << std::endl;
1838 out_stream << solution_names[c] <<
" 1" << std::endl;
1843 for (
unsigned int n=0; n<elem->n_nodes(); n++)
1844 out_stream << v[(nn++)*
n_vars + c] <<
" ";
1846 out_stream << std::endl << std::endl;
1852 out_stream <<
"endvars" << std::endl;
1857 out_stream << std::endl <<
"endgmv" << std::endl;
1865 const std::vector<Real> * cell_centered_data_vals)
1867 libmesh_assert(cell_centered_data_vals);
1890 libmesh_experimental();
1892 #ifndef LIBMESH_HAVE_GMV 1894 libmesh_error_msg(
"Cannot read GMV file " <<
name <<
" without the GMV API.");
1913 int ierr = GMVLib::gmvread_open_fromfileskip(const_cast<char *>(
name.c_str()));
1915 libmesh_error_msg(
"GMVLib::gmvread_open_fromfileskip failed!");
1922 GMVLib::gmvread_data();
1925 if (GMVLib::gmv_data.keyword == GMVEND)
1928 GMVLib::gmvread_close();
1933 if (GMVLib::gmv_data.keyword == GMVERROR)
1934 libmesh_error_msg(
"Encountered GMVERROR while reading!");
1937 switch (GMVLib::gmv_data.keyword)
1941 if (GMVLib::gmv_data.num2 ==
NODES)
1944 else if (GMVLib::gmv_data.num2 == NODE_V)
1945 libmesh_error_msg(
"Unsupported GMV data type NODE_V!");
1972 if (GMVLib::gmv_data.datatype == ENDKEYWORD)
1977 if (GMVLib::gmv_data.datatype == NODE)
1986 << GMVLib::gmv_data.name1
1987 <<
" which is of unsupported GMV datatype " 1988 << GMVLib::gmv_data.datatype
1989 <<
". Nodal field data is currently the only type currently supported." 1997 libmesh_error_msg(
"Encountered unknown GMV keyword " << GMVLib::gmv_data.keyword);
2003 for (
unsigned char i=0; i!=4; ++i)
2009 libmesh_error_msg(
"Cannot open dimension " \
2011 <<
" mesh file when configured without " \
2034 #ifdef LIBMESH_HAVE_GMV 2037 _nodal_data.insert ( std::make_pair(std::string(GMVLib::gmv_data.name1),
2038 std::vector<Number>(GMVLib::gmv_data.doubledata1, GMVLib::gmv_data.doubledata1+GMVLib::gmv_data.num) ) );
2046 #ifdef LIBMESH_HAVE_GMV 2049 libmesh_assert_equal_to (GMVLib::gmv_data.datatype, CELL);
2058 for (
int i = 0; i < GMVLib::gmv_data.nlongdata1; i++)
2060 cast_int<processor_id_type>(GMVLib::gmv_data.longdata1[i]-1);
2070 #ifdef LIBMESH_HAVE_GMV 2072 libmesh_assert_equal_to (GMVLib::gmv_data.datatype, UNSTRUCT);
2076 for (
int i = 0; i < GMVLib::gmv_data.num; i++)
2080 GMVLib::gmv_data.doubledata2[i],
2081 GMVLib::gmv_data.doubledata3[i]), i);
2089 #ifdef LIBMESH_HAVE_GMV 2094 (GMVLib::gmv_data.datatype==REGULAR) ||
2095 (GMVLib::gmv_data.datatype==ENDKEYWORD);
2097 libmesh_assert (recognized);
2101 if (GMVLib::gmv_data.datatype == REGULAR)
2120 const ElementDefinition & eledef = eletypes[type];
2124 for (
int i=0; i<GMVLib::gmv_data.num2; i++)
2127 unsigned mapped_i = eledef.node_map[i];
2131 (cast_int<dof_id_type>(GMVLib::gmv_data.longdata1[mapped_i]-1));
2141 if (GMVLib::gmv_data.datatype == ENDKEYWORD)
2154 elemname.erase(std::remove_if(elemname.begin(), elemname.end(), isspace), elemname.end());
2160 libmesh_error_msg(
"Unknown/unsupported element: " << elemname <<
" was read.");
2173 libMesh::err <<
"Unable to copy nodal solution: No nodal " 2174 <<
"solution has been read in from file." << std::endl;
2187 std::set<std::string> vars_copied;
2191 for (
unsigned int sys=0; sys<es.
n_systems(); ++sys)
2200 const std::string & var_name = pr.first;
2215 libMesh::err <<
"Only FIRST-order LAGRANGE variables can be read from GMV files. " 2216 <<
"Skipping variable " << var_name << std::endl;
2224 sz = cast_int<dof_id_type>(pr.second.size());
2229 const unsigned int dof_index =
2235 if ((dof_index >= system.
solution->first_local_index()) &&
2236 (dof_index < system.solution->last_local_index()))
2237 system.
solution->set (dof_index, pr.second [i]);
2241 vars_copied.insert (var_name);
2254 if (vars_copied.find(pr.first) == vars_copied.end())
2257 <<
" was not copied to the EquationSystems object." std::string name(const ElemQuality q)
Manages the family, order, etc. parameters for a given FE.
virtual void read(const std::string &mesh_file) override
Manages multiples systems of equations.
void build_variable_names(std::vector< std::string > &var_names, const FEType *type=nullptr, const std::set< std::string > *system_names=nullptr) const
virtual Node *& set_node(const unsigned int i)
virtual dof_id_type n_active_elem() const =0
unsigned int n_systems() const
static std::map< std::string, ElemType > _reading_element_map
virtual void write(const std::string &) override
void allow_renumbering(bool allow)
void write_binary(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
const T_sys & get_system(const std::string &name) const
unsigned int _next_elem_id
The base class for all geometric element types.
unsigned int & ascii_precision()
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
const unsigned int n_vars
long double max(long double a, double b)
bool has_variable(const std::string &var) const
std::map< std::string, std::vector< Number > > _nodal_data
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
bool & write_subdomain_id_as_material()
ElemType gmv_elem_to_libmesh_elem(std::string elemname)
std::map< std::string, const std::vector< Real > *> _cell_centered_data
processor_id_type n_processors() const
static std::map< std::string, ElemType > build_reading_element_map()
Manages consistently variables, degrees of freedom, and coefficient vectors.
virtual Elem * add_elem(Elem *e)=0
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
unsigned short int variable_number(const std::string &var) const
bool _write_subdomain_id_as_material
std::unique_ptr< NumericVector< Number > > solution
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
OStreamProxy err(std::cerr)
void set_mesh_dimension(unsigned char d)
void copy_nodal_solution(EquationSystems &es)
void write_ascii_old_impl(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
std::string enum_to_string(const T e)
unsigned int n_partitions() const
bool & subdivide_second_order()
const FEType & variable_type(const unsigned int i) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void write_ascii_new_impl(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
virtual unsigned short dim() const =0
Temporarily serializes a DistributedMesh for output.
void swap(Iterator &lhs, Iterator &rhs)
dof_id_type n_active_sub_elem() const
unsigned int mesh_dimension() const
void add_cell_centered_data(const std::string &cell_centered_data_name, const std::vector< Real > *cell_centered_data_vals)
virtual const Point & point(const dof_id_type i) const =0
virtual dof_id_type max_node_id() const =0
virtual const Node * node_ptr(const dof_id_type i) const =0
processor_id_type processor_id() const
void build_discontinuous_solution_vector(std::vector< Number > &soln, const std::set< std::string > *system_names=nullptr) const
static ElemType first_order_equivalent_type(const ElemType et)
A geometric point in (x,y,z) space.
void write_discontinuous_gmv(const std::string &name, const EquationSystems &es, const bool write_partitioning, const std::set< std::string > *system_names=nullptr) const
virtual dof_id_type n_nodes() const =0