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/turbulence/venturi3d/Makefile | 105 ++++++++++ examples/turbulence/venturi3d/definitions.mk | 30 +++ examples/turbulence/venturi3d/module.mk | 29 +++ examples/turbulence/venturi3d/venturi3d.cpp | 284 +++++++++++++++++++++++++++ examples/turbulence/venturi3d/venturi3d.xml | 41 ++++ 5 files changed, 489 insertions(+) create mode 100644 examples/turbulence/venturi3d/Makefile create mode 100644 examples/turbulence/venturi3d/definitions.mk create mode 100644 examples/turbulence/venturi3d/module.mk create mode 100644 examples/turbulence/venturi3d/venturi3d.cpp create mode 100644 examples/turbulence/venturi3d/venturi3d.xml (limited to 'examples/turbulence/venturi3d') diff --git a/examples/turbulence/venturi3d/Makefile b/examples/turbulence/venturi3d/Makefile new file mode 100644 index 0000000..a953954 --- /dev/null +++ b/examples/turbulence/venturi3d/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/turbulence/venturi3d/definitions.mk b/examples/turbulence/venturi3d/definitions.mk new file mode 100644 index 0000000..1d8fc65 --- /dev/null +++ b/examples/turbulence/venturi3d/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 := venturi3d.cpp +OUTPUT := venturi3d diff --git a/examples/turbulence/venturi3d/module.mk b/examples/turbulence/venturi3d/module.mk new file mode 100644 index 0000000..1190482 --- /dev/null +++ b/examples/turbulence/venturi3d/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/turbulence/venturi3d/venturi3d.cpp b/examples/turbulence/venturi3d/venturi3d.cpp new file mode 100644 index 0000000..fc3dd55 --- /dev/null +++ b/examples/turbulence/venturi3d/venturi3d.cpp @@ -0,0 +1,284 @@ +/* Lattice Boltzmann sample, written in C++, using the OpenLB + * library + * + * Copyright (C) 2014 Mathias J. Krause, Thomas Henn, + * Cyril Masquelier + * 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. + */ + +/* venturi3d.cpp: + * This example examines a steady flow in a venturi tube. At the + * main inlet, a Poiseuille profile is imposed as Dirichlet velocity + * boundary condition, whereas at the outlet and the minor inlet + * a Dirichlet pressure condition is set by p=0 (i.e. rho=1). + * + * The example shows the usage of the Indicator functors to + * build up a geometry and explains how to set boundary conditions + * automatically. + */ + +#include "olb3D.h" +#ifndef OLB_PRECOMPILED // Unless precompiled version is used +#include "olb3D.hh" // Include full template code +#endif + +#include +#include + +using namespace olb; +using namespace olb::descriptors; +using namespace olb::graphics; +using namespace olb::util; +using namespace std; + +typedef double T; +#define DESCRIPTOR D3Q19<> + +T maxPhysT = 200.0; // max. simulation time in s, SI unit + +SuperGeometry3D prepareGeometry( ) { + + OstreamManager clout( std::cout,"prepareGeometry" ); + clout << "Prepare Geometry ..." << std::endl; + + std::string fName("venturi3d.xml"); + XMLreader config(fName); + + std::shared_ptr > inflow = createIndicatorCylinder3D(config["Geometry"]["Inflow"]["IndicatorCylinder3D"], false); + std::shared_ptr > outflow0 = createIndicatorCylinder3D(config["Geometry"]["Outflow0"]["IndicatorCylinder3D"], false); + std::shared_ptr > outflow1 = createIndicatorCylinder3D(config["Geometry"]["Outflow1"]["IndicatorCylinder3D"], false); + + std::shared_ptr > venturi = createIndicatorF3D(config["Geometry"]["Venturi"], false); + + // Build CoboidGeometry from IndicatorF (weights are set, remove and shrink is done) + int N = config["Application"]["Discretization"]["Resolution"].get(); + CuboidGeometry3D* cuboidGeometry = new CuboidGeometry3D( *venturi, 1./N, 20*singleton::mpi().getSize() ); + + // Build LoadBalancer from CuboidGeometry (weights are respected) + HeuristicLoadBalancer* loadBalancer = new HeuristicLoadBalancer( *cuboidGeometry ); + + // Default instantiation of superGeometry + SuperGeometry3D superGeometry( *cuboidGeometry, *loadBalancer, 2 ); + + // Set boundary voxels by rename material numbers + superGeometry.rename( 0,2, venturi ); + superGeometry.rename( 2,1,1,1,1 ); + superGeometry.rename( 2,3,1, inflow ); + superGeometry.rename( 2,4,1, outflow0 ); + superGeometry.rename( 2,5,1, outflow1 ); + + // 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.getStatistics().print(); + superGeometry.communicate(); + + clout << "Prepare Geometry ... OK" << std::endl; + return superGeometry; +} + + +void prepareLattice( SuperLattice3D& sLattice, + UnitConverter const& converter, + Dynamics& bulkDynamics, + sOnLatticeBoundaryCondition3D& bc, + 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 ); + + // Material=2 -->bounce back + sLattice.defineDynamics( superGeometry, 2, &instances::getBounceBack() ); + + // Material=3 -->bulk dynamics (inflow) + sLattice.defineDynamics( superGeometry, 3, &bulkDynamics ); + + // Material=4 -->bulk dynamics (outflow) + sLattice.defineDynamics( superGeometry, 4, &bulkDynamics ); + + // Material=5 -->bulk dynamics (2nd outflow) + sLattice.defineDynamics( superGeometry, 5, &bulkDynamics ); + + // Setting of the boundary conditions + bc.addVelocityBoundary( superGeometry, 3, omega ); + bc.addPressureBoundary( superGeometry, 4, omega ); + bc.addPressureBoundary( superGeometry, 5, omega ); + + clout << "Prepare Lattice ... OK" << std::endl; +} + +// Generates a slowly increasing sinuidal inflow for the first iTMax timesteps +void setBoundaryValues( SuperLattice3D& sLattice, + UnitConverter const& converter, int iT, + SuperGeometry3D& superGeometry ) { + + OstreamManager clout( std::cout,"setBoundaryValues" ); + + // No of time steps for smooth start-up + int iTmaxStart = converter.getLatticeTime( maxPhysT*0.8 ); + int iTperiod = 50; + + if ( iT==0 ) { + // Make the lattice ready for simulation + sLattice.initialize(); + } + + else if ( iT%iTperiod==0 && iT<= iTmaxStart ) { + //clout << "Set Boundary Values ..." << std::endl; + + //SinusStartScale startScale(iTmaxStart, (T) 1); + PolynomialStartScale startScale( iTmaxStart, T( 1 ) ); + int iTvec[1]= {iT}; + T frac = T(); + startScale( &frac,iTvec ); + + // Creates and sets the Poiseuille inflow profile using functors + CirclePoiseuille3D poiseuilleU( superGeometry, 3, frac*converter.getCharLatticeVelocity(), converter.getConversionFactorLength() ); + sLattice.defineU( superGeometry, 3, poiseuilleU ); + + //clout << "step=" << iT << "; scalingFactor=" << frac << std::endl; + } + //clout << "Set Boundary Values ... ok" << std::endl; +} + +void getResults( SuperLattice3D& sLattice, + UnitConverter& converter, int iT, + SuperGeometry3D& superGeometry, Timer& timer ) { + + OstreamManager clout( std::cout,"getResults" ); + SuperVTMwriter3D vtmWriter( "venturi3d" ); + + 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 + if ( iT%converter.getLatticeTime( 1. )==0 ) { + // Create the data-reading functors... + SuperLatticePhysVelocity3D velocity( sLattice, converter ); + SuperLatticePhysPressure3D pressure( sLattice, converter ); + vtmWriter.addFunctor( velocity ); + vtmWriter.addFunctor( pressure ); + vtmWriter.write( iT ); + + SuperEuklidNorm3D normVel( velocity ); + BlockReduction3D2D planeReduction( normVel, {0, 0, 1} ); + + // write output as JPEG + heatmap::write(planeReduction, iT); + + // write output as JPEG and changing properties + heatmap::plotParam jpeg_Param; + jpeg_Param.name = "outflow"; + jpeg_Param.contourlevel = 5; + jpeg_Param.colour = "blackbody"; + jpeg_Param.zoomOrigin = {0.6, 0.3}; + jpeg_Param.zoomExtend = {0.4, 0.7}; + heatmap::write(planeReduction, iT, jpeg_Param); + } + + // Writes output on the console + if ( iT%converter.getLatticeTime( 1. )==0 ) { + timer.update( iT ); + timer.printStep(); + sLattice.getStatistics().print( iT, converter.getPhysTime( iT ) ); + + } +} + + +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); + + std::string fName("venturi3d.xml"); + XMLreader config(fName); + + UnitConverter* converter = createUnitConverter(config); + + // Prints the converter log as console output + converter->print(); + // Writes the converter log in a file + converter->write("venturi3d"); + + // === 2nd Step: Prepare Geometry === + + SuperGeometry3D superGeometry( prepareGeometry() ); + + // === 3rd Step: Prepare Lattice === + + SuperLattice3D sLattice( superGeometry ); + + RLBdynamics bulkDynamics( converter->getLatticeRelaxationFrequency(), instances::getBulkMomenta() ); + + sOnLatticeBoundaryCondition3D sBoundaryCondition( sLattice ); + createInterpBoundaryCondition3D ( sBoundaryCondition ); + + sOffLatticeBoundaryCondition3D sOffBoundaryCondition( sLattice ); + createBouzidiBoundaryCondition3D ( sOffBoundaryCondition ); + + prepareLattice( sLattice, *converter, bulkDynamics, sBoundaryCondition, sOffBoundaryCondition, superGeometry ); + + Timer timer( converter->getLatticeTime( maxPhysT ), superGeometry.getStatistics().getNvoxel() ); + timer.start(); + getResults( sLattice, *converter, 0, superGeometry, timer ); + + // === 4th Step: Main Loop with Timer === + for ( int iT = 0; iT <= converter->getLatticeTime( maxPhysT ); ++iT ) { + + // === 5th Step: Definition of Initial and Boundary Conditions === + setBoundaryValues( sLattice, *converter, iT, superGeometry ); + + // === 6th Step: Collide and Stream Execution === + sLattice.collideAndStream(); + + // === 7th Step: Computation and Output of the Results === + getResults( sLattice, *converter, iT, superGeometry, timer ); + } + + timer.stop(); + timer.printSummary(); +} diff --git a/examples/turbulence/venturi3d/venturi3d.xml b/examples/turbulence/venturi3d/venturi3d.xml new file mode 100644 index 0000000..3f78fb5 --- /dev/null +++ b/examples/turbulence/venturi3d/venturi3d.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 0.2 + + + + 0.1 + + 2 + + 0.001 + + 1 + + + -- cgit v1.2.3