From 94d3e79a8617f88dc0219cfdeedfa3147833719d Mon Sep 17 00:00:00 2001
From: Adrian Kummerlaender
Date: Mon, 24 Jun 2019 14:43:36 +0200
Subject: Initialize at openlb-1-3
---
examples/porousMedia/porousPoiseuille2d/Makefile | 105 +++++
.../porousMedia/porousPoiseuille2d/definitions.mk | 30 ++
examples/porousMedia/porousPoiseuille2d/input.xml | 21 +
examples/porousMedia/porousPoiseuille2d/module.mk | 29 ++
.../porousPoiseuille2d/porousPoiseuille2d.cpp | 478 ++++++++++++++++++++
examples/porousMedia/porousPoiseuille3d/Makefile | 105 +++++
.../porousMedia/porousPoiseuille3d/definitions.mk | 30 ++
examples/porousMedia/porousPoiseuille3d/module.mk | 29 ++
.../porousPoiseuille3d/porousPoiseuille3d.cpp | 484 +++++++++++++++++++++
9 files changed, 1311 insertions(+)
create mode 100644 examples/porousMedia/porousPoiseuille2d/Makefile
create mode 100644 examples/porousMedia/porousPoiseuille2d/definitions.mk
create mode 100644 examples/porousMedia/porousPoiseuille2d/input.xml
create mode 100644 examples/porousMedia/porousPoiseuille2d/module.mk
create mode 100644 examples/porousMedia/porousPoiseuille2d/porousPoiseuille2d.cpp
create mode 100644 examples/porousMedia/porousPoiseuille3d/Makefile
create mode 100644 examples/porousMedia/porousPoiseuille3d/definitions.mk
create mode 100644 examples/porousMedia/porousPoiseuille3d/module.mk
create mode 100644 examples/porousMedia/porousPoiseuille3d/porousPoiseuille3d.cpp
(limited to 'examples/porousMedia')
diff --git a/examples/porousMedia/porousPoiseuille2d/Makefile b/examples/porousMedia/porousPoiseuille2d/Makefile
new file mode 100644
index 0000000..a953954
--- /dev/null
+++ b/examples/porousMedia/porousPoiseuille2d/Makefile
@@ -0,0 +1,105 @@
+# This file is part of the OpenLB library
+#
+# Copyright (C) 2007 Mathias Krause
+# E-mail contact: info@openlb.net
+# The most recent release of OpenLB can be downloaded at
+#
+#
+# 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.
+
+###########################################################################
+## definitions
+
+include definitions.mk
+
+include $(ROOT)/global.mk
+
+OBJECTS := $(foreach file, $(SRC), $(PWD)/$(file:.cpp=.o))
+DEPS := $(foreach file, $(SRC), $(PWD)/$(file:.cpp=.d))
+
+###########################################################################
+## all
+
+all : depend compile link
+
+
+###########################################################################
+## dependencies
+
+depend : $(DEPS)
+
+$(PWD)/%.d : %.cpp
+ @echo Create dependencies for $<
+ @$(SHELL) -ec '$(CXX) -M $(CXXFLAGS) $(IDIR) $< \
+ | sed -e "s!$*\.o!$(PWD)\/$*\.o!1" > .tmpfile; \
+ cp -f .tmpfile $@;'
+
+###########################################################################
+## compile
+
+compile : $(OBJECTS)
+
+$(PWD)/%.o: %.cpp
+ @echo Compile $<
+ $(CXX) $(CXXFLAGS) $(IDIR) -c $< -o $@
+
+###########################################################################
+## clean
+
+clean : cleanrub cleanobj cleandep
+
+cleanrub:
+ @echo Clean rubbish files
+ @rm -f *~ core .tmpfile tmp/*.* $(OUTPUT)
+ @rm -f tmp/vtkData/*.* tmp/vtkData/data/*.* tmp/imageData/*.* tmp/gnuplotData/*.* tmp/gnuplotData/data/*.*
+
+cleanobj:
+ @echo Clean object files
+ @rm -f $(OBJECTS)
+
+cleandep:
+ @echo Clean dependencies files
+ @rm -f $(DEPS)
+
+cleanbuild:
+ @cd $(ROOT); \
+ $(MAKE) cleanlib;
+
+###########################################################################
+## update lib
+
+$(ROOT)/$(LIBDIR)/lib$(LIB).a :
+ @cd $(ROOT); \
+ $(MAKE) all
+
+###########################################################################
+## link
+
+link: $(OUTPUT)
+
+$(OUTPUT): $(OBJECTS) $(ROOT)/$(LIBDIR)/lib$(LIB).a
+ @echo Link $@
+ $(CXX) $(foreach file, $(SRC), $(file:.cpp=.o)) $(LDFLAGS) -L$(ROOT)/$(LIBDIR) -l$(LIB) -lz -o $@
+
+###########################################################################
+## include dependencies
+
+ifneq "$(strip $(wildcard *.d))" ""
+ include $(foreach file,$(DEPS),$(file))
+endif
+
+###########################################################################
+###########################################################################
diff --git a/examples/porousMedia/porousPoiseuille2d/definitions.mk b/examples/porousMedia/porousPoiseuille2d/definitions.mk
new file mode 100644
index 0000000..55a8413
--- /dev/null
+++ b/examples/porousMedia/porousPoiseuille2d/definitions.mk
@@ -0,0 +1,30 @@
+# This file is part of the OpenLB library
+#
+# Copyright (C) 2007 Mathias Krause
+# E-mail contact: info@openlb.net
+# The most recent release of OpenLB can be downloaded at
+#
+#
+# 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.
+
+
+###########################################################################
+###########################################################################
+## DEFINITIONS TO BE CHANGED
+
+ROOT := ../../..
+SRC := porousPoiseuille2d.cpp
+OUTPUT := porousPoiseuille2d
diff --git a/examples/porousMedia/porousPoiseuille2d/input.xml b/examples/porousMedia/porousPoiseuille2d/input.xml
new file mode 100644
index 0000000..d497d40
--- /dev/null
+++ b/examples/porousMedia/porousPoiseuille2d/input.xml
@@ -0,0 +1,21 @@
+
+
+1
+1
+200
+0.8
+.1
+1e-4
+
+
+0.1
+1e-2
+
+
+
+1e-7
+
+
diff --git a/examples/porousMedia/porousPoiseuille2d/module.mk b/examples/porousMedia/porousPoiseuille2d/module.mk
new file mode 100644
index 0000000..1190482
--- /dev/null
+++ b/examples/porousMedia/porousPoiseuille2d/module.mk
@@ -0,0 +1,29 @@
+# This file is part of the OpenLB library
+#
+# Copyright (C) 2017 Markus Mohrhard
+# E-mail contact: info@openlb.net
+# The most recent release of OpenLB can be downloaded at
+#
+#
+# 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.
+
+current_dir := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
+
+include global.mk
+include rules.mk
+include $(addsuffix definitions.mk, $(current_dir))
+
+$(eval $(call sample,$(current_dir)$(OUTPUT),$(addprefix $(current_dir), $(SRC))))
diff --git a/examples/porousMedia/porousPoiseuille2d/porousPoiseuille2d.cpp b/examples/porousMedia/porousPoiseuille2d/porousPoiseuille2d.cpp
new file mode 100644
index 0000000..91f3456
--- /dev/null
+++ b/examples/porousMedia/porousPoiseuille2d/porousPoiseuille2d.cpp
@@ -0,0 +1,478 @@
+/* Lattice Boltzmann sample, written in C++, using the OpenLB
+ * library
+ *
+ * Copyright (C) 2017 Davide Dapelo, Mathias J. Krause
+ * E-mail contact: info@openlb.net
+ * The most recent release of OpenLB can be downloaded at
+ *
+ *
+ * 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.
+ */
+
+/* porousPoiseuille2d.cpp:
+ * Poiseuille flow through porous media.
+ * This implementation is the reproduction of the Guo and Zhao (2002)'s
+ * benchmark example A. The theoretical maximum velocity is calculated
+ * as in Equation 21, and the velocity profile as in Equation 23 of
+ * the original reference.
+ */
+
+#include "olb2D.h"
+#include "olb2D.hh" // use only generic version!
+
+#include
+#include
+#include
+#include
+#include
+
+using namespace olb;
+using namespace olb::descriptors;
+using namespace olb::graphics;
+using namespace std;
+
+typedef double T;
+#define DESCRIPTOR GuoZhaoD2Q9Descriptor
+#define DYNAMICS GuoZhaoBGKdynamics
+//#define DYNAMICS SmagorinskyGuoZhaoBGKdynamics
+
+/// Functional to calculate velocity profile on pipe with porous media.
+template
+class PorousPipe2D : public AnalyticalF2D {
+protected:
+ std::vector axisPoint;
+ std::vector axisDirection;
+ T radius, rFactor, u0;
+
+public:
+ PorousPipe2D(std::vector axisPoint_, std::vector axisDirection_, T radius_, T rFactor_, T u0_);
+ bool operator()(T output[], const T x[]) override;
+};
+
+template
+PorousPipe2D::PorousPipe2D(std::vector axisPoint_, std::vector axisDirection_, T radius_, T rFactor_, T u0_)
+ : AnalyticalF2D(2)
+{
+ this->getName() = "PorousPipe2D";
+ axisPoint.resize(2);
+ axisDirection.resize(2);
+ for (int i = 0; i < 2; ++i) {
+ axisDirection[i] = axisDirection_[i];
+ axisPoint[i] = axisPoint_[i];
+ }
+ radius = radius_;
+ rFactor = rFactor_;
+ u0 = u0_;
+}
+
+template
+bool PorousPipe2D::operator()(T output[], const T x[])
+{
+ output[0] = axisDirection[0]*u0*(cosh(rFactor*radius) - cosh(rFactor*x[1] - rFactor*radius))/(cosh(rFactor*radius) - 1);
+ output[1] = axisDirection[1]*u0*(cosh(rFactor*radius) - cosh(rFactor*x[0] - rFactor*radius))/(cosh(rFactor*radius) - 1);
+
+ return true;
+}
+
+/// Stores geometry information in form of material numbers
+void prepareGeometry(UnitConverter const& converter, T lx, T ly,
+ SuperGeometry2D& superGeometry)
+{
+
+ OstreamManager clout(std::cout,"prepareGeometry");
+ clout << "Prepare Geometry ..." << std::endl;
+
+ superGeometry.rename(0,2);
+
+ std::vector extend(2,T());
+ extend[0] = lx;
+ extend[1] = ly - 1.8*converter.getPhysLength(1);
+ std::vector origin(2,T());
+ origin[1] = 0.9*converter.getPhysLength(1);
+ IndicatorCuboid2D cuboid2(extend, origin);
+
+ superGeometry.rename(2,1,cuboid2);
+
+ /// Removes all not needed boundary voxels outside the surface
+ superGeometry.clean();
+ /// Removes all not needed boundary voxels inside the surface
+ superGeometry.innerClean();
+ superGeometry.checkForErrors();
+
+ superGeometry.print();
+
+ clout << "Prepare Geometry ... OK" << std::endl;
+}
+
+/// Set up the geometry of the simulation
+void prepareLattice(UnitConverter const& converter, T lx, T ly,
+ T epsilonIn, T KIn, T bodyForceIn,
+ SuperLattice2D& sLattice,
+ Dynamics& bulkDynamics,
+ sOnLatticeBoundaryCondition2D& sBoundaryCondition,
+ SuperGuoZhaoInstantiator2D >& sGuoZhaoInstantiator,
+ SuperGeometry2D& superGeometry )
+{
+
+ OstreamManager clout(std::cout,"prepareLattice");
+ clout << "Prepare Lattice ..." << std::endl;
+
+ T omega = converter.getLatticeRelaxationFrequency();
+
+ /// Material=0 -->do nothing
+ sLattice.defineDynamics(superGeometry, 0, &instances::getNoDynamics());
+
+ /// Material=1 -->bulk dynamics
+ sLattice.defineDynamics(superGeometry, 1, &bulkDynamics);
+
+ /// Material=2 -->bulk dynamics
+ sLattice.defineDynamics(superGeometry, 2, &bulkDynamics);
+
+ /// Setting of the boundary conditions
+ sBoundaryCondition.addVelocityBoundary(superGeometry, 2, omega);
+
+ /// Initial conditions
+ std::vector epsilonValue(1, epsilonIn);
+ AnalyticalConst2D epsilon(epsilonValue);
+
+ std::vector KValue(1, KIn);
+ AnalyticalConst2D K(KValue);
+
+ std::vector bodyForceValue (2, (T)0);
+ bodyForceValue[0] = bodyForceIn;
+ AnalyticalConst2D bodyForce(bodyForceValue);
+
+ // Initialize porosity
+ sGuoZhaoInstantiator.defineEpsilon(superGeometry, 1, epsilon);
+ sGuoZhaoInstantiator.defineEpsilon(superGeometry, 2, epsilon);
+
+ sGuoZhaoInstantiator.defineK(converter, superGeometry, 1, K);
+ sGuoZhaoInstantiator.defineK(converter, superGeometry, 2, K);
+
+ sGuoZhaoInstantiator.defineNu(converter, superGeometry, 1);
+ sGuoZhaoInstantiator.defineNu(converter, superGeometry, 2);
+
+ sGuoZhaoInstantiator.defineBodyForce(converter, superGeometry, 1, bodyForce);
+ sGuoZhaoInstantiator.defineBodyForce(converter, superGeometry, 2, bodyForce);
+
+ /// Make the lattice ready for simulation
+ clout << "Ready to initialize the lattice..." << std::endl;
+ sLattice.initialize();
+
+ clout << "Prepare Lattice ... OK" << std::endl;
+}
+
+/// Compute error norms
+void error( SuperGeometry2D& superGeometry,
+ SuperLattice2D& sLattice,
+ UnitConverter const& converter,
+ Dynamics& bulkDynamics,
+ AnalyticalF2D& uSol) {
+
+ OstreamManager clout( std::cout,"error" );
+
+ int input[1] = { };
+ T result[1] = { };
+
+ SuperLatticePhysVelocity2D u( sLattice,converter );
+ auto indicatorF = superGeometry.getMaterialIndicator(1);
+
+ // velocity error
+ SuperAbsoluteErrorL1Norm2D absVelocityErrorNormL1(u, uSol, indicatorF);
+ absVelocityErrorNormL1(result, input);
+ clout << "velocity-L1-error(abs)=" << result[0];
+ SuperRelativeErrorL1Norm2D relVelocityErrorNormL1(u, uSol, indicatorF);
+ relVelocityErrorNormL1(result, input);
+ clout << "; velocity-L1-error(rel)=" << result[0] << std::endl;
+
+ SuperAbsoluteErrorL2Norm2D absVelocityErrorNormL2(u, uSol, indicatorF);
+ absVelocityErrorNormL2(result, input);
+ clout << "velocity-L2-error(abs)=" << result[0];
+ SuperRelativeErrorL2Norm2D relVelocityErrorNormL2(u, uSol, indicatorF);
+ relVelocityErrorNormL2(result, input);
+ clout << "; velocity-L2-error(rel)=" << result[0] << std::endl;
+
+ SuperAbsoluteErrorLinfNorm2D absVelocityErrorNormLinf(u, uSol, indicatorF);
+ absVelocityErrorNormLinf(result, input);
+ clout << "velocity-Linf-error(abs)=" << result[0] << std::endl;
+}
+
+/// Output to console and files
+void getResults(SuperLattice2D& sLattice, Dynamics& bulkDynamics,
+ UnitConverter const& converter, T lx, T ly, T G, T K, T nu, T epsilon, T maxPhysT, int iT, int numOfIterations,
+ SuperGeometry2D& superGeometry, Timer& timer, bool hasConverged)
+{
+
+ OstreamManager clout(std::cout,"getResults");
+
+ SuperVTMwriter2D vtkWriter("porousPoiseuille2d");
+ SuperLatticePhysVelocity2D velocity(sLattice, converter);
+ SuperLatticePhysPressure2D pressure(sLattice, converter);
+// SuperLatticeEpsilon2D epsilonVTM(sLattice, converter);
+// SuperLatticePhysK2D KVTM(sLattice, converter);
+// SuperLatticePhysBodyForce2D bodyForce(sLattice, converter);
+ vtkWriter.addFunctor( velocity );
+ vtkWriter.addFunctor( pressure );
+// vtkWriter.addFunctor( epsilonVTM );
+// vtkWriter.addFunctor( KVTM );
+// vtkWriter.addFunctor( bodyForce );
+
+ const int vtkIter = converter.getLatticeTime(maxPhysT/numOfIterations);
+ const int statIter = converter.getLatticeTime(maxPhysT/numOfIterations);
+
+ static Gnuplot gplot_uCentre( "uCentre" );
+ static Gnuplot gplot_profile( "profile" );
+
+ if (iT==0) {
+ /// Writes the geometry, cuboid no. and rank no. as vti file for visualization
+ SuperLatticeGeometry2D geometry(sLattice, superGeometry);
+ SuperLatticeCuboid2D cuboid(sLattice);
+ SuperLatticeRank2D rank(sLattice);
+ superGeometry.rename(0,2);
+ vtkWriter.write(geometry);
+ vtkWriter.write(cuboid);
+ vtkWriter.write(rank);
+
+ vtkWriter.createMasterFile();
+ }
+
+ /// Writes the vtk files and profile text file
+ T Ly = converter.getLatticeLength(ly);
+ AnalyticalFfromSuperF2D intpolateVelocity( velocity, true );
+ T centre[2] = {converter.getCharPhysLength()/2, converter.getCharPhysLength()/2};
+ T uCentre[2];
+ intpolateVelocity(uCentre, centre);
+ T r = sqrt(epsilon/K);
+ T dx = converter.getPhysDeltaX();
+ const T radius = ly/2.;
+ std::vector axisPoint(2,T());
+ axisPoint[0] = lx/2.;
+ axisPoint[1] = ly/2.;
+ std::vector axisDirection(2,T());
+ axisDirection[0] = 1;
+ axisDirection[1] = 0;
+ PorousPipe2D uSol(axisPoint, axisDirection, radius, r, uCentre[0]);
+
+
+ if (iT%vtkIter==0 || hasConverged) {
+ vtkWriter.write(iT);
+
+ SuperEuklidNorm2D normVel(velocity);
+ BlockReduction2D2D planeReduction( normVel, 600, BlockDataSyncMode::ReduceOnly );
+ // write output of velocity as JPEG
+ heatmap::write(planeReduction, iT);
+
+ ofstream *ofile = nullptr;
+ if (singleton::mpi().isMainProcessor()) {
+ ofile = new ofstream((singleton::directories().getLogOutDir()+"centerVel.dat").c_str());
+ }
+ for (int iY=0; iY<=Ly; ++iY) {
+ T point[2]= {T(),T()};
+ point[0] = lx/2.;
+ point[1] = (T)iY*converter.getPhysLength(1);
+ T analytical[2] = {T(),T()};
+ uSol(analytical,point);
+ SuperLatticePhysVelocity2D velocity(sLattice, converter);
+ AnalyticalFfromSuperF2D intpolateVelocity(velocity, true);
+ T numerical[2] = {T(),T()};
+ intpolateVelocity(numerical,point);
+ if (singleton::mpi().isMainProcessor()) {
+ *ofile << iY*dx << " " << analytical[0]
+ << " " << numerical[0] << "\n";
+ if ( iT == .8*converter.getLatticeTime( maxPhysT ) ) {
+// if ( iT == converter.numTimeSteps( maxPhysT )-1 ) {
+ gplot_profile.setData( point[1], {numerical[0], analytical[0]}, {"Numerical profile", "Analytical profile"}, "bottom right" );
+ gplot_profile.writePNG();
+ }
+ }
+ }
+ delete ofile;
+ }
+
+ /// Writes output on the console
+ if (iT%statIter==0 || hasConverged) {
+ /// Timer console output
+ timer.update(iT);
+ timer.printStep();
+
+ /// Lattice statistics console output
+ sLattice.getStatistics().print(iT,converter.getPhysTime(iT));
+
+ /// Error norms
+ error(superGeometry, sLattice, converter, bulkDynamics, uSol);
+
+ AnalyticalFfromSuperF2D intpolatePressure( pressure, true );
+ AnalyticalFfromSuperF2D intpolateVelocity( velocity, true );
+ T centre[2] = {converter.getCharPhysLength()/2, converter.getCharPhysLength()/2};
+ T uCentre[2];
+ intpolateVelocity(uCentre, centre);
+
+ T uMaxMeas = sLattice.getStatistics().getMaxU() / converter.getCharLatticeVelocity();
+ T uMaxTheo = G*K/nu*(1.-1./cosh(converter.getCharPhysLength()/2 * sqrt(epsilon/K)));
+ clout << "uMaxTheo=" << uMaxTheo
+ << "; uMaxMeas=" << uMaxMeas
+ << "; uCentre=" << uCentre[0]
+ << std::endl;
+
+ gplot_uCentre.setData( converter.getPhysTime( iT ), uCentre[0], "Centre velocity", "bottom right" );
+ gplot_uCentre.writePNG( iT, maxPhysT );
+ }
+}
+
+int main(int argc, char* argv[])
+{
+
+ /// === 1st Step: Initialization ===
+ olbInit(&argc, &argv);
+ singleton::directories().setOutputDir("./tmp/");
+ OstreamManager clout(std::cout,"main");
+ // display messages from every single mpi process
+ //clout.setMultiOutput(true);
+
+ // Parameters for the simulation setup
+ int nx; // length of the channel
+ int ny; // height of the channel
+ int N; // resolution of the model
+ T tau; // Relaxation time
+ T Re; // Reynolds number
+ T Da; // Darcy number
+
+ T epsilon; // Porosity (non-dimensional)
+ T K; // Permeability (SI units)
+
+ T maxPhysT; // max. simulation time in s, SI unit
+ int numOfIterations; // number of iterations reported in paraview-Gnuplot.
+ T residuum;
+
+ string fName("input.xml");
+ XMLreader config(fName);
+
+ config["setup"]["nx"].read(nx);
+ config["setup"]["ny"].read(ny);
+ config["setup"]["tau"].read(tau);
+ config["setup"]["N"].read(N);
+ config["setup"]["Da"].read(Da);
+ config["setup"]["Re"].read(Re);
+ config["porous"]["epsilon"].read(epsilon);
+ config["porous"]["K"].read(K);
+ config["time"]["maxPhysT"].read(maxPhysT);
+ config["time"]["numOfIterations"].read(numOfIterations);
+ config["convergence"]["residuum"].read(residuum);
+
+ T charL = sqrt(K/Da);
+ T lx = nx*charL;
+ T ly = ny*charL;
+
+ //T latticeU = Re*(tau-(T).5)/((T)3*N);
+ T charU = (T)1.;
+ T bodyForceValue = charU*charU*charL / ( Re*K*((T)1. - (T)1./cosh(charL/(T)2 * sqrt(epsilon/K))) );
+ T nu = bodyForceValue*K/charU*((T)1. - (T)1./cosh(charL/(T)2 * sqrt(epsilon/K)));
+
+ UnitConverterFromResolutionAndRelaxationTime const converter(
+ int {N}, // resolution: number of voxels per charPhysL
+ (T) tau, // latticeRelaxationTime: relaxation time, have to be greater than 0.5!
+ (T) charL, // charPhysLength: reference length of simulation geometry
+ (T) charU, // charPhysVelocity: maximal/highest expected velocity during simulation in __m / s__
+ (T) nu, // physViscosity: physical kinematic viscosity in __m^2 / s__
+ (T) 1.0 // physDensity: physical density in __kg / m^3__
+ );
+ // Prints the converter log as console output
+ converter.print();
+ // Writes the converter log in a file
+ converter.write("porousPoiseuille2d");
+
+ /// === 2nd Step: Prepare Geometry ===
+ std::vector extend(2,T());
+ extend[0] = lx;
+ extend[1] = ly;
+ std::vector origin(2,T());
+ IndicatorCuboid2D cuboid(extend, origin);
+
+ /// Instantiation of a cuboidGeometry with weights
+#ifdef PARALLEL_MODE_MPI
+ const int noOfCuboids = singleton::mpi().getSize();
+#else
+ const int noOfCuboids = 7;
+#endif
+ CuboidGeometry2D cuboidGeometry(cuboid, converter.getPhysDeltaX(), noOfCuboids);
+
+ /// Periodic boundaries in x-direction
+ cuboidGeometry.setPeriodicity(true, false);
+
+ /// Instantiation of a loadBalancer
+ HeuristicLoadBalancer loadBalancer(cuboidGeometry);
+
+ /// Instantiation of a superGeometry
+ SuperGeometry2D superGeometry(cuboidGeometry, loadBalancer, 2);
+
+ prepareGeometry(converter, lx, ly, superGeometry);
+
+ /// === 3rd Step: Prepare Lattice ===
+ SuperLattice2D sLattice(superGeometry);
+
+ DYNAMICS bulkDynamics (
+ converter.getLatticeRelaxationFrequency(),
+ instances::getBulkMomenta()
+ );
+
+ SuperGuoZhaoInstantiator2D > sGuoZhaoInstantiator(sLattice);
+
+ // choose between local and non-local boundary condition
+ sOnLatticeBoundaryCondition2D sBoundaryCondition(sLattice);
+ createInterpBoundaryCondition2D > (sBoundaryCondition);
+
+ prepareLattice(converter, lx, ly, epsilon, K, bodyForceValue, sLattice, bulkDynamics, sBoundaryCondition, sGuoZhaoInstantiator, superGeometry);
+
+ SuperExternal2D externalForce(superGeometry, sLattice, 2);
+ SuperExternal2D externalEpsilon(superGeometry, sLattice, 2);
+ SuperExternal2D externalK(superGeometry, sLattice, 2);
+ SuperExternal2D externalNu(superGeometry, sLattice, 2);
+ SuperExternal2D externalBodyForce(superGeometry, sLattice, 2);
+
+ /// === 4th Step: Main Loop with Timer ===
+ clout << "starting simulation..." << endl;
+ Timer timer(converter.getLatticeTime(maxPhysT), superGeometry.getStatistics().getNvoxel() );
+ util::ValueTracer converge( converter.getLatticeTime(maxPhysT/numOfIterations), residuum );
+ timer.start();
+
+ for (int iT = 0; iT < converter.getLatticeTime(maxPhysT); ++iT) {
+ if ( converge.hasConverged() ) {
+ clout << "Simulation converged." << endl;
+ getResults(sLattice, bulkDynamics, converter, lx, ly, bodyForceValue, K, converter.getPhysViscosity(), epsilon, maxPhysT, iT, numOfIterations, superGeometry, timer, converge.hasConverged() );
+ break;
+ }
+
+ /// === 5th Step: Definition of Initial and Boundary Conditions ===
+ // in this application no boundary conditions have to be adjusted
+
+ /// === 6th Step: Collide and Stream Execution ===
+ sLattice.collideAndStream();
+
+ externalForce.communicate();
+ externalEpsilon.communicate();
+ externalK.communicate();
+ externalNu.communicate();
+ externalBodyForce.communicate();
+
+ /// === 7th Step: Computation and Output of the Results ===
+ getResults(sLattice, bulkDynamics, converter, lx, ly, bodyForceValue, K, converter.getPhysViscosity(), epsilon, maxPhysT, iT, numOfIterations, superGeometry, timer, converge.hasConverged() );
+ converge.takeValue( sLattice.getStatistics().getAverageEnergy(), true );
+ }
+
+ timer.stop();
+ timer.printSummary();
+}
+
diff --git a/examples/porousMedia/porousPoiseuille3d/Makefile b/examples/porousMedia/porousPoiseuille3d/Makefile
new file mode 100644
index 0000000..a953954
--- /dev/null
+++ b/examples/porousMedia/porousPoiseuille3d/Makefile
@@ -0,0 +1,105 @@
+# This file is part of the OpenLB library
+#
+# Copyright (C) 2007 Mathias Krause
+# E-mail contact: info@openlb.net
+# The most recent release of OpenLB can be downloaded at
+#
+#
+# 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.
+
+###########################################################################
+## definitions
+
+include definitions.mk
+
+include $(ROOT)/global.mk
+
+OBJECTS := $(foreach file, $(SRC), $(PWD)/$(file:.cpp=.o))
+DEPS := $(foreach file, $(SRC), $(PWD)/$(file:.cpp=.d))
+
+###########################################################################
+## all
+
+all : depend compile link
+
+
+###########################################################################
+## dependencies
+
+depend : $(DEPS)
+
+$(PWD)/%.d : %.cpp
+ @echo Create dependencies for $<
+ @$(SHELL) -ec '$(CXX) -M $(CXXFLAGS) $(IDIR) $< \
+ | sed -e "s!$*\.o!$(PWD)\/$*\.o!1" > .tmpfile; \
+ cp -f .tmpfile $@;'
+
+###########################################################################
+## compile
+
+compile : $(OBJECTS)
+
+$(PWD)/%.o: %.cpp
+ @echo Compile $<
+ $(CXX) $(CXXFLAGS) $(IDIR) -c $< -o $@
+
+###########################################################################
+## clean
+
+clean : cleanrub cleanobj cleandep
+
+cleanrub:
+ @echo Clean rubbish files
+ @rm -f *~ core .tmpfile tmp/*.* $(OUTPUT)
+ @rm -f tmp/vtkData/*.* tmp/vtkData/data/*.* tmp/imageData/*.* tmp/gnuplotData/*.* tmp/gnuplotData/data/*.*
+
+cleanobj:
+ @echo Clean object files
+ @rm -f $(OBJECTS)
+
+cleandep:
+ @echo Clean dependencies files
+ @rm -f $(DEPS)
+
+cleanbuild:
+ @cd $(ROOT); \
+ $(MAKE) cleanlib;
+
+###########################################################################
+## update lib
+
+$(ROOT)/$(LIBDIR)/lib$(LIB).a :
+ @cd $(ROOT); \
+ $(MAKE) all
+
+###########################################################################
+## link
+
+link: $(OUTPUT)
+
+$(OUTPUT): $(OBJECTS) $(ROOT)/$(LIBDIR)/lib$(LIB).a
+ @echo Link $@
+ $(CXX) $(foreach file, $(SRC), $(file:.cpp=.o)) $(LDFLAGS) -L$(ROOT)/$(LIBDIR) -l$(LIB) -lz -o $@
+
+###########################################################################
+## include dependencies
+
+ifneq "$(strip $(wildcard *.d))" ""
+ include $(foreach file,$(DEPS),$(file))
+endif
+
+###########################################################################
+###########################################################################
diff --git a/examples/porousMedia/porousPoiseuille3d/definitions.mk b/examples/porousMedia/porousPoiseuille3d/definitions.mk
new file mode 100644
index 0000000..6dcc037
--- /dev/null
+++ b/examples/porousMedia/porousPoiseuille3d/definitions.mk
@@ -0,0 +1,30 @@
+# This file is part of the OpenLB library
+#
+# Copyright (C) 2007 Mathias Krause
+# E-mail contact: info@openlb.net
+# The most recent release of OpenLB can be downloaded at
+#
+#
+# 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.
+
+
+###########################################################################
+###########################################################################
+## DEFINITIONS TO BE CHANGED
+
+ROOT := ../../..
+SRC := porousPoiseuille3d.cpp
+OUTPUT := porousPoiseuille3d
diff --git a/examples/porousMedia/porousPoiseuille3d/module.mk b/examples/porousMedia/porousPoiseuille3d/module.mk
new file mode 100644
index 0000000..1190482
--- /dev/null
+++ b/examples/porousMedia/porousPoiseuille3d/module.mk
@@ -0,0 +1,29 @@
+# This file is part of the OpenLB library
+#
+# Copyright (C) 2017 Markus Mohrhard
+# E-mail contact: info@openlb.net
+# The most recent release of OpenLB can be downloaded at
+#
+#
+# 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.
+
+current_dir := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
+
+include global.mk
+include rules.mk
+include $(addsuffix definitions.mk, $(current_dir))
+
+$(eval $(call sample,$(current_dir)$(OUTPUT),$(addprefix $(current_dir), $(SRC))))
diff --git a/examples/porousMedia/porousPoiseuille3d/porousPoiseuille3d.cpp b/examples/porousMedia/porousPoiseuille3d/porousPoiseuille3d.cpp
new file mode 100644
index 0000000..01a7a62
--- /dev/null
+++ b/examples/porousMedia/porousPoiseuille3d/porousPoiseuille3d.cpp
@@ -0,0 +1,484 @@
+/* Lattice Boltzmann sample, written in C++, using the OpenLB
+ * library
+ *
+ * Copyright (C) 2019 Fabian Klemens, Marc Haußmann
+ * Mathias J. Krause, Vojtech Cvrcek, Peter Weisbrod
+ * E-mail contact: info@openlb.net
+ * The most recent release of OpenLB can be downloaded at
+ *
+ *
+ * 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.
+ */
+
+/* porousPoiseuille3d.cpp:
+ * This example examines a 3D Poseuille flow with porous media.
+ * Two porous media LB methods can be used here:
+ * Spaid and Phelan (doi:10.1063/1.869392), or
+ * Guo and Zhao (doi:10.1103/PhysRevE.66.036304)
+ */
+
+
+#include "olb3D.h"
+#include "olb3D.hh"
+
+#include
+#include
+#include
+#include
+#include
+
+using namespace olb;
+
+typedef double T;
+
+#define SPAID_PHELAN
+//#define GUO_ZHAO
+
+T epsilon = 1.;
+T K = 1e-3;
+
+#ifdef SPAID_PHELAN
+#define DESCRIPTOR descriptors::PorousD3Q19Descriptor
+#elif defined GUO_ZHAO
+#define DESCRIPTOR descriptors::GuoZhaoD3Q19Descriptor
+#endif
+
+
+// Parameters for the simulation setup
+const T length = 2.; // length of the pie
+const T diameter = 1.; // diameter of the pipe
+int N = 21; // resolution of the model
+const T physU = 1.; // physical velocity
+const T Re = 1.; // Reynolds number
+const T physRho = 1.; // physical density
+const T tau = 0.8; // lattice relaxation time
+const T maxPhysT = 20.; // max. simulation time in s, SI unit
+const T residuum = 1e-5; // residuum for the convergence check
+const T tuner = 0.97; // for partialSlip only: 0->bounceBack, 1->freeSlip
+
+// Scaled Parameters
+const T radius = diameter/2.; // radius of the pipe
+const T physInterval = 0.0125*maxPhysT; // interval for the convergence check in s
+
+
+// Stores geometry information in form of material numbers
+void prepareGeometry( UnitConverter const& converter,
+ SuperGeometry3D& superGeometry )
+{
+
+ OstreamManager clout(std::cout, "prepareGeometry");
+
+ clout << "Prepare Geometry ..." << std::endl;
+
+ Vector center0(-converter.getPhysDeltaX() * 0.2, radius, radius);
+ Vector center1(length, radius, radius);
+ IndicatorCylinder3D pipe(center0, center1, radius);
+
+ superGeometry.rename(0, 2);
+
+ superGeometry.rename(2, 1, pipe);
+
+ Vector origin(0, radius, radius);
+ Vector extend = origin;
+
+ // Set material number for inflow
+ origin[0] = -converter.getPhysDeltaX() * 2;
+ extend[0] = converter.getPhysDeltaX() * 2;
+ IndicatorCylinder3D inflow(origin, extend, radius);
+ superGeometry.rename(2, 3, 1, inflow);
+
+ // Set material number for outflow
+ origin[0] = length - 2 * converter.getPhysDeltaX();
+ extend[0] = length + 2 * converter.getPhysDeltaX();
+ IndicatorCylinder3D outflow(extend, origin, radius);
+ superGeometry.rename(2, 4, 1, outflow);
+
+ // Removes all not needed boundary voxels outside the surface
+ superGeometry.clean();
+ // Removes all not needed boundary voxels inside the surface
+ superGeometry.innerClean();
+ superGeometry.checkForErrors();
+
+ superGeometry.print();
+
+ clout << "Prepare Geometry ... OK" << std::endl;
+}
+
+// Set up the geometry of the simulation
+void prepareLattice(SuperLattice3D& sLattice,
+ UnitConverterconst& converter,
+ Dynamics& bulkDynamics,
+ sOnLatticeBoundaryCondition3D& onBc,
+ sOffLatticeBoundaryCondition3D& offBc,
+ SuperGeometry3D& superGeometry)
+{
+
+ OstreamManager clout( std::cout,"prepareLattice" );
+ clout << "Prepare Lattice ..." << std::endl;
+
+ const T omega = converter.getLatticeRelaxationFrequency();
+
+ // Material=0 -->do nothing
+ sLattice.defineDynamics( superGeometry, 0, &instances::getNoDynamics() );
+
+ // Material=1 -->bulk dynamics
+ sLattice.defineDynamics( superGeometry, 1, &bulkDynamics );
+
+ Vector center0(0, radius, radius);
+ Vector center1(length, radius, radius);
+
+ std::vector origin = { length, radius, radius};
+ std::vector axis = { 1, 0, 0 };
+
+ CirclePoiseuille3D poiseuilleU(origin, axis, converter.getCharLatticeVelocity(), radius);
+
+ AnalyticalConst3D zero(0.);
+ AnalyticalConst3D one(1.);
+
+ T nu = (tau-0.5)/3.;
+ T h = converter.getPhysDeltaX();
+#ifdef SPAID_PHELAN
+ T d = 1. - (h*h*nu*tau/K);
+ clout << "Lattice Porosity: " << d << std::endl;
+ clout << "Kmin: " << h*h*nu*tau << std::endl;
+ if (K < h*h*nu*tau) {
+ clout << "WARNING: Chosen K is too small!" << std::endl;
+ exit(1);
+ }
+#endif
+
+#ifdef SPAID_PHELAN
+ AnalyticalConst3D porosity(d);
+ sLattice.defineField(superGeometry, 1, porosity);
+#elif defined GUO_ZHAO
+ AnalyticalConst3D Nu(nu);
+ AnalyticalConst3D k(K/(h*h));
+ AnalyticalConst3D eps(epsilon);
+
+ sLattice.defineField(superGeometry, 1, eps);
+ sLattice.defineField(superGeometry, 1, 1, Nu);
+ sLattice.defineField(superGeometry, 1, k);
+#endif
+
+ sLattice.defineDynamics(superGeometry, 2, &instances::getNoDynamics() );
+
+ center0[0] -= 0.5*converter.getPhysDeltaX();
+ center1[0] += 0.5*converter.getPhysDeltaX();
+ IndicatorCylinder3D pipe(center0, center1, radius);
+ offBc.addZeroVelocityBoundary(superGeometry, 2, pipe);
+
+ sLattice.defineDynamics( superGeometry, 2, &bulkDynamics );
+ onBc.addVelocityBoundary( superGeometry, 2, omega );
+
+ sLattice.defineDynamics(superGeometry, 3, &instances::getNoDynamics() );
+ offBc.addVelocityBoundary(superGeometry, 3, pipe);
+ offBc.defineU(superGeometry,3,poiseuilleU);
+
+ // Material=4 -->bulk dynamics
+ sLattice.defineDynamics( superGeometry, 4, &bulkDynamics );
+ onBc.addPressureBoundary( superGeometry, 4, omega );
+
+ // Initial conditions
+ T p0 = 4. * converter.getPhysViscosity() * converter.getCharPhysVelocity() * length / (radius * radius);
+
+ p0 = converter.getLatticePressure(p0);
+ AnalyticalLinear3D rho(-p0 / length * descriptors::invCs2(), 0, 0, p0 * descriptors::invCs2() + 1);
+
+ std::vector velocity(3, T());
+ AnalyticalConst3D uF(velocity);
+
+ // Initialize all values of distribution functions to their local equilibrium
+ sLattice.defineRhoU(superGeometry, 0, rho, uF);
+ sLattice.iniEquilibrium(superGeometry, 0, rho, uF);
+ sLattice.defineRhoU(superGeometry, 1, rho, poiseuilleU);
+ sLattice.iniEquilibrium(superGeometry, 1, rho, poiseuilleU);
+ sLattice.defineRhoU(superGeometry, 2, rho, poiseuilleU);
+ sLattice.iniEquilibrium(superGeometry, 2, rho, poiseuilleU);
+ sLattice.defineRhoU(superGeometry, 3, rho, poiseuilleU);
+ sLattice.iniEquilibrium(superGeometry, 3, rho, poiseuilleU);
+ sLattice.defineRhoU(superGeometry, 4, rho, poiseuilleU);
+ sLattice.iniEquilibrium(superGeometry, 4, rho, poiseuilleU);
+
+ // Make the lattice ready for simulation
+ sLattice.initialize();
+
+ clout << "Prepare Lattice ... OK" << std::endl;
+}
+
+/// Compute error norms
+void error( SuperGeometry3D& superGeometry,
+ SuperLattice3D& sLattice,
+ UnitConverter const& converter,
+ AnalyticalF3D& porVel) {
+
+ OstreamManager clout( std::cout,"error" );
+
+
+ int tmp[]= { };
+ T result[2]= { };
+ auto indicatorF = superGeometry.getMaterialIndicator(1);
+ SuperLatticePhysVelocity3D u( sLattice, converter );
+
+ SuperAbsoluteErrorL1Norm3D absVelocityErrorNormL1(u, porVel, indicatorF);
+ absVelocityErrorNormL1(result, tmp);
+ clout << "velocity-L1-error(abs)=" << result[0];
+ SuperRelativeErrorL1Norm3D relVelocityErrorNormL1(u, porVel, indicatorF);
+ relVelocityErrorNormL1(result, tmp);
+ clout << "; velocity-L1-error(rel)=" << result[0] << std::endl;
+
+ SuperAbsoluteErrorL2Norm3D absVelocityErrorNormL2(u, porVel, indicatorF);
+ absVelocityErrorNormL2(result, tmp);
+ clout << "velocity-L2-error(abs)=" << result[0];
+ SuperRelativeErrorL2Norm3D relVelocityErrorNormL2(u, porVel, indicatorF);
+ relVelocityErrorNormL2(result, tmp);
+ clout << "; velocity-L2-error(rel)=" << result[0] << std::endl;
+
+ SuperAbsoluteErrorLinfNorm3D absVelocityErrorNormLinf(u, porVel, indicatorF);
+ absVelocityErrorNormLinf(result, tmp);
+ clout << "velocity-Linf-error(abs)=" << result[0];
+ SuperRelativeErrorLinfNorm3D relVelocityErrorNormLinf(u, porVel, indicatorF);
+ relVelocityErrorNormLinf(result, tmp);
+ clout << "; velocity-Linf-error(rel)=" << result[0] << std::endl;
+}
+
+
+// Output to console and files
+void getResults( SuperLattice3D& sLattice, Dynamics& bulkDynamics,
+ UnitConverter const& converter, int iT,
+ SuperGeometry3D& superGeometry, Timer& timer, bool hasConverged )
+{
+
+ OstreamManager clout( std::cout,"getResults" );
+
+ SuperVTMwriter3D vtmWriter( "porousPoiseuille3d" );
+ SuperLatticePhysVelocity3D velocity( sLattice, converter );
+ SuperLatticePhysPressure3D pressure( sLattice, converter );
+ vtmWriter.addFunctor( velocity );
+ vtmWriter.addFunctor( pressure );
+
+ const int vtmIter = converter.getLatticeTime( maxPhysT/20. );
+ const int statIter = converter.getLatticeTime( maxPhysT/20. );
+
+ if ( iT==0 ) {
+ // Writes the geometry, cuboid no. and rank no. as vti file for visualization
+ SuperLatticeGeometry3D geometry( sLattice, superGeometry );
+ SuperLatticeCuboid3D cuboid( sLattice );
+ SuperLatticeRank3D rank( sLattice );
+
+ vtmWriter.write( geometry );
+ vtmWriter.write( cuboid );
+ vtmWriter.write( rank );
+
+ vtmWriter.createMasterFile();
+ }
+
+ // Writes the vtm files and profile text file
+ if ( iT%vtmIter==0 || hasConverged ) {
+ vtmWriter.write( iT );
+ }
+
+
+ // Writes output on the console
+ if ( iT%statIter==0 || hasConverged ) {
+ // Timer console output
+ timer.update( iT );
+ timer.printStep();
+
+ // Lattice statistics console output
+ sLattice.getStatistics().print( iT,converter.getPhysTime( iT ) );
+
+ // Error norms
+ AnalyticalFfromSuperF3D intpolatePressure( pressure, true );
+
+ T point1[3] = {0, radius, radius};
+ T point2[3] = {0, radius, radius};
+
+ point1[0] = length*0.5 - length*0.01;
+ point2[0] = length*0.5 + length*0.01;
+
+ T p1, p2;
+ intpolatePressure( &p1,point1 );
+ intpolatePressure( &p2,point2 );
+
+ clout << "pressure1=" << p1;
+ clout << "; pressure2=" << p2;
+
+ T pressureDrop = p1-p2;
+ clout << "; pressureDrop=" << pressureDrop;
+
+ AnalyticalFfromSuperF3D intpolateVelocity( velocity, true );
+ T midVel[3];
+ T mid[3] = {length*0.5, radius, radius};
+ intpolateVelocity(midVel, mid);
+ T mu = converter.getPhysViscosity()*converter.getPhysDensity();
+ T l = point2[0] - point1[0];
+ T vel = midVel[0];
+ T pressureGradient = pressureDrop/l;
+
+ AnalyticalPorousVelocity3D porVel(superGeometry, 3, K, mu, pressureGradient, radius, epsilon);
+
+ /// Darcy law
+ T expectedPressureDrop = vel*mu*l/K;
+ T darcyFlux = K*pressureGradient/mu;
+#ifdef GUO_ZHAO
+ expectedPressureDrop *= epsilon;
+ darcyFlux /= epsilon;
+#endif
+
+ clout << "; expected(darcy)=" << expectedPressureDrop << std::endl;
+ clout << "peakVelocity=" << midVel[0];
+ clout << "; expected(darcy)=" << darcyFlux << std::endl;
+ clout << "peakVelocity(analytical)=" << porVel.getPeakVelocity();
+ clout << "; peakVelocity-error(rel)=" << abs(porVel.getPeakVelocity()-vel)/porVel.getPeakVelocity() << std::endl;
+
+ error(superGeometry, sLattice, converter, porVel);
+
+ // Gnuplot
+ Gnuplot gplot( "velocityProfile" );
+ T uAnalytical[3] = {};
+ T uNumerical[3] = {};
+ for (int i=0; i<101; i++) {
+ T yInput = diameter*i/100.;
+ T input[3] = {length*0.5, yInput, radius};
+ porVel(uAnalytical, input);
+ intpolateVelocity(uNumerical, input);
+ gplot.setData( yInput, {uAnalytical[0], uNumerical[0]}, {"analytical","numerical"} );
+ }
+
+ // Create PNG file
+ gplot.writePNG();
+ }
+}
+
+int main( int argc, char* argv[] )
+{
+
+ // === 1st Step: Initialization ===
+ olbInit( &argc, &argv );
+ singleton::directories().setOutputDir( "./tmp/" );
+ OstreamManager clout( std::cout,"main" );
+
+ if (argc > 1) {
+ if (argv[1][0]=='-'&&argv[1][1]=='h') {
+ OstreamManager clout( std::cout,"help" );
+ clout<<"Usage: program [Resolution] [Permeability]" < 1) {
+ N = atoi(argv[1]);
+ if (N < 1) {
+ std::cerr << "Fluid domain is too small" << std::endl;
+ return 1;
+ }
+ }
+
+ if (argc > 2) {
+ K = atof(argv[2]);
+ if (K < 0) {
+ std::cerr << "Permeabilty must be greater than 0" << std::endl;
+ return 2;
+ }
+ }
+
+ UnitConverterFromResolutionAndRelaxationTime const converter(
+ int {N}, // resolution: number of voxels per charPhysL
+ (T) tau, // latticeRelaxationTime: relaxation time, have to be greater than 0.5!
+ (T) diameter, // charPhysLength: reference length of simulation geometry
+ (T) physU, // charPhysVelocity: maximal/highest expected velocity during simulation in __m / s__
+ (T) diameter*physU/Re, // physViscosity: physical kinematic viscosity in __m^2 / s__
+ (T) physRho // physDensity: physical density in __kg / m^3__
+ );
+ // Prints the converter log as console output
+ converter.print();
+ // Writes the converter log in a file
+ converter.write("porousPoiseuille3d");
+
+
+ // === 2nd Step: Prepare Geometry ===
+
+ Vector center0(0, radius, radius);
+ Vector center1(length, radius, radius);
+ IndicatorCylinder3D pipe(center0, center1, radius);
+ IndicatorLayer3D extendedDomain(pipe, converter.getPhysDeltaX());
+
+ // Instantiation of a cuboidGeometry with weights
+#ifdef PARALLEL_MODE_MPI
+ const int noOfCuboids = 2*singleton::mpi().getSize();
+#else // ifdef PARALLEL_MODE_MPI
+ const int noOfCuboids = 6;
+#endif // ifdef PARALLEL_MODE_MPI
+ CuboidGeometry3D cuboidGeometry(extendedDomain, converter.getPhysDeltaX(), noOfCuboids);
+
+ // Instantiation of a loadBalancer
+ HeuristicLoadBalancer loadBalancer(cuboidGeometry);
+
+ // Instantiation of a superGeometry
+ SuperGeometry3D superGeometry(cuboidGeometry, loadBalancer, 2);
+
+ prepareGeometry(converter, superGeometry);
+
+ // === 3rd Step: Prepare Lattice ===
+ SuperLattice3D sLattice( superGeometry );
+
+ std::unique_ptr> bulkDynamics;
+
+#ifdef SPAID_PHELAN
+ bulkDynamics.reset(new PorousBGKdynamics( converter.getLatticeRelaxationFrequency(), instances::getBulkMomenta() ));
+#elif defined GUO_ZHAO
+ bulkDynamics.reset(new GuoZhaoBGKdynamics( converter.getLatticeRelaxationFrequency(), instances::getBulkMomenta() ));
+#endif
+
+
+ // choose between local and non-local boundary condition
+ sOnLatticeBoundaryCondition3D sOnBoundaryCondition( sLattice );
+ sOffLatticeBoundaryCondition3D sOffBoundaryCondition(sLattice);
+ createBouzidiBoundaryCondition3D(sOffBoundaryCondition);
+
+ createInterpBoundaryCondition3D ( sOnBoundaryCondition );
+
+ prepareLattice(sLattice, converter, *bulkDynamics, sOnBoundaryCondition, sOffBoundaryCondition, superGeometry);
+
+ // === 4th Step: Main Loop with Timer ===
+ clout << "starting simulation..." << endl;
+ Timer timer( converter.getLatticeTime( maxPhysT ), superGeometry.getStatistics().getNvoxel() );
+ util::ValueTracer converge( converter.getLatticeTime( physInterval ), residuum );
+ timer.start();
+
+ for ( int iT = 0; iT < converter.getLatticeTime( maxPhysT ); ++iT ) {
+ if ( converge.hasConverged() ) {
+ clout << "Simulation converged." << endl;
+ getResults( sLattice, *bulkDynamics, converter, iT, superGeometry, timer, converge.hasConverged() );
+
+ break;
+ }
+
+ // === 5th Step: Definition of Initial and Boundary Conditions ===
+ // in this application no boundary conditions have to be adjusted
+
+ // === 6th Step: Collide and Stream Execution ===
+ sLattice.collideAndStream();
+
+ // === 7th Step: Computation and Output of the Results ===
+ getResults( sLattice, *bulkDynamics, converter, iT, superGeometry, timer, converge.hasConverged() );
+ converge.takeValue( sLattice.getStatistics().getAverageEnergy(), true );
+ }
+
+ timer.stop();
+ timer.printSummary();
+}
--
cgit v1.2.3