6#include <deal.II/grid/manifold.h>
7#include <deal.II/grid/manifold_lib.h>
11#ifdef DEAL_II_WITH_OPENCASCADE
12# include <deal.II/opencascade/manifold_lib.h>
13# include <deal.II/opencascade/utilities.h>
15# include <BRepBuilderAPI_MakeVertex.hxx>
16# include <BRepClass3d_SolidClassifier.hxx>
17# include <BRepExtrema_DistShapeShape.hxx>
48 Point<dim> center_of_rotation =
position;
49 Point<dim> rotated_point;
50 Point<dim> translated_point;
59 Point<dim> centralized_point;
60 centralized_point = evaluation_point - center_of_rotation;
61 Point<dim> centralized_rotated = centralized_point;
66 if constexpr (dim == 2)
70 Tensor<2, 2> rot_matrix =
71 Physics::Transformations::Rotations::rotation_matrix_2d(-theta[2]);
74 centralized_rotated.clear();
75 for (
int j = 0; j < dim; ++j)
77 for (
int k = 0; k < dim; ++k)
79 centralized_rotated[j] +=
80 rot_matrix[j][k] * centralized_point[k];
87 for (
unsigned int i = 0; i < 3; ++i)
93 Tensor<2, 3> rot_matrix =
94 Physics::Transformations::Rotations::rotation_matrix_3d(
98 centralized_rotated.clear();
99 for (
int j = 0; j < dim; ++j)
101 for (
int k = 0; k < dim; ++k)
103 centralized_rotated[j] +=
104 rot_matrix[j][k] * centralized_point[k];
107 centralized_point = centralized_rotated;
112 rotated_point = centralized_rotated + center_of_rotation;
115 translated_point = rotated_point -
position;
117 return translated_point;
126 Point<dim> center_of_rotation =
position;
127 Point<dim> rotated_point;
128 Point<dim> translated_point;
137 Point<dim> centralized_point;
138 centralized_point = evaluation_point;
139 Point<dim> centralized_rotated = centralized_point;
145 if constexpr (dim == 2)
149 Tensor<2, 2> rot_matrix =
150 Physics::Transformations::Rotations::rotation_matrix_2d(theta[2]);
153 centralized_rotated.clear();
154 for (
int j = 0; j < dim; ++j)
156 for (
int k = 0; k < dim; ++k)
158 centralized_rotated[j] +=
159 rot_matrix[j][k] * centralized_point[k];
166 for (
int i = 0; i < dim; ++i)
172 Tensor<2, 3> rot_matrix =
173 Physics::Transformations::Rotations::rotation_matrix_3d(
177 centralized_rotated.clear();
178 for (
int j = 0; j < dim; ++j)
180 for (
int k = 0; k < dim; ++k)
182 centralized_rotated[j] +=
183 rot_matrix[j][k] * centralized_point[k];
186 centralized_point = centralized_rotated;
190 rotated_point = centralized_rotated + center_of_rotation;
193 translated_point = rotated_point;
195 return translated_point;
199std::shared_ptr<Manifold<dim - 1, dim>>
202 return std::make_shared<FlatManifold<dim - 1, dim>>();
211 std::string point_in_string =
"";
212 for (
int d = 0; d < dim; ++d)
215 point_in_string +
";" +
216 std::to_string(std::round(evaluation_point[d] * 1e12) / 1e12);
218 return point_in_string;
226 Point<dim> &closest_point,
227 const typename DoFHandler<dim>::active_cell_iterator &cell_guess)
229 Tensor<1, dim> actual_gradient;
230 double distance_from_surface;
236 closest_point = p - (actual_gradient / (actual_gradient.norm() +
238 distance_from_surface;
245 Point<dim> &closest_point)
const
247 Tensor<1, dim> actual_gradient;
248 double distance_from_surface;
249 actual_gradient = this->gradient(p);
250 distance_from_surface = this->
value(p);
255 closest_point = p - (actual_gradient / (actual_gradient.norm() +
257 distance_from_surface;
263 const Point<dim> &evaluation_point,
264 const typename DoFHandler<dim>::active_cell_iterator & ,
267 return this->
value(evaluation_point);
273 const Point<dim> &evaluation_point,
274 const typename DoFHandler<dim>::active_cell_iterator & ,
277 return this->gradient(evaluation_point);
283 const unsigned int )
const
290std::shared_ptr<Shape<dim>>
293 std::shared_ptr<Shape<dim>> copy =
303 const unsigned int )
const
309 if ((evaluation_point - this->
position).norm() <
311 return AutoDerivativeFunction<dim>::gradient(evaluation_point);
316std::shared_ptr<Manifold<dim - 1, dim>>
319 return std::make_shared<SphericalManifold<dim - 1, dim>>(this->
position);
342 sphere_function = std::make_shared<Functions::SignedDistance::Sphere<dim>>(
347std::tuple<double, Tensor<1, dim>, Point<dim>>
350 const typename DoFHandler<dim>::active_cell_iterator &cell,
351 std::vector<Point<dim>> &candidate_points,
353 bool exact_distance_outside_of_contact)
355 (void)candidate_points;
357 (void)exact_distance_outside_of_contact;
358 double distance = DBL_MAX;
359 Tensor<1, dim> normal;
360 Point<dim> contact_point;
363 Tensor<1, dim> center_to_center_vector =
368 normal = center_to_center_vector / center_to_center_vector.norm();
382 return std::make_tuple(distance, normal, contact_point);
386std::tuple<double, Tensor<1, dim>, Point<dim>>
388 std::vector<Point<dim>> &candidate_points,
390 bool exact_distance_outside_of_contact)
392 (void)candidate_points;
394 (void)exact_distance_outside_of_contact;
395 double distance = DBL_MAX;
396 Tensor<1, dim> normal;
397 Point<dim> contact_point;
400 Tensor<1, dim> center_to_center_vector =
405 normal = center_to_center_vector / center_to_center_vector.norm();
412 normal = -shape.gradient(this->
position);
417 return std::make_tuple(distance, normal, contact_point);
431 const typename DoFHandler<dim>::active_cell_iterator &cell)
441 const unsigned int )
const
444 double dot_product = scalar_product((current_point),
normal);
445 Point<dim> projected_point =
446 current_point - dot_product /
normal.norm_square() *
normal;
449 return (rotate_in_globalpoint - evaluation_point).norm();
451 return -(rotate_in_globalpoint - evaluation_point).norm();
455std::shared_ptr<Shape<dim>>
458 std::shared_ptr<Shape<dim>> copy =
466 const unsigned int )
const
468 (void)evaluation_point;
470 if constexpr (dim == 2)
492 Point<dim> &closest_point,
493 const typename DoFHandler<dim>::active_cell_iterator & )
501 Point<dim> copy_closest_point{};
502 for (
int d = 0; d < dim; d++)
503 copy_closest_point[d] = closest_point[d];
512 closest_point = iterator->second;
518 Point<dim> &closest_point)
const
529 unsigned int iteration = 0;
530 constexpr unsigned int iteration_max = 1e2;
532 Point<dim> dx{}, distance_gradient{};
535 while (iteration < iteration_max && abs(current_distance) >
epsilon)
537 constexpr double relaxation = 1;
541 if (distance_gradient.norm() <
epsilon)
547 dx = -relaxation * (current_distance * distance_gradient) /
548 distance_gradient.norm() /
549 std::max(1.0, distance_gradient.norm());
551 current_point = current_point + dx;
559 closest_point = iterator->second;
565 const unsigned int )
const
570 auto iterator = this->
value_cache.find(point_in_string);
575 Point<dim> closest_point{};
580 return (closest_point - evaluation_point).norm() -
583 return -(closest_point - evaluation_point).norm() -
587 return iterator->second;
593 const Point<dim> &evaluation_point,
594 const typename DoFHandler<dim>::active_cell_iterator & ,
598 auto iterator = this->
value_cache.find(point_in_string);
603 Point<dim> closest_point{};
605 Point<dim> copy_closest_point{};
606 for (
int d = 0; d < dim; d++)
607 copy_closest_point[d] = closest_point[d];
620 return iterator->second;
624std::shared_ptr<Shape<dim>>
627 std::shared_ptr<Shape<dim>> copy =
639 const unsigned int )
const
645 Point<dim> closest_point{};
651 gradient = (evaluation_point - closest_point) /
652 ((evaluation_point - closest_point).norm() +
655 gradient = -(evaluation_point - closest_point) /
656 ((evaluation_point - closest_point).norm() +
661 return iterator->second;
667 const Point<dim> &evaluation_point,
668 const typename DoFHandler<dim>::active_cell_iterator & ,
677 Point<dim> closest_point{};
679 Point<dim> copy_closest_point{};
680 for (
int d = 0; d < dim; d++)
681 copy_closest_point[d] = closest_point[d];
683 Tensor<1, dim>
gradient = this->gradient(evaluation_point);
693 return iterator->second;
699 const unsigned int )
const
701#ifdef DEAL_II_WITH_OPENCASCADE
703 auto iterator = this->
value_cache.find(point_in_string);
705 return iterator->second;
708 Point<dim> projected_point;
709 auto pt = OpenCASCADE::point(centered_point);
710 TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(pt);
711 BRepExtrema_DistShapeShape distancetool(shape, vertex);
712 distancetool.Perform();
713 gp_Pnt pt_on_surface = distancetool.PointOnShape1(1);
714 projected_point[0] = pt_on_surface.X();
715 projected_point[1] = pt_on_surface.Y();
716 if constexpr (dim == 3)
718 projected_point[2] = pt_on_surface.Z();
721 BRepClass3d_SolidClassifier point_classifier(shape);
722 point_classifier.Perform(pt, shape_tol);
723 TopAbs_State point_state = point_classifier.State();
727 if (point_state == TopAbs_State::TopAbs_IN)
733 auto rotate_in_globalpoint =
735 return -(rotate_in_globalpoint - evaluation_point).norm() -
740 auto rotate_in_globalpoint =
742 return (rotate_in_globalpoint - evaluation_point).norm() -
747 (void)evaluation_point;
754 const Point<dim> &evaluation_point,
755 const typename DoFHandler<dim>::active_cell_iterator & ,
758#ifdef DEAL_II_WITH_OPENCASCADE
760 auto iterator = this->
value_cache.find(point_in_string);
766 Point<dim> projected_point;
767 vertex_position = OpenCASCADE::point(centered_point);
769 vertex = BRepBuilderAPI_MakeVertex(vertex_position);
770 distancetool.LoadS2(vertex);
771 distancetool.Perform();
774 gp_Pnt pt_on_surface = distancetool.PointOnShape1(1);
775 projected_point[0] = pt_on_surface.X();
776 projected_point[1] = pt_on_surface.Y();
777 if constexpr (dim == 3)
779 projected_point[2] = pt_on_surface.Z();
782 point_classifier.Perform(vertex_position, shape_tol);
783 TopAbs_State point_state = point_classifier.State();
788 if (point_state == TopAbs_State::TopAbs_IN)
798 -(centered_point - projected_point).norm();
799 auto rotate_in_globalpoint =
802 (rotate_in_globalpoint - evaluation_point) /
803 ((rotate_in_globalpoint - evaluation_point).norm() + 1.0e-16);
805 return -(centered_point - projected_point).norm() -
813 (centered_point - projected_point).norm();
814 auto rotate_in_globalpoint =
817 -(rotate_in_globalpoint - evaluation_point) /
818 ((rotate_in_globalpoint - evaluation_point).norm() + 1.0e-16);
820 return (centered_point - projected_point).norm() -
829 (void)evaluation_point;
835std::shared_ptr<Shape<dim>>
838 std::shared_ptr<Shape<dim>> copy =
848 const unsigned int )
const
850#ifdef DEAL_II_WITH_OPENCASCADE
852 Point<dim> projected_point;
855 auto pt = OpenCASCADE::point(centered_point);
856 TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(pt);
858 BRepExtrema_DistShapeShape distancetool(shape, vertex);
859 distancetool.Perform();
860 gp_Pnt pt_on_surface = distancetool.PointOnShape1(1);
863 projected_point[0] = pt_on_surface.X();
864 projected_point[1] = pt_on_surface.Y();
865 if constexpr (dim == 3)
867 projected_point[2] = pt_on_surface.Z();
869 BRepClass3d_SolidClassifier point_classifier(shape);
870 point_classifier.Perform(pt, shape_tol);
871 TopAbs_State point_state = point_classifier.State();
875 if (point_state == TopAbs_State::TopAbs_IN)
881 auto rotate_in_globalpoint =
883 return (rotate_in_globalpoint - evaluation_point) /
884 ((rotate_in_globalpoint - evaluation_point).norm() + 1.0e-16);
888 auto rotate_in_globalpoint =
890 return -(rotate_in_globalpoint - evaluation_point) /
891 ((rotate_in_globalpoint - evaluation_point).norm() + 1.0e-16);
895 (void)evaluation_point;
904 const Point<dim> &evaluation_point,
905 const typename DoFHandler<dim>::active_cell_iterator & ,
908#ifdef DEAL_II_WITH_OPENCASCADE
921 Point<dim> projected_point;
922 vertex_position = OpenCASCADE::point(centered_point);
924 vertex = BRepBuilderAPI_MakeVertex(vertex_position);
925 distancetool.LoadS2(vertex);
926 distancetool.Perform();
929 gp_Pnt pt_on_surface = distancetool.PointOnShape1(1);
930 projected_point[0] = pt_on_surface.X();
931 projected_point[1] = pt_on_surface.Y();
932 if constexpr (dim == 3)
934 projected_point[2] = pt_on_surface.Z();
936 point_classifier.Perform(vertex_position, shape_tol);
937 TopAbs_State point_state = point_classifier.State();
942 if (point_state == TopAbs_State::TopAbs_IN)
946 auto rotate_in_globalpoint =
951 -(centered_point - projected_point).norm();
953 (rotate_in_globalpoint - evaluation_point) /
954 ((rotate_in_globalpoint - evaluation_point).norm() + 1.0e-16);
958 return (rotate_in_globalpoint - evaluation_point) /
959 ((rotate_in_globalpoint - evaluation_point).norm() +
964 auto rotate_in_globalpoint =
969 (centered_point - projected_point).norm();
971 -(rotate_in_globalpoint - evaluation_point) /
972 ((rotate_in_globalpoint - evaluation_point).norm() + 1.0e-16);
976 return -(rotate_in_globalpoint - evaluation_point) /
977 ((rotate_in_globalpoint - evaluation_point).norm() +
989 (void)evaluation_point;
990 return Tensor<1, dim>();
1013 const unsigned int )
const
1018 Point<dim> half_lengths_dim;
1019 for (
int i = 0; i < dim; ++i)
1021 abs_p[i] = std::abs(centered_point[i]);
1025 q = abs_p - half_lengths_dim;
1027 for (
int i = 0; i < dim; ++i)
1029 max_q_0[i] = std::max(q[i], 0.0);
1031 const double max_q = std::max(q[0], std::max(q[1], q[dim - 1]));
1036std::shared_ptr<Shape<dim>>
1039 std::shared_ptr<Shape<dim>> copy =
1040 std::make_shared<HyperRectangle<dim>>(this->
half_lengths,
1050 double solid_volume = 1.0;
1051 for (
int i = 0; i < dim; ++i)
1055 return solid_volume;
1061 const unsigned int )
const
1067 for (
int i = 0; i < dim; ++i)
1070 v_k0[i] = centered_point[i] /
radii[i];
1071 v_k1[i] = centered_point[i] / (
radii[i] *
radii[i]);
1073 double k0 = v_k0.norm();
1074 double k1 = v_k1.norm();
1079std::shared_ptr<Shape<dim>>
1082 std::shared_ptr<Shape<dim>> copy =
1083 std::make_shared<Ellipsoid<dim>>(this->
radii,
1094 double solid_volume = PI * 4.0 / 3.0;
1095 for (
int i = 0; i < dim; i++)
1097 solid_volume = solid_volume *
radii[i];
1099 return solid_volume;
1105 const unsigned int )
const
1107 AssertDimension(dim, 3);
1111 Point<2> p_xz({centered_point[0], centered_point[2]});
1112 Point<2> q({p_xz.norm() -
ring_radius, centered_point[1]});
1117std::shared_ptr<Shape<dim>>
1120 std::shared_ptr<Shape<dim>> copy = std::make_shared<Torus<dim>>(
1136 const unsigned int )
const
1138 AssertDimension(dim, 3);
1143 Point<2> p_xz({centered_point[0], centered_point[2]});
1144 Point<2> w({p_xz.norm(), centered_point[1]});
1145 double dot_w_q = scalar_product<1, 2, double>(w,
intermediate_q);
1149 Point<2> b_intermediate1({std::clamp(w[0] /
intermediate_q[0], 0.0, 1.), 1.});
1150 Point<2> b_intermediate2({
intermediate_q[0] * b_intermediate1[0],
1153 b = w - b_intermediate2;
1155 double d = std::min(scalar_product<1, 2, double>(a, a),
1156 scalar_product<1, 2, double>(b, b));
1160 return sqrt(d) * ((s > 0) ? 1 : ((s < 0) ? -1 : 0)) - this->
layer_thickening;
1164std::shared_ptr<Shape<dim>>
1167 std::shared_ptr<Shape<dim>> copy = std::make_shared<Cone<dim>>(
1183 const unsigned int )
const
1185 AssertDimension(dim, 3);
1189 Point<2> p_xz({centered_point[0], centered_point[2]});
1190 Point<2> q({p_xz.norm(), centered_point[1]});
1205std::shared_ptr<Shape<dim>>
1208 std::shared_ptr<Shape<dim>> copy =
1209 std::make_shared<CutHollowSphere<dim>>(this->
radius,
1223 return 4.0 * PI / 3.0 *
1225 small_radius * small_radius * small_radius);
1231 const unsigned int )
const
1233 AssertDimension(dim, 3);
1237 Point<2> p_yz({centered_point[1], centered_point[2]});
1238 Point<2> corrected_p_2d({centered_point[0], p_yz.norm()});
1248 return std::max(corrected_p_2d.norm() -
radius,
1255std::shared_ptr<Shape<dim>>
1258 std::shared_ptr<Shape<dim>> copy =
1259 std::make_shared<DeathStar<dim>>(this->
radius,
1278 const unsigned int )
const
1281 auto iterator = this->
value_cache.find(point_in_string);
1289 std::map<unsigned int, double> constituent_shapes_values;
1290 std::map<unsigned int, Tensor<1, dim>> constituent_shapes_gradients;
1291 for (
auto const &[component_id, component] :
constituents)
1293 constituent_shapes_values[component_id] =
1294 component->value(centered_point);
1299 constituent_shapes_gradients[component_id] = Tensor<1, dim>{};
1305 constituent_shapes_gradients);
1309 return iterator->second;
1315 const Point<dim> &evaluation_point,
1316 const typename DoFHandler<dim>::active_cell_iterator &cell,
1317 const unsigned int )
1320 auto iterator = this->
value_cache.find(point_in_string);
1328 std::map<unsigned int, double> constituent_shapes_values;
1329 std::map<unsigned int, Tensor<1, dim>> constituent_shapes_gradients;
1330 for (
auto const &[component_id, component] :
constituents)
1332 constituent_shapes_values[component_id] =
1333 component->value_with_cell_guess(centered_point, cell);
1338 constituent_shapes_gradients[component_id] = Tensor<1, dim>{};
1344 constituent_shapes_gradients);
1358 const unsigned int )
const
1368 std::map<unsigned int, double> constituent_shapes_values;
1369 std::map<unsigned int, Tensor<1, dim>> constituent_shapes_gradients;
1370 for (
auto const &[component_id, component] :
constituents)
1372 constituent_shapes_values[component_id] =
1373 component->value(centered_point);
1374 constituent_shapes_gradients[component_id] =
1375 component->gradient(centered_point);
1382 constituent_shapes_gradients);
1388 Point<dim> closest_point_shape_referential =
1392 Point<dim> closest_point_global_referential =
1394 gradient = -(closest_point_global_referential - evaluation_point) /
1395 ((closest_point_global_referential - evaluation_point).norm() +
1401 return iterator->second;
1407 const Point<dim> &evaluation_point,
1408 const typename DoFHandler<dim>::active_cell_iterator &cell,
1409 const unsigned int )
1419 std::map<unsigned int, double> constituent_shapes_values;
1420 std::map<unsigned int, Tensor<1, dim>> constituent_shapes_gradients;
1421 for (
auto const &[component_id, component] :
constituents)
1423 constituent_shapes_values[component_id] =
1424 component->value_with_cell_guess(centered_point, cell);
1425 constituent_shapes_gradients[component_id] =
1426 component->gradient_with_cell_guess(centered_point, cell);
1433 constituent_shapes_gradients);
1439 Point<dim> closest_point_shape_referential =
1443 Point<dim> closest_point_global_referential =
1445 gradient = -(closest_point_global_referential - evaluation_point) /
1446 ((closest_point_global_referential - evaluation_point).norm() +
1459std::shared_ptr<Shape<dim>>
1462 std::shared_ptr<Shape<dim>> copy = std::make_shared<CompositeShape<dim>>(
1470 DoFHandler<dim> &updated_dof_handler,
1471 const bool mesh_based_precalculations)
1473 if (!mesh_based_precalculations)
1475 for (
auto const &constituent :
constituents | boost::adaptors::map_values)
1477 std::static_pointer_cast<RBFShape<dim>>(constituent)
1479 mesh_based_precalculations);
1481 std::static_pointer_cast<CompositeShape<dim>>(constituent)
1483 mesh_based_precalculations);
1490 for (
auto const &constituent :
constituents | boost::adaptors::map_values)
1492 std::static_pointer_cast<RBFShape<dim>>(constituent)
1495 std::static_pointer_cast<CompositeShape<dim>>(constituent)
1502 DoFHandler<dim> &updated_dof_handler,
1503 const bool mesh_based_precalculations)
1505 for (
auto const &constituent :
constituents | boost::adaptors::map_values)
1507 std::static_pointer_cast<RBFShape<dim>>(constituent)
1509 mesh_based_precalculations);
1511 std::static_pointer_cast<CompositeShape<dim>>(constituent)
1513 mesh_based_precalculations);
1517std::pair<double, Tensor<1, dim>>
1519 std::map<unsigned int, double> constituent_shapes_values,
1520 std::map<
unsigned int, Tensor<1, dim>> constituent_shapes_gradients)
const
1524 double levelset = constituent_shapes_values[0];
1525 Tensor<1, dim>
gradient = constituent_shapes_gradients[0];
1526 for (
auto const &[operation_id, op_triplet] :
operations)
1529 unsigned int first_id;
1530 unsigned int second_id;
1531 std::tie(operation, first_id, second_id) = op_triplet;
1533 double value_first_component, value_second_component;
1534 Tensor<1, dim> gradient_first_component{};
1535 Tensor<1, dim> gradient_second_component{};
1536 value_first_component = constituent_shapes_values.at(first_id);
1537 value_second_component = constituent_shapes_values.at(second_id);
1538 gradient_first_component = constituent_shapes_gradients.at(first_id);
1539 gradient_second_component = constituent_shapes_gradients.at(second_id);
1543 if (value_first_component < value_second_component)
1545 constituent_shapes_values[operation_id] = value_first_component;
1546 constituent_shapes_gradients[operation_id] =
1547 gradient_first_component;
1551 constituent_shapes_values[operation_id] =
1552 value_second_component;
1553 constituent_shapes_gradients[operation_id] =
1554 gradient_second_component;
1558 if (-value_first_component > value_second_component)
1560 constituent_shapes_values[operation_id] =
1561 -value_first_component;
1562 constituent_shapes_gradients[operation_id] =
1563 -gradient_first_component;
1567 constituent_shapes_values[operation_id] =
1568 value_second_component;
1569 constituent_shapes_gradients[operation_id] =
1570 gradient_second_component;
1574 if (value_first_component > value_second_component)
1576 constituent_shapes_values[operation_id] = value_first_component;
1577 constituent_shapes_gradients[operation_id] =
1578 gradient_first_component;
1582 constituent_shapes_values[operation_id] =
1583 value_second_component;
1584 constituent_shapes_gradients[operation_id] =
1585 gradient_second_component;
1588 levelset = constituent_shapes_values[operation_id];
1589 gradient = constituent_shapes_gradients[operation_id];
1609 for (
auto const &constituent :
constituents | boost::adaptors::map_values)
1629 this->
filename = shape_arguments_str;
1636 const Point<dim> &evaluation_point,
1637 const typename DoFHandler<dim>::active_cell_iterator &cell,
1638 const unsigned int )
1640 double bounding_box_distance =
bounding_box->value(evaluation_point);
1641 if (bounding_box_distance >= 0)
1645 auto iterator = this->
value_cache.find(point_in_string);
1649 double value = this->value(evaluation_point);
1666 const Point<dim> &evaluation_point,
1667 const typename DoFHandler<dim>::active_cell_iterator &cell,
1668 const unsigned int )
1670 Point<dim> centered_point = evaluation_point;
1671 double bounding_box_distance =
bounding_box->value(centered_point);
1672 Tensor<1, dim> bounding_box_gradient =
bounding_box->gradient(centered_point);
1673 if (bounding_box_distance > 0.)
1674 return bounding_box_gradient;
1681 Tensor<1, dim>
gradient = this->gradient(evaluation_point);
1698 const unsigned int )
const
1700 double bounding_box_distance =
bounding_box->value(evaluation_point);
1701 if (bounding_box_distance >= 0)
1706 auto iterator = this->
value_cache.find(point_in_string);
1708 return iterator->second;
1710 double value = std::max(bounding_box_distance, 0.0);
1711 double normalized_distance, basis;
1716 for (
size_t portion_id = 0; portion_id <
iterable_nodes.size(); portion_id++)
1718 for (
const size_t &node_id : *(std::get<2>(
iterable_nodes[portion_id])))
1720 normalized_distance =
1727 normalized_distance);
1731 return value - this->layer_thickening;
1737 const unsigned int )
const
1739 Point<dim> centered_point = evaluation_point;
1740 double bounding_box_distance =
bounding_box->value(centered_point);
1741 Tensor<1, dim> bounding_box_gradient =
bounding_box->gradient(centered_point);
1742 if (bounding_box_distance > 0.)
1743 return bounding_box_gradient;
1745 double distance, normalized_distance;
1746 Point<dim> relative_position{};
1751 double dbasis_drnorm_derivative;
1752 double drnorm_dr_derivative;
1753 Tensor<1, dim> dr_dx_derivative{};
1758 throw std::logic_error(
1759 "Every location inside the bounding box should be covered by the radius "
1760 "of at least one RBF node. It this isn't the case, an error has been "
1761 "introduced in the code. ");
1766 for (
size_t portion_id = 0; portion_id <
iterable_nodes.size(); portion_id++)
1768 for (
const size_t &node_id : *(std::get<2>(
iterable_nodes[portion_id])))
1773 distance = (relative_position).norm();
1776 dr_dx_derivative = relative_position / distance;
1788 for (
int d = 0; d < dim; d++)
1789 dr_dx_derivative[d] = 0;
1798 normalized_distance);
1800 gradient += dbasis_drnorm_derivative * drnorm_dr_derivative *
1801 dr_dx_derivative *
weights[node_id];
1808std::shared_ptr<Shape<dim>>
1811 std::shared_ptr<Shape<dim>> copy =
1812 std::make_shared<RBFShape<dim>>(this->
filename,
1829 Point<dim> high_bounding_point{};
1830 Point<dim> low_bounding_point{};
1832 Tensor<1, dim> half_lengths = Tensor<1, dim>();
1833 for (
int d = 0; d < dim; d++)
1835 high_bounding_point[d] = std::numeric_limits<double>::lowest();
1836 low_bounding_point[d] = std::numeric_limits<double>::max();
1839 low_bounding_point[d] =
1841 high_bounding_point[d] =
1845 0.5 * (low_bounding_point[d] + high_bounding_point[d]);
1846 half_lengths[d] = 0.5 * (high_bounding_point[d] - low_bounding_point[d]);
1849 std::make_shared<HyperRectangle<dim>>(half_lengths,
1854 this->bounding_box_center =
1861 const bool mesh_based_precalculations)
1863 if (!mesh_based_precalculations)
1871 const unsigned int maximal_level =
1872 updated_dof_handler.get_triangulation().n_levels();
1876 std::shared_ptr<std::vector<size_t>> temporary_node_numbers =
1878 std::iota(std::begin(*temporary_node_numbers),
1879 std::end(*temporary_node_numbers),
1881 std::map<const typename DoFHandler<dim>::cell_iterator,
1882 std::tuple<Point<dim>, double, std::shared_ptr<std::vector<size_t>>>>
1883 temporary_nodes_portions_map;
1884 temporary_nodes_portions_map.clear();
1885 for (
unsigned int level = 0; level < maximal_level; level++)
1888 const auto &cell_iterator =
1889 updated_dof_handler.cell_iterators_on_level(level);
1890 for (
const auto &cell : cell_iterator)
1892 if (cell->is_artificial_on_level())
1894 if (cell->level() > 0)
1897 const auto cell_parent = cell->parent();
1898 const auto parent_iterator =
1899 temporary_nodes_portions_map.find(cell_parent);
1900 if (parent_iterator != temporary_nodes_portions_map.end())
1902 temporary_node_numbers =
1903 std::get<2>(parent_iterator->second);
1910 catch (TriaAccessorExceptions::ExcCellHasNoParent())
1913 std::shared_ptr<std::vector<size_t>> current_cell_nodes =
1914 std::make_shared<std::vector<size_t>>();
1916 for (
unsigned int i = 0; i < temporary_node_numbers->size(); i++)
1918 if (cell->point_inside(
1920 current_cell_nodes->push_back(temporary_node_numbers->at(i));
1924 current_cell_nodes->shrink_to_fit();
1925 if (!current_cell_nodes->empty())
1926 temporary_nodes_portions_map[cell] =
1927 std::make_tuple(cell->barycenter(),
1929 current_cell_nodes);
1936 for (
auto it = temporary_nodes_portions_map.cbegin();
1937 it != temporary_nodes_portions_map.cend();)
1939 auto cell = it->first;
1940 const unsigned int cell_level = cell->level();
1941 bool cell_still_needed = cell->is_active() || cell_level == level;
1943 auto previous_it = it;
1945 if (!cell_still_needed)
1946 temporary_nodes_portions_map.erase(previous_it);
1951 const auto &cell_iterator = updated_dof_handler.cell_iterators_on_level(0);
1952 typename DoFHandler<dim>::cell_iterator temp_cell;
1953 std::tuple<Point<dim>, double, std::shared_ptr<std::vector<size_t>>>
1955 for (
const auto &cell : cell_iterator)
1957 if (cell->is_artificial_on_level())
1962 tuple<Point<dim>, double, std::shared_ptr<std::vector<size_t>>>>>();
1963 for (
auto it = temporary_nodes_portions_map.cbegin();
1964 it != temporary_nodes_portions_map.cend();
1967 temp_cell = it->first;
1968 if (temp_cell->is_active())
1970 temp_cell_tuple = std::make_tuple(temp_cell->barycenter(),
1971 temp_cell->diameter(),
1972 std::get<2>(it->second));
1979 for (
unsigned int level = 1; level < maximal_level; level++)
1981 const auto &cell_iterator_on_level =
1982 updated_dof_handler.cell_iterators_on_level(level);
1983 for (
const auto &cell : cell_iterator_on_level)
1985 if (cell->is_artificial_on_level())
1991 const bool cell_smaller_than_rbf_radius =
1993 if (cell_smaller_than_rbf_radius)
2004 auto cell = it->first;
2005 bool cell_still_needed = cell->is_active() && !cell->is_artificial();
2007 auto previous_it = it;
2009 if (!cell_still_needed)
2019 for (
auto it = temporary_nodes_portions_map.cbegin();
2020 it != temporary_nodes_portions_map.cend();
2023 auto cell = it->first;
2024 if (!cell->is_active())
2026 if (std::get<2>(it->second).use_count() <= 1)
2028 for (
const size_t &node_id : *(std::get<2>(it->second)))
2036 const typename DoFHandler<dim>::cell_iterator &cell,
2037 const Point<dim> support_point)
2043 bool parent_found =
false;
2045 std::tuple<Point<dim>, double, std::shared_ptr<std::vector<size_t>>>>
2046 temporary_iterable_nodes{
2047 {Point<dim>{}, 0, std::make_shared<std::vector<size_t>>()}};
2048 if (cell->level() > 0)
2051 const auto cell_parent = cell->parent();
2055 parent_found =
true;
2060 catch (TriaAccessorExceptions::ExcCellHasNoParent())
2063 double distance, max_distance;
2064 const double cell_diameter = cell->diameter();
2065 Point<dim> temp_cell_barycenter;
2068 std::tuple<Point<dim>, double, std::shared_ptr<std::vector<size_t>>>>>();
2070 for (
size_t portion_id = 0; portion_id < number_of_portions; portion_id++)
2072 double temp_cell_diameter;
2073 std::tie(temp_cell_barycenter, temp_cell_diameter, std::ignore) =
2077 distance = (support_point - temp_cell_barycenter).norm();
2083 if (distance < max_distance)
2091 const auto cell_parent = cell->parent();
2114 std::map<std::string, std::vector<double>> rbf_data;
2118 weights.swap(rbf_data[
"weight"]);
2122 Point<dim> temp_point;
2125 temp_point[0] = rbf_data[
"node_x"][i];
2126 temp_point[1] = rbf_data[
"node_y"][i];
2127 if constexpr (dim == 3)
2128 temp_point[2] = rbf_data[
"node_z"][i];
2132 std::shared_ptr<std::vector<size_t>> temp_nodes_id =
2134 std::iota(std::begin(*temp_nodes_id), std::end(*temp_nodes_id), 0);
2137 std::numeric_limits<double>::max(),
2149 const bool mesh_based_precalculations)
2151 if (!mesh_based_precalculations)
2156 mesh_based_precalculations);
2159 size_t current_number_of_kept_rbf_nodes = 0;
2162 current_number_of_kept_rbf_nodes++;
2164 std::vector<double> temp_weights;
2165 std::vector<Point<dim>> temp_rotated_nodes_positions;
2166 std::vector<double> temp_support_radii;
2167 std::vector<double> temp_basis_functions;
2170 std::shared_ptr<std::vector<size_t>> temp_nodes_id =
2171 std::make_shared<std::vector<size_t>>(current_number_of_kept_rbf_nodes);
2172 std::iota(std::begin(*temp_nodes_id), std::end(*temp_nodes_id), 0);
2175 std::numeric_limits<double>::max(),
2181 temp_weights.resize(current_number_of_kept_rbf_nodes);
2187 temp_weights[counter] =
weights[i];
2192 temp_weights.clear();
2196 temp_rotated_nodes_positions.resize(current_number_of_kept_rbf_nodes);
2207 temp_rotated_nodes_positions.clear();
2211 temp_support_radii.resize(current_number_of_kept_rbf_nodes);
2222 temp_support_radii.clear();
2226 temp_basis_functions.resize(current_number_of_kept_rbf_nodes);
2237 temp_basis_functions.clear();
2248 for (
unsigned int i = 0; i <
weights.size(); ++i)
2258 const double distance)
const
2260 switch (basis_function)
2299 const double distance)
const
2301 switch (basis_function)
2339 const typename DoFHandler<dim>::active_cell_iterator &cell)
2350 const unsigned int )
const
2355 double p_radius = std::pow(centered_point[0] * centered_point[0] +
2356 centered_point[1] * centered_point[1],
2358 double radius_diff = p_radius -
radius;
2359 double h_diff = abs(centered_point[2]) -
half_length;
2361 if (radius_diff > 0 && h_diff > 0)
2362 return std::pow(radius_diff * radius_diff + h_diff * h_diff, 0.5) -
2364 else if (radius_diff <= 0 && h_diff > 0)
2366 else if (radius_diff > 0 && h_diff <= 0)
2367 return radius_diff - this->layer_thickening;
2369 return std::max(radius_diff, h_diff) - this->layer_thickening;
2373std::shared_ptr<Shape<dim>>
2376 std::shared_ptr<Shape<dim>> copy = std::make_shared<Cylinder<dim>>(
2388 return solid_volume;
2394 const unsigned int )
const
2400 double level_set_of_cylinder_hollow = 0;
2401 double p_radius = std::pow(centered_point[0] * centered_point[0] +
2402 centered_point[1] * centered_point[1],
2406 double h_diff_o = abs(centered_point[2] -
height / 2) -
height / 2;
2408 if (radius_diff_o > 0 && h_diff_o > 0)
2409 level_set_of_cylinder_hollow =
2410 std::pow(radius_diff_o * radius_diff_o + h_diff_o * h_diff_o, 0.5);
2411 else if (radius_diff_o > 0 && h_diff_o <= 0)
2412 level_set_of_cylinder_hollow = radius_diff_o;
2413 else if (radius_diff_o <= 0 && radius_diff_i > 0 && h_diff_o > 0)
2414 level_set_of_cylinder_hollow = h_diff_o;
2415 else if (radius_diff_i <= 0 && h_diff_o > 0)
2416 level_set_of_cylinder_hollow =
2417 std::pow(radius_diff_i * radius_diff_i + h_diff_o * h_diff_o, 0.5);
2418 else if (radius_diff_i <= 0 && h_diff_o <= 0)
2419 level_set_of_cylinder_hollow = -radius_diff_i;
2421 level_set_of_cylinder_hollow =
2422 std::max({radius_diff_o, h_diff_o, -radius_diff_i});
2428std::shared_ptr<Shape<dim>>
2431 std::shared_ptr<Shape<dim>> copy =
2445 double solid_volume =
height * PI *
2451 return solid_volume;
2458 const unsigned int )
const
2468 double phase = std::atan2(centered_point[1], centered_point[0]);
2469 if (std::isnan(
phase))
2476 double phase_at_top = (nb_turns - std::floor(nb_turns)) * 2 * numbers::PI;
2477 double x = centered_point[2] -
phase *
pitch / (2 * numbers::PI);
2481 double t_initial_guess = 0;
2486 t_initial_guess = std::floor(x /
pitch) * 2 * numbers::PI +
phase;
2490 double level_set_tube = 0;
2491 t = t_initial_guess;
2492 double residual = -(
radius * cos(t) - centered_point[0]) * sin(t) *
radius +
2493 (
radius * sin(t) - centered_point[1]) * cos(t) *
radius +
2494 (
pitch / (2 * numbers::PI) * t - centered_point[2]) *
2495 pitch / (2 * numbers::PI);
2502 residual = -(
radius * cos(t) - centered_point[0]) * sin(t) *
radius +
2503 (
radius * sin(t) - centered_point[1]) * cos(t) *
radius +
2504 (
pitch / (2 * numbers::PI) * t - centered_point[2]) *
pitch /
2506 double dr_dt = centered_point[0] * cos(t) *
radius +
2507 centered_point[1] * sin(t) *
radius +
2508 (
pitch / (2 * numbers::PI)) * (
pitch / (2 * numbers::PI));
2509 t = t - residual / dr_dt;
2513 if (t > nb_turns * numbers::PI * 2)
2515 t = nb_turns * numbers::PI * 2;
2516 Point<dim> point_on_helix;
2517 point_on_helix[0] =
radius * cos(t);
2518 point_on_helix[1] =
radius * sin(t);
2519 point_on_helix[2] = t *
pitch / (2 * numbers::PI);
2520 level_set_tube = (centered_point - point_on_helix).norm();
2525 Point<dim> point_on_helix;
2526 point_on_helix[0] =
radius * cos(t);
2527 point_on_helix[1] =
radius * sin(t);
2528 point_on_helix[2] = t *
pitch / (2 * numbers::PI);
2530 level_set_tube = (centered_point - point_on_helix).norm();
2534 Point<dim> point_on_helix;
2535 point_on_helix[0] =
radius * cos(t);
2536 point_on_helix[1] =
radius * sin(t);
2537 point_on_helix[2] = t *
pitch / (2 * numbers::PI);
2538 level_set_tube = (centered_point - point_on_helix).norm() -
radius_disk;
2542 double level_set_tube_2 = 0;
2543 t = t_initial_guess + 2 * numbers::PI;
2544 residual = -(
radius * cos(t) - centered_point[0]) * sin(t) *
radius +
2545 (
radius * sin(t) - centered_point[1]) * cos(t) *
radius +
2546 (
pitch / (2 * numbers::PI) * t - centered_point[2]) *
pitch /
2552 residual = -(
radius * cos(t) - centered_point[0]) * sin(t) *
radius +
2553 (
radius * sin(t) - centered_point[1]) * cos(t) *
radius +
2554 (
pitch / (2 * numbers::PI) * t - centered_point[2]) *
pitch /
2556 double dr_dt = centered_point[0] * cos(t) *
radius +
2557 centered_point[1] * sin(t) *
radius +
2558 (
pitch / (2 * numbers::PI)) * (
pitch / (2 * numbers::PI));
2559 t = t - residual / dr_dt;
2563 if (t > nb_turns * numbers::PI * 2)
2565 t = nb_turns * numbers::PI * 2;
2566 Point<dim> point_on_helix;
2567 point_on_helix[0] =
radius * cos(t);
2568 point_on_helix[1] =
radius * sin(t);
2569 point_on_helix[2] = t *
pitch / (2 * numbers::PI);
2570 level_set_tube_2 = (centered_point - point_on_helix).norm();
2575 Point<dim> point_on_helix;
2576 point_on_helix[0] =
radius * cos(t);
2577 point_on_helix[1] =
radius * sin(t);
2578 point_on_helix[2] = t *
pitch / (2 * numbers::PI);
2580 level_set_tube_2 = (centered_point - point_on_helix).norm();
2584 Point<dim> point_on_helix;
2585 point_on_helix[0] =
radius * cos(t);
2586 point_on_helix[1] =
radius * sin(t);
2587 point_on_helix[2] = t *
pitch / (2 * numbers::PI);
2588 level_set_tube_2 = (centered_point - point_on_helix).norm() -
radius_disk;
2592 level_set_tube = std::min(level_set_tube, level_set_tube_2);
2595 Point<dim> point_at_base;
2596 Tensor<1, dim> vector_at_base;
2597 point_at_base[0] =
radius;
2598 point_at_base[1] = 0;
2599 point_at_base[2] = 0;
2600 vector_at_base[0] = 0;
2601 vector_at_base[1] = -
radius;
2602 vector_at_base[2] = -
pitch / (2 * numbers::PI);
2604 double p_radius_cap_base =
2605 ((centered_point - point_at_base) -
2606 scalar_product((centered_point - point_at_base), vector_at_base) /
2607 vector_at_base.norm_square() * vector_at_base)
2609 double radial_distance_cap_base = p_radius_cap_base -
radius_disk;
2610 double h_dist_from_cap_0 =
2611 (scalar_product((centered_point - point_at_base), vector_at_base) /
2612 vector_at_base.norm_square() * vector_at_base)
2615 double dist_from_cap = 0;
2616 if (radial_distance_cap_base > 0)
2618 std::pow(h_dist_from_cap_0 * h_dist_from_cap_0 +
2619 radial_distance_cap_base * radial_distance_cap_base,
2622 dist_from_cap = h_dist_from_cap_0;
2625 Point<dim> point_at_top;
2626 Tensor<1, dim> vector_at_top;
2627 point_at_top[0] = std::cos(phase_at_top) *
radius;
2628 point_at_top[1] = std::sin(phase_at_top) *
radius;
2629 point_at_top[2] =
height;
2630 vector_at_top[0] = -point_at_top[1];
2631 vector_at_top[1] = point_at_top[0];
2632 vector_at_top[2] =
pitch / (2 * numbers::PI);
2634 double p_radius_cap_top =
2635 ((centered_point - point_at_top) -
2636 scalar_product((centered_point - point_at_top), vector_at_top) /
2637 vector_at_top.norm_square() * vector_at_top)
2639 double radial_distance_cap_top = p_radius_cap_top -
radius_disk;
2640 double h_dist_from_cap_top =
2641 (scalar_product((centered_point - point_at_top), vector_at_top) /
2642 vector_at_top.norm_square() * vector_at_top)
2645 double dist_from_cap_top = 0;
2646 if (radial_distance_cap_top > 0)
2648 std::pow(h_dist_from_cap_top * h_dist_from_cap_top +
2649 radial_distance_cap_top * radial_distance_cap_top,
2652 dist_from_cap_top = h_dist_from_cap_top;
2655 double level_set = 0;
2656 if (level_set_tube > 0)
2657 level_set = std::min({level_set_tube, dist_from_cap, dist_from_cap_top});
2659 level_set = std::max({level_set_tube, -dist_from_cap_top, -dist_from_cap});
2665std::shared_ptr<Shape<dim>>
2668 std::shared_ptr<Shape<dim>> copy =
2669 std::make_shared<CylindricalHelix<dim>>(this->
radius,
2683 constexpr double solid_volume = 0;
2685 return solid_volume;
This class was designed so that specific composite shapes could be defined through the parameter file...
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.
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.
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.
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.
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.
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.
std::shared_ptr< Shape< dim > > static_copy() const override
Return a pointer to a copy of the Shape.
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.
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
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.
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 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.
RBF Shapes express the signed distance function as a linear combination of Radial Basis Functions (RB...
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.
virtual Point< dim > get_position()
Returns the position of the shape.
Tensor< 2, 3 > rotation_matrix
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.
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...
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.
std::unordered_map< std::string, Tensor< 1, dim > > gradient_cache
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 void set_position(const Point< dim > &new_position)
Sets a new position for the shape.
Point< dim > reverse_align_and_center(const Point< dim > &evaluation_point) const
This function applies the inverse operation of align_and_center.
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 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 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...
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.
This class defines superquadric shapes. Their signed distance function is: .
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...
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.
Tensor< 1, dim > half_lengths
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.
void fill_vectors_from_file(std::map< std::string, std::vector< double > > &map, const std::string &file_name, const std::string &delimiter=" ")
function that read a file that was build from a dealii table and fill 2 vectors. The first vector con...
@ phase
Phase indicator scalar field from CLS.
Tensor< 1, 3 > tensor_nd_to_3d(const Tensor< 1, dim > &tensor)
Tensor< 1, 2 > tensor_nd_to_2d(const Tensor< 1, dim > &tensor)