libMesh
ensight_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 #ifndef LIBMESH_ENSIGHT_IO_H
20 #define LIBMESH_ENSIGHT_IO_H
21 
22 // libMesh includes
23 #include "libmesh/libmesh.h"
24 #include "libmesh/mesh_base.h"
25 #include "libmesh/mesh_output.h"
26 
27 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
28 namespace libMesh
29 {
30 enum ElemType : int;
31 }
32 #else
33 #include "libmesh/enum_elem_type.h"
34 #endif
35 
36 // C++ includes
37 #include <map>
38 #include <string>
39 #include <vector>
40 
41 namespace libMesh
42 {
43 
44 // Forward declarations
45 class EquationSystems;
46 
55 class EnsightIO : public MeshOutput<MeshBase>
56 {
57 public:
58 
62  EnsightIO (const std::string & filename,
63  const EquationSystems & eq);
64 
68  ~EnsightIO () {}
69 
77  void add_scalar (const std::string & system,
78  const std::string & scalar_description,
79  const std::string & s);
80 
88  void add_vector (const std::string & system,
89  const std::string & vec_description,
90  const std::string & u,
91  const std::string & v);
92 
100  void add_vector (const std::string & system,
101  const std::string & vec_description,
102  const std::string & u,
103  const std::string & v,
104  const std::string & w);
113  void write (Real time = 0);
114 
118  virtual void write (const std::string & name) override;
119 
120 private:
121  // Represents the vectors that are used by the EnsightIO
122  struct Vectors
123  {
124  std::string description;
125  std::vector<std::string> components;
126  };
127 
128  // Represents the scalars
129  struct Scalars
130  {
131  std::string scalar_name;
132  std::string description;
133  };
134 
135  // Store the variables of system
136  struct SystemVars
137  {
138  std::vector<Vectors> EnsightVectors;
139  std::vector<Scalars> EnsightScalars;
140  };
141 
142  // private methods
143  // write solution in ascii format file
144  void write_ascii (Real time = 0);
145  void write_scalar_ascii (const std::string & sys, const std::string & var);
146  void write_vector_ascii (const std::string & sys, const std::vector<std::string> & vec, const std::string & var_name);
147  void write_solution_ascii ();
148  void write_geometry_ascii ();
149  void write_case();
150 
151  // private Attributes
152  std::string _ensight_file_name;
153  std::vector<Real> _time_steps;
154 
155  // mapping from system names to variable names+descriptions
156  std::map <std::string, SystemVars> _system_vars_map;
157 
158  // Reference to the EquationSystems we were constructed with
160 
161  // static mapping between libmesh ElemTypes and Ensight element strings.
162  static std::map<ElemType, std::string> _element_map;
163 
164  // Static function used to build the _element_map.
165  static std::map<ElemType, std::string> build_element_map();
166 };
167 
168 
169 } // namespace libMesh
170 
171 
172 #endif // LIBMESH_ENSIGHT_IO_H
libMesh::EnsightIO::SystemVars::EnsightVectors
std::vector< Vectors > EnsightVectors
Definition: ensight_io.h:138
libMesh::EnsightIO::Scalars
Definition: ensight_io.h:129
libMesh::EnsightIO::Vectors::description
std::string description
Definition: ensight_io.h:124
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::SystemVars::EnsightScalars
std::vector< Scalars > EnsightScalars
Definition: ensight_io.h:139
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::EnsightIO
This class implements writing meshes and solutions in Ensight's Gold format.
Definition: ensight_io.h:55
libMesh::EnsightIO::Vectors
Definition: ensight_io.h:122
libMesh::EnsightIO::_element_map
static std::map< ElemType, std::string > _element_map
Definition: ensight_io.h:162
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::EnsightIO::_time_steps
std::vector< Real > _time_steps
Definition: ensight_io.h:153
libMesh::EnsightIO::add_scalar
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".
Definition: ensight_io.C:122
libMesh::EnsightIO::Scalars::scalar_name
std::string scalar_name
Definition: ensight_io.h:131
libMesh::EnsightIO::write_case
void write_case()
Definition: ensight_io.C:274
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::EnsightIO::Scalars::description
std::string description
Definition: ensight_io.h:132
libMesh::EnsightIO::add_vector
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.
Definition: ensight_io.C:82
libMesh::EnsightIO::EnsightIO
EnsightIO(const std::string &filename, const EquationSystems &eq)
Constructor.
Definition: ensight_io.C:65
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::EnsightIO::_system_vars_map
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:156
libMesh::MeshOutput
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
libMesh::EnsightIO::build_element_map
static std::map< ElemType, std::string > build_element_map()
Definition: ensight_io.C:45
libMesh::EnsightIO::SystemVars
Definition: ensight_io.h:136
libMesh::EnsightIO::write_solution_ascii
void write_solution_ascii()
Definition: ensight_io.C:320
libMesh::EnsightIO::~EnsightIO
~EnsightIO()
Empty destructor.
Definition: ensight_io.h:68
libMesh::EnsightIO::Vectors::components
std::vector< std::string > components
Definition: ensight_io.h:125
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::EnsightIO::write_scalar_ascii
void write_scalar_ascii(const std::string &sys, const std::string &var)
Definition: ensight_io.C:336
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
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::ElemType
ElemType
Defines an enum for geometric element types.
Definition: enum_elem_type.h:33