From d900d8c794bb9d50f528bc8e72ceb594fbc292c8 Mon Sep 17 00:00:00 2001
From: Adrian Kummerlaender
Date: Thu, 17 Jan 2019 13:37:26 +0100
Subject: Add named types to Grid2D constructor
This allows for readable differentiation between constructor overloads.
---
apps/adrian/cylinder2d/cylinder2d.cpp | 12 ++++-----
apps/adrian/poiseuille2d/poiseuille2d.cpp | 6 ++---
src/refinement/grid2D.h | 26 +++++++++++++++++-
src/refinement/grid2D.hh | 44 +++++++++++++++++++++++++++++--
4 files changed, 76 insertions(+), 12 deletions(-)
diff --git a/apps/adrian/cylinder2d/cylinder2d.cpp b/apps/adrian/cylinder2d/cylinder2d.cpp
index cb0cfc6..739c02c 100644
--- a/apps/adrian/cylinder2d/cylinder2d.cpp
+++ b/apps/adrian/cylinder2d/cylinder2d.cpp
@@ -1,8 +1,8 @@
-/* Lattice Boltzmann sample, written in C++, using the OpenLB
- * library
+/*
+ * Lattice Boltzmann grid refinement sample, written in C++,
+ * using the OpenLB library
*
- * Copyright (C) 2007, 2012 Jonas Latt, Mathias J. Krause
- * Vojtech Cvrcek, Peter Weisbrod
+ * Copyright (C) 2019 Adrian Kummerländer
* E-mail contact: info@openlb.net
* The most recent release of OpenLB can be downloaded at
*
@@ -170,7 +170,7 @@ void getResults(const std::string& prefix,
vtmWriter.createMasterFile();
}
- if (iT%20==0) {
+ if (iT%100==0) {
vtmWriter.write(iT);
}
@@ -192,7 +192,7 @@ int main(int argc, char* argv[])
const Vector coarseExtend {lx, ly};
IndicatorCuboid2D coarseCuboid(coarseExtend, coarseOrigin);
- Grid2D coarseGrid(coarseCuboid, N, baseTau, Re);
+ Grid2D coarseGrid(coarseCuboid, N, RelaxationTime(baseTau), Re);
prepareGeometry(coarseGrid);
const Vector fineExtend {3.0, 1.5};
diff --git a/apps/adrian/poiseuille2d/poiseuille2d.cpp b/apps/adrian/poiseuille2d/poiseuille2d.cpp
index d92934b..19dc4d7 100644
--- a/apps/adrian/poiseuille2d/poiseuille2d.cpp
+++ b/apps/adrian/poiseuille2d/poiseuille2d.cpp
@@ -38,9 +38,9 @@ typedef double T;
const T lx = 4.0; // length of the channel
const T ly = 1.0; // height of the channel
-const int N = 30; // resolution of the model
+const int N = 50; // resolution of the model
const T Re = 100.; // Reynolds number
-const T baseTau = 0.8; // Relaxation time of coarsest grid
+const T uMax = 0.02; // Max lattice speed
const T maxPhysT = 60.; // max. simulation time in s, SI unit
const T physInterval = 0.25; // interval for the convergence check in s
const T residuum = 1e-5; // residuum for the convergence check
@@ -184,7 +184,7 @@ int main(int argc, char* argv[])
const Vector coarseExtend {lx/2, ly};
IndicatorCuboid2D coarseCuboid(coarseExtend, coarseOrigin);
- Grid2D coarseGrid(coarseCuboid, N, baseTau, Re);
+ Grid2D coarseGrid(coarseCuboid, N, LatticeVelocity(uMax), Re);
prepareGeometry(coarseGrid);
const T coarseDeltaX = coarseGrid.getConverter().getPhysDeltaX();
diff --git a/src/refinement/grid2D.h b/src/refinement/grid2D.h
index 9a20544..f58a4ea 100644
--- a/src/refinement/grid2D.h
+++ b/src/refinement/grid2D.h
@@ -43,6 +43,29 @@ template class DESCRIPTOR> class FineCoupler2D;
template class DESCRIPTOR> class CoarseCoupler2D;
template class DESCRIPTOR> class RefiningGrid2D;
+template
+class NamedType {
+private:
+ T _value;
+
+public:
+ explicit NamedType(const T& value):
+ _value(value) {}
+ explicit NamedType(T&& value):
+ _value(std::move(value)) {}
+
+ operator T() const
+ {
+ return _value;
+ }
+};
+
+template
+using RelaxationTime = NamedType;
+
+template
+using LatticeVelocity = NamedType;
+
template class DESCRIPTOR>
class Grid2D {
protected:
@@ -60,7 +83,8 @@ protected:
std::vector>> _coarseCouplers;
public:
- Grid2D(FunctorPtr>&& domainF, int resolution, T tau, int re);
+ Grid2D(FunctorPtr>&& domainF, int resolution, RelaxationTime tau, int re);
+ Grid2D(FunctorPtr>&& domainF, int resolution, LatticeVelocity uMax, int re);
UnitConverter& getConverter();
CuboidGeometry2D& getCuboidGeometry();
diff --git a/src/refinement/grid2D.hh b/src/refinement/grid2D.hh
index 02fe351..2bf2f7f 100644
--- a/src/refinement/grid2D.hh
+++ b/src/refinement/grid2D.hh
@@ -34,7 +34,11 @@ namespace olb {
template class DESCRIPTOR>
-Grid2D::Grid2D(FunctorPtr>&& domainF, int resolution, T tau, int re):
+Grid2D::Grid2D(
+ FunctorPtr>&& domainF,
+ int resolution,
+ RelaxationTime tau,
+ int re):
_domainF(std::move(domainF)),
_converter(new UnitConverterFromResolutionAndRelaxationTime(
resolution, // resolution: number of voxels per charPhysL
@@ -65,6 +69,42 @@ Grid2D::Grid2D(FunctorPtr>&& domainF, int resoluti
_converter->print();
}
+template class DESCRIPTOR>
+Grid2D::Grid2D(
+ FunctorPtr>&& domainF,
+ int resolution,
+ LatticeVelocity velocity,
+ int re):
+ _domainF(std::move(domainF)),
+ _converter(new UnitConverterFromResolutionAndLatticeVelocity(
+ resolution, // resolution: number of voxels per charPhysL
+ velocity, // maxLatticeVelocity
+ T{1}, // charPhysLength: reference length of simulation geometry
+ T{1}, // charPhysVelocity: maximal/highest expected velocity during simulation in __m / s__
+ T{1./re}, // physViscosity: physical kinematic viscosity in __m^2 / s__
+ T{1}, // physDensity: physical density in __kg / m^3__
+ T{1})),
+ _cuboids(new CuboidGeometry2D(
+ *_domainF,
+ _converter->getConversionFactorLength(),
+#ifdef PARALLEL_MODE_MPI
+ singleton::mpi().getSize()
+#else
+ 1
+#endif
+ )),
+ _balancer(new HeuristicLoadBalancer(
+ *_cuboids)),
+ _geometry(new SuperGeometry2D(
+ *_cuboids,
+ *_balancer,
+ 2)),
+ _lattice(new SuperLattice2D(
+ *_geometry))
+{
+ _converter->print();
+}
+
template class DESCRIPTOR>
UnitConverter& Grid2D::getConverter()
{
@@ -209,7 +249,7 @@ RefiningGrid2D::RefiningGrid2D(
Grid2D(
std::unique_ptr>(new IndicatorCuboid2D(extend, origin)),
2*parentGrid.getConverter().getResolution(),
- 2*parentGrid.getConverter().getLatticeRelaxationTime() - 0.5,
+ RelaxationTime(2*parentGrid.getConverter().getLatticeRelaxationTime() - 0.5),
parentGrid.getConverter().getReynoldsNumber()),
_origin(origin),
_extend(extend),
--
cgit v1.2.3