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

5
#include <amdis/AMDiS.hpp>
6
#include <amdis/common/FieldMatVec.hpp>
7
8
9
10
11
#include <amdis/AdaptInstationary.hpp>
#include <amdis/ProblemStat.hpp>
#include <amdis/ProblemInstat.hpp>
#include <amdis/Operators.hpp>
#include <amdis/assembler/StokesOperator.hpp>
12

13
14
using namespace AMDiS;

15
16
struct NavierStokesBasis
{
17
  using Grid = Dune::YaspGrid<AMDIS_DIM>;
18
19
  using GlobalBasis = typename TaylorHoodBasis<Grid::LeafGridView>::GlobalBasis;
};
20

21
22
using StokesProblem = ProblemStat<NavierStokesBasis>;
using StokesProblemInstat = ProblemInstat<NavierStokesBasis>;
23

24
25
int main(int argc, char** argv)
{
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  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);

41
  AdaptInfo adaptInfo("adapt");
42
43
44
45
46
47

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

  // <1/tau * u, v>
48
  auto opTime = makeOperator(tag::testvec_trialvec{}, density);
49
50
51
  prob.addMatrixOperator(opTime, _v, _v);

  // <1/tau * u^old, v>
52
  auto opTimeOld = makeOperator(tag::testvec{}, density * prob.getSolution(_v));
53
54
55
  prob.addVectorOperator(opTimeOld, _v);


56
57
58
  // sum_i <grad(u_i),grad(v_i)> + <p, div(v)> + <div(u), q>
  auto opStokes = makeOperator(tag::stokes{}, viscosity);
  prob.addMatrixOperator(opStokes, treepath(), treepath());
59

60
61
62
  // <(u * nabla)u_i^old, v_i>
  auto opNonlin1 = makeOperator(tag::testvec_trialvec{}, density * trans(gradientAtQP(prob.getSolution(_v))));
  prob.addMatrixOperator(opNonlin1, _v, _v);
63

64
  for (std::size_t i = 0; i < AMDIS_DOW; ++i) {
65
    // <(u^old * nabla)u_i, v_i>
66
    auto opNonlin2 = makeOperator(tag::test_gradtrial{}, density * prob.getSolution(_v));
67
68
    prob.addMatrixOperator(opNonlin2, treepath(_v,i), treepath(_v,i));
  }
69

70
71
72
73
  // <(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);

74
75
76
  // 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; };
77

78
79
80
81
82
  // define boundary values
  auto parabolic_y = [](auto const& x) -> Dune::FieldVector<double,2>
  {
    return {0.0, x[1]*(1.0 - x[1])};
  };
83

84
85
86
87
  auto zero = [](auto const& x) -> Dune::FieldVector<double,2>
  {
    return {0.0, 0.0};
  };
88

89
90
91
  // set boundary conditions for velocity
  prob.addDirichletBC(left, _v, _v, parabolic_y);
  prob.addDirichletBC(not_left, _v, _v, zero);
92

93
94
95
  // 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);

96
97
98
  // set initial conditions
  prob.getSolution(_v).interpolate(parabolic_y);
  prob.getSolution(_p).interpolate(0.0);
99
100
101
102
103
104
105
106
107

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

  // output solution
  prob.writeFiles(adaptInfo);

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