From 1e28fc71cab0c4576cde62d490fc893e38dcdf0c Mon Sep 17 00:00:00 2001 From: David Wells Date: Sat, 6 Jul 2024 09:32:31 -0400 Subject: [PATCH] Manifold: add accessors for all Manifold ctor arguments. This makes it easier to manipulate Manifolds after they are constructed, e.g., by applying a translation. --- doc/news/changes/minor/20240706DavidWells | 5 + include/deal.II/grid/manifold.h | 15 ++ include/deal.II/grid/manifold_lib.h | 161 +++++++++++++++++++++- source/grid/manifold_lib.cc | 22 ++- 4 files changed, 196 insertions(+), 7 deletions(-) create mode 100644 doc/news/changes/minor/20240706DavidWells diff --git a/doc/news/changes/minor/20240706DavidWells b/doc/news/changes/minor/20240706DavidWells new file mode 100644 index 0000000000..0c04cdf81d --- /dev/null +++ b/doc/news/changes/minor/20240706DavidWells @@ -0,0 +1,5 @@ +New: All the basic Manifold objects describing a coordinate system now make +their essential geometric properties (e.g., the center) available through member +functions. +
+(David Wells, 2024/07/06) diff --git a/include/deal.II/grid/manifold.h b/include/deal.II/grid/manifold.h index 931a1c6351..623288d158 100644 --- a/include/deal.II/grid/manifold.h +++ b/include/deal.II/grid/manifold.h @@ -779,6 +779,12 @@ public: const Tensor<1, spacedim> & get_periodicity() const; + /** + * Return the relative tolerance set in the constructor. + */ + double + get_tolerance() const; + private: /** * The periodicity of this Manifold. Periodicity affects the way a middle @@ -1133,6 +1139,15 @@ Manifold<3, 3>::get_new_point_on_hex( /*---Templated functions---*/ +template +inline double +FlatManifold::get_tolerance() const +{ + return tolerance; +} + + + namespace Manifolds { template diff --git a/include/deal.II/grid/manifold_lib.h b/include/deal.II/grid/manifold_lib.h index 1cc44a64f1..156f65a840 100644 --- a/include/deal.II/grid/manifold_lib.h +++ b/include/deal.II/grid/manifold_lib.h @@ -134,6 +134,12 @@ public: const typename Triangulation::face_iterator &face, const Point &p) const override; + /** + * Return the center of the spherical coordinate system. + */ + const Point & + get_center() const; + /** * The center of the spherical coordinate system. */ @@ -323,6 +329,12 @@ public: get_new_point(const ArrayView> &vertices, const ArrayView &weights) const override; + /** + * Return the center of the spherical coordinate system. + */ + const Point & + get_center() const; + /** * The center of the spherical coordinate system. */ @@ -446,6 +458,27 @@ public: get_new_point(const ArrayView> &surrounding_points, const ArrayView &weights) const override; + /** + * Get the Tensor parallel to the cylinder's axis. + */ + const Tensor<1, spacedim> & + get_direction() const; + + /** + * Get a point on the Cylinder's axis. + * + * @note This argument, like get_direction() and get_tolerance(), just returns + * the arguments set in the three-argument constructor. + */ + const Point & + get_point_on_axis() const; + + /** + * Get the tolerance which determines if a point is on the Cylinder's axis. + */ + double + get_tolerance() const; + private: /** * A vector orthogonal to the normal direction. @@ -544,16 +577,40 @@ public: virtual DerivativeForm<1, spacedim, spacedim> push_forward_gradient(const Point &chart_point) const override; + /** + * Get the Tensor parallel to the cylinder's major axis. + */ + const Tensor<1, spacedim> & + get_major_axis_direction() const; + + /** + * Return the center of the elliptical coordinate system. + */ + const Point & + get_center() const; + + /** + * Return the ellipse's eccentricity. + */ + double + get_eccentricity() const; private: /** * The direction vector of the major axis. */ - Tensor<1, spacedim> direction; + const Tensor<1, spacedim> direction; + /** * The center of the manifold. */ const Point center; + + /** + * The eccentricity. + */ + const double eccentricity; + /** * Parameters deriving from the eccentricity of the manifold. */ @@ -816,6 +873,18 @@ public: virtual DerivativeForm<1, 3, 3> push_forward_gradient(const Point<3> &chart_point) const override; + /** + * Get the radius of the centerline. + */ + double + get_centerline_radius() const; + + /** + * Get the inner radius of the torus. + */ + double + get_inner_radius() const; + private: double centerline_radius; @@ -1159,6 +1228,96 @@ private: boost::signals2::connection clear_signal; }; +/*----------------------------- inline functions -----------------------------*/ + +template +inline const Point & +PolarManifold::get_center() const +{ + return center; +} + + + +template +inline const Point & +SphericalManifold::get_center() const +{ + return center; +} + + + +template +inline const Tensor<1, spacedim> & +CylindricalManifold::get_direction() const +{ + return direction; +} + + + +template +inline const Point & +CylindricalManifold::get_point_on_axis() const +{ + return point_on_axis; +} + + + +template +inline double +CylindricalManifold::get_tolerance() const +{ + return tolerance; +} + + + +template +inline const Tensor<1, spacedim> & +EllipticalManifold::get_major_axis_direction() const +{ + return direction; +} + + + +template +inline const Point & +EllipticalManifold::get_center() const +{ + return center; +} + + + +template +inline double +EllipticalManifold::get_eccentricity() const +{ + return eccentricity; +} + + + +template +inline double +TorusManifold::get_centerline_radius() const +{ + return centerline_radius; +} + + + +template +inline double +TorusManifold::get_inner_radius() const +{ + return inner_radius; +} + DEAL_II_NAMESPACE_CLOSE #endif diff --git a/source/grid/manifold_lib.cc b/source/grid/manifold_lib.cc index a7b4541939..07d5e1dbff 100644 --- a/source/grid/manifold_lib.cc +++ b/source/grid/manifold_lib.cc @@ -1165,6 +1165,20 @@ CylindricalManifold::push_forward_gradient( +namespace +{ + template + Tensor<1, dim> + check_and_normalize(const Tensor<1, dim> &t) + { + const double norm = t.norm(); + Assert(norm > 0.0, ExcMessage("The major axis must have a positive norm.")); + return t / norm; + } +} // namespace + + + // ============================================================ // EllipticalManifold // ============================================================ @@ -1175,8 +1189,9 @@ EllipticalManifold::EllipticalManifold( const double eccentricity) : ChartManifold( EllipticalManifold::get_periodicity()) - , direction(major_axis_direction) + , direction(check_and_normalize(major_axis_direction)) , center(center) + , eccentricity(eccentricity) , cosh_u(1.0 / eccentricity) , sinh_u(std::sqrt(cosh_u * cosh_u - 1.0)) { @@ -1186,11 +1201,6 @@ EllipticalManifold::EllipticalManifold( Assert(std::signbit(cosh_u * cosh_u - 1.0) == false, ExcMessage( "Invalid eccentricity: It must satisfy 0 < eccentricity < 1.")); - const double direction_norm = direction.norm(); - Assert(direction_norm != 0.0, - ExcMessage( - "Invalid major axis direction vector: Null vector not allowed.")); - direction /= direction_norm; } -- 2.39.5