Reference documentation for deal.II version GIT 6dd81a2340 2022-11-29 05:55:02+00:00
\(\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 
25 #include <limits>
26 
28 
33 enum class NeighborType
34 {
38  not_neighbors = 0,
39 
45  simple_neighbors = 1,
46 
53 
65 };
66 
131 template <int spacedim, typename Number = double>
133 {
134 public:
139  BoundingBox() = default;
140 
147  &boundary_points);
148 
156  template <class Container>
157  BoundingBox(const Container &points);
158 
162  std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
164 
168  const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
170 
174  bool
176 
180  bool
182 
191  const BoundingBox<spacedim, Number> &other_bbox,
192  const double tolerance = std::numeric_limits<Number>::epsilon()) const;
193 
199  void
200  merge_with(const BoundingBox<spacedim, Number> &other_bbox);
201 
208  bool
209  point_inside(
210  const Point<spacedim, Number> &p,
211  const double tolerance = std::numeric_limits<Number>::epsilon()) const;
212 
223  void
224  extend(const Number amount);
225 
229  double
230  volume() const;
231 
236  center() const;
237 
241  Number
242  side_length(const unsigned int direction) const;
243 
247  Number
248  lower_bound(const unsigned int direction) const;
249 
253  Number
254  upper_bound(const unsigned int direction) const;
255 
260  bounds(const unsigned int direction) const;
261 
267  vertex(const unsigned int index) const;
268 
274  child(const unsigned int index) const;
275 
283  BoundingBox<spacedim - 1, Number>
284  cross_section(const unsigned int direction) const;
285 
296 
307 
313  template <class Archive>
314  void
315  serialize(Archive &ar, const unsigned int version);
316 
317 private:
318  std::pair<Point<spacedim, Number>, Point<spacedim, Number>> boundary_points;
319 };
320 
326 template <typename Number>
327 class BoundingBox<0, Number>
328 {
329 public:
334 
339 
343  template <class Container>
344  BoundingBox(const Container &);
345 };
346 
347 
353 template <int dim, typename Number = double>
356 
357 
358 namespace internal
359 {
392  template <int dim>
393  inline int
394  coordinate_to_one_dim_higher(const int locked_coordinate,
395  const int coordinate_in_dim)
396  {
397  AssertIndexRange(locked_coordinate, dim + 1);
398  AssertIndexRange(coordinate_in_dim, dim);
399  return (locked_coordinate + coordinate_in_dim + 1) % (dim + 1);
400  }
401 
402 } // namespace internal
403 
404 /*------------------------ Inline functions: BoundingBox --------------------*/
405 
406 #ifndef DOXYGEN
407 
408 
409 template <int spacedim, typename Number>
412  &boundary_points)
413 {
414  // We check the Bounding Box is not degenerate
415  for (unsigned int i = 0; i < spacedim; ++i)
416  Assert(boundary_points.first[i] <= boundary_points.second[i],
417  ExcMessage("Bounding Box can't be created: the points' "
418  "order should be bottom left, top right!"));
419 
420  this->boundary_points = boundary_points;
421 }
422 
423 
424 
425 template <int spacedim, typename Number>
426 template <class Container>
427 inline BoundingBox<spacedim, Number>::BoundingBox(const Container &points)
428 {
429  // Use the default constructor in case points is empty instead of setting
430  // things to +oo and -oo
431  if (points.size() > 0)
432  {
433  auto &min = boundary_points.first;
434  auto &max = boundary_points.second;
435  std::fill(min.begin_raw(),
436  min.end_raw(),
437  std::numeric_limits<Number>::infinity());
438  std::fill(max.begin_raw(),
439  max.end_raw(),
440  -std::numeric_limits<Number>::infinity());
441 
442  for (const Point<spacedim, Number> &point : points)
443  for (unsigned int d = 0; d < spacedim; ++d)
444  {
445  min[d] = std::min(min[d], point[d]);
446  max[d] = std::max(max[d], point[d]);
447  }
448  }
449 }
450 
451 
452 
453 template <int spacedim, typename Number>
454 inline std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
456 {
457  return this->boundary_points;
458 }
459 
460 
461 
462 template <int spacedim, typename Number>
463 inline const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
465 {
466  return this->boundary_points;
467 }
468 
469 
470 
471 template <int spacedim, typename Number>
472 inline bool
474  const BoundingBox<spacedim, Number> &box) const
475 {
476  return boundary_points == box.boundary_points;
477 }
478 
479 
480 
481 template <int spacedim, typename Number>
482 inline bool
484  const BoundingBox<spacedim, Number> &box) const
485 {
486  return boundary_points != box.boundary_points;
487 }
488 
489 
490 
491 template <int spacedim, typename Number>
492 inline void
493 BoundingBox<spacedim, Number>::extend(const Number amount)
494 {
495  for (unsigned int d = 0; d < spacedim; ++d)
496  {
497  boundary_points.first[d] -= amount;
498  boundary_points.second[d] += amount;
499  Assert(boundary_points.first[d] <= boundary_points.second[d],
500  ExcMessage("Bounding Box can't be shrunk this much: the points' "
501  "order should remain bottom left, top right."));
502  }
503 }
504 
505 
506 template <int spacedim, typename Number>
507 template <class Archive>
508 void
510  const unsigned int /*version*/)
511 {
512  ar &boundary_points;
513 }
514 
515 
516 
517 template <typename Number>
519 {
520  AssertThrow(false, ExcImpossibleInDim(0));
521 }
522 
523 
524 
525 template <typename Number>
527  const std::pair<Point<0, Number>, Point<0, Number>> &)
528 {
529  AssertThrow(false, ExcImpossibleInDim(0));
530 }
531 
532 
533 
534 template <typename Number>
535 template <class Container>
536 inline BoundingBox<0, Number>::BoundingBox(const Container &)
537 {
538  AssertThrow(false, ExcImpossibleInDim(0));
539 }
540 
541 
542 
543 #endif // DOXYGEN
545 
546 #endif
NeighborType
Definition: bounding_box.h:34
BoundingBox(const std::pair< Point< 0, Number >, Point< 0, Number >> &)
BoundingBox(const Container &)
int coordinate_to_one_dim_higher(const int locked_coordinate, const int coordinate_in_dim)
Definition: bounding_box.h:394
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > boundary_points
Definition: bounding_box.h:318
BoundingBox< 1, Number > bounds(const unsigned int direction) const
const std::pair< Point< spacedim, Number >, Point< spacedim, Number > > & get_boundary_points() const
BoundingBox< dim, Number > create_unit_bounding_box()
Point< spacedim, Number > center() const
BoundingBox()=default
Number lower_bound(const unsigned int direction) const
bool operator==(const BoundingBox< spacedim, Number > &box) const
void serialize(Archive &ar, const unsigned int version)
void merge_with(const BoundingBox< spacedim, Number > &other_bbox)
Definition: bounding_box.cc:48
bool point_inside(const Point< spacedim, Number > &p, const double tolerance=std::numeric_limits< Number >::epsilon()) const
Definition: bounding_box.cc:25
double volume() const
void extend(const Number amount)
BoundingBox(const Container &points)
Point< spacedim, Number > real_to_unit(const Point< spacedim, Number > &point) const
Number side_length(const unsigned int direction) const
BoundingBox(const std::pair< Point< spacedim, Number >, Point< spacedim, Number >> &boundary_points)
BoundingBox< spacedim, Number > child(const unsigned int index) const
bool operator!=(const BoundingBox< spacedim, Number > &box) const
NeighborType get_neighbor_type(const BoundingBox< spacedim, Number > &other_bbox, const double tolerance=std::numeric_limits< Number >::epsilon()) const
Definition: bounding_box.cc:66
Point< spacedim, Number > vertex(const unsigned int index) const
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > & get_boundary_points()
BoundingBox< spacedim - 1, Number > cross_section(const unsigned int direction) const
Number upper_bound(const unsigned int direction) const
Point< spacedim, Number > unit_to_real(const Point< spacedim, Number > &point) const
VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &x, const ::VectorizedArray< Number, width > &y)
VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &x, const ::VectorizedArray< Number, width > &y)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:458
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:459
#define Assert(cond, exc)
Definition: exceptions.h:1501
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1760
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Definition: exceptions.h:1611
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition: utilities.cc:189
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > epsilon(const Tensor< 2, dim, Number > &Grad_u)