From 1a3e6730edfa81903e9b76d750c0cfe71095c253 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Tue, 26 Mar 2019 16:05:56 +0100 Subject: [PATCH 01/38] initial commit of rewritten adaption interface to allow to attach bases to the grid-transfer --- src/amdis/CMakeLists.txt | 1 - src/amdis/ProblemStat.inc.hpp | 1 + test/DOFVectorTest.cpp | 1 + test/DataTransferTest.hpp | 2 +- 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/amdis/CMakeLists.txt b/src/amdis/CMakeLists.txt index 35fe7555..4fe38438 100644 --- a/src/amdis/CMakeLists.txt +++ b/src/amdis/CMakeLists.txt @@ -18,7 +18,6 @@ install(FILES AdaptInfo.hpp AdaptInstationary.hpp AdaptionInterface.hpp - AdaptiveGlobalBasis.hpp AdaptStationary.hpp AMDiS.hpp Assembler.hpp diff --git a/src/amdis/ProblemStat.inc.hpp b/src/amdis/ProblemStat.inc.hpp index 0a942639..2aab43ac 100644 --- a/src/amdis/ProblemStat.inc.hpp +++ b/src/amdis/ProblemStat.inc.hpp @@ -170,6 +170,7 @@ void ProblemStat::initGlobalBasis() { dirichletBCs_.init(*globalBasis_, *globalBasis_); periodicBCs_.init(*globalBasis_, *globalBasis_); + GridTransferManager::attach(*globalBasis_); } diff --git a/test/DOFVectorTest.cpp b/test/DOFVectorTest.cpp index 19bc9395..eab5908b 100644 --- a/test/DOFVectorTest.cpp +++ b/test/DOFVectorTest.cpp @@ -49,6 +49,7 @@ int main(int argc, char** argv) auto basis = makeBasis(gridView, composite(power<2>(lagrange<2>(), flatInterleaved()), lagrange<1>(), flatLexicographic())); using Basis = decltype(basis); + GridTransferManager::attach(basis); { DOFVector vec1(basis); diff --git a/test/DataTransferTest.hpp b/test/DataTransferTest.hpp index e9c7c3d3..ddae1261 100644 --- a/test/DataTransferTest.hpp +++ b/test/DataTransferTest.hpp @@ -82,7 +82,7 @@ double calcError(Problem const& prob, Fcts const& funcs) { auto& globalBasis = *prob->globalBasis(); auto localView = globalBasis.localView(); - auto const& sol = prob->solution().coefficients(); + auto const& sol = prob.solution().coefficients(); std::vector ref; ref.resize(globalBasis.size()); double error = 0; -- GitLab From 0aac8188aca28855539ab43bd880f1ace1b0b4bd Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Wed, 27 Mar 2019 14:50:53 +0100 Subject: [PATCH 02/38] Wrapper for GlobalBasis with automatic adaption added --- src/amdis/AdaptionInterface.hpp | 2 +- src/amdis/AdaptiveGlobalBasis.hpp | 107 ++++++++++++++++++++++++++++++ src/amdis/CMakeLists.txt | 1 + src/amdis/ProblemStat.hpp | 7 +- src/amdis/ProblemStat.inc.hpp | 3 +- test/DOFVectorTest.cpp | 2 +- test/DataTransferTest.hpp | 2 +- 7 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 src/amdis/AdaptiveGlobalBasis.hpp diff --git a/src/amdis/AdaptionInterface.hpp b/src/amdis/AdaptionInterface.hpp index 66a0baf6..04df4d3b 100644 --- a/src/amdis/AdaptionInterface.hpp +++ b/src/amdis/AdaptionInterface.hpp @@ -26,7 +26,7 @@ namespace AMDiS { template auto requires_(Basis const& basis) -> decltype( - const_cast(basis).update(basis.gridView()) + const_cast(basis).update() ); }; diff --git a/src/amdis/AdaptiveGlobalBasis.hpp b/src/amdis/AdaptiveGlobalBasis.hpp new file mode 100644 index 00000000..5e78aca8 --- /dev/null +++ b/src/amdis/AdaptiveGlobalBasis.hpp @@ -0,0 +1,107 @@ +#pragma once + +#include + +#include + +#include + +namespace AMDiS +{ + /** + * \addtogroup Adaption + * @{ + **/ + + template + class AdaptiveGlobalBasis + { + using GlobalBasis = GB; + + public: + AdaptiveGlobalBasis() = default; + + AdaptiveGlobalBasis(std::shared_ptr basis) + : basis_(basis) // use a custom deleter + { + GridTransferManager::attach(*this); + } + + AdaptiveGlobalBasis(GB& basis) + : AdaptiveGlobalBasis(Dune::stackobject_to_shared_ptr(basis)) + {} + + AdaptiveGlobalBasis(AdaptiveGlobalBasis const&) = delete; + AdaptiveGlobalBasis(AdaptiveGlobalBasis&&) = delete; + + ~AdaptiveGlobalBasis() + { + if (basis_) + GridTransferManager::detach(*this); + } + + AdaptiveGlobalBasis& operator=(std::shared_ptr basis) + { + basis_ = basis; + GridTransferManager::attach(*this); + return *this; + } + + public: + void update() + { + assert(basis_); + basis_->update(basis_->gridView()); + } + + typename GB::GridView const& gridView() const + { + return basis_->gridView(); + } + + public: // smart-pointer interface + + GlobalBasis& operator*() + { + return *basis_; + } + + GlobalBasis const& operator*() const + { + return *basis_; + } + + GlobalBasis* operator->() + { + return basis_.get(); + } + + GlobalBasis const* operator->() const + { + return basis_.get(); + } + + operator bool() const + { + return bool(basis_); + } + + public: + + std::shared_ptr get() + { + return basis_; + } + + std::shared_ptr get() const + { + return basis_; + } + + private: + std::shared_ptr basis_; + }; + + /// @} + +} // end namespace AMDiS diff --git a/src/amdis/CMakeLists.txt b/src/amdis/CMakeLists.txt index 4fe38438..35fe7555 100644 --- a/src/amdis/CMakeLists.txt +++ b/src/amdis/CMakeLists.txt @@ -18,6 +18,7 @@ install(FILES AdaptInfo.hpp AdaptInstationary.hpp AdaptionInterface.hpp + AdaptiveGlobalBasis.hpp AdaptStationary.hpp AMDiS.hpp Assembler.hpp diff --git a/src/amdis/ProblemStat.hpp b/src/amdis/ProblemStat.hpp index 005cf68e..ecad2421 100644 --- a/src/amdis/ProblemStat.hpp +++ b/src/amdis/ProblemStat.hpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -326,8 +327,8 @@ namespace AMDiS std::shared_ptr const> boundaryManager() const { return boundaryManager_; } /// Return the \ref globalBasis_ - std::shared_ptr globalBasis() { return globalBasis_; } - std::shared_ptr globalBasis() const { return globalBasis_; } + std::shared_ptr globalBasis() { return globalBasis_.get(); } + std::shared_ptr globalBasis() const { return globalBasis_.get(); } /// Return a reference to the linear solver, \ref linearSolver std::shared_ptr solver() { return linearSolver_; } @@ -484,7 +485,7 @@ namespace AMDiS std::shared_ptr> boundaryManager_; /// FE spaces of this problem. - std::shared_ptr globalBasis_; + AdaptiveGlobalBasis globalBasis_; /// A FileWriter object std::list> filewriter_; diff --git a/src/amdis/ProblemStat.inc.hpp b/src/amdis/ProblemStat.inc.hpp index 2aab43ac..164b49f2 100644 --- a/src/amdis/ProblemStat.inc.hpp +++ b/src/amdis/ProblemStat.inc.hpp @@ -68,7 +68,7 @@ void ProblemStat::initialize( if (adoptProblem && (adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) { - adoptGlobalBasis(adoptProblem->globalBasis_); + adoptGlobalBasis(adoptProblem->globalBasis_.get()); } } @@ -170,7 +170,6 @@ void ProblemStat::initGlobalBasis() { dirichletBCs_.init(*globalBasis_, *globalBasis_); periodicBCs_.init(*globalBasis_, *globalBasis_); - GridTransferManager::attach(*globalBasis_); } diff --git a/test/DOFVectorTest.cpp b/test/DOFVectorTest.cpp index eab5908b..d67ba896 100644 --- a/test/DOFVectorTest.cpp +++ b/test/DOFVectorTest.cpp @@ -49,7 +49,6 @@ int main(int argc, char** argv) auto basis = makeBasis(gridView, composite(power<2>(lagrange<2>(), flatInterleaved()), lagrange<1>(), flatLexicographic())); using Basis = decltype(basis); - GridTransferManager::attach(basis); { DOFVector vec1(basis); @@ -72,6 +71,7 @@ int main(int argc, char** argv) // test GridTransferManager registration { + AdaptiveGlobalBasis adaptiveBasis(basis); DOFVector vec1(basis); test_dofvector(basis, vec1); for (auto const& e : elements(gridView)) diff --git a/test/DataTransferTest.hpp b/test/DataTransferTest.hpp index ddae1261..e9c7c3d3 100644 --- a/test/DataTransferTest.hpp +++ b/test/DataTransferTest.hpp @@ -82,7 +82,7 @@ double calcError(Problem const& prob, Fcts const& funcs) { auto& globalBasis = *prob->globalBasis(); auto localView = globalBasis.localView(); - auto const& sol = prob.solution().coefficients(); + auto const& sol = prob->solution().coefficients(); std::vector ref; ref.resize(globalBasis.size()); double error = 0; -- GitLab From 3c2a9d70baa51256bb1d184749ab90f81b3cc4fa Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Wed, 27 Mar 2019 17:16:53 +0100 Subject: [PATCH 03/38] register global basis in GridTransfer via DOFVector --- src/amdis/AdaptionInterface.hpp | 2 +- src/amdis/AdaptiveGlobalBasis.hpp | 107 ------------------------------ src/amdis/ProblemStat.hpp | 7 +- src/amdis/ProblemStat.inc.hpp | 2 +- test/DOFVectorTest.cpp | 1 - 5 files changed, 5 insertions(+), 114 deletions(-) delete mode 100644 src/amdis/AdaptiveGlobalBasis.hpp diff --git a/src/amdis/AdaptionInterface.hpp b/src/amdis/AdaptionInterface.hpp index 04df4d3b..66a0baf6 100644 --- a/src/amdis/AdaptionInterface.hpp +++ b/src/amdis/AdaptionInterface.hpp @@ -26,7 +26,7 @@ namespace AMDiS { template auto requires_(Basis const& basis) -> decltype( - const_cast(basis).update() + const_cast(basis).update(basis.gridView()) ); }; diff --git a/src/amdis/AdaptiveGlobalBasis.hpp b/src/amdis/AdaptiveGlobalBasis.hpp deleted file mode 100644 index 5e78aca8..00000000 --- a/src/amdis/AdaptiveGlobalBasis.hpp +++ /dev/null @@ -1,107 +0,0 @@ -#pragma once - -#include - -#include - -#include - -namespace AMDiS -{ - /** - * \addtogroup Adaption - * @{ - **/ - - template - class AdaptiveGlobalBasis - { - using GlobalBasis = GB; - - public: - AdaptiveGlobalBasis() = default; - - AdaptiveGlobalBasis(std::shared_ptr basis) - : basis_(basis) // use a custom deleter - { - GridTransferManager::attach(*this); - } - - AdaptiveGlobalBasis(GB& basis) - : AdaptiveGlobalBasis(Dune::stackobject_to_shared_ptr(basis)) - {} - - AdaptiveGlobalBasis(AdaptiveGlobalBasis const&) = delete; - AdaptiveGlobalBasis(AdaptiveGlobalBasis&&) = delete; - - ~AdaptiveGlobalBasis() - { - if (basis_) - GridTransferManager::detach(*this); - } - - AdaptiveGlobalBasis& operator=(std::shared_ptr basis) - { - basis_ = basis; - GridTransferManager::attach(*this); - return *this; - } - - public: - void update() - { - assert(basis_); - basis_->update(basis_->gridView()); - } - - typename GB::GridView const& gridView() const - { - return basis_->gridView(); - } - - public: // smart-pointer interface - - GlobalBasis& operator*() - { - return *basis_; - } - - GlobalBasis const& operator*() const - { - return *basis_; - } - - GlobalBasis* operator->() - { - return basis_.get(); - } - - GlobalBasis const* operator->() const - { - return basis_.get(); - } - - operator bool() const - { - return bool(basis_); - } - - public: - - std::shared_ptr get() - { - return basis_; - } - - std::shared_ptr get() const - { - return basis_; - } - - private: - std::shared_ptr basis_; - }; - - /// @} - -} // end namespace AMDiS diff --git a/src/amdis/ProblemStat.hpp b/src/amdis/ProblemStat.hpp index ecad2421..005cf68e 100644 --- a/src/amdis/ProblemStat.hpp +++ b/src/amdis/ProblemStat.hpp @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -327,8 +326,8 @@ namespace AMDiS std::shared_ptr const> boundaryManager() const { return boundaryManager_; } /// Return the \ref globalBasis_ - std::shared_ptr globalBasis() { return globalBasis_.get(); } - std::shared_ptr globalBasis() const { return globalBasis_.get(); } + std::shared_ptr globalBasis() { return globalBasis_; } + std::shared_ptr globalBasis() const { return globalBasis_; } /// Return a reference to the linear solver, \ref linearSolver std::shared_ptr solver() { return linearSolver_; } @@ -485,7 +484,7 @@ namespace AMDiS std::shared_ptr> boundaryManager_; /// FE spaces of this problem. - AdaptiveGlobalBasis globalBasis_; + std::shared_ptr globalBasis_; /// A FileWriter object std::list> filewriter_; diff --git a/src/amdis/ProblemStat.inc.hpp b/src/amdis/ProblemStat.inc.hpp index 164b49f2..0a942639 100644 --- a/src/amdis/ProblemStat.inc.hpp +++ b/src/amdis/ProblemStat.inc.hpp @@ -68,7 +68,7 @@ void ProblemStat::initialize( if (adoptProblem && (adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) { - adoptGlobalBasis(adoptProblem->globalBasis_.get()); + adoptGlobalBasis(adoptProblem->globalBasis_); } } diff --git a/test/DOFVectorTest.cpp b/test/DOFVectorTest.cpp index d67ba896..19bc9395 100644 --- a/test/DOFVectorTest.cpp +++ b/test/DOFVectorTest.cpp @@ -71,7 +71,6 @@ int main(int argc, char** argv) // test GridTransferManager registration { - AdaptiveGlobalBasis adaptiveBasis(basis); DOFVector vec1(basis); test_dofvector(basis, vec1); for (auto const& e : elements(gridView)) -- GitLab From b9ad5235faf2fd13b631607d977e860e3e5426e7 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Fri, 5 Apr 2019 17:46:10 +0200 Subject: [PATCH 04/38] Added Matrix and Vector wrapper for hierarchic insertion, resize and initialization, added MAtrixIndexSet and restructured the DOFVector and DOFMatrix to be build of MAtrixVectorTraits instead of a backend --- src/amdis/ProblemStat.inc.hpp | 4 +- src/amdis/common/CMakeLists.txt | 2 - src/amdis/functions/Blocking.hpp | 193 +++++++++++++++ src/amdis/functions/MultiIndex.hpp | 56 +++++ src/amdis/linearalgebra/CMakeLists.txt | 5 + src/amdis/linearalgebra/Common.hpp | 39 +++ src/amdis/linearalgebra/DOFMatrixBase.hpp | 71 ++++-- src/amdis/linearalgebra/DOFMatrixBase.inc.hpp | 84 ++++--- src/amdis/linearalgebra/DOFVectorBase.hpp | 86 ++++--- src/amdis/linearalgebra/DOFVectorBase.inc.hpp | 41 ++-- src/amdis/linearalgebra/MatrixIndexSet.hpp | 72 ++++++ .../linearalgebra/MatrixVectorGenerator.hpp | 129 ++++++++++ .../linearalgebra/MatrixVectorTraits.hpp | 136 +++++++++++ src/amdis/linearalgebra/MatrixWrapper.hpp | 79 +++++++ src/amdis/linearalgebra/MatrixWrapper.inc.hpp | 222 ++++++++++++++++++ .../MultiTypeMatrix.hpp | 16 +- .../MultiTypeVector.hpp | 21 +- src/amdis/linearalgebra/VectorWrapper.hpp | 79 +++++++ src/amdis/linearalgebra/VectorWrapper.inc.hpp | 188 +++++++++++++++ src/amdis/linearalgebra/istl/BCRSMatrix.hpp | 68 ++++++ src/amdis/linearalgebra/istl/CMakeLists.txt | 2 + src/amdis/linearalgebra/istl/DOFMatrix.hpp | 107 +-------- src/amdis/linearalgebra/istl/DOFVector.hpp | 97 +------- .../linearalgebra/istl/MatrixVectorTraits.hpp | 61 +++++ src/amdis/linearalgebra/mtl/CMakeLists.txt | 3 + src/amdis/linearalgebra/mtl/DOFMatrix.hpp | 118 +--------- src/amdis/linearalgebra/mtl/DOFVector.hpp | 88 +------ .../linearalgebra/mtl/MatrixVectorTraits.hpp | 33 +++ src/amdis/linearalgebra/mtl/MtlMatrix.hpp | 104 ++++++++ src/amdis/linearalgebra/mtl/MtlVector.hpp | 72 ++++++ src/amdis/typetree/MultiIndex.hpp | 23 -- src/amdis/typetree/RangeType.hpp | 2 +- test/BasisTester.hpp | 157 +++++++++++++ test/BlockingTest.cpp | 93 ++++++++ test/CMakeLists.txt | 12 + test/GeneratorsTest.cpp | 54 +++++ test/MatrixTest.cpp | 159 +++++++++++++ test/MultiTypeMatrixTest.cpp | 2 +- test/MultiTypeVectorTest.cpp | 2 +- test/VectorTest.cpp | 132 +++++++++++ 40 files changed, 2346 insertions(+), 566 deletions(-) create mode 100644 src/amdis/functions/Blocking.hpp create mode 100644 src/amdis/functions/MultiIndex.hpp create mode 100644 src/amdis/linearalgebra/MatrixIndexSet.hpp create mode 100644 src/amdis/linearalgebra/MatrixVectorGenerator.hpp create mode 100644 src/amdis/linearalgebra/MatrixVectorTraits.hpp create mode 100644 src/amdis/linearalgebra/MatrixWrapper.hpp create mode 100644 src/amdis/linearalgebra/MatrixWrapper.inc.hpp rename src/amdis/{common => linearalgebra}/MultiTypeMatrix.hpp (91%) rename src/amdis/{common => linearalgebra}/MultiTypeVector.hpp (81%) create mode 100644 src/amdis/linearalgebra/VectorWrapper.hpp create mode 100644 src/amdis/linearalgebra/VectorWrapper.inc.hpp create mode 100644 src/amdis/linearalgebra/istl/BCRSMatrix.hpp create mode 100644 src/amdis/linearalgebra/istl/MatrixVectorTraits.hpp create mode 100644 src/amdis/linearalgebra/mtl/MatrixVectorTraits.hpp create mode 100644 src/amdis/linearalgebra/mtl/MtlMatrix.hpp create mode 100644 src/amdis/linearalgebra/mtl/MtlVector.hpp delete mode 100644 src/amdis/typetree/MultiIndex.hpp create mode 100644 test/BasisTester.hpp create mode 100644 test/BlockingTest.cpp create mode 100644 test/GeneratorsTest.cpp create mode 100644 test/MatrixTest.cpp create mode 100644 test/VectorTest.cpp diff --git a/src/amdis/ProblemStat.inc.hpp b/src/amdis/ProblemStat.inc.hpp index 0a942639..a6db2d44 100644 --- a/src/amdis/ProblemStat.inc.hpp +++ b/src/amdis/ProblemStat.inc.hpp @@ -450,8 +450,8 @@ buildAfterAdapt(AdaptInfo& /*adaptInfo*/, Flag /*flag*/, bool asmMatrix, bool as } // 3. finish matrix insertion and apply dirichlet boundary conditions - systemMatrix_->finish(asmMatrix); - rhs_->finish(asmVector); + systemMatrix_->finish(); + rhs_->finish(); for_each_node(localView.tree(), [&,this](auto const& rowNode, auto row_tp) -> void { for_each_node(localView.tree(), [&,this](auto const& colNode, auto col_tp) -> void { diff --git a/src/amdis/common/CMakeLists.txt b/src/amdis/common/CMakeLists.txt index d71fa706..695c0954 100644 --- a/src/amdis/common/CMakeLists.txt +++ b/src/amdis/common/CMakeLists.txt @@ -20,8 +20,6 @@ install(FILES Literals.hpp Logical.hpp Math.hpp - MultiTypeMatrix.hpp - MultiTypeVector.hpp Range.hpp Resize.hpp StaticSize.hpp diff --git a/src/amdis/functions/Blocking.hpp b/src/amdis/functions/Blocking.hpp new file mode 100644 index 00000000..cfd29206 --- /dev/null +++ b/src/amdis/functions/Blocking.hpp @@ -0,0 +1,193 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +namespace AMDiS +{ + // Lightweight representation of (hierarchic) block structure + namespace Blocking + { + struct Unknown + { + enum { isFlat = false }; + enum { isBlocked = false }; + }; + + /// \brief Blocking structure corresponding to IndexMergingStrategies \ref FlatLexicographic and \ref FlatInterleaved + struct Flat + { + enum { isFlat = true }; + enum { isBlocked = false }; + + template + Flat operator[](const Index&) const { return {}; } + }; + + /// \brief Blocking structure corresponding to IndexMergingStrategy \ref LeafBlockedInterleaved + template + struct LeafBlocked + { + enum { isFlat = false }; + enum { isBlocked = false }; + + template + Flat operator[](const Index&) const { return {}; } + }; + + /// \brief Blocking structure corresponding to IndexMergingStrategy \ref BlockedLexicographic + template + struct Blocked + { + enum { isFlat = false }; + enum { isBlocked = true }; + + template + auto operator[](index_t) const { return std::get(t); } + + Tag0 operator[](std::size_t /*i*/) const { return {}; } + + std::tuple t; + }; + + } // end namespace tag + + + namespace Impl + { + // Handle non-leaf nodes + template