ensight_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
void write_solution_ascii()
Definition: ensight_io.C:321
void write_geometry_ascii()
Definition: ensight_io.C:169
std::string _ensight_file_name
Definition: ensight_io.h:152
Manages multiples systems of equations.
EnsightIO(const std::string &filename, const EquationSystems &eq)
Definition: ensight_io.C:64
static std::map< ElemType, std::string > build_element_map()
Definition: ensight_io.C:44
std::vector< std::string > components
Definition: ensight_io.h:125
std::vector< Scalars > EnsightScalars
Definition: ensight_io.h:139
PetscBool eq
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:156
void write_scalar_ascii(const std::string &sys, const std::string &var)
Definition: ensight_io.C:337
void add_vector(const std::string &system, const std::string &vec_description, const std::string &u, const std::string &v)
Definition: ensight_io.C:81
static std::map< ElemType, std::string > _element_map
Definition: ensight_io.h:162
void write_vector_ascii(const std::string &sys, const std::vector< std::string > &vec, const std::string &var_name)
Definition: ensight_io.C:408
void write(Real time=0)
Definition: ensight_io.C:151
const EquationSystems & _equation_systems
Definition: ensight_io.h:159
void add_scalar(const std::string &system, const std::string &scalar_description, const std::string &s)
Definition: ensight_io.C:121
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Real > _time_steps
Definition: ensight_io.h:153
void write_ascii(Real time=0)
Definition: ensight_io.C:159
std::vector< Vectors > EnsightVectors
Definition: ensight_io.h:138