]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Specialize BoundingBox<0> to prevent instantiating BoundingBox<-1>. 10235/head
authorDavid Wells <drwells@email.unc.edu>
Fri, 15 May 2020 21:11:33 +0000 (17:11 -0400)
committerDavid Wells <drwells@email.unc.edu>
Fri, 15 May 2020 21:11:33 +0000 (17:11 -0400)
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<spacedim != 1 ? spacedim - 1 : 1, Number>
    cross_section(const unsigned int direction) const;

to make MSVC happy.

include/deal.II/base/bounding_box.h
tests/base/bounding_box_6.cc
tests/base/bounding_box_6.output

index f837743889cb39a59b6a80c2ffb7604486fe33d4..040894ac726e8f2a12bb4b388f41b0f05a6a3636 100644 (file)
@@ -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
+   * <code>BoundingBox&lt;0&gt;</code> is not implemented.
    */
   BoundingBox<spacedim - 1, Number>
   cross_section(const unsigned int direction) const;
@@ -268,6 +271,32 @@ private:
   std::pair<Point<spacedim, Number>, Point<spacedim, Number>> 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 <typename Number>
+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>, Point<0, Number>> &);
+
+  /**
+   * Equivalent container constructor. Throws an exception.
+   */
+  template <class Container>
+  BoundingBox(const Container &);
+};
+
 
 /**
  * Returns the unit box $[0,1]^\text{dim}$.
@@ -382,6 +411,34 @@ BoundingBox<spacedim, Number>::serialize(Archive &ar,
   ar &boundary_points;
 }
 
+
+
+template <typename Number>
+inline BoundingBox<0, Number>::BoundingBox()
+{
+  AssertThrow(false, ExcImpossibleInDim(0));
+}
+
+
+
+template <typename Number>
+inline BoundingBox<0, Number>::BoundingBox(
+  const std::pair<Point<0, Number>, Point<0, Number>> &)
+{
+  AssertThrow(false, ExcImpossibleInDim(0));
+}
+
+
+
+template <typename Number>
+template <class Container>
+inline BoundingBox<0, Number>::BoundingBox(const Container &)
+{
+  AssertThrow(false, ExcImpossibleInDim(0));
+}
+
+
+
 #endif // DOXYGEN
 DEAL_II_NAMESPACE_CLOSE
 
index cab24bc69d2410c7a787141e4d8cbd6d845ccb93..059298b3c848aeb321a5c3cea69baaade5fdcdef 100644 (file)
@@ -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 <int dim>
 void
index 0f979012ae8ca3e3392bf6bd156dbe21e3f7104c..4073a8671bfa6ee163dabcd16347edd69ba70c2d 100644 (file)
@@ -1,8 +1,5 @@
 
 DEAL::dim = 1
-DEAL::test_cross_section
-DEAL::orthogonal to 0
-DEAL::
 DEAL::
 DEAL::test_center
 DEAL::center 0.500000

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.