Reference documentation for deal.II version Git 53084d8c6a 2020-10-21 00:34:33 -0400
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
bounding_box.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2020 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_base_bounding_box_h
17 #define dealii_base_bounding_box_h
18 
19 
20 #include <deal.II/base/config.h>
21 
23 #include <deal.II/base/point.h>
24 #include <deal.II/base/utilities.h>
25 
27 #include <boost/geometry/algorithms/envelope.hpp>
28 #include <boost/geometry/geometries/multi_point.hpp>
30 
32 
37 enum class NeighborType
38 {
42  not_neighbors = 0,
43 
49  simple_neighbors = 1,
50 
57 
69 };
70 
125 template <int spacedim, typename Number = double>
127 {
128 public:
133  BoundingBox() = default;
134 
141  &boundary_points);
142 
150  template <class Container>
151  BoundingBox(const Container &points);
152 
156  std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
157  get_boundary_points();
158 
162  const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
163  get_boundary_points() const;
164 
172  get_neighbor_type(const BoundingBox<spacedim, Number> &other_bbox) const;
173 
179  void
180  merge_with(const BoundingBox<spacedim, Number> &other_bbox);
181 
188  bool
189  point_inside(
190  const Point<spacedim, Number> &p,
191  const double tolerance = std::numeric_limits<Number>::epsilon()) const;
192 
203  void
204  extend(const Number &amount);
205 
209  double
210  volume() const;
211 
216  center() const;
217 
221  Number
222  side_length(const unsigned int direction) const;
223 
227  Number
228  lower_bound(const unsigned int direction) const;
229 
233  Number
234  upper_bound(const unsigned int direction) const;
235 
240  bounds(const unsigned int direction) const;
241 
247  vertex(const unsigned int index) const;
248 
254  child(const unsigned int index) const;
255 
263  BoundingBox<spacedim - 1, Number>
264  cross_section(const unsigned int direction) const;
265 
275  real_to_unit(const Point<spacedim, Number> &point) const;
276 
286  unit_to_real(const Point<spacedim, Number> &point) const;
287 
291  template <class Archive>
292  void
293  serialize(Archive &ar, const unsigned int version);
294 
295 private:
296  std::pair<Point<spacedim, Number>, Point<spacedim, Number>> boundary_points;
297 };
298 
304 template <typename Number>
305 class BoundingBox<0, Number>
306 {
307 public:
311  BoundingBox();
312 
316  BoundingBox(const std::pair<Point<0, Number>, Point<0, Number>> &);
317 
321  template <class Container>
322  BoundingBox(const Container &);
323 };
324 
325 
331 template <int dim, typename Number = double>
334 
335 
336 namespace internal
337 {
370  template <int dim>
371  inline int
372  coordinate_to_one_dim_higher(const int locked_coordinate,
373  const int coordinate_in_dim)
374  {
375  AssertIndexRange(locked_coordinate, dim + 1);
376  AssertIndexRange(coordinate_in_dim, dim);
377  return (locked_coordinate + coordinate_in_dim + 1) % (dim + 1);
378  }
379 
380 } // namespace internal
381 
382 /*------------------------ Inline functions: BoundingBox --------------------*/
383 
384 #ifndef DOXYGEN
385 
386 
387 template <int spacedim, typename Number>
390  &boundary_points)
391 {
392  // We check the Bounding Box is not degenerate
393  for (unsigned int i = 0; i < spacedim; ++i)
394  Assert(boundary_points.first[i] <= boundary_points.second[i],
395  ExcMessage("Bounding Box can't be created: the points' "
396  "order should be bottom left, top right!"));
397 
398  this->boundary_points = boundary_points;
399 }
400 
401 
402 
403 template <int spacedim, typename Number>
404 template <class Container>
405 inline BoundingBox<spacedim, Number>::BoundingBox(const Container &points)
406 {
407  boost::geometry::envelope(
408  boost::geometry::model::multi_point<Point<spacedim, Number>>(points.begin(),
409  points.end()),
410  *this);
411 }
412 
413 
414 
415 template <int spacedim, typename Number>
416 inline void
417 BoundingBox<spacedim, Number>::extend(const Number &amount)
418 {
419  for (unsigned int d = 0; d < spacedim; ++d)
420  {
421  boundary_points.first[d] -= amount;
422  boundary_points.second[d] += amount;
423  Assert(boundary_points.first[d] <= boundary_points.second[d],
424  ExcMessage("Bounding Box can't be shrunk this much: the points' "
425  "order should remain bottom left, top right."));
426  }
427 }
428 
429 
430 template <int spacedim, typename Number>
431 template <class Archive>
432 void
434  const unsigned int /*version*/)
435 {
436  ar &boundary_points;
437 }
438 
439 
440 
441 template <typename Number>
443 {
444  AssertThrow(false, ExcImpossibleInDim(0));
445 }
446 
447 
448 
449 template <typename Number>
451  const std::pair<Point<0, Number>, Point<0, Number>> &)
452 {
453  AssertThrow(false, ExcImpossibleInDim(0));
454 }
455 
456 
457 
458 template <typename Number>
459 template <class Container>
460 inline BoundingBox<0, Number>::BoundingBox(const Container &)
461 {
462  AssertThrow(false, ExcImpossibleInDim(0));
463 }
464 
465 
466 
467 #endif // DOXYGEN
469 
470 #endif
Iterator lower_bound(Iterator first, Iterator last, const T &val)
Definition: utilities.h:1075
NeighborType
Definition: bounding_box.h:37
double volume(const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping=(StaticMappingQ1< dim, spacedim >::mapping))
Definition: grid_tools.cc:134
void extend(const Number &amount)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1648
#define AssertThrow(cond, exc)
Definition: exceptions.h:1533
int coordinate_to_one_dim_higher(const int locked_coordinate, const int coordinate_in_dim)
Definition: bounding_box.h:372
Definition: point.h:110
SymmetricTensor< 2, dim, Number > epsilon(const Tensor< 2, dim, Number > &Grad_u)
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Definition: config.h:382
BoundingBox()=default
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1423
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:369
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > boundary_points
Definition: bounding_box.h:296
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition: utilities.cc:188
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
BoundingBox< dim, Number > create_unit_bounding_box()
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
Definition: config.h:419
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:368
void serialize(Archive &ar, const unsigned int version)
Point< 3 > center