【OpenFOAM】学习module1
M1-overview OpenFOAM
of9
1.programming new solvers
solve
(
fvm::ddt(T) - fvm::laplacian(DT, T)
);
2.directory organization
键入tut,跳转到教程目录
类似的alias,查看方法:
vim $WM_PROJECT_DIR/etc/config.sh/alias
列出所有和OpenFOAM相关的alias
alias | grep -i "FOAM"
application:
solver,求解器代码
test,测试OpenFOAM类的一些测试案例
utilities,小工具(前处理、后处理、网格…)
bin:
shell脚本(foamInfo, paraFOam…)
doc:
user guide
programmer’s guide
Doxygen,在Allwmake这一步时间20分钟
firefox README.html
sudo apt-get install doxygen graphviz
doxygen -w html header.html footer.html customdoxygen.css
./Allwmake
cd ./html
firefox index.html
bin:
super dictionary controlDict
src:
this is the core of OpenFOAM
finiteVolume/lnInclude, fvCFD,h
tutorials:
interFoam
…
wmake:
wamke/rules,available compilers
3. search source code
find $WM_PROJECT_DIR -type d -name "*fvPatch*"
find $WM_PROJECT_DIR -type f -name "*fvPatch*"
grep -r -n "LES" $FOAM_SOLVERS
find $FOAM_TUTORIALS -iname "*dict"
find $FOAM_TUTORIALS -type f | xargs grep 'slip'
find $FOAM_SRC -name "*slip*"
find $WM_PROJECT_DIR -type f | xargs grep -sl 'noParallel'
4. structure of an OpenFOAM application/utility
/OpenFOAM/OpenFOAM-9/applications/solvers/incompressible/icoFoam
.
├── createFields.H
├── icoFoam.C
└── Make
├── files
└── options
icoFoam.C
fvVectorMatrix UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
- fvm::laplacian(nu, U)
);
if (piso.momentumPredictor())
{
solve(UEqn == -fvc::grad(p));
}
Make/files
solverName name and location of the output file
icoFoam.C
EXE = $(FOAM_APPBIN)/icoFoam
Make/options
specifies directions to research for include files and libraries to link the solver against
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lmeshTools
surfaceAutoPatch
surfaceAutoPatch -doc
surfaceAutoPatch -help
case: tut icoFoam/cavity
├── 0
│ ├── p
│ └── U
├── constant
│ ├── polyMesh
│ │ ├── boundary
│ │ ├── faces
│ │ ├── neighbour
│ │ ├── owner
│ │ └── points
│ └── transportProperties
└── system
├── blockMeshDict
├── controlDict
├── fvSchemes
└── fvSolution
case: OF9/101OF/cavity2D
bash ./run_all.sh
case: of2206 tut verificationAndValidation/multiphase/interIsoFoam/porousDamBreak
./Allrun
./plot
cd plots
gwenview surface_compare.png
5. 使用OpenFOAM
建立网格,检查网格checkMesh,避免之后计算发散
求解
后处理
画图
blockMesh
checkMesh
icoFoam
postProcess -func sampleDict -latestTime
gnuplot gnuplot/gnuplot_script
paraview
icoFoam是基础的求解器
用pisoFoam或者pimpleFoam是等效于icoFoam的,并且会有更多特征
#!/bin/bash
foamCleanTutorials
blockMesh | tee log.blockMesh
checkMesh | tee log.checkMesh
icoFoam | tee log.icoFoam
#pisoFoam | tee log.solver
foamLog log.icoFoam
gnuplot
set logscale y
plot 'logs/p_0' using 1:2 with lines
plot 'logs/p_0' using 1:2 with lines, 'logs/pFinalRes_0' using 1:2 with lines
reset
plot ‘logs/CourantMax_0’ u 1:2 w l
set logscale y
plot [30:50][] 'logs/Ux_0' u 1:2 w l title 'Ux','logs/Uy_0' u 1:2 w l title 'Uy'
exit
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt writeNow;
#This will stop your simulation and will save the current time-step or iteration.
endTime 1.5;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
#By setting the keyword runTimeModifiable to true, you will be able to modify most of the dictionaries on-the-fly
清除案例文件夹
foamCleanTutorials
# erase the mesh and the solution,also erase the processorN
foamCleanPolyMesh
#only erase the mesh
foamListTimes -rm
#erasing the saved solutions
foamListTimes –rm -processor
#erase the solution saved in the processorN