Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 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 : // C++ includes 28 : #include <map> 29 : #include <string> 30 : #include <vector> 31 : 32 : namespace libMesh 33 : { 34 : 35 : // Forward declarations 36 : class EquationSystems; 37 : enum ElemType : int; 38 : 39 : /** 40 : * This class implements writing meshes and solutions in Ensight's Gold format. 41 : * 42 : * \author Camata 43 : * \date 2009 44 : * \author J. W. Peterson (refactoring and iostreams implementation) 45 : * \date 2016 46 : */ 47 : class EnsightIO : public MeshOutput<MeshBase> 48 : { 49 : public: 50 : 51 : /** 52 : * Constructor. 53 : */ 54 : EnsightIO (const std::string & filename, 55 : const EquationSystems & eq); 56 : 57 : /** 58 : * Empty destructor. 59 : */ 60 0 : ~EnsightIO () = default; 61 : 62 : /** 63 : * Tell the EnsightIO interface to output the finite element (not 64 : * SCALAR) variable named "s". 65 : * 66 : * \note You must call add_scalar() or add_vector() (see below) at 67 : * least once, otherwise only the Mesh will be written out. 68 : */ 69 : void add_scalar (const std::string & system, 70 : std::string_view scalar_description, 71 : std::string_view s); 72 : 73 : /** 74 : * Tell the EnsightIO interface that the variables (u,v) constitute 75 : * a vector. 76 : * 77 : * \note \p u and \p v must have the same FEType, and be defined in 78 : * the same system. 79 : */ 80 : void add_vector (const std::string & system, 81 : std::string_view vec_description, 82 : std::string u, 83 : std::string v); 84 : 85 : /** 86 : * Tell the EnsightIO interface that the variables (u, v, w) 87 : * constitute a vector. 88 : * 89 : * \note Requires a 3D mesh, \p u, \p v, and \p w must have the same 90 : * FEType, and must be defined in the same system. 91 : */ 92 : void add_vector (const std::string & system, 93 : std::string_view vec_description, 94 : std::string u, 95 : std::string v, 96 : std::string w); 97 : /** 98 : * Calls write_ascii() and write_case(). 99 : * Writes case, mesh, and solution files named: 100 : * name.case (contains a description of other files) 101 : * name.geo000 (mesh) 102 : * name_{varname}.scl000 (one file per scalar variable) 103 : * name_{vecname}.vec000 (one file per vector variable) 104 : */ 105 : void write (Real time = 0); 106 : 107 : /** 108 : * Calls this->write(0); 109 : */ 110 : virtual void write (const std::string & name) override; 111 : 112 : private: 113 : // Represents the vectors that are used by the EnsightIO 114 0 : struct Vectors 115 : { 116 : std::string description; 117 : std::vector<std::string> components; 118 : }; 119 : 120 : // Represents the scalars 121 0 : struct Scalars 122 : { 123 : std::string scalar_name; 124 : std::string description; 125 : }; 126 : 127 : // Store the variables of system 128 : struct SystemVars 129 : { 130 : std::vector<Vectors> EnsightVectors; 131 : std::vector<Scalars> EnsightScalars; 132 : }; 133 : 134 : // private methods 135 : // write solution in ascii format file 136 : void write_ascii (Real time = 0); 137 : void write_scalar_ascii (std::string_view sys, std::string_view var); 138 : void write_vector_ascii (std::string_view sys, const std::vector<std::string> & vec, std::string_view var_name); 139 : void write_solution_ascii (); 140 : void write_geometry_ascii (); 141 : void write_case(); 142 : 143 : // private Attributes 144 : std::string _ensight_file_name; 145 : std::vector<Real> _time_steps; 146 : 147 : // mapping from system names to variable names+descriptions 148 : std::map <std::string, SystemVars> _system_vars_map; 149 : 150 : // Reference to the EquationSystems we were constructed with 151 : const EquationSystems & _equation_systems; 152 : 153 : // static mapping between libmesh ElemTypes and Ensight element strings. 154 : static std::map<ElemType, std::string> _element_map; 155 : 156 : // Static function used to build the _element_map. 157 : static std::map<ElemType, std::string> build_element_map(); 158 : }; 159 : 160 : 161 : } // namespace libMesh 162 : 163 : 164 : #endif // LIBMESH_ENSIGHT_IO_H