Reference documentation for deal.II version Git 08727cc441 2020-07-02 15:45:42 -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 
269  template <class Archive>
270  void
271  serialize(Archive &ar, const unsigned int version);
272 
273 private:
274  std::pair<Point<spacedim, Number>, Point<spacedim, Number>> boundary_points;
275 };
276 
282 template <typename Number>
283 class BoundingBox<0, Number>
284 {
285 public:
289  BoundingBox();
290 
294  BoundingBox(const std::pair<Point<0, Number>, Point<0, Number>> &);
295 
299  template <class Container>
300  BoundingBox(const Container &);
301 };
302 
303 
309 template <int dim, typename Number = double>
312 
313 
314 namespace internal
315 {
348  template <int dim>
349  inline unsigned int
350  coordinate_to_one_dim_higher(const unsigned int locked_coordinate,
351  const unsigned int coordiante_in_dim)
352  {
353  AssertIndexRange(locked_coordinate, dim + 1);
354  AssertIndexRange(coordiante_in_dim, dim);
355  return (locked_coordinate + coordiante_in_dim + 1) % (dim + 1);
356  }
357 
358 } // namespace internal
359 
360 /*------------------------ Inline functions: BoundingBox --------------------*/
361 
362 #ifndef DOXYGEN
363 
364 
365 template <int spacedim, typename Number>
368  &boundary_points)
369 {
370  // We check the Bounding Box is not degenerate
371  for (unsigned int i = 0; i < spacedim; ++i)
372  Assert(boundary_points.first[i] <= boundary_points.second[i],
373  ExcMessage("Bounding Box can't be created: the points' "
374  "order should be bottom left, top right!"));
375 
376  this->boundary_points = boundary_points;
377 }
378 
379 
380 
381 template <int spacedim, typename Number>
382 template <class Container>
383 inline BoundingBox<spacedim, Number>::BoundingBox(const Container &points)
384 {
385  boost::geometry::envelope(
386  boost::geometry::model::multi_point<Point<spacedim, Number>>(points.begin(),
387  points.end()),
388  *this);
389 }
390 
391 
392 
393 template <int spacedim, typename Number>
394 inline void
395 BoundingBox<spacedim, Number>::extend(const Number &amount)
396 {
397  for (unsigned int d = 0; d < spacedim; ++d)
398  {
399  boundary_points.first[d] -= amount;
400  boundary_points.second[d] += amount;
401  Assert(boundary_points.first[d] <= boundary_points.second[d],
402  ExcMessage("Bounding Box can't be shrunk this much: the points' "
403  "order should remain bottom left, top right."));
404  }
405 }
406 
407 
408 template <int spacedim, typename Number>
409 template <class Archive>
410 void
412  const unsigned int /*version*/)
413 {
414  ar &boundary_points;
415 }
416 
417 
418 
419 template <typename Number>
421 {
422  AssertThrow(false, ExcImpossibleInDim(0));
423 }
424 
425 
426 
427 template <typename Number>
429  const std::pair<Point<0, Number>, Point<0, Number>> &)
430 {
431  AssertThrow(false, ExcImpossibleInDim(0));
432 }
433 
434 
435 
436 template <typename Number>
437 template <class Container>
438 inline BoundingBox<0, Number>::BoundingBox(const Container &)
439 {
440  AssertThrow(false, ExcImpossibleInDim(0));
441 }
442 
443 
444 
445 #endif // DOXYGEN
447 
448 #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:135
void extend(const Number &amount)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1628
#define AssertThrow(cond, exc)
Definition: exceptions.h:1513
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:376
BoundingBox()=default
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1403
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > boundary_points
Definition: bounding_box.h:274
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:413
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
void serialize(Archive &ar, const unsigned int version)
Point< 3 > center
unsigned int coordinate_to_one_dim_higher(const unsigned int locked_coordinate, const unsigned int coordiante_in_dim)
Definition: bounding_box.h:350