25 #include "libmesh/libmesh_config.h" 26 #include "libmesh/libmesh_logging.h" 27 #include "libmesh/gmv_io.h" 28 #include "libmesh/mesh_base.h" 29 #include "libmesh/elem.h" 30 #include "libmesh/equation_systems.h" 31 #include "libmesh/numeric_vector.h" 32 #include "libmesh/enum_to_string.h" 33 #include "libmesh/enum_io_package.h" 34 #include "libmesh/enum_elem_type.h" 35 #include "libmesh/int_range.h" 36 #include "libmesh/utility.h" 40 #ifdef LIBMESH_HAVE_GMV 63 struct ElementDefinition {
68 std::vector<unsigned> node_map;
76 std::map<ElemType, ElementDefinition> eletypes;
79 void add_eletype_entry(
ElemType libmesh_elem_type,
80 const unsigned * node_map,
81 const std::string & gmv_label,
85 ElementDefinition & map_entry = eletypes[libmesh_elem_type];
88 map_entry.label = gmv_label;
93 std::vector<unsigned int>(node_map,
94 node_map+nodes_size).swap(map_entry.node_map);
100 void init_eletypes ()
102 if (eletypes.empty())
111 const unsigned int node_map[] = {0,1};
112 add_eletype_entry(
EDGE2, node_map,
"line 2", 2);
117 const unsigned int node_map[] = {0,1,2};
118 add_eletype_entry(
EDGE3, node_map,
"3line 3", 3);
123 const unsigned int node_map[] = {0,1,2};
124 add_eletype_entry(
TRI3, node_map,
"tri3 3", 3);
129 const unsigned int node_map[] = {0,1,2,3,4,5};
130 add_eletype_entry(
TRI6, node_map,
"6tri 6", 6);
135 const unsigned int node_map[] = {0,1,2,3};
136 add_eletype_entry(
QUAD4, node_map,
"quad 4", 4);
141 const unsigned int node_map[] = {0,1,2,3,4,5,6,7};
142 add_eletype_entry(
QUAD8, node_map,
"8quad 8", 8);
150 const unsigned int node_map[] = {0,1,2,3,4,5,6,7};
151 add_eletype_entry(
HEX8, node_map,
"phex8 8", 8);
157 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};
158 add_eletype_entry(
HEX20, node_map,
"phex20 20", 20);
168 const unsigned node_map[] = {0,2,1,3};
169 add_eletype_entry(
TET4, node_map,
"tet 4", 4);
174 const unsigned int node_map[] = {0,1,2,3,4,5,6,7,8,9};
175 add_eletype_entry(
TET10, node_map,
"ptet10 10", 10);
180 const unsigned int node_map[] = {0,1,2,3,4,5};
181 add_eletype_entry(
PRISM6, node_map,
"pprism6 6", 6);
187 const unsigned int node_map[] = {0,1,2,3,4,5,6,7,8,12,13,14, 9,10,11};
188 add_eletype_entry(
PRISM15, node_map,
"pprism15 15", 15);
211 std::map<std::string, ElemType> ret;
223 ret[
"phex20"] =
HEX20;
224 ret[
"phex27"] =
HEX27;
226 ret[
"ptet10"] =
TET10;
228 ret[
"8quad"] =
QUAD8;
229 ret[
"3line"] =
EDGE3;
245 _discontinuous (false),
246 _partitioning (true),
247 _write_subdomain_id_as_material (false),
248 _subdivide_second_order (true),
260 _discontinuous (false),
261 _partitioning (true),
262 _write_subdomain_id_as_material (false),
263 _subdivide_second_order (true),
282 const std::vector<Number> & soln,
283 const std::vector<std::string> & names)
285 LOG_SCOPE(
"write_nodal_data()",
"GMVIO");
296 const std::vector<Number> * v,
297 const std::vector<std::string> * solution_names)
299 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 301 libMesh::err <<
"WARNING: GMVIO::write_ascii_new_impl() not infinite-element aware!" 320 std::ofstream out_stream (fname.c_str());
325 if (!out_stream.good())
326 libmesh_file_error(fname.c_str());
328 unsigned int mesh_max_p_level = 0;
332 out_stream <<
"gmvinput ascii\n\n";
344 out_stream << 0. <<
" ";
352 out_stream << 0. <<
" ";
354 out_stream <<
"\n\n";
359 out_stream <<
"cells " << n_active_elem <<
"\n";
364 for (
const auto & elem :
mesh.active_element_ptr_range())
366 mesh_max_p_level = std::max(mesh_max_p_level,
373 const ElementDefinition & ele = eletypes[elem->type()];
377 libmesh_assert_less_equal (ele.node_map.size(), elem->n_nodes());
379 out_stream << ele.label <<
"\n";
381 out_stream << elem->node_id(ele.node_map[i])+1 <<
" ";
391 "Not yet supported in GMVIO::write_ascii_new_impl");
393 out_stream <<
"material " 408 out_stream <<
"proc_" << proc <<
"\n";
411 for (
const auto & elem :
mesh.active_element_ptr_range())
412 out_stream << elem->processor_id()+1 <<
"\n";
420 bool write_variable =
false;
423 if (this->
p_levels() && mesh_max_p_level)
424 write_variable =
true;
427 if ((solution_names !=
nullptr) && (v !=
nullptr))
428 write_variable =
true;
432 write_variable =
true;
435 out_stream <<
"variable\n";
442 if (this->
p_levels() && mesh_max_p_level)
444 out_stream <<
"p_level 0\n";
446 for (
const auto & elem :
mesh.active_element_ptr_range())
448 const ElementDefinition & ele = eletypes[elem->type()];
452 libmesh_assert_less_equal (ele.node_map.size(), elem->n_nodes());
454 for (std::size_t i=0, enms=ele.node_map.size(); i < enms; i++)
455 out_stream << elem->p_level() <<
" ";
457 out_stream <<
"\n\n";
467 out_stream << var_name <<
" 0\n";
472 for (
const auto & elem :
mesh.active_element_ptr_range())
475 libmesh_assert_less (elem->id(), the_array->size());
476 const Real the_value = (*the_array)[elem->id()];
479 for (
unsigned int se=0, nse=elem->n_sub_elem(); se<nse; se++)
480 out_stream << the_value <<
" ";
482 out_stream << the_value <<
" ";
485 out_stream <<
"\n\n";
491 if ((solution_names !=
nullptr) && (v !=
nullptr))
493 const unsigned int n_vars = solution_names->size();
504 for (
unsigned int c=0; c<
n_vars; c++)
507 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 513 out_stream <<
"r_" << (*solution_names)[c] <<
" 1\n";
516 out_stream << (*v)[n*
n_vars + c].real() <<
" ";
518 out_stream <<
"\n\n";
521 out_stream <<
"i_" << (*solution_names)[c] <<
" 1\n";
524 out_stream << (*v)[n*
n_vars + c].imag() <<
" ";
526 out_stream <<
"\n\n";
529 out_stream <<
"a_" << (*solution_names)[c] <<
" 1\n";
531 out_stream << std::abs((*v)[n*
n_vars + c]) <<
" ";
533 out_stream <<
"\n\n";
537 out_stream << (*solution_names)[c] <<
" 1\n";
540 out_stream << (*v)[n*
n_vars + c] <<
" ";
542 out_stream <<
"\n\n";
551 out_stream <<
"endvars\n";
555 out_stream <<
"\nendgmv\n";
566 const std::vector<Number> * v,
567 const std::vector<std::string> * solution_names)
587 std::ofstream out_stream (fname.c_str());
593 if (!out_stream.good())
594 libmesh_file_error(fname.c_str());
608 unsigned int mesh_max_p_level = 0;
618 out_stream <<
"gmvinput ascii\n\n";
629 out_stream << 0. <<
" ";
638 out_stream << 0. <<
" ";
641 out_stream <<
'\n' <<
'\n';
649 out_stream <<
"cells ";
651 out_stream << n_active_sub_elem;
653 out_stream << n_active_elem;
657 std::vector<dof_id_type> conn;
659 for (
const auto & elem :
mesh.active_element_ptr_range())
661 mesh_max_p_level = std::max(mesh_max_p_level,
669 for (
auto se :
make_range(elem->n_sub_elem()))
671 out_stream <<
"line 2\n";
672 elem->connectivity(se,
TECPLOT, conn);
673 for (
const auto &
idx : conn)
674 out_stream <<
idx <<
" ";
680 out_stream <<
"line 2\n";
681 if (elem->default_order() ==
FIRST)
682 elem->connectivity(0,
TECPLOT, conn);
686 for (
auto i : lo_elem->node_index_range())
687 lo_elem->set_node(i, const_cast<Node*>(elem->node_ptr(i)));
688 lo_elem->connectivity(0,
TECPLOT, conn);
690 for (
const auto &
idx : conn)
691 out_stream <<
idx <<
" ";
702 for (
auto se :
make_range(elem->n_sub_elem()))
705 if ((elem->type() ==
QUAD4) ||
706 (elem->type() ==
QUAD8) ||
709 (elem->type() ==
QUAD9)
710 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
716 out_stream <<
"quad 4\n";
717 elem->connectivity(se,
TECPLOT, conn);
718 for (
const auto &
idx : conn)
719 out_stream <<
idx <<
" ";
723 else if ((elem->type() ==
TRI3) ||
724 (elem->type() ==
TRI6))
726 out_stream <<
"tri 3\n";
727 elem->connectivity(se,
TECPLOT, conn);
728 for (
unsigned int i=0; i<3; i++)
729 out_stream << conn[i] <<
" ";
737 if ((elem->type() ==
QUAD4)
738 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
743 elem->connectivity(0,
TECPLOT, conn);
744 out_stream <<
"quad 4\n";
745 for (
const auto &
idx : conn)
746 out_stream <<
idx <<
" ";
748 else if ((elem->type() ==
QUAD8) ||
749 (elem->type() ==
QUAD9)
750 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
756 for (
auto i : lo_elem->node_index_range())
757 lo_elem->set_node(i, const_cast<Node*>(elem->node_ptr(i)));
758 lo_elem->connectivity(0,
TECPLOT, conn);
759 out_stream <<
"quad 4\n";
760 for (
const auto &
idx : conn)
761 out_stream <<
idx <<
" ";
763 else if (elem->type() ==
TRI3)
765 elem->connectivity(0,
TECPLOT, conn);
766 out_stream <<
"tri 3\n";
767 for (
unsigned int i=0; i<3; i++)
768 out_stream << conn[i] <<
" ";
770 else if (elem->type() ==
TRI6)
773 for (
auto i : lo_elem->node_index_range())
774 lo_elem->set_node(i, const_cast<Node*>(elem->node_ptr(i)));
775 lo_elem->connectivity(0,
TECPLOT, conn);
776 out_stream <<
"tri 3\n";
777 for (
unsigned int i=0; i<3; i++)
778 out_stream << conn[i] <<
" ";
790 for (
auto se :
make_range(elem->n_sub_elem()))
793 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS 794 if ((elem->type() ==
HEX8) ||
795 (elem->type() ==
HEX27))
797 out_stream <<
"phex8 8\n";
798 elem->connectivity(se,
TECPLOT, conn);
799 for (
const auto &
idx : conn)
800 out_stream <<
idx <<
" ";
803 else if (elem->type() ==
HEX20)
805 out_stream <<
"phex20 20\n";
806 out_stream << elem->node_id(0)+1 <<
" " 807 << elem->node_id(1)+1 <<
" " 808 << elem->node_id(2)+1 <<
" " 809 << elem->node_id(3)+1 <<
" " 810 << elem->node_id(4)+1 <<
" " 811 << elem->node_id(5)+1 <<
" " 812 << elem->node_id(6)+1 <<
" " 813 << elem->node_id(7)+1 <<
" " 814 << elem->node_id(8)+1 <<
" " 815 << elem->node_id(9)+1 <<
" " 816 << elem->node_id(10)+1 <<
" " 817 << elem->node_id(11)+1 <<
" " 818 << elem->node_id(16)+1 <<
" " 819 << elem->node_id(17)+1 <<
" " 820 << elem->node_id(18)+1 <<
" " 821 << elem->node_id(19)+1 <<
" " 822 << elem->node_id(12)+1 <<
" " 823 << elem->node_id(13)+1 <<
" " 824 << elem->node_id(14)+1 <<
" " 825 << elem->node_id(15)+1 <<
" ";
880 #else // LIBMESH_ENABLE_INFINITE_ELEMENTS 885 if ((elem->type() ==
HEX8) ||
886 (elem->type() ==
HEX27) ||
890 (elem->type() ==
HEX20))
892 out_stream <<
"phex8 8\n";
893 elem->connectivity(se,
TECPLOT, conn);
894 for (
const auto &
idx : conn)
895 out_stream <<
idx <<
" ";
899 else if ((elem->type() ==
TET4) ||
900 (elem->type() ==
TET10))
902 out_stream <<
"tet 4\n";
907 elem->connectivity(se,
TECPLOT, conn);
908 out_stream << conn[0] <<
" " 913 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS 914 else if ((elem->type() ==
PRISM6) ||
919 else if ((elem->type() ==
PRISM6) ||
929 out_stream <<
"phex8 8\n";
930 elem->connectivity(se,
TECPLOT, conn);
931 for (
const auto &
idx : conn)
932 out_stream <<
idx <<
" ";
936 libmesh_error_msg(
"Encountered an unrecognized element " \
937 <<
"type: " << elem->type() \
938 <<
"\nPossibly a dim-1 dimensional " \
939 <<
"element? Aborting...");
946 for (
auto i : lo_elem->node_index_range())
947 lo_elem->set_node(i, const_cast<Node*>(elem->node_ptr(i)));
948 if ((lo_elem->type() ==
HEX8)
949 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
950 || (lo_elem->type() ==
HEX27)
954 out_stream <<
"phex8 8\n";
955 lo_elem->connectivity(0,
TECPLOT, conn);
956 for (
const auto &
idx : conn)
957 out_stream <<
idx <<
" ";
960 else if (lo_elem->type() ==
TET4)
962 out_stream <<
"tet 4\n";
963 lo_elem->connectivity(0,
TECPLOT, conn);
964 out_stream << conn[0] <<
" " 969 else if ((lo_elem->type() ==
PRISM6)
970 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
977 out_stream <<
"phex8 8\n";
978 lo_elem->connectivity(0,
TECPLOT, conn);
979 for (
const auto &
idx : conn)
980 out_stream <<
idx <<
" ";
984 libmesh_error_msg(
"Encountered an unrecognized element " \
985 <<
"type. Possibly a dim-1 dimensional " \
986 <<
"element? Aborting...");
995 libmesh_error_msg(
"Unsupported element dimension: " <<
1018 std::map<subdomain_id_type, unsigned> sbdid_map;
1021 for (
const auto & elem :
mesh.active_element_ptr_range())
1022 sbdid_map.emplace(elem->subdomain_id(), 0);
1028 for (
auto & pr : sbdid_map)
1032 out_stream <<
"material " 1036 for (
auto sbdid :
make_range(sbdid_map.size()))
1037 out_stream <<
"proc_" << sbdid <<
"\n";
1039 for (
const auto & elem :
mesh.active_element_ptr_range())
1042 unsigned gmv_mat_number = libmesh_map_find(sbdid_map, elem->subdomain_id());
1045 for (
unsigned int se=0, nse=elem->n_sub_elem(); se<nse; se++)
1046 out_stream << gmv_mat_number+1 <<
'\n';
1048 out_stream << gmv_mat_number+1 <<
"\n";
1055 out_stream <<
"material " 1060 out_stream <<
"proc_" << proc <<
'\n';
1062 for (
const auto & elem :
mesh.active_element_ptr_range())
1064 for (
unsigned int se=0, nse=elem->n_sub_elem(); se<nse; se++)
1065 out_stream << elem->processor_id()+1 <<
'\n';
1067 out_stream << elem->processor_id()+1 <<
'\n';
1078 bool write_variable =
false;
1081 if (this->
p_levels() && mesh_max_p_level)
1082 write_variable =
true;
1085 if ((solution_names !=
nullptr) && (v !=
nullptr))
1086 write_variable =
true;
1090 write_variable =
true;
1093 out_stream <<
"variable\n";
1097 if (this->
p_levels() && mesh_max_p_level)
1099 out_stream <<
"p_level 0\n";
1101 for (
const auto & elem :
mesh.active_element_ptr_range())
1103 for (
unsigned int se=0, nse=elem->n_sub_elem(); se<nse; se++)
1104 out_stream << elem->p_level() <<
" ";
1106 out_stream << elem->p_level() <<
" ";
1107 out_stream <<
"\n\n";
1119 out_stream << var_name <<
" 0\n";
1124 for (
const auto & elem :
mesh.active_element_ptr_range())
1127 libmesh_assert_less (elem->id(), the_array->size());
1128 const Real the_value = (*the_array)[elem->id()];
1131 for (
unsigned int se=0, nse=elem->n_sub_elem(); se<nse; se++)
1132 out_stream << the_value <<
" ";
1134 out_stream << the_value <<
" ";
1137 out_stream <<
"\n\n";
1145 if ((solution_names !=
nullptr) &&
1148 const unsigned int n_vars =
1149 cast_int<unsigned int>(solution_names->size());
1160 for (
unsigned int c=0; c<
n_vars; c++)
1163 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 1169 out_stream <<
"r_" << (*solution_names)[c] <<
" 1\n";
1172 out_stream << (*v)[n*
n_vars + c].real() <<
" ";
1174 out_stream <<
'\n' <<
'\n';
1178 out_stream <<
"i_" << (*solution_names)[c] <<
" 1\n";
1181 out_stream << (*v)[n*
n_vars + c].imag() <<
" ";
1183 out_stream <<
'\n' <<
'\n';
1186 out_stream <<
"a_" << (*solution_names)[c] <<
" 1\n";
1188 out_stream << std::abs((*v)[n*
n_vars + c]) <<
" ";
1190 out_stream <<
'\n' <<
'\n';
1194 out_stream << (*solution_names)[c] <<
" 1\n";
1197 out_stream << (*v)[n*
n_vars + c] <<
" ";
1199 out_stream <<
'\n' <<
'\n';
1208 out_stream <<
"endvars\n";
1212 out_stream <<
"\nendgmv\n";
1222 const std::vector<Number> * vec,
1223 const std::vector<std::string> * solution_names)
1238 std::ofstream out_stream (fname.c_str());
1242 unsigned int mesh_max_p_level = 0;
1249 buffer =
"gmvinput";
1250 out_stream.write(buffer.c_str(), buffer.size());
1252 buffer =
"ieeei4r4";
1253 out_stream.write(buffer.c_str(), buffer.size());
1261 out_stream.write(buffer.c_str(), buffer.size());
1264 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1269 temp[v] =
static_cast<float>(
mesh.
point(v)(0));
1270 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1276 temp[v] =
static_cast<float>(
mesh.
point(v)(1));
1281 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1287 temp[v] =
static_cast<float>(
mesh.
point(v)(2));
1292 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1299 out_stream.write(buffer.c_str(), buffer.size());
1301 unsigned int tempint = n_active_elem;
1302 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1304 for (
const auto & elem :
mesh.active_element_ptr_range())
1306 mesh_max_p_level = std::max(mesh_max_p_level,
1312 const ElementDefinition & ed = eletypes[elem->type()];
1321 buffer.erase(buffer.find_first_of(
' '), std::string::npos);
1324 while (buffer.size() < 8)
1325 buffer.insert(buffer.end(),
' ');
1328 out_stream.write(buffer.c_str(), buffer.size());
1335 tempint = cast_int<unsigned int>(ed.node_map.size());
1336 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1339 for (
const auto & ed_id : ed.node_map)
1342 out_stream.write(reinterpret_cast<char *>(&
id),
sizeof(
dof_id_type));
1353 "Not yet supported in GMVIO::write_binary");
1355 buffer =
"material";
1356 out_stream.write(buffer.c_str(), buffer.size());
1359 out_stream.write(reinterpret_cast<char *>(&tmpint),
sizeof(
unsigned int));
1362 out_stream.write(reinterpret_cast<char *>(&tmpint),
sizeof(
unsigned int));
1369 std::ostringstream oss;
1370 oss <<
"proc_" << std::setw(3) << std::left << proc;
1371 out_stream.write(oss.str().c_str(), oss.str().size());
1374 std::vector<unsigned int> proc_id (n_active_elem);
1380 for (
const auto & elem :
mesh.active_element_ptr_range())
1381 proc_id[n++] = elem->processor_id() + 1;
1383 out_stream.write(reinterpret_cast<char *>(proc_id.data()),
1384 sizeof(
unsigned int)*proc_id.size());
1391 bool write_variable =
false;
1394 if (this->
p_levels() && mesh_max_p_level)
1395 write_variable =
true;
1398 if ((solution_names !=
nullptr) && (vec !=
nullptr))
1399 write_variable =
true;
1407 buffer =
"variable";
1408 out_stream.write(buffer.c_str(), buffer.size());
1412 if (this->
p_levels() && mesh_max_p_level)
1414 unsigned int n_floats = n_active_elem;
1418 std::vector<float> temp(n_floats);
1421 out_stream.write(buffer.c_str(), buffer.size());
1423 unsigned int tempint = 0;
1424 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1427 for (
const auto & elem :
mesh.active_element_ptr_range())
1428 for (
unsigned int se=0, nse=elem->n_sub_elem(); se<nse; se++)
1429 temp[n++] = static_cast<float>( elem->p_level() );
1431 out_stream.write(reinterpret_cast<char *>(temp.data()),
1432 sizeof(
float)*n_floats);
1438 libMesh::err <<
"Cell-centered data not (yet) supported in binary I/O mode!" << std::endl;
1444 if ((solution_names !=
nullptr) &&
1449 const unsigned int n_vars =
1450 cast_int<unsigned int>(solution_names->size());
1452 for (
unsigned int c=0; c<
n_vars; c++)
1455 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 1461 out_stream.write(buffer.c_str(), buffer.size());
1463 buffer = (*solution_names)[c];
1464 out_stream.write(buffer.c_str(), buffer.size());
1466 unsigned int tempint = 1;
1467 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1470 temp[n] =
static_cast<float>( (*vec)[n*
n_vars + c].real() );
1472 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1477 out_stream.write(buffer.c_str(), buffer.size());
1479 buffer = (*solution_names)[c];
1480 out_stream.write(buffer.c_str(), buffer.size());
1482 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1485 temp[n] =
static_cast<float>( (*vec)[n*
n_vars + c].imag() );
1487 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1491 out_stream.write(buffer.c_str(), buffer.size());
1492 buffer = (*solution_names)[c];
1493 out_stream.write(buffer.c_str(), buffer.size());
1495 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1498 temp[n] =
static_cast<float>(std::abs((*vec)[n*
n_vars + c]));
1500 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1504 buffer = (*solution_names)[c];
1505 out_stream.write(buffer.c_str(), buffer.size());
1507 unsigned int tempint = 1;
1508 out_stream.write(reinterpret_cast<char *>(&tempint),
sizeof(
unsigned int));
1511 temp[n] =
static_cast<float>((*vec)[n*
n_vars + c]);
1513 out_stream.write(reinterpret_cast<char *>(temp.data()),
sizeof(
float)*
mesh.
n_nodes());
1522 buffer =
"endvars ";
1523 out_stream.write(buffer.c_str(), buffer.size());
1528 out_stream.write(buffer.c_str(), buffer.size());
1541 const bool write_partitioning,
1542 const std::set<std::string> * system_names)
const 1544 std::vector<std::string> solution_names;
1545 std::vector<Number> v;
1559 std::ofstream out_stream(
name.c_str());
1567 out_stream <<
"gmvinput ascii" << std::endl << std::endl;
1573 for (
const auto & elem :
mesh.active_element_ptr_range())
1574 tw += elem->n_nodes();
1576 out_stream <<
"nodes " << tw << std::endl;
1583 for (
const auto & elem :
mesh.active_element_ptr_range())
1584 for (
const Node & node : elem->node_ref_range())
1585 out_stream << node(0) <<
" ";
1587 out_stream << std::endl;
1593 for (
const auto & elem :
mesh.active_element_ptr_range())
1594 for (
const Node & node : elem->node_ref_range())
1596 out_stream << node(1) <<
" ";
1598 out_stream << 0. <<
" ";
1601 out_stream << std::endl;
1607 for (
const auto & elem :
mesh.active_element_ptr_range())
1608 for (
const Node & node : elem->node_ref_range())
1610 out_stream << node(2) <<
" ";
1612 out_stream << 0. <<
" ";
1615 out_stream << std::endl << std::endl;
1624 out_stream <<
"cells " << n_active_elem << std::endl;
1632 for (
const auto & elem :
mesh.active_element_ptr_range())
1633 for (
unsigned int se=0, nse=elem->n_sub_elem(); se<nse; se++)
1635 if ((elem->type() ==
EDGE2) ||
1636 (elem->type() ==
EDGE3) ||
1637 (elem->type() ==
EDGE4)
1638 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1643 out_stream <<
"line 2" << std::endl;
1644 for (
unsigned int i=0, enn=elem->n_nodes(); i<enn; i++)
1645 out_stream << nn++ <<
" ";
1651 out_stream << std::endl;
1659 for (
const auto & elem :
mesh.active_element_ptr_range())
1660 for (
unsigned int se=0, nse=elem->n_sub_elem(); se<nse; se++)
1662 if ((elem->type() ==
QUAD4) ||
1663 (elem->type() ==
QUAD8) ||
1666 (elem->type() ==
QUAD9)
1667 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1673 out_stream <<
"quad 4" << std::endl;
1674 for (
unsigned int i=0, enn=elem->n_nodes(); i<enn; i++)
1675 out_stream << nn++ <<
" ";
1678 else if ((elem->type() ==
TRI3) ||
1679 (elem->type() ==
TRI6))
1681 out_stream <<
"tri 3" << std::endl;
1682 for (
unsigned int i=0, enn=elem->n_nodes(); i<enn; i++)
1683 out_stream << nn++ <<
" ";
1689 out_stream << std::endl;
1698 for (
const auto & elem :
mesh.active_element_ptr_range())
1699 for (
unsigned int se=0, nse=elem->n_sub_elem(); se<nse; se++)
1701 if ((elem->type() ==
HEX8) ||
1702 (elem->type() ==
HEX20) ||
1703 (elem->type() ==
HEX27)
1704 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1711 out_stream <<
"phex8 8" << std::endl;
1712 for (
unsigned int i=0, enn=elem->n_nodes(); i<enn; i++)
1713 out_stream << nn++ <<
" ";
1715 else if ((elem->type() ==
PRISM6) ||
1718 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1724 out_stream <<
"pprism6 6" << std::endl;
1725 for (
unsigned int i=0, enn=elem->n_nodes(); i<enn; i++)
1726 out_stream << nn++ <<
" ";
1728 else if ((elem->type() ==
TET4) ||
1729 (elem->type() ==
TET10))
1731 out_stream <<
"tet 4" << std::endl;
1732 for (
unsigned int i=0, enn=elem->n_nodes(); i<enn; i++)
1733 out_stream << nn++ <<
" ";
1738 out_stream << std::endl;
1748 out_stream << std::endl;
1754 if (write_partitioning)
1757 "Not yet supported in GMVIO::write_discontinuous_gmv");
1759 out_stream <<
"material " 1761 <<
" 0"<< std::endl;
1764 out_stream <<
"proc_" << proc << std::endl;
1766 for (
const auto & elem :
mesh.active_element_ptr_range())
1767 out_stream << elem->processor_id()+1 << std::endl;
1769 out_stream << std::endl;
1776 libMesh::err <<
"Cell-centered data not (yet) supported for discontinuous GMV files!" << std::endl;
1783 const unsigned int n_vars =
1784 cast_int<unsigned int>(solution_names.size());
1788 out_stream <<
"variable" << std::endl;
1791 for (
unsigned int c=0; c<
n_vars; c++)
1794 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 1800 out_stream <<
"r_" << solution_names[c] <<
" 1" << std::endl;
1801 for (
const auto & elem :
mesh.active_element_ptr_range())
1802 for (
auto n : elem->node_index_range())
1803 out_stream << v[(n++)*
n_vars + c].real() <<
" ";
1804 out_stream << std::endl << std::endl;
1808 out_stream <<
"i_" << solution_names[c] <<
" 1" << std::endl;
1809 for (
const auto & elem :
mesh.active_element_ptr_range())
1810 for (
auto n : elem->node_index_range())
1811 out_stream << v[(n++)*
n_vars + c].imag() <<
" ";
1812 out_stream << std::endl << std::endl;
1815 out_stream <<
"a_" << solution_names[c] <<
" 1" << std::endl;
1816 for (
const auto & elem :
mesh.active_element_ptr_range())
1817 for (
auto n : elem->node_index_range())
1818 out_stream << std::abs(v[(n++)*
n_vars + c]) <<
" ";
1819 out_stream << std::endl << std::endl;
1823 out_stream << solution_names[c] <<
" 1" << std::endl;
1827 for (
const auto & elem :
mesh.active_element_ptr_range())
1828 for (
unsigned int i=0, enn=elem->n_nodes(); i<enn; i++)
1829 out_stream << v[(nn++)*
n_vars + c] <<
" ";
1831 out_stream << std::endl << std::endl;
1837 out_stream <<
"endvars" << std::endl;
1842 out_stream << std::endl <<
"endgmv" << std::endl;
1850 const std::vector<Real> * cell_centered_data_vals)
1875 libmesh_experimental();
1877 #ifndef LIBMESH_HAVE_GMV 1879 libmesh_error_msg(
"Cannot read GMV file " <<
name <<
" without the GMV API.");
1898 int ierr = GMVLib::gmvread_open_fromfileskip(const_cast<char *>(
name.c_str()));
1899 libmesh_error_msg_if(ierr != 0,
"GMVLib::gmvread_open_fromfileskip failed!");
1905 GMVLib::gmvread_data();
1908 if (GMVLib::gmv_data.keyword == GMVEND)
1911 GMVLib::gmvread_close();
1916 libmesh_error_msg_if(GMVLib::gmv_data.keyword == GMVERROR,
1917 "Encountered GMVERROR while reading!");
1920 switch (GMVLib::gmv_data.keyword)
1924 if (GMVLib::gmv_data.num2 ==
NODES)
1928 libmesh_error_msg_if(GMVLib::gmv_data.num2 == NODE_V,
1929 "Unsupported GMV data type NODE_V!");
1956 if (GMVLib::gmv_data.datatype == ENDKEYWORD)
1961 if (GMVLib::gmv_data.datatype == NODE)
1970 << GMVLib::gmv_data.name1
1971 <<
" which is of unsupported GMV datatype " 1972 << GMVLib::gmv_data.datatype
1973 <<
". Nodal field data is currently the only type currently supported." 1981 libmesh_error_msg(
"Encountered unknown GMV keyword " << GMVLib::gmv_data.keyword);
1987 for (
unsigned char i=0; i!=4; ++i)
1993 "Cannot open dimension " 1995 <<
" mesh file when configured without " 2018 #ifdef LIBMESH_HAVE_GMV 2021 _nodal_data.emplace(std::string(GMVLib::gmv_data.name1),
2022 std::vector<Number>(GMVLib::gmv_data.doubledata1, GMVLib::gmv_data.doubledata1+GMVLib::gmv_data.num));
2030 #ifdef LIBMESH_HAVE_GMV 2033 libmesh_assert_equal_to (GMVLib::gmv_data.datatype, CELL);
2042 for (
int i = 0; i < GMVLib::gmv_data.nlongdata1; i++)
2044 cast_int<processor_id_type>(GMVLib::gmv_data.longdata1[i]-1);
2054 #ifdef LIBMESH_HAVE_GMV 2056 libmesh_assert_equal_to (GMVLib::gmv_data.datatype, UNSTRUCT);
2060 for (
int i = 0; i < GMVLib::gmv_data.num; i++)
2064 GMVLib::gmv_data.doubledata2[i],
2065 GMVLib::gmv_data.doubledata3[i]), i);
2073 #ifdef LIBMESH_HAVE_GMV 2078 (GMVLib::gmv_data.datatype==REGULAR) ||
2079 (GMVLib::gmv_data.datatype==ENDKEYWORD);
2085 if (GMVLib::gmv_data.datatype == REGULAR)
2104 const ElementDefinition & eledef = eletypes[type];
2108 for (
int i=0; i<GMVLib::gmv_data.num2; i++)
2111 unsigned mapped_i = eledef.node_map[i];
2116 (cast_int<dof_id_type>(GMVLib::gmv_data.longdata1[mapped_i]-1)));
2126 if (GMVLib::gmv_data.datatype == ENDKEYWORD)
2139 elemname.erase(std::remove_if(elemname.begin(), elemname.end(),
2140 [](
unsigned char const c){
return std::isspace(c);}),
2153 libMesh::err <<
"Unable to copy nodal solution: No nodal " 2154 <<
"solution has been read in from file." << std::endl;
2167 std::set<std::string> vars_copied;
2193 libMesh::err <<
"Only FIRST-order LAGRANGE variables can be read from GMV files. " 2194 <<
"Skipping variable " << var_name << std::endl;
2202 sz = cast_int<dof_id_type>(vec.size());
2207 const unsigned int dof_index =
2213 if ((dof_index >= system.
solution->first_local_index()) &&
2214 (dof_index < system.solution->last_local_index()))
2215 system.
solution->set (dof_index, vec[i]);
2219 vars_copied.insert (var_name);
2232 if (vars_copied.find(pr.first) == vars_copied.end())
2235 <<
" was not copied to the EquationSystems object." std::string name(const ElemQuality q)
This function returns a string containing some name for q.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
virtual void read(const std::string &mesh_file) override
This method implements reading a mesh from a specified file.
FEFamily family
The type of finite element.
ElemType
Defines an enum for geometric element types.
This is the EquationSystems class.
void _read_nodes()
Helper functions for reading nodes/cells from a GMV file.
void build_variable_names(std::vector< std::string > &var_names, const FEType *type=nullptr, const std::set< std::string > *system_names=nullptr) const
Fill the input vector var_names with the names of the variables for each system.
virtual dof_id_type n_active_elem() const =0
A Node is like a Point, but with more information.
unsigned int n_systems() const
static std::map< std::string, ElemType > _reading_element_map
Static map from string -> ElementType for use during reading.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use...
void write_binary(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
void build_discontinuous_solution_vector(std::vector< Number > &soln, const std::set< std::string > *system_names=nullptr, const std::vector< std::string > *var_names=nullptr, bool vertices_only=false, bool add_sides=false) const
Fill the input vector soln with solution values.
unsigned int _next_elem_id
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly ecreated (or read) mesh for use.
unsigned int & ascii_precision()
Return/set the precision to use when writing ASCII files.
OrderWrapper order
The approximation order of the element.
This class defines an abstract interface for Mesh output.
The libMesh namespace provides an interface to certain functionality in the library.
bool & partitioning()
Flag indicating whether or not to write the partitioning information for the mesh.
const T_sys & get_system(std::string_view name) const
std::map< std::string, std::vector< Number > > _nodal_data
This is the MeshBase class.
bool & binary()
Flag indicating whether or not to write a binary file.
unsigned int variable_number(std::string_view var) const
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
bool & write_subdomain_id_as_material()
Flag to write element subdomain_id's as GMV "materials" instead of element processor_id's.
ElemType gmv_elem_to_libmesh_elem(std::string elemname)
std::map< std::string, const std::vector< Real > *> _cell_centered_data
Storage for arbitrary cell-centered data.
bool has_variable(std::string_view var) const
processor_id_type n_processors() const
static std::map< std::string, ElemType > build_reading_element_map()
Static function used to build the _reading_element_map.
Manages consistently variables, degrees of freedom, and coefficient vectors.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
bool _write_subdomain_id_as_material
Flag to write element subdomain_id's as GMV "materials" instead of element processor_id's.
bool & p_levels()
Flag indicating whether or not to write p level information for p refined meshes. ...
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
void copy_nodal_solution(EquationSystems &es)
If we read in a nodal solution while reading in a mesh, we can attempt to copy that nodal solution in...
virtual void clear()
Deletes all the element and node data that is currently stored.
void write_ascii_old_impl(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
int get_order() const
Explicitly request the order as an int.
std::string enum_to_string(const T e)
unsigned int n_partitions() const
bool & subdivide_second_order()
Flag indicating whether or not to subdivide second order elements.
virtual void update()
Update the local values to reflect the solution on neighboring processors.
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)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
GMVIO(const MeshBase &)
Constructor.
Temporarily serialize a DistributedMesh for non-distributed-mesh capable code paths.
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
dof_id_type n_active_sub_elem() const
Same as n_sub_elem(), but only counts active elements.
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)
Takes a vector of cell-centered data to be plotted.
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
static ElemType first_order_equivalent_type(const ElemType et)
A Point defines a location in LIBMESH_DIM dimensional Real 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
Writes a GMV file with discontinuous data.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
virtual dof_id_type n_nodes() const =0