From a93566f863d6d0421c95f370922348554855f128 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Tue, 19 Oct 2021 09:34:47 +0200 Subject: [PATCH] Rename Functions::LevelSet -> Functions::SignedDistance --- .../changes/incompatibilities/20211019Munch | 4 + include/deal.II/base/function_level_set.h | 98 +------------ .../deal.II/base/function_signed_distance.h | 132 ++++++++++++++++++ source/base/CMakeLists.txt | 4 +- ...vel_set.cc => function_signed_distance.cc} | 8 +- ...st.in => function_signed_distance.inst.in} | 4 +- 6 files changed, 147 insertions(+), 103 deletions(-) create mode 100644 doc/news/changes/incompatibilities/20211019Munch create mode 100644 include/deal.II/base/function_signed_distance.h rename source/base/{function_level_set.cc => function_signed_distance.cc} (95%) rename source/base/{function_level_set.inst.in => function_signed_distance.inst.in} (82%) diff --git a/doc/news/changes/incompatibilities/20211019Munch b/doc/news/changes/incompatibilities/20211019Munch new file mode 100644 index 0000000000..a501b92883 --- /dev/null +++ b/doc/news/changes/incompatibilities/20211019Munch @@ -0,0 +1,4 @@ +Renamed: The namespace Functions::LevelSet has been renamed to +Functions::SignedDistance. +
+(Peter Munch, 2021/10/19) diff --git a/include/deal.II/base/function_level_set.h b/include/deal.II/base/function_level_set.h index 6af6c082c7..bbe096e9de 100644 --- a/include/deal.II/base/function_level_set.h +++ b/include/deal.II/base/function_level_set.h @@ -18,7 +18,7 @@ #include -#include +#include DEAL_II_NAMESPACE_OPEN @@ -26,103 +26,11 @@ namespace Functions { namespace LevelSet { - /** - * Signed-distance level set function of a sphere: - * $\psi(x) = \| x - x^c \| - R$. - * Here, $x^c$ is the center of the sphere and $R$ is its radius. This - * function is thus zero on the sphere, negative "inside" the ball having - * the sphere as its boundary, and positive in the rest of - * $\mathbb{R}^{dim}$. - * - * This function has gradient and Hessian equal to - * $\partial_i \psi(x) = (x - x^c)/\| x - x^c \|$, - * $\partial_i \partial_j \psi = - * \delta_{ij}/\| x - x^c \| - (x_i - x_i^c)(x_j - x_j^c)/\| x - x^c \|^3$, - * where $\delta_{ij}$ is the Kronecker delta function. - * - * @ingroup functions - */ template - class Sphere : public Function - { - public: - /** - * Constructor, takes the center and radius of the sphere. - */ - Sphere(const Point ¢er = Point(), const double radius = 1); + using Sphere DEAL_II_DEPRECATED = SignedDistance::Sphere; - double - value(const Point & point, - const unsigned int component = 0) const override; - - /** - * @copydoc Function::gradient() - * - * @note The gradient is singular at the center of the sphere. If the - * incoming @p point is too close to the center, a floating-point - * exception may be thrown or entries in the gradient may be +inf/-inf - * or +nan/-nan, depending on how the point is located relative to the - * singularity. - */ - Tensor<1, dim> - gradient(const Point & point, - const unsigned int component = 0) const override; - - /** - * @copydoc Function::hessian() - * - * @note The Hessian is singular at the center of the sphere. If the - * incoming @p point is too close to the center, a floating-point - * exception may be thrown or entries in the Hessian may be +inf/-inf - * or +nan/-nan, depending on how the point is located relative to the - * singularity. - */ - SymmetricTensor<2, dim> - hessian(const Point & point, - const unsigned int component = 0) const override; - - private: - const Point center; - const double radius; - }; - - - /** - * Signed level set function of a plane in $\mathbb{R}^{dim}$: - * $\psi(x) = n \cdot (x - x_p)$. - * Here, $n$ is the plane normal and $x_p$ is a point in the plane. - * Thus, with respect to the direction of the normal, this function is - * positive above the plane, zero in the plane, and negative below the - * plane. If the normal is normalized, $\psi$ will be the signed distance to - * the closest point in the plane. - * - * @ingroup functions - */ template - class Plane : public Function - { - public: - /** - * Constructor, takes a point in the plane and the plane normal. - */ - Plane(const Point &point, const Tensor<1, dim> &normal); - - double - value(const Point & point, - const unsigned int component = 0) const override; - - Tensor<1, dim> - gradient(const Point &, - const unsigned int component = 0) const override; - - SymmetricTensor<2, dim> - hessian(const Point &, - const unsigned int component = 0) const override; - - private: - const Point point_in_plane; - const Tensor<1, dim> normal; - }; + using Plane DEAL_II_DEPRECATED = SignedDistance::Plane; } // namespace LevelSet } // namespace Functions diff --git a/include/deal.II/base/function_signed_distance.h b/include/deal.II/base/function_signed_distance.h new file mode 100644 index 0000000000..253aaecb3f --- /dev/null +++ b/include/deal.II/base/function_signed_distance.h @@ -0,0 +1,132 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 - 2021 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +#ifndef dealii_function_signed_distance_h +#define dealii_function_signed_distance_h + +#include + +#include + +DEAL_II_NAMESPACE_OPEN + +namespace Functions +{ + namespace SignedDistance + { + /** + * Signed-distance level set function of a sphere: + * $\psi(x) = \| x - x^c \| - R$. + * Here, $x^c$ is the center of the sphere and $R$ is its radius. This + * function is thus zero on the sphere, negative "inside" the ball having + * the sphere as its boundary, and positive in the rest of + * $\mathbb{R}^{dim}$. + * + * This function has gradient and Hessian equal to + * $\partial_i \psi(x) = (x - x^c)/\| x - x^c \|$, + * $\partial_i \partial_j \psi = + * \delta_{ij}/\| x - x^c \| - (x_i - x_i^c)(x_j - x_j^c)/\| x - x^c \|^3$, + * where $\delta_{ij}$ is the Kronecker delta function. + * + * @ingroup functions + */ + template + class Sphere : public Function + { + public: + /** + * Constructor, takes the center and radius of the sphere. + */ + Sphere(const Point ¢er = Point(), const double radius = 1); + + double + value(const Point & point, + const unsigned int component = 0) const override; + + /** + * @copydoc Function::gradient() + * + * @note The gradient is singular at the center of the sphere. If the + * incoming @p point is too close to the center, a floating-point + * exception may be thrown or entries in the gradient may be +inf/-inf + * or +nan/-nan, depending on how the point is located relative to the + * singularity. + */ + Tensor<1, dim> + gradient(const Point & point, + const unsigned int component = 0) const override; + + /** + * @copydoc Function::hessian() + * + * @note The Hessian is singular at the center of the sphere. If the + * incoming @p point is too close to the center, a floating-point + * exception may be thrown or entries in the Hessian may be +inf/-inf + * or +nan/-nan, depending on how the point is located relative to the + * singularity. + */ + SymmetricTensor<2, dim> + hessian(const Point & point, + const unsigned int component = 0) const override; + + private: + const Point center; + const double radius; + }; + + + /** + * Signed level set function of a plane in $\mathbb{R}^{dim}$: + * $\psi(x) = n \cdot (x - x_p)$. + * Here, $n$ is the plane normal and $x_p$ is a point in the plane. + * Thus, with respect to the direction of the normal, this function is + * positive above the plane, zero in the plane, and negative below the + * plane. If the normal is normalized, $\psi$ will be the signed distance to + * the closest point in the plane. + * + * @ingroup functions + */ + template + class Plane : public Function + { + public: + /** + * Constructor, takes a point in the plane and the plane normal. + */ + Plane(const Point &point, const Tensor<1, dim> &normal); + + double + value(const Point & point, + const unsigned int component = 0) const override; + + Tensor<1, dim> + gradient(const Point &, + const unsigned int component = 0) const override; + + SymmetricTensor<2, dim> + hessian(const Point &, + const unsigned int component = 0) const override; + + private: + const Point point_in_plane; + const Tensor<1, dim> normal; + }; + + } // namespace SignedDistance +} // namespace Functions + +DEAL_II_NAMESPACE_CLOSE + +#endif diff --git a/source/base/CMakeLists.txt b/source/base/CMakeLists.txt index 59674c60e1..bb9e2bcfd0 100644 --- a/source/base/CMakeLists.txt +++ b/source/base/CMakeLists.txt @@ -32,7 +32,7 @@ SET(_unity_include_src function.cc function_cspline.cc function_derivative.cc - function_level_set.cc + function_signed_distance.cc function_lib.cc function_lib_cutoff.cc function_parser.cc @@ -131,7 +131,7 @@ SET(_inst bounding_box.inst.in data_out_base.inst.in function.inst.in - function_level_set.inst.in + function_signed_distance.inst.in function_restriction.inst.in function_time.inst.in function_tools.inst.in diff --git a/source/base/function_level_set.cc b/source/base/function_signed_distance.cc similarity index 95% rename from source/base/function_level_set.cc rename to source/base/function_signed_distance.cc index b51080b36e..114b358e17 100644 --- a/source/base/function_level_set.cc +++ b/source/base/function_signed_distance.cc @@ -14,13 +14,13 @@ // --------------------------------------------------------------------- #include -#include +#include DEAL_II_NAMESPACE_OPEN namespace Functions { - namespace LevelSet + namespace SignedDistance { template Sphere::Sphere(const Point ¢er, const double radius) @@ -126,9 +126,9 @@ namespace Functions return SymmetricTensor<2, dim>(); } - } // namespace LevelSet + } // namespace SignedDistance } // namespace Functions -#include "function_level_set.inst" +#include "function_signed_distance.inst" DEAL_II_NAMESPACE_CLOSE diff --git a/source/base/function_level_set.inst.in b/source/base/function_signed_distance.inst.in similarity index 82% rename from source/base/function_level_set.inst.in rename to source/base/function_signed_distance.inst.in index 8b32cd1e34..9227b43001 100644 --- a/source/base/function_level_set.inst.in +++ b/source/base/function_signed_distance.inst.in @@ -15,6 +15,6 @@ for (deal_II_dimension : SPACE_DIMENSIONS) { - template class Functions::LevelSet::Sphere; - template class Functions::LevelSet::Plane; + template class Functions::SignedDistance::Sphere; + template class Functions::SignedDistance::Plane; } -- 2.39.5