1 // The libMesh Finite Element Library. 2 // Copyright (C) 2002-2020 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 20 #ifndef LIBMESH_UCD_IO_H 21 #define LIBMESH_UCD_IO_H 22 23 // C++ includes 24 #include <map> 25 26 // Local includes 27 #include "libmesh/libmesh_common.h" 28 #include "libmesh/mesh_input.h" 29 #include "libmesh/mesh_output.h" 30 31 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS 32 namespace libMesh 33 { 34 enum ElemType : int; 35 } 36 #else 37 #include "libmesh/enum_elem_type.h" 38 #endif 39 40 namespace libMesh 41 { 42 43 // Forward declarations 44 class MeshBase; 45 46 /** 47 * This class implements reading & writing meshes in the AVS's UCD format. 48 * 49 * \author Benjamin S. Kirk 50 * \date 2004 51 */ 52 class UCDIO : public MeshInput<MeshBase>, 53 public MeshOutput<MeshBase> 54 { 55 public: 56 57 /** 58 * Constructor. Takes a writable reference to a mesh object. 59 * This is the constructor required to read a mesh. 60 */ 61 explicit UCDIO(MeshBase & mesh)62 UCDIO (MeshBase & mesh) : 63 MeshInput<MeshBase> (mesh), 64 MeshOutput<MeshBase>(mesh) 65 {} 66 67 /** 68 * Constructor. Takes a reference to a constant mesh object. 69 * This constructor will only allow us to write the mesh. 70 */ 71 explicit UCDIO(const MeshBase & mesh)72 UCDIO (const MeshBase & mesh) : 73 MeshOutput<MeshBase> (mesh) 74 {} 75 76 /** 77 * This method implements reading a mesh from a specified file 78 * in UCD format. 79 */ 80 virtual void read (const std::string &) override; 81 82 /** 83 * This method implements writing a mesh to a specified file 84 * in UCD format. 85 */ 86 virtual void write (const std::string &) override; 87 88 /** 89 * Bring in base class functionality for name resolution and to 90 * avoid warnings about hidden overloaded virtual functions. 91 */ 92 using MeshOutput<MeshBase>::write_nodal_data; 93 94 /** 95 * This method implements writing a mesh and solution to a specified file 96 * in UCD format. This is internally called by MeshOutput::write_equation_systems 97 */ 98 virtual void write_nodal_data(const std::string & fname, 99 const std::vector<Number> & soln, 100 const std::vector<std::string> & names) override; 101 102 103 private: 104 105 /** 106 * The actual implementation of the read function. 107 * The public read interface simply decides which 108 * type of stream to pass the implementation. 109 */ 110 void read_implementation (std::istream & in_stream); 111 112 /** 113 * The actual implementation of the write function. 114 * The public write interface simply decides which 115 * type of stream to pass the implementation. 116 */ 117 void write_implementation (std::ostream & out_stream); 118 119 /** 120 * Write UCD format header 121 */ 122 void write_header(std::ostream & out, 123 const MeshBase & mesh, 124 dof_id_type n_elems, 125 unsigned int n_vars); 126 127 /** 128 * Write node information 129 */ 130 void write_nodes(std::ostream & out, 131 const MeshBase & mesh); 132 133 /** 134 * Write element information 135 */ 136 void write_interior_elems(std::ostream & out, 137 const MeshBase & mesh); 138 139 /** 140 * Writes all nodal solution variables 141 */ 142 void write_soln(std::ostream & out, 143 const MeshBase & mesh, 144 const std::vector<std::string> & names, 145 const std::vector<Number> & soln); 146 147 // Static map from libmesh ElementType -> UCD description string for 148 // use during writing. 149 static std::map<ElemType, std::string> _writing_element_map; 150 151 // Static map from libmesh UCD description string -> ElementType for 152 // use during reading. 153 static std::map<std::string, ElemType> _reading_element_map; 154 155 // Static function used to build the _writing_element_map. 156 static std::map<ElemType, std::string> build_writing_element_map(); 157 158 // Static function used to build the _reading_element_map. 159 static std::map<std::string, ElemType> build_reading_element_map(); 160 }; 161 162 } // namespace libMesh 163 164 165 #endif // LIBMESH_UCD_IO_H 166