libMesh
mesh_input.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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_MESH_INPUT_H
21 #define LIBMESH_MESH_INPUT_H
22 
23 
24 // Local includes
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/mesh_base.h"
27 
28 // C++ includes
29 #include <cstddef>
30 #include <istream>
31 #include <string>
32 #include <vector>
33 
34 namespace libMesh
35 {
36 
37 
38 
47 template <class MT>
48 class MeshInput
49 {
50 protected:
51 
56  explicit
57  MeshInput (bool is_parallel_format = false);
58 
63  explicit
64  MeshInput (MT &, const bool is_parallel_format = false);
65 
66 public:
67 
71  virtual ~MeshInput ();
72 
80  virtual void read (const std::string &) = 0;
81 
87  bool is_parallel_format () const { return this->_is_parallel_format; }
88 
89 protected:
90 
94  MT & mesh ();
95 
101  void set_n_partitions (unsigned int n_parts) { this->mesh().set_n_partitions() = n_parts; }
102 
107  std::vector<bool> elems_of_dimension;
108 
113  void skip_comment_lines (std::istream & in,
114  const char comment_start);
115 
116 private:
117 
118 
123  MT * _obj;
124 
131 };
132 
133 
134 
135 // ------------------------------------------------------------
136 // MeshInput inline members
137 template <class MT>
138 inline
139 MeshInput<MT>::MeshInput (const bool is_parallel_format) :
140  elems_of_dimension(),
141  _obj (nullptr),
142  _is_parallel_format(is_parallel_format)
143 {
144 }
145 
146 
147 
148 template <class MT>
149 inline
150 MeshInput<MT>::MeshInput (MT & obj, const bool is_parallel_format) :
151  elems_of_dimension(),
152  _obj (&obj),
153  _is_parallel_format(is_parallel_format)
154 {
155  if (!_is_parallel_format && !this->mesh().is_serial())
156  {
157  if (this->mesh().processor_id() == 0)
158  {
159  libmesh_do_once(libMesh::out <<
160  "Warning: This MeshOutput subclass only supports meshes which have been serialized!"
161  << std::endl;);
162  }
163  }
164 }
165 
166 
167 
168 template <class MT>
169 inline
171 {
172 }
173 
174 
175 
176 template <class MT>
177 inline
179 {
180  libmesh_error_msg_if(_obj == nullptr, "ERROR: _obj should not be nullptr!");
181  return *_obj;
182 }
183 
184 
185 
186 template <class MT>
187 void MeshInput<MT>::skip_comment_lines (std::istream & in,
188  const char comment_start)
189 {
190  char c, line[256];
191 
192  while (in.get(c), c==comment_start)
193  in.getline (line, 255);
194 
195  // put back first character of
196  // first non-comment line
197  in.putback (c);
198 }
199 
200 
201 } // namespace libMesh
202 
203 
204 #endif // LIBMESH_MESH_INPUT_H
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition: mesh_input.h:130
std::vector< bool > elems_of_dimension
A vector of bools describing what dimension elements have been encountered when reading a mesh...
Definition: mesh_input.h:107
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
void skip_comment_lines(std::istream &in, const char comment_start)
Reads input from in, skipping all the lines that start with the character comment_start.
Definition: mesh_input.h:187
virtual void read(const std::string &)=0
This method implements reading a mesh from a specified file.
MeshInput(bool is_parallel_format=false)
Default constructor.
Definition: mesh_input.h:139
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:56
bool is_parallel_format() const
Returns true iff this mesh file format and input class are parallelized, so that all processors can r...
Definition: mesh_input.h:87
OStreamProxy out
void set_n_partitions(unsigned int n_parts)
Sets the number of partitions in the mesh.
Definition: mesh_input.h:101
virtual ~MeshInput()
Destructor.
Definition: mesh_input.h:170
MT * _obj
A pointer to a non-const object object.
Definition: mesh_input.h:123