1
// Copyright (C) 2006-2009 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// Modified by Johan Hoffman, 2007.
5
// Modified by Magnus Vikstrøm, 2007.
6
// Modified by Garth N. Wells, 2007.
7
// Modified by Niclas Jansson, 2008.
8
// Modified by Kristoffer Selim, 2008.
10
// First added: 2006-05-08
11
// Last changed: 2009-03-02
17
#include <dolfin/common/types.h>
18
#include <dolfin/common/Variable.h>
19
#include <dolfin/ale/ALEType.h>
20
#include "MeshTopology.h"
21
#include "MeshGeometry.h"
28
template <class T> class MeshFunction;
29
class IntersectionDetector;
35
/// A Mesh consists of a set of connected and numbered mesh entities.
37
/// Both the representation and the interface are dimension-independent,
38
/// but a concrete interface is also provided for standard named mesh
41
/// Entity Dimension Codimension
50
/// When working with mesh iterators, all entities and connectivity
51
/// are precomputed automatically the first time an iterator is
52
/// created over any given topological dimension or connectivity.
54
/// Note that for efficiency, only entities of dimension zero
55
/// (vertices) and entities of the maximal dimension (cells) exist
56
/// when creating a Mesh. Other entities must be explicitly created
57
/// by calling init(). For example, all edges in a mesh may be created
58
/// by a call to mesh.init(1). Similarly, connectivities such as
59
/// all edges connected to a given vertex must also be explicitly
60
/// created (in this case by a call to mesh.init(0, 1)).
62
class Mesh : public Variable
70
Mesh(const Mesh& mesh);
72
/// Create mesh from data file
73
explicit Mesh(std::string filename);
79
const Mesh& operator=(const Mesh& mesh);
81
/// Return number of vertices
82
inline uint numVertices() const { return _topology.size(0); }
84
/// Return number of edges
85
inline uint numEdges() const { return _topology.size(1); }
87
/// Return number of faces
88
inline uint numFaces() const { return _topology.size(2); }
90
/// Return number of facets
91
inline uint numFacets() const { return _topology.size(_topology.dim() - 1); }
93
/// Return number of cells
94
inline uint numCells() const { return _topology.size(_topology.dim()); }
96
/// Return coordinates of all vertices
97
inline double* coordinates() { return _geometry.x(); }
99
/// Return coordinates of all vertices
100
inline const double* coordinates() const { return _geometry.x(); }
102
/// Return connectivity for all cells
103
inline const uint* cells() const { return _topology(_topology.dim(), 0)(); }
105
/// Return number of entities of given topological dimension
106
inline uint size(uint dim) const { return _topology.size(dim); }
108
/// Return mesh topology (non-const version)
109
inline MeshTopology& topology() { return _topology; }
111
/// Return mesh topology (const version)
112
inline const MeshTopology& topology() const { return _topology; }
114
/// Return mesh geometry (non-const version)
115
inline MeshGeometry& geometry() { return _geometry; }
117
/// Return mesh geometry (const version)
118
inline const MeshGeometry& geometry() const { return _geometry; }
120
/// Return mesh data (non-const version)
121
MeshData& data() { return _data; }
123
/// Return mesh data (const version)
124
const MeshData& data() const { return _data; }
126
/// Return mesh cell type
127
inline CellType& type() { dolfin_assert(_cell_type); return *_cell_type; }
129
/// Return mesh cell type
130
inline const CellType& type() const { dolfin_assert(_cell_type); return *_cell_type; }
132
/// Compute entities of given topological dimension and return number of entities
133
uint init(uint dim) const;
135
/// Compute connectivity between given pair of dimensions
136
void init(uint d0, uint d1) const;
138
/// Compute all entities and connectivity
141
/// Clear all mesh data
144
/// Order all mesh entities (not needed if "mesh order entities" is set)
147
/// Return true iff topology is ordered according to the UFC numbering
148
bool ordered() const;
150
/// Refine mesh uniformly
153
/// Refine mesh according to cells marked for refinement,
154
void refine(MeshFunction<bool>& cell_markers);
156
/// Coarsen mesh uniformly
159
/// Coarsen mesh according to cells marked for coarsening
160
void coarsen(MeshFunction<bool>& cell_markers, bool coarsen_boundary = false);
162
/// Move coordinates of mesh according to new boundary coordinates
163
void move(BoundaryMesh& boundary, dolfin::ALEType method=hermite);
165
/// Move coordinates of mesh according to adjacent mesh with common global vertices
166
void move(Mesh& mesh, dolfin::ALEType method=hermite);
168
/// Move coordinates of mesh according to displacement function
169
void move(const Function& displacement);
171
/// Smooth mesh using Lagrangian mesh smoothing
172
void smooth(uint num_smoothings=1);
174
/// Compute cells intersecting point
175
void intersection(const Point& p, std::vector<uint>& cells, bool fixed_mesh=true);
177
/// Compute cells overlapping line defined by points
178
void intersection(const Point& p1, const Point& p2, std::vector<uint>& cells, bool fixed_mesh=true);
180
/// Compute cells overlapping cell
181
void intersection(Cell& cell, std::vector<uint>& cells, bool fixed_mesh=true);
183
/// Compute intersection with curve defined by points
184
void intersection(std::vector<Point>& points, std::vector<uint>& intersection, bool fixed_mesh=true);
186
/// Compute intersection with mesh
187
void intersection(Mesh& mesh, std::vector<unsigned int>& cells, bool fixed_mesh=true);
189
/// Display mesh data
192
/// Return a short desriptive string
193
std::string str() const;
196
friend LogStream& operator<< (LogStream& stream, const Mesh& mesh);
198
/// Define XMLHandler for use in new XML reader/writer
199
typedef NewXMLMesh XMLHandler;
204
friend class MeshEditor;
205
friend class TopologyComputation;
206
friend class MeshOrdering;
207
friend class MPIMeshCommunicator;
210
MeshTopology _topology;
213
MeshGeometry _geometry;
215
// Auxiliary mesh data
219
CellType* _cell_type;
221
// Intersection detector
222
IntersectionDetector* detector;
224
// True if mesh has been ordered
225
mutable bool _ordered;