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