From 8fc3c9f724991f5dbcfe7fac8a24a46577d107e2 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Wed, 15 Jul 2020 13:59:46 +0200 Subject: [PATCH] Add new hp::MappingCollection constructor --- doc/news/changes/minor/20200715Munch | 4 ++ include/deal.II/hp/mapping_collection.h | 28 ++++++++++++++ tests/hp/mapping_collection_05.cc | 51 +++++++++++++++++++++++++ tests/hp/mapping_collection_05.output | 5 +++ 4 files changed, 88 insertions(+) create mode 100644 doc/news/changes/minor/20200715Munch create mode 100644 tests/hp/mapping_collection_05.cc create mode 100644 tests/hp/mapping_collection_05.output diff --git a/doc/news/changes/minor/20200715Munch b/doc/news/changes/minor/20200715Munch new file mode 100644 index 0000000000..3538664713 --- /dev/null +++ b/doc/news/changes/minor/20200715Munch @@ -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. +
+(Peter Munch, 2020/07/15) diff --git a/include/deal.II/hp/mapping_collection.h b/include/deal.II/hp/mapping_collection.h index bbc9f3ea7d..d24a622963 100644 --- a/include/deal.II/hp/mapping_collection.h +++ b/include/deal.II/hp/mapping_collection.h @@ -74,6 +74,15 @@ namespace hp MappingCollection( const MappingCollection &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. + */ + template + 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 + template + MappingCollection::MappingCollection( + const MappingTypes &... mappings) + { + static_assert( + is_base_of_all, MappingTypes...>::value, + "Not all of the input arguments of this function " + "are derived from FiniteElement!"); + + // 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 *>(&mappings))...}; + for (const auto p : mapping_pointers) + push_back(*p); + } + template inline unsigned int MappingCollection::size() const diff --git a/tests/hp/mapping_collection_05.cc b/tests/hp/mapping_collection_05.cc new file mode 100644 index 0000000000..90adcad0c2 --- /dev/null +++ b/tests/hp/mapping_collection_05.cc @@ -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 + +#include + +#include "../tests.h" + + + +template +void +test() +{ + hp::MappingCollection mappings(MappingQ(1), MappingQ(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 index 0000000000..59b8e8777e --- /dev/null +++ b/tests/hp/mapping_collection_05.output @@ -0,0 +1,5 @@ + +DEAL::2 +DEAL::2 +DEAL::2 +DEAL::OK -- 2.39.5