DOLFIN
DOLFIN C++ interface
MeshGeometry.h
1// Copyright (C) 2006 Anders Logg
2//
3// This file is part of DOLFIN.
4//
5// DOLFIN is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// DOLFIN is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17//
18// Modified by Garth N. Wells, 2008.
19//
20// First added: 2006-05-08
21// Last changed: 2016-06-10
22
23#ifndef __MESH_GEOMETRY_H
24#define __MESH_GEOMETRY_H
25
26#include <string>
27#include <vector>
28#include <dolfin/geometry/Point.h>
29#include <dolfin/log/log.h>
30
31namespace dolfin
32{
33 class Function;
34
36
40 {
41 public:
42
45
47 MeshGeometry(const MeshGeometry& geometry);
48
51
53 const MeshGeometry& operator= (const MeshGeometry& geometry);
54
56 std::size_t dim() const
57 { return _dim; }
58
60 std::size_t degree() const
61 { return _degree; }
62
64 std::size_t num_vertices() const
65 {
66 dolfin_assert(coordinates.size() % _dim == 0);
67 if (_degree > 1)
68 {
69 dolfin_assert(entity_offsets.size() > 1);
70 dolfin_assert(entity_offsets[1].size() > 0);
71 return entity_offsets[1][0];
72 }
73 return coordinates.size()/_dim;
74 }
75
78 std::size_t num_points() const
79 {
80 dolfin_assert(coordinates.size() % _dim == 0);
81 return coordinates.size()/_dim;
82 }
83
85 const double* vertex_coordinates(std::size_t point_index)
86 {
87 dolfin_assert(point_index < num_vertices());
88 return &coordinates[point_index*_dim];
89 }
90
92 const double* point_coordinates(std::size_t point_index)
93 {
94 dolfin_assert(point_index*_dim < coordinates.size());
95 return &coordinates[point_index*_dim];
96 }
97
99 double x(std::size_t n, std::size_t i) const
100 {
101 dolfin_assert((n*_dim + i) < coordinates.size());
102 dolfin_assert(i < _dim);
103 return coordinates[n*_dim + i];
104 }
105
107 const double* x(std::size_t n) const
108 {
109 dolfin_assert(n*_dim < coordinates.size());
110 return &coordinates[n*_dim];
111 }
112
114 std::vector<double>& x()
115 { return coordinates; }
116
118 const std::vector<double>& x() const
119 { return coordinates; }
120
122 Point point(std::size_t n) const;
123
125 void init(std::size_t dim, std::size_t degree);
126
128 void init_entities(const std::vector<std::size_t>& num_entities);
129
131 std::size_t num_entity_coordinates(std::size_t entity_dim) const
132 {
133 // Calculate the number of points per entity for Lagrange
134 // elements
135 switch(entity_dim)
136 {
137 case 0:
138 return 1;
139 case 1:
140 return (_degree - 1);
141 case 2:
142 return (_degree - 2)*(_degree - 1)/2;
143 case 3:
144 return (_degree - 3)*(_degree - 2)*(_degree - 1)/6;
145 }
146 dolfin_error("MeshGeometry.h",
147 "calculate number of points",
148 "Entity dimension out of range");
149 return 0;
150 }
151
153 std::size_t get_entity_index(std::size_t entity_dim, std::size_t order,
154 std::size_t index) const
155 {
156 dolfin_assert(entity_dim < entity_offsets.size());
157 dolfin_assert(order < entity_offsets[entity_dim].size());
158 const std::size_t idx = (entity_offsets[entity_dim][order] + index);
159 dolfin_assert(idx*_dim < coordinates.size());
160 return idx;
161 }
162
164 void set(std::size_t local_index, const double* x);
165
172 std::size_t hash() const;
173
175 std::string str(bool verbose) const;
176
177 private:
178
179 // Euclidean dimension
180 std::size_t _dim;
181
182 // Polynomial degree (1 = linear, 2 = quadratic etc.)
183 std::size_t _degree;
184
185 // Offsets to storage for coordinate points for each entity type
186 std::vector<std::vector<std::size_t>> entity_offsets;
187
188 // Coordinates for all points stored as a contiguous array
189 std::vector<double> coordinates;
190
191 };
192
193}
194
195#endif
MeshGeometry stores the geometry imposed on a mesh.
Definition: MeshGeometry.h:40
const MeshGeometry & operator=(const MeshGeometry &geometry)
Assignment.
Definition: MeshGeometry.cpp:48
~MeshGeometry()
Destructor.
Definition: MeshGeometry.cpp:43
const std::vector< double > & x() const
Return array of values for all coordinates.
Definition: MeshGeometry.h:118
std::size_t hash() const
Definition: MeshGeometry.cpp:121
void set(std::size_t local_index, const double *x)
Set value of coordinate.
Definition: MeshGeometry.cpp:115
const double * x(std::size_t n) const
Return array of values for coordinate with local index n.
Definition: MeshGeometry.h:107
Point point(std::size_t n) const
Return coordinate with local index n as a 3D point value.
Definition: MeshGeometry.cpp:60
void init_entities(const std::vector< std::size_t > &num_entities)
Initialise entities. To be called after init.
Definition: MeshGeometry.cpp:95
const double * point_coordinates(std::size_t point_index)
Get vertex coordinates.
Definition: MeshGeometry.h:92
std::size_t get_entity_index(std::size_t entity_dim, std::size_t order, std::size_t index) const
Get the index for an entity point in coordinates.
Definition: MeshGeometry.h:153
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: MeshGeometry.cpp:129
std::size_t num_vertices() const
Return the number of vertex coordinates.
Definition: MeshGeometry.h:64
std::size_t dim() const
Return Euclidean dimension of coordinate system.
Definition: MeshGeometry.h:56
std::vector< double > & x()
Return array of values for all coordinates.
Definition: MeshGeometry.h:114
std::size_t num_points() const
Definition: MeshGeometry.h:78
std::size_t degree() const
Return polynomial degree of coordinate field.
Definition: MeshGeometry.h:60
const double * vertex_coordinates(std::size_t point_index)
Get vertex coordinates.
Definition: MeshGeometry.h:85
double x(std::size_t n, std::size_t i) const
Return value of coordinate with local index n in direction i.
Definition: MeshGeometry.h:99
std::size_t num_entity_coordinates(std::size_t entity_dim) const
Get the number of coordinate points per entity for this degree.
Definition: MeshGeometry.h:131
void init(std::size_t dim, std::size_t degree)
Initialize coordinate list to given dimension and degree.
Definition: MeshGeometry.cpp:65
MeshGeometry()
Create empty set of coordinates.
Definition: MeshGeometry.cpp:33
Definition: Point.h:41
Definition: adapt.h:30
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129