Reference documentation for deal.II version Git 418c2197d0 2021-10-27 08:19:48 +0200
\(\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 - 2021 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 
32 enum class NeighborType
33 {
37  not_neighbors = 0,
38 
44  simple_neighbors = 1,
45 
52 
64 };
65 
130 template <int spacedim, typename Number = double>
132 {
133 public:
138  BoundingBox() = default;
139 
146  &boundary_points);
147 
155  template <class Container>
156  BoundingBox(const Container &points);
157 
161  std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
162  get_boundary_points();
163 
167  const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
168  get_boundary_points() const;
169 
173  bool
174  operator==(const BoundingBox<spacedim, Number> &box) const;
175 
179  bool
180  operator!=(const BoundingBox<spacedim, Number> &box) const;
181 
189  get_neighbor_type(const BoundingBox<spacedim, Number> &other_bbox) const;
190 
196  void
197  merge_with(const BoundingBox<spacedim, Number> &other_bbox);
198 
205  bool
206  point_inside(
207  const Point<spacedim, Number> &p,
208  const double tolerance = std::numeric_limits<Number>::epsilon()) const;
209 
220  void
221  extend(const Number amount);
222 
226  double
227  volume() const;
228 
233  center() const;
234 
238  Number
239  side_length(const unsigned int direction) const;
240 
244  Number
245  lower_bound(const unsigned int direction) const;
246 
250  Number
251  upper_bound(const unsigned int direction) const;
252 
257  bounds(const unsigned int direction) const;
258 
264  vertex(const unsigned int index) const;
265 
271  child(const unsigned int index) const;
272 
280  BoundingBox<spacedim - 1, Number>
281  cross_section(const unsigned int direction) const;
282 
292  real_to_unit(const Point<spacedim, Number> &point) const;
293 
303  unit_to_real(const Point<spacedim, Number> &point) const;
304 
310  template <class Archive>
311  void
312  serialize(Archive &ar, const unsigned int version);
313 
314 private:
315  std::pair<Point<spacedim, Number>, Point<spacedim, Number>> boundary_points;
316 };
317 
323 template <typename Number>
324 class BoundingBox<0, Number>
325 {
326 public:
330  BoundingBox();
331 
335  BoundingBox(const std::pair<Point<0, Number>, Point<0, Number>> &);
336 
340  template <class Container>
341  BoundingBox(const Container &);
342 };
343 
344 
350 template <int dim, typename Number = double>
353 
354 
355 namespace internal
356 {
389  template <int dim>
390  inline int
391  coordinate_to_one_dim_higher(const int locked_coordinate,
392  const int coordinate_in_dim)
393  {
394  AssertIndexRange(locked_coordinate, dim + 1);
395  AssertIndexRange(coordinate_in_dim, dim);
396  return (locked_coordinate + coordinate_in_dim + 1) % (dim + 1);
397  }
398 
399 } // namespace internal
400 
401 /*------------------------ Inline functions: BoundingBox --------------------*/
402 
403 #ifndef DOXYGEN
404 
405 
406 template <int spacedim, typename Number>
409  &boundary_points)
410 {
411  // We check the Bounding Box is not degenerate
412  for (unsigned int i = 0; i < spacedim; ++i)
413  Assert(boundary_points.first[i] <= boundary_points.second[i],
414  ExcMessage("Bounding Box can't be created: the points' "
415  "order should be bottom left, top right!"));
416 
417  this->boundary_points = boundary_points;
418 }
419 
420 
421 
422 template <int spacedim, typename Number>
423 template <class Container>
424 inline BoundingBox<spacedim, Number>::BoundingBox(const Container &points)
425 {
426  // Use the default constructor in case points is empty instead of setting
427  // things to +oo and -oo
428  if (points.size() > 0)
429  {
430  auto &min = boundary_points.first;
431  auto &max = boundary_points.second;
432  std::fill(min.begin_raw(),
433  min.end_raw(),
434  std::numeric_limits<Number>::infinity());
435  std::fill(max.begin_raw(),
436  max.end_raw(),
437  -std::numeric_limits<Number>::infinity());
438 
439  for (const Point<spacedim, Number> &point : points)
440  for (unsigned int d = 0; d < spacedim; ++d)
441  {
442  min[d] = std::min(min[d], point[d]);
443  max[d] = std::max(max[d], point[d]);
444  }
445  }
446 }
447 
448 
449 
450 template <int spacedim, typename Number>
451 inline std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
453 {
454  return this->boundary_points;
455 }
456 
457 
458 
459 template <int spacedim, typename Number>
460 inline const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
462 {
463  return this->boundary_points;
464 }
465 
466 
467 
468 template <int spacedim, typename Number>
469 inline bool
471  const BoundingBox<spacedim, Number> &box) const
472 {
473  return boundary_points == box.boundary_points;
474 }
475 
476 
477 
478 template <int spacedim, typename Number>
479 inline bool
481  const BoundingBox<spacedim, Number> &box) const
482 {
483  return boundary_points != box.boundary_points;
484 }
485 
486 
487 
488 template <int spacedim, typename Number>
489 inline void
490 BoundingBox<spacedim, Number>::extend(const Number amount)
491 {
492  for (unsigned int d = 0; d < spacedim; ++d)
493  {
494  boundary_points.first[d] -= amount;
495  boundary_points.second[d] += amount;
496  Assert(boundary_points.first[d] <= boundary_points.second[d],
497  ExcMessage("Bounding Box can't be shrunk this much: the points' "
498  "order should remain bottom left, top right."));
499  }
500 }
501 
502 
503 template <int spacedim, typename Number>
504 template <class Archive>
505 void
507  const unsigned int /*version*/)
508 {
509  ar &boundary_points;
510 }
511 
512 
513 
514 template <typename Number>
516 {
517  AssertThrow(false, ExcImpossibleInDim(0));
518 }
519 
520 
521 
522 template <typename Number>
524  const std::pair<Point<0, Number>, Point<0, Number>> &)
525 {
526  AssertThrow(false, ExcImpossibleInDim(0));
527 }
528 
529 
530 
531 template <typename Number>
532 template <class Container>
533 inline BoundingBox<0, Number>::BoundingBox(const Container &)
534 {
535  AssertThrow(false, ExcImpossibleInDim(0));
536 }
537 
538 
539 
540 #endif // DOXYGEN
542 
543 #endif
Iterator lower_bound(Iterator first, Iterator last, const T &val)
Definition: utilities.h:1112
NeighborType
Definition: bounding_box.h:32
bool operator!=(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1720
#define AssertThrow(cond, exc)
Definition: exceptions.h:1571
int coordinate_to_one_dim_higher(const int locked_coordinate, const int coordinate_in_dim)
Definition: bounding_box.h:391
Definition: point.h:110
bool operator==(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
SymmetricTensor< 2, dim, Number > epsilon(const Tensor< 2, dim, Number > &Grad_u)
BoundingBox()=default
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1461
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:401
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > boundary_points
Definition: bounding_box.h:315
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition: utilities.cc:185
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()
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > & get_boundary_points()
bool operator!=(const BoundingBox< spacedim, Number > &box) const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:400
bool operator==(const BoundingBox< spacedim, Number > &box) const
double volume(const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping=(ReferenceCells::get_hypercube< dim >() .template get_default_linear_mapping< dim, spacedim >()))
Definition: grid_tools.cc:138
void serialize(Archive &ar, const unsigned int version)
Point< 3 > center
void extend(const Number amount)