expressions.cc 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:

#include <iostream>

#include <dune/amdis/AMDiS.hpp>
#include <dune/amdis/ProblemStat.hpp>
#include <dune/amdis/Operators.hpp>
#include <dune/amdis/common/Literals.hpp>
10
#include <dune/amdis/common/FieldMatVec.hpp>
11
#include <dune/amdis/gridfunctions/Integrate.hpp>
12

13 14 15 16

using namespace AMDiS;

// 1 component with polynomial degree 1
17 18
//using Grid = Dune::AlbertaGrid<AMDIS_DIM, AMDIS_DOW>;
using ElliptParam   = YaspGridBasis<AMDIS_DIM, 2>;
19 20 21 22 23 24 25 26 27
using ElliptProblem = ProblemStat<ElliptParam>;

int main(int argc, char** argv)
{
  AMDiS::init(argc, argv);

  ElliptProblem prob("ellipt");
  prob.initialize(INIT_ALL);

28
  auto u = prob.getSolution(_0);
29

30 31 32 33
  // eval a functor at global coordinates (at quadrature points)
  auto expr1 = evalAtQP([](Dune::FieldVector<double, AMDIS_DOW> const& x) { return x[0] + x[1]; });
  auto expr2 = [](Dune::FieldVector<double, AMDIS_DOW> const& x) { return x[0] + x[1]; };
  auto expr3 = [](auto const& x) { return x[0] + x[1]; };
34

35 36 37 38
  // constant values at quadrature points
  auto expr4 = 1.0;
  auto expr5 = Dune::FieldVector<double, AMDIS_DOW>{1.0, 2.0};
  auto expr6 = std::ref(expr4);
39

40 41 42
  // Coordinate vector and component
  auto expr7 = X();
  auto expr8 = X(0);
43

44 45 46 47 48 49 50 51
  // Evaluation of the DOFVector (component) at quadrature points
  auto expr9 = prob.getSolution(_0);

  // ---------------------------------

  // derivative of expressions

  auto diff4 = gradientAtQP(expr4);
52
  // auto diff5 = gradientAtQP(expr5);
53 54
  auto diff6 = gradientAtQP(expr6);

55
  // auto diff7 = gradientAtQP(expr7);
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
  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();

99 100
  auto int1 = integrate(op1, gv, 5);
  auto int2 = integrate(op2, gv, 5);
101
  auto int3 = integrate(op3, gv);
102 103 104 105 106
  auto int4 = integrate(op4, gv, 5);
  auto int5 = integrate(op5, gv, 5);
  auto int6 = integrate(op6, gv, 5);

  std::cout << int1 << int2 << int3 << int4 << int5 << int6 << "\n";
107 108

  AdaptInfo adaptInfo("adapt", 1);
109 110 111 112
  prob.writeFiles(adaptInfo, true);
  AMDiS::finalize();
  return 0;
}