libMesh
Loading...
Searching...
No Matches
mesh_input.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
34namespace libMesh
35{
36
37
38
47template <class MT>
49{
50protected:
51
56 explicit
58
63 explicit
64 MeshInput (MT &, const bool is_parallel_format = false);
65
66public:
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
89protected:
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
116private:
117
118
123 MT * _obj;
124
131};
132
133
134
135// ------------------------------------------------------------
136// MeshInput inline members
137template <class MT>
138inline
139MeshInput<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
148template <class MT>
149inline
150MeshInput<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
168template <class MT>
169inline
173
174
175
176template <class MT>
177inline
179{
180 libmesh_error_msg_if(_obj == nullptr, "ERROR: _obj should not be nullptr!");
181 return *_obj;
182}
183
184
185
186template <class MT>
187void 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
This class defines an abstract interface for Mesh input.
Definition mesh_input.h:49
MeshInput(bool is_parallel_format=false)
Default constructor.
Definition mesh_input.h:139
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
MeshInput(MT &, const bool is_parallel_format=false)
Constructor.
Definition mesh_input.h:150
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
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
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
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition mesh_input.h:130
virtual void read(const std::string &)=0
This method implements reading a mesh from a specified file.
MT * _obj
A pointer to a non-const object object.
Definition mesh_input.h:123
The libMesh namespace provides an interface to certain functionality in the library.
OStreamProxy out