OpenFOAM programming tutorial

OpenFOAM programming tutorial

-

Documents
55 pages
Lire
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

POLITECNICO DI MILANO CHALMERSOpenFOAM programming tutorialTommaso LucchiniDepartment of EnergyPolitecnico di MilanoTommaso Lucchini/ OpenFOAM programming tutorialPOLITECNICO DI MILANO CHALMERSOutline• Overview of the OpenFOAM structure• A look at icoFoam• Customizing an application• Implementing a transport equation in a new application• Customizing a boundary condition• General informationTommaso Lucchini/ OpenFOAM programming tutorialPOLITECNICO DI MILANO CHALMERSStructure of OpenFOAMThe OpenFOAM code is structures as follows (typefoam and thenls).• applications: source files of all the executables:◮ solvers◮ utilities◮ bin◮ test• bin: basic executable scripts.• doc: pdf and Doxygen documentation.◮ Doxygen◮ Guides-a4• lib: compiled libraries.• src: source library files.• test: library test source files.• tutorials: tutorial cases.• wmake: compiler settings.Tommaso Lucchini/ OpenFOAM programming tutorialPOLITECNICO DI MILANO CHALMERSStructure of OpenFOAMNavigating the source code• Some useful commands to navigate inside the OpenFOAM sources:◮ app =$WM_PROJECT_DIR/applications◮ sol =$WM_PROJECT_DIR/applications/solvers◮ util =$WM_PROJECT_DIR/applications/utilities◮ src =$WM_PROJECT_DIR/src• Environment variables:◮ $FOAM_APP = $WM_PROJECT_DIR/applications◮ $FOAM_SOLVERS = $WM_PROJECT_DIR/applications/solvers◮ $FOAM_UTILITIES = $WM_PROJECT_DIR/applications/utilities◮ $FOAM_SRC = $WM_PROJECT_DIR/src• OpenFOAM source code serves ...

Sujets

Informations

Publié par
Nombre de visites sur la page 948
Langue English
Signaler un problème
POLITECNICODIMIALONHCLAEMSRmaomTihccuLosFnepO/inmaimgnutAOpMorrg
Tommaso Lucchini
Department of Energy Politecnico di Milano
torial
OpenFOAM programming tutorial
PTILOLAMICHNONIECDICOSRLAEMTmouLccamostotualriamgrngmiAOFnorpMinihepO/
Outline
Customizing an application
Implementing a transport equation in a new application
General information
Customizing a boundary condition
Overview of the OpenFOAM structure
A look at icoFoam
NIECITOLPRSLAEMONHCIMALOCIDutotirla
Structure of OpenFOAM The OpenFOAM code is structures as follows (typefoamand thenls). applications: source les of all the executables: solvers utilities bin test
bin: basic executable scripts.
doc: pdf and Doxygen documentation. Doxygen Guides-a4
src: source library les.
lib: compiled libraries.
tutorials: tutorial cases.
test: library test source les.
nFOAMprogrammingosamccuLinihepO/omT
wmake: compiler settings.
CIDOMILIOPILETNCSEROCANLMHAtgturoail
OpenFOAM source code serves two functions:  Ready to run inEfcient and customised top-level solver for class of physics. a manner of commercial CFD/CCM software Example of OpenFOAM classes and library functionality in use
Structure of OpenFOAM Navigating the source code
commands to navigate inside the OpenFOAM sources:Some useful app=$WM_PROJECT_DIR/applications sol=$WM PROJECT DIR/applications/solvers _ _ util=$WM PROJECT DIR/applications/utilities _ _ src=$WM PROJECT DIR/src _ _
Environment variables:  $WM PROJECT DIR/applications =$FOAM APP _ _ _ $FOAM SOLVERS $WM PROJECT DIR/applications/solvers = _ _ _ $FOAM UTILITIES = $WM PROJECT DIR/applications/utilities _ _ _ $FOAM SRC $WM PROJECT DIR/src = _ _ _
cuLosammpO/inihcprAMFOeninmmraogTo
Walk through a simple solver
Solver walk-through:icoFoam Types of les Header les Located before the entry line of the executable int main(int argc, char* argv[]) Contain various class denitions Grouped together for easier use Include les Often repeated code snippets, e.g. mesh creation, Courant number calculation and similar Held centrally for easier maintenance Enforce consistent naming between executables, e.g.mesh,runTime Local implementation les Main code, named consistently with the executable createFields.H
ltutgairooToLucmmasi/OpchinMArpneOFmmnigoarPLOTICERSMEIMIDOCINLAHCONAL
NCCIILETOPLMEROCHAILANODIMSsomaomTnihiccLuroMpamgrpe/OOAnFlair
Walk through icoFoam File organization solcd incompressiblecd icoFoam TheicoFoamdirectory consists of what follows (typels): createFields.H FoamX/ icoFoam.C icoFoam.dep Make/ TheFoamXdirectory is for pre-processing. TheMakedirectory contains instructions for thewmakecompilation command. icoFoam.Cis the main le, whilecreateFields.His included byicoFoam.C. The lefvCFD.H,included byicoFoam.C, contains all the class denitions which are needed byicoFoam. See the leMake/optionsto understand wherefvCFD.His included from: $FOAM_SRC/finiteVolume/lnInclude/fvCFD.H, symbolic link to: $FOAM SRC/finiteVolume/cfdTools/general/include/fvCFD.H _ Use the commandfind PATH -iname "*LETTERSINFILENAME*"to nd where inPATHa le name containingLETTERSFILENAMEin its le name is located. _ _ Example:find $WM PROJECT DIR -iname "*fvCFD.H*"
gnimotut
PECNIOLITMILACODItutgnimm
Walk through icoFoam A look into fvCFD.H
#include "Time.H" #include "fvMesh.H" #include "fvc.H" #include "fvMatrices.H" #include "fvm.H" #include "linear.H" #include "calculatedFvPatchFields.H" #include "fixedValueFvPatchFields.H" #include "adjustPhi.H" #include "findRefCell.H" #include "mathematicalConstants.H"
lairo
The inclusion les beforemain are all the class denitions required byicoFoam. Have a look into the source les to understand what these classes do.
#include "OSspecific.H" #include "argList.H"
#ifndef namespaceFoam #define namespaceFoam using namespace Foam; #endif
#endif
#ifndef fvCFD H _ #define fvCFD H _
#include "parRun.H"
mmsaoThcniLocuenFOi/OpograAMprRSALMENOCH
LMHASERNCETDOCILIMICONAILOPTmaomLusohiccammingtutorial
Walk through icoFoam A look into icoFoam.C, case setup and variable initialization icoFoamstarts with int main(int argc, char *argv[]) whereint argcandchar *argv[]are the number of parameters and the actual parameters used when runningicoFoam.
inO/epFnAOpMorrg
# include "createTime.H" # include "createMesh.H" # include "createFields.H" # include "initContinuityErrs.H" where all the included les exceptcreateFields.Hare in $FOAM SRC/finiteVolume/lnInclude. _
The case is initialized by: # include "setRootCase.H"
createFields.His located in theicoFoamdirectory. It initializes all the variables used inicoFoama look inside it and see how variables are. Have created.
saLooTmmni/icuhcc::g=-fvp));rad(los=nqEU(evSREOPILETNCANOCHALMICODIMILarmmrpgoOFMApOne
Walk through icoFoam A look into icoFoam.C, time-loop code
The momentum equations are dened and a velocity predictor is solved by: fvVectorMatrix UEqn ( fvm::ddt(U) + fvm::div(phi, U) - fvm::laplacian(nu, U) );
ThefvSolutionsubdictionaryPISOis read, and the Courant Number is calculated and written to the screen by (use thefindcommand): # include "readPISOControls.H" # include "CourantNo.H"
The time-loop starts by: for (runTime++; !runTime.end(); runTime++) and the rest is done at each time-step
ialutoringt
Tammo
A PISO corrector loop is initialized by: for (int corr=0; corr<nCorr; corr++) The PISO algorithm uses these member functions: A()returns the central coefcients of anfvVectorMatrix H()returns the H operation source of anfvVectorMatrix Sf()returns cell face area vector of anfvMesh flux()returns the face ux eld from anfvScalarMatrix correctBoundaryConditions()corrects the boundary elds of a volVectorField Identify the object types (classes) and use the OpenFOAM Doxygen (oa/f:/tpceursom.thlmyxeg/ntht/doc/Doforge.ne) to better understand them what they do
Walk through icoFoam A look into icoFoam.C, the PISO loop
alritognutmaimorrgAOpMpenFni/OcchisoLuPOCNICLITEILANODIMMLRECOAHS
CIDOETNCNACOMILIERSHALMLIPO
At the end oficoFoamthere are some write statements runTime.write();
Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl;
write()that all the variables that were dened as anmakes sure IOobject withIOobject::AUTO WRITEare written to the time directory according to the _ settings in the$FOAM_CASE/system/controlDictle. elapsedCPUTime()is the elapsed CPU time. elapsedClockTime()is the elapsed wall clock time.
Walk through icoFoam A look into icoFoam.C, write statements
alTmaomLusoccihinO/epFnAOpMrogrammingtutori