deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17:20:01+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\}}\)
Loading...
Searching...
No Matches
bounding_box.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2017 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_base_bounding_box_h
14#define dealii_base_bounding_box_h
15
16
17#include <deal.II/base/config.h>
18
21#include <deal.II/base/point.h>
22
23#include <Kokkos_Macros.hpp>
24
25#include <algorithm>
26#include <iterator>
27#include <limits>
28#include <string>
29#include <utility>
30
32
37enum class NeighborType
38{
42 not_neighbors = 0,
43
51
59
73};
74
139template <int spacedim, typename Number = double>
141{
142public:
147 static constexpr unsigned int dimension = spacedim;
148
153 BoundingBox() = default;
154
159
165
170
178
186 template <class Container>
187 BoundingBox(const Container &points);
188
192 std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
194
198 const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
200
204 bool
206
210 bool
212
217 bool
219 const BoundingBox<spacedim, Number> &other_bbox,
220 const double tolerance = std::numeric_limits<Number>::epsilon()) const;
221
227 const BoundingBox<spacedim, Number> &other_bbox,
228 const double tolerance = std::numeric_limits<Number>::epsilon()) const;
229
235 void
236 merge_with(const BoundingBox<spacedim, Number> &other_bbox);
237
244 bool
247 const double tolerance = std::numeric_limits<Number>::epsilon()) const;
248
259 void
260 extend(const Number amount);
261
267 create_extended(const Number amount) const;
268
283 create_extended_relative(const Number relative_amount) const;
284
288 double
289 volume() const;
290
295 center() const;
296
300 Number
301 side_length(const unsigned int direction) const;
302
306 Number
307 lower_bound(const unsigned int direction) const;
308
312 Number
313 upper_bound(const unsigned int direction) const;
314
319 bounds(const unsigned int direction) const;
320
326 vertex(const unsigned int index) const;
327
333 child(const unsigned int index) const;
334
342 BoundingBox<spacedim - 1, Number>
343 cross_section(const unsigned int direction) const;
344
354 real_to_unit(const Point<spacedim, Number> &point) const;
355
365 unit_to_real(const Point<spacedim, Number> &point) const;
373 Number
375 const unsigned int direction) const;
376
382 Number
383 signed_distance(const Point<spacedim, Number> &point) const;
384
390 template <class Archive>
391 void
392 serialize(Archive &ar, const unsigned int version);
393
394private:
395 std::pair<Point<spacedim, Number>, Point<spacedim, Number>> boundary_points;
396};
397
403template <typename Number>
404class BoundingBox<0, Number>
405{
406public:
411
416
420 template <class Container>
421 BoundingBox(const Container &);
422};
423
424
430template <int dim, typename Number = double>
433
434
435namespace internal
436{
469 template <int dim>
470 inline int
471 coordinate_to_one_dim_higher(const int locked_coordinate,
472 const int coordinate_in_dim)
473 {
474 AssertIndexRange(locked_coordinate, dim + 1);
475 AssertIndexRange(coordinate_in_dim, dim);
476 return (locked_coordinate + coordinate_in_dim + 1) % (dim + 1);
477 }
478
479} // namespace internal
480
481/*------------------------ Inline functions: BoundingBox --------------------*/
482
483#ifndef DOXYGEN
484
485
486template <int spacedim, typename Number>
489 : BoundingBox({p, p})
490{}
491
492
493
494template <int spacedim, typename Number>
497 &boundary_points)
498{
499 // We check the Bounding Box is not degenerate
500 for (unsigned int i = 0; i < spacedim; ++i)
501 Assert(boundary_points.first[i] <= boundary_points.second[i],
502 ExcMessage("Bounding Box can't be created: the points' "
503 "order should be bottom left, top right!"));
504
505 this->boundary_points = boundary_points;
506}
507
508
509
510template <int spacedim, typename Number>
511template <class Container>
512inline BoundingBox<spacedim, Number>::BoundingBox(const Container &points)
513{
514 // Use the default constructor in case points is empty instead of setting
515 // things to +oo and -oo
516 if (points.size() > 0)
517 {
518 auto &min = boundary_points.first;
519 auto &max = boundary_points.second;
520 for (unsigned int d = 0; d < spacedim; ++d)
521 {
522 min[d] = std::numeric_limits<Number>::infinity();
523 max[d] = -std::numeric_limits<Number>::infinity();
524 }
525
526 for (const Point<spacedim, Number> &point : points)
527 for (unsigned int d = 0; d < spacedim; ++d)
528 {
529 min[d] = std::min(min[d], point[d]);
530 max[d] = std::max(max[d], point[d]);
531 }
532 }
533}
534
535
536
537template <int spacedim, typename Number>
538inline std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
540{
541 return this->boundary_points;
542}
543
544
545
546template <int spacedim, typename Number>
547inline const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
549{
550 return this->boundary_points;
551}
552
553
554
555template <int spacedim, typename Number>
556inline bool
558 const BoundingBox<spacedim, Number> &box) const
559{
560 return boundary_points == box.boundary_points;
561}
562
563
564
565template <int spacedim, typename Number>
566inline bool
568 const BoundingBox<spacedim, Number> &box) const
569{
570 return boundary_points != box.boundary_points;
571}
572
573
574
575template <int spacedim, typename Number>
576inline void
577BoundingBox<spacedim, Number>::extend(const Number amount)
578{
579 for (unsigned int d = 0; d < spacedim; ++d)
580 {
581 boundary_points.first[d] -= amount;
582 boundary_points.second[d] += amount;
583 Assert(boundary_points.first[d] <= boundary_points.second[d],
584 ExcMessage("Bounding Box can't be shrunk this much: the points' "
585 "order should remain bottom left, top right."));
586 }
587}
588
589
590
591template <int spacedim, typename Number>
593BoundingBox<spacedim, Number>::create_extended(const Number amount) const
594{
595 // create and modify copy
596 auto bb = *this;
597 bb.extend(amount);
598
599 return bb;
600}
601
602
603
604template <int spacedim, typename Number>
607 const Number relative_amount) const
608{
609 // create and modify copy
610 auto bb = *this;
611
612 for (unsigned int d = 0; d < spacedim; ++d)
613 {
614 bb.boundary_points.first[d] -= relative_amount * side_length(d);
615 bb.boundary_points.second[d] += relative_amount * side_length(d);
616 Assert(bb.boundary_points.first[d] <= bb.boundary_points.second[d],
617 ExcMessage("Bounding Box can't be shrunk this much: the points' "
618 "order should remain bottom left, top right."));
619 }
620
621 return bb;
622}
623
624
625
626template <int spacedim, typename Number>
627template <class Archive>
628void
630 const unsigned int /*version*/)
631{
632 // Avoid including boost/serialization/utility.hpp by unpacking the pair
633 // ourselves
634 ar &boundary_points.first;
635 ar &boundary_points.second;
636}
637
638
639
640template <typename Number>
642{
644}
645
646
647
648template <typename Number>
650 const std::pair<Point<0, Number>, Point<0, Number>> &)
651{
653}
654
655
656
657template <typename Number>
658template <class Container>
659inline BoundingBox<0, Number>::BoundingBox(const Container &)
660{
662}
663
664
665
666#endif // DOXYGEN
668
669#endif
*  *  for(const auto &cell :triangulation.active_cell_iterators())
NeighborType
BoundingBox< dim, Number > create_unit_bounding_box()
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)
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > boundary_points
BoundingBox< 1, Number > bounds(const unsigned int direction) const
bool has_overlap_with(const BoundingBox< spacedim, Number > &other_bbox, const double tolerance=std::numeric_limits< Number >::epsilon()) const
BoundingBox(const std::pair< Point< spacedim, Number >, Point< spacedim, Number > > &boundary_points)
Point< spacedim, Number > center() const
BoundingBox()=default
Number lower_bound(const unsigned int direction) const
Number signed_distance(const Point< spacedim, Number > &point, 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)
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > & get_boundary_points()
bool point_inside(const Point< spacedim, Number > &p, const double tolerance=std::numeric_limits< Number >::epsilon()) const
double volume() const
void extend(const Number amount)
BoundingBox< spacedim, Number > create_extended_relative(const Number relative_amount) const
BoundingBox(const Container &points)
Point< spacedim, Number > real_to_unit(const Point< spacedim, Number > &point) const
const std::pair< Point< spacedim, Number >, Point< spacedim, Number > > & get_boundary_points() const
static constexpr unsigned int dimension
Number side_length(const unsigned int direction) const
BoundingBox< spacedim, Number > child(const unsigned int index) const
bool operator!=(const BoundingBox< spacedim, Number > &box) const
BoundingBox< spacedim, Number > & operator=(const BoundingBox< spacedim, Number > &t)=default
NeighborType get_neighbor_type(const BoundingBox< spacedim, Number > &other_bbox, const double tolerance=std::numeric_limits< Number >::epsilon()) const
BoundingBox< spacedim, Number > create_extended(const Number amount) const
Point< spacedim, Number > vertex(const unsigned int index) const
BoundingBox(const Point< spacedim, Number > &point)
BoundingBox< spacedim - 1, Number > cross_section(const unsigned int direction) const
BoundingBox(const BoundingBox< spacedim, Number > &box)=default
Number upper_bound(const unsigned int direction) const
Point< spacedim, Number > unit_to_real(const Point< spacedim, Number > &point) const
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define Assert(cond, exc)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)