From d6e19bfe00aad616c5d31538a834ce6d416e964d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20M=C3=BCller?= Date: Fri, 23 Nov 2018 14:35:25 +0100 Subject: [PATCH] Added support for PreTreePath argument to makeDiscreteFunction/DOFVectorView; Updated unit test --- src/amdis/gridfunctions/DOFVectorView.hpp | 7 ++-- src/amdis/gridfunctions/DiscreteFunction.hpp | 8 +++-- test/DiscreteFunctionTest.cpp | 35 ++++++++++++++++++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/amdis/gridfunctions/DOFVectorView.hpp b/src/amdis/gridfunctions/DOFVectorView.hpp index 50f1253..ff4cf0f 100644 --- a/src/amdis/gridfunctions/DOFVectorView.hpp +++ b/src/amdis/gridfunctions/DOFVectorView.hpp @@ -115,10 +115,11 @@ namespace AMDiS #endif /// A Generator for a mutable \ref DOFVectorView - template - auto makeDOFVectorView(DOFVector& dofVector, TreePath const& treePath) + template + auto makeDOFVectorView(DOFVector& dofVector, PreTreePath const& preTreePath) { - return DOFVectorView{dofVector, treePath}; + auto treePath = makeTreePath(preTreePath); + return DOFVectorView{dofVector, treePath}; } /// A Generator for a mutable \ref DOFVectorView diff --git a/src/amdis/gridfunctions/DiscreteFunction.hpp b/src/amdis/gridfunctions/DiscreteFunction.hpp index 3b0f4ad..4e853ea 100644 --- a/src/amdis/gridfunctions/DiscreteFunction.hpp +++ b/src/amdis/gridfunctions/DiscreteFunction.hpp @@ -11,6 +11,7 @@ #include #include +#include namespace AMDiS { @@ -126,10 +127,11 @@ namespace AMDiS #endif /// A Generator for a \ref DiscreteFunction - template - auto makeDiscreteFunction(DOFVector const& dofVector, TreePath const& treePath) + template + auto makeDiscreteFunction(DOFVector const& dofVector, PreTreePath const& preTreePath) { - return DiscreteFunction{dofVector, treePath}; + auto treePath = makeTreePath(preTreePath); + return DiscreteFunction{dofVector, treePath}; } /// A Generator for a \ref DiscreteFunction diff --git a/test/DiscreteFunctionTest.cpp b/test/DiscreteFunctionTest.cpp index 8d483c8..0862d4f 100644 --- a/test/DiscreteFunctionTest.cpp +++ b/test/DiscreteFunctionTest.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "Tests.hpp" @@ -48,7 +49,7 @@ int main(int argc, char** argv) auto u1 = makeDOFVectorView(U1); auto u2 = makeDOFVectorView(U2); - auto expr = [](auto const& x) { return x[0] + x[1]; }; + auto expr = [](auto const& x) { return 1 + x[0] + x[1]; }; u0.interpolate_noalias(expr); u1.interpolate(expr); u2 << expr; @@ -56,7 +57,7 @@ int main(int argc, char** argv) AMDIS_TEST( comp(U0, U1) ); AMDIS_TEST( comp(U0, U2) ); - auto expr2 = [](auto const& x) { return 2*x[0] - 3*x[1]; }; + auto expr2 = [](auto const& x) { return 1 + 2*x[0] - 3*x[1]; }; u0.interpolate_noalias(u2 + expr2); u1.interpolate(u1 + expr2); @@ -65,7 +66,7 @@ int main(int argc, char** argv) AMDIS_TEST( comp(U0, U1) ); AMDIS_TEST( comp(U0, U2) ); - auto expr3 = [](auto const& x) { return -0.5*x[0] - 2*x[1]; }; + auto expr3 = [](auto const& x) { return 1 - 0.5*x[0] - 2*x[1]; }; u0.interpolate_noalias(u2 - expr3); u1.interpolate(u1 - expr3); @@ -100,6 +101,34 @@ int main(int argc, char** argv) auto v0 = makeDOFVectorView(V0); v0 << expr; + // test makeDiscreteFunction + int preTP1 = 0; + std::integral_constant preTP2; + auto tp = treepath(preTP1); + auto W0 = prob.solutionVector(); + auto W1 = prob.solutionVector(); + auto W2 = prob.solutionVector(); + auto w0 = makeDiscreteFunction(W0, preTP1); + auto w1 = makeDiscreteFunction(W1, preTP2); + auto w2 = makeDiscreteFunction(W2, tp); + + // test makeDOFVectorView with (pre)treepath argument + auto W3 = prob.solutionVector(); + auto W4 = prob.solutionVector(); + auto W5 = prob.solutionVector(); + auto w3 = makeDOFVectorView(W3, preTP1); + auto w4 = makeDOFVectorView(W4, preTP2); + auto w5 = makeDOFVectorView(W5, tp); + auto w6 = prob.solution(tp); + auto& W6 = prob.solutionVector(); + w3 << expr; + w4 << expr; + w5 << expr; + w6 << expr; + AMDIS_TEST( comp(W3, W4) ); + AMDIS_TEST( comp(W3, W5) ); + AMDIS_TEST( comp(W3, W6) ); + AMDiS::finalize(); return 0; } -- GitLab