42 #include <unordered_map> 44 #ifdef LIBMESH_HAVE_GZSTREAM 46 # include "gzstream.h" 98 if (file_name.rfind(
".gz") < file_name.size())
100 #ifdef LIBMESH_HAVE_GZSTREAM 102 igzstream in_stream (file_name.c_str());
107 libmesh_error_msg(
"ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
115 std::ifstream in_stream (file_name.c_str());
129 if (!in_stream.good())
130 libmesh_error_msg(
"ERROR: Input file not good.");
147 old_line = current_line;
150 std::getline(in_stream, current_line);
158 current_line.erase(std::remove_if(current_line.begin(), current_line.end(), isspace),
177 libmesh_error_msg(
"ERROR: The Nodes section must come before the Elements section of the UNV file!");
190 if (!found_node || !found_elem)
191 libmesh_error_msg(
"ERROR: The Nodes and Elements sections must come before the Groups section of the UNV file!");
199 if (found_node && found_elem && found_group)
211 libmesh_error_msg(
"Stream is bad! Perhaps the file does not exist?");
217 libmesh_error_msg(
"ERROR: Could not find nodes!");
220 libmesh_error_msg(
"ERROR: Could not find elements!");
231 libmesh_error_msg(
"Cannot open dimension " \
233 <<
" mesh file when configured without " \
247 if (elem->dim() < max_dim)
262 if (file_name.rfind(
".gz") < file_name.size())
264 #ifdef LIBMESH_HAVE_GZSTREAM 266 ogzstream out_stream(file_name.c_str());
271 libmesh_error_msg(
"ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
280 std::ofstream out_stream (file_name.c_str());
291 if (!out_file.good())
292 libmesh_error_msg(
"ERROR: Output file not good.");
304 LOG_SCOPE(
"nodes_in()",
"UNVIO");
323 std::istringstream coords_stream;
330 in_file >> node_label;
333 if (node_label == -1)
341 std::getline(in_file, line);
344 std::getline(in_file, line);
350 last_pos = line.find(
"D", last_pos);
352 if (last_pos != std::string::npos)
353 line.replace(last_pos, 1,
"E");
360 coords_stream.str(line);
361 coords_stream.clear();
362 coords_stream >> xyz(0) >> xyz(1) >> xyz(2);
377 unsigned char max_dim = 0;
379 unsigned char elem_dimensions_size = cast_int<unsigned char>
382 for (
unsigned char i=1; i<elem_dimensions_size; ++i)
394 std::string::size_type position = number.find(
"D", 6);
396 if (position != std::string::npos)
399 number.replace(position, 1,
"e");
422 typedef std::unordered_multimap<dof_id_type, Elem *> map_type;
423 map_type provide_bcs;
430 in_file >> group_number;
432 if (group_number == -1)
445 unsigned num_entities;
446 std::string group_name;
449 in_file >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy
453 in_file >> group_name;
459 is_subdomain_group =
false,
460 is_sideset_group =
false;
476 unsigned entity_type_code, entity_tag, dummy;
477 for (
unsigned entity=0; entity<num_entities; ++entity)
479 in_file >> entity_type_code >> entity_tag >> dummy >> dummy;
481 if (entity_type_code != 8)
482 libMesh::err <<
"Warning, unrecognized entity type code = " 492 unsigned libmesh_elem_id = it->second;
498 if (group_elem->
dim() < max_dim)
500 is_sideset_group =
true;
506 if (group_elem->
dim()+1 != max_dim)
507 libmesh_error_msg(
"ERROR: Expected boundary element of dimension " \
508 << max_dim-1 <<
" but got " << group_elem->
dim());
513 cast_int<subdomain_id_type>(group_number);
516 provide_bcs.insert(std::make_pair(group_elem->
key(), group_elem));
520 else if (group_elem->
dim() == max_dim)
522 is_subdomain_group =
true;
524 cast_int<subdomain_id_type>(group_number);
528 libmesh_error_msg(
"ERROR: Found an elem with dim=" \
529 << group_elem->
dim() <<
" > " <<
"max_dim=" << +max_dim);
532 libMesh::err <<
"WARNING: UNV Element " << entity_tag <<
" not found while parsing groups." << std::endl;
537 if (is_sideset_group)
539 (cast_int<boundary_id_type>(group_number)) = group_name;
541 if (is_subdomain_group)
543 (cast_int<subdomain_id_type>(group_number)) = group_name;
549 if (elem->dim() == max_dim)
550 for (
auto sn : elem->side_index_range())
551 for (
const auto & pr :
as_range(provide_bcs.equal_range (elem->key(sn))))
561 std::unique_ptr<Elem>
side (elem->build_side_ptr(sn));
564 Elem * lower_dim_elem = pr.second;
567 if (*lower_dim_elem == *
side)
576 LOG_SCOPE(
"elements_in()",
"UNVIO");
594 std::vector<unsigned int> node_labels (21);
608 unsigned int assign_elem_nodes[21];
615 in_file >> element_label;
617 if (element_label == -1)
620 in_file >> fe_descriptor_id
638 if (fe_descriptor_id < 25)
641 in_file >> dummy >> dummy >> dummy;
645 for (
unsigned int j=1; j<=
n_nodes; j++)
646 in_file >> node_labels[j];
649 Elem * elem =
nullptr;
651 switch (fe_descriptor_id)
657 assign_elem_nodes[1]=0;
658 assign_elem_nodes[2]=1;
667 assign_elem_nodes[1]=0;
668 assign_elem_nodes[2]=2;
669 assign_elem_nodes[3]=1;
678 assign_elem_nodes[1]=0;
679 assign_elem_nodes[2]=5;
680 assign_elem_nodes[3]=2;
681 assign_elem_nodes[4]=4;
682 assign_elem_nodes[5]=1;
683 assign_elem_nodes[6]=3;
688 libmesh_error_msg(
"ERROR: UNV-element type 43: Plane Stress Cubic Triangle not supported.");
695 assign_elem_nodes[1]=0;
696 assign_elem_nodes[2]=3;
697 assign_elem_nodes[3]=2;
698 assign_elem_nodes[4]=1;
707 assign_elem_nodes[1]=0;
708 assign_elem_nodes[2]=7;
709 assign_elem_nodes[3]=3;
710 assign_elem_nodes[4]=6;
711 assign_elem_nodes[5]=2;
712 assign_elem_nodes[6]=5;
713 assign_elem_nodes[7]=1;
714 assign_elem_nodes[8]=4;
722 assign_elem_nodes[1]=0;
723 assign_elem_nodes[2]=7;
724 assign_elem_nodes[3]=3;
725 assign_elem_nodes[4]=6;
726 assign_elem_nodes[5]=2;
727 assign_elem_nodes[6]=5;
728 assign_elem_nodes[7]=1;
729 assign_elem_nodes[8]=4;
730 assign_elem_nodes[9]=8;
735 libmesh_error_msg(
"ERROR: UNV-element type 46: Plane Stress Cubic Quadrilateral not supported.");
741 assign_elem_nodes[1]=0;
742 assign_elem_nodes[2]=1;
743 assign_elem_nodes[3]=2;
744 assign_elem_nodes[4]=3;
752 assign_elem_nodes[1]=0;
753 assign_elem_nodes[2]=1;
754 assign_elem_nodes[3]=2;
755 assign_elem_nodes[4]=3;
756 assign_elem_nodes[5]=4;
757 assign_elem_nodes[6]=5;
765 assign_elem_nodes[1]=0;
766 assign_elem_nodes[2]=4;
767 assign_elem_nodes[3]=5;
768 assign_elem_nodes[4]=1;
769 assign_elem_nodes[5]=3;
770 assign_elem_nodes[6]=7;
771 assign_elem_nodes[7]=6;
772 assign_elem_nodes[8]=2;
780 assign_elem_nodes[1]=0;
781 assign_elem_nodes[2]=12;
782 assign_elem_nodes[3]=4;
783 assign_elem_nodes[4]=16;
784 assign_elem_nodes[5]=5;
785 assign_elem_nodes[6]=13;
786 assign_elem_nodes[7]=1;
787 assign_elem_nodes[8]=8;
789 assign_elem_nodes[9]=11;
790 assign_elem_nodes[10]=19;
791 assign_elem_nodes[11]=17;
792 assign_elem_nodes[12]=9;
794 assign_elem_nodes[13]=3;
795 assign_elem_nodes[14]=15;
796 assign_elem_nodes[15]=7;
797 assign_elem_nodes[16]=18;
798 assign_elem_nodes[17]=6;
799 assign_elem_nodes[18]=14;
800 assign_elem_nodes[19]=2;
801 assign_elem_nodes[20]=10;
806 libmesh_error_msg(
"Error: UNV-element type 117: Solid Cubic Brick not supported.");
812 assign_elem_nodes[1]=0;
813 assign_elem_nodes[2]=4;
814 assign_elem_nodes[3]=1;
815 assign_elem_nodes[4]=5;
816 assign_elem_nodes[5]=2;
817 assign_elem_nodes[6]=6;
818 assign_elem_nodes[7]=7;
819 assign_elem_nodes[8]=8;
820 assign_elem_nodes[9]=9;
821 assign_elem_nodes[10]=3;
826 libmesh_error_msg(
"ERROR: UNV-element type " << fe_descriptor_id <<
" not supported.");
835 elem->
set_node(assign_elem_nodes[j]) = it->second;
837 libmesh_error_msg(
"ERROR: UNV node " << node_labels[j] <<
" not found!");
874 exp_coord_sys_dummy = 0,
875 disp_coord_sys_dummy = 0,
882 out_file << std::scientific << std::setprecision(16) << std::uppercase;
888 out_file << std::setw(10) << node_id
889 << std::setw(10) << exp_coord_sys_dummy
890 << std::setw(10) << disp_coord_sys_dummy
891 << std::setw(10) << color_dummy
895 Real x = (*current_node)(0);
898 Real y = (*current_node)(1);
904 Real z = (*current_node)(2);
909 out_file << std::setw(25) << x
910 << std::setw(25) << y
911 << std::setw(25) << z
936 fe_descriptor_id = 0,
937 phys_prop_tab_dummy = 2,
938 mat_prop_tab_dummy = 1,
954 unsigned int assign_elem_nodes[20];
956 unsigned int n_elem_written=0;
963 switch (elem->type())
968 fe_descriptor_id = 41;
969 assign_elem_nodes[0] = 0;
970 assign_elem_nodes[1] = 2;
971 assign_elem_nodes[2] = 1;
977 fe_descriptor_id = 42;
978 assign_elem_nodes[0] = 0;
979 assign_elem_nodes[1] = 5;
980 assign_elem_nodes[2] = 2;
981 assign_elem_nodes[3] = 4;
982 assign_elem_nodes[4] = 1;
983 assign_elem_nodes[5] = 3;
989 fe_descriptor_id = 44;
990 assign_elem_nodes[0] = 0;
991 assign_elem_nodes[1] = 3;
992 assign_elem_nodes[2] = 2;
993 assign_elem_nodes[3] = 1;
999 fe_descriptor_id = 45;
1000 assign_elem_nodes[0] = 0;
1001 assign_elem_nodes[1] = 7;
1002 assign_elem_nodes[2] = 3;
1003 assign_elem_nodes[3] = 6;
1004 assign_elem_nodes[4] = 2;
1005 assign_elem_nodes[5] = 5;
1006 assign_elem_nodes[6] = 1;
1007 assign_elem_nodes[7] = 4;
1013 fe_descriptor_id = 300;
1014 assign_elem_nodes[0] = 0;
1015 assign_elem_nodes[1] = 7;
1016 assign_elem_nodes[2] = 3;
1017 assign_elem_nodes[3] = 6;
1018 assign_elem_nodes[4] = 2;
1019 assign_elem_nodes[5] = 5;
1020 assign_elem_nodes[6] = 1;
1021 assign_elem_nodes[7] = 4;
1022 assign_elem_nodes[8] = 8;
1028 fe_descriptor_id = 111;
1029 assign_elem_nodes[0] = 0;
1030 assign_elem_nodes[1] = 1;
1031 assign_elem_nodes[2] = 2;
1032 assign_elem_nodes[3] = 3;
1038 fe_descriptor_id = 112;
1039 assign_elem_nodes[0] = 0;
1040 assign_elem_nodes[1] = 1;
1041 assign_elem_nodes[2] = 2;
1042 assign_elem_nodes[3] = 3;
1043 assign_elem_nodes[4] = 4;
1044 assign_elem_nodes[5] = 5;
1050 fe_descriptor_id = 115;
1051 assign_elem_nodes[0] = 0;
1052 assign_elem_nodes[1] = 4;
1053 assign_elem_nodes[2] = 5;
1054 assign_elem_nodes[3] = 1;
1055 assign_elem_nodes[4] = 3;
1056 assign_elem_nodes[5] = 7;
1057 assign_elem_nodes[6] = 6;
1058 assign_elem_nodes[7] = 2;
1064 fe_descriptor_id = 116;
1065 assign_elem_nodes[ 0] = 0;
1066 assign_elem_nodes[ 1] = 12;
1067 assign_elem_nodes[ 2] = 4;
1068 assign_elem_nodes[ 3] = 16;
1069 assign_elem_nodes[ 4] = 5;
1070 assign_elem_nodes[ 5] = 13;
1071 assign_elem_nodes[ 6] = 1;
1072 assign_elem_nodes[ 7] = 8;
1074 assign_elem_nodes[ 8] = 11;
1075 assign_elem_nodes[ 9] = 19;
1076 assign_elem_nodes[10] = 17;
1077 assign_elem_nodes[11] = 9;
1079 assign_elem_nodes[12] = 3;
1080 assign_elem_nodes[13] = 15;
1081 assign_elem_nodes[14] = 7;
1082 assign_elem_nodes[15] = 18;
1083 assign_elem_nodes[16] = 6;
1084 assign_elem_nodes[17] = 14;
1085 assign_elem_nodes[18] = 2;
1086 assign_elem_nodes[19] = 10;
1094 fe_descriptor_id = 118;
1095 assign_elem_nodes[0] = 0;
1096 assign_elem_nodes[1] = 4;
1097 assign_elem_nodes[2] = 1;
1098 assign_elem_nodes[3] = 5;
1099 assign_elem_nodes[4] = 2;
1100 assign_elem_nodes[5] = 6;
1101 assign_elem_nodes[6] = 7;
1102 assign_elem_nodes[7] = 8;
1103 assign_elem_nodes[8] = 9;
1104 assign_elem_nodes[9] = 3;
1109 libmesh_error_msg(
"ERROR: Element type = " << elem->type() <<
" not supported in " <<
"UNVIO!");
1114 out_file << std::setw(10) << elem_id
1115 << std::setw(10) << fe_descriptor_id
1116 << std::setw(10) << phys_prop_tab_dummy
1117 << std::setw(10) << mat_prop_tab_dummy
1118 << std::setw(10) << color_dummy
1119 << std::setw(10) << elem->n_nodes()
1122 for (
auto j : elem->node_index_range())
1127 const Node * node_in_unv_order = elem->node_ptr(assign_elem_nodes[j]);
1136 out_file << std::setw(10) << node_id;
1145 libMesh::out <<
" Finished writing " << n_elem_written <<
" elements" << std::endl;
1148 out_file <<
" -1\n";
1155 std::ifstream in_stream(file_name.c_str());
1157 if (!in_stream.good())
1158 libmesh_error_msg(
"Error opening UNV data file.");
1160 std::string olds, news, dummy;
1164 in_stream >> olds >> news;
1167 while (((olds !=
"-1") || (news ==
"-1")) && !in_stream.eof())
1173 if (in_stream.eof())
1181 for (
unsigned int i=0; i<3; i++)
1182 std::getline(in_stream, dummy);
1188 unsigned int dataset_location;
1189 in_stream >> dataset_location;
1192 if (dataset_location != 1)
1193 libmesh_error_msg(
"ERROR: Currently only Data at nodes is supported.");
1196 for (
unsigned int i=0; i<6; i++)
1197 std::getline(in_stream, dummy);
1203 data_characteristic,
1211 unsigned int num_vals_per_node;
1213 in_stream >> model_type
1215 >> data_characteristic
1218 >> num_vals_per_node;
1221 for (
unsigned int i=0; i<5; i++)
1222 std::getline(in_stream, dummy);
1227 std::vector<Number> values;
1231 in_stream >> f_n_id;
1239 values.resize(num_vals_per_node);
1242 for (
unsigned int data_cnt=0; data_cnt<num_vals_per_node; data_cnt++)
1255 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 1256 values[data_cnt] =
Complex(std::atof(buf.c_str()), 0.);
1258 values[data_cnt] = std::atof(buf.c_str());
1264 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 1265 Real re_val, im_val;
1272 re_val = std::atof(buf.c_str());
1275 im_val = std::atof(buf.c_str());
1279 re_val = std::atof(buf.c_str());
1280 in_stream >> im_val;
1283 values[data_cnt] =
Complex(re_val,im_val);
1286 libmesh_error_msg(
"ERROR: Complex data only supported when libMesh is configured with --enable-complex!");
1291 libmesh_error_msg(
"ERROR: Data type not supported.");
1299 libmesh_error_msg(
"UNV node id " << f_n_id <<
" was not found.");
1313 const std::vector<Number> *
1321 return &(it->second);
void write_implementation(std::ostream &out_stream)
A 2D triangular element with 3 nodes.
virtual Node *& set_node(const unsigned int i)
A geometric point in (x,y,z) space associated with a DOF.
A 2D quadrilateral element with 4 nodes.
A 3D hexahedral element with 8 nodes.
std::map< dof_id_type, Node * > _unv_node_id_to_libmesh_node_ptr
static const std::string _elements_dataset_label
A 3D prismatic element with 6 nodes.
void nodes_in(std::istream &in_file)
void read_implementation(std::istream &in_stream)
A 3D hexahedral element with 20 nodes.
void read_dataset(std::string file_name)
The base class for all geometric element types.
std::map< Node *, std::vector< Number > > _node_data
A 2D quadrilateral element with 8 nodes.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
unsigned char max_elem_dimension_seen()
void nodes_out(std::ostream &out_file)
const BoundaryInfo & get_boundary_info() const
static const std::string _groups_dataset_label
void elements_out(std::ostream &out_file)
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
A 2D triangular element with 6 nodes.
virtual void write(const std::string &) override
const dof_id_type n_nodes
virtual void delete_elem(Elem *e)=0
virtual SimpleRange< element_iterator > element_ptr_range()=0
virtual Elem * add_elem(Elem *e)=0
virtual dof_id_type key(const unsigned int s) const =0
virtual SimpleRange< node_iterator > node_ptr_range()=0
SimpleRange< I > as_range(const std::pair< I, I > &p)
std::string & subdomain_name(subdomain_id_type id)
OStreamProxy err(std::cerr)
A 2D quadrilateral element with 9 nodes.
std::map< unsigned, unsigned > _unv_elem_id_to_libmesh_elem_id
std::string & sideset_name(boundary_id_type id)
virtual const Elem * elem_ptr(const dof_id_type i) const =0
std::complex< Real > Complex
bool need_D_to_e(std::string &number)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
subdomain_id_type subdomain_id() const
A 3D tetrahedral element with 10 nodes.
virtual unsigned short dim() const =0
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
A 1D geometric element with 2 nodes.
const std::vector< Number > * get_data(Node *node) const
A 3D tetrahedral element with 4 nodes.
static const std::string _nodes_dataset_label
OStreamProxy out(std::cout)
virtual void read(const std::string &) override
A geometric point in (x,y,z) space.
void elements_in(std::istream &in_file)
void groups_in(std::istream &in_file)