23template <
int spacedim,
typename Number>
26 const double tolerance)
const
28 for (
unsigned int i = 0; i < spacedim; ++i)
34 this->boundary_points.first[i] - tolerance * side_length(i)) ||
35 (p[i] > this->boundary_points.second[i] + tolerance * side_length(i)))
43template <
int spacedim,
typename Number>
48 for (
unsigned int i = 0; i < spacedim; ++i)
50 this->boundary_points.first[i] =
51 std::min(this->boundary_points.first[i],
53 this->boundary_points.second[i] =
54 std::max(this->boundary_points.second[i],
59template <
int spacedim,
typename Number>
63 const double tolerance)
const
65 for (
unsigned int i = 0; i < spacedim; ++i)
69 this->boundary_points.first[i] - tolerance * side_length(i)) ||
71 this->boundary_points.second[i] + tolerance * side_length(i)))
77template <
int spacedim,
typename Number>
81 const double tolerance)
const
83 if (!has_overlap_with(other_bbox, tolerance))
94 const std::array<Point<spacedim, Number>, 2> bbox1 = {
95 {this->get_boundary_points().first,
96 this->get_boundary_points().second}};
97 const std::array<Point<spacedim, Number>, 2> bbox2 = {
103 std::array<double, spacedim> intersect_bbox_min;
104 std::array<double, spacedim> intersect_bbox_max;
105 for (
unsigned int d = 0; d < spacedim; ++d)
107 intersect_bbox_min[d] =
std::max(bbox1[0][d], bbox2[0][d]);
108 intersect_bbox_max[d] =
std::min(bbox1[1][d], bbox2[1][d]);
112 int intersect_dim = spacedim;
113 for (
unsigned int d = 0; d < spacedim; ++d)
114 if (
std::abs(intersect_bbox_min[d] - intersect_bbox_max[d]) <=
115 tolerance * (
std::abs(intersect_bbox_min[d]) +
119 if (intersect_dim == 0 || intersect_dim == spacedim - 2)
124 unsigned int not_align_1 = 0, not_align_2 = 0;
125 bool same_direction =
true;
126 for (
unsigned int d = 0; d < spacedim; ++d)
128 if (
std::abs(bbox2[0][d] - bbox1[0][d]) >
131 if (
std::abs(bbox1[1][d] - bbox2[1][d]) >
134 if (not_align_1 != not_align_2)
136 same_direction =
false;
141 if (not_align_1 <= 1 && not_align_2 <= 1 && same_direction)
145 if ((this->point_inside(bbox2[0]) && this->point_inside(bbox2[1])) ||
157template <
int spacedim,
typename Number>
162 for (
unsigned int i = 0; i < spacedim; ++i)
163 vol *= (this->boundary_points.second[i] - this->boundary_points.first[i]);
169template <
int spacedim,
typename Number>
175 return boundary_points.first[direction];
180template <
int spacedim,
typename Number>
186 return boundary_points.second[direction];
191template <
int spacedim,
typename Number>
196 for (
unsigned int i = 0; i < spacedim; ++i)
197 point[i] = .5 * (boundary_points.first[i] + boundary_points.second[i]);
204template <
int spacedim,
typename Number>
211 lower_upper_bounds.first[0] = lower_bound(direction);
212 lower_upper_bounds.second[0] = upper_bound(direction);
219template <
int spacedim,
typename Number>
225 return boundary_points.second[direction] - boundary_points.first[direction];
230template <
int spacedim,
typename Number>
240 for (
unsigned int i = 0; i < spacedim; ++i)
241 point[i] = boundary_points.first[i] + side_length(i) * unit_cell_vertex[i];
248template <
int spacedim,
typename Number>
266 child_lower_upper_corner;
267 for (
unsigned int i = 0; i < spacedim; ++i)
269 const double child_side_length = side_length(i) / 2;
271 const double child_center = (parent_center[i] + parent_vertex[i]) / 2;
273 child_lower_upper_corner.first[i] =
274 child_center + child_side_length * (lower_corner_unit_cell[i] - .5);
275 child_lower_upper_corner.second[i] =
276 child_center + child_side_length * (upper_corner_unit_cell[i] - .5);
284template <
int spacedim,
typename Number>
290 std::pair<
Point<spacedim - 1, Number>,
Point<spacedim - 1, Number>>
291 cross_section_lower_upper_corner;
292 for (
unsigned int d = 0; d < spacedim - 1; ++d)
294 const int index_to_write_from =
295 internal::coordinate_to_one_dim_higher<spacedim - 1>(direction, d);
297 cross_section_lower_upper_corner.first[d] =
298 boundary_points.first[index_to_write_from];
300 cross_section_lower_upper_corner.second[d] =
301 boundary_points.second[index_to_write_from];
304 return BoundingBox<spacedim - 1, Number>(cross_section_lower_upper_corner);
309template <
int spacedim,
typename Number>
315 const auto diag = boundary_points.second - boundary_points.first;
316 unit -= boundary_points.first;
317 for (
unsigned int d = 0; d < spacedim; ++d)
324template <
int spacedim,
typename Number>
329 auto real = boundary_points.first;
330 const auto diag = boundary_points.second - boundary_points.first;
331 for (
unsigned int d = 0; d < spacedim; ++d)
332 real[d] += diag[d] * point[d];
338template <
int spacedim,
typename Number>
342 const unsigned int direction)
const
344 const Number p1 = lower_bound(direction);
345 const Number p2 = upper_bound(direction);
347 if (point[direction] > p2)
348 return point[direction] - p2;
349 else if (point[direction] < p1)
350 return p1 - point[direction];
352 return -
std::min(point[direction] - p1, p2 - point[direction]);
357template <
int spacedim,
typename Number>
363 std::array<Number, spacedim> distances;
364 for (
unsigned int d = 0; d < spacedim; ++d)
365 distances[d] = signed_distance(point, d);
368 const unsigned int n_positive_signed_distances =
369 std::count_if(distances.begin(), distances.end(), [](
const auto &a) {
373 if (n_positive_signed_distances <= 1)
378 return *std::max_element(distances.begin(), distances.end());
383 return std::sqrt(std::accumulate(distances.begin(),
386 [](
const auto &a,
const auto &b) {
387 return a + (b > 0 ? b * b : 0.0);
393template <
int dim,
typename Number>
398 for (
unsigned int i = 0; i < dim; ++i)
400 lower_upper_corner.second[i] = 1;
406#include "bounding_box.inst"
BoundingBox< dim, Number > create_unit_bounding_box()
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
Point< spacedim, Number > center() const
Number lower_bound(const unsigned int direction) const
Number signed_distance(const Point< spacedim, Number > &point, const unsigned int direction) const
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
Point< spacedim, Number > real_to_unit(const Point< spacedim, Number > &point) const
Number side_length(const unsigned int direction) const
BoundingBox< spacedim, Number > child(const unsigned int index) const
NeighborType get_neighbor_type(const BoundingBox< spacedim, Number > &other_bbox, const double tolerance=std::numeric_limits< Number >::epsilon()) 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
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define AssertIndexRange(index, range)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
static Point< dim > unit_cell_vertex(const unsigned int vertex)