libMesh
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
libMesh::EnsightIO Class Reference

This class implements writing meshes and solutions in Ensight's Gold format. More...

#include <ensight_io.h>

Inheritance diagram for libMesh::EnsightIO:
[legend]

Classes

struct  Scalars
 
struct  SystemVars
 
struct  Vectors
 

Public Member Functions

 EnsightIO (const std::string &filename, const EquationSystems &eq)
 Constructor. More...
 
 ~EnsightIO ()
 Empty destructor. More...
 
void add_scalar (const std::string &system, const std::string &scalar_description, const std::string &s)
 Tell the EnsightIO interface to output the finite element (not SCALAR) variable named "s". More...
 
void add_vector (const std::string &system, const std::string &vec_description, const std::string &u, const std::string &v)
 Tell the EnsightIO interface that the variables (u,v) constitute a vector. More...
 
void add_vector (const std::string &system, const std::string &vec_description, const std::string &u, const std::string &v, const std::string &w)
 Tell the EnsightIO interface that the variables (u, v, w) constitute a vector. More...
 
void write (Real time=0)
 Calls write_ascii() and write_case(). More...
 
virtual void write (const std::string &name) override
 Calls this->write(0);. More...
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object. More...
 
virtual void write_discontinuous_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object. More...
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided. More...
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 This method may be overridden by "parallel" output formats for writing nodal data. More...
 
virtual void write_nodal_data (const std::string &, const EquationSystems &, const std::set< std::string > *)
 This method should be overridden by "parallel" output formats for writing nodal data. More...
 
virtual void write_nodal_data_discontinuous (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided. More...
 
unsigned intascii_precision ()
 Return/set the precision to use when writing ASCII files. More...
 

Protected Member Functions

const MeshBasemesh () const
 

Protected Attributes

const bool _is_parallel_format
 Flag specifying whether this format is parallel-capable. More...
 
const bool _serial_only_needed_on_proc_0
 Flag specifying whether this format can be written by only serializing the mesh to processor zero. More...
 

Private Member Functions

void write_ascii (Real time=0)
 
void write_scalar_ascii (const std::string &sys, const std::string &var)
 
void write_vector_ascii (const std::string &sys, const std::vector< std::string > &vec, const std::string &var_name)
 
void write_solution_ascii ()
 
void write_geometry_ascii ()
 
void write_case ()
 

Static Private Member Functions

static std::map< ElemType, std::string > build_element_map ()
 

Private Attributes

std::string _ensight_file_name
 
std::vector< Real_time_steps
 
std::map< std::string, SystemVars_system_vars_map
 
const EquationSystems_equation_systems
 
const MeshBase *const _obj
 A pointer to a constant object. More...
 
unsigned int _ascii_precision
 Precision to use when writing ASCII files. More...
 

Static Private Attributes

static std::map< ElemType, std::string > _element_map = EnsightIO::build_element_map()
 

Detailed Description

This class implements writing meshes and solutions in Ensight's Gold format.

Author
Camata
Date
2009
Author
J. W. Peterson (refactoring and iostreams implementation)
Date
2016

Definition at line 55 of file ensight_io.h.

Constructor & Destructor Documentation

◆ EnsightIO()

libMesh::EnsightIO::EnsightIO ( const std::string &  filename,
const EquationSystems eq 
)

Constructor.

Definition at line 65 of file ensight_io.C.

66  :
67  MeshOutput<MeshBase> (eq.get_mesh()),
69 {
71  _ensight_file_name = filename;
72  else
73  {
74  std::ostringstream tmp_file;
75  tmp_file << filename << "_rank" << _equation_systems.processor_id();
76  _ensight_file_name = tmp_file.str();
77  }
78 }

References _ensight_file_name, _equation_systems, libMesh::ParallelObject::n_processors(), and libMesh::ParallelObject::processor_id().

◆ ~EnsightIO()

libMesh::EnsightIO::~EnsightIO ( )
inline

Empty destructor.

Definition at line 68 of file ensight_io.h.

68 {}

Member Function Documentation

◆ add_scalar()

void libMesh::EnsightIO::add_scalar ( const std::string &  system,
const std::string &  scalar_description,
const std::string &  s 
)

Tell the EnsightIO interface to output the finite element (not SCALAR) variable named "s".

Note
You must call add_scalar() or add_vector() (see below) at least once, otherwise only the Mesh will be written out.

Definition at line 122 of file ensight_io.C.

125 {
127  libmesh_assert(_equation_systems.get_system(system_name).has_variable(s));
128 
129  Scalars scl;
130  scl.description = scl_description;
131  scl.scalar_name = s;
132 
133  _system_vars_map[system_name].EnsightScalars.push_back(scl);
134 }

References _equation_systems, _system_vars_map, libMesh::EnsightIO::Scalars::description, libMesh::EquationSystems::get_system(), libMesh::EquationSystems::has_system(), and libMesh::libmesh_assert().

◆ add_vector() [1/2]

void libMesh::EnsightIO::add_vector ( const std::string &  system,
const std::string &  vec_description,
const std::string &  u,
const std::string &  v 
)

Tell the EnsightIO interface that the variables (u,v) constitute a vector.

Note
u and v must have the same FEType, and be defined in the same system.

Definition at line 82 of file ensight_io.C.

86 {
88  libmesh_assert (_equation_systems.get_system(system_name).has_variable(u));
89  libmesh_assert (_equation_systems.get_system(system_name).has_variable(v));
90 
91  Vectors vec;
92  vec.description = vec_description;
93  vec.components.push_back(u);
94  vec.components.push_back(v);
95 
96  _system_vars_map[system_name].EnsightVectors.push_back(vec);
97 }

References _equation_systems, _system_vars_map, libMesh::EnsightIO::Vectors::description, libMesh::EquationSystems::get_system(), libMesh::EquationSystems::has_system(), and libMesh::libmesh_assert().

◆ add_vector() [2/2]

void libMesh::EnsightIO::add_vector ( const std::string &  system,
const std::string &  vec_description,
const std::string &  u,
const std::string &  v,
const std::string &  w 
)

Tell the EnsightIO interface that the variables (u, v, w) constitute a vector.

Note
Requires a 3D mesh, u, v, and w must have the same FEType, and must be defined in the same system.

Definition at line 101 of file ensight_io.C.

106 {
108  libmesh_assert(_equation_systems.get_system(system_name).has_variable(u));
109  libmesh_assert(_equation_systems.get_system(system_name).has_variable(v));
110  libmesh_assert(_equation_systems.get_system(system_name).has_variable(w));
111 
112  Vectors vec;
113  vec.description = vec_name;
114  vec.components.push_back(u);
115  vec.components.push_back(v);
116  vec.components.push_back(w);
117  _system_vars_map[system_name].EnsightVectors.push_back(vec);
118 }

References _equation_systems, _system_vars_map, libMesh::EnsightIO::Vectors::description, libMesh::EquationSystems::get_system(), libMesh::EquationSystems::has_system(), and libMesh::libmesh_assert().

◆ ascii_precision()

unsigned int & libMesh::MeshOutput< MeshBase >::ascii_precision ( )
inlineinherited

Return/set the precision to use when writing ASCII files.

By default we use numeric_limits<Real>::max_digits10, which should be enough to write out to ASCII and get the exact same Real back when reading in.

Definition at line 257 of file mesh_output.h.

258 {
259  return _ascii_precision;
260 }

◆ build_element_map()

std::map< ElemType, std::string > libMesh::EnsightIO::build_element_map ( )
staticprivate

Definition at line 45 of file ensight_io.C.

46 {
47  std::map<ElemType, std::string> ret;
48  ret[EDGE2] = "bar2";
49  ret[EDGE3] = "bar3";
50  ret[QUAD4] = "quad4";
51  ret[QUAD8] = "quad8";
52  // ret[QUAD9] = "quad9"; // not supported
53  ret[TRI3] = "tria3";
54  ret[TRI6] = "tria6";
55  ret[TET4] = "tetra4";
56  ret[TET10] = "tetra10";
57  ret[HEX8] = "hexa8";
58  ret[HEX20] = "hexa20";
59  // ret[HEX27] = "HEX27"; // not supported
60  ret[PYRAMID5] = "pyramid5";
61  return ret;
62 }

References libMesh::EDGE2, libMesh::EDGE3, libMesh::HEX20, libMesh::HEX8, libMesh::PYRAMID5, libMesh::QUAD4, libMesh::QUAD8, libMesh::TET10, libMesh::TET4, libMesh::TRI3, and libMesh::TRI6.

◆ mesh()

const MeshBase & libMesh::MeshOutput< MeshBase >::mesh ( ) const
inlineprotectedinherited
Returns
The object as a read-only reference.

Definition at line 247 of file mesh_output.h.

248 {
250  return *_obj;
251 }

◆ write() [1/2]

void libMesh::EnsightIO::write ( const std::string &  name)
overridevirtual

Calls this->write(0);.

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 140 of file ensight_io.C.

141 {
142  // We may need to gather a DistributedMesh to output it, making that
143  // const qualifier in our constructor a dirty lie
144  MeshSerializer serialize(const_cast<MeshBase &>(this->mesh()), !_is_parallel_format);
145 
147  this->write();
148 }

References _ensight_file_name, libMesh::MeshOutput< MeshBase >::_is_parallel_format, libMesh::MeshOutput< MeshBase >::mesh(), libMesh::Quality::name(), and write().

◆ write() [2/2]

void libMesh::EnsightIO::write ( Real  time = 0)

Calls write_ascii() and write_case().

Writes case, mesh, and solution files named: name.case (contains a description of other files) name.geo000 (mesh) name_{varname}.scl000 (one file per scalar variable) name_{vecname}.vec000 (one file per vector variable)

Definition at line 152 of file ensight_io.C.

153 {
154  this->write_ascii(time);
155  this->write_case();
156 }

References write_ascii(), and write_case().

Referenced by write().

◆ write_ascii()

void libMesh::EnsightIO::write_ascii ( Real  time = 0)
private

Definition at line 160 of file ensight_io.C.

161 {
162  _time_steps.push_back(time);
163 
164  this->write_geometry_ascii();
165  this->write_solution_ascii();
166 }

References _time_steps, write_geometry_ascii(), and write_solution_ascii().

Referenced by write().

◆ write_case()

void libMesh::EnsightIO::write_case ( )
private

Definition at line 274 of file ensight_io.C.

275 {
276  std::ostringstream case_file;
277  case_file << _ensight_file_name << ".case";
278 
279  // Open a stream for writing the case file.
280  std::ofstream case_stream(case_file.str().c_str());
281 
282  case_stream << "FORMAT\n";
283  case_stream << "type: ensight gold\n\n";
284  case_stream << "GEOMETRY\n";
285  case_stream << "model: 1 " << _ensight_file_name << ".geo" << "***\n";
286 
287  // Write Variable per node section
288  if (!_system_vars_map.empty())
289  case_stream << "\n\nVARIABLE\n";
290 
291  for (const auto & pr : _system_vars_map)
292  {
293  for (const auto & scalar : pr.second.EnsightScalars)
294  case_stream << "scalar per node: 1 "
295  << scalar.description << " "
296  << _ensight_file_name << "_" << scalar.scalar_name << ".scl***\n";
297 
298  for (const auto & vec : pr.second.EnsightVectors)
299  case_stream << "vector per node: 1 "
300  << vec.description << " "
301  << _ensight_file_name << "_" << vec.description << ".vec***\n";
302 
303  // Write time step section
304  if (_time_steps.size() != 0)
305  {
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";
312  for (const auto & time : _time_steps)
313  case_stream << std::setw(12) << std::setprecision(5) << std::scientific << time << "\n";
314  }
315  }
316 }

References _ensight_file_name, _system_vars_map, and _time_steps.

Referenced by write().

◆ write_discontinuous_equation_systems()

void libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object.

Definition at line 87 of file mesh_output.C.

90 {
91  LOG_SCOPE("write_discontinuous_equation_systems()", "MeshOutput");
92 
93  // We may need to gather and/or renumber a DistributedMesh to output
94  // it, making that const qualifier in our constructor a dirty lie
95  MT & my_mesh = const_cast<MT &>(*_obj);
96 
97  // If we're asked to write data that's associated with a different
98  // mesh, output files full of garbage are the result.
99  libmesh_assert_equal_to(&es.get_mesh(), _obj);
100 
101  // A non-renumbered mesh may not have a contiguous numbering, and
102  // that needs to be fixed before we can build a solution vector.
103  if (my_mesh.max_elem_id() != my_mesh.n_elem() ||
104  my_mesh.max_node_id() != my_mesh.n_nodes())
105  {
106  // If we were allowed to renumber then we should have already
107  // been properly renumbered...
108  libmesh_assert(!my_mesh.allow_renumbering());
109 
110  libmesh_do_once(libMesh::out <<
111  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
112  << std::endl;);
113 
114  my_mesh.allow_renumbering(true);
115 
116  my_mesh.renumber_nodes_and_elements();
117 
118  // Not sure what good going back to false will do here, the
119  // renumbering horses have already left the barn...
120  my_mesh.allow_renumbering(false);
121  }
122 
123  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
124 
125  // Build the list of variable names that will be written.
126  std::vector<std::string> names;
127  es.build_variable_names (names, nullptr, system_names);
128 
129  if (!_is_parallel_format)
130  {
131  // Build the nodal solution values & get the variable
132  // names from the EquationSystems object
133  std::vector<Number> soln;
134  es.build_discontinuous_solution_vector (soln, system_names);
135 
136  this->write_nodal_data_discontinuous (fname, soln, names);
137  }
138  else // _is_parallel_format
139  {
140  libmesh_not_implemented();
141  }
142 }

◆ write_equation_systems()

void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.

Reimplemented in libMesh::NameBasedIO.

Definition at line 31 of file mesh_output.C.

34 {
35  LOG_SCOPE("write_equation_systems()", "MeshOutput");
36 
37  // We may need to gather and/or renumber a DistributedMesh to output
38  // it, making that const qualifier in our constructor a dirty lie
39  MT & my_mesh = const_cast<MT &>(*_obj);
40 
41  // If we're asked to write data that's associated with a different
42  // mesh, output files full of garbage are the result.
43  libmesh_assert_equal_to(&es.get_mesh(), _obj);
44 
45  // A non-renumbered mesh may not have a contiguous numbering, and
46  // that needs to be fixed before we can build a solution vector.
47  if (my_mesh.max_elem_id() != my_mesh.n_elem() ||
48  my_mesh.max_node_id() != my_mesh.n_nodes())
49  {
50  // If we were allowed to renumber then we should have already
51  // been properly renumbered...
52  libmesh_assert(!my_mesh.allow_renumbering());
53 
54  libmesh_do_once(libMesh::out <<
55  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
56  << std::endl;);
57 
58  my_mesh.allow_renumbering(true);
59 
60  my_mesh.renumber_nodes_and_elements();
61 
62  // Not sure what good going back to false will do here, the
63  // renumbering horses have already left the barn...
64  my_mesh.allow_renumbering(false);
65  }
66 
68  {
69  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
70 
71  // Build the list of variable names that will be written.
72  std::vector<std::string> names;
73  es.build_variable_names (names, nullptr, system_names);
74 
75  // Build the nodal solution values & get the variable
76  // names from the EquationSystems object
77  std::vector<Number> soln;
78  es.build_solution_vector (soln, system_names);
79 
80  this->write_nodal_data (fname, soln, names);
81  }
82  else // _is_parallel_format
83  this->write_nodal_data (fname, es, system_names);
84 }

◆ write_geometry_ascii()

void libMesh::EnsightIO::write_geometry_ascii ( )
private

Definition at line 170 of file ensight_io.C.

171 {
172  std::ostringstream file;
173  file << _ensight_file_name
174  << ".geo"
175  << std::setw(3)
176  << std::setprecision(0)
177  << std::setfill('0')
178  << std::right
179  << _time_steps.size()-1;
180 
181  // Open a stream to write the mesh
182  std::ofstream mesh_stream(file.str().c_str());
183 
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";
192 
193  // mapping between nodal index and your coordinates
194  std::map<int, Point> mesh_nodes_map;
195 
196  // Map for grouping elements of the same type
197  std::map<ElemType, std::vector<const Elem *>> ensight_parts_map;
198 
199  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
200 
201  // Construct the various required maps
202  for (const auto & elem : the_mesh.active_local_element_ptr_range())
203  {
204  ensight_parts_map[elem->type()].push_back(elem);
205 
206  for (const Node & node : elem->node_ref_range())
207  mesh_nodes_map[node.id()] = node;
208  }
209 
210  // Write number of local points
211  mesh_stream << std::setw(10) << mesh_nodes_map.size() << "\n";
212 
213  // write x, y, and z node positions, build mapping between
214  // ensight and libmesh node numbers.
215  std::map <int, int> ensight_node_index;
216  for (unsigned direction=0; direction<3; ++direction)
217  {
218  int i = 1;
219  for (const auto & pr : mesh_nodes_map)
220  {
221  mesh_stream << std::setw(12)
222  << std::setprecision(5)
223  << std::scientific
224  << pr.second(direction)
225  << "\n";
226  ensight_node_index[pr.first] = i++;
227  }
228  }
229 
230  // Write parts
231  for (const auto & pr : ensight_parts_map)
232  {
233  // Look up this ElemType in the map, error if not present.
234  std::string name = libmesh_map_find(_element_map, pr.first);
235 
236  // Write element type
237  mesh_stream << "\n" << name << "\n";
238 
239  const std::vector<const Elem *> & elem_ref = pr.second;
240 
241  // Write number of element
242  mesh_stream << std::setw(10) << elem_ref.size() << "\n";
243 
244  // Write element id
245  for (const auto & elem : elem_ref)
246  mesh_stream << std::setw(10) << elem->id() << "\n";
247 
248  // Write connectivity
249  for (auto i : index_range(elem_ref))
250  {
251  for (const auto & node : elem_ref[i]->node_ref_range())
252  {
253  // tests!
254  if (pr.first == QUAD9 && i==4)
255  continue;
256 
257  // tests!
258  if (pr.first == HEX27 &&
259  (i==4 || i ==10 || i == 12 ||
260  i == 13 || i ==14 || i == 16 || i == 22))
261  continue;
262 
263  mesh_stream << std::setw(10) << ensight_node_index[node.id()];
264  }
265  mesh_stream << "\n";
266  }
267  }
268 }

References _element_map, _ensight_file_name, _time_steps, libMesh::MeshBase::active_local_element_ptr_range(), libMesh::HEX27, libMesh::index_range(), libMesh::MeshOutput< MT >::mesh(), libMesh::Quality::name(), and libMesh::QUAD9.

Referenced by write_ascii().

◆ write_nodal_data() [1/3]

void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names 
)
virtualinherited

This method should be overridden by "parallel" output formats for writing nodal data.

Instead of getting a localized copy of the nodal solution vector, it directly uses EquationSystems current_local_solution vectors to look up nodal values.

If not implemented, reorders the solutions into a nodal-only NumericVector and calls the above version of this function.

Reimplemented in libMesh::Nemesis_IO.

Definition at line 158 of file mesh_output.C.

161 {
162  std::vector<std::string> names;
163  es.build_variable_names (names, nullptr, system_names);
164 
165  std::unique_ptr<NumericVector<Number>> parallel_soln =
166  es.build_parallel_solution_vector(system_names);
167 
168  this->write_nodal_data (fname, *parallel_soln, names);
169 }

◆ write_nodal_data() [2/3]

void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  fname,
const NumericVector< Number > &  parallel_soln,
const std::vector< std::string > &  names 
)
virtualinherited

This method may be overridden by "parallel" output formats for writing nodal data.

Instead of getting a localized copy of the nodal solution vector, it is passed a NumericVector of type=PARALLEL which is in node-major order i.e. (u0,v0,w0, u1,v1,w1, u2,v2,w2, u3,v3,w3, ...) and contains n_nodes*n_vars total entries. Then, it is up to the individual I/O class to extract the required solution values from this vector and write them in parallel.

If not implemented, localizes the parallel vector into a std::vector and calls the other version of this function.

Reimplemented in libMesh::Nemesis_IO.

Definition at line 145 of file mesh_output.C.

148 {
149  // This is the fallback implementation for parallel I/O formats that
150  // do not yet implement proper writing in parallel, and instead rely
151  // on the full solution vector being available on all processors.
152  std::vector<Number> soln;
153  parallel_soln.localize(soln);
154  this->write_nodal_data(fname, soln, names);
155 }

◆ write_nodal_data() [3/3]

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtualinherited

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.

Reimplemented in libMesh::Nemesis_IO, libMesh::UCDIO, libMesh::ExodusII_IO, libMesh::GmshIO, libMesh::NameBasedIO, libMesh::GMVIO, libMesh::VTKIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.

Definition at line 105 of file mesh_output.h.

108  { libmesh_not_implemented(); }

◆ write_nodal_data_discontinuous()

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data_discontinuous ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtualinherited

This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided.

Reimplemented in libMesh::ExodusII_IO.

Definition at line 114 of file mesh_output.h.

117  { libmesh_not_implemented(); }

◆ write_scalar_ascii()

void libMesh::EnsightIO::write_scalar_ascii ( const std::string &  sys,
const std::string &  var 
)
private

Definition at line 336 of file ensight_io.C.

338 {
339  // Construct scalar variable filename
340  std::ostringstream scl_file;
341  scl_file << _ensight_file_name
342  << "_"
343  << var_name
344  << ".scl"
345  << std::setw(3)
346  << std::setprecision(0)
347  << std::setfill('0')
348  << std::right
349  << _time_steps.size()-1;
350 
351  // Open a stream and start writing scalar variable info.
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";
357 
358  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
359  const unsigned int dim = the_mesh.mesh_dimension();
360  const System & system = _equation_systems.get_system(sys);
361  const DofMap & dof_map = system.get_dof_map();
362  int var = system.variable_number(var_name);
363 
364  std::vector<dof_id_type> dof_indices_scl;
365 
366  // Map from node id -> solution value. We end up just writing this
367  // map out in order, not sure what would happen if there were holes
368  // in the numbering...
369  std::map<int, Real> local_soln;
370 
371  std::vector<Number> elem_soln;
372  std::vector<Number> nodal_soln;
373 
374  // Loop over active local elements, construct the nodal solution, and write it to file.
375  for (const auto & elem : the_mesh.active_local_element_ptr_range())
376  {
377  const FEType & fe_type = system.variable_type(var);
378 
379  dof_map.dof_indices (elem, dof_indices_scl, var);
380 
381  elem_soln.resize(dof_indices_scl.size());
382 
383  for (auto i : index_range(dof_indices_scl))
384  elem_soln[i] = system.current_solution(dof_indices_scl[i]);
385 
386  FEInterface::nodal_soln (dim, fe_type, elem, elem_soln, nodal_soln);
387 
388  libmesh_assert_equal_to (nodal_soln.size(), elem->n_nodes());
389 
390 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
391  libmesh_error_msg("Complex-valued Ensight output not yet supported");
392 #endif
393 
394  for (auto n : elem->node_index_range())
395  local_soln[elem->node_id(n)] = libmesh_real(nodal_soln[n]);
396  }
397 
398  for (const auto & pr : local_soln)
399  scl_stream << std::setw(12)
400  << std::setprecision(5)
401  << std::scientific
402  << pr.second
403  << "\n";
404 }

References _ensight_file_name, _equation_systems, _time_steps, libMesh::MeshBase::active_local_element_ptr_range(), libMesh::System::current_solution(), dim, libMesh::DofMap::dof_indices(), libMesh::System::get_dof_map(), libMesh::EquationSystems::get_system(), libMesh::index_range(), libMesh::libmesh_real(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::FEInterface::nodal_soln(), libMesh::System::variable_number(), and libMesh::System::variable_type().

Referenced by write_solution_ascii().

◆ write_solution_ascii()

void libMesh::EnsightIO::write_solution_ascii ( )
private

Definition at line 320 of file ensight_io.C.

321 {
322  for (const auto & pr : _system_vars_map)
323  {
324  for (const auto & scalar : pr.second.EnsightScalars)
325  this->write_scalar_ascii(pr.first,
326  scalar.scalar_name);
327 
328  for (const auto & vec : pr.second.EnsightVectors)
329  this->write_vector_ascii(pr.first,
330  vec.components,
331  vec.description);
332  }
333 }

References _system_vars_map, write_scalar_ascii(), and write_vector_ascii().

Referenced by write_ascii().

◆ write_vector_ascii()

void libMesh::EnsightIO::write_vector_ascii ( const std::string &  sys,
const std::vector< std::string > &  vec,
const std::string &  var_name 
)
private

Definition at line 407 of file ensight_io.C.

410 {
411  // Construct vector variable filename
412  std::ostringstream vec_file;
413  vec_file << _ensight_file_name
414  << "_"
415  << var_name
416  << ".vec"
417  << std::setw(3)
418  << std::setprecision(0)
419  << std::setfill('0')
420  << std::right
421  << _time_steps.size()-1;
422 
423  // Open a stream and start writing vector variable info.
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";
429 
430  // Get a constant reference to the mesh object.
431  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
432 
433  // The dimension that we are running
434  const unsigned int dim = the_mesh.mesh_dimension();
435 
436  const System & system = _equation_systems.get_system(sys);
437 
438  const DofMap & dof_map = system.get_dof_map();
439 
440  const unsigned int u_var = system.variable_number(vec[0]);
441  const unsigned int v_var = system.variable_number(vec[1]);
442  const unsigned int w_var = (dim==3) ? system.variable_number(vec[2]) : 0;
443 
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;
447 
448  // Map from node id -> solution value. We end up just writing this
449  // map out in order, not sure what would happen if there were holes
450  // in the numbering...
451  std::map<int,std::vector<Real>> local_soln;
452 
453  // Now we will loop over all the elements in the mesh.
454  for (const auto & elem : the_mesh.active_local_element_ptr_range())
455  {
456  const FEType & fe_type = system.variable_type(u_var);
457 
458  dof_map.dof_indices (elem, dof_indices_u, u_var);
459  dof_map.dof_indices (elem, dof_indices_v, v_var);
460  if (dim==3)
461  dof_map.dof_indices (elem, dof_indices_w, w_var);
462 
463  std::vector<Number> elem_soln_u;
464  std::vector<Number> elem_soln_v;
465  std::vector<Number> elem_soln_w;
466 
467  std::vector<Number> nodal_soln_u;
468  std::vector<Number> nodal_soln_v;
469  std::vector<Number> nodal_soln_w;
470 
471  elem_soln_u.resize(dof_indices_u.size());
472  elem_soln_v.resize(dof_indices_v.size());
473  if (dim == 3)
474  elem_soln_w.resize(dof_indices_w.size());
475 
476  for (auto i : index_range(dof_indices_u))
477  {
478  elem_soln_u[i] = system.current_solution(dof_indices_u[i]);
479  elem_soln_v[i] = system.current_solution(dof_indices_v[i]);
480  if (dim==3)
481  elem_soln_w[i] = system.current_solution(dof_indices_w[i]);
482  }
483 
484  FEInterface::nodal_soln (dim, fe_type, elem, elem_soln_u, nodal_soln_u);
485  FEInterface::nodal_soln (dim, fe_type, elem, elem_soln_v, nodal_soln_v);
486  if (dim == 3)
487  FEInterface::nodal_soln (dim, fe_type, elem, elem_soln_w, nodal_soln_w);
488 
489  libmesh_assert_equal_to (nodal_soln_u.size(), elem->n_nodes());
490  libmesh_assert_equal_to (nodal_soln_v.size(), elem->n_nodes());
491 
492 #ifdef LIBMESH_ENABLE_COMPLEX
493  libmesh_error_msg("Complex-valued Ensight output not yet supported");
494 #endif
495 
496  for (const auto & n : elem->node_index_range())
497  {
498  std::vector<Real> node_vec(3);
499  node_vec[0] = libmesh_real(nodal_soln_u[n]);
500  node_vec[1] = libmesh_real(nodal_soln_v[n]);
501  node_vec[2] = 0.0;
502  if (dim==3)
503  node_vec[2] = libmesh_real(nodal_soln_w[n]);
504  local_soln[elem->node_id(n)] = node_vec;
505  }
506  }
507 
508  for (unsigned dir=0; dir<3; ++dir)
509  {
510  for (const auto & pr : local_soln)
511  vec_stream << std::setw(12)
512  << std::scientific
513  << std::setprecision(5)
514  << pr.second[dir]
515  << "\n";
516  }
517 }

References _ensight_file_name, _equation_systems, _time_steps, libMesh::MeshBase::active_local_element_ptr_range(), libMesh::System::current_solution(), dim, libMesh::DofMap::dof_indices(), libMesh::System::get_dof_map(), libMesh::EquationSystems::get_system(), libMesh::index_range(), libMesh::libmesh_real(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::FEInterface::nodal_soln(), libMesh::System::variable_number(), and libMesh::System::variable_type().

Referenced by write_solution_ascii().

Member Data Documentation

◆ _ascii_precision

unsigned int libMesh::MeshOutput< MeshBase >::_ascii_precision
privateinherited

Precision to use when writing ASCII files.

Definition at line 195 of file mesh_output.h.

◆ _element_map

std::map< ElemType, std::string > libMesh::EnsightIO::_element_map = EnsightIO::build_element_map()
staticprivate

Definition at line 162 of file ensight_io.h.

Referenced by write_geometry_ascii().

◆ _ensight_file_name

std::string libMesh::EnsightIO::_ensight_file_name
private

◆ _equation_systems

const EquationSystems& libMesh::EnsightIO::_equation_systems
private

◆ _is_parallel_format

const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format
protectedinherited

Flag specifying whether this format is parallel-capable.

If this is false (default) I/O is only permitted when the mesh has been serialized.

Definition at line 172 of file mesh_output.h.

◆ _obj

const MeshBase * const libMesh::MeshOutput< MeshBase >::_obj
privateinherited

A pointer to a constant object.

This allows us to write the object to file.

Definition at line 190 of file mesh_output.h.

◆ _serial_only_needed_on_proc_0

const bool libMesh::MeshOutput< MeshBase >::_serial_only_needed_on_proc_0
protectedinherited

Flag specifying whether this format can be written by only serializing the mesh to processor zero.

If this is false (default) the mesh will be serialized to all processors

Definition at line 181 of file mesh_output.h.

◆ _system_vars_map

std::map<std::string, SystemVars> libMesh::EnsightIO::_system_vars_map
private

Definition at line 156 of file ensight_io.h.

Referenced by add_scalar(), add_vector(), write_case(), and write_solution_ascii().

◆ _time_steps

std::vector<Real> libMesh::EnsightIO::_time_steps
private

The documentation for this class was generated from the following files:
libMesh::HEX20
Definition: enum_elem_type.h:48
libMesh::MeshOutput< MeshBase >::_serial_only_needed_on_proc_0
const bool _serial_only_needed_on_proc_0
Flag specifying whether this format can be written by only serializing the mesh to processor zero.
Definition: mesh_output.h:181
eq
PetscBool eq
Definition: petscdmlibmeshimpl.C:1030
libMesh::EnsightIO::_equation_systems
const EquationSystems & _equation_systems
Definition: ensight_io.h:159
libMesh::EnsightIO::_ensight_file_name
std::string _ensight_file_name
Definition: ensight_io.h:152
libMesh::EnsightIO::write_vector_ascii
void write_vector_ascii(const std::string &sys, const std::vector< std::string > &vec, const std::string &var_name)
Definition: ensight_io.C:407
libMesh::HEX8
Definition: enum_elem_type.h:47
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::EnsightIO::_element_map
static std::map< ElemType, std::string > _element_map
Definition: ensight_io.h:162
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
libMesh::TET10
Definition: enum_elem_type.h:46
libMesh::EquationSystems::get_system
const T_sys & get_system(const std::string &name) const
Definition: equation_systems.h:757
libMesh::EnsightIO::_time_steps
std::vector< Real > _time_steps
Definition: ensight_io.h:153
libMesh::EquationSystems::has_system
bool has_system(const std::string &name) const
Definition: equation_systems.h:694
dim
unsigned int dim
Definition: adaptivity_ex3.C:113
libMesh::FEInterface::nodal_soln
static void nodal_soln(const unsigned int dim, const FEType &fe_t, const Elem *elem, const std::vector< Number > &elem_soln, std::vector< Number > &nodal_soln)
Build the nodal soln from the element soln.
Definition: fe_interface.C:580
libMesh::EnsightIO::write_case
void write_case()
Definition: ensight_io.C:274
libMesh::TET4
Definition: enum_elem_type.h:45
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::HEX27
Definition: enum_elem_type.h:49
libMesh::NumericVector::localize
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.
libMesh::ParallelObject::n_processors
processor_id_type n_processors() const
Definition: parallel_object.h:100
libMesh::EnsightIO::write
void write(Real time=0)
Calls write_ascii() and write_case().
Definition: ensight_io.C:152
libMesh::EnsightIO::write_geometry_ascii
void write_geometry_ascii()
Definition: ensight_io.C:170
libMesh::MeshOutput< MeshBase >::_is_parallel_format
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition: mesh_output.h:172
libMesh::ParallelObject::processor_id
processor_id_type processor_id() const
Definition: parallel_object.h:106
libMesh::QUAD4
Definition: enum_elem_type.h:41
libMesh::TRI3
Definition: enum_elem_type.h:39
libMesh::EnsightIO::_system_vars_map
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:156
libMesh::TRI6
Definition: enum_elem_type.h:40
libMesh::MeshOutput< MeshBase >::write_nodal_data
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: mesh_output.h:105
libMesh::MeshOutput< MeshBase >::mesh
const MeshBase & mesh() const
Definition: mesh_output.h:247
libMesh::EnsightIO::write_solution_ascii
void write_solution_ascii()
Definition: ensight_io.C:320
libMesh::PYRAMID5
Definition: enum_elem_type.h:53
libMesh::EDGE3
Definition: enum_elem_type.h:36
libMesh::MeshOutput< MeshBase >::write_nodal_data_discontinuous
virtual void write_nodal_data_discontinuous(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
This method implements writing a mesh with discontinuous data to a specified file where the nodal dat...
Definition: mesh_output.h:114
libMesh::MeshOutput< MeshBase >::_obj
const MeshBase *const _obj
A pointer to a constant object.
Definition: mesh_output.h:190
libMesh::QUAD9
Definition: enum_elem_type.h:43
libMesh::out
OStreamProxy out
libMesh::EnsightIO::write_scalar_ascii
void write_scalar_ascii(const std::string &sys, const std::string &var)
Definition: ensight_io.C:336
libMesh::MeshOutput< MeshBase >::_ascii_precision
unsigned int _ascii_precision
Precision to use when writing ASCII files.
Definition: mesh_output.h:195
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libMesh::EnsightIO::write_ascii
void write_ascii(Real time=0)
Definition: ensight_io.C:160
libMesh::EDGE2
Definition: enum_elem_type.h:35
libMesh::QUAD8
Definition: enum_elem_type.h:42