ExpressionsTest.cpp 2.47 KB
 Praetorius, Simon committed Jan 28, 2018 1 2 3 4 5 ``````// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: #include `````` Praetorius, Simon committed Jan 28, 2018 6 ``````#include `````` Praetorius, Simon committed Oct 23, 2018 7 ``````#include `````` Praetorius, Simon committed Feb 28, 2019 8 ``````#include `````` Praetorius, Simon committed Jan 28, 2018 9 10 ``````#include #include `````` Praetorius, Simon committed Jan 28, 2018 11 12 13 14 15 16 17 18 19 `````` using namespace AMDiS; using ElliptParam = YaspGridBasis<2, 2>; using ElliptProblem = ProblemStat; int main(int argc, char** argv) { `````` Praetorius, Simon committed Apr 26, 2019 20 `````` Environment env(argc, argv); `````` Praetorius, Simon committed Jan 28, 2018 21 22 23 24 `````` ElliptProblem prob("ellipt"); prob.initialize(INIT_ALL); `````` Müller, Felix committed Jan 31, 2020 25 `````` auto u = prob.solution(); `````` Praetorius, Simon committed Jan 28, 2018 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 `````` // eval a functor at global coordinates (at quadrature points) auto expr1 = evalAtQP([](Dune::FieldVector const& x) { return x[0] + x[1]; }); auto expr2 = [](Dune::FieldVector const& x) { return x[0] + x[1]; }; auto expr3 = [](auto const& x) { return x[0] + x[1]; }; // constant values at quadrature points auto expr4 = 1.0; auto expr5 = Dune::FieldVector{1.0, 2.0}; auto expr6 = std::ref(expr4); // Coordinate vector and component auto expr7 = X(); auto expr8 = X(0); // Evaluation of the DOFVector (component) at quadrature points `````` Müller, Felix committed Jan 31, 2020 42 `````` auto expr9 = prob.solution(); `````` Praetorius, Simon committed Jan 28, 2018 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 `````` // --------------------------------- // derivative of expressions auto diff4 = gradientAtQP(expr4); // auto diff5 = gradientAtQP(expr5); auto diff6 = gradientAtQP(expr6); // auto diff7 = gradientAtQP(expr7); auto diff8 = gradientAtQP(expr8); auto diff9 = gradientAtQP(expr9); // --------------------------------- u.interpolate(expr1); u.interpolate(expr2); u.interpolate(expr3); u.interpolate(expr4); u.interpolate(expr6); u.interpolate(expr8); u.interpolate(expr9); // --------------------------------- // operations with expressions auto op1 = expr1 + expr2; auto op2 = expr1 * expr4; auto op3 = two_norm(expr5); auto op4 = min(expr6, expr8); auto op5 = one_norm(expr7); auto op6 = invokeAtQP([](double v) { return 2*v; }, op5); u.interpolate(two_norm(diff4)); u.interpolate(two_norm(diff6)); u.interpolate(two_norm(diff8)); u.interpolate(two_norm(diff9)); // --------------------------------- // integration of expressions `````` Praetorius, Simon committed Dec 30, 2019 94 `````` auto gv = u.basis().gridView(); `````` Praetorius, Simon committed Jan 28, 2018 95 96 97 98 99 100 101 102 103 104 `````` DUNE_UNUSED auto int1 = integrate(op1, gv, 5); DUNE_UNUSED auto int2 = integrate(op2, gv, 5); DUNE_UNUSED auto int3 = integrate(op3, gv); DUNE_UNUSED auto int4 = integrate(op4, gv, 5); DUNE_UNUSED auto int5 = integrate(op5, gv, 5); DUNE_UNUSED auto int6 = integrate(op6, gv, 5); return 0; }``````