Moving boundary in openFoam
Linear motion -‐ OpenFoam #2
Julien Réveillon
University of Rouen
and
CORIA
[email protected]
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 main(int argc, char *argv[])
{ #include "setRootCase.H" #include "createTime.H" #include "createDynamicFvMesh.H" #include "initContinuityErrs.H" #include "createFields.H" #include "readTimeControls.H" pimpleControl pimple(mesh);
/* JR
surfaceScalarField phiAbs("phiAbs", phi); fvc::makeAbsolute(phiAbs, 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::reconstruct(fvc::meshPhi(U)); }
*/
// 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 { type zeroGradient; } fixedWalls { type zeroGradient; } atmosphere { type inletOutlet; inletValue uniform 0; value uniform 0; } frontAndBack { type 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 { type buoyantPressure; value uniform 0; } fixedWalls { type buoyantPressure; value uniform 0; } atmosphere { type totalPressure; p0 uniform 0; U U; phi phi; rho rho; psi none; gamma 1; value uniform 0; } frontAndBack { type 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 volVectorField; location "0"; object U; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 1 -1 0 0 0 0]; internalField uniform (0 0 0); boundaryField { fixedWalls { type fixedValue; value uniform (0 0 0); } movingWall { type movingWallVelocity; value uniform (0 0 0); } atmosphere { type pressureInletOutletVelocity; value uniform (0 0 0); } frontAndBack { type 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 interDyMFoam; startFrom 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; // ************************************************************************* //