]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add new hp::MappingCollection constructor 10707/head
authorPeter Munch <peterrmuench@gmail.com>
Wed, 15 Jul 2020 11:59:46 +0000 (13:59 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Wed, 15 Jul 2020 15:11:23 +0000 (17:11 +0200)
doc/news/changes/minor/20200715Munch [new file with mode: 0644]
include/deal.II/hp/mapping_collection.h
tests/hp/mapping_collection_05.cc [new file with mode: 0644]
tests/hp/mapping_collection_05.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20200715Munch b/doc/news/changes/minor/20200715Munch
new file mode 100644 (file)
index 0000000..3538664
--- /dev/null
@@ -0,0 +1,4 @@
+New: The class hp::MappingCollection has a new constructor. This constructor creates 
+a MappingCollection from one or more mapping objects passed to the constructor.
+<br>
+(Peter Munch, 2020/07/15)
index bbc9f3ea7d23a5333132f18125c93f13f87d7b6a..d24a6229638a1b59ba09dd945b069453259881f3 100644 (file)
@@ -74,6 +74,15 @@ namespace hp
     MappingCollection(
       const MappingCollection<dim, spacedim> &mapping_collection);
 
+    /**
+     * Constructor. This constructor creates a MappingCollection from one or
+     * more mapping objects passed to the constructor. For this
+     * call to be valid, all arguments need to be of types derived
+     * from class Mapping<dim,spacedim>.
+     */
+    template <class... MappingTypes>
+    explicit MappingCollection(const MappingTypes &... mappings);
+
     /**
      * Add a new mapping to the MappingCollection. Generally, you will
      * want to use the same order for mappings as for the elements of
@@ -149,6 +158,25 @@ namespace hp
 
   /* --------------- inline functions ------------------- */
 
+  template <int dim, int spacedim>
+  template <class... MappingTypes>
+  MappingCollection<dim, spacedim>::MappingCollection(
+    const MappingTypes &... mappings)
+  {
+    static_assert(
+      is_base_of_all<Mapping<dim, spacedim>, MappingTypes...>::value,
+      "Not all of the input arguments of this function "
+      "are derived from FiniteElement<dim,spacedim>!");
+
+    // loop over all of the given arguments and add the mappings to
+    // this collection. Inlining the definition of mapping_pointers causes
+    // internal compiler errors on GCC 7.1.1 so we define it separately:
+    const auto mapping_pointers = {
+      (static_cast<const Mapping<dim, spacedim> *>(&mappings))...};
+    for (const auto p : mapping_pointers)
+      push_back(*p);
+  }
+
   template <int dim, int spacedim>
   inline unsigned int
   MappingCollection<dim, spacedim>::size() const
diff --git a/tests/hp/mapping_collection_05.cc b/tests/hp/mapping_collection_05.cc
new file mode 100644 (file)
index 0000000..90adcad
--- /dev/null
@@ -0,0 +1,51 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Test constructor of hp::MappingCollection that accepts multiple mappings.
+
+
+#include <deal.II/fe/mapping_q.h>
+
+#include <deal.II/hp/mapping_collection.h>
+
+#include "../tests.h"
+
+
+
+template <int dim>
+void
+test()
+{
+  hp::MappingCollection<dim> mappings(MappingQ<dim>(1), MappingQ<dim>(2));
+
+  deallog << mappings.size() << std::endl;
+}
+
+
+
+int
+main()
+{
+  initlog();
+  deallog.get_file_stream().precision(2);
+
+  test<1>();
+  test<2>();
+  test<3>();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/hp/mapping_collection_05.output b/tests/hp/mapping_collection_05.output
new file mode 100644 (file)
index 0000000..59b8e87
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL::2
+DEAL::2
+DEAL::2
+DEAL::OK

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.