Reference documentation for deal.II version Git 4fbb5374f0 2021-01-22 15:02:13 -0500
\(\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 
32 enum class NeighborType
33 {
37  not_neighbors = 0,
38 
44  simple_neighbors = 1,
45 
52 
64 };
65 
120 template <int spacedim, typename Number = double>
122 {
123 public:
128  BoundingBox() = default;
129 
136  &boundary_points);
137 
145  template <class Container>
146  BoundingBox(const Container &points);
147 
151  std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
152  get_boundary_points();
153 
157  const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
158  get_boundary_points() const;
159 
163  bool
164  operator==(const BoundingBox<spacedim, Number> &box) const;
165 
169  bool
170  operator!=(const BoundingBox<spacedim, Number> &box) const;
171 
179  get_neighbor_type(const BoundingBox<spacedim, Number> &other_bbox) const;
180 
186  void
187  merge_with(const BoundingBox<spacedim, Number> &other_bbox);
188 
195  bool
196  point_inside(
197  const Point<spacedim, Number> &p,
198  const double tolerance = std::numeric_limits<Number>::epsilon()) const;
199 
210  void
211  extend(const Number &amount);
212 
216  double
217  volume() const;
218 
223  center() const;
224 
228  Number
229  side_length(const unsigned int direction) const;
230 
234  Number
235  lower_bound(const unsigned int direction) const;
236 
240  Number
241  upper_bound(const unsigned int direction) const;
242 
247  bounds(const unsigned int direction) const;
248 
254  vertex(const unsigned int index) const;
255 
261  child(const unsigned int index) const;
262 
270  BoundingBox<spacedim - 1, Number>
271  cross_section(const unsigned int direction) const;
272 
282  real_to_unit(const Point<spacedim, Number> &point) const;
283 
293  unit_to_real(const Point<spacedim, Number> &point) const;
294 
300  template <class Archive>
301  void
302  serialize(Archive &ar, const unsigned int version);
303 
304 private:
305  std::pair<Point<spacedim, Number>, Point<spacedim, Number>> boundary_points;
306 };
307 
313 template <typename Number>
314 class BoundingBox<0, Number>
315 {
316 public:
320  BoundingBox();
321 
325  BoundingBox(const std::pair<Point<0, Number>, Point<0, Number>> &);
326 
330  template <class Container>
331  BoundingBox(const Container &);
332 };
333 
334 
340 template <int dim, typename Number = double>
343 
344 
345 namespace internal
346 {
379  template <int dim>
380  inline int
381  coordinate_to_one_dim_higher(const int locked_coordinate,
382  const int coordinate_in_dim)
383  {
384  AssertIndexRange(locked_coordinate, dim + 1);
385  AssertIndexRange(coordinate_in_dim, dim);
386  return (locked_coordinate + coordinate_in_dim + 1) % (dim + 1);
387  }
388 
389 } // namespace internal
390 
391 /*------------------------ Inline functions: BoundingBox --------------------*/
392 
393 #ifndef DOXYGEN
394 
395 
396 template <int spacedim, typename Number>
399  &boundary_points)
400 {
401  // We check the Bounding Box is not degenerate
402  for (unsigned int i = 0; i < spacedim; ++i)
403  Assert(boundary_points.first[i] <= boundary_points.second[i],
404  ExcMessage("Bounding Box can't be created: the points' "
405  "order should be bottom left, top right!"));
406 
407  this->boundary_points = boundary_points;
408 }
409 
410 
411 
412 template <int spacedim, typename Number>
413 template <class Container>
414 inline BoundingBox<spacedim, Number>::BoundingBox(const Container &points)
415 {
416  // Use the default constructor in case points is empty instead of setting
417  // things to +oo and -oo
418  if (points.size() > 0)
419  {
420  auto &min = boundary_points.first;
421  auto &max = boundary_points.second;
422  std::fill(min.begin_raw(),
423  min.end_raw(),
424  std::numeric_limits<Number>::infinity());
425  std::fill(max.begin_raw(),
426  max.end_raw(),
427  -std::numeric_limits<Number>::infinity());
428 
429  for (const Point<spacedim, Number> &point : points)
430  for (unsigned int d = 0; d < spacedim; ++d)
431  {
432  min[d] = std::min(min[d], point[d]);
433  max[d] = std::max(max[d], point[d]);
434  }
435  }
436 }
437 
438 
439 
440 template <int spacedim, typename Number>
441 inline bool
444 {
445  return boundary_points == box.boundary_points;
446 }
447 
448 
449 
450 template <int spacedim, typename Number>
451 inline bool
454 {
455  return boundary_points != box.boundary_points;
456 }
457 
458 
459 
460 template <int spacedim, typename Number>
461 inline void
462 BoundingBox<spacedim, Number>::extend(const Number &amount)
463 {
464  for (unsigned int d = 0; d < spacedim; ++d)
465  {
466  boundary_points.first[d] -= amount;
467  boundary_points.second[d] += amount;
468  Assert(boundary_points.first[d] <= boundary_points.second[d],
469  ExcMessage("Bounding Box can't be shrunk this much: the points' "
470  "order should remain bottom left, top right."));
471  }
472 }
473 
474 
475 template <int spacedim, typename Number>
476 template <class Archive>
477 void
479  const unsigned int /*version*/)
480 {
481  ar &boundary_points;
482 }
483 
484 
485 
486 template <typename Number>
488 {
489  AssertThrow(false, ExcImpossibleInDim(0));
490 }
491 
492 
493 
494 template <typename Number>
496  const std::pair<Point<0, Number>, Point<0, Number>> &)
497 {
498  AssertThrow(false, ExcImpossibleInDim(0));
499 }
500 
501 
502 
503 template <typename Number>
504 template <class Container>
505 inline BoundingBox<0, Number>::BoundingBox(const Container &)
506 {
507  AssertThrow(false, ExcImpossibleInDim(0));
508 }
509 
510 
511 
512 #endif // DOXYGEN
514 
515 #endif
Iterator lower_bound(Iterator first, Iterator last, const T &val)
Definition: utilities.h:1075
NeighborType
Definition: bounding_box.h:32
bool operator!=(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
void extend(const Number &amount)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1691
#define AssertThrow(cond, exc)
Definition: exceptions.h:1576
int coordinate_to_one_dim_higher(const int locked_coordinate, const int coordinate_in_dim)
Definition: bounding_box.h:381
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:1466
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:380
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > boundary_points
Definition: bounding_box.h:305
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()
double volume(const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping=ReferenceCell::get_default_linear_mapping< dim, spacedim >(ReferenceCell::Type::get_hypercube< dim >()))
Definition: grid_tools.cc:134
bool operator!=(const BoundingBox< spacedim, Number > &box) const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:379
T min(const T &t, const MPI_Comm &mpi_communicator)
bool operator==(const BoundingBox< spacedim, Number > &box) const
void serialize(Archive &ar, const unsigned int version)
Point< 3 > center
T max(const T &t, const MPI_Comm &mpi_communicator)