ExpressionsTest.cpp 2.61 KB
 Praetorius, Simon committed Jan 28, 2018 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 ``````// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: #include #include #include #include #include #include #include using namespace AMDiS; using ElliptParam = YaspGridBasis<2, 2>; using ElliptProblem = ProblemStat; int main(int argc, char** argv) { AMDiS::init(argc, argv); using namespace Dune::Indices; ElliptProblem prob("ellipt"); prob.initialize(INIT_ALL); auto u = prob.getSolution(_0); // 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 auto expr9 = prob.getSolution(_0); // --------------------------------- // 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 auto gv = u.basis().gridView(); 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); AMDiS::finalize(); return 0; }``````