场变量有定义在内部cell上的值,也有边界上的值 例如给组分限值 Example of a mass fraction limiter used in this project: // Initialize the variable Y_i for use in a loop scalarField& CO2Internal = CO2.internalField(); 引用内部点 // Loop for all mesh points 遍历内部点 forAll(CO2, celli) { // Limits the mass fraction to a positive number if (CO2Internal[celli] < 0.0) { CO2Internal[celli] = 0.0; } // Limits the mass fraction to max 1.0 if (CO2Internal[celli] > 1.0) { CO2Internal[celli] = 1.0; } } c.定义输运方程 OpenFOAM 定义方程时要选择一种类型的fvMatrix,有fvScalarMatrix和fvVectorMatrix 离散格式在case/system/fvSchemes.中设定 // Define a ScalarMatrix as a object fvScalarMatrix CO2Eqn 定义系数矩阵 ( fvm::div(phi, CO2) 对流项离散fvm::div - fvm::laplacian(turbulence->nuEff(),CO2) 扩散项离散fvm::div == S_CO2 源项 ); // Apply underrelaxation to the equation // Under relaxation factors defined in file: fvSolution CO2Eqn.relax(); 松弛 CO2Eqn.solve(); 求解 2013年3月20日 转载 snappyHexMesh Tutorial In order to use the automatic meshing tool snappyHexMesh, you have to create a raw background mesh. This can easily be achieved by using blockMesh of OpenFOAM. For this tutorial, I assume that you wish to compute the flow around a body, such as a ship’s hull. Create (or copy) the blockMeshDict in $CASE_DIR/constant/polyMesh. It is not necessary to create a fine background mesh, since it will be refined by snappyHexMesh. Basic case directory setup For the execution of blockMesh, the case folder has to be set up correctly. This can either be seen in the User Guide or in lots of tutorials, such as icoFoam/cavity. For the icoFoam solver, an example case-directory can be seen in the screenshot. Goto your case-directory and execute blockMesh This creates the background mesh. One has to mention, that is is necessary to dimension it sufficiently, in order to fit the hull into that mesh and suppress numerical errors, caused by a way to small mesh. Assuming, that you’ve already exported your geometry as an STL-file, you’ve to copy that file to $CASE_DIR/constant/triSurface. For the following tutorial, I assume, that the filename is hull.stl. Mesh created by blockMesh Create (or copy from a snappyHexMesh tutorial) the snappyHexMeshDict in $CASE_DIR/system and insert the standard header into that file: FoamFile { version 2.0; format ascii; root \ case \ instance \ local \ class dictionary; object autoHexMeshDict; } Now we can start with creating the necessary dictionaries. First of all, tell snappyHexMesh, what to do (in a global sense) castellatedMesh true; snap true; addLayers true; Secondly, snappyHexMesh needs to know which geometry to use. You can simply add just one STL-file, or add add searchableBoxes etc. to this dictionary, if you either wish to create a geometry without an STL-file or you like to specify a region in your mesh, that should be refined specifically. Trying to map the wake field requires a specific refinement region. geometry { hull.stl { type triSurfaceMesh; name HULL; } }; Now we have to configure the settings for the mesh, generated by snappyHexMesh. This is done in the castellatedMeshControls sub-dictionary. Valid settings and options can be seen in the user-guide (table 5.8) or in the snappyHexMesh tutorials. An example for that sub-dictionary is the following castellatedMeshControls { maxLocalCells 10000000; maxGlobalCells 2000000; minRefinementCells 0; nCellsBetweenLevels 1; refinementSurfaces { HULL { level (4 5); } } resolveFeatureAngle 30; refinementRegions { HULL { mode distance; levels ((0.1 5) (0.4 4) (1 2)); } } locationInMesh (3.11 1.51 -1.1); } Visualized levels of region refinement The most important part for a working mesh refinement are locationInMesh, which specifies a point inside the mesh generated by blockMesh, but not inside the geometry (in this case the hull). Secondly, the refinementSurfaces tells snappyHexMesh, which surfaces are the ones to be refined. The level tag defines minimum and maximum refinement level. The refinementRegions tag sets the levels of refinement in various distances to the body, this can be seen in the figure. It doesn’t matter, how much refinementRegions are defined, but the scheme is always the same. levels((maxDistance refinementLevel)...) After the specification of the general meshing and refinement parameters, it is essential to set up controls for the snapping process itself. (cp. [1] table 5.9) snapControls { nSmoothPatch 3; tolerance 4.0; nSolveIter 30; nRelaxIter 5; } Patch name in an ASCII STL file The layer addition is controlled by the addLayersControls dictionary, whose options can be seen in table 5.10 of the user guide (cp. [1]). These options are skipped for this tutorial, and sample values can be found in the user guide as well. Nevertheless, the layers sub-directory is important to talk about. As stated in [1], it tells snappyHexMesh which patches “need” layers attached and the number of those layers. Since this is an mesh oriented option, not the surface geometry has to be specified, but the patch name. If you have an ASCII STL file, you can open simply open it with an texteditor of your choice and the word after solid is the patch name. In my case, this was OBJECT. addLayersControls { layers { HULL_OBJECT