]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Allow not specifying the multiplicity in the FESystem constructor.
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 14 Sep 2017 20:41:08 +0000 (14:41 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 17 Sep 2017 23:56:45 +0000 (17:56 -0600)
include/deal.II/fe/fe_system.h

index caa792058936f4bf356df522f5ec1a554c0ab85e..f9218330dfdd35a2c182b011a6a228268c76ad5c 100644 (file)
@@ -448,12 +448,30 @@ public:
    * elements. The temporary is destroyed again at the end of the code that
    * corresponds to this line, but this does not matter because FESystem
    * creates its own copy of the FE_Q object.
+   *
+   * As a shortcut, this constructor also allows calling
+   * @code
+   *   FESystem<dim> fe (FE_Q<dim>(2)^dim, FE_Q<dim>(1));
+   * @endcode
+   * instead of the more explicit
+   * @code
+   *   FESystem<dim> fe (FE_Q<dim>(2)^dim, FE_Q<dim>(1)^1);
+   * @endcode
+   * In other words, if no multiplicity for an element is explicitly specified
+   * via the exponentiation operation, then it is assumed to be one (as one
+   * would have expected).
    */
   template <class... FEPairs,
-            typename = typename std::enable_if<all_same_as<typename std::decay<FEPairs>::type...,
-                                                           std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>,
-                                                               unsigned int>>::value>::type>
-  FESystem (FEPairs&& ... fe_pairs);
+            typename = typename enable_if_all<
+              (std::is_same<typename std::decay<FEPairs>::type,
+                            std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>::value
+               ||
+               std::is_base_of<FiniteElement<dim, spacedim>,
+                               typename std::decay<FEPairs>::type>::value)
+              ...
+              >::type
+            >
+  FESystem (FEPairs &&... fe_pairs);
 
   /**
    * Same as above allowing the following syntax:
@@ -1149,6 +1167,26 @@ namespace
       return fe_system.second > 0;
     });
   }
+
+
+
+  template <int dim, int spacedim>
+  std::pair<std::unique_ptr<FiniteElement<dim, spacedim> >, unsigned int>
+  promote_to_fe_pair (const FiniteElement<dim,spacedim> &fe)
+  {
+    return std::make_pair<std::unique_ptr<FiniteElement<dim, spacedim> >,
+           unsigned int> (std::move(fe.clone()), 1u);
+  }
+
+
+
+  template <int dim, int spacedim>
+  auto
+  promote_to_fe_pair (std::pair<std::unique_ptr<FiniteElement<dim, spacedim> >, unsigned int> &&p)
+  -> decltype(std::forward<std::pair<std::unique_ptr<FiniteElement<dim, spacedim> >, unsigned int> >(p))
+  {
+    return std::forward<std::pair<std::unique_ptr<FiniteElement<dim, spacedim> >, unsigned int> >(p);
+  }
 }
 
 
@@ -1157,10 +1195,11 @@ namespace
 // If we decide to remove the deprecated constructors, we might just use the variadic
 // constructor with a suitable static_assert instead of the std::enable_if.
 template<int dim, int spacedim>
-template <class... FEPairs, typename>
+template <class... FEPairs,
+          typename>
 FESystem<dim,spacedim>::FESystem (FEPairs &&... fe_pairs)
   :
-  FESystem<dim, spacedim> ({std::forward<FEPairs>(fe_pairs)...})
+  FESystem<dim, spacedim> ({promote_to_fe_pair<dim,spacedim>(std::forward<FEPairs>(fe_pairs))...})
 {}
 
 

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.