10#include <deal.II/base/auto_derivative_function.h>
11#include <deal.II/base/function.h>
13#include <deal.II/grid/manifold.h>
14#include <deal.II/grid/manifold_lib.h>
16#include <boost/range/adaptor/map.hpp>
18#ifdef DEAL_II_WITH_OPENCASCADE
19# include <deal.II/opencascade/manifold_lib.h>
20# include <deal.II/opencascade/utilities.h>
22# include <BRepBuilderAPI_MakeVertex.hxx>
23# include <BRepClass3d_SolidClassifier.hxx>
24# include <BRepExtrema_DistShapeShape.hxx>
25# include <BRepGProp.hxx>
26# include <GProp_GProps.hxx>
29#include <deal.II/base/function_signed_distance.h>
31#include <deal.II/dofs/dof_handler.h>
32#include <deal.II/dofs/dof_tools.h>
34#include <deal.II/physics/transformations.h>
52class Shape :
public AutoDerivativeFunction<dim>
90 : AutoDerivativeFunction<dim>(1e-8)
108 value(
const Point<dim> &evaluation_point,
109 const unsigned int component = 0)
const override = 0;
121 const Point<dim> &evaluation_point,
122 const typename DoFHandler<dim>::active_cell_iterator &cell,
123 const unsigned int component = 0);
132 smooth_max(
const double a,
const double b,
const double smooth_factor = 10)
134 return (a * std::exp(a * smooth_factor) + b * std::exp(b * smooth_factor)) /
135 ((std::exp(a * smooth_factor) + std::exp(b * smooth_factor)));
146 virtual std::tuple<double, Tensor<1, dim>, Point<dim>>
149 const typename DoFHandler<dim>::active_cell_iterator &cell,
150 std::vector<Point<dim>> &candidate_points,
151 double precision = 1e-6,
152 bool exact_distance_outside_of_contact =
false)
155 double distance = DBL_MAX;
156 Tensor<1, dim> normal;
157 Point<dim> contact_point;
162 if (exact_distance_outside_of_contact ==
false)
164 Point<dim> bounding_box_center_one;
165 Point<dim> bounding_box_center_two;
172 radius_one = radius_two;
176 radius_two = radius_one;
178 if constexpr (dim == 3)
180 bounding_box_center_one =
183 bounding_box_center_two =
189 bounding_box_center_one =
193 bounding_box_center_two =
198 if (((bounding_box_center_one - bounding_box_center_two).norm() -
199 radius_one - radius_two) <= 0)
216 std::vector<Tensor<1, dim>> search_direction(2 * dim);
218 search_direction[0][0] = 1.;
219 search_direction[1][0] = -1.;
220 search_direction[2][1] = 1.;
221 search_direction[3][1] = -1.;
222 if constexpr (dim == 3)
224 search_direction[4][2] = 1.;
225 search_direction[5][2] = -1.;
228 for (
unsigned int i = 0; i < candidate_points.size(); ++i)
231 Point<dim> current_point = candidate_points[i];
232 Point<dim> dx{}, distance_gradient{}, previous_position{};
234 unsigned int iteration = 0;
235 constexpr unsigned int iteration_max = 2e2;
241 double previous_step_size = max_step;
247 double value_first_component =
249 double value_second_component =
251 double current_distance =
252 smooth_max(value_first_component, value_second_component);
254 previous_position = current_point;
256 double previous_value = DBL_MAX;
257 unsigned int consecutive_center = 0;
260 while (iteration < iteration_max && previous_step_size > precision)
263 value_first_component =
265 value_second_component =
267 if (value_first_component > value_second_component)
277 Tensor<1, dim> direction = distance_gradient;
278 dx = -max_step * direction / direction.norm();
279 if (distance_gradient.norm() == 0)
281 dx = -max_step * direction;
285 Point<dim> new_point = current_point + dx;
286 value_first_component =
288 value_second_component =
290 double new_distance =
291 smooth_max(value_first_component, value_second_component);
294 if (new_distance > current_distance - precision * precision)
297 std::vector<double> diff_results;
298 diff_results.resize(search_direction.size());
299 Point<dim> best_point;
300 double best_dist = current_distance;
301 for (
unsigned int d = 0; d < search_direction.size(); ++d)
303 Tensor<1, dim> perturbation =
304 search_direction[d] * max_step;
306 current_point + perturbation, cell);
308 current_point + perturbation, cell);
309 new_distance =
smooth_max(value_first_component,
310 value_second_component);
312 (new_distance - current_distance) / max_step;
315 if (new_distance < best_dist - precision * precision)
317 best_dist = new_distance;
318 best_point = current_point + perturbation;
322 if (best_dist < current_distance - precision * precision)
324 current_distance = best_dist;
325 current_point = best_point;
331 if (current_distance >
332 previous_value - precision * precision)
336 previous_position[0] -
337 ((diff_results[0] - diff_results[1]) / 2) /
338 ((diff_results[0] + diff_results[1]) / max_step);
340 previous_position[1] -
341 ((diff_results[2] - diff_results[3]) / 2) /
342 ((diff_results[2] + diff_results[3]) / max_step);
343 if constexpr (dim == 3)
346 previous_position[2] -
347 ((diff_results[4] - diff_results[5]) / 2) /
348 ((diff_results[4] + diff_results[5]) /
351 value_first_component =
353 value_second_component =
355 new_distance =
smooth_max(value_first_component,
356 value_second_component);
359 previous_value - precision * precision)
363 max_step = (new_point - previous_position).norm();
364 current_distance = new_distance;
365 current_point = new_point;
373 if (current_distance >
374 previous_value - precision * precision)
376 consecutive_center += 1;
377 previous_step_size = max_step;
378 max_step *= 1.0 / std::pow(2.0, consecutive_center);
379 current_point = previous_position;
380 current_distance = previous_value;
385 consecutive_center = 0;
390 current_point = new_point;
391 current_distance = new_distance;
393 consecutive_center = 0;
397 previous_value = current_distance;
398 previous_position = current_point;
403 if (distance > current_distance)
405 distance = current_distance;
406 contact_point = current_point;
409 Point<dim> closest_surface_point_on_this_shape;
410 Point<dim> closest_surface_point_on_the_input_shape;
412 closest_surface_point_on_this_shape,
416 closest_surface_point_on_the_input_shape,
420 normal = (closest_surface_point_on_the_input_shape -
421 closest_surface_point_on_this_shape) /
422 ((closest_surface_point_on_the_input_shape -
423 closest_surface_point_on_this_shape)
429 normal = (closest_surface_point_on_this_shape -
430 closest_surface_point_on_the_input_shape) /
431 ((closest_surface_point_on_this_shape -
432 closest_surface_point_on_the_input_shape)
439 return std::make_tuple(distance, normal, contact_point);
449 virtual std::tuple<double, Tensor<1, dim>, Point<dim>>
451 std::vector<Point<dim>> &candidate_points,
452 double precision = 1e-6,
453 bool exact_distance_outside_of_contact =
false)
456 double distance = DBL_MAX;
457 Tensor<1, dim> normal;
458 Point<dim> contact_point;
463 if (exact_distance_outside_of_contact ==
false)
465 Point<dim> bounding_box_center_one;
466 Point<dim> bounding_box_center_two;
473 radius_one = radius_two;
477 radius_two = radius_one;
479 if constexpr (dim == 3)
481 bounding_box_center_one =
484 bounding_box_center_two =
490 bounding_box_center_one =
494 bounding_box_center_two =
499 if (((bounding_box_center_one - bounding_box_center_two).norm() -
500 radius_one - radius_two) <= 0)
517 std::vector<Tensor<1, dim>> search_direction(2 * dim);
519 search_direction[0][0] = 1.;
520 search_direction[1][0] = -1.;
521 search_direction[2][1] = 1.;
522 search_direction[3][1] = -1.;
523 if constexpr (dim == 3)
525 search_direction[4][2] = 1.;
526 search_direction[5][2] = -1.;
529 for (
unsigned int i = 0; i < candidate_points.size(); ++i)
532 Point<dim> current_point = candidate_points[i];
533 Point<dim> dx{}, distance_gradient{}, previous_position{};
536 unsigned int iteration = 0;
537 constexpr unsigned int iteration_max = 2e2;
543 double previous_step_size = max_step;
549 double value_first_component = this->
value(current_point);
550 double value_second_component = shape.
value(current_point);
551 double current_distance =
552 smooth_max(value_first_component, value_second_component);
554 previous_position = current_point;
556 double previous_value = DBL_MAX;
557 unsigned int consecutive_center = 0;
560 while (iteration < iteration_max &&
561 (previous_step_size) > precision)
564 value_first_component = this->
value(current_point);
565 value_second_component = shape.
value(current_point);
566 if (value_first_component > value_second_component)
568 distance_gradient = this->gradient(current_point);
572 distance_gradient = shape.gradient(current_point);
574 Tensor<1, dim> direction = distance_gradient;
575 dx = -max_step * direction / direction.norm();
576 if (distance_gradient.norm() == 0)
578 dx = -max_step * direction;
582 Point<dim> new_point = current_point + dx;
583 value_first_component = this->
value(new_point);
584 value_second_component = shape.
value(new_point);
585 double new_distance =
586 smooth_max(value_first_component, value_second_component);
589 if (new_distance > current_distance - precision * precision)
592 std::vector<double> diff_results;
593 diff_results.resize(search_direction.size());
594 Point<dim> best_point;
595 double best_dist = current_distance;
596 for (
unsigned int d = 0; d < search_direction.size(); ++d)
598 Tensor<1, dim> perturbation =
599 search_direction[d] * max_step;
600 value_first_component =
601 this->
value(current_point + perturbation);
602 value_second_component =
603 shape.
value(current_point + perturbation);
604 new_distance =
smooth_max(value_first_component,
605 value_second_component);
607 (new_distance - current_distance) / max_step;
610 if (new_distance < best_dist - precision * precision)
612 best_dist = new_distance;
613 best_point = current_point + perturbation;
617 if (best_dist < current_distance - precision * precision)
619 current_distance = best_dist;
620 current_point = best_point;
626 if (current_distance >
627 previous_value - precision * precision)
631 previous_position[0] -
632 ((diff_results[0] - diff_results[1]) / 2) /
633 ((diff_results[0] + diff_results[1]) / max_step);
635 previous_position[1] -
636 ((diff_results[2] - diff_results[3]) / 2) /
637 ((diff_results[2] + diff_results[3]) / max_step);
638 if constexpr (dim == 3)
641 previous_position[2] -
642 ((diff_results[4] - diff_results[5]) / 2) /
643 ((diff_results[4] + diff_results[5]) /
646 value_first_component = this->
value(new_point);
647 value_second_component = shape.
value(new_point);
648 new_distance =
smooth_max(value_first_component,
649 value_second_component);
652 previous_value - precision * precision)
656 max_step = (new_point - previous_position).norm();
657 current_distance = new_distance;
658 current_point = new_point;
666 if (current_distance >
667 previous_value - precision * precision)
669 consecutive_center += 1;
670 previous_step_size = max_step;
671 max_step *= 1.0 / std::pow(2.0, consecutive_center);
672 current_point = previous_position;
673 current_distance = previous_value;
678 consecutive_center = 0;
683 current_point = new_point;
684 current_distance = new_distance;
686 consecutive_center = 0;
690 previous_value = current_distance;
691 previous_position = current_point;
696 if (distance > current_distance)
698 distance = current_distance;
699 contact_point = current_point;
700 Point<dim> closest_surface_point_on_this_shape;
701 Point<dim> closest_surface_point_on_the_input_shape;
705 current_point, closest_surface_point_on_this_shape);
707 current_point, closest_surface_point_on_the_input_shape);
710 normal = (closest_surface_point_on_the_input_shape -
711 closest_surface_point_on_this_shape) /
712 ((closest_surface_point_on_the_input_shape -
713 closest_surface_point_on_this_shape)
719 normal = (closest_surface_point_on_this_shape -
720 closest_surface_point_on_the_input_shape) /
721 ((closest_surface_point_on_this_shape -
722 closest_surface_point_on_the_input_shape)
729 return std::make_tuple(distance, normal, contact_point);
743 if constexpr (dim == 3)
751 for (
int i = -1; i < 2; i += 2)
753 for (
int j = -1; j < 2; j += 2)
755 for (
int k = -1; k < 2; k += 2)
758 Tensor<1, dim> vertex_position(
773 if (this->
value(vertex) <= 0)
785 for (
int i = -1; i < 2; i += 2)
787 for (
int j = -1; j < 2; j += 2)
789 for (
int k = -1; k < 2; k += 2)
792 Tensor<1, dim> vertex_position(
807 if (shape.
value(vertex) <= 0)
818 Tensor<2, dim> R, AbsR;
821 for (
int i = 0; i < 3; i++)
823 for (
int j = 0; j < 3; j++)
836 for (
int i = 0; i < 3; i++)
838 for (
int j = 0; j < 3; j++)
841 std::abs(R[i][j]) + std::numeric_limits<double>::epsilon();
845 for (
int i = 0; i < 3; i++)
854 if (std::abs(t[i]) > ra + rb)
858 for (
int i = 0; i < 3; i++)
867 if (std::abs(t[0] * R[0][i] + t[1] * R[1][i] + t[2] * R[2][i]) >
873 for (
int i = 0; i < 3; i++)
875 for (
int j = 0; j < 3; j++)
881 AbsR[(i + 2) % 3][j] +
884 AbsR[(i + 1) % 3][j];
887 AbsR[i][(j + 2) % 3] +
890 AbsR[i][(j + 1) % 3];
891 if (std::abs(scalar_product(t, L)) > ra + rb)
906 for (
int i = -1; i < 2; i += 2)
908 for (
int j = -1; j < 2; j += 2)
911 Tensor<1, dim> vertex_position(
934 for (
int i = -1; i < 2; i += 2)
936 for (
int j = -1; j < 2; j += 2)
939 Tensor<1, 3> vertex_position(
961 Tensor<2, 3> R, AbsR;
965 for (
int i = 0; i < 3; i++)
967 for (
int j = 0; j < 3; j++)
984 for (
int i = 0; i < 3; i++)
986 for (
int j = 0; j < 3; j++)
989 std::abs(R[i][j]) + std::numeric_limits<double>::epsilon();
994 for (
int i = 0; i < 2; i++)
1001 if (std::abs(t[i]) > ra + rb)
1006 for (
int i = 0; i < 2; i++)
1013 if (std::abs(t[0] * R[0][i] + t[1] * R[1][i]) > ra + rb)
1028 virtual Tensor<1, dim>
1030 const Point<dim> &evaluation_point,
1031 const typename DoFHandler<dim>::active_cell_iterator &cell,
1032 const unsigned int component = 0);
1038 virtual std::shared_ptr<Shape<dim>>
1054 const Point<dim> &p,
1055 Point<dim> &closest_point,
1056 const typename DoFHandler<dim>::active_cell_iterator &cell_guess);
1079 double curvature = 0;
1081 for (
int d = 0; d < dim; ++d)
1083 Tensor<1, dim> perturbation;
1084 perturbation[d] = epsilone;
1085 Tensor<1, dim> gradient_p = this->gradient(p + perturbation);
1086 gradient_p = gradient_p / (gradient_p.norm() + DBL_MIN);
1087 Tensor<1, dim> gradient_m = this->gradient(p - perturbation);
1088 gradient_m = gradient_m / (gradient_m.norm() + DBL_MIN);
1089 curvature += (gradient_p - gradient_m)[d] / (2 * epsilone);
1092 double radius_of_curvature = 1.0 / abs(curvature);
1093 return std::min(std::max(radius_of_curvature,
1094 this->effective_radius * 1e-2),
1095 this->effective_radius * 1e2);
1106 const Point<dim> &p,
1107 const typename DoFHandler<dim>::active_cell_iterator &cell)
1109 double curvature = 0;
1114 for (
int d = 0; d < dim; ++d)
1116 Tensor<1, dim> perturbation;
1117 perturbation[d] = epsilone;
1118 Tensor<1, dim> gradient_p =
1120 gradient_p = gradient_p / (gradient_p.norm() + DBL_MIN);
1121 Tensor<1, dim> gradient_m =
1123 gradient_m = gradient_m / (gradient_m.norm() + DBL_MIN);
1124 curvature += (gradient_p - gradient_m)[d] / (2 * epsilone);
1127 double radius_of_curvature = 1.0 / abs(curvature);
1128 return std::min(std::max(radius_of_curvature,
1129 this->effective_radius * 1e-2),
1130 this->effective_radius * 1e2);
1160 if constexpr (dim == 2)
1165 Physics::Transformations::Rotations::rotation_matrix_3d(
1166 axis, new_orientation[2]);
1168 if constexpr (dim == 3)
1170 for (
unsigned int i = 0; i < 3; ++i)
1175 Physics::Transformations::Rotations::rotation_matrix_3d(
1176 axis, new_orientation[2 - i]) *
1186 inline virtual Point<dim>
1196 inline virtual Tensor<1, 3>
1206 inline virtual Tensor<2, 3>
1216 inline virtual Tensor<1, dim>
1226 inline virtual Point<dim>
1236 virtual std::shared_ptr<Manifold<dim - 1, dim>>
1323 Tensor<1, 3> xyz_rotation;
1324 xyz_rotation[0] = std::atan2(-rotation_matrix_representation[1][2],
1325 rotation_matrix_representation[2][2]);
1326 xyz_rotation[1] = std::asin(rotation_matrix_representation[0][2]);
1327 xyz_rotation[2] = std::atan2(-rotation_matrix_representation[0][1],
1328 rotation_matrix_representation[0][0]);
1329 return xyz_rotation;
1384 std::make_shared<Functions::SignedDistance::Sphere<dim>>(
position,
1386 for (
int d = 0; d < dim; ++d)
1401 value(
const Point<dim> &evaluation_point,
1402 const unsigned int component = 0)
const override;
1408 std::shared_ptr<Shape<dim>>
1417 gradient(
const Point<dim> &evaluation_point,
1418 const unsigned int component = 0)
const override;
1433 virtual std::shared_ptr<Manifold<dim - 1, dim>>
1445 std::tuple<double, Tensor<1, dim>, Point<dim>>
1448 const typename DoFHandler<dim>::active_cell_iterator &cell,
1449 std::vector<Point<dim>> &candidate_points,
1450 double precision = 1e-6,
1451 bool exact_distance_outside_of_contact =
false)
override;
1460 std::tuple<double, Tensor<1, dim>, Point<dim>>
1462 std::vector<Point<dim>> &candidate_points,
1463 double precision = 1e-6,
1464 bool exact_distance_outside_of_contact =
false)
override;
1483 const Point<dim> &p,
1484 const typename DoFHandler<dim>::active_cell_iterator &cell)
override;
1504 if constexpr (dim == 3)
1506 normal = Tensor<1, dim>({0, 0, 1});
1510 normal = Tensor<1, dim>({0, 1});
1514 for (
int d = 0; d < dim; ++d)
1530 value(
const Point<dim> &evaluation_point,
1531 const unsigned int component = 0)
const override;
1537 std::shared_ptr<Shape<dim>>
1546 gradient(
const Point<dim> &evaluation_point,
1547 const unsigned int component = 0)
const override;
1592 for (
int d = 0; d < dim; ++d)
1606 value(
const Point<dim> &evaluation_point,
1607 const unsigned int component = 0)
const override;
1619 const Point<dim> &evaluation_point,
1620 const typename DoFHandler<dim>::active_cell_iterator &cell,
1621 [[maybe_unused]]
const unsigned int component = 0)
override;
1626 std::shared_ptr<Shape<dim>>
1635 gradient(
const Point<dim> &evaluation_point,
1636 const unsigned int component = 0)
const override;
1646 const Point<dim> &evaluation_point,
1647 const typename DoFHandler<dim>::active_cell_iterator &cell,
1648 const unsigned int component = 0)
override;
1664 const Point<dim> &p,
1665 Point<dim> &closest_point,
1666 const typename DoFHandler<dim>::active_cell_iterator &cell_guess)
override;
1669 Point<dim> &closest_point)
const override;
1675 static inline double
1706 for (
int d = 0; d < dim; d++)
1711 if (abs(centered_point[d]) >
epsilon)
1714 pow(abs(centered_point[d]),
exponents[d]) /
1715 (centered_point[d] + DBL_MIN);
1747 for (
int d = 0; d < dim; ++d)
1762 value(
const Point<dim> &evaluation_point,
1763 const unsigned int component = 0)
const override;
1768 std::shared_ptr<Shape<dim>>
1799 for (
int d = 0; d < dim; ++d)
1813 value(
const Point<dim> &evaluation_point,
1814 const unsigned int component = 0)
const override;
1819 std::shared_ptr<Shape<dim>>
1853 if constexpr (dim == 3)
1859 for (
int d = 0; d < dim; ++d)
1873 value(
const Point<dim> &evaluation_point,
1874 const unsigned int component = 0)
const override;
1879 std::shared_ptr<Shape<dim>>
1915 if constexpr (dim == 3)
1934 value(
const Point<dim> &evaluation_point,
1935 const unsigned int component = 0)
const override;
1940 std::shared_ptr<Shape<dim>>
1986 if constexpr (dim == 3)
2001 value(
const Point<dim> &evaluation_point,
2002 const unsigned int component = 0)
const override;
2007 std::shared_ptr<Shape<dim>>
2057 if constexpr (dim == 3)
2072 value(
const Point<dim> &evaluation_point,
2073 const unsigned int component = 0)
const override;
2078 std::shared_ptr<Shape<dim>>
2123 std::map<
unsigned int,
2124 std::tuple<BooleanOperation, unsigned int, unsigned int>>
2132 Point<dim> point_max;
2133 Point<dim> point_min;
2134 bool xyz_min_max_is_initialized =
false;
2137 for (
auto const &constituent :
constituents | boost::adaptors::map_values)
2141 constituent->set_part_of_a_composite(
true);
2144 if constexpr (dim == 2)
2146 std::vector<Point<3>> component_bounding_box_vertex(4);
2147 unsigned int index = 0;
2148 for (
int i = -1; i < 2; i += 2)
2150 for (
int j = -1; j < 2; j += 2)
2152 component_bounding_box_vertex[index][0] =
2153 constituent->get_bounding_box_center()[0] +
2154 constituent->get_bounding_box_half_length()[0] * i;
2155 component_bounding_box_vertex[index][1] =
2156 constituent->get_bounding_box_center()[1] +
2157 constituent->get_bounding_box_half_length()[1] * j;
2161 for (
unsigned int i = 0; i < 4; ++i)
2165 constituent->set_position(constituent->get_position());
2166 constituent->set_orientation(constituent->get_orientation());
2167 auto new_point = constituent->get_rotation_matrix() *
2168 component_bounding_box_vertex[i] +
2170 if (xyz_min_max_is_initialized ==
false)
2172 for (
int d = 0; d < dim; ++d)
2174 point_min[d] = new_point[d];
2175 point_max[d] = new_point[d];
2177 xyz_min_max_is_initialized =
true;
2181 for (
int d = 0; d < dim; ++d)
2183 point_min[d] = std::min(point_min[d], new_point[d]);
2184 point_max[d] = std::max(point_max[d], new_point[d]);
2191 std::vector<Point<3>> component_bounding_box_vertex(8);
2192 unsigned int index = 0;
2193 for (
int i = -1; i < 2; i += 2)
2195 for (
int j = -1; j < 2; j += 2)
2197 for (
int k = -1; k < 2; k += 2)
2199 component_bounding_box_vertex[index][0] =
2200 constituent->get_bounding_box_center()[0] +
2201 constituent->get_bounding_box_half_length()[0] * i;
2202 component_bounding_box_vertex[index][1] =
2203 constituent->get_bounding_box_center()[1] +
2204 constituent->get_bounding_box_half_length()[1] * j;
2205 component_bounding_box_vertex[index][2] =
2206 constituent->get_bounding_box_center()[2] +
2207 constituent->get_bounding_box_half_length()[2] * k;
2212 for (
unsigned int i = 0; i < 8; ++i)
2216 constituent->set_position(constituent->get_position());
2217 constituent->set_orientation(constituent->get_orientation());
2218 auto new_point = constituent->get_rotation_matrix() *
2219 component_bounding_box_vertex[i] +
2222 if (xyz_min_max_is_initialized ==
false)
2224 for (
int d = 0; d < dim; ++d)
2226 point_min[d] = new_point[d];
2227 point_max[d] = new_point[d];
2229 xyz_min_max_is_initialized =
true;
2233 for (
int d = 0; d < dim; ++d)
2235 point_min[d] = std::min(point_min[d], new_point[d]);
2236 point_max[d] = std::max(point_max[d], new_point[d]);
2259 size_t number_of_constituents = constituents_vector.size();
2261 for (
size_t i = 0; i < number_of_constituents; i++)
2263 if (number_of_constituents > 1)
2270 for (
size_t i = 1; i < number_of_constituents - 1; i++)
2275 i + number_of_constituents - 1);
2279 for (
auto const &constituent :
constituents | boost::adaptors::map_values)
2294 value(
const Point<dim> &evaluation_point,
2295 const unsigned int component = 0)
const override;
2307 const Point<dim> &evaluation_point,
2308 const typename DoFHandler<dim>::active_cell_iterator &cell,
2309 [[maybe_unused]]
const unsigned int component = 0)
override;
2317 gradient(
const Point<dim> &evaluation_point,
2318 const unsigned int component = 0)
const override;
2328 const Point<dim> &evaluation_point,
2329 const typename DoFHandler<dim>::active_cell_iterator &cell,
2330 const unsigned int component = 0)
override;
2335 std::shared_ptr<Shape<dim>>
2346 const bool mesh_based_precalculations);
2364 const bool mesh_based_precalculations);
2371 inline std::pair<double, Tensor<1, dim>>
2373 std::map<unsigned int, double> constituent_shapes_values,
2374 std::map<
unsigned int, Tensor<1, dim>> constituent_shapes_gradients)
const;
2399 std::map<
unsigned int,
2400 std::tuple<BooleanOperation, unsigned int, unsigned int>>
2421#ifdef DEAL_II_WITH_OPENCASCADE
2424 std::vector<std::string> file_name_and_extension(
2428 if (file_name_and_extension[1] ==
"step" ||
2429 file_name_and_extension[1] ==
"stp")
2434 else if (file_name_and_extension[1] ==
"iges" ||
2435 file_name_and_extension[1] ==
"igs")
2440 else if (file_name_and_extension[1] ==
"stl")
2447 throw std::runtime_error(
2448 "Wrong file extension for an opencascade shape. The possible file type are: step, stp, iges, igs, stl.");
2452 shape_tol = OpenCASCADE::get_shape_tolerance(shape);
2455 OpenCASCADE::extract_compound_shapes(
2456 shape, compounds, compsolids, solids, shells, wires);
2457 vertex_position = OpenCASCADE::point(Point<dim>());
2458 vertex = BRepBuilderAPI_MakeVertex(vertex_position);
2459 distancetool = BRepExtrema_DistShapeShape(shape, vertex);
2463 if (shells.size() > 0)
2469 if (solids.size() == 1)
2474 OpenCASCADE::extract_compound_shapes(
2475 shape, compounds, compsolids, solids, shells, wires);
2477 distancetool = BRepExtrema_DistShapeShape(shells[0], vertex);
2478 point_classifier.Load(shape);
2480 else if (shells.size() > 1)
2482 throw std::runtime_error(
2483 "Error!: The shape has more than one shell. The code does not support shapes with multiple shells or solids. If your shape has more than one shell or solid, it is usually possible to recombine them into one. Otherwise, it is possible to split the shape into sub-shells and sub-solids and then define one particle for each of them.");
2485 distancetool = BRepExtrema_DistShapeShape(shells[0], vertex);
2486 point_classifier.Load(shape);
2490 distancetool = BRepExtrema_DistShapeShape(shape, vertex);
2491 point_classifier.Load(shape);
2496 GProp_GProps system;
2497 BRepGProp::LinearProperties(shape, system);
2498 BRepGProp::SurfaceProperties(shape, system);
2499 BRepGProp::VolumeProperties(shape, system);
2501 std::pow(system.Mass() * 3.0 / (4 * numbers::PI), 1.0 / dim);
2508 if constexpr (dim == 3)
2525 value(
const Point<dim> &evaluation_point,
2526 const unsigned int component = 0)
const override;
2538 const Point<dim> &evaluation_point,
2539 const typename DoFHandler<dim>::active_cell_iterator &cell,
2540 const unsigned int component = 0)
override;
2545 std::shared_ptr<Shape<dim>>
2554 gradient(
const Point<dim> &evaluation_point,
2555 const unsigned int component = 0)
const override;
2565 const Point<dim> &evaluation_point,
2566 const typename DoFHandler<dim>::active_cell_iterator &cell,
2567 const unsigned int component = 0)
override;
2588#ifdef DEAL_II_WITH_OPENCASCADE
2593 std::vector<TopoDS_Compound> compounds;
2594 std::vector<TopoDS_CompSolid> compsolids;
2595 std::vector<TopoDS_Solid> solids;
2596 std::vector<TopoDS_Shell> shells;
2597 std::vector<TopoDS_Wire> wires;
2600 gp_Pnt vertex_position;
2603 TopoDS_Vertex vertex;
2606 BRepClass3d_SolidClassifier point_classifier;
2607 BRepExtrema_DistShapeShape distancetool;
2608 BRepExtrema_DistShapeShape distancetool_shell;
2661 RBFShape(
const std::string &shape_arguments_str,
2681 const bool mesh_based_precalculations);
2695 value(
const Point<dim> &evaluation_point,
2696 const unsigned int component = 0)
const override;
2708 const Point<dim> &evaluation_point,
2709 [[maybe_unused]]
const typename DoFHandler<dim>::active_cell_iterator &cell,
2710 [[maybe_unused]]
const unsigned int component = 0)
override;
2720 const Point<dim> &evaluation_point,
2721 const typename DoFHandler<dim>::active_cell_iterator &cell,
2722 const unsigned int component = 0)
override;
2730 gradient(
const Point<dim> &evaluation_point,
2731 const unsigned int component = 0)
const override;
2736 std::shared_ptr<Shape<dim>>
2769 const double distance)
const;
2779 const double distance)
const;
2788 const typename DoFHandler<dim>::cell_iterator &cell,
2789 const Point<dim> support_point);
2799 const bool mesh_based_precalculations);
2811 static inline double
2814 return distance > 1.0 ?
2816 std::pow(1. - distance, 4.0) * (4.0 * distance + 1.0);
2823 static inline double
2826 return distance > 1.0 ? 0.0 : (1.0 - distance);
2833 static inline double
2836 double eps = std::pow(-1.0 * std::log(0.1), 0.5);
2837 return std::exp(-1.0 * std::pow(distance * eps, 2.0));
2844 static inline double
2847 double eps = std::pow(-1.0 * std::log(0.05), 0.5);
2848 return std::exp(-1.0 * std::pow(distance * eps, 2.0));
2855 static inline double
2858 double eps = std::pow(-1.0 * std::log(0.01), 0.5);
2859 return std::exp(-1.0 * std::pow(distance * eps, 2.0));
2868 static inline double
2871 return distance > 1.0 ? 0.0 : (1.0 - std::pow(distance, 2.0));
2880 static inline double
2883 return distance > 1.0 ? 0.0 : (1.0 - std::pow(distance, 3.0));
2892 static inline double
2895 return distance > 1.0 ? 0.0 :
2896 (1.0 - 2.0 * distance + std::pow(distance, 2.0));
2905 static inline double
2908 return distance > 1.0 ? 0.0 :
2909 (1.0 - 3.0 * std::pow(distance, 2.0) +
2910 2.0 * std::pow(distance, 3.0));
2919 static inline double
2922 return distance > 1.0 ? 0.0 :
2923 (1.0 - 4.0 * std::pow(distance, 3.0) +
2924 3.0 * std::pow(distance, 4.0));
2933 static inline double
2936 return distance > 1.0 ?
2938 (1.0 - 3.0 * distance + 3.0 * std::pow(distance, 2.0) -
2939 std::pow(distance, 3.0));
2948 static inline double
2951 return distance > 1.0 ?
2953 (1.0 - 6.0 * std::pow(distance, 2.0) +
2954 8.0 * std::pow(distance, 3.0) - 3.0 * std::pow(distance, 4.0));
2963 static inline double
2966 return distance > 1.0 ?
2968 (1.0 - 10.0 * std::pow(distance, 3.0) +
2969 15.0 * std::pow(distance, 4.0) - 6.0 * std::pow(distance, 5.0));
2976 static inline double
2979 return distance > 1.0 ? 0.0 : 0.5 + 0.5 * std::cos(distance * M_PI);
2987 static inline double
2990 return distance > 1.0 ? 0.0 :
2991 -20.0 * distance * std::pow(1.0 - distance, 3.0);
2998 static inline double
3001 return distance > 1.0 ? 0.0 : -1.0;
3008 static inline double
3011 double eps = std::pow(-1.0 * std::log(0.1), 0.5);
3012 return -2.0 * std::pow(eps, 2.0) * distance *
3013 std::exp(-1.0 * std::pow(distance * eps, 2.0));
3020 static inline double
3023 double eps = std::pow(-1.0 * std::log(0.05), 0.5);
3024 return -2.0 * std::pow(eps, 2.0) * distance *
3025 std::exp(-1.0 * std::pow(distance * eps, 2.0));
3032 static inline double
3035 double eps = std::pow(-1.0 * std::log(0.01), 0.5);
3036 return -2.0 * std::pow(eps, 2.0) * distance *
3037 std::exp(-1.0 * std::pow(distance * eps, 2.0));
3046 static inline double
3049 return distance > 1.0 ? 0.0 : -2.0 * distance;
3058 static inline double
3061 return distance > 1.0 ? 0.0 : -3.0 * std::pow(distance, 2.0);
3070 static inline double
3073 return distance > 1.0 ? 0.0 : 2.0 * (distance - 1.0);
3082 static inline double
3085 return distance > 1.0 ? 0.0 : 6.0 * (distance - 1.0) * distance;
3094 static inline double
3097 return distance > 1.0 ? 0.0 :
3098 12 * (distance - 1.0) * std::pow(distance, 2.0);
3107 static inline double
3110 return distance > 1.0 ? 0.0 : -3.0 * std::pow(distance - 1.0, 2.0);
3119 static inline double
3122 return distance > 1.0 ?
3124 (1.0 - 6.0 * std::pow(distance, 2.0) +
3125 8.0 * std::pow(distance, 3.0) - 3.0 * std::pow(distance, 4.0));
3134 static inline double
3137 return distance > 1.0 ?
3139 -30.0 * std::pow(distance - 1.0, 2.0) * std::pow(distance, 2.0);
3147 static inline double
3150 return distance > 1.0 ? 0.0 : -M_PI_2 * std::sin(M_PI * distance);
3159 const typename DoFHandler<dim>::active_cell_iterator &cell);
3169 std::tuple<Point<dim>, double, std::shared_ptr<std::vector<size_t>>>>
3182 const typename DoFHandler<dim>::cell_iterator,
3183 std::shared_ptr<std::vector<
3184 std::tuple<Point<dim>, double, std::shared_ptr<std::vector<size_t>>>>>>
3236 value(
const Point<dim> &evaluation_point,
3237 const unsigned int component = 0)
const override;
3242 std::shared_ptr<Shape<dim>>
3271 double radius_outside,
3276 ,
radius((radius_outside + radius_inside) / 2.)
3277 ,
height(half_length * 2.)
3284 if constexpr (dim == 3)
3299 value(
const Point<dim> &evaluation_point,
3300 const unsigned int component = 0)
const override;
3305 std::shared_ptr<Shape<dim>>
3352 if constexpr (dim == 3)
3367 value(
const Point<dim> &evaluation_point,
3368 const unsigned int component = 0)
const override;
3373 std::shared_ptr<Shape<dim>>
void update_precalculations(DoFHandler< dim > &updated_dof_handler, const bool mesh_based_precalculations)
Sets the proper dof handler, then computes/updates the map of cells and their likely non-null nodes.
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
void remove_superfluous_data(DoFHandler< dim > &updated_dof_handler, const bool mesh_based_precalculations)
Remove data that affects only artificial cells (not locally owned and not ghost). The data is removed...
double value_with_cell_guess(const Point< dim > &evaluation_point, const typename DoFHandler< dim >::active_cell_iterator &cell, const unsigned int component=0) override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
Tensor< 1, dim > gradient(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the gradient of the distance function.
std::map< unsigned int, std::tuple< BooleanOperation, unsigned int, unsigned int > > operations
Tensor< 1, dim > gradient_with_cell_guess(const Point< dim > &evaluation_point, const typename DoFHandler< dim >::active_cell_iterator &cell, const unsigned int component=0) override
Return the gradient of the distance function.
std::map< unsigned int, std::shared_ptr< Shape< dim > > > constituents
void set_layer_thickening(const double layer_thickening) override
See base.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
std::pair< double, Tensor< 1, dim > > apply_boolean_operations(std::map< unsigned int, double > constituent_shapes_values, std::map< unsigned int, Tensor< 1, dim > > constituent_shapes_gradients) const
Computes the assigned boolean operations.
CompositeShape(std::vector< std::shared_ptr< Shape< dim > > > constituents_vector, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructs an assembly of shapes into a composite shape from a vector of shapes. This constructor is ...
void load_data_from_file()
Load data from file. To be called at initialization, after repartitioning or when shape has moved....
virtual void clear_cache() override
Clear the cache of the shape.
CompositeShape(std::map< unsigned int, std::shared_ptr< Shape< dim > > > constituents, std::map< unsigned int, std::tuple< BooleanOperation, unsigned int, unsigned int > > operations, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructs an assembly of shapes into a composite shape.
Tensor< 1, 2 > intermediate_q
double displaced_volume() override
Return the volume displaced by the solid.
Cone(double tan_base_angle, double height, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructs a cone.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
CutHollowSphere(double radius, double cut_depth, double shell_thickness, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructs a hollow sphere that has a wall thickness and that is cut by a given depth.
double displaced_volume() override
Return the volume displaced by the solid.
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
double displaced_volume() override
Return the volume displaced by the solid.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
Cylinder(double radius, double half_length, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructs a cylinder aligned with the z axis.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
double displaced_volume() override
Return the volume displaced by the solid.
CylindricalHelix(double radius_helix, double radius_disk, double height, double pitch, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructs a cylindrical helix by extruding a disk through a helicoidal path aligned with the z axis ...
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
double displaced_volume() override
Return the volume displaced by the solid.
CylindricalTube(double radius_inside, double radius_outside, double half_length, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructs a tube by boolean difference of two tubes aligned with the z axis when orientation is set ...
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
DeathStar(double radius, double hole_radius, double spheres_distance, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
The Death Star is the result of a boolean subtraction of one sphere from another.
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
double displaced_volume() override
Return the volume displaced by the solid.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
double displaced_volume() override
Return the volume displaced by the solid.
Ellipsoid(const Tensor< 1, dim > &radii, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructs an ellipsoid with the given arguments.
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
double displaced_volume() override
Return the volume displaced by the solid.
Tensor< 1, dim > half_lengths
HyperRectangle(const Tensor< 1, dim > &half_lengths, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructs a box with the given parameters.
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
double value_with_cell_guess(const Point< dim > &evaluation_point, const typename DoFHandler< dim >::active_cell_iterator &cell, const unsigned int component=0) override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
Tensor< 1, dim > gradient(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the gradient of the distance function.
std::string local_file_name
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
double displaced_volume() override
Return the volume displaced by the solid.
Tensor< 1, dim > gradient_with_cell_guess(const Point< dim > &evaluation_point, const typename DoFHandler< dim >::active_cell_iterator &cell, const unsigned int component=0) override
Return the gradient of the distance function.
void set_position(const Point< dim > &position) override
Sets a new position for the shape.
OpenCascadeShape(const std::string &file_name, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructor for an OpenCascade shape.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
Plane(const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructor for a infinite plane. The plane is normal to the Z axis in 3D and Y axis in 2D in the ref...
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
double displaced_volume() override
Return the volume displaced by the solid.
Tensor< 1, dim > gradient(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the analytical gradient of the distance.
static double c2c0_derivative(const double distance)
Derivative of a compact polynomial function defined from 0 to 1. It preserves C2 continuity at distan...
static double gauss95(const double distance)
Non-compact Gaussian function with 0.05 value at distance equal to 1.
void remove_superfluous_data(DoFHandler< dim > &dof_handler, const bool mesh_based_precalculations)
Remove data that affects only artificial cells (not locally owned and not ghost). The data is removed...
static double c1c0(const double distance)
Compact polynomial function defined from 0 to 1. It preserves C1 continuity at distance=0,...
static double cosinus_derivative(const double distance)
Derivative of a compact cosinusoidal basis function. It preserves continuity at every point.
std::vector< double > basis_functions
static double c0c1(const double distance)
Compact polynomial function defined from 0 to 1. It preserves C0 continuity at distance=0,...
std::vector< std::tuple< Point< dim >, double, std::shared_ptr< std::vector< size_t > > > > iterable_nodes
RBFShape(const std::string &shape_arguments_str, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
An RBFShape represents a physical object by describing its signed distance field with a linear combin...
static double linear(const double distance)
Compact linear function defined from 0 to 1.
RBFBasisFunction
Enum class defining types of RBF kernel functions that could be used in the class.
static double c0c1_derivative(const double distance)
Derivative of a compact polynomial function defined from 0 to 1. It preserves C0 continuity at distan...
void determine_likely_nodes_for_one_cell(const typename DoFHandler< dim >::cell_iterator &cell, const Point< dim > support_point)
Establishes which nodes bring a non null contribution to the RBF.
static double c2c2_derivative(const double distance)
Derivative of a compact polynomial function defined from 0 to 1. It preserves C2 continuity at distan...
static double c1c1_derivative(const double distance)
Derivative of a compact polynomial function defined from 0 to 1. It preserves C1 continuity at distan...
double evaluate_basis_function(const RBFBasisFunction basis_function, const double distance) const
Returns the value of the basis function for a given distance. Inspired by Optimad Bitpit....
void rotate_nodes()
Rotate RBF nodes in the global reference frame (the reference frame of the triangulation).
void load_data_from_file()
Load RBF data from file. To be called at initialization, after repartitioning or when shape has moved...
static double gauss99(const double distance)
Non-compact Gaussian function with 0.01 value at distance equal to 1.
static double c1c0_derivative(const double distance)
Derivative of a compact polynomial function defined from 0 to 1. It preserves C1 continuity at distan...
Tensor< 1, dim > gradient_with_cell_guess(const Point< dim > &evaluation_point, const typename DoFHandler< dim >::active_cell_iterator &cell, const unsigned int component=0) override
Return the analytical gradient of the distance.
static double gauss90_derivative(const double distance)
Derivative of a non-compact Gaussian function with 0.1 value at distance equal to 1.
double value_with_cell_guess(const Point< dim > &evaluation_point, const typename DoFHandler< dim >::active_cell_iterator &cell, const unsigned int component=0) override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
static double wendlandc2(const double distance)
Compact Wendland C2 function defined from 0 to 1.
static double c0c2_derivative(const double distance)
Derivative of a compact polynomial function defined from 0 to 1. It preserves C0 continuity at distan...
size_t max_number_of_inside_nodes
static double c1c2(const double distance)
Compact polynomial function defined from 0 to 1. It preserves C1 continuity at distance=0,...
static double gauss99_derivative(const double distance)
Derivative of a non-compact Gaussian function with 0.01 value at distance equal to 1.
std::vector< double > support_radii
void swap_iterable_nodes(const typename DoFHandler< dim >::active_cell_iterator &cell)
Swap the vector of all nodes with a likely node vector.
static double c2c2(const double distance)
Compact polynomial function defined from 0 to 1. It preserves C2 continuity at distance=0,...
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
static double wendlandc2_derivative(const double distance)
Derivative of a compact Wendland C2 function defined from 0 to 1.
std::map< const typename DoFHandler< dim >::cell_iterator, std::shared_ptr< std::vector< std::tuple< Point< dim >, double, std::shared_ptr< std::vector< size_t > > > > > > likely_nodes_map
void initialize_bounding_box()
Initializes the bounding box around the nodes which enables distance calculation even if the RBF node...
static double c2c1(const double distance)
Compact polynomial function defined from 0 to 1. It preserves C2 continuity at distance=0,...
DoFHandler< dim > * dof_handler
double evaluate_basis_function_derivative(const RBFBasisFunction basis_function, const double distance) const
Returns the derivative of the basis function for a given distance. Inspired by Optimad Bitpit....
std::vector< double > weights
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
double maximal_support_radius
static double cos(const double distance)
Compact cosinusoidal basis function. It is null when r>1.
static double c2c0(const double distance)
Compact polynomial function defined from 0 to 1. It preserves C2 continuity at distance=0,...
std::vector< Point< dim > > rotated_nodes_positions
Tensor< 1, dim > gradient(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the analytical gradient of the distance for the current RBF.
double displaced_volume() override
Return the volume displaced by the solid.
static double c1c1(const double distance)
Compact polynomial function defined from 0 to 1. It preserves C1 continuity at distance=0,...
std::vector< Point< dim > > nodes_positions
static double c0c2(const double distance)
Compact polynomial function defined from 0 to 1. It preserves C0 continuity at distance=0,...
void update_precalculations(DoFHandler< dim > &updated_dof_handler, const bool mesh_based_precalculations)
Sets the proper dof handler, then computes/updates the map of cells and their likely non-null nodes.
std::vector< bool > useful_rbf_nodes
static double c1c2_derivative(const double distance)
Derivative of a compact polynomial function defined from 0 to 1. It preserves C1 continuity at distan...
std::shared_ptr< HyperRectangle< dim > > bounding_box
static double gauss95_derivative(const double distance)
Derivative of a non-compact Gaussian function with 0.05 value at distance equal to 1.
static double c2c1_derivative(const double distance)
Derivative of a compact polynomial function defined from 0 to 1. It preserves C2 continuity at distan...
static double gauss90(const double distance)
Non-compact Gaussian function with 0.1 value at distance equal to 1.
static double linear_derivative(const double distance)
Derivative of a compact linear function defined from 0 to 1.
A base class used to represent geometrical entities. Its main uses are to return signed distance and ...
virtual Point< dim > get_position()
Returns the position of the shape.
Tensor< 2, 3 > rotation_matrix
virtual std::shared_ptr< Shape< dim > > static_copy() const =0
Return a pointer to a copy of the Shape.
Tensor< 1, 3 > orientation
virtual void clear_cache()
Clear the cache of the shape.
virtual Tensor< 1, dim > gradient_with_cell_guess(const Point< dim > &evaluation_point, const typename DoFHandler< dim >::active_cell_iterator &cell, const unsigned int component=0)
Return the analytical gradient of the distance.
ShapeType
enum class that associate an integer index tp each type of shape. The enumerator names are the values...
virtual void closest_surface_point(const Point< dim > &p, Point< dim > &closest_point, const typename DoFHandler< dim >::active_cell_iterator &cell_guess)
Sets the closest_point parameter to be the point on the surface of the shape which has the minimal di...
static Tensor< 1, 3 > rotation_matrix_to_xyz_angles(Tensor< 2, 3 > &rotation_matrix_representation)
Function that return the XYZ rotation angles from a rotation matrix.
virtual std::tuple< double, Tensor< 1, dim >, Point< dim > > distance_to_shape_with_cell_guess(Shape< dim > &shape, const typename DoFHandler< dim >::active_cell_iterator &cell, std::vector< Point< dim > > &candidate_points, double precision=1e-6, bool exact_distance_outside_of_contact=false)
Return the distance, the center point, and the unit normal vector between the current shape and the s...
virtual double displaced_volume()
Return the volume displaced by the solid.
std::string point_to_string(const Point< dim > &evaluation_point) const
This function returns a point in a string of text. This is used in the cache of the shape.
virtual double local_curvature_radius(Point< dim > p)
Return the curvature of the level set at a given point.
std::unordered_map< std::string, Tensor< 1, dim > > gradient_cache
virtual std::tuple< double, Tensor< 1, dim >, Point< dim > > distance_to_shape(Shape< dim > &shape, std::vector< Point< dim > > &candidate_points, double precision=1e-6, bool exact_distance_outside_of_contact=false)
Return the distance, the center point, and the normal between the current shape and the shape given i...
enum Shape::ShapeType type
std::unordered_map< std::string, double > value_cache
virtual std::shared_ptr< Manifold< dim - 1, dim > > get_shape_manifold()
Returns the default manifold of the shape. If not redefined, it is a flat manifold.
Point< dim > bounding_box_center
virtual double local_curvature_radius_with_cell_guess(const Point< dim > &p, const typename DoFHandler< dim >::active_cell_iterator &cell)
Return the curvature of the level at a given point using the cell guess functions.
virtual void set_position(const Point< dim > &new_position)
Sets a new position for the shape.
virtual Tensor< 1, 3 > get_orientation()
Returns the orientation of the shape.
Point< dim > reverse_align_and_center(const Point< dim > &evaluation_point) const
This function applies the inverse operation of align_and_center.
virtual Point< dim > get_bounding_box_center()
Returns the bounding box position.
static double smooth_max(const double a, const double b, const double smooth_factor=10)
Return the smoothed maximum of two variables used for shape contact calculation.
std::unordered_map< std::string, Point< dim > > closest_point_cache
Tensor< 1, dim > bounding_box_half_length
virtual void set_layer_thickening(const double the_layer_thickening)
Sets the layer thickening value (positive or negative) of the particle's shape.
virtual Tensor< 1, dim > get_bounding_box_half_length()
Returns the bounding box half length.
bool bounding_box_contact(Shape< dim > &shape)
Check if the bounding box of this shape and another one are overlapping. This function uses the Separ...
virtual void set_orientation(const Tensor< 1, 3 > &new_orientation)
Sets a new orientation for the shape.
virtual double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override=0
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
Point< dim > align_and_center(const Point< dim > &evaluation_point) const
Most value functions assume that the particle's position is at the origin and that the shape is align...
virtual Tensor< 2, 3 > get_rotation_matrix()
Returns the orientation of the shape.
std::string additional_info_on_shape
virtual double value_with_cell_guess(const Point< dim > &evaluation_point, const typename DoFHandler< dim >::active_cell_iterator &cell, const unsigned int component=0)
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
void set_part_of_a_composite(const bool is_part_of_a_composite)
Defines if this shape is part of a composite. If true, cache management is deactivated and delegated ...
Shape(double radius, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
A general constructor for the Shapes.
virtual double local_curvature_radius_with_cell_guess(const Point< dim > &p, const typename DoFHandler< dim >::active_cell_iterator &cell) override
Return the curvature of the level set at a given point using the.
virtual std::shared_ptr< Manifold< dim - 1, dim > > get_shape_manifold() override
Return the manifold of the sphere as a spherical manifold center at the position of the shape.
Tensor< 1, dim > gradient(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the analytical gradient of the distance.
Sphere(double radius, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructor for a sphere.
void set_position(const Point< dim > &position) override
Sets a new position for the shape.
std::shared_ptr< Functions::SignedDistance::Sphere< dim > > sphere_function
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
std::tuple< double, Tensor< 1, dim >, Point< dim > > distance_to_shape(Shape< dim > &shape, std::vector< Point< dim > > &candidate_points, double precision=1e-6, bool exact_distance_outside_of_contact=false) override
Return the distance, the center point, and the normal between the current shape and the shape given i...
virtual double local_curvature_radius(Point< dim > p) override
Return the curvature of the level set at a given point.
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
std::tuple< double, Tensor< 1, dim >, Point< dim > > distance_to_shape_with_cell_guess(Shape< dim > &shape, const typename DoFHandler< dim >::active_cell_iterator &cell, std::vector< Point< dim > > &candidate_points, double precision=1e-6, bool exact_distance_outside_of_contact=false) override
Return the distance, the center point, and the normal between the current shape and the shape given i...
double displaced_volume() override
Return the volume displaced by the solid.
Point< dim > superquadric_gradient(const Point< dim > ¢ered_point) const
Computes the gradient of the superquadric from its equation.
double value_with_cell_guess(const Point< dim > &evaluation_point, const typename DoFHandler< dim >::active_cell_iterator &cell, const unsigned int component=0) override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
Tensor< 1, dim > gradient_with_cell_guess(const Point< dim > &evaluation_point, const typename DoFHandler< dim >::active_cell_iterator &cell, const unsigned int component=0) override
Return the gradient of the distance function.
void closest_surface_point(const Point< dim > &p, Point< dim > &closest_point, const typename DoFHandler< dim >::active_cell_iterator &cell_guess) override
Sets the closest_point parameter to be the point on the surface of the shape which has the minimal di...
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
Superquadric(const Tensor< 1, dim > half_lengths, const Tensor< 1, dim > exponents, const double epsilon, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructor for a superquadric shape.
Tensor< 1, dim > gradient(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the analytical gradient of the distance.
Tensor< 1, dim > exponents
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
double superquadric(const Point< dim > ¢ered_point) const
Computes the value of the superquadric from its equation.
static double sign(const double prm)
Return the sign of the parameter. To be removed once PR#794 is merged.
Tensor< 1, dim > half_lengths
Torus(double ring_radius, double ring_thickness, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
Constructs a torus with a given thickness and radius.
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
double value(const Point< dim > &evaluation_point, const unsigned int component=0) const override
Return the evaluation of the signed distance function of this solid at the given point evaluation poi...
double displaced_volume() override
Return the volume displaced by the solid.
Point< 2 > point_nd_to_2d(const Point< dim > &point)
Tensor< 1, 2 > tensor_nd_to_2d(const Tensor< 1, dim > &tensor)
Point< 3 > point_nd_to_3d(const Point< dim > &point)