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/multiComponent/phaseSeparation2d/Makefile | 105 ++++++++++
.../phaseSeparation2d/definitions.mk | 30 +++
.../multiComponent/phaseSeparation2d/module.mk | 29 +++
.../phaseSeparation2d/phaseSeparation2d.cpp | 216 +++++++++++++++++++++
4 files changed, 380 insertions(+)
create mode 100644 examples/multiComponent/phaseSeparation2d/Makefile
create mode 100644 examples/multiComponent/phaseSeparation2d/definitions.mk
create mode 100644 examples/multiComponent/phaseSeparation2d/module.mk
create mode 100644 examples/multiComponent/phaseSeparation2d/phaseSeparation2d.cpp
(limited to 'examples/multiComponent/phaseSeparation2d')
diff --git a/examples/multiComponent/phaseSeparation2d/Makefile b/examples/multiComponent/phaseSeparation2d/Makefile
new file mode 100644
index 0000000..a953954
--- /dev/null
+++ b/examples/multiComponent/phaseSeparation2d/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/multiComponent/phaseSeparation2d/definitions.mk b/examples/multiComponent/phaseSeparation2d/definitions.mk
new file mode 100644
index 0000000..4f8999f
--- /dev/null
+++ b/examples/multiComponent/phaseSeparation2d/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 := phaseSeparation2d.cpp
+OUTPUT := phaseSeparation2d
diff --git a/examples/multiComponent/phaseSeparation2d/module.mk b/examples/multiComponent/phaseSeparation2d/module.mk
new file mode 100644
index 0000000..1190482
--- /dev/null
+++ b/examples/multiComponent/phaseSeparation2d/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/multiComponent/phaseSeparation2d/phaseSeparation2d.cpp b/examples/multiComponent/phaseSeparation2d/phaseSeparation2d.cpp
new file mode 100644
index 0000000..c4b1839
--- /dev/null
+++ b/examples/multiComponent/phaseSeparation2d/phaseSeparation2d.cpp
@@ -0,0 +1,216 @@
+/* This file is part of the OpenLB library
+ *
+ * Copyright (C) 2014 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.
+*/
+
+/* phaseSeparation2d.cpp:
+ * In this example the simulation is initialized with a given
+ * density plus a small random number all over the domain. This
+ * condition is unstable and leads to liquid-vapor phase separation.
+ * Boundaries are assumed to be periodic. This example shows the
+ * usage of multiphase flow.
+ */
+
+
+#include "olb2D.h"
+#include "olb2D.hh" // use only generic version!
+#include
+#include
+
+using namespace olb;
+using namespace olb::descriptors;
+using namespace olb::graphics;
+using namespace std;
+
+typedef double T;
+#define DESCRIPTOR ShanChenDynOmegaForcedD2Q9Descriptor
+
+
+// Parameters for the simulation setup
+const int maxIter = 10000;
+const int nx = 201;
+const int ny = 201;
+
+
+// Stores geometry information in form of material numbers
+void prepareGeometry( SuperGeometry2D& superGeometry ) {
+
+ OstreamManager clout( std::cout,"prepareGeometry" );
+ clout << "Prepare Geometry ..." << std::endl;
+
+ // Sets material number for fluid
+ superGeometry.rename( 0,1 );
+
+ // 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( SuperLattice2D& sLattice,
+ Dynamics& bulkDynamics1,
+ SuperGeometry2D& superGeometry ) {
+
+ // Material=1 -->bulk dynamics
+ sLattice.defineDynamics( superGeometry, 1, &bulkDynamics1 );
+
+ // Initial conditions
+ AnalyticalConst2D noise( 2. );
+ std::vector v( 2,T() );
+ AnalyticalConst2D zeroVelocity( v );
+ AnalyticalConst2D oldRho( 199. );
+ AnalyticalRandom2D random;
+ AnalyticalIdentity2D newRho( random*noise+oldRho );
+
+ // Initialize all values of distribution functions to their local equilibrium
+ sLattice.defineRhoU( superGeometry, 1, newRho, zeroVelocity );
+ sLattice.iniEquilibrium( superGeometry, 1, newRho, zeroVelocity );
+
+ // Make the lattice ready for simulation
+ sLattice.initialize();
+}
+
+// Output to console and files
+void getResults( SuperLattice2D& sLattice, int iT,
+ SuperGeometry2D& superGeometry, Timer& timer ) {
+
+ OstreamManager clout( std::cout,"getResults" );
+
+ SuperVTMwriter2D vtmWriter( "phaseSeparation2d" );
+ SuperLatticeVelocity2D velocity( sLattice );
+ SuperLatticeDensity2D density( sLattice );
+ vtmWriter.addFunctor( velocity );
+ vtmWriter.addFunctor( density );
+
+ const int vtkIter = 20;
+ const int statIter = 20;
+
+ 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 );
+ vtmWriter.write( geometry );
+ vtmWriter.write( cuboid );
+ vtmWriter.write( rank );
+
+ vtmWriter.createMasterFile();
+ }
+
+ // Writes the vtk files
+ if ( iT%vtkIter==0 ) {
+ clout << "Writing VTK and JPEG..." << std::endl;
+ vtmWriter.write( iT );
+
+ BlockReduction2D2D planeReduction( density, 600, BlockDataSyncMode::ReduceOnly );
+ // write output as JPEG
+ heatmap::write(planeReduction, iT);
+ }
+
+ // Writes output on the console
+ if ( iT%statIter==0 ) {
+ // Timer console output
+ timer.update( iT );
+ timer.printStep();
+
+ // Lattice statistics console output
+ sLattice.getStatistics().print( iT,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);
+
+ const T omega1 = 1.0;
+ const T G = -120.;
+
+ // === 2rd Step: Prepare Geometry ===
+
+ // Instantiation of a cuboidGeometry with weights
+#ifdef PARALLEL_MODE_MPI
+ const int noOfCuboids = singleton::mpi().getSize();
+#else
+ const int noOfCuboids = 1;
+#endif
+ CuboidGeometry2D cuboidGeometry( 0, 0, 1, nx, ny, noOfCuboids );
+
+ // Periodic boundaries in x- and y-direction
+ cuboidGeometry.setPeriodicity( true, true );
+
+ // Instantiation of a loadBalancer
+ HeuristicLoadBalancer loadBalancer( cuboidGeometry );
+
+ // Instantiation of a superGeometry
+ SuperGeometry2D superGeometry( cuboidGeometry,loadBalancer,2 );
+
+ prepareGeometry( superGeometry );
+
+ // === 3rd Step: Prepare Lattice ===
+ SuperLattice2D sLattice( superGeometry );
+
+ ForcedShanChenBGKdynamics bulkDynamics1 (
+ omega1, instances::getExternalVelocityMomenta() );
+
+ std::vector rho0;
+ rho0.push_back( 1 );
+ rho0.push_back( 1 );
+ ShanChen94 interactionPotential;
+ ShanChenForcedSingleComponentGenerator2D coupling( G,rho0,interactionPotential );
+
+ sLattice.addLatticeCoupling( coupling, sLattice );
+
+ prepareLattice( sLattice, bulkDynamics1, superGeometry );
+
+ // === 4th Step: Main Loop ===
+ int iT = 0;
+ clout << "starting simulation..." << endl;
+ Timer timer( maxIter, superGeometry.getStatistics().getNvoxel() );
+ timer.start();
+
+ for ( iT = 0; iT < maxIter; ++iT ) {
+
+ // === 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();
+ sLattice.communicate();
+ sLattice.executeCoupling();
+
+ // === 7th Step: Computation and Output of the Results ===
+ getResults( sLattice, iT, superGeometry, timer );
+ }
+
+ timer.stop();
+ timer.printSummary();
+}
--
cgit v1.2.3