21template <
int spacedim,
typename Number>
24 const double tolerance)
const
26 for (
unsigned int i = 0; i < spacedim; ++i)
32 this->boundary_points.first[i] - tolerance * side_length(i)) ||
33 (p[i] > this->boundary_points.second[i] + tolerance * side_length(i)))
41template <
int spacedim,
typename Number>
46 for (
unsigned int i = 0; i < spacedim; ++i)
48 this->boundary_points.first[i] =
49 std::min(this->boundary_points.first[i],
51 this->boundary_points.second[i] =
52 std::max(this->boundary_points.second[i],
57template <
int spacedim,
typename Number>
61 const double tolerance)
const
63 for (
unsigned int i = 0; i < spacedim; ++i)
67 this->boundary_points.first[i] - tolerance * side_length(i)) ||
69 this->boundary_points.second[i] + tolerance * side_length(i)))
75template <
int spacedim,
typename Number>
79 const double tolerance)
const
81 if (!has_overlap_with(other_bbox, tolerance))
92 const std::array<Point<spacedim, Number>, 2> bbox1 = {
93 {this->get_boundary_points().first,
94 this->get_boundary_points().second}};
95 const std::array<Point<spacedim, Number>, 2> bbox2 = {
101 std::array<double, spacedim> intersect_bbox_min;
102 std::array<double, spacedim> intersect_bbox_max;
103 for (
unsigned int d = 0; d < spacedim; ++d)
105 intersect_bbox_min[d] =
std::max(bbox1[0][d], bbox2[0][d]);
106 intersect_bbox_max[d] =
std::min(bbox1[1][d], bbox2[1][d]);
110 int intersect_dim = spacedim;
111 for (
unsigned int d = 0; d < spacedim; ++d)
112 if (
std::abs(intersect_bbox_min[d] - intersect_bbox_max[d]) <=
113 tolerance * (
std::abs(intersect_bbox_min[d]) +
117 if (intersect_dim == 0 || intersect_dim == spacedim - 2)
122 unsigned int not_align_1 = 0, not_align_2 = 0;
123 bool same_direction =
true;
124 for (
unsigned int d = 0; d < spacedim; ++d)
126 if (
std::abs(bbox2[0][d] - bbox1[0][d]) >
129 if (
std::abs(bbox1[1][d] - bbox2[1][d]) >
132 if (not_align_1 != not_align_2)
134 same_direction =
false;
139 if (not_align_1 <= 1 && not_align_2 <= 1 && same_direction)
143 if ((this->point_inside(bbox2[0]) && this->point_inside(bbox2[1])) ||
155template <
int spacedim,
typename Number>
160 for (
unsigned int i = 0; i < spacedim; ++i)
161 vol *= (this->boundary_points.second[i] - this->boundary_points.first[i]);
167template <
int spacedim,
typename Number>
173 return boundary_points.first[direction];
178template <
int spacedim,
typename Number>
184 return boundary_points.second[direction];
189template <
int spacedim,
typename Number>
194 for (
unsigned int i = 0; i < spacedim; ++i)
195 point[i] = .5 * (boundary_points.first[i] + boundary_points.second[i]);
202template <
int spacedim,
typename Number>
209 lower_upper_bounds.first[0] = lower_bound(direction);
210 lower_upper_bounds.second[0] = upper_bound(direction);
217template <
int spacedim,
typename Number>
223 return boundary_points.second[direction] - boundary_points.first[direction];
228template <
int spacedim,
typename Number>
238 for (
unsigned int i = 0; i < spacedim; ++i)
239 point[i] = boundary_points.first[i] + side_length(i) * unit_cell_vertex[i];
246template <
int spacedim,
typename Number>
264 child_lower_upper_corner;
265 for (
unsigned int i = 0; i < spacedim; ++i)
267 const double child_side_length = side_length(i) / 2;
269 const double child_center = (parent_center[i] + parent_vertex[i]) / 2;
271 child_lower_upper_corner.first[i] =
272 child_center + child_side_length * (lower_corner_unit_cell[i] - .5);
273 child_lower_upper_corner.second[i] =
274 child_center + child_side_length * (upper_corner_unit_cell[i] - .5);
282template <
int spacedim,
typename Number>
288 std::pair<
Point<spacedim - 1, Number>,
Point<spacedim - 1, Number>>
289 cross_section_lower_upper_corner;
290 for (
unsigned int d = 0; d < spacedim - 1; ++d)
292 const int index_to_write_from =
293 internal::coordinate_to_one_dim_higher<spacedim - 1>(direction, d);
295 cross_section_lower_upper_corner.first[d] =
296 boundary_points.first[index_to_write_from];
298 cross_section_lower_upper_corner.second[d] =
299 boundary_points.second[index_to_write_from];
302 return BoundingBox<spacedim - 1, Number>(cross_section_lower_upper_corner);
307template <
int spacedim,
typename Number>
313 const auto diag = boundary_points.second - boundary_points.first;
314 unit -= boundary_points.first;
315 for (
unsigned int d = 0; d < spacedim; ++d)
322template <
int spacedim,
typename Number>
327 auto real = boundary_points.first;
328 const auto diag = boundary_points.second - boundary_points.first;
329 for (
unsigned int d = 0; d < spacedim; ++d)
330 real[d] += diag[d] * point[d];
336template <
int spacedim,
typename Number>
340 const unsigned int direction)
const
342 const Number p1 = lower_bound(direction);
343 const Number p2 = upper_bound(direction);
345 if (point[direction] > p2)
346 return point[direction] - p2;
347 else if (point[direction] < p1)
348 return p1 - point[direction];
350 return -
std::min(point[direction] - p1, p2 - point[direction]);
355template <
int spacedim,
typename Number>
361 std::array<Number, spacedim> distances;
362 for (
unsigned int d = 0; d < spacedim; ++d)
363 distances[d] = signed_distance(point, d);
366 const unsigned int n_positive_signed_distances =
367 std::count_if(distances.begin(), distances.end(), [](
const auto &a) {
371 if (n_positive_signed_distances <= 1)
376 return *std::max_element(distances.begin(), distances.end());
381 return std::sqrt(std::accumulate(distances.begin(),
384 [](
const auto &a,
const auto &b) {
385 return a + (b > 0 ? b * b : 0.0);
391template <
int dim,
typename Number>
396 for (
unsigned int i = 0; i < dim; ++i)
398 lower_upper_corner.second[i] = 1;
404#include "base/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)