Moving boundary in openfoam Linear motion - OpenFoam #2 Julien Réveillon University of Rouen and CORIA Julien.reveillon@coria.fr http://www.cfdandco.com 7 juin 2012 Intent: The objective is to present the procedure to generate a moving boundary mesh. It is directly inspired of the work of Gonzalez [Mesh motion alternatives in OpenFoam Andreu Oliver Gonzalez December 2009, Göteborg, Sweden], which contains much more details. It has been adapted to the interdymfoam solver in order to work on a water tank case. Prerequisites: All the environment variables concerning openfoam must be correctly defined. OF solver compilation knowledge necessary c.f. OF #1). Procedure: 1/ Creation of the working repository jr:~/openfoam/jr-2.1.0/run$ cp -r $FOAM_TUTORIALS/multiphase/interDyMFoam/ras/damBreakWithObstacle movingbc 2/ Grid construction jr:~/openfoam/jr2.1.0/run$ cd movingbc jr:~/openfoam/jr2.1.0/run/movingbc$ gedit constant/polymesh/blockmeshdict And modify the file according to annex 1. jr:~/openfoam/jr/2.1.0/run/movingbc$ blockmesh
3/ Solver preparation interdymfoam is modified so that only the mesh motion is computed. No resolution of the fluid will be carried out. First, let's go in the user solver repository see OF #1). jr:~/openfoam/jr-2.1.0/run/movingbc$ cd ~/OpenFOAM/jr-2.1.0/solvers/ One will use interdymfoam. There is a small peculiarity : interdymfoam is part of interfoam solver and needs the «creatfields.h» file for the interfoam solver to compile. Thus we need to copy the complete interfoam + interdymfoam solver : jr:~/openfoam/jr-2.1.0/solvers$ cp -r $FOAM_SOLVERS/multiphase/interFoam BCFoam Just to be clear, rename interdymfoam : jr:~/openfoam/jr-2.1.0/solvers$ mv BCFoam/interDyMFoam BCFoam/meshBCFoam Then, continue the renaming jr:~/openfoam/jr-2.1.0/solvers$ cd BCFoam/meshBCFoam jr:~/openfoam/jr-2.1.0/solvers/bcfoam/meshbcfoam$ mv interdymfoam.c meshbcfoam.c in file Make/files jr:~/openfoam/jr-2.1.0/solvers/bcfoam/meshbcfoam$ gedit Make/files Modify warning : do not forget FOAM_USER_APPBIN) such as meshbcfoam.c EXE = $FOAM_USER_APPBIN)/meshBCFoam 4/Modification of the code Edit the solver: jr:~/openfoam/jr-2.1.0/solvers/bcfoam/meshbcfoam $ gedit meshbcfoam.c and comment the parts that does not concern the mesh.update. /* JR */ in annex 2). 5/Compilation jr:~/openfoam/jr- 2.1.0/solvers/BCFoam/meshBCFoam$ wclean
jr:~/openfoam/jr- 2.1.0/solvers/BCFoam/meshBCFoam$ wmake 6/ Initial Fields Back in your 'run' directory, initial fields. jr:~/openfoam/jr- 2.1.0/solvers/BCFoam/meshBCFoam$ cd ~/OpenFOAM/jr- 2.1.0/run/movingBC jr:~/openfoam/jr- 2.1.0/run/movingBC $ mv 0.org 0 jr:~/openfoam/jr- 2.1.0/run/movingBC $ gedit 0/alpha1 0/p_rgh 0/U Modify the face names so that it corresponds to boundaries and do not generate errors. Fields won't be used anyway. Annex 3-4- 5 7/ Set the prefcell and prefvalue jr:~/openfoam/jr- 2.1.0/run/movingBC/0$ cd.. jr:~/openfoam/jr- 2.1.0/run/movingBC$ gedit system/fvsolution Put the prefcell value to 0 prefvalue remains null). prefcell 0; in the PIMPLE section. 9/ Set the moving boundary properties. jr:~/openfoam/jr-2.1.0/run/movingbc$ gedit constant/dynamicmeshdict See Appendix 6 10/ Set the execution properties. jr:~/openfoam/jr- 2.1.0/run/movingBC$ gedit system/controldict See Appendix 7 11/ Run jr:~/openfoam/jr- 2.1.0/run/movingBC$ meshbcfoam
12/ Visualization
Annex 1 blockmeshdict /*--------------------------------*- C++ -*----------------------------------*\ ========= \\ / F ield OpenFOAM: The Open Source CFD Toolbox \\ / O peration Version: 1.6 \\ / A nd Web: http://www.openfoam.org \\/ M anipulation FoamFile version 2.0; format ascii; class dictionary; object blockmeshdict; converttometers 0.1; vertices -3 0 0) 0 0 0) 0 1 0) -3 1 0) -3 0 0.1) 0 0 0.1) 0 1 0.1) -3 1 0.1) ); blocks hex 0 1 2 3 4 5 6 7) 60 20 1) simplegrading 1 1 1) ); edges ); patches patch atmosphere 3 7 6 2) ) wall movingwall 0 4 7 3) ) wall fixedwalls 1 2 6 5) 1 5 4 0) ) empty frontandback 0 3 2 1) 4 5 6 7) ) ); mergepatchpairs );
Annex 2 meshbcfoam.c /*---------------------------------------------------------------------------*\ ========= \\ / F ield OpenFOAM: The Open Source CFD Toolbox \\ / O peration \\ / A nd Copyright C) 2011 OpenFOAM Foundation \\/ M anipulation ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM 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 3 of the License, or at your option) any later version. OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. Application meshbcfoam Description Solver for 2 incompressible, isothermal immiscible fluids using a VOF volume of fluid) phase-fraction based interface capturing approach, with optional mesh motion and mesh topology changes including adaptive re-meshing. #include "fvcfd.h" #include "dynamicfvmesh.h" #include "MULES.H" #include "subcycle.h" #include "interfaceproperties.h" #include "twophasemixture.h" #include "turbulencemodel.h" #include "pimplecontrol.h" int mainint argc, char *argv[]) #include "setrootcase.h" #include "createtime.h" #include "createdynamicfvmesh.h" #include "initcontinuityerrs.h" #include "createfields.h" #include "readtimecontrols.h" pimplecontrol pimplemesh);
/* JR surfacescalarfield phiabs"phiabs", phi); fvc::makeabsolutephiabs, U); #include "correctphi.h" #include "CourantNo.H" #include "setinitialdeltat.h"*/ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nstarting time loop\n" << endl; while runtime.run)) #include "readcontrols.h" #include "alphacourantno.h" #include "CourantNo.H" #include "setdeltat.h" runtime++; Info<< "Time = " << runtime.timename) << nl << endl; scalar timebeforemeshupdate = runtime.elapsedcputime); /* JR // Calculate the relative velocity used to map the relative flux phi volvectorfield Urel"Urel", U); */ if mesh.moving)) Urel -= fvc::reconstructfvc::meshphiu)); // Do any mesh changes mesh.update);
/* JR if mesh.changing)) Info<< "Execution time for mesh.update) = " << runtime.elapsedcputime) - timebeforemeshupdate << " s" << endl; gh = g & mesh.c); ghf = g & mesh.cf); if mesh.changing) && correctphi) #include "correctphi.h" if mesh.changing) && checkmeshcourantno) #include "meshcourantno.h" twophaseproperties.correct); #include "alphaeqnsubcycle.h" // --- Pressure-velocity PIMPLE corrector loop while pimple.loop)) #include "UEqn.H" // --- Pressure corrector loop while pimple.correct)) #include "peqn.h" */ if pimple.turbcorr)) turbulence->correct); runtime.write); Info<< "ExecutionTime = " << runtime.elapsedcputime) << " s" << " ClockTime = " << runtime.elapsedclocktime) << " s" << nl << endl; Info<< "End\n" << endl; return 0;
Annex 3 alpha1 /*--------------------------------*- C++ -*----------------------------------*\ ========= \\ / F ield OpenFOAM: The Open Source CFD Toolbox \\ / O peration Version: 2.1.0 \\ / A nd Web: www.openfoam.org \\/ M anipulation FoamFile version 2.0; format ascii; class volscalarfield; object alpha1; dimensions [0 0 0 0 0 0 0]; internalfield uniform 0; boundaryfield movingwall fixedwalls zerogradient; zerogradient; atmosphere inletoutlet; inletvalue uniform 0; value uniform 0; frontandback empty;
Annex 4 p_rgh /*--------------------------------*- C++ -*----------------------------------*\ ========= \\ / F ield OpenFOAM: The Open Source CFD Toolbox \\ / O peration Version: 2.1.0 \\ / A nd Web: www.openfoam.org \\/ M anipulation FoamFile version 2.0; format ascii; class volscalarfield; object p_rgh; dimensions [1-1 -2 0 0 0 0]; internalfield uniform 0; boundaryfield movingwall buoyantpressure; value uniform 0; fixedwalls buoyantpressure; value uniform 0; atmosphere totalpressure; p0 uniform 0; U U; phi phi; rho rho; psi none; gamma 1; value uniform 0; frontandback empty;
Annex 5 U /*--------------------------------*- C++ -*----------------------------------*\ ========= \\ / F ield OpenFOAM: The Open Source CFD Toolbox \\ / O peration Version: 2.1.0 \\ / A nd Web: www.openfoam.org \\/ M anipulation FoamFile version 2.0; format ascii; class location "0"; object U; volvectorfield; dimensions [0 1-1 0 0 0 0]; internalfield uniform 0 0 0); boundaryfield fixedwalls fixedvalue; value uniform 0 0 0); movingwall movingwallvelocity; value uniform 0 0 0); atmosphere pressureinletoutletvelocity; value uniform 0 0 0); frontandback empty;
Annex 6 /*--------------------------------*- C++ -*----------------------------------*\ ========= \\ / F ield OpenFOAM: The Open Source CFD Toolbox \\ / O peration Version: 2.1.0 \\ / A nd Web: www.openfoam.org \\/ M anipulation FoamFile version 2.0; format ascii; class dictionary; location "constant"; object dynamicmeshdict; dynamicfvmesh dynamicinkjetfvmesh; motionsolverlibs "libfvmotionsolvers.so" ); dynamicinkjetfvmeshcoeffs amplitude 0.3; frequency 2; refplanex 0;
Annex 7 /*--------------------------------*- C++ -*----------------------------------*\ ========= \\ / F ield OpenFOAM: The Open Source CFD Toolbox \\ / O peration Version: 2.1.0 \\ / A nd Web: www.openfoam.org \\/ M anipulation FoamFile version 2.0; format ascii; class dictionary; location "system"; object controldict; application startfrom interdymfoam; latesttime; starttime 0; stopat endtime; endtime 2; deltat 0.001; writecontrol timestep; writeinterval 10; purgewrite 0; writeformat ascii; writeprecision 6; writecompression uncompressed; timeformat general; timeprecision 6; runtimemodifiable yes; adjusttimestep no; maxco 0.1; maxalphaco 0.1; maxdeltat 1;