summaryrefslogtreecommitdiff
path: root/apps/adrian/poiseuille2d
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-12-17 13:07:29 +0100
committerAdrian Kummerlaender2019-06-24 15:13:44 +0200
commitb7518cbd6700a219f7d1be92b992f0c47fcf7a7b (patch)
treed7edfc4e6fbbe567a85bc139a8232020adf7bbed /apps/adrian/poiseuille2d
parent94d3e79a8617f88dc0219cfdeedfa3147833719d (diff)
downloadgrid_refinement_openlb-b7518cbd6700a219f7d1be92b992f0c47fcf7a7b.tar
grid_refinement_openlb-b7518cbd6700a219f7d1be92b992f0c47fcf7a7b.tar.gz
grid_refinement_openlb-b7518cbd6700a219f7d1be92b992f0c47fcf7a7b.tar.bz2
grid_refinement_openlb-b7518cbd6700a219f7d1be92b992f0c47fcf7a7b.tar.lz
grid_refinement_openlb-b7518cbd6700a219f7d1be92b992f0c47fcf7a7b.tar.xz
grid_refinement_openlb-b7518cbd6700a219f7d1be92b992f0c47fcf7a7b.tar.zst
grid_refinement_openlb-b7518cbd6700a219f7d1be92b992f0c47fcf7a7b.zip
Simplify poiseuille2d as a starting point
i.e. restrict to non-forced BGK dynamics and bounce back boundaries. Remove further distractions that will have to be modified anyway such as error norms.
Diffstat (limited to 'apps/adrian/poiseuille2d')
-rw-r--r--apps/adrian/poiseuille2d/Makefile105
-rw-r--r--apps/adrian/poiseuille2d/definitions.mk30
-rw-r--r--apps/adrian/poiseuille2d/module.mk29
-rw-r--r--apps/adrian/poiseuille2d/poiseuille2d.cpp243
4 files changed, 407 insertions, 0 deletions
diff --git a/apps/adrian/poiseuille2d/Makefile b/apps/adrian/poiseuille2d/Makefile
new file mode 100644
index 0000000..a953954
--- /dev/null
+++ b/apps/adrian/poiseuille2d/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
+# <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.
+
+###########################################################################
+## 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/apps/adrian/poiseuille2d/definitions.mk b/apps/adrian/poiseuille2d/definitions.mk
new file mode 100644
index 0000000..632d078
--- /dev/null
+++ b/apps/adrian/poiseuille2d/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
+# <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.
+
+
+###########################################################################
+###########################################################################
+## DEFINITIONS TO BE CHANGED
+
+ROOT := ../../..
+SRC := poiseuille2d.cpp
+OUTPUT := poiseuille2d
diff --git a/apps/adrian/poiseuille2d/module.mk b/apps/adrian/poiseuille2d/module.mk
new file mode 100644
index 0000000..1190482
--- /dev/null
+++ b/apps/adrian/poiseuille2d/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
+# <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.
+
+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/apps/adrian/poiseuille2d/poiseuille2d.cpp b/apps/adrian/poiseuille2d/poiseuille2d.cpp
new file mode 100644
index 0000000..2f582ab
--- /dev/null
+++ b/apps/adrian/poiseuille2d/poiseuille2d.cpp
@@ -0,0 +1,243 @@
+/* Lattice Boltzmann sample, written in C++, using the OpenLB
+ * library
+ *
+ * Copyright (C) 2007, 2012 Jonas Latt, Mathias J. Krause
+ * Vojtech Cvrcek, Peter Weisbrod
+ * 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"
+#include "olb2D.hh"
+
+#include <vector>
+#include <cmath>
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+using namespace olb;
+using namespace olb::descriptors;
+using namespace olb::graphics;
+using namespace std;
+
+typedef double T;
+
+#define DESCRIPTOR D2Q9Descriptor
+
+const T lx = 2.; // length of the channel
+const T ly = 1.; // height of the channel
+int N = 50; // resolution of the model
+const T Re = 10.; // Reynolds number
+const T maxPhysT = 20.; // 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
+const T tuner = 0.99; // for partialSlip only: 0->bounceBack, 1->freeSlip
+
+
+void prepareGeometry( UnitConverter<T,DESCRIPTOR> const& converter,
+ SuperGeometry2D<T>& superGeometry ) {
+
+ OstreamManager clout( std::cout,"prepareGeometry" );
+ clout << "Prepare Geometry ..." << std::endl;
+
+ superGeometry.rename( 0,2 );
+
+ superGeometry.rename( 2,1,1,1 );
+
+ Vector<T,2> extend;
+ Vector<T,2> origin;
+ T physSpacing = converter.getPhysDeltaX();
+
+ // Set material number for inflow
+ extend[1] = ly;
+ extend[0] = physSpacing / 2;
+ origin[0] -= physSpacing / 4;
+ IndicatorCuboid2D<T> inflow( extend, origin );
+ superGeometry.rename( 2,3,1,inflow );
+
+ // Set material number for outflow
+ origin[0] = lx - physSpacing / 4;
+ IndicatorCuboid2D<T> outflow( extend, origin );
+ 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;
+}
+
+void prepareLattice( UnitConverter<T,DESCRIPTOR> const& converter,
+ SuperLattice2D<T, DESCRIPTOR>& sLattice,
+ Dynamics<T, DESCRIPTOR>& bulkDynamics,
+ sOnLatticeBoundaryCondition2D<T,DESCRIPTOR>& sBoundaryCondition,
+ SuperGeometry2D<T>& superGeometry ) {
+
+ OstreamManager clout( std::cout,"prepareLattice" );
+ clout << "Prepare Lattice ..." << std::endl;
+
+ const T omega = converter.getLatticeRelaxationFrequency();
+
+ sLattice.defineDynamics( superGeometry, 0, &instances::getNoDynamics<T, DESCRIPTOR>() );
+ sLattice.defineDynamics( superGeometry, 1, &bulkDynamics );
+ sLattice.defineDynamics( superGeometry, 2, &instances::getBounceBack<T, DESCRIPTOR>() );
+ sLattice.defineDynamics( superGeometry, 3, &bulkDynamics );
+ sLattice.defineDynamics( superGeometry, 4, &bulkDynamics );
+
+ sBoundaryCondition.addVelocityBoundary( superGeometry, 3, omega );
+ sBoundaryCondition.addPressureBoundary( superGeometry, 4, omega );
+
+ T Lx = converter.getLatticeLength( lx );
+ T Ly = converter.getLatticeLength( ly );
+
+ T p0 =8.*converter.getLatticeViscosity()*converter.getCharLatticeVelocity()*Lx/( Ly*Ly );
+ AnalyticalLinear2D<T,T> rho( -p0/lx*DESCRIPTOR<T>::invCs2 , 0 , p0*DESCRIPTOR<T>::invCs2+1 );
+
+ T maxVelocity = converter.getCharLatticeVelocity();
+ T distance2Wall = converter.getConversionFactorLength();
+ Poiseuille2D<T> u( superGeometry, 3, maxVelocity, distance2Wall );
+
+ // Initialize all values of distribution functions to their local equilibrium
+ sLattice.defineRhoU( superGeometry, 1, rho, u );
+ sLattice.iniEquilibrium( superGeometry, 1, rho, u );
+ sLattice.defineRhoU( superGeometry, 2, rho, u );
+ sLattice.iniEquilibrium( superGeometry, 2, rho, u );
+ sLattice.defineRhoU( superGeometry, 3, rho, u );
+ sLattice.iniEquilibrium( superGeometry, 3, rho, u );
+ sLattice.defineRhoU( superGeometry, 4, rho, u );
+ sLattice.iniEquilibrium( superGeometry, 4, rho, u );
+
+ sLattice.initialize();
+
+ clout << "Prepare Lattice ... OK" << std::endl;
+}
+
+void getResults( SuperLattice2D<T,DESCRIPTOR>& sLattice, Dynamics<T, DESCRIPTOR>& bulkDynamics,
+ UnitConverter<T,DESCRIPTOR> const& converter, int iT,
+ SuperGeometry2D<T>& superGeometry, Timer<T>& timer, bool hasConverged ) {
+
+ OstreamManager clout( std::cout,"getResults" );
+
+ SuperVTMwriter2D<T> vtmWriter( "poiseuille2d" );
+ SuperLatticePhysVelocity2D<T, DESCRIPTOR> velocity( sLattice, converter );
+ SuperLatticePhysPressure2D<T, DESCRIPTOR> 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 ) {
+ SuperLatticeGeometry2D<T, DESCRIPTOR> geometry( sLattice, superGeometry );
+ SuperLatticeCuboid2D<T, DESCRIPTOR> cuboid( sLattice );
+ SuperLatticeRank2D<T, DESCRIPTOR> rank( sLattice );
+ superGeometry.rename( 0,2 );
+ vtmWriter.write( geometry );
+ vtmWriter.write( cuboid );
+ vtmWriter.write( rank );
+
+ vtmWriter.createMasterFile();
+ }
+
+ if ( iT%vtmIter==0 || hasConverged ) {
+ vtmWriter.write( iT );
+
+ SuperEuklidNorm2D<T, DESCRIPTOR> normVel( velocity );
+ BlockReduction2D2D<T> planeReduction( normVel, 600, BlockDataSyncMode::ReduceOnly );
+ // write output as JPEG
+ heatmap::write(planeReduction, iT);
+ }
+
+ if ( iT%statIter==0 || hasConverged ) {
+ timer.update( iT );
+ timer.printStep();
+
+ sLattice.getStatistics().print( iT,converter.getPhysTime( iT ) );
+ }
+}
+
+int main( int argc, char* argv[] ) {
+ olbInit( &argc, &argv );
+ singleton::directories().setOutputDir( "./tmp/" );
+ OstreamManager clout( std::cout,"main" );
+
+ UnitConverterFromResolutionAndRelaxationTime<T, DESCRIPTOR> const converter(
+ int {N}, // resolution: number of voxels per charPhysL
+ (T) 0.8, // latticeRelaxationTime: relaxation time, have to be greater than 0.5!
+ (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.0 // physDensity: physical density in __kg / m^3__
+ );
+ converter.print();
+ converter.write("poiseuille2d");
+
+ Vector<T,2> extend( lx, ly );
+ Vector<T,2> origin;
+ IndicatorCuboid2D<T> cuboid( extend, origin );
+
+#ifdef PARALLEL_MODE_MPI
+ const int noOfCuboids = singleton::mpi().getSize();
+#else
+ const int noOfCuboids = 1;
+#endif
+ CuboidGeometry2D<T> cuboidGeometry( cuboid, converter.getConversionFactorLength(), noOfCuboids );
+
+ HeuristicLoadBalancer<T> loadBalancer( cuboidGeometry );
+ SuperGeometry2D<T> superGeometry( cuboidGeometry, loadBalancer, 2 );
+
+ prepareGeometry( converter, superGeometry );
+
+ SuperLattice2D<T, DESCRIPTOR> sLattice( superGeometry );
+
+ Dynamics<T, DESCRIPTOR>* bulkDynamics;
+ bulkDynamics = new BGKdynamics<T, DESCRIPTOR>( converter.getLatticeRelaxationFrequency(), instances::getBulkMomenta<T, DESCRIPTOR>() );
+
+ sOnLatticeBoundaryCondition2D<T, DESCRIPTOR> sBoundaryCondition( sLattice );
+ createInterpBoundaryCondition2D<T, DESCRIPTOR> ( sBoundaryCondition );
+
+ prepareLattice( converter, sLattice, *bulkDynamics, sBoundaryCondition, superGeometry );
+
+ clout << "starting simulation..." << endl;
+ Timer<T> timer( converter.getLatticeTime( maxPhysT ), superGeometry.getStatistics().getNvoxel() );
+ util::ValueTracer<T> 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;
+ }
+
+ sLattice.collideAndStream();
+
+ getResults( sLattice, *bulkDynamics, converter, iT, superGeometry, timer, converge.hasConverged() );
+ converge.takeValue( sLattice.getStatistics().getAverageEnergy(), true );
+ }
+
+ timer.stop();
+ timer.printSummary();
+}