From: Ralf Hartmann Date: Fri, 6 Apr 2001 12:03:04 +0000 (+0000) Subject: Derive HyperShellBoundary from HyperBallBoundary to avoid copying lots of code. X-Git-Tag: v8.0.0~19395 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=086e823c1a7a05407ae59ba0e14a1f633b03582e;p=dealii.git Derive HyperShellBoundary from HyperBallBoundary to avoid copying lots of code. git-svn-id: https://svn.dealii.org/trunk@4387 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/grid/tria_boundary_lib.h b/deal.II/deal.II/include/grid/tria_boundary_lib.h index 5ea463b7ad..5d1673ae97 100644 --- a/deal.II/deal.II/include/grid/tria_boundary_lib.h +++ b/deal.II/deal.II/include/grid/tria_boundary_lib.h @@ -107,8 +107,48 @@ class HyperBallBoundary : public StraightBoundary * Return the radius of the ball. */ double get_radius () const; + + /** + * Exception. Thrown by the + * @p{get_radius} if the + * @p{compute_radius_automatically}, + * see below, flag is set true. + */ + DeclException0 (ExcRadiusNotSet); + protected: + + /** + * Center point of the hyperball. + */ + const Point center; + + /** + * Radius of the hyperball. + */ + const double radius; + + /** + * This flag is @p{false} for + * this class and for all derived + * classes that set the radius by + * the constructor. For example + * this flag is @p{false} for the + * @ref{HalfHyperBallBoundary} + * class but it is @p{true} for + * the @ref{HyperShellBoundary} + * class, for example. The + * latter class doesn't get its + * radii by the constructor but + * need to compute the radii + * automatically each time one of + * the virtual functions is + * called. + */ + bool compute_radius_automatically; + + private: /** * Called by @@ -123,18 +163,7 @@ class HyperBallBoundary : public StraightBoundary * base class. */ void get_intermediate_points_between_points (const Point &p0, const Point &p1, - typename std::vector > &points) const; - - - /** - * Center point of the hyperball. - */ - const Point center; - - /** - * Radius of the hyperball. - */ - const double radius; + typename std::vector > &points) const; }; @@ -227,47 +256,21 @@ class HalfHyperBallBoundary : public HyperBallBoundary * @author Wolfgang Bangerth, 1999 */ template -class HyperShellBoundary : public StraightBoundary +class HyperShellBoundary : public HyperBallBoundary { public: /** * Constructor. The center of the * spheres defaults to the * origin. - */ - HyperShellBoundary (const Point ¢er = Point()); - - /** - * Construct a new point on a line. - */ - virtual Point - get_new_point_on_line (const typename Triangulation::line_iterator &line) const; - - /** - * Construct a new point on a quad. - */ - virtual Point - get_new_point_on_quad (const typename Triangulation::quad_iterator &quad) const; - - /** - * Compute the normals to the - * boundary at the vertices of - * the given face. * - * Refer to the general - * documentation of this class - * and the documentation of the - * base class. + * Calls the constructor of its + * base @p{HyperBallBoundary} + * class with a dummy radius as + * argument. This radius will be + * ignored */ - virtual void - get_normals_at_vertices (const typename Triangulation::face_iterator &face, - typename Boundary::FaceVertexNormals &face_vertex_normals) const; - - private: - /** - * Store the center of the spheres. - */ - const Point center; + HyperShellBoundary (const Point ¢er = Point()); }; diff --git a/deal.II/deal.II/source/grid/tria_boundary_lib.cc b/deal.II/deal.II/source/grid/tria_boundary_lib.cc index ac081480ed..448876192e 100644 --- a/deal.II/deal.II/source/grid/tria_boundary_lib.cc +++ b/deal.II/deal.II/source/grid/tria_boundary_lib.cc @@ -23,7 +23,7 @@ template HyperBallBoundary::HyperBallBoundary (const Point p, const double radius) : - center(p), radius(radius) + center(p), radius(radius), compute_radius_automatically(false) {}; @@ -35,8 +35,17 @@ HyperBallBoundary::get_new_point_on_line (const typename Triangulation Point middle = StraightBoundary::get_new_point_on_line (line); middle -= center; + + double r=0; + if (compute_radius_automatically) + { + const Point vertex_relative = line->vertex(0) - center; + r = sqrt(vertex_relative.square()); + } + else + r=radius; // project to boundary - middle *= radius / sqrt(middle.square()); + middle *= r / sqrt(middle.square()); middle += center; return middle; @@ -67,8 +76,17 @@ get_new_point_on_quad (const typename Triangulation::quad_iterator &quad) c Point middle = StraightBoundary::get_new_point_on_quad (quad); middle -= center; + + double r=0; + if (compute_radius_automatically) + { + const Point vertex_relative = quad->vertex(0) - center; + r = sqrt(vertex_relative.square()); + } + else + r=radius; // project to boundary - middle *= radius / sqrt(middle.square()); + middle *= r / sqrt(middle.square()); middle += center; return middle; @@ -83,7 +101,7 @@ HyperBallBoundary<1>::get_intermediate_points_on_line ( const Triangulation<1>::line_iterator &, std::vector > &) const { - Assert(false, ExcInternalError()); + Assert (false, Boundary<1>::ExcFunctionNotUseful(1)); } #else @@ -116,8 +134,17 @@ HyperBallBoundary::get_intermediate_points_between_points ( const double length=sqrt((v1-v0).square()); double eps=1e-14; - Assert(fabs(v0.square()-radius*radius) vertex_relative = p0 - center; + r = sqrt(vertex_relative.square()); + } + else + r=radius; + + Assert(fabs(v0.square()-r*r)::get_intermediate_points_between_points ( // HyperBallBoundary for (unsigned int i=0; i::get_intermediate_points_on_quad ( const Triangulation::quad_iterator &, typename std::vector > &) const { - Assert(false,ExcNotImplemented()); + Assert(false, Boundary::ExcFunctionNotUseful(dim)); } @@ -253,6 +280,7 @@ template double HyperBallBoundary::get_radius () const { + Assert(!compute_radius_automatically, ExcRadiusNotSet()); return radius; }; @@ -405,101 +433,12 @@ get_normals_at_vertices (const typename Triangulation::face_iterator &face, template HyperShellBoundary::HyperShellBoundary (const Point ¢er) : - center (center) -{}; - - - -template -Point -HyperShellBoundary:: -get_new_point_on_line (const typename Triangulation::line_iterator &line) const + HyperBallBoundary(center, 0.) { - const Point middle = StraightBoundary::get_new_point_on_line (line); - // compute the position of the - // points relative to the origin - const Point middle_relative = middle - center, - vertex_relative = line->vertex(0) - center; - - // take vertex(0) to gauge the - // radius corresponding to the line - // under consideration - const double radius = sqrt(vertex_relative.square()); - - // scale and shift back to the - // original coordinate system - return (middle_relative * (radius / sqrt(middle_relative.square()))) + center; + compute_radius_automatically=true; }; - -#if deal_II_dimension == 1 - -template <> -Point<1> -HyperShellBoundary<1>:: -get_new_point_on_quad (const Triangulation<1>::quad_iterator &) const -{ - Assert (false, ExcInternalError()); - return Point<1>(); -}; - -#endif - - - -template -Point -HyperShellBoundary:: -get_new_point_on_quad (const typename Triangulation::quad_iterator &quad) const -{ - const Point middle = StraightBoundary::get_new_point_on_quad (quad); - // compute the position of the points relative to the origin - const Point middle_relative = middle - center, - vertex_relative = quad->vertex(0) - center; - - // take vertex(0) to gauge the - // radius corresponding to the line - // under consideration - const double radius = sqrt(vertex_relative.square()); - - // scale and shift back to the - // original coordinate system - return (middle_relative * (radius / sqrt(middle_relative.square()))) + center; -}; - - - -#if deal_II_dimension == 1 - -template <> -void -HyperShellBoundary<1>:: -get_normals_at_vertices (const Triangulation<1>::face_iterator &, - Boundary<1>::FaceVertexNormals &) const -{ - Assert (false, Boundary<1>::ExcFunctionNotUseful(1)); -}; - -#endif - - -template -void -HyperShellBoundary:: -get_normals_at_vertices (const typename Triangulation::face_iterator &face, - typename Boundary::FaceVertexNormals &face_vertex_normals) const -{ - // this is equivalent to the case - // in the hyperball boundary. note - // that we need not normalize nor - // direct the normal - for (unsigned int vertex=0; vertex::vertices_per_face; ++vertex) - face_vertex_normals[vertex] = face->vertex(vertex)-center; -}; - - - /* ---------------------------------------------------------------------- */