35
[302.044] Numerical Methods in Fluid Dynamics OpenFOAM Tutorial Finite Volume Method, Dictionary Syntax, and Implementation Details Univ. Assist. MSc. Francesco Roman [email protected] December 11th, 2014

[302.044] Numerical Methods in Fluid Dynamics …info.tuwien.ac.at/ViennaOpenFOAMUserGroup/9thb... · OpenFOAM Tutorial Finite Volume Method, Dictionary ... [email protected]

Embed Size (px)

Citation preview

[302.044] Numerical Methodsin Fluid Dynamics

OpenFOAM TutorialFinite Volume Method, Dictionary Syntax,

and Implementation Details

Univ. Assist. MSc. Francesco Romanò

[email protected]

December 11th, 2014

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

Outline

1 Open FOAMblockMeshDictInitial Conditionstransport PropertiescontrolDictfvSchemesfvSolutionRunning OpenFOAM

[302.044] – Univ. Assist. MSc. Francesco Romanò 2/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMDescription of the Software

OpenFOAM: Description of the Software

. The OpenFOAM CFD Toolbox is a free, open source CFDsoftware package which solves using a collocation FVM;

. It can solve complex fluid flows involving chemicalreactions, turbulence and heat transfer, solid dynamicsand electromagnetics and includes tools for meshing, pre-and post-processing;

. Almost everything runs in parallel as standard;

. OpenFOAM offers users possibility to customise and extendthe existing functionality.

[302.044] – Univ. Assist. MSc. Francesco Romanò 3/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMDescription of the Software

OpenFOAM: Description of the Software

. The OpenFOAM CFD Toolbox is a free, open source CFDsoftware package which solves using a collocation FVM;

. It can solve complex fluid flows involving chemicalreactions, turbulence and heat transfer, solid dynamicsand electromagnetics and includes tools for meshing, pre-and post-processing;

. Almost everything runs in parallel as standard;

. OpenFOAM offers users possibility to customise and extendthe existing functionality.

[302.044] – Univ. Assist. MSc. Francesco Romanò 3/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMDescription of the Software

OpenFOAM: Description of the Software

. The OpenFOAM CFD Toolbox is a free, open source CFDsoftware package which solves using a collocation FVM;

. It can solve complex fluid flows involving chemicalreactions, turbulence and heat transfer, solid dynamicsand electromagnetics and includes tools for meshing, pre-and post-processing;

. Almost everything runs in parallel as standard;

. OpenFOAM offers users possibility to customise and extendthe existing functionality.

[302.044] – Univ. Assist. MSc. Francesco Romanò 3/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMDescription of the Software

OpenFOAM: Description of the Software

. The OpenFOAM CFD Toolbox is a free, open source CFDsoftware package which solves using a collocation FVM;

. It can solve complex fluid flows involving chemicalreactions, turbulence and heat transfer, solid dynamicsand electromagnetics and includes tools for meshing, pre-and post-processing;

. Almost everything runs in parallel as standard;

. OpenFOAM offers users possibility to customise and extendthe existing functionality.

[302.044] – Univ. Assist. MSc. Francesco Romanò 3/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMblockMeshDict

OpenFOAM: blockMeshDict

. <problem_folder>/constant/polyMesh/blockMeshDict

◦ initial banner:/*--------------------------------*- C++ -*----------------------------------*\| ========= | || \\ / F ield | OpenFOAM: The Open Source CFD Toolbox || \\ / O peration | Version: 2.2.2 || \\ / A nd | Web: www.OpenFOAM.org || \\/ M anipulation | |\*---------------------------------------------------------------------------*/

◦ FoamFile: sub-dictionary delimited by curly bracketscontaining code’s information:

FoamFile{

version 2.0;format ascii;class dictionary;object blockMeshDict;

}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

[302.044] – Univ. Assist. MSc. Francesco Romanò 4/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMblockMeshDict

OpenFOAM: blockMeshDict

. <problem_folder>/constant/polyMesh/blockMeshDict

◦ scaling parameter:

convertToMeters 0.1;

◦ vertices: function delimited by parenthesis specifyingCartesian coordinates of the domain vertices1:

vertices(

(0 0 0)(1 0 0)

...(1 1 0.1)(0 1 0.1)

);1For 2–D cases, it is necessary to indicate suitable BCs.

[302.044] – Univ. Assist. MSc. Francesco Romanò 5/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMblockMeshDict

OpenFOAM: blockMeshDict

. <problem_folder>/constant/polyMesh/blockMeshDict

◦ blocks: function specifying how many mesh blocks formthe discrete domain and their properties.

◦ hex: function specifying the vertices of this block.◦ simpleGrading: function specifying how to distribute

the mesh. The ratio between the firstand the last element of the mesh blockis setted 1 for each direction: it meansit is used a constant discretization inx, y (“and z”).

blocks(

hex(0 1 2 3 4 5 6 7)(20 20 1)simpleGrading(1 1 1));

[302.044] – Univ. Assist. MSc. Francesco Romanò 6/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMblockMeshDict

OpenFOAM: blockMeshDict

. <problem_folder>/constant/polyMesh/blockMeshDict

◦ edges: tool that defines all the non–straight edges.edges();

◦ edges: There are different sort of definable edges: arc,simpleSpline, polyLine, etc...

◦ arc: sort of edge which defines a circular arc, (in thiscase between nodes 0 and 5, and passing throughthe point in parenthesis).

edges(

arc 0 5 (0.469846 0.17101 0));

[302.044] – Univ. Assist. MSc. Francesco Romanò 7/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMblockMeshDict

OpenFOAM: blockMeshDict. <problem_folder>/constant/polyMesh/blockMeshDict

◦ boundary: function specifying name, type and facesof each sub-bound. They are delimitedby curly brackets after each of their name.

boundary(<NameOfTheBoundary>{

type <TypeOfTheBoundary>;faces(

(<4EdgesOfTheCurrentFace>));

});

[302.044] – Univ. Assist. MSc. Francesco Romanò 8/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMblockMeshDict

OpenFOAM: blockMeshDict

. <problem_folder>/constant/polyMesh/blockMeshDict

◦ type: type of the boundary that can be wall, empty,patch, etc...

◦ mergePatchPairs: tool that defines a list of patches tobe meshed using a reciprocal corre-spondence of master and slave.

mergePatchPairs();// ***************************************** //

◦ running commands:<problem\_folder>$ blockMesh

[302.044] – Univ. Assist. MSc. Francesco Romanò 9/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMInitial Conditions

OpenFOAM: Initial Conditions

. <problem_folder>/0/p

◦ initial banner:/*--------------------------------*- C++ -*----------------------------------*\| ========= | || \\ / F ield | OpenFOAM: The Open Source CFD Toolbox || \\ / O peration | Version: 2.2.2 || \\ / A nd | Web: www.OpenFOAM.org || \\/ M anipulation | |\*---------------------------------------------------------------------------*/

◦ FoamFile: sub-dictionary delimited by curly bracketscontaining code’s information:

FoamFile{

version 2.0;format ascii;class volScalarField;object p;

}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

[302.044] – Univ. Assist. MSc. Francesco Romanò 10/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMInitial Conditions

OpenFOAM: Initial Conditions

. <problem_folder>/0/p

◦ dimensions of the system:dimensions [0 2 -2 0 0 0 0]; % m^2/s^2

◦ internalField: it can be uniform (only one value) ornot (scalar point-wise field)

internalField uniform 0;

[302.044] – Univ. Assist. MSc. Francesco Romanò 11/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMblockMeshDict

OpenFOAM: blockMeshDict

. <problem_folder>/0/p

◦ boundaryField: function containing boundary condi-tions referred to the name already usedcreating the mesh.

boundaryField{<NameOfTheBoundary>{

type <TypeOfTheBoundaryCondition>;}}// ***************************************** //

◦ type: type of the boundary condition that can bezeroGradient, fixedValue, empty, etc...

[302.044] – Univ. Assist. MSc. Francesco Romanò 12/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMInitial Conditions

OpenFOAM: Initial Conditions

. <problem_folder>/0/U

◦ initial banner:/*--------------------------------*- C++ -*----------------------------------*\| ========= | || \\ / F ield | OpenFOAM: The Open Source CFD Toolbox || \\ / O peration | Version: 2.2.2 || \\ / A nd | Web: www.OpenFOAM.org || \\/ M anipulation | |\*---------------------------------------------------------------------------*/

◦ FoamFile: sub-dictionary delimited by curly bracketscontaining code’s information:

FoamFile{

version 2.0;format ascii;class volVectorField;object U;

}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

[302.044] – Univ. Assist. MSc. Francesco Romanò 13/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMInitial Conditions

OpenFOAM: Initial Conditions

. <problem_folder>/0/U

◦ dimensions of the system:dimensions [0 1 -1 0 0 0 0]; % m/s

◦ internalField: it can be uniform (only one vectorialvalue) or not (vectorial point-wise field)

internalField uniform (0 0 0);

[302.044] – Univ. Assist. MSc. Francesco Romanò 14/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMblockMeshDict

OpenFOAM: blockMeshDict

. <problem_folder>/0/U

◦ boundaryField: function containing boundary condi-tions referred to the name already usedcreating the mesh.

boundaryField{<NameOfTheBoundary>{

type <TypeOfTheBoundaryCondition>;}}// ***************************************** //

◦ type: type of the boundary condition that can bezeroGradient, fixedValue, empty, etc...

[302.044] – Univ. Assist. MSc. Francesco Romanò 15/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMtransportProperties

OpenFOAM: transportProperties

. <problem_folder>/constant/transportProperties

◦ initial banner:/*--------------------------------*- C++ -*----------------------------------*\| ========= | || \\ / F ield | OpenFOAM: The Open Source CFD Toolbox || \\ / O peration | Version: 2.2.2 || \\ / A nd | Web: www.OpenFOAM.org || \\/ M anipulation | |\*---------------------------------------------------------------------------*/

◦ FoamFile: sub-dictionary delimited by curly bracketscontaining code’s information:

FoamFile{

version 2.0;format ascii;class dictionary;location "constant"object transportProperties;

}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

[302.044] – Univ. Assist. MSc. Francesco Romanò 16/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMtransportProperties

OpenFOAM: transportProperties

. <problem_folder>/constant/transportProperties

◦ physical properties of the system2:

nu nu [ 0 2 -1 0 0 0 0 ] 0.01; % m^2/s

// **************************************** //

2In the case of incompressible single-phase flows, just kinematicviscosity has to be defined. Other properties should be eventuallyincluded in the transportProperties dictionary.

[302.044] – Univ. Assist. MSc. Francesco Romanò 17/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMcontrolDict

OpenFOAM: controlDict

. <problem_folder>/system/controlDict

◦ initial banner:/*--------------------------------*- C++ -*----------------------------------*\| ========= | || \\ / F ield | OpenFOAM: The Open Source CFD Toolbox || \\ / O peration | Version: 2.2.2 || \\ / A nd | Web: www.OpenFOAM.org || \\/ M anipulation | |\*---------------------------------------------------------------------------*/

◦ FoamFile: sub-dictionary delimited by curly bracketscontaining code’s information:

FoamFile{

version 2.0;format ascii;class dictionary;location "system";object controlDict;

}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

[302.044] – Univ. Assist. MSc. Francesco Romanò 18/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMcontrolDict

OpenFOAM: controlDict

. <problem_folder>/system/controlDict

◦ application: function that defines the model to use.

application icoFoam;

◦ startFrom: command used to set the initial time of thesimulation. In this case the command isstarTime and, in the next row, it indicatesthat the simulation has tin = 0. The initialcondition is then in a directory named 0.To use a previous calculation, instead of thecommand startTime, latestTime is used.

startFrom startTime;startTime 0;

[302.044] – Univ. Assist. MSc. Francesco Romanò 19/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMcontrolDict

OpenFOAM: controlDict. <problem_folder>/system/controlDict

◦ stopAt: command used to set the final time of the simu-lation. In this case the command is endTimeand indicates that the simulation has tfin = .5.

stopAt endTime;endTime 0.5;

◦ deltaT: defines the time step used for the simulation.Numerical stability problems can be due to timeand the spatial discretization steps. Theoretical-ly analysing the incompressible flow solver,the stability is controlled by the local Courantnumber, which has to be less than one.

deltaT 0.005;

[302.044] – Univ. Assist. MSc. Francesco Romanò 20/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMcontrolDict

OpenFOAM: controlDict. <problem_folder>/system/controlDict

◦ writeControl: defines the kind of control used to savedata. The command timeStep saveseach (writeInterval)x(time steps).The storage is in folders created usingas name the time of saving.

◦ purgeWrite: defines a limit on the number of storage di-rectories: if the needed directories are morethan the indicator, the previous data arecyclically overwritten. Not to define a limitpurgeWrite has to be 0.

writeControl timeStep;writeInterval 20;purgeWrite 0;

[302.044] – Univ. Assist. MSc. Francesco Romanò 21/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMcontrolDict

OpenFOAM: controlDict

. <problem_folder>/system/controlDict

◦ further instruction for saving the data:

writeFormat ascii;writePrecision 6;writeCompression off;timeFormat general;timePrecision 6;runTimeModifiable true;

// ***************************************** //

[302.044] – Univ. Assist. MSc. Francesco Romanò 22/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMfvSchemes

OpenFOAM: fvSchemes

. <problem_folder>/system/fvSchemes

◦ initial banner:/*--------------------------------*- C++ -*----------------------------------*\| ========= | || \\ / F ield | OpenFOAM: The Open Source CFD Toolbox || \\ / O peration | Version: 2.2.2 || \\ / A nd | Web: www.OpenFOAM.org || \\/ M anipulation | |\*---------------------------------------------------------------------------*/

◦ FoamFile: sub-dictionary delimited by curly bracketscontaining code’s information:

FoamFile{

version 2.0;format ascii;class dictionary;location "system";object fvSchemes;

}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

[302.044] – Univ. Assist. MSc. Francesco Romanò 23/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMfvSchemes

OpenFOAM: fvSchemes

. <problem_folder>/system/fvSchemes

◦ ddtSchemes: contains the information about the methodto discretize the temporal derivative.Euler means that the time derivative isdiscretized using an Implicit Euler scheme.Other options are: CrankNicholson,backward, etc...

ddtSchemes{

default Euler;}

[302.044] – Univ. Assist. MSc. Francesco Romanò 24/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMfvSchemes

OpenFOAM: fvSchemes

. <problem_folder>/system/fvSchemes

◦ gradSchemes: contains the information about theselected method to discretize the gradient.Gauss linear means that OpenFOAMdiscretizes the gradient operator with thelinear Gaussian method. Another methodis the least squares method settingleastSquares instead of Gauss linear.

gradSchemes{

default Gauss linear;grad(p) Gauss linear;

}

[302.044] – Univ. Assist. MSc. Francesco Romanò 25/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMfvSchemes

OpenFOAM: fvSchemes. <problem_folder>/system/fvSchemes

◦ divSchemes and laplacianSchemes:contains information about the selected method fordiscretizing the divergence and laplacian operators.

divSchemes{

default none;div(phi,U) Gauss linear;

}laplacianSchemes{

default none;laplacian(nu,U) Gauss linear orthogonal;laplacian((1|A(U)),p) Gauss linear orthogonal;

}[302.044] – Univ. Assist. MSc. Francesco Romanò 26/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMfvSchemes

OpenFOAM: fvSchemes

. <problem_folder>/system/fvSchemes

◦ interpolationSchemes: sets the interpolation method.

interpolationSchemes{

default linear;interpolate(HbyA) linear;

}

◦ snGradSchemes: sets the treatment for (·),n.

snGradSchemes{

default orthogonal;}

[302.044] – Univ. Assist. MSc. Francesco Romanò 27/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMfvSchemes

OpenFOAM: fvSchemes

. <problem_folder>/system/fvSchemes

◦ fluxRequired: sets the information about fields forwhich is required to calculate a flux.

fluxRequired{

default no;p ;

}// *************************************** //

[302.044] – Univ. Assist. MSc. Francesco Romanò 28/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMfvSolution

OpenFOAM: fvSolution

. <problem_folder>/system/fvSolution

◦ initial banner:/*--------------------------------*- C++ -*----------------------------------*\| ========= | || \\ / F ield | OpenFOAM: The Open Source CFD Toolbox || \\ / O peration | Version: 2.2.2 || \\ / A nd | Web: www.OpenFOAM.org || \\/ M anipulation | |\*---------------------------------------------------------------------------*/

◦ FoamFile: sub-dictionary delimited by curly bracketscontaining code’s information:

FoamFile{

version 2.0;format ascii;class dictionary;location "system";object fvSolution;

}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

[302.044] – Univ. Assist. MSc. Francesco Romanò 29/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMfvSolution

OpenFOAM: fvSolution

. <problem_folder>/system/fvSolution

◦ solvers: defines the set-up of the linear solvers.

solvers{

<Var>{

solver <SolverType>;preconditioner <PreconditionerType>;tolerance <AbsoluteTollerance>;relTol <RelativeTollerance>;

}}

[302.044] – Univ. Assist. MSc. Francesco Romanò 30/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMfvSolution

OpenFOAM: fvSolution

. <problem_folder>/system/fvSolution

◦ <SplittingOperator>: defines the respective treatmentof pressure and velocity.

PISO{

nCorrectors 2;nNonOrthogonalCorrectors 0;pRefCell 0;pRefValue 0;

}// **************************************** //

[302.044] – Univ. Assist. MSc. Francesco Romanò 31/32

Open FOAMblockMeshDictInitialConditionstransportPropertiescontrolDictfvSchemesfvSolutionRunningOpenFOAM

OpenFOAMRunning a Case

OpenFOAM: Running a Case

. <problem_folder>

◦ running a solver in foreground:

<problem_folder>$ <solverName>

◦ running a solver in background:

<problem_folder>$ <solverName> > log &

◦ data visualization:

<problem_folder>$ paraFoam

[302.044] – Univ. Assist. MSc. Francesco Romanò 32/32