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_NAMEBASED_IO_H
21 #define LIBMESH_NAMEBASED_IO_H
22
23 // Local includes
24 #include "libmesh/mesh_output.h"
25 #include "libmesh/mesh_input.h"
26
27 namespace libMesh
28 {
29
30 // Forward declarations
31 class MeshBase;
32
33 /**
34 * This class supports simple reads and writes in any
35 * libMesh-supported format, by dispatching to one of the other I/O
36 * classes based on filename.
37 *
38 * Other I/O classes may have more advanced features that are not
39 * accessible via this interface.
40 *
41 * \author Roy H. Stogner
42 * \date 2015
43 */
44 class NameBasedIO : public MeshInput<MeshBase>,
45 public MeshOutput<MeshBase>
46 {
47 public:
48
49 /**
50 * Constructor. Takes a reference to a constant mesh object.
51 * This constructor will only allow us to write the mesh.
52 */
53 explicit
54 NameBasedIO (const MeshBase &);
55
56 /**
57 * Constructor. Takes a writable reference to a mesh object.
58 * This constructor is required to let us read in a mesh.
59 */
60 explicit
61 NameBasedIO (MeshBase &);
62
63 /**
64 * This method implements reading a mesh from a specified file.
65 */
66 virtual void read (const std::string & mesh_file) override;
67
68 /**
69 * This method implements writing a mesh to a specified file.
70 */
71 virtual void write (const std::string & mesh_file) override;
72
73 /**
74 * This method implements writing a mesh with data to a specified file
75 * where the data is taken from the \p EquationSystems object.
76 *
77 * We override the default MeshOutput::write_equation_systems
78 * because it only outputs nodal data by default, whereas we want to
79 * output a proper restart file if the requested filename is an XDA
80 * or XDR type.
81 */
82 virtual void write_equation_systems (const std::string & filename,
83 const EquationSystems & es,
84 const std::set<std::string> * system_names=nullptr) override;
85
86 /**
87 * Bring in base class functionality for name resolution and to
88 * avoid warnings about hidden overloaded virtual functions.
89 */
90 using MeshOutput<MeshBase>::write_nodal_data;
91
92 /**
93 * This method implements writing a mesh with nodal data to a
94 * specified file where the nodal data and variable names are provided.
95 */
96 virtual void write_nodal_data (const std::string &,
97 const std::vector<Number> &,
98 const std::vector<std::string> &) override;
99
100 // Certain mesh formats can support parallel I/O, including the
101 // "new" Xdr format and the Nemesis format.
102 bool is_parallel_file_format (const std::string & filename);
103 };
104
105
106
107 // ------------------------------------------------------------
108 // NameBasedIO inline members
109 inline
NameBasedIO(const MeshBase & mesh)110 NameBasedIO::NameBasedIO (const MeshBase & mesh) :
111 MeshOutput<MeshBase> (mesh)
112 {
113 }
114
115 inline
NameBasedIO(MeshBase & mesh)116 NameBasedIO::NameBasedIO (MeshBase & mesh) :
117 MeshInput<MeshBase> (mesh),
118 MeshOutput<MeshBase>(mesh)
119 {
120 }
121
122 inline
123 bool
is_parallel_file_format(const std::string & name)124 NameBasedIO::is_parallel_file_format (const std::string & name)
125 {
126 return ((name.rfind(".xda") < name.size()) ||
127 (name.rfind(".xdr") < name.size()) ||
128 (name.rfind(".nem") + 4 == name.size()) ||
129 (name.rfind(".n") + 2 == name.size()) ||
130 (name.rfind(".cp") < name.size())
131 );
132 }
133
134
135 } // namespace libMesh
136
137
138 #endif // LIBMESH_NAMEBASED_IO_H
139