summaryrefslogtreecommitdiff
path: root/apps/adrian/cylinder2d/outflow_refinement/cylinder2d.cpp
blob: 5a6725b3f98a9ba36c5467a233cbd6036b4da06d (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 *  Lattice Boltzmann grid refinement sample, written in C++,
 *  using the OpenLB library
 *
 *  Copyright (C) 2019 Adrian Kummerländer
 *  E-mail contact: info@openlb.net
 *  The most recent release of OpenLB can be downloaded at
 *  <http://www.openlb.net/>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA  02110-1301, USA.
 */

#include "olb2D.h"
#ifndef OLB_PRECOMPILED
#include "olb2D.hh"
#endif

using namespace olb;

typedef double T;

#define DESCRIPTOR descriptors::D2Q9Descriptor

/// Setup geometry relative to cylinder diameter as defined by [SchaeferTurek96]
const T   cylinderD = 0.1;
const int N         = 5;                      // resolution of the cylinder

const T   Re        = 100.;                   // Reynolds number
const T   tau       = 0.51;                   // relaxation time
const T   maxPhysT  = 16.;                    // max. simulation time in s, SI unit

const Characteristics<T> PhysCharacteristics(
  cylinderD,   // char. phys. length
  1.0,         // char. phys. velocity
  0.1/Re,      // phsy. kinematic viscosity
  1.0);        // char. phys. density

#include "../common/model.h"

void setupRefinement(Grid2D<T,DESCRIPTOR>& coarseGrid,
                     Vector<T,2> domainOrigin, Vector<T,2> domainExtend)
{
  const auto coarseDeltaX = coarseGrid.getConverter().getPhysDeltaX();

  const Vector<T,2> fineOutflowExtend {1*cylinderD, domainExtend[1]};
  const Vector<T,2> fineOutflowOrigin {domainExtend[0]-1*cylinderD, 0};

  auto& fineOutflowGrid = coarseGrid.refine(fineOutflowOrigin, fineOutflowExtend, false);
  SchaeferTurek::prepareGeometry(fineOutflowGrid, domainOrigin, domainExtend);

  {
    const Vector<T,2> origin = fineOutflowGrid.getOrigin();
    const Vector<T,2> extend = fineOutflowGrid.getExtend();

    const Vector<T,2> extendY = {0,extend[1]};

    coarseGrid.addFineCoupling(fineOutflowGrid, origin, extendY);
    coarseGrid.addCoarseCoupling(fineOutflowGrid, origin + Vector<T,2> {coarseDeltaX,0}, extendY);

    IndicatorCuboid2D<T> refined(extend, origin + Vector<T,2> {2*coarseDeltaX,0});
    coarseGrid.getSuperGeometry().reset(refined);
  }

  const Vector<T,2> fineOutflowExtend2 {0.5*cylinderD, domainExtend[1]};
  const Vector<T,2> fineOutflowOrigin2 {domainExtend[0]-0.5*cylinderD, 0};

  auto& fineOutflowGrid2 = fineOutflowGrid.refine(fineOutflowOrigin2, fineOutflowExtend2, false);
  SchaeferTurek::prepareGeometry(fineOutflowGrid2, domainOrigin, domainExtend);

  {
    const Vector<T,2> origin = fineOutflowGrid2.getOrigin();
    const Vector<T,2> extend = fineOutflowGrid2.getExtend();

    const Vector<T,2> extendY = {0,extend[1]};

    fineOutflowGrid.addFineCoupling(fineOutflowGrid2, origin, extendY);
    fineOutflowGrid.addCoarseCoupling(fineOutflowGrid2, origin + Vector<T,2> {coarseDeltaX,0}, extendY);

    IndicatorCuboid2D<T> refined(extend, origin + Vector<T,2> {coarseDeltaX,0});
    fineOutflowGrid.getSuperGeometry().reset(refined);
  }
}

int main(int argc, char* argv[])
{
  olbInit(&argc, &argv);
  singleton::directories().setOutputDir("./tmp/");
  OstreamManager clout(std::cout,"main");

  IndicatorCuboid2D<T> coarseCuboid(SchaeferTurek::modelExtend, SchaeferTurek::modelOrigin);

  Grid2D<T,DESCRIPTOR> coarseGrid(
    coarseCuboid,
    RelaxationTime<T>(tau),
    N,
    PhysCharacteristics);
  const Vector<T,2> domainOrigin = coarseGrid.getSuperGeometry().getStatistics().getMinPhysR(0);
  const Vector<T,2> domainExtend = coarseGrid.getSuperGeometry().getStatistics().getPhysExtend(0);

  SchaeferTurek::prepareGeometry(coarseGrid, domainOrigin, domainExtend);

  setupRefinement(coarseGrid, domainOrigin, domainExtend);

  coarseGrid.forEachGrid(SchaeferTurek::prepareLattice);

  clout << "Total number of active cells: " << coarseGrid.getActiveVoxelN() << endl;
  clout << "Starting simulation..." << endl;

  const int statIter = coarseGrid.getConverter().getLatticeTime(0.5);
  Timer<T> timer(
    coarseGrid.getConverter().getLatticeTime(maxPhysT),
    coarseGrid.getSuperGeometry().getStatistics().getNvoxel());
  timer.start();

  Grid2D<T,DESCRIPTOR>& cylinderGrid = coarseGrid.locate(SchaeferTurek::cylinderCenter);

  for (int iT = 0; iT <= coarseGrid.getConverter().getLatticeTime(maxPhysT); ++iT) {
    SchaeferTurek::setBoundaryValues(coarseGrid, iT);

    coarseGrid.collideAndStream();

    if (iT == 0 || iT%statIter == 0) {
      timer.update(iT);
      timer.printStep();

      coarseGrid.forEachGrid("cylinder2d", [&](Grid2D<T,DESCRIPTOR>& grid, const std::string& id) {
        SchaeferTurek::getResults(grid, id, iT);
      });

      SchaeferTurek::takeMeasurements(cylinderGrid, iT);
    }
  }

  timer.stop();
  timer.printSummary();
}