21 #include "libmesh/dof_map.h"
22 #include "libmesh/ensight_io.h"
23 #include "libmesh/equation_systems.h"
24 #include "libmesh/fe_interface.h"
25 #include "libmesh/libmesh.h"
26 #include "libmesh/system.h"
27 #include "libmesh/elem.h"
28 #include "libmesh/enum_elem_type.h"
29 #include "libmesh/int_range.h"
30 #include "libmesh/utility.h"
47 std::map<ElemType, std::string> ret;
56 ret[
TET10] =
"tetra10";
58 ret[
HEX20] =
"hexa20";
74 std::ostringstream tmp_file;
83 const std::string & vec_description,
84 const std::string & u,
85 const std::string & v)
93 vec.components.push_back(u);
94 vec.components.push_back(v);
102 const std::string & vec_name,
103 const std::string & u,
104 const std::string & v,
105 const std::string & w)
114 vec.components.push_back(u);
115 vec.components.push_back(v);
116 vec.components.push_back(w);
123 const std::string & scl_description,
124 const std::string & s)
172 std::ostringstream file;
176 << std::setprecision(0)
182 std::ofstream mesh_stream(file.str().c_str());
184 mesh_stream <<
"EnSight Gold Geometry File Format\n";
185 mesh_stream <<
"Generated by \n";
186 mesh_stream <<
"node id off\n";
187 mesh_stream <<
"element id given\n";
188 mesh_stream <<
"part\n";
189 mesh_stream << std::setw(10) << 1 <<
"\n";
190 mesh_stream <<
"uns-elements\n";
191 mesh_stream <<
"coordinates\n";
194 std::map<int, Point> mesh_nodes_map;
197 std::map<ElemType, std::vector<const Elem *>> ensight_parts_map;
204 ensight_parts_map[elem->type()].push_back(elem);
206 for (
const Node & node : elem->node_ref_range())
207 mesh_nodes_map[node.id()] = node;
211 mesh_stream << std::setw(10) << mesh_nodes_map.size() <<
"\n";
215 std::map <int, int> ensight_node_index;
216 for (
unsigned direction=0; direction<3; ++direction)
219 for (
const auto & pr : mesh_nodes_map)
221 mesh_stream << std::setw(12)
222 << std::setprecision(5)
224 << pr.second(direction)
226 ensight_node_index[pr.first] = i++;
231 for (
const auto & pr : ensight_parts_map)
237 mesh_stream <<
"\n" <<
name <<
"\n";
239 const std::vector<const Elem *> & elem_ref = pr.second;
242 mesh_stream << std::setw(10) << elem_ref.size() <<
"\n";
245 for (
const auto & elem : elem_ref)
246 mesh_stream << std::setw(10) << elem->id() <<
"\n";
251 for (
const auto & node : elem_ref[i]->node_ref_range())
254 if (pr.first ==
QUAD9 && i==4)
258 if (pr.first ==
HEX27 &&
259 (i==4 || i ==10 || i == 12 ||
260 i == 13 || i ==14 || i == 16 || i == 22))
263 mesh_stream << std::setw(10) << ensight_node_index[node.id()];
276 std::ostringstream case_file;
280 std::ofstream case_stream(case_file.str().c_str());
282 case_stream <<
"FORMAT\n";
283 case_stream <<
"type: ensight gold\n\n";
284 case_stream <<
"GEOMETRY\n";
289 case_stream <<
"\n\nVARIABLE\n";
293 for (
const auto & scalar : pr.second.EnsightScalars)
294 case_stream <<
"scalar per node: 1 "
295 << scalar.description <<
" "
298 for (
const auto & vec : pr.second.EnsightVectors)
299 case_stream <<
"vector per node: 1 "
300 << vec.description <<
" "
306 case_stream <<
"\n\nTIME\n";
307 case_stream <<
"time set: 1\n";
308 case_stream <<
"number of steps: " << std::setw(10) <<
_time_steps.size() <<
"\n";
309 case_stream <<
"filename start number: " << std::setw(10) << 0 <<
"\n";
310 case_stream <<
"filename increment: " << std::setw(10) << 1 <<
"\n";
311 case_stream <<
"time values:\n";
313 case_stream << std::setw(12) << std::setprecision(5) << std::scientific << time <<
"\n";
324 for (
const auto & scalar : pr.second.EnsightScalars)
328 for (
const auto & vec : pr.second.EnsightVectors)
337 const std::string & var_name)
340 std::ostringstream scl_file;
346 << std::setprecision(0)
352 std::ofstream scl_stream(scl_file.str().c_str());
353 scl_stream <<
"Per node scalar value\n";
354 scl_stream <<
"part\n";
355 scl_stream << std::setw(10) << 1 <<
"\n";
356 scl_stream <<
"coordinates\n";
364 std::vector<dof_id_type> dof_indices_scl;
369 std::map<int, Real> local_soln;
371 std::vector<Number> elem_soln;
372 std::vector<Number> nodal_soln;
381 elem_soln.resize(dof_indices_scl.size());
388 libmesh_assert_equal_to (nodal_soln.size(), elem->n_nodes());
390 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
391 libmesh_error_msg(
"Complex-valued Ensight output not yet supported");
394 for (
auto n : elem->node_index_range())
395 local_soln[elem->node_id(n)] =
libmesh_real(nodal_soln[n]);
398 for (
const auto & pr : local_soln)
399 scl_stream << std::setw(12)
400 << std::setprecision(5)
408 const std::vector<std::string> & vec,
409 const std::string & var_name)
412 std::ostringstream vec_file;
418 << std::setprecision(0)
424 std::ofstream vec_stream(vec_file.str().c_str());
425 vec_stream <<
"Per vector per value\n";
426 vec_stream <<
"part\n";
427 vec_stream << std::setw(10) << 1 <<
"\n";
428 vec_stream <<
"coordinates\n";
444 std::vector<dof_id_type> dof_indices_u;
445 std::vector<dof_id_type> dof_indices_v;
446 std::vector<dof_id_type> dof_indices_w;
451 std::map<int,std::vector<Real>> local_soln;
463 std::vector<Number> elem_soln_u;
464 std::vector<Number> elem_soln_v;
465 std::vector<Number> elem_soln_w;
467 std::vector<Number> nodal_soln_u;
468 std::vector<Number> nodal_soln_v;
469 std::vector<Number> nodal_soln_w;
471 elem_soln_u.resize(dof_indices_u.size());
472 elem_soln_v.resize(dof_indices_v.size());
474 elem_soln_w.resize(dof_indices_w.size());
489 libmesh_assert_equal_to (nodal_soln_u.size(), elem->n_nodes());
490 libmesh_assert_equal_to (nodal_soln_v.size(), elem->n_nodes());
492 #ifdef LIBMESH_ENABLE_COMPLEX
493 libmesh_error_msg(
"Complex-valued Ensight output not yet supported");
496 for (
const auto & n : elem->node_index_range())
498 std::vector<Real> node_vec(3);
504 local_soln[elem->node_id(n)] = node_vec;
508 for (
unsigned dir=0; dir<3; ++dir)
510 for (
const auto & pr : local_soln)
511 vec_stream << std::setw(12)
513 << std::setprecision(5)