Reference documentation for deal.II version 8.4.2
manifold.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2015 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/base/tensor.h>
17 #include <deal.II/grid/manifold.h>
18 #include <deal.II/grid/tria.h>
19 #include <deal.II/grid/tria_iterator.h>
20 #include <deal.II/grid/tria_accessor.h>
21 #include <deal.II/fe/fe_q.h>
22 #include <cmath>
23 
24 DEAL_II_NAMESPACE_OPEN
25 
26 using namespace Manifolds;
27 
28 /* -------------------------- Manifold --------------------- */
29 
30 
31 template <int dim, int spacedim>
33 {}
34 
35 
36 
37 template <int dim, int spacedim>
40 project_to_manifold (const std::vector<Point<spacedim> > &,
41  const Point<spacedim> &) const
42 {
43  Assert (false, ExcPureFunctionCalled());
44  return Point<spacedim>();
45 }
46 
47 
48 
49 template <int dim, int spacedim>
53 {
54  const std::vector<Point<spacedim> > &surrounding_points = quad.get_points();
55  const std::vector<double> &weights = quad.get_weights();
57 
58 #ifdef DEBUG
59  double sum=0;
60  for (unsigned int i=0; i<weights.size(); ++i)
61  sum+= weights[i];
62  Assert(std::abs(sum-1.0) < 1e-10, ExcMessage("Weights should sum to 1!"));
63 #endif
64 
65  for (unsigned int i=0; i<surrounding_points.size(); ++i)
66  p += surrounding_points[i]*weights[i];
67 
68  return project_to_manifold(surrounding_points, p);
69 }
70 
71 
72 template <int dim, int spacedim>
75 get_new_point_on_line (const typename Triangulation<dim, spacedim>::line_iterator &line) const
76 {
77  return get_new_point (get_default_quadrature(line));
78 }
79 
80 
81 
82 template <int dim, int spacedim>
85 get_new_point_on_quad (const typename Triangulation<dim, spacedim>::quad_iterator &quad) const
86 {
87  return get_new_point (get_default_quadrature(quad));
88 }
89 
90 
91 template <int dim, int spacedim>
95 {
96  Assert (dim>1, ExcImpossibleInDim(dim));
97 
98  switch (dim)
99  {
100  case 2:
101  return get_new_point_on_line (face);
102  case 3:
103  return get_new_point_on_quad (face);
104  }
105 
106  return Point<spacedim>();
107 }
108 
109 
110 
111 template <int dim, int spacedim>
115 {
116  switch (dim)
117  {
118  case 1:
119  return get_new_point_on_line (cell);
120  case 2:
121  return get_new_point_on_quad (cell);
122  case 3:
123  return get_new_point_on_hex (cell);
124  }
125 
126  return Point<spacedim>();
127 }
128 
129 
130 template <>
131 Point<1>
134 {
135  Assert (false, ExcImpossibleInDim(1));
136  return Point<1>();
137 }
138 
139 
140 template <>
141 Point<2>
144 {
145  Assert (false, ExcImpossibleInDim(1));
146  return Point<2>();
147 }
148 
149 
150 
151 template <>
152 Point<3>
155 {
156  Assert (false, ExcImpossibleInDim(1));
157  return Point<3>();
158 }
159 
160 
161 template <>
162 Point<1>
164 get_new_point_on_quad (const Triangulation<1,1>::quad_iterator &) const
165 {
166  Assert (false, ExcImpossibleInDim(1));
167  return Point<1>();
168 }
169 
170 template <>
171 Point<2>
173 get_new_point_on_quad (const Triangulation<1,2>::quad_iterator &) const
174 {
175  Assert (false, ExcImpossibleInDim(1));
176  return Point<2>();
177 }
178 
179 
180 template <>
181 Point<3>
183 get_new_point_on_quad (const Triangulation<1,3>::quad_iterator &) const
184 {
185  Assert (false, ExcImpossibleInDim(1));
186  return Point<3>();
187 }
188 
189 template <int dim, int spacedim>
192 get_new_point_on_hex (const typename Triangulation<dim, spacedim>::hex_iterator &/*hex*/) const
193 {
194  Assert (false, ExcImpossibleInDim(dim));
195  return Point<spacedim>();
196 }
197 
198 template <>
199 Point<3>
201 get_new_point_on_hex (const Triangulation<3, 3>::hex_iterator &hex) const
202 {
203  return get_new_point(get_default_quadrature(hex, true));
204 }
205 
206 
207 /* -------------------------- FlatManifold --------------------- */
208 
209 
210 template <int dim, int spacedim>
212  const double tolerance) :
213  periodicity(periodicity),
214  tolerance(tolerance)
215 {}
216 
217 template <int dim, int spacedim>
221 {
222  const std::vector<Point<spacedim> > &surrounding_points = quad.get_points();
223  const std::vector<double> &weights = quad.get_weights();
224 
225 #ifdef DEBUG
226  double sum=0;
227  for (unsigned int i=0; i<weights.size(); ++i)
228  sum+= weights[i];
229  // Here it is correct to use tolerance as an absolute one, since
230  // this should be relative to unity.
231  Assert(std::abs(sum-1.0) < tolerance, ExcMessage("Weights should sum to 1!"));
232 #endif
233 
234 
235  Point<spacedim> p;
236  Point<spacedim> dp;
238  const bool check_period = (periodicity.norm() > tolerance);
239  if (check_period)
240  for (unsigned int i=0; i<surrounding_points.size(); ++i)
241  for (unsigned int d=0; d<spacedim; ++d)
242  {
243  minP[d] = std::min(minP[d], surrounding_points[i][d]);
244  if (periodicity[d] > 0)
245  Assert( (surrounding_points[i][d] < periodicity[d]+tolerance*periodicity.norm()) ||
246  (surrounding_points[i][d] >= -tolerance*periodicity.norm()),
247  ExcPeriodicBox(d, surrounding_points[i], periodicity, tolerance*periodicity.norm()));
248  }
249 
250  for (unsigned int i=0; i<surrounding_points.size(); ++i)
251  {
252  dp = Point<spacedim>();
253  if (check_period)
254  {
255  for (unsigned int d=0; d<spacedim; ++d)
256  if (periodicity[d] > 0)
257  dp[d] = ( (surrounding_points[i][d]-minP[d]) > periodicity[d]/2.0 ?
258  -periodicity[d] : 0.0 );
259  }
260  p += (surrounding_points[i]+dp)*weights[i];
261  }
262  if (check_period)
263  for (unsigned int d=0; d<spacedim; ++d)
264  if (periodicity[d] > 0)
265  p[d] = (p[d] < 0 ? p[d] + periodicity[d] : p[d]);
266 
267  return project_to_manifold(surrounding_points, p);
268 }
269 
270 template <int dim, int spacedim>
273  const Point<spacedim> &candidate) const
274 {
275  return candidate;
276 }
277 
278 
279 /* -------------------------- ChartManifold --------------------- */
280 
281 template <int dim, int spacedim, int chartdim>
283 {}
284 
285 template <int dim, int spacedim, int chartdim>
287  sub_manifold(periodicity)
288 {}
289 
290 
291 template <int dim, int spacedim, int chartdim>
295 {
296  const std::vector<Point<spacedim> > &surrounding_points = quad.get_points();
297  const std::vector<double> &weights = quad.get_weights();
298  std::vector<Point<chartdim> > chart_points(surrounding_points.size());
299 
300  for (unsigned int i=0; i<surrounding_points.size(); ++i)
301  chart_points[i] = pull_back(surrounding_points[i]);
302 
303  const Quadrature<chartdim> chart_quad(chart_points, weights);
304  const Point<chartdim> p_chart = sub_manifold.get_new_point(chart_quad);
305 
306  return push_forward(p_chart);
307 }
308 
309 
310 
311 
312 
313 
314 // explicit instantiations
315 #include "manifold.inst"
316 
317 DEAL_II_NAMESPACE_CLOSE
318 
Quadrature< OBJECT::AccessorType::space_dimension > get_default_quadrature(const OBJECT &obj, bool with_laplace=false)
virtual Point< spacedim > get_new_point(const Quadrature< spacedim > &quad) const
Definition: manifold.cc:52
const std::vector< Point< dim > > & get_points() const
const std::vector< double > & get_weights() const
virtual Point< spacedim > get_new_point_on_hex(const typename Triangulation< dim, spacedim >::hex_iterator &hex) const
Definition: manifold.cc:192
::ExceptionBase & ExcMessage(std::string arg1)
numbers::NumberTraits< Number >::real_type norm() const
Definition: tensor.h:1047
const FlatManifold< dim, chartdim > sub_manifold
Definition: manifold.h:433
virtual Point< spacedim > get_new_point_on_line(const typename Triangulation< dim, spacedim >::line_iterator &line) const
Definition: manifold.cc:75
virtual Point< spacedim > project_to_manifold(const std::vector< Point< spacedim > > &points, const Point< spacedim > &candidate) const
Definition: manifold.cc:272
ChartManifold(const Point< chartdim > periodicity=Point< chartdim >())
Definition: manifold.cc:286
#define Assert(cond, exc)
Definition: exceptions.h:294
virtual Point< spacedim > project_to_manifold(const std::vector< Point< spacedim > > &surrounding_points, const Point< spacedim > &candidate) const
Definition: manifold.cc:40
virtual Point< spacedim > get_new_point(const Quadrature< spacedim > &quad) const
Definition: manifold.cc:294
const double tolerance
Definition: manifold.h:312
FlatManifold(const Point< spacedim > periodicity=Point< spacedim >(), const double tolerance=1e-10)
Definition: manifold.cc:211
virtual ~Manifold()
Definition: manifold.cc:32
const Point< spacedim > periodicity
Definition: manifold.h:301
virtual Point< spacedim > get_new_point_on_quad(const typename Triangulation< dim, spacedim >::quad_iterator &quad) const
Definition: manifold.cc:85
virtual Point< spacedim > push_forward(const Point< chartdim > &chart_point) const =0
virtual ~ChartManifold()
Definition: manifold.cc:282
Point< spacedim > get_new_point_on_face(const typename Triangulation< dim, spacedim >::face_iterator &face) const
Definition: manifold.cc:94
virtual Point< spacedim > get_new_point(const Quadrature< spacedim > &quad) const
Definition: manifold.cc:220
virtual Point< chartdim > pull_back(const Point< spacedim > &space_point) const =0
Point< spacedim > get_new_point_on_cell(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
Definition: manifold.cc:114