summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/adrian/cylinder2d/common/model.h222
-rw-r--r--apps/adrian/cylinder2d/optimized_grid/cylinder2d.cpp231
-rw-r--r--apps/adrian/cylinder2d/outflow_refinement/cylinder2d.cpp259
3 files changed, 275 insertions, 437 deletions
diff --git a/apps/adrian/cylinder2d/common/model.h b/apps/adrian/cylinder2d/common/model.h
new file mode 100644
index 0000000..89b276b
--- /dev/null
+++ b/apps/adrian/cylinder2d/common/model.h
@@ -0,0 +1,222 @@
+/*
+ * 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.
+ */
+
+namespace SchaeferTurek {
+
+const T deltaR = cylinderD / N; // coarse lattice spacing
+
+const Vector<T,2> modelOrigin {0.0, 0.0};
+const Vector<T,2> modelExtend {22*cylinderD + deltaR, 4.1*cylinderD + deltaR};
+
+const Vector<T,2> cylinderCenter {2*cylinderD, 2*cylinderD + deltaR/2};
+
+void prepareGeometry(Grid2D<T,DESCRIPTOR>& grid, Vector<T,2> origin, Vector<T,2> extend)
+{
+ OstreamManager clout(std::cout,"prepareGeometry");
+ clout << "Prepare Geometry ..." << std::endl;
+
+ auto& converter = grid.getConverter();
+ auto& sGeometry = grid.getSuperGeometry();
+
+ sGeometry.rename(0,1);
+
+ const T physSpacing = converter.getPhysDeltaX();
+
+ // Set material number for channel walls
+ {
+ const Vector<T,2> wallExtend { extend[0]+physSpacing/2, physSpacing/2 };
+ const Vector<T,2> wallOrigin = origin - physSpacing/4;
+
+ IndicatorCuboid2D<T> lowerWall(wallExtend, wallOrigin);
+ sGeometry.rename(1,2,lowerWall);
+ }
+ {
+ const Vector<T,2> wallExtend { extend[0]+physSpacing/2, physSpacing/2 };
+ const Vector<T,2> wallOrigin { origin[0]-physSpacing/4, extend[1]-physSpacing/4 };
+
+ IndicatorCuboid2D<T> upperWall(wallExtend, wallOrigin);
+ sGeometry.rename(1,2,upperWall);
+ }
+
+ // Set material number for inflow and outflow
+ {
+ const Vector<T,2> inflowExtend { physSpacing/2, extend[1]+physSpacing/4 };
+ const Vector<T,2> inflowOrigin = origin - physSpacing/4;
+
+ IndicatorCuboid2D<T> inflow(inflowExtend, inflowOrigin);
+ sGeometry.rename(1,3,inflow);
+ }
+ {
+ const Vector<T,2> outflowExtend { physSpacing/2, extend[1]+physSpacing/4 };
+ const Vector<T,2> outflowOrigin { extend[0]-physSpacing/4, origin[0]-physSpacing/4 };
+
+ IndicatorCuboid2D<T> outflow(outflowExtend, outflowOrigin);
+ sGeometry.rename(1,4,outflow);
+ }
+
+ // Set material number for vertically centered cylinder
+ {
+ const Vector<T,2> cylinderOrigin = origin + Vector<T,2> {cylinderCenter[0], cylinderCenter[1]};
+ IndicatorCircle2D<T> obstacle(cylinderOrigin, cylinderD/2);
+ sGeometry.rename(1,5,obstacle);
+ }
+
+ sGeometry.clean();
+ sGeometry.innerClean();
+ sGeometry.checkForErrors();
+
+ clout << "Prepare Geometry ... OK" << std::endl;
+}
+
+void prepareLattice(Grid2D<T,DESCRIPTOR>& grid)
+{
+ OstreamManager clout(std::cout,"prepareLattice");
+ clout << "Prepare lattice ..." << std::endl;
+
+ auto& converter = grid.getConverter();
+ auto& sGeometry = grid.getSuperGeometry();
+ auto& sLattice = grid.getSuperLattice();
+
+ Dynamics<T,DESCRIPTOR>& bulkDynamics = grid.addDynamics(
+ std::unique_ptr<Dynamics<T,DESCRIPTOR>>(
+ new BGKdynamics<T,DESCRIPTOR>(
+ grid.getConverter().getLatticeRelaxationFrequency(),
+ instances::getBulkMomenta<T,DESCRIPTOR>())));
+
+ sOnLatticeBoundaryCondition2D<T,DESCRIPTOR>& sBoundaryCondition = grid.getOnLatticeBoundaryCondition();
+ createLocalBoundaryCondition2D<T,DESCRIPTOR>(sBoundaryCondition);
+
+ const T omega = converter.getLatticeRelaxationFrequency();
+
+ sLattice.defineDynamics(sGeometry, 0, &instances::getNoDynamics<T,DESCRIPTOR>());
+ sLattice.defineDynamics(sGeometry, 1, &bulkDynamics); // bulk
+ sLattice.defineDynamics(sGeometry, 2, &bulkDynamics); // walls
+ sLattice.defineDynamics(sGeometry, 3, &bulkDynamics); // inflow
+ sLattice.defineDynamics(sGeometry, 4, &bulkDynamics); // outflow
+ sLattice.defineDynamics(sGeometry, 5, &instances::getBounceBack<T,DESCRIPTOR>()); // cylinder
+
+ sBoundaryCondition.addVelocityBoundary(sGeometry, 2, omega);
+ sBoundaryCondition.addVelocityBoundary(sGeometry, 3, omega);
+ sBoundaryCondition.addPressureBoundary(sGeometry, 4, omega);
+
+ AnalyticalConst2D<T,T> rho0(1.0);
+ AnalyticalConst2D<T,T> u0(0.0, 0.0);
+
+ auto materials = sGeometry.getMaterialIndicator({1, 2, 3, 4});
+ sLattice.defineRhoU(materials, rho0, u0);
+ sLattice.iniEquilibrium(materials, rho0, u0);
+
+ sLattice.initialize();
+
+ clout << "Prepare lattice ... OK" << std::endl;
+ sGeometry.print();
+}
+
+void setBoundaryValues(Grid2D<T,DESCRIPTOR>& grid, int iT)
+{
+ auto& converter = grid.getConverter();
+ auto& sGeometry = grid.getSuperGeometry();
+ auto& sLattice = grid.getSuperLattice();
+
+ const int iTmaxStart = converter.getLatticeTime(0.4*16);
+ const int iTupdate = 5;
+
+ if ( iT % iTupdate == 0 && iT <= iTmaxStart ) {
+ PolynomialStartScale<T,T> StartScale(iTmaxStart, 1);
+
+ T iTvec[1] { T(iT) };
+ T frac[1] { };
+ StartScale(frac, iTvec);
+
+ const T maxVelocity = converter.getCharLatticeVelocity() * 3./2. * frac[0];
+ Poiseuille2D<T> u(sGeometry, 3, maxVelocity, converter.getPhysDeltaX()/2);
+
+ sLattice.defineU(sGeometry, 3, u);
+ }
+}
+
+void getResults(Grid2D<T,DESCRIPTOR>& grid,
+ const std::string& prefix,
+ int iT)
+{
+ auto& converter = grid.getConverter();
+ auto& sLattice = grid.getSuperLattice();
+ auto& sGeometry = grid.getSuperGeometry();
+
+ SuperVTMwriter2D<T> vtmWriter(prefix);
+ SuperLatticePhysVelocity2D<T,DESCRIPTOR> velocity(sLattice, converter);
+ SuperLatticePhysPressure2D<T,DESCRIPTOR> pressure(sLattice, converter);
+ SuperLatticeGeometry2D<T,DESCRIPTOR> geometry(sLattice, sGeometry);
+ SuperLatticeKnudsen2D<T,DESCRIPTOR> knudsen(sLattice);
+ vtmWriter.addFunctor(geometry);
+ vtmWriter.addFunctor(velocity);
+ vtmWriter.addFunctor(pressure);
+ vtmWriter.addFunctor(knudsen);
+
+ if (iT==0) {
+ vtmWriter.createMasterFile();
+ }
+
+ vtmWriter.write(iT);
+}
+
+void takeMeasurements(Grid2D<T,DESCRIPTOR>& grid, int iT, bool print=true)
+{
+ auto& sLattice = grid.getSuperLattice();
+ auto& sGeometry = grid.getSuperGeometry();
+ auto& converter = grid.getConverter();
+
+ SuperLatticePhysPressure2D<T,DESCRIPTOR> pressure(sLattice, converter);
+ AnalyticalFfromSuperF2D<T> intpolatePressure(pressure, true);
+ SuperLatticePhysDrag2D<T,DESCRIPTOR> dragF(sLattice, sGeometry, 5, converter);
+
+ const T radiusCylinder = cylinderD/2;
+
+ const T point1[2] { cylinderCenter[0] - radiusCylinder, cylinderCenter[1] };
+ const T point2[2] { cylinderCenter[0] + radiusCylinder, cylinderCenter[1] };
+
+ T pressureInFrontOfCylinder, pressureBehindCylinder;
+ intpolatePressure(&pressureInFrontOfCylinder, point1);
+ intpolatePressure(&pressureBehindCylinder, point2);
+ const T pressureDrop = pressureInFrontOfCylinder - pressureBehindCylinder;
+
+ const int input[3] {};
+ T drag[dragF.getTargetDim()] {};
+ dragF(drag, input);
+
+ static Gnuplot<T> gplot("results");
+ gplot.setData(converter.getPhysTime(iT), {drag[0], drag[1], pressureDrop}, {"drag", "lift", "deltaP"}, "bottom right", {'l','l'});
+ gplot.writePNG();
+
+ if (print) {
+ OstreamManager clout(std::cout, "measurement");
+ clout << "pressureDrop=" << pressureDrop
+ << "; drag=" << drag[0]
+ << "; lift=" << drag[1]
+ << endl;
+ }
+}
+
+}
diff --git a/apps/adrian/cylinder2d/optimized_grid/cylinder2d.cpp b/apps/adrian/cylinder2d/optimized_grid/cylinder2d.cpp
index b4c3689..16fb95c 100644
--- a/apps/adrian/cylinder2d/optimized_grid/cylinder2d.cpp
+++ b/apps/adrian/cylinder2d/optimized_grid/cylinder2d.cpp
@@ -28,8 +28,6 @@
#include "olb2D.hh"
#endif
-#include <vector>
-
using namespace olb;
typedef double T;
@@ -39,210 +37,22 @@ typedef double T;
/// 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 deltaR = cylinderD / N; // coarse lattice spacing
-const T lx = 22*cylinderD + deltaR; // length of the channel
-const T ly = 4.1*cylinderD + deltaR; // height of the channel
-const T cylinderX = 2*cylinderD;
-const T cylinderY = 2*cylinderD + deltaR/2;
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(
- 0.1, // char. phys. length
+ cylinderD, // char. phys. length
1.0, // char. phys. velocity
0.1/Re, // phsy. kinematic viscosity
1.0); // char. phys. density
-void prepareGeometry(Grid2D<T,DESCRIPTOR>& grid, Vector<T,2> origin, Vector<T,2> extend)
-{
- OstreamManager clout(std::cout,"prepareGeometry");
- clout << "Prepare Geometry ..." << std::endl;
-
- auto& converter = grid.getConverter();
- auto& sGeometry = grid.getSuperGeometry();
-
- sGeometry.rename(0,1);
+#include "../common/model.h"
- const T physSpacing = converter.getPhysDeltaX();
-
- // Set material number for channel walls
- {
- const Vector<T,2> wallExtend { extend[0]+physSpacing/2, physSpacing/2 };
- const Vector<T,2> wallOrigin = origin - physSpacing/4;
-
- IndicatorCuboid2D<T> lowerWall(wallExtend, wallOrigin);
- sGeometry.rename(1,2,lowerWall);
- }
- {
- const Vector<T,2> wallExtend { extend[0]+physSpacing/2, physSpacing/2 };
- const Vector<T,2> wallOrigin { origin[0]-physSpacing/4, extend[1]-physSpacing/4 };
-
- IndicatorCuboid2D<T> upperWall(wallExtend, wallOrigin);
- sGeometry.rename(1,2,upperWall);
- }
-
- // Set material number for inflow and outflow
- {
- const Vector<T,2> inflowExtend { physSpacing/2, extend[1]+physSpacing/4 };
- const Vector<T,2> inflowOrigin = origin - physSpacing/4;
-
- IndicatorCuboid2D<T> inflow(inflowExtend, inflowOrigin);
- sGeometry.rename(1,3,inflow);
- }
- {
- const Vector<T,2> outflowExtend { physSpacing/2, extend[1]+physSpacing/4 };
- const Vector<T,2> outflowOrigin { extend[0]-physSpacing/4, origin[0]-physSpacing/4 };
-
- IndicatorCuboid2D<T> outflow(outflowExtend, outflowOrigin);
- sGeometry.rename(1,4,outflow);
- }
-
- // Set material number for vertically centered cylinder
- {
- const Vector<T,2> cylinderOrigin = origin + Vector<T,2> {cylinderX, cylinderY};
- IndicatorCircle2D<T> obstacle(cylinderOrigin, cylinderD/2);
- sGeometry.rename(1,5,obstacle);
- }
-
- sGeometry.clean();
- sGeometry.innerClean();
- sGeometry.checkForErrors();
-
- clout << "Prepare Geometry ... OK" << std::endl;
-}
-
-void prepareLattice(Grid2D<T,DESCRIPTOR>& grid)
-{
- OstreamManager clout(std::cout,"prepareLattice");
- clout << "Prepare lattice ..." << std::endl;
-
- auto& converter = grid.getConverter();
- auto& sGeometry = grid.getSuperGeometry();
- auto& sLattice = grid.getSuperLattice();
-
- Dynamics<T,DESCRIPTOR>& bulkDynamics = grid.addDynamics(
- std::unique_ptr<Dynamics<T,DESCRIPTOR>>(
- new BGKdynamics<T,DESCRIPTOR>(
- grid.getConverter().getLatticeRelaxationFrequency(),
- instances::getBulkMomenta<T,DESCRIPTOR>())));
-
- sOnLatticeBoundaryCondition2D<T,DESCRIPTOR>& sBoundaryCondition = grid.getOnLatticeBoundaryCondition();
- createLocalBoundaryCondition2D<T,DESCRIPTOR>(sBoundaryCondition);
-
- const T omega = converter.getLatticeRelaxationFrequency();
-
- sLattice.defineDynamics(sGeometry, 0, &instances::getNoDynamics<T,DESCRIPTOR>());
- sLattice.defineDynamics(sGeometry, 1, &bulkDynamics); // bulk
- sLattice.defineDynamics(sGeometry, 2, &bulkDynamics); // walls
- sLattice.defineDynamics(sGeometry, 3, &bulkDynamics); // inflow
- sLattice.defineDynamics(sGeometry, 4, &bulkDynamics); // outflow
- sLattice.defineDynamics(sGeometry, 5, &instances::getBounceBack<T,DESCRIPTOR>()); // cylinder
-
- sBoundaryCondition.addVelocityBoundary(sGeometry, 2, omega);
- sBoundaryCondition.addVelocityBoundary(sGeometry, 3, omega);
- sBoundaryCondition.addPressureBoundary(sGeometry, 4, omega);
-
- AnalyticalConst2D<T,T> rho0(1.0);
- AnalyticalConst2D<T,T> u0(0.0, 0.0);
-
- auto materials = sGeometry.getMaterialIndicator({1, 2, 3, 4});
- sLattice.defineRhoU(materials, rho0, u0);
- sLattice.iniEquilibrium(materials, rho0, u0);
-
- sLattice.initialize();
-
- clout << "Prepare lattice ... OK" << std::endl;
- sGeometry.print();
-}
-
-void setBoundaryValues(Grid2D<T,DESCRIPTOR>& grid, int iT)
-{
- auto& converter = grid.getConverter();
- auto& sGeometry = grid.getSuperGeometry();
- auto& sLattice = grid.getSuperLattice();
-
- const int iTmaxStart = converter.getLatticeTime(0.4*16);
- const int iTupdate = 5;
-
- if ( iT % iTupdate == 0 && iT <= iTmaxStart ) {
- PolynomialStartScale<T,T> StartScale(iTmaxStart, 1);
-
- T iTvec[1] { T(iT) };
- T frac[1] { };
- StartScale(frac, iTvec);
-
- const T maxVelocity = converter.getCharLatticeVelocity() * 3./2. * frac[0];
- Poiseuille2D<T> u(sGeometry, 3, maxVelocity, deltaR/2);
-
- sLattice.defineU(sGeometry, 3, u);
- }
-}
-
-void getResults(Grid2D<T,DESCRIPTOR>& grid,
- const std::string& prefix,
- int iT)
-{
- auto& converter = grid.getConverter();
- auto& sLattice = grid.getSuperLattice();
- auto& sGeometry = grid.getSuperGeometry();
-
- SuperVTMwriter2D<T> vtmWriter(prefix);
- SuperLatticePhysVelocity2D<T,DESCRIPTOR> velocity(sLattice, converter);
- SuperLatticePhysPressure2D<T,DESCRIPTOR> pressure(sLattice, converter);
- SuperLatticeGeometry2D<T,DESCRIPTOR> geometry(sLattice, sGeometry);
- SuperLatticeKnudsen2D<T,DESCRIPTOR> knudsen(sLattice);
- vtmWriter.addFunctor(geometry);
- vtmWriter.addFunctor(velocity);
- vtmWriter.addFunctor(pressure);
- vtmWriter.addFunctor(knudsen);
-
- if (iT==0) {
- vtmWriter.createMasterFile();
- }
-
- vtmWriter.write(iT);
-}
-
-void takeMeasurements(Grid2D<T,DESCRIPTOR>& grid, int iT, bool print=true)
-{
- auto& sLattice = grid.getSuperLattice();
- auto& sGeometry = grid.getSuperGeometry();
- auto& converter = grid.getConverter();
-
- SuperLatticePhysPressure2D<T,DESCRIPTOR> pressure(sLattice, converter);
- AnalyticalFfromSuperF2D<T> intpolatePressure(pressure, true);
- SuperLatticePhysDrag2D<T,DESCRIPTOR> dragF(sLattice, sGeometry, 5, converter);
-
- const T radiusCylinder = cylinderD/2;
-
- const T point1[2] { cylinderX - radiusCylinder, cylinderY };
- const T point2[2] { cylinderX + radiusCylinder, cylinderY };
-
- T pressureInFrontOfCylinder, pressureBehindCylinder;
- intpolatePressure(&pressureInFrontOfCylinder, point1);
- intpolatePressure(&pressureBehindCylinder, point2);
- const T pressureDrop = pressureInFrontOfCylinder - pressureBehindCylinder;
-
- const int input[3] {};
- T drag[dragF.getTargetDim()] {};
- dragF(drag, input);
-
- static Gnuplot<T> gplot("results");
- gplot.setData(converter.getPhysTime(iT), {drag[0], drag[1], pressureDrop}, {"drag", "lift", "deltaP"}, "bottom right", {'l','l'});
- gplot.writePNG();
-
- if (print) {
- OstreamManager clout(std::cout, "measurement");
- clout << "pressureDrop=" << pressureDrop
- << "; drag=" << drag[0]
- << "; lift=" << drag[1]
- << endl;
- }
-}
-
-void setupRefinement(Grid2D<T,DESCRIPTOR>& coarseGrid, Vector<T,2> domainOrigin, Vector<T,2> domainExtend)
+void setupRefinement(Grid2D<T,DESCRIPTOR>& coarseGrid,
+ Vector<T,2> domainOrigin, Vector<T,2> domainExtend,
+ Vector<T,2> cylinderCenter)
{
const auto coarseDeltaX = coarseGrid.getConverter().getPhysDeltaX();
@@ -250,7 +60,7 @@ void setupRefinement(Grid2D<T,DESCRIPTOR>& coarseGrid, Vector<T,2> domainOrigin,
const Vector<T,2> fineOutflowOrigin {domainExtend[0]-1*cylinderD, 0};
auto& fineOutflowGrid = coarseGrid.refine(fineOutflowOrigin, fineOutflowExtend, false);
- prepareGeometry(fineOutflowGrid, domainOrigin, domainExtend);
+ SchaeferTurek::prepareGeometry(fineOutflowGrid, domainOrigin, domainExtend);
{
const Vector<T,2> origin = fineOutflowGrid.getOrigin();
@@ -269,7 +79,7 @@ void setupRefinement(Grid2D<T,DESCRIPTOR>& coarseGrid, Vector<T,2> domainOrigin,
const Vector<T,2> fineOutflowOrigin2 {domainExtend[0]-0.5*cylinderD, 0};
auto& fineOutflowGrid2 = fineOutflowGrid.refine(fineOutflowOrigin2, fineOutflowExtend2, false);
- prepareGeometry(fineOutflowGrid2, domainOrigin, domainExtend);
+ SchaeferTurek::prepareGeometry(fineOutflowGrid2, domainOrigin, domainExtend);
{
const Vector<T,2> origin = fineOutflowGrid2.getOrigin();
@@ -288,19 +98,19 @@ void setupRefinement(Grid2D<T,DESCRIPTOR>& coarseGrid, Vector<T,2> domainOrigin,
const Vector<T,2> fineOrigin {0.5*cylinderD, coarseDeltaX};
auto& fineGrid = coarseGrid.refine(fineOrigin, fineExtend);
- prepareGeometry(fineGrid, domainOrigin, domainExtend);
+ SchaeferTurek::prepareGeometry(fineGrid, domainOrigin, domainExtend);
const Vector<T,2> fineExtend2 {5*cylinderD, fineGrid.getExtend()[1]-2*coarseDeltaX};
const Vector<T,2> fineOrigin2 {1*cylinderD, (domainExtend[1]-fineExtend2[1])/2};
auto& fineGrid2 = fineGrid.refine(fineOrigin2, fineExtend2);
- prepareGeometry(fineGrid2, domainOrigin, domainExtend);
+ SchaeferTurek::prepareGeometry(fineGrid2, domainOrigin, domainExtend);
const Vector<T,2> fineExtend3 {1.25*cylinderD, 1.25*cylinderD};
- const Vector<T,2> fineOrigin3 {cylinderX-fineExtend3[0]/2, cylinderY-fineExtend3[1]/2};
+ const Vector<T,2> fineOrigin3 {cylinderCenter[0]-fineExtend3[0]/2, cylinderCenter[1]-fineExtend3[1]/2};
auto& fineGrid3 = fineGrid2.refine(fineOrigin3, fineExtend3);
- prepareGeometry(fineGrid3, domainOrigin, domainExtend);
+ SchaeferTurek::prepareGeometry(fineGrid3, domainOrigin, domainExtend);
}
int main(int argc, char* argv[])
@@ -309,9 +119,7 @@ int main(int argc, char* argv[])
singleton::directories().setOutputDir("./tmp/");
OstreamManager clout(std::cout,"main");
- const Vector<T,2> coarseOrigin {0.0, 0.0};
- const Vector<T,2> coarseExtend {lx, ly};
- IndicatorCuboid2D<T> coarseCuboid(coarseExtend, coarseOrigin);
+ IndicatorCuboid2D<T> coarseCuboid(SchaeferTurek::modelExtend, SchaeferTurek::modelOrigin);
Grid2D<T,DESCRIPTOR> coarseGrid(
coarseCuboid,
@@ -321,10 +129,11 @@ int main(int argc, char* argv[])
const Vector<T,2> domainOrigin = coarseGrid.getSuperGeometry().getStatistics().getMinPhysR(0);
const Vector<T,2> domainExtend = coarseGrid.getSuperGeometry().getStatistics().getPhysExtend(0);
- prepareGeometry(coarseGrid, domainOrigin, domainExtend);
- setupRefinement(coarseGrid, domainOrigin, domainExtend);
+ SchaeferTurek::prepareGeometry(coarseGrid, domainOrigin, domainExtend);
+
+ setupRefinement(coarseGrid, domainOrigin, domainExtend, SchaeferTurek::cylinderCenter);
- coarseGrid.forEachGrid(prepareLattice);
+ coarseGrid.forEachGrid(SchaeferTurek::prepareLattice);
clout << "Total number of active cells: " << coarseGrid.getActiveVoxelN() << endl;
clout << "Starting simulation..." << endl;
@@ -335,10 +144,10 @@ int main(int argc, char* argv[])
coarseGrid.getSuperGeometry().getStatistics().getNvoxel());
timer.start();
- Grid2D<T,DESCRIPTOR>& cylinderGrid = coarseGrid.locate({cylinderX, cylinderY});
+ Grid2D<T,DESCRIPTOR>& cylinderGrid = coarseGrid.locate(SchaeferTurek::cylinderCenter);
for (int iT = 0; iT <= coarseGrid.getConverter().getLatticeTime(maxPhysT); ++iT) {
- setBoundaryValues(coarseGrid, iT);
+ SchaeferTurek::setBoundaryValues(coarseGrid, iT);
coarseGrid.collideAndStream();
@@ -347,10 +156,10 @@ int main(int argc, char* argv[])
timer.printStep();
coarseGrid.forEachGrid("cylinder2d", [&](Grid2D<T,DESCRIPTOR>& grid, const std::string& id) {
- getResults(grid, id, iT);
+ SchaeferTurek::getResults(grid, id, iT);
});
- takeMeasurements(cylinderGrid, iT);
+ SchaeferTurek::takeMeasurements(cylinderGrid, iT);
}
}
diff --git a/apps/adrian/cylinder2d/outflow_refinement/cylinder2d.cpp b/apps/adrian/cylinder2d/outflow_refinement/cylinder2d.cpp
index f1e6fa9..5a6725b 100644
--- a/apps/adrian/cylinder2d/outflow_refinement/cylinder2d.cpp
+++ b/apps/adrian/cylinder2d/outflow_refinement/cylinder2d.cpp
@@ -28,8 +28,6 @@
#include "olb2D.hh"
#endif
-#include <vector>
-
using namespace olb;
typedef double T;
@@ -39,243 +37,29 @@ typedef double T;
/// 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 deltaR = cylinderD / N; // coarse lattice spacing
-const T lx = 22*cylinderD + deltaR; // length of the channel
-const T ly = 4.1*cylinderD + deltaR; // height of the channel
-const T cylinderX = 2*cylinderD;
-const T cylinderY = 2*cylinderD + deltaR/2;
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(
- 0.1, // char. phys. length
+ cylinderD, // char. phys. length
1.0, // char. phys. velocity
0.1/Re, // phsy. kinematic viscosity
1.0); // char. phys. density
-void prepareGeometry(Grid2D<T,DESCRIPTOR>& grid, Vector<T,2> origin, Vector<T,2> extend)
-{
- OstreamManager clout(std::cout,"prepareGeometry");
- clout << "Prepare Geometry ..." << std::endl;
-
- auto& converter = grid.getConverter();
- auto& sGeometry = grid.getSuperGeometry();
-
- sGeometry.rename(0,1);
-
- const T physSpacing = converter.getPhysDeltaX();
-
- // Set material number for channel walls
- {
- const Vector<T,2> wallExtend { extend[0]+physSpacing/2, physSpacing/2 };
- const Vector<T,2> wallOrigin = origin - physSpacing/4;
-
- IndicatorCuboid2D<T> lowerWall(wallExtend, wallOrigin);
- sGeometry.rename(1,2,lowerWall);
- }
- {
- const Vector<T,2> wallExtend { extend[0]+physSpacing/2, physSpacing/2 };
- const Vector<T,2> wallOrigin { origin[0]-physSpacing/4, extend[1]-physSpacing/4 };
-
- IndicatorCuboid2D<T> upperWall(wallExtend, wallOrigin);
- sGeometry.rename(1,2,upperWall);
- }
-
- // Set material number for inflow and outflow
- {
- const Vector<T,2> inflowExtend { physSpacing/2, extend[1]+physSpacing/4 };
- const Vector<T,2> inflowOrigin = origin - physSpacing/4;
-
- IndicatorCuboid2D<T> inflow(inflowExtend, inflowOrigin);
- sGeometry.rename(1,3,inflow);
- }
- {
- const Vector<T,2> outflowExtend { physSpacing/2, extend[1]+physSpacing/4 };
- const Vector<T,2> outflowOrigin { extend[0]-physSpacing/4, origin[0]-physSpacing/4 };
-
- IndicatorCuboid2D<T> outflow(outflowExtend, outflowOrigin);
- sGeometry.rename(1,4,outflow);
- }
-
- // Set material number for vertically centered cylinder
- {
- const Vector<T,2> cylinderOrigin = origin + Vector<T,2> {cylinderX, cylinderY};
- IndicatorCircle2D<T> obstacle(cylinderOrigin, cylinderD/2);
- sGeometry.rename(1,5,obstacle);
- }
-
- sGeometry.clean();
- sGeometry.innerClean();
- sGeometry.checkForErrors();
-
- clout << "Prepare Geometry ... OK" << std::endl;
-}
-
-void disableRefinedArea(Grid2D<T,DESCRIPTOR>& coarseGrid,
- RefiningGrid2D<T,DESCRIPTOR>& fineGrid)
-{
- auto& sGeometry = coarseGrid.getSuperGeometry();
- auto refinedOverlap = fineGrid.getRefinedOverlap();
- sGeometry.reset(*refinedOverlap);
-}
-
-void prepareLattice(Grid2D<T,DESCRIPTOR>& grid)
-{
- OstreamManager clout(std::cout,"prepareLattice");
- clout << "Prepare lattice ..." << std::endl;
-
- auto& converter = grid.getConverter();
- auto& sGeometry = grid.getSuperGeometry();
- auto& sLattice = grid.getSuperLattice();
-
- Dynamics<T,DESCRIPTOR>& bulkDynamics = grid.addDynamics(
- std::unique_ptr<Dynamics<T,DESCRIPTOR>>(
- new BGKdynamics<T,DESCRIPTOR>(
- grid.getConverter().getLatticeRelaxationFrequency(),
- instances::getBulkMomenta<T,DESCRIPTOR>())));
-
- sOnLatticeBoundaryCondition2D<T,DESCRIPTOR>& sBoundaryCondition = grid.getOnLatticeBoundaryCondition();
- //createInterpBoundaryCondition2D<T,DESCRIPTOR>(sBoundaryCondition);
- createLocalBoundaryCondition2D<T,DESCRIPTOR>(sBoundaryCondition);
-
- const T omega = converter.getLatticeRelaxationFrequency();
-
- sLattice.defineDynamics(sGeometry, 0, &instances::getNoDynamics<T,DESCRIPTOR>());
- sLattice.defineDynamics(sGeometry, 1, &bulkDynamics); // bulk
- sLattice.defineDynamics(sGeometry, 2, &bulkDynamics); // walls
- sLattice.defineDynamics(sGeometry, 3, &bulkDynamics); // inflow
- sLattice.defineDynamics(sGeometry, 4, &bulkDynamics); // outflow
- sLattice.defineDynamics(sGeometry, 5, &instances::getBounceBack<T,DESCRIPTOR>()); // cylinder
-
- sBoundaryCondition.addVelocityBoundary(sGeometry, 2, omega);
- sBoundaryCondition.addVelocityBoundary(sGeometry, 3, omega);
- sBoundaryCondition.addPressureBoundary(sGeometry, 4, omega);
-
- AnalyticalConst2D<T,T> rho0(1.0);
- AnalyticalConst2D<T,T> u0(0.0, 0.0);
-
- auto materials = sGeometry.getMaterialIndicator({1, 2, 3, 4});
- sLattice.defineRhoU(materials, rho0, u0);
- sLattice.iniEquilibrium(materials, rho0, u0);
-
- sLattice.initialize();
-
- clout << "Prepare lattice ... OK" << std::endl;
- sGeometry.print();
-}
-
-void setBoundaryValues(Grid2D<T,DESCRIPTOR>& grid, int iT)
-{
- auto& converter = grid.getConverter();
- auto& sGeometry = grid.getSuperGeometry();
- auto& sLattice = grid.getSuperLattice();
-
- const int iTmaxStart = converter.getLatticeTime(0.4*16);
- const int iTupdate = 5;
-
- if ( iT % iTupdate == 0 && iT <= iTmaxStart ) {
- PolynomialStartScale<T,T> StartScale(iTmaxStart, 1);
-
- T iTvec[1] { T(iT) };
- T frac[1] { };
- StartScale(frac, iTvec);
-
- const T maxVelocity = converter.getCharLatticeVelocity() * 3./2. * frac[0];
- Poiseuille2D<T> u(sGeometry, 3, maxVelocity, deltaR/2);
-
- sLattice.defineU(sGeometry, 3, u);
- }
-}
-
-void getResults(Grid2D<T,DESCRIPTOR>& grid,
- const std::string& prefix,
- int iT)
-{
- auto& converter = grid.getConverter();
- auto& sLattice = grid.getSuperLattice();
- auto& sGeometry = grid.getSuperGeometry();
-
- SuperVTMwriter2D<T> vtmWriter(prefix);
- SuperLatticePhysVelocity2D<T,DESCRIPTOR> velocity(sLattice, converter);
- SuperLatticePhysPressure2D<T,DESCRIPTOR> pressure(sLattice, converter);
- SuperLatticeGeometry2D<T,DESCRIPTOR> geometry(sLattice, sGeometry);
- SuperLatticeKnudsen2D<T,DESCRIPTOR> knudsen(sLattice);
- vtmWriter.addFunctor(geometry);
- vtmWriter.addFunctor(velocity);
- vtmWriter.addFunctor(pressure);
- vtmWriter.addFunctor(knudsen);
-
- if (iT==0) {
- vtmWriter.createMasterFile();
- }
+#include "../common/model.h"
- vtmWriter.write(iT);
-}
-
-void takeMeasurements(Grid2D<T,DESCRIPTOR>& grid)
+void setupRefinement(Grid2D<T,DESCRIPTOR>& coarseGrid,
+ Vector<T,2> domainOrigin, Vector<T,2> domainExtend)
{
- static T maxDrag = 0.0;
-
- OstreamManager clout(std::cout,"measurement");
-
- auto& sLattice = grid.getSuperLattice();
- auto& sGeometry = grid.getSuperGeometry();
- auto& converter = grid.getConverter();
-
- SuperLatticePhysPressure2D<T,DESCRIPTOR> pressure(sLattice, converter);
- AnalyticalFfromSuperF2D<T> intpolatePressure(pressure, true);
- SuperLatticePhysDrag2D<T,DESCRIPTOR> dragF(sLattice, sGeometry, 5, converter);
-
- const T radiusCylinder = cylinderD/2;
-
- const T point1[2] { cylinderX - radiusCylinder, cylinderY };
- const T point2[2] { cylinderX + radiusCylinder, cylinderY };
-
- T pressureInFrontOfCylinder, pressureBehindCylinder;
- intpolatePressure(&pressureInFrontOfCylinder, point1);
- intpolatePressure(&pressureBehindCylinder, point2);
-
- T pressureDrop = pressureInFrontOfCylinder - pressureBehindCylinder;
- clout << "pressureDrop=" << pressureDrop;
-
- const int input[3] {};
- T drag[dragF.getTargetDim()] {};
- dragF(drag, input);
- if (drag[0] > maxDrag) {
- maxDrag = drag[0];
- };
- clout << "; drag=" << drag[0] << "; maxDrag: " << maxDrag << "; lift=" << drag[1] << endl;
-}
-
-int main(int argc, char* argv[])
-{
- olbInit(&argc, &argv);
- singleton::directories().setOutputDir("./tmp/");
- OstreamManager clout(std::cout,"main");
-
- const Vector<T,2> coarseOrigin {0.0, 0.0};
- const Vector<T,2> coarseExtend {lx, ly};
- IndicatorCuboid2D<T> coarseCuboid(coarseExtend, coarseOrigin);
-
- 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);
-
- prepareGeometry(coarseGrid, domainOrigin, 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);
- prepareGeometry(fineOutflowGrid, domainOrigin, domainExtend);
+ SchaeferTurek::prepareGeometry(fineOutflowGrid, domainOrigin, domainExtend);
{
const Vector<T,2> origin = fineOutflowGrid.getOrigin();
@@ -294,7 +78,7 @@ int main(int argc, char* argv[])
const Vector<T,2> fineOutflowOrigin2 {domainExtend[0]-0.5*cylinderD, 0};
auto& fineOutflowGrid2 = fineOutflowGrid.refine(fineOutflowOrigin2, fineOutflowExtend2, false);
- prepareGeometry(fineOutflowGrid2, domainOrigin, domainExtend);
+ SchaeferTurek::prepareGeometry(fineOutflowGrid2, domainOrigin, domainExtend);
{
const Vector<T,2> origin = fineOutflowGrid2.getOrigin();
@@ -308,8 +92,29 @@ int main(int argc, char* argv[])
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");
- coarseGrid.forEachGrid(prepareLattice);
+ 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;
@@ -320,8 +125,10 @@ int main(int argc, char* argv[])
coarseGrid.getSuperGeometry().getStatistics().getNvoxel());
timer.start();
+ Grid2D<T,DESCRIPTOR>& cylinderGrid = coarseGrid.locate(SchaeferTurek::cylinderCenter);
+
for (int iT = 0; iT <= coarseGrid.getConverter().getLatticeTime(maxPhysT); ++iT) {
- setBoundaryValues(coarseGrid, iT);
+ SchaeferTurek::setBoundaryValues(coarseGrid, iT);
coarseGrid.collideAndStream();
@@ -330,10 +137,10 @@ int main(int argc, char* argv[])
timer.printStep();
coarseGrid.forEachGrid("cylinder2d", [&](Grid2D<T,DESCRIPTOR>& grid, const std::string& id) {
- getResults(grid, id, iT);
+ SchaeferTurek::getResults(grid, id, iT);
});
- takeMeasurements(coarseGrid);
+ SchaeferTurek::takeMeasurements(cylinderGrid, iT);
}
}