diff --git a/CMakeLists.txt b/CMakeLists.txt index 1608e8f280bddd9d8bde972f115071fa9fc6a3b8..3c315eb07ab7b95ec7b4170bff73d9b4654a4684 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,6 @@ add_subdirectory("libs") add_subdirectory("test") dune_target_link_libraries(amdis fmt) -target_compile_options(amdis PUBLIC "-Wall" "-Wpedantic") - if (MTL_FOUND) dune_target_link_libraries(amdis MTL::MTL) @@ -48,7 +46,8 @@ endif (PETSc_FOUND) option(ENABLE_ALL_WARNINGS "enable all meaningful warnings" OFF) if (ENABLE_ALL_WARNINGS) - target_compile_options(amdis PUBLIC "-Wextra" "-Wnon-virtual-dtor" + target_compile_options(amdis PUBLIC "-Wall" "-Wpedantic" + "-Wextra" "-Wnon-virtual-dtor" "-Wold-style-cast" "-Wcast-align" "-Woverloaded-virtual" "-Wconversion") endif (ENABLE_ALL_WARNINGS) diff --git a/amdis/AdaptiveGrid.hpp b/amdis/AdaptiveGrid.hpp index 0402adea9c436105ceec5d5263dbd9b416a36c1e..41e0708065413e820265242deb3d9738e6a6ce90 100644 --- a/amdis/AdaptiveGrid.hpp +++ b/amdis/AdaptiveGrid.hpp @@ -312,6 +312,11 @@ namespace AMDiS unsigned long changeIndex_ = 0; }; + // deduction guide + template + AdaptiveGrid(HostGrid const&) + -> AdaptiveGrid; + template class AdaptiveGridFamily diff --git a/amdis/DOFVector.hpp b/amdis/DOFVector.hpp index 555245157040e4d01671590f82e47c8f544aba08..f6a1a162164f2be9434f078af5b1bc1a840c477f 100644 --- a/amdis/DOFVector.hpp +++ b/amdis/DOFVector.hpp @@ -222,7 +222,7 @@ namespace AMDiS // deduction guides template DOFVector(GB&& basis, DataTransferOperation op = DataTransferOperation::INTERPOLATE) - -> DOFVector::PreBasis>>; + -> DOFVector>; template DOFVector(GV const& gridView, PBF const& pbf, DataTransferOperation op = DataTransferOperation::INTERPOLATE) @@ -240,7 +240,7 @@ namespace AMDiS * \ref DataTransferOperation for more options. **/ template - DOFVector::PreBasis>, ValueType> + DOFVector, ValueType> makeDOFVector(GB&& basis, DataTransferOperation op = DataTransferOperation::INTERPOLATE) { return {FWD(basis), op}; diff --git a/amdis/Observer.hpp b/amdis/Observer.hpp index 704980580937e724bcf9b439c9ca2647c07a3b1f..ec78aa56741d406732967300d8e9e2fe6e73083a 100644 --- a/amdis/Observer.hpp +++ b/amdis/Observer.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -100,13 +101,22 @@ namespace AMDiS : public ObserverInterface { public: - template - Observer(Notifier const& notifier) - : notifier_(const_cast(¬ifier)) + template ,N>)> + Observer(N const& notifier) + : notifier_(const_cast(¬ifier)) { notifier_->attach(this); } + template ,N>)> + Observer(N const& notifier) + { + warning("Ignoring Notifier. Use AdaptiveGrid wrapper."); + } + + /// Destructor, detaches from the notifier virtual ~Observer() { diff --git a/amdis/functions/CMakeLists.txt b/amdis/functions/CMakeLists.txt index 0491d5b0d970908248a5bc60afbf338c9be169a6..a8814ffc21bd6db20ea1c3a42469190b500e631a 100644 --- a/amdis/functions/CMakeLists.txt +++ b/amdis/functions/CMakeLists.txt @@ -1,4 +1,5 @@ install(FILES + FlatPreBasis.hpp FunctionFromCallable.hpp GlobalIdSet.hpp HierarchicNodeToRangeMap.hpp diff --git a/amdis/functions/FlatPreBasis.hpp b/amdis/functions/FlatPreBasis.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6c204861e5089a6d8ba1e06be49b4a5eaae911d8 --- /dev/null +++ b/amdis/functions/FlatPreBasis.hpp @@ -0,0 +1,183 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace AMDiS +{ + // Convert the index-merging strategy to FlatLexicographic or FlatInterleaved for + // composite or power bases, respectively. + template > + struct FlatPreBasis + { + using type = PreBasis; + + template + static type create(PB const& preBasis) + { + return {preBasis.gridView()}; + } + + static PreBasis const& create(PreBasis const& preBasis) + { + return preBasis; + } + }; + + template > + using FlatPreBasis_t = typename FlatPreBasis::type; + + template + auto flatPreBasis(PreBasis const& preBasis) + { + return FlatPreBasis::create(preBasis); + } + + // specialization for Lagrange basis that needs an additional `order` parameter. +#if DUNE_VERSION_LT(DUNE_FUNCTIONS,2,7) + template + struct FlatPreBasis, MultiIndex> + { + using type = Dune::Functions::LagrangePreBasis; +#else + template + struct FlatPreBasis, MultiIndex> + { + using type = Dune::Functions::LagrangePreBasis; +#endif + + template + static type create(PB const& preBasis) + { + auto node = preBasis.makeNode(); + node.bind(*preBasis.gridView().template begin<0>()); + return {preBasis.gridView(), (unsigned int)(polynomialDegree(node))}; + } + + static type const& create(type const& preBasis) + { + return preBasis; + } + }; + + namespace Impl + { +#if DUNE_VERSION_LT(DUNE_FUNCTIONS,2,7) + // NOTE: dirty hack to get access to protected member variable, due to missing + // function in dune-functions-2.6 + template + class DerivedPreBasis { + public: + // specialization for PowerPreBasis + template + static SPB const& subPreBasis(PB const& pb) + { + return access(pb).subPreBasis_; + } + + // specialization for CompositePreBasis + template > + static SPB const& subPreBasis(PB const& pb, Dune::index_constant) + { + return std::get(access(pb).subPreBases_); + } + + template + class Accessor : public T { friend class DerivedPreBasis; }; + + template + static Accessor const& access(T const& obj) { return static_cast const&>(obj); } + }; + + template + static auto const& subPreBasis(PreBasis const& preBasis, Index... ii) + { + return DerivedPreBasis::subPreBasis(preBasis,ii...); + } +#else + template + static auto const& subPreBasis(PreBasis const& preBasis, Index... ii) + { + return preBasis.subPreBasis(ii...); + } +#endif + } // end namespace Impl + + + // specialization for composite bases + template + struct FlatPreBasis, MultiIndex> + { + using FIMS = Dune::Functions::BasisFactory::FlatLexicographic; + using type = Dune::Functions::CompositePreBasis...>; + + template + static type create(PreBasis const& preBasis) + { + return create(preBasis, std::index_sequence_for{}); + } + + template + static type create(PreBasis const& preBasis, std::index_sequence) + { + test_warning(std::is_same_v, "Basis converted into flat index-merging strategy."); + return {FlatPreBasis::create(Impl::subPreBasis(preBasis,Dune::index_constant{}))...}; + } + }; + + // specialization for flat power bases + template + struct FlatPreBasis, MultiIndex> + { + using type = Dune::Functions::PowerPreBasis; + + template + static type create(PreBasis const& preBasis) + { + return {FlatPreBasis::create(Impl::subPreBasis(preBasis))}; + } + }; + + // specialization for blocked power bases + template + struct FlatPreBasis, MultiIndex> + { + using FIMS = Dune::Functions::BasisFactory::FlatInterleaved; + using type = Dune::Functions::PowerPreBasis, C>; + + template + static type create(PreBasis const& preBasis) + { + warning("Basis converted into flat index-merging strategy."); + return {FlatPreBasis::create(Impl::subPreBasis(preBasis))}; + } + }; + + // specialization for blocked power bases + template + struct FlatPreBasis, MultiIndex> + { + using FIMS = Dune::Functions::BasisFactory::FlatLexicographic; + using type = Dune::Functions::PowerPreBasis, C>; + + template + static type create(PreBasis const& preBasis) + { + warning("Basis converted into flat index-merging strategy."); + return {FlatPreBasis::create(Impl::subPreBasis(preBasis))}; + } + }; + +} // end namespace AMDiS diff --git a/amdis/functions/ParallelGlobalBasis.hpp b/amdis/functions/ParallelGlobalBasis.hpp index bcd63d2b3d60429cd823aa6a27ee2922d0c73e70..16e7de46921b14af9891c0f83fb652af89037b48 100644 --- a/amdis/functions/ParallelGlobalBasis.hpp +++ b/amdis/functions/ParallelGlobalBasis.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -103,7 +104,7 @@ namespace AMDiS template ParallelGlobalBasis(std::string const& name, GridView const& gridView, PBF const& preBasisFactory) : ParallelGlobalBasis(name, gridView.grid(), - preBasisFactory.template makePreBasis>(gridView)) + flatPreBasis(preBasisFactory.template makePreBasis>(gridView))) {} /// Construct this global basis with empty name @@ -179,13 +180,13 @@ namespace AMDiS // Deduction guides template - ParallelGlobalBasis(std::string const& name, GV const& gridView, PBF&& preBasisFactory) - -> ParallelGlobalBasis>(gridView))>; + ParallelGlobalBasis(std::string const& name, GV const& gridView, PBF const& preBasisFactory) + -> ParallelGlobalBasis>(gridView)))>; template - ParallelGlobalBasis(GV const& gridView, PBF&& preBasisFactory) - -> ParallelGlobalBasis>(gridView))>; + ParallelGlobalBasis(GV const& gridView, PBF const& preBasisFactory) + -> ParallelGlobalBasis>(gridView)))>; } // end namespace AMDiS diff --git a/examples/ellipt.cc b/examples/ellipt.cc index 419242e94bc91f93279757062d3d8427d96c2308..0deafb2203b4a92684802b47ee8cf09e15e603b3 100644 --- a/examples/ellipt.cc +++ b/examples/ellipt.cc @@ -8,6 +8,7 @@ using Grid = Dune::YaspGrid; using namespace AMDiS; +using namespace Dune::Functions::BasisFactory; int main(int argc, char** argv) { @@ -28,8 +29,9 @@ int main(int argc, char** argv) return {-20.0 * std::exp(-10.0 * dot(x,x)) * x}; }; - using Param = LagrangeBasis; - ProblemStat prob("ellipt"); + auto grid = MeshCreator{"elliptMesh"}.create(); + + ProblemStat prob("ellipt", *grid, lagrange<2>()); prob.initialize(INIT_ALL); auto opL = makeOperator(tag::gradtest_gradtrial{}, 1.0); diff --git a/examples/vecellipt.cc b/examples/vecellipt.cc index 6f6b2048c5396651cc49a02494f0777b197c7fef..f9b06185a3ec52a258644c26eb2a241fc0b184fa 100644 --- a/examples/vecellipt.cc +++ b/examples/vecellipt.cc @@ -7,15 +7,15 @@ #include using namespace AMDiS; - -using ElliptParam = YaspGridBasis; -using ElliptProblem = ProblemStat; +using namespace Dune::Functions::BasisFactory; int main(int argc, char** argv) { Environment env(argc, argv); - ElliptProblem prob("ellipt"); + using Grid = Dune::YaspGrid; + auto grid = MeshCreator{"elliptMesh"}.create(); + ProblemStat prob("ellipt", *grid, power<2>(lagrange<2>())); prob.initialize(INIT_ALL); AdaptInfo adaptInfo("adapt"); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ded27d37c9b9985b865813d7163b152cb42224cc..2274a638a41a719f07265882e065b4155b38dc96 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -60,6 +60,9 @@ dune_add_test(SOURCES FilesystemTest.cpp dune_add_test(SOURCES FlatMatVecTest.cpp LINK_LIBRARIES amdis) +dune_add_test(SOURCES FlatPreBasisTest.cpp + LINK_LIBRARIES amdis) + dune_add_test(SOURCES GlobalIdSetTest.cpp LINK_LIBRARIES amdis MPI_RANKS 2 diff --git a/test/FlatPreBasisTest.cpp b/test/FlatPreBasisTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18fd12a5723a9809f1a4b8a9f191c992ab05236a --- /dev/null +++ b/test/FlatPreBasisTest.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +#include + +int test() +{ + using namespace AMDiS; + using namespace Dune::Functions::BasisFactory; + + // construct a grid + Dune::YaspGrid<2> grid({1.0, 1.0}, {8,8}); + auto gridView = grid.leafGridView(); + + // construct a basis + ParallelGlobalBasis basis1(gridView, power<2>(lagrange<1>(), blockedInterleaved())); + ParallelGlobalBasis basis2(gridView, power<2>(lagrange<1>(), blockedLexicographic())); + ParallelGlobalBasis basis3(gridView, power<2>(lagrange<1>(), flatInterleaved())); + ParallelGlobalBasis basis4(gridView, power<2>(lagrange<1>(), flatLexicographic())); + ParallelGlobalBasis basis5(gridView, power<2>(lagrange<1>())); + ParallelGlobalBasis basis6(gridView, composite(lagrange<1>())); + + // construct a ProblemStat + ProblemStat prob1("prob1", grid, power<2>(lagrange<1>(), blockedInterleaved())); + ProblemStat prob2("prob2", grid, power<2>(lagrange<1>(), blockedLexicographic())); + ProblemStat prob3("prob3", grid, power<2>(lagrange<1>(), flatInterleaved())); + ProblemStat prob4("prob4", grid, power<2>(lagrange<1>(), flatLexicographic())); + ProblemStat prob5("prob5", grid, power<2>(lagrange<1>())); + ProblemStat prob6("prob6", grid, composite(lagrange<1>())); + + // construct a DOFVector + DOFVector vec1(gridView, power<2>(lagrange<1>(), blockedInterleaved())); + DOFVector vec2(gridView, power<2>(lagrange<1>(), blockedLexicographic())); + DOFVector vec3(gridView, power<2>(lagrange<1>(), flatInterleaved())); + DOFVector vec4(gridView, power<2>(lagrange<1>(), flatLexicographic())); + DOFVector vec5(gridView, power<2>(lagrange<1>())); + DOFVector vec6(gridView, composite(lagrange<1>())); + + return 0; +} + +int main(int argc, char** argv) +{ + AMDiS::Environment env(argc, argv); + + return test(); +}