diff options
Add refined N=20 cylinder2d example for reference
Diffstat (limited to 'apps/adrian')
4 files changed, 294 insertions, 0 deletions
diff --git a/apps/adrian/cylinder2d/optimized_grid_n20/Makefile b/apps/adrian/cylinder2d/optimized_grid_n20/Makefile new file mode 100644 index 0000000..a953954 --- /dev/null +++ b/apps/adrian/cylinder2d/optimized_grid_n20/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/cylinder2d/optimized_grid_n20/cylinder2d.cpp b/apps/adrian/cylinder2d/optimized_grid_n20/cylinder2d.cpp new file mode 100644 index 0000000..e4b0c5f --- /dev/null +++ b/apps/adrian/cylinder2d/optimized_grid_n20/cylinder2d.cpp @@ -0,0 +1,130 @@ +/* + * Lattice Boltzmann grid refinement sample, written in C++, + * using the OpenLB library + * + * Copyright (C) 2019 Adrian Kummerländer + * 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" +#ifndef OLB_PRECOMPILED +#include "olb2D.hh" +#endif + +using namespace olb; + +typedef double T; + +#define DESCRIPTOR descriptors::D2Q9Descriptor + +/// Setup geometry relative to cylinder diameter as defined by [SchaeferTurek96] +const T cylinderD = 0.1; +const int N = 20; // resolution of the cylinder + +const T Re = 100.; // Reynolds number +const T tau = 0.51; // relaxation time +const T maxPhysT = 16.; // max. simulation time in s, SI unit + +const Characteristics<T> PhysCharacteristics( + cylinderD, // char. phys. length + 1.0, // char. phys. velocity + 0.1/Re, // phsy. kinematic viscosity + 1.0); // char. phys. density + +#include "../common/model.h" + +void setupRefinement(Grid2D<T,DESCRIPTOR>& coarseGrid, + Vector<T,2> domainOrigin, Vector<T,2> domainExtend, + Vector<T,2> cylinderCenter) +{ + const auto coarseDeltaX = coarseGrid.getConverter().getPhysDeltaX(); + + const Vector<T,2> fineExtend {11.2*cylinderD, domainExtend[1]-1.5*coarseDeltaX}; + const Vector<T,2> fineOrigin {0.5*cylinderD, coarseDeltaX}; + + auto& fineGrid = coarseGrid.refine(fineOrigin, fineExtend); + SchaeferTurek::prepareGeometry(fineGrid, domainOrigin, domainExtend); + + const Vector<T,2> fineExtend2 {5*cylinderD, fineGrid.getExtend()[1]-2*coarseDeltaX}; + const Vector<T,2> fineOrigin2 {1*cylinderD, (domainExtend[1]-fineExtend2[1])/2}; + + auto& fineGrid2 = fineGrid.refine(fineOrigin2, fineExtend2); + SchaeferTurek::prepareGeometry(fineGrid2, domainOrigin, domainExtend); + + const Vector<T,2> fineExtend3 {1.4*cylinderD, 1.4*cylinderD}; + const Vector<T,2> fineOrigin3 {cylinderCenter[0]-fineExtend3[0]/2, cylinderCenter[1]-fineExtend3[1]/2}; + + auto& fineGrid3 = fineGrid2.refine(fineOrigin3, fineExtend3); + SchaeferTurek::prepareGeometry(fineGrid3, domainOrigin, domainExtend); +} + +int main(int argc, char* argv[]) +{ + olbInit(&argc, &argv); + singleton::directories().setOutputDir("./tmp/"); + OstreamManager clout(std::cout,"main"); + + IndicatorCuboid2D<T> coarseCuboid(SchaeferTurek::modelExtend, SchaeferTurek::modelOrigin); + + Grid2D<T,DESCRIPTOR> coarseGrid( + coarseCuboid, + RelaxationTime<T>(tau), + N, + PhysCharacteristics); + const Vector<T,2> domainOrigin = coarseGrid.getSuperGeometry().getStatistics().getMinPhysR(0); + const Vector<T,2> domainExtend = coarseGrid.getSuperGeometry().getStatistics().getPhysExtend(0); + + SchaeferTurek::prepareGeometry(coarseGrid, domainOrigin, domainExtend); + + setupRefinement(coarseGrid, domainOrigin, domainExtend, SchaeferTurek::cylinderCenter); + + coarseGrid.forEachGrid(SchaeferTurek::prepareLattice); + + clout << "Total number of active cells: " << coarseGrid.getActiveVoxelN() << endl; + clout << "Starting simulation..." << endl; + + const int statIter = coarseGrid.getConverter().getLatticeTime(0.01); + Timer<T> timer( + coarseGrid.getConverter().getLatticeTime(maxPhysT), + coarseGrid.getSuperGeometry().getStatistics().getNvoxel()); + timer.start(); + + Grid2D<T,DESCRIPTOR>& cylinderGrid = coarseGrid.locate(SchaeferTurek::cylinderCenter); + + for (int iT = 0; iT <= coarseGrid.getConverter().getLatticeTime(maxPhysT); ++iT) { + SchaeferTurek::setBoundaryValues(coarseGrid, iT); + + coarseGrid.collideAndStream(); + + if (iT == 0 || iT%statIter == 0) { + timer.update(iT); + timer.printStep(); + + coarseGrid.forEachGrid("cylinder2d", [&](Grid2D<T,DESCRIPTOR>& grid, const std::string& id) { + SchaeferTurek::getResults(grid, id, iT); + }); + + SchaeferTurek::takeMeasurements(cylinderGrid, iT); + } + } + + timer.stop(); + timer.printSummary(); +} diff --git a/apps/adrian/cylinder2d/optimized_grid_n20/definitions.mk b/apps/adrian/cylinder2d/optimized_grid_n20/definitions.mk new file mode 100644 index 0000000..c11e80b --- /dev/null +++ b/apps/adrian/cylinder2d/optimized_grid_n20/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 := cylinder2d.cpp +OUTPUT := cylinder2d diff --git a/apps/adrian/cylinder2d/optimized_grid_n20/module.mk b/apps/adrian/cylinder2d/optimized_grid_n20/module.mk new file mode 100644 index 0000000..1190482 --- /dev/null +++ b/apps/adrian/cylinder2d/optimized_grid_n20/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)))) |