From 6f3c6945d58341c7f68ae99833391b83a27bd079 Mon Sep 17 00:00:00 2001 From: David Wells Date: Fri, 15 May 2020 17:11:33 -0400 Subject: [PATCH] Specialize BoundingBox<0> to prevent instantiating BoundingBox<-1>. A zero-dimensional bounding box doesn't make sense and causes weird problems with intel's compiler when the compiler tries to instantiate BoundingBox::cross_section(). We have to use this workaround and not something like BoundingBox cross_section(const unsigned int direction) const; to make MSVC happy. --- include/deal.II/base/bounding_box.h | 57 +++++++++++++++++++++++++++++ tests/base/bounding_box_6.cc | 8 ++++ tests/base/bounding_box_6.output | 3 -- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/include/deal.II/base/bounding_box.h b/include/deal.II/base/bounding_box.h index f837743889..040894ac72 100644 --- a/include/deal.II/base/bounding_box.h +++ b/include/deal.II/base/bounding_box.h @@ -253,6 +253,9 @@ public: /** * Returns the cross section of the box orthogonal to @p direction. * This is a box in one dimension lower. + * + * @note Calling this method in 1D will result in an exception since + * BoundingBox<0> is not implemented. */ BoundingBox cross_section(const unsigned int direction) const; @@ -268,6 +271,32 @@ private: std::pair, Point> boundary_points; }; +/** + * Specialization of BoundingBox for spacedim 0. This class exists to enable + * dimension-independent programming but unconditionally throws an exception + * in its constructor. + */ +template +class BoundingBox<0, Number> +{ +public: + /** + * Default constructor. Throws an exception. + */ + BoundingBox(); + + /** + * Equivalent two-point constructor. Throws an exception. + */ + BoundingBox(const std::pair, Point<0, Number>> &); + + /** + * Equivalent container constructor. Throws an exception. + */ + template + BoundingBox(const Container &); +}; + /** * Returns the unit box $[0,1]^\text{dim}$. @@ -382,6 +411,34 @@ BoundingBox::serialize(Archive &ar, ar &boundary_points; } + + +template +inline BoundingBox<0, Number>::BoundingBox() +{ + AssertThrow(false, ExcImpossibleInDim(0)); +} + + + +template +inline BoundingBox<0, Number>::BoundingBox( + const std::pair, Point<0, Number>> &) +{ + AssertThrow(false, ExcImpossibleInDim(0)); +} + + + +template +template +inline BoundingBox<0, Number>::BoundingBox(const Container &) +{ + AssertThrow(false, ExcImpossibleInDim(0)); +} + + + #endif // DOXYGEN DEAL_II_NAMESPACE_CLOSE diff --git a/tests/base/bounding_box_6.cc b/tests/base/bounding_box_6.cc index cab24bc69d..059298b3c8 100644 --- a/tests/base/bounding_box_6.cc +++ b/tests/base/bounding_box_6.cc @@ -72,6 +72,14 @@ test_cross_section() +// It doesn't make sense to test the cross section in 1D so skip it: +template <> +void +test_cross_section<1>() +{} + + + // Compute and print the center of the box. template void diff --git a/tests/base/bounding_box_6.output b/tests/base/bounding_box_6.output index 0f979012ae..4073a8671b 100644 --- a/tests/base/bounding_box_6.output +++ b/tests/base/bounding_box_6.output @@ -1,8 +1,5 @@ DEAL::dim = 1 -DEAL::test_cross_section -DEAL::orthogonal to 0 -DEAL:: DEAL:: DEAL::test_center DEAL::center 0.500000 -- 2.39.5