Reference documentation for deal.II version 9.4.1
\(\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// 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>
25
27
32enum class NeighborType
33{
37 not_neighbors = 0,
38
45
52
64};
65
130template <int spacedim, typename Number = double>
132{
133public:
138 BoundingBox() = default;
139
147
155 template <class Container>
156 BoundingBox(const Container &points);
157
161 std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
163
167 const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
169
173 bool
175
179 bool
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
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
314private:
315 std::pair<Point<spacedim, Number>, Point<spacedim, Number>> boundary_points;
316};
317
323template <typename Number>
324class BoundingBox<0, Number>
325{
326public:
331
336
340 template <class Container>
341 BoundingBox(const Container &);
342};
343
344
350template <int dim, typename Number = double>
353
354
355namespace 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
406template <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
422template <int spacedim, typename Number>
423template <class Container>
424inline 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
450template <int spacedim, typename Number>
451inline std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
453{
454 return this->boundary_points;
455}
456
457
458
459template <int spacedim, typename Number>
460inline const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
462{
463 return this->boundary_points;
464}
465
466
467
468template <int spacedim, typename Number>
469inline bool
471 const BoundingBox<spacedim, Number> &box) const
472{
473 return boundary_points == box.boundary_points;
474}
475
476
477
478template <int spacedim, typename Number>
479inline bool
481 const BoundingBox<spacedim, Number> &box) const
482{
483 return boundary_points != box.boundary_points;
484}
485
486
487
488template <int spacedim, typename Number>
489inline void
490BoundingBox<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
503template <int spacedim, typename Number>
504template <class Archive>
505void
507 const unsigned int /*version*/)
508{
509 ar &boundary_points;
510}
511
512
513
514template <typename Number>
516{
518}
519
520
521
522template <typename Number>
524 const std::pair<Point<0, Number>, Point<0, Number>> &)
525{
527}
528
529
530
531template <typename Number>
532template <class Container>
533inline BoundingBox<0, Number>::BoundingBox(const Container &)
534{
536}
537
538
539
540#endif // DOXYGEN
542
543#endif
NeighborType
Definition: bounding_box.h:33
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)
Definition: bounding_box.h:391
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > boundary_points
Definition: bounding_box.h:315
BoundingBox< 1, Number > bounds(const unsigned int direction) const
BoundingBox(const std::pair< Point< spacedim, Number >, Point< spacedim, Number > > &boundary_points)
NeighborType get_neighbor_type(const BoundingBox< spacedim, Number > &other_bbox) const
Definition: bounding_box.cc:64
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:46
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
Definition: bounding_box.cc:23
double volume() const
void extend(const Number amount)
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
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
Point< spacedim, Number > vertex(const unsigned int index) const
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
Definition: point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
#define Assert(cond, exc)
Definition: exceptions.h:1473
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1732
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Definition: exceptions.h:1583
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 > &)