navier_stokes.cc 3.45 KB
Newer Older
1
2
3
4
5
#include <iostream>
#include <ctime>
#include <cmath>

#include <dune/amdis/AMDiS.hpp>
6
#include <dune/amdis/AdaptInstationary.hpp>
7
#include <dune/amdis/ProblemStat.hpp>
8
#include <dune/amdis/ProblemInstat.hpp>
9
#include <dune/amdis/Terms.hpp>
10

11
12
#ifdef DOW
#undef DOW
13
#endif
14
#define DOW AMDIS_DOW
15

16
17
18
19
#ifndef STRATEGY
#define STRATEGY 1
#endif

20
21
using namespace AMDiS;

22
23
using Grid = Dune::AlbertaGrid<AMDIS_DIM, AMDIS_DOW>;
using StokesParam   = TaylorHoodBasis<Grid::LeafGridView>;
24
using StokesProblem = ProblemStat<StokesParam>;
25
using StokesProblemInstat = ProblemInstat<StokesParam>;
26

27
28
using Op = StokesProblem::ElementOperator;

29
30
int main(int argc, char** argv)
{
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  AMDiS::init(argc, argv);

  StokesProblem prob("stokes");
  prob.initialize(INIT_ALL);

  StokesProblemInstat probInstat("stokes", prob);
  probInstat.initialize(INIT_UH_OLD);

  double viscosity = 1.0;
  double density = 1.0;
  double vel = 1.0;
  Parameters::get("stokes->viscosity", viscosity);
  Parameters::get("stokes->density", density);
  Parameters::get("stokes->boundary velocity", vel);

  AdaptInfo adaptInfo("adapt", prob.getNumComponents());

  // tree-paths for components
  auto _v = 0_c;
  auto _p = 1_c;

  // <1/tau * u, v>
53
  auto opTime = makeOperator(tag::testvec_trialvec{}, density);
54
55
56
  prob.addMatrixOperator(opTime, _v, _v);

  // <1/tau * u^old, v>
57
  auto opTimeOld = makeOperator(tag::testvec{}, density * prob.getSolution(_v));
58
59
60
  prob.addVectorOperator(opTimeOld, _v);

  // sum_i <grad(u_i),grad(v_i)>
61
62
63
64
  for (std::size_t i = 0; i < DOW; ++i) {
    auto opL = makeOperator(tag::gradtest_gradtrial{}, viscosity);
    prob.addMatrixOperator(opL, treepath(_v,i), treepath(_v,i));
  }
65
66

  // <p, div(v)>
67
  auto opP = makeOperator(tag::divtestvec_trial{}, 1.0);
68
69
70
  prob.addMatrixOperator(opP, _v, _p);

  // <div(u), q>
71
  auto opDiv = makeOperator(tag::test_divtrialvec{}, 1.0);
72
73
74
  prob.addMatrixOperator(opDiv, _p, _v);


75
76
77
  // <(u * nabla)u_i^old, v_i>
  auto opNonlin1 = makeOperator(tag::testvec_trialvec{}, density * trans(gradientAtQP(prob.getSolution(_v))));
  prob.addMatrixOperator(opNonlin1, _v, _v);
78

79
  for (std::size_t i = 0; i < DOW; ++i) {
80
    // <(u^old * nabla)u_i, v_i>
81
    auto opNonlin2 = makeOperator(tag::test_gradtrial{}, density * prob.getSolution(_v));
82
83
    prob.addMatrixOperator(opNonlin2, treepath(_v,i), treepath(_v,i));
  }
84

85
86
87
88
  // <(u^old * grad(u_i^old)), v_i>
  auto opNonlin3 = makeOperator(tag::testvec{}, trans(gradientAtQP(prob.getSolution(_v))) * prob.getSolution(_v));
  prob.addVectorOperator(opNonlin3, _v);

89
90
91
  // define boundary regions
  auto left = [](auto const& x) { return x[0] < 1.e-8; };
  auto not_left = [](auto const& x) { return x[0] > 1.0 - 1.e-8 || x[1] < 1.e-8 || x[1] > 1.0 - 1.e-8; };
92

93
94
95
96
97
  // define boundary values
  auto parabolic_y = [](auto const& x) -> Dune::FieldVector<double,2>
  {
    return {0.0, x[1]*(1.0 - x[1])};
  };
98

99
100
101
102
  auto zero = [](auto const& x) -> Dune::FieldVector<double,2>
  {
    return {0.0, 0.0};
  };
103

104
105
106
  // set boundary conditions for velocity
  prob.addDirichletBC(left, _v, _v, parabolic_y);
  prob.addDirichletBC(not_left, _v, _v, zero);
107

108
109
110
  // set point constraint for pressure
  prob.addDirichletBC([](auto const& x) { return x[0] < 1.e-8 && x[1] < 1.e-8; }, _p, _p, 0.0);

111
112
113
  // set initial conditions
  prob.getSolution(_v).interpolate(parabolic_y);
  prob.getSolution(_p).interpolate(0.0);
114
115
116
117
118
119
120
121
122

  AdaptInstationary adapt("adapt", prob, adaptInfo, probInstat, adaptInfo);
  adapt.adapt();

  // output solution
  prob.writeFiles(adaptInfo);

  AMDiS::finalize();
  return 0;
123
}