~ubuntu-branches/ubuntu/maverick/dolfin/maverick

« back to all changes in this revision

Viewing changes to dolfin/mesh/Mesh.h

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2008-09-16 08:41:20 UTC
  • Revision ID: james.westby@ubuntu.com-20080916084120-i8k3u6lhx3mw3py3
Tags: upstream-0.9.2
Import upstream version 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2006-2009 Anders Logg.
 
2
// Licensed under the GNU LGPL Version 2.1.
 
3
//
 
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.
 
9
//
 
10
// First added:  2006-05-08
 
11
// Last changed: 2009-03-02
 
12
 
 
13
#ifndef __MESH_H
 
14
#define __MESH_H
 
15
 
 
16
#include <string>
 
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"
 
22
#include "MeshData.h"
 
23
#include "CellType.h"
 
24
 
 
25
namespace dolfin
 
26
{
 
27
  
 
28
  template <class T> class MeshFunction;
 
29
  class IntersectionDetector;
 
30
  class Function;
 
31
  class BoundaryMesh;
 
32
  class XMLMesh;
 
33
  class NewXMLMesh;
 
34
 
 
35
  /// A Mesh consists of a set of connected and numbered mesh entities.
 
36
  ///
 
37
  /// Both the representation and the interface are dimension-independent,
 
38
  /// but a concrete interface is also provided for standard named mesh
 
39
  /// entities:
 
40
  ///
 
41
  ///     Entity  Dimension  Codimension
 
42
  ///
 
43
  ///     Vertex      0           -
 
44
  ///     Edge        1           -
 
45
  ///     Face        2           -
 
46
  ///
 
47
  ///     Facet       -           1
 
48
  ///     Cell        -           0
 
49
  ///
 
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.
 
53
  ///
 
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)).
 
61
  
 
62
  class Mesh : public Variable
 
63
  {
 
64
  public:
 
65
    
 
66
    /// Create empty mesh
 
67
    Mesh();
 
68
 
 
69
    /// Copy constructor
 
70
    Mesh(const Mesh& mesh);
 
71
 
 
72
    /// Create mesh from data file
 
73
    explicit Mesh(std::string filename);
 
74
    
 
75
    /// Destructor
 
76
    ~Mesh();
 
77
 
 
78
    /// Assignment
 
79
    const Mesh& operator=(const Mesh& mesh);
 
80
 
 
81
    /// Return number of vertices
 
82
    inline uint numVertices() const { return _topology.size(0); }
 
83
 
 
84
    /// Return number of edges
 
85
    inline uint numEdges() const { return _topology.size(1); }
 
86
 
 
87
    /// Return number of faces
 
88
    inline uint numFaces() const { return _topology.size(2); }
 
89
 
 
90
    /// Return number of facets
 
91
    inline uint numFacets() const { return _topology.size(_topology.dim() - 1); }
 
92
 
 
93
    /// Return number of cells
 
94
    inline uint numCells() const { return _topology.size(_topology.dim()); }
 
95
 
 
96
    /// Return coordinates of all vertices
 
97
    inline double* coordinates() { return _geometry.x(); }
 
98
 
 
99
    /// Return coordinates of all vertices
 
100
    inline const double* coordinates() const { return _geometry.x(); }
 
101
 
 
102
    /// Return connectivity for all cells
 
103
    inline const uint* cells() const { return _topology(_topology.dim(), 0)(); }
 
104
 
 
105
    /// Return number of entities of given topological dimension
 
106
    inline uint size(uint dim) const { return _topology.size(dim); }
 
107
    
 
108
    /// Return mesh topology (non-const version)
 
109
    inline MeshTopology& topology() { return _topology; }
 
110
 
 
111
    /// Return mesh topology (const version)
 
112
    inline const MeshTopology& topology() const { return _topology; }
 
113
 
 
114
    /// Return mesh geometry (non-const version)
 
115
    inline MeshGeometry& geometry() { return _geometry; }
 
116
 
 
117
    /// Return mesh geometry (const version)
 
118
    inline const MeshGeometry& geometry() const { return _geometry; }
 
119
 
 
120
    /// Return mesh data (non-const version)
 
121
    MeshData& data() { return _data; }
 
122
 
 
123
    /// Return mesh data (const version)
 
124
    const MeshData& data() const { return _data; }
 
125
 
 
126
    /// Return mesh cell type
 
127
    inline CellType& type() { dolfin_assert(_cell_type); return *_cell_type; }
 
128
 
 
129
    /// Return mesh cell type
 
130
    inline const CellType& type() const { dolfin_assert(_cell_type); return *_cell_type; }
 
131
 
 
132
    /// Compute entities of given topological dimension and return number of entities
 
133
    uint init(uint dim) const;
 
134
 
 
135
    /// Compute connectivity between given pair of dimensions
 
136
    void init(uint d0, uint d1) const;
 
137
 
 
138
    /// Compute all entities and connectivity
 
139
    void init() const;
 
140
 
 
141
    /// Clear all mesh data
 
142
    void clear();
 
143
 
 
144
    /// Order all mesh entities (not needed if "mesh order entities" is set)
 
145
    void order();
 
146
 
 
147
    /// Return true iff topology is ordered according to the UFC numbering
 
148
    bool ordered() const;
 
149
 
 
150
    /// Refine mesh uniformly
 
151
    void refine();
 
152
 
 
153
    /// Refine mesh according to cells marked for refinement,
 
154
    void refine(MeshFunction<bool>& cell_markers);
 
155
 
 
156
    /// Coarsen mesh uniformly
 
157
    void coarsen();
 
158
 
 
159
    /// Coarsen mesh according to cells marked for coarsening
 
160
    void coarsen(MeshFunction<bool>& cell_markers, bool coarsen_boundary = false);
 
161
 
 
162
    /// Move coordinates of mesh according to new boundary coordinates
 
163
    void move(BoundaryMesh& boundary, dolfin::ALEType method=hermite);
 
164
    
 
165
    /// Move coordinates of mesh according to adjacent mesh with common global vertices
 
166
    void move(Mesh& mesh, dolfin::ALEType method=hermite);
 
167
 
 
168
    /// Move coordinates of mesh according to displacement function
 
169
    void move(const Function& displacement);
 
170
 
 
171
    /// Smooth mesh using Lagrangian mesh smoothing
 
172
    void smooth(uint num_smoothings=1);
 
173
    
 
174
    /// Compute cells intersecting point
 
175
    void intersection(const Point& p, std::vector<uint>& cells, bool fixed_mesh=true);
 
176
 
 
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);
 
179
    
 
180
    /// Compute cells overlapping cell
 
181
    void intersection(Cell& cell, std::vector<uint>& cells, bool fixed_mesh=true);
 
182
    
 
183
    /// Compute intersection with curve defined by points
 
184
    void intersection(std::vector<Point>& points, std::vector<uint>& intersection, bool fixed_mesh=true);
 
185
    
 
186
    /// Compute intersection with mesh
 
187
    void intersection(Mesh& mesh, std::vector<unsigned int>& cells, bool fixed_mesh=true);
 
188
 
 
189
    /// Display mesh data
 
190
    void disp() const;
 
191
    
 
192
    /// Return a short desriptive string
 
193
    std::string str() const;
 
194
 
 
195
    /// Output
 
196
    friend LogStream& operator<< (LogStream& stream, const Mesh& mesh);
 
197
 
 
198
    /// Define XMLHandler for use in new XML reader/writer
 
199
    typedef NewXMLMesh XMLHandler;
 
200
    
 
201
  private:
 
202
 
 
203
    // Friends
 
204
    friend class MeshEditor;
 
205
    friend class TopologyComputation;
 
206
    friend class MeshOrdering;
 
207
    friend class MPIMeshCommunicator;
 
208
 
 
209
    // Mesh topology
 
210
    MeshTopology _topology;
 
211
 
 
212
    // Mesh geometry
 
213
    MeshGeometry _geometry;
 
214
 
 
215
    // Auxiliary mesh data
 
216
    MeshData _data;
 
217
 
 
218
    // Cell type
 
219
    CellType* _cell_type;
 
220
    
 
221
    // Intersection detector
 
222
    IntersectionDetector* detector;
 
223
 
 
224
    // True if mesh has been ordered
 
225
    mutable bool _ordered;
 
226
    
 
227
  };
 
228
 
 
229
}
 
230
 
 
231
#endif