summaryrefslogtreecommitdiff
path: root/examples/laminar/cavity3d
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-06-24 14:43:36 +0200
committerAdrian Kummerlaender2019-06-24 14:43:36 +0200
commit94d3e79a8617f88dc0219cfdeedfa3147833719d (patch)
treec1a6894679563e271f5c6ea7a17fa3462f7212a3 /examples/laminar/cavity3d
downloadgrid_refinement_openlb-94d3e79a8617f88dc0219cfdeedfa3147833719d.tar
grid_refinement_openlb-94d3e79a8617f88dc0219cfdeedfa3147833719d.tar.gz
grid_refinement_openlb-94d3e79a8617f88dc0219cfdeedfa3147833719d.tar.bz2
grid_refinement_openlb-94d3e79a8617f88dc0219cfdeedfa3147833719d.tar.lz
grid_refinement_openlb-94d3e79a8617f88dc0219cfdeedfa3147833719d.tar.xz
grid_refinement_openlb-94d3e79a8617f88dc0219cfdeedfa3147833719d.tar.zst
grid_refinement_openlb-94d3e79a8617f88dc0219cfdeedfa3147833719d.zip
Initialize at openlb-1-3
Diffstat (limited to 'examples/laminar/cavity3d')
-rw-r--r--examples/laminar/cavity3d/parallel/Makefile105
-rw-r--r--examples/laminar/cavity3d/parallel/cavity3d.cpp277
-rw-r--r--examples/laminar/cavity3d/parallel/definitions.mk30
-rw-r--r--examples/laminar/cavity3d/parallel/module.mk29
-rw-r--r--examples/laminar/cavity3d/sequential/Makefile105
-rw-r--r--examples/laminar/cavity3d/sequential/cavity3d.cpp253
-rw-r--r--examples/laminar/cavity3d/sequential/definitions.mk30
-rw-r--r--examples/laminar/cavity3d/sequential/module.mk29
8 files changed, 858 insertions, 0 deletions
diff --git a/examples/laminar/cavity3d/parallel/Makefile b/examples/laminar/cavity3d/parallel/Makefile
new file mode 100644
index 0000000..a953954
--- /dev/null
+++ b/examples/laminar/cavity3d/parallel/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/examples/laminar/cavity3d/parallel/cavity3d.cpp b/examples/laminar/cavity3d/parallel/cavity3d.cpp
new file mode 100644
index 0000000..1d6ed50
--- /dev/null
+++ b/examples/laminar/cavity3d/parallel/cavity3d.cpp
@@ -0,0 +1,277 @@
+/* Lattice Boltzmann sample, written in C++, using the OpenLB
+ * library
+ *
+ * Copyright (C) 2014 Mathias J. 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.
+ */
+
+/* cavity3d.cpp:
+ * This example illustrates a flow in a cuboid, lid-driven cavity.
+ * This version is for parallel use. A version for sequential use
+ * is also available.
+ */
+
+
+#include "olb3D.h"
+#ifndef OLB_PRECOMPILED // Unless precompiled version is used,
+#include "olb3D.hh" // include full template code
+#endif
+
+#include <cmath>
+#include <iostream>
+#include <fstream>
+
+
+using namespace olb;
+using namespace olb::descriptors;
+using namespace olb::graphics;
+using namespace olb::util;
+using namespace std;
+
+typedef double T;
+#define DESCRIPTOR D3Q19<>
+
+const int N = 30; // resolution of the model
+//const int M = 1; // time discretization refinement
+const T maxT = (T) 100.; // max. simulation time in s, SI unit
+
+const T interval = 1.0; // Time intervall in seconds for convergence check
+const T epsilon = 1e-3; // Residuum for convergence check
+
+void prepareGeometry( UnitConverter<T, DESCRIPTOR> const& converter, IndicatorF3D<T>& indicator, SuperGeometry3D<T>& superGeometry ) {
+
+ OstreamManager clout( std::cout,"prepareGeometry" );
+ clout << "Prepare Geometry ..." << std::endl;
+
+ // Sets material number for fluid and boundary
+ superGeometry.rename( 0,2,indicator );
+ superGeometry.rename( 2,1,1,1,1 );
+
+ T eps = converter.getConversionFactorLength();
+ Vector<T,3> origin( -eps, converter.getCharPhysLength() - eps, -eps );
+ Vector<T,3> extend( converter.getCharPhysLength() + 2*eps, 2*eps, converter.getCharPhysLength() + 2*eps );
+ IndicatorCuboid3D<T> lid( extend,origin );
+
+ superGeometry.rename( 2,3,1,lid );
+
+ // 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,
+ SuperLattice3D<T,DESCRIPTOR>& lattice,
+ Dynamics<T, DESCRIPTOR>& bulkDynamics,
+ sOnLatticeBoundaryCondition3D<T,DESCRIPTOR>& bc,
+ SuperGeometry3D<T>& superGeometry ) {
+
+ OstreamManager clout( std::cout,"prepareLattice" );
+ clout << "Prepare Lattice ..." << std::endl;
+
+ const T omega = converter.getLatticeRelaxationFrequency();
+
+ // Material=0 -->do nothing
+ lattice.defineDynamics( superGeometry, 0, &instances::getNoDynamics<T, DESCRIPTOR>() );
+
+ // Material=1 -->bulk dynamics
+ lattice.defineDynamics( superGeometry, 1, &bulkDynamics );
+
+ // Material=2,3 -->bulk dynamics, velocity boundary
+ lattice.defineDynamics( superGeometry, 2, &bulkDynamics );
+ lattice.defineDynamics( superGeometry, 3, &bulkDynamics );
+ bc.addVelocityBoundary( superGeometry, 2, omega );
+ bc.addVelocityBoundary( superGeometry, 3, omega );
+
+ clout << "Prepare Lattice ... OK" << std::endl;
+}
+
+void setBoundaryValues( UnitConverter<T, DESCRIPTOR> const& converter,
+ SuperLattice3D<T,DESCRIPTOR>& lattice, SuperGeometry3D<T>& superGeometry, int iT ) {
+
+ OstreamManager clout( std::cout,"setBoundaryValues" );
+
+ if ( iT==0 ) {
+
+ AnalyticalConst3D<T,T> rhoF( T( 1 ) );
+ AnalyticalConst3D<T,T> uF( T( 0 ), T( 0 ), T( 0 ) );
+
+ auto bulkIndicator = superGeometry.getMaterialIndicator({1, 2, 3});
+ lattice.iniEquilibrium( bulkIndicator, rhoF, uF );
+ lattice.defineRhoU( bulkIndicator, rhoF, uF );
+
+ clout << converter.getCharLatticeVelocity() << std::endl;
+ AnalyticalConst3D<T,T> uTop( converter.getCharLatticeVelocity(), T( 0 ), T( 0 ) );
+ lattice.defineU( superGeometry,3,uTop );
+
+ // Make the lattice ready for simulation
+ lattice.initialize();
+ }
+}
+
+void getResults( SuperLattice3D<T,DESCRIPTOR>& sLattice,
+ UnitConverter<T, DESCRIPTOR> const& converter, SuperGeometry3D<T>& superGeometry,
+ int iT, Timer<T>& timer, bool converged ) {
+
+ OstreamManager clout( std::cout,"getResults" );
+ SuperVTMwriter3D<T> vtmWriter( "cavity3d" );
+
+ const T logT = ( T )1.;
+ const T vtkSave = ( T )1.;
+ const T imSave = ( T )5.;
+
+ if ( iT==0 ) {
+ SuperLatticeGeometry3D<T, DESCRIPTOR> geometry( sLattice, superGeometry );
+ SuperLatticeCuboid3D<T, DESCRIPTOR> cuboid( sLattice );
+ SuperLatticeRank3D<T, DESCRIPTOR> rank( sLattice );
+ vtmWriter.write( geometry );
+ vtmWriter.write( cuboid );
+ vtmWriter.write( rank );
+ vtmWriter.createMasterFile();
+ }
+
+ // Get statistics
+ if ( (iT%converter.getLatticeTime( logT )==0 && iT>0) || converged ) {
+ timer.update( iT );
+ timer.printStep( 2 );
+ sLattice.getStatistics().print( iT,converter.getPhysTime( iT ) );
+ }
+
+ // Writes the VTK
+ if ( (iT%converter.getLatticeTime( vtkSave )==0 && iT>0) || converged ) {
+ SuperLatticePhysVelocity3D<T, DESCRIPTOR> velocity( sLattice, converter );
+ SuperLatticePhysPressure3D<T, DESCRIPTOR> pressure( sLattice, converter );
+ vtmWriter.addFunctor( velocity );
+ vtmWriter.addFunctor( pressure );
+
+ vtmWriter.write( iT );
+ }
+
+ // Writes the JPEG files
+ if ( (iT%converter.getLatticeTime( imSave )==0 && iT>0) || converged ) {
+ SuperLatticePhysVelocity3D<T, DESCRIPTOR> velocity( sLattice, converter );
+ // define vector which span the plane
+ Vector<T,3> u( 1,0,0 );
+ Vector<T,3> v( 0,1,0 );
+ T tmp = T( converter.getCharPhysLength() / 2. );
+ T origin[3] = {tmp,tmp,tmp};
+
+ SuperEuklidNorm3D<T, DESCRIPTOR> normVel( velocity );
+ BlockReduction3D2D<T> planeReduction( normVel, origin, u, v, 600 );
+
+ // write a heatmap
+ heatmap::plotParam<T> plotParam;
+ plotParam.maxValue = 1.;
+ plotParam.name = "velocity";
+ heatmap::write(planeReduction, iT, plotParam);
+ }
+}
+
+
+int main( int argc, char **argv ) {
+
+ // === 1st Step: Initialization ===
+
+ 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.509, // latticeRelaxationTime: relaxation time, have to be greater than 0.5!
+ (T) 1.0, // charPhysLength: reference length of simulation geometry
+ (T) 1.0, // charPhysVelocity: maximal/highest expected velocity during simulation in __m / s__
+ (T) 0.001, // 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("cavity3d");
+
+
+ // === 2nd Step: Prepare Geometry ===
+
+ // Instantiation of a unit cube by an indicator
+ Vector<T,3> origin( T( 0 ) );
+ Vector<T,3> extend( converter.getCharPhysLength() );
+ IndicatorCuboid3D<T> cube( extend,origin );
+
+ // Instantiation of a cuboid geometry with weights
+ int noCuboids = singleton::mpi().getSize();
+ if ( noCuboids < 7 ) {
+ noCuboids = 7;
+ }
+ CuboidGeometry3D<T> cuboidGeometry( cube, converter.getConversionFactorLength(), noCuboids );
+
+ // Instantiation of a load balancer
+ HeuristicLoadBalancer<T> loadBalancer( cuboidGeometry );
+
+ // Instantiation of a super geometry
+ SuperGeometry3D<T> superGeometry( cuboidGeometry, loadBalancer, 2 );
+
+ prepareGeometry( converter, cube, superGeometry );
+
+
+ // === 3rd Step: Prepare Lattice ===
+ SuperLattice3D<T, DESCRIPTOR> sLattice( superGeometry );
+
+ ConstRhoBGKdynamics<T, DESCRIPTOR> bulkDynamics (
+ converter.getLatticeRelaxationFrequency(), instances::getBulkMomenta<T,DESCRIPTOR>() );
+
+ sOnLatticeBoundaryCondition3D<T,DESCRIPTOR> sBoundaryCondition( sLattice );
+ createInterpBoundaryCondition3D<T,DESCRIPTOR,ConstRhoBGKdynamics<T,DESCRIPTOR> >( sBoundaryCondition );
+
+ prepareLattice( converter, sLattice, bulkDynamics, sBoundaryCondition, superGeometry );
+
+ // === 4th Step: Main Loop with Timer ===
+ util::ValueTracer<T> converge( converter.getLatticeTime(interval), epsilon );
+
+ Timer<T> timer( converter.getLatticeTime( maxT ), std::pow<int>(converter.getResolution(),3) );
+ timer.start();
+
+ for ( int iT = 0; iT <= converter.getLatticeTime( maxT ); ++iT ) {
+
+ if ( converge.hasConverged() ) {
+ clout << "Simulation converged." << endl;
+ getResults( sLattice, converter, superGeometry, iT, timer, converge.hasConverged() );
+ break;
+ }
+
+ // === 5th Step: Definition of Initial and Boundary Conditions ===
+ setBoundaryValues( converter, sLattice, superGeometry, iT );
+
+ // === 6th Step: Collide and Stream Execution ===
+ sLattice.collideAndStream();
+
+ // === 7th Step: Computation and Output of the Results ===
+ getResults( sLattice, converter, superGeometry, iT, timer, converge.hasConverged() );
+ converge.takeValue( sLattice.getStatistics().getAverageEnergy(), true );
+ }
+
+ timer.stop();
+ timer.printSummary();
+}
diff --git a/examples/laminar/cavity3d/parallel/definitions.mk b/examples/laminar/cavity3d/parallel/definitions.mk
new file mode 100644
index 0000000..1fd7ebc
--- /dev/null
+++ b/examples/laminar/cavity3d/parallel/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 := cavity3d.cpp
+OUTPUT := cavity3d
diff --git a/examples/laminar/cavity3d/parallel/module.mk b/examples/laminar/cavity3d/parallel/module.mk
new file mode 100644
index 0000000..1190482
--- /dev/null
+++ b/examples/laminar/cavity3d/parallel/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/examples/laminar/cavity3d/sequential/Makefile b/examples/laminar/cavity3d/sequential/Makefile
new file mode 100644
index 0000000..a953954
--- /dev/null
+++ b/examples/laminar/cavity3d/sequential/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/examples/laminar/cavity3d/sequential/cavity3d.cpp b/examples/laminar/cavity3d/sequential/cavity3d.cpp
new file mode 100644
index 0000000..3700de8
--- /dev/null
+++ b/examples/laminar/cavity3d/sequential/cavity3d.cpp
@@ -0,0 +1,253 @@
+/* Lattice Boltzmann sample, written in C++, using the OpenLB
+ * library
+ *
+ * Copyright (C) 2014 Mathias J. 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.
+ */
+
+/* cavity3d.cpp:
+ * This example illustrates a flow in a cuboid, lid-driven cavity.
+ * This version is for sequential use. A version for parallel use
+ * is also available.
+ */
+
+
+#include "olb3D.h"
+#ifndef OLB_PRECOMPILED // Unless precompiled version is used,
+#include "olb3D.hh" // include full template code
+#endif
+
+#include <cmath>
+#include <iostream>
+#include <fstream>
+
+
+using namespace olb;
+using namespace olb::descriptors;
+using namespace olb::graphics;
+using namespace olb::util;
+using namespace std;
+
+typedef double T;
+#define DESCRIPTOR D3Q19<>
+
+const int N = 30; // resolution of the model
+//const int M = 1; // time discretization refinement
+const T maxT = (T) 100.; // max. simulation time in s, SI unit
+
+const T interval = 1.0; // Time intervall in seconds for convergence check
+const T epsilon = 1e-3; // Residuum for convergence check
+
+void prepareGeometry( UnitConverter<T, DESCRIPTOR> const& converter, IndicatorF3D<T>& indicator, BlockGeometry3D<T>& blockGeometry ) {
+
+ OstreamManager clout( std::cout,"prepareGeometry" );
+ clout << "Prepare Geometry ..." << std::endl;
+
+ // Sets material number for fluid and boundary
+ blockGeometry.rename( 0,2,indicator );
+ blockGeometry.rename( 2,1,1,1,1 );
+
+ Vector<T,3> origin( T(), converter.getCharPhysLength(), T() );
+ Vector<T,3> extend( converter.getCharPhysLength(), converter.getConversionFactorLength(), converter.getCharPhysLength() );
+ IndicatorCuboid3D<T> lid( extend,origin );
+
+ blockGeometry.rename( 2,3,1,lid );
+
+ // Removes all not needed boundary voxels outside the surface
+ blockGeometry.clean();
+ // Removes all not needed boundary voxels inside the surface
+ blockGeometry.innerClean();
+ blockGeometry.checkForErrors();
+
+ clout << "Prepare Geometry ... OK" << std::endl;
+}
+
+
+void prepareLattice( UnitConverter<T, DESCRIPTOR> const& converter,
+ BlockLatticeStructure3D<T,DESCRIPTOR>& lattice,
+ Dynamics<T, DESCRIPTOR>& bulkDynamics,
+ OnLatticeBoundaryCondition3D<T,DESCRIPTOR>& bc,
+ BlockGeometry3D<T>& blockGeometry) {
+
+ OstreamManager clout( std::cout,"prepareLattice" );
+ clout << "Prepare Lattice ..." << std::endl;
+
+ const T omega = converter.getLatticeRelaxationFrequency();
+
+ // Material=0 -->do nothing
+ lattice.defineDynamics( blockGeometry, 0, &instances::getNoDynamics<T, DESCRIPTOR>() );
+
+ // Material=1 -->bulk dynamics
+ lattice.defineDynamics( blockGeometry, 1, &bulkDynamics );
+
+ // Material=2 -->bounce back
+ //lattice.defineDynamics(superGeometry, 2, &instances::getBounceBack<T, DESCRIPTOR>());
+
+ // Material=2,3 -->bulk dynamics, velocity boundary
+ lattice.defineDynamics( blockGeometry, 2, &bulkDynamics );
+ lattice.defineDynamics( blockGeometry, 3, &bulkDynamics );
+ bc.addVelocityBoundary( blockGeometry, 2, omega );
+ bc.addVelocityBoundary( blockGeometry, 3, omega );
+
+ clout << "Prepare Lattice ... OK" << std::endl;
+}
+
+void setBoundaryValues( UnitConverter<T, DESCRIPTOR> const& converter,
+ BlockLatticeStructure3D<T,DESCRIPTOR>& lattice, BlockGeometry3D<T>& blockGeometry, int iT ) {
+
+ OstreamManager clout( std::cout,"setBoundaryValues" );
+
+ if ( iT==0 ) {
+
+ AnalyticalConst3D<T,T> rhoF( 1 );
+ std::vector<T> velocity( 3,T() );
+ AnalyticalConst3D<T,T> uF( velocity );
+
+ lattice.iniEquilibrium( blockGeometry, 1, rhoF, uF );
+ lattice.iniEquilibrium( blockGeometry, 2, rhoF, uF );
+ lattice.iniEquilibrium( blockGeometry, 3, rhoF, uF );
+
+ lattice.defineRhoU( blockGeometry, 1, rhoF, uF );
+ lattice.defineRhoU( blockGeometry, 2, rhoF, uF );
+ lattice.defineRhoU( blockGeometry, 3, rhoF, uF );
+
+ velocity[0]=converter.getCharLatticeVelocity();
+ AnalyticalConst3D<T,T> u( velocity );
+
+ lattice.defineU( blockGeometry,3,u );
+
+ // Make the lattice ready for simulation
+ lattice.initialize();
+ }
+}
+
+void getResults( BlockLatticeStructure3D<T,DESCRIPTOR>& lattice,
+ UnitConverter<T, DESCRIPTOR> const& converter, BlockGeometry3D<T>& blockGeometry, int iT, Timer<T>& timer, bool converged ) {
+
+ OstreamManager clout( std::cout,"getResults" );
+ BlockVTKwriter3D<T> vtkWriter( "cavity3d" );
+
+ const T logT = ( T )1.;
+ const T vtkSave = ( T )1.;
+
+ if ( iT==0 ) {
+ BlockLatticeGeometry3D<T, DESCRIPTOR> geometry( lattice, blockGeometry );
+ vtkWriter.write( geometry );
+ }
+
+ // Get statistics
+ if ( (iT%converter.getLatticeTime( logT )==0 && iT>0) || converged ) {
+ timer.update( iT );
+ timer.printStep( 2 );
+ lattice.getStatistics().print( iT,converter.getPhysTime( iT ) );
+ }
+
+ // Writes the VTK files
+ if ( (iT%converter.getLatticeTime( vtkSave )==0 && iT>0) || converged ) {
+
+ BlockLatticePhysVelocity3D<T, DESCRIPTOR> velocity( lattice, 0, converter );
+ BlockLatticePhysPressure3D<T, DESCRIPTOR> pressure( lattice, 0, converter );
+ vtkWriter.addFunctor( velocity );
+ vtkWriter.addFunctor( pressure );
+
+ vtkWriter.write( iT );
+ }
+}
+
+
+
+int main( int argc, char **argv ) {
+
+ // === 1st Step: Initialization ===
+
+ 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.509, // latticeRelaxationTime: relaxation time, have to be greater than 0.5!
+ (T) 1.0, // charPhysLength: reference length of simulation geometry
+ (T) 1.0, // charPhysVelocity: maximal/highest expected velocity during simulation in __m / s__
+ (T) 0.001, // 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("cavity3d");
+
+
+ // === 2nd Step: Prepare Geometry ===
+
+ // Instantiation of a unit cube by an indicator
+ Vector<T,3> origin;
+ Vector<T,3> extend( converter.getCharPhysLength() );
+ IndicatorCuboid3D<T> cube( extend,origin );
+
+ Cuboid3D<T> cuboid( cube, converter.getConversionFactorLength() );
+
+ // Instantiation of a block geometry
+ BlockGeometry3D<T> blockGeometry( cuboid );
+
+ prepareGeometry( converter, cube, blockGeometry );
+
+
+ // === 3rd Step: Prepare Lattice ===
+
+ BlockLattice3D<T, DESCRIPTOR> lattice( blockGeometry.getNx(), blockGeometry.getNy(), blockGeometry.getNz(), blockGeometry );
+
+ ConstRhoBGKdynamics<T, DESCRIPTOR> bulkDynamics (
+ converter.getLatticeRelaxationFrequency(), instances::getBulkMomenta<T,DESCRIPTOR>() );
+
+ OnLatticeBoundaryCondition3D<T,DESCRIPTOR>*
+ boundaryCondition = createInterpBoundaryCondition3D<T,DESCRIPTOR,ConstRhoBGKdynamics<T,DESCRIPTOR> >( lattice );
+
+ prepareLattice( converter, lattice, bulkDynamics, *boundaryCondition, blockGeometry );
+
+ // === 4th Step: Main Loop with Timer ===
+ util::ValueTracer<T> converge( converter.getLatticeTime(interval), epsilon );
+
+ Timer<T> timer( converter.getLatticeTime( maxT ), std::pow<int>(converter.getResolution(),3) );
+ timer.start();
+ int iT;
+
+ for ( iT=0; iT < converter.getLatticeTime( maxT ); ++iT ) {
+
+ if ( converge.hasConverged() ) {
+ clout << "Simulation converged." << endl;
+ getResults( lattice, converter, blockGeometry, iT, timer, converge.hasConverged() );
+ break;
+ }
+
+ // === 5th Step: Definition of Initial and Boundary Conditions ===
+ setBoundaryValues( converter, lattice, blockGeometry, iT );
+
+ // === 6th Step: Collide and Stream Execution ===
+ lattice.collideAndStream();
+
+ // === 7th Step: Computation and Output of the Results ===
+ getResults( lattice, converter, blockGeometry, iT, timer, converge.hasConverged() );
+ converge.takeValue( lattice.getStatistics().getAverageEnergy(), true );
+ }
+
+ timer.stop();
+ timer.printSummary();
+}
diff --git a/examples/laminar/cavity3d/sequential/definitions.mk b/examples/laminar/cavity3d/sequential/definitions.mk
new file mode 100644
index 0000000..1fd7ebc
--- /dev/null
+++ b/examples/laminar/cavity3d/sequential/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 := cavity3d.cpp
+OUTPUT := cavity3d
diff --git a/examples/laminar/cavity3d/sequential/module.mk b/examples/laminar/cavity3d/sequential/module.mk
new file mode 100644
index 0000000..1190482
--- /dev/null
+++ b/examples/laminar/cavity3d/sequential/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))))