24template <
int spacedim,
typename Number>
27 const double tolerance)
const
29 for (
unsigned int i = 0; i < spacedim; ++i)
35 this->boundary_points.first[i] - tolerance * side_length(i)) ||
36 (p[i] > this->boundary_points.second[i] + tolerance * side_length(i)))
44template <
int spacedim,
typename Number>
49 for (
unsigned int i = 0; i < spacedim; ++i)
51 this->boundary_points.first[i] =
52 std::min(this->boundary_points.first[i],
54 this->boundary_points.second[i] =
55 std::max(this->boundary_points.second[i],
60template <
int spacedim,
typename Number>
64 const double tolerance)
const
66 for (
unsigned int i = 0; i < spacedim; ++i)
70 this->boundary_points.first[i] - tolerance * side_length(i)) ||
72 this->boundary_points.second[i] + tolerance * side_length(i)))
78template <
int spacedim,
typename Number>
82 const double tolerance)
const
84 if (!has_overlap_with(other_bbox, tolerance))
95 const std::array<Point<spacedim, Number>, 2> bbox1 = {
96 {this->get_boundary_points().first,
97 this->get_boundary_points().second}};
98 const std::array<Point<spacedim, Number>, 2> bbox2 = {
104 std::array<double, spacedim> intersect_bbox_min;
105 std::array<double, spacedim> intersect_bbox_max;
106 for (
unsigned int d = 0; d < spacedim; ++d)
108 intersect_bbox_min[d] =
std::max(bbox1[0][d], bbox2[0][d]);
109 intersect_bbox_max[d] =
std::min(bbox1[1][d], bbox2[1][d]);
113 int intersect_dim = spacedim;
114 for (
unsigned int d = 0; d < spacedim; ++d)
115 if (
std::abs(intersect_bbox_min[d] - intersect_bbox_max[d]) <=
116 tolerance * (
std::abs(intersect_bbox_min[d]) +
120 if (intersect_dim == 0 || intersect_dim == spacedim - 2)
125 unsigned int not_align_1 = 0, not_align_2 = 0;
126 bool same_direction =
true;
127 for (
unsigned int d = 0; d < spacedim; ++d)
129 if (
std::abs(bbox2[0][d] - bbox1[0][d]) >
132 if (
std::abs(bbox1[1][d] - bbox2[1][d]) >
135 if (not_align_1 != not_align_2)
137 same_direction =
false;
142 if (not_align_1 <= 1 && not_align_2 <= 1 && same_direction)
146 if ((this->point_inside(bbox2[0]) && this->point_inside(bbox2[1])) ||
158template <
int spacedim,
typename Number>
163 for (
unsigned int i = 0; i < spacedim; ++i)
164 vol *= (this->boundary_points.second[i] - this->boundary_points.first[i]);
170template <
int spacedim,
typename Number>
176 return boundary_points.first[direction];
181template <
int spacedim,
typename Number>
187 return boundary_points.second[direction];
192template <
int spacedim,
typename Number>
197 for (
unsigned int i = 0; i < spacedim; ++i)
198 point[i] = .5 * (boundary_points.first[i] + boundary_points.second[i]);
205template <
int spacedim,
typename Number>
212 lower_upper_bounds.first[0] = lower_bound(direction);
213 lower_upper_bounds.second[0] = upper_bound(direction);
220template <
int spacedim,
typename Number>
226 return boundary_points.second[direction] - boundary_points.first[direction];
231template <
int spacedim,
typename Number>
241 for (
unsigned int i = 0; i < spacedim; ++i)
242 point[i] = boundary_points.first[i] + side_length(i) * unit_cell_vertex[i];
249template <
int spacedim,
typename Number>
267 child_lower_upper_corner;
268 for (
unsigned int i = 0; i < spacedim; ++i)
270 const double child_side_length = side_length(i) / 2;
272 const double child_center = (parent_center[i] + parent_vertex[i]) / 2;
274 child_lower_upper_corner.first[i] =
275 child_center + child_side_length * (lower_corner_unit_cell[i] - .5);
276 child_lower_upper_corner.second[i] =
277 child_center + child_side_length * (upper_corner_unit_cell[i] - .5);
285template <
int spacedim,
typename Number>
291 std::pair<
Point<spacedim - 1, Number>,
Point<spacedim - 1, Number>>
292 cross_section_lower_upper_corner;
293 for (
unsigned int d = 0; d < spacedim - 1; ++d)
295 const int index_to_write_from =
296 internal::coordinate_to_one_dim_higher<spacedim - 1>(direction, d);
298 cross_section_lower_upper_corner.first[d] =
299 boundary_points.first[index_to_write_from];
301 cross_section_lower_upper_corner.second[d] =
302 boundary_points.second[index_to_write_from];
305 return BoundingBox<spacedim - 1, Number>(cross_section_lower_upper_corner);
310template <
int spacedim,
typename Number>
316 const auto diag = boundary_points.second - boundary_points.first;
317 unit -= boundary_points.first;
318 for (
unsigned int d = 0; d < spacedim; ++d)
325template <
int spacedim,
typename Number>
330 auto real = boundary_points.first;
331 const auto diag = boundary_points.second - boundary_points.first;
332 for (
unsigned int d = 0; d < spacedim; ++d)
333 real[d] += diag[d] * point[d];
339template <
int spacedim,
typename Number>
343 const unsigned int direction)
const
345 const Number p1 = lower_bound(direction);
346 const Number p2 = upper_bound(direction);
348 if (point[direction] > p2)
349 return point[direction] - p2;
350 else if (point[direction] < p1)
351 return p1 - point[direction];
353 return -
std::min(point[direction] - p1, p2 - point[direction]);
358template <
int spacedim,
typename Number>
364 std::array<Number, spacedim> distances;
365 for (
unsigned int d = 0; d < spacedim; ++d)
366 distances[d] = signed_distance(point, d);
369 const unsigned int n_positive_signed_distances =
370 std::count_if(distances.begin(), distances.end(), [](
const auto &a) {
374 if (n_positive_signed_distances <= 1)
379 return *std::max_element(distances.begin(), distances.end());
384 return std::sqrt(std::accumulate(distances.begin(),
387 [](
const auto &a,
const auto &b) {
388 return a + (b > 0 ? b * b : 0.0);
394template <
int dim,
typename Number>
399 for (
unsigned int i = 0; i < dim; ++i)
401 lower_upper_corner.second[i] = 1;
407#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)