Common tools in OF s (to be sorted out)

Keywords: openfoam

OpenFoam has many gadgets that come with it for your convenience. If you need a partner, you can go to the following for yourself:

hty@ubuntu:~$ util
hty@ubuntu:/opt/openfoam4/applications/utilities$ ls
mesh           parallelProcessing  preProcessing  thermophysical
miscellaneous  postProcessing      surface
hty@ubuntu:/opt/openfoam4/applications/utilities$ 

The following is a preliminary overview of several commonly used tools, which will be updated later. It would be grateful to have organized little buddies to call me.

1. Co

C o = δ t ∣ U ∣ δ x Co=\frac{\delta t|\mathbf U|}{\delta x} Co=δxδt∣U∣​

2. vorticity (curl of velocity field)

3. yPlus

The y+ value is important because it reflects that the grid grid correctly resolves the boundary layer. In general, you can also use the wall function, otherwise you can use y+<5 at the viscous sublayer. yPlus calculates and reports y+wall patches for all near-wall cells for specified times of laminar flow, LES, and RAS. For walls with wall functionality, the wall function provides y+ values, otherwise the velocity gradient from the near wall and effective laminar viscosity are obtained directly.

4. sample

  • Sample utilities are used to generate images or extract surfaces.
  • In order to use it, a system/simpleDict file is required under the case folder.
  • Type sample-help to get an optional flag.

5. foamCalc

Operate on the farm:

foamCalc <calcType> <fieldName1 ... fieldnameN>

CalType includes:

  • div: the divergence of the field requires attention to the fvScheme, which specifies the format necessary for calculating the divergence;
  • magSqr: square of amplitude
  • mag: amplitude
  • grad: the gradient of the field
  • components: part of the extraction farm

6. probeLocations

  • Continuous sampling at fixed locations over time;
  • A system/simpleDict file is required under the case folder.
  • Sampling fields and points need to be declared;
fields//Declare sampling field
(
p
):
probeLocations//Declare sample points
(
0.2 0.2 0.2
);

7. topoSet

The grid sequence (points, polygons, grids) is manipulated through a dictionary file;

topoSetDict file is required;

actions
(
	{
	name	c0;
	type	cellSet;
	action	new;
	source	boxTocell;
	sourceInfo
	{
		box (0.3 0.3 0.3) (0.6 0.6 0);
	} 
	}
);

action types:

  • Clear: clear
  • invert: Reverse, select unselected elements, reset selected elements to unselected
  • Remove: remove
  • new +source: Create a new setting or source
  • add+source: add source
  • delete+source: delete source

Source operation type:

  • labelToCell: Select a cell from a given label.
  • cellToCell: Copy elements from a cell set.
  • ZoeToCell: Select the cells in the cell area.
  • faceToCell: Select a cell from a face (owner or neighbor)
  • boxToCell: Select the cell in the box.
  • cylinderToCell: Select the cell whose center is inside the cylinder.
  • sphereToCell: Select the cell whose center is inside the sphere.
  • nearestToCell: Select the closest cell center to coordinate.
  • fieldToCell: Select a cell with a range of field values.

8. setFields

Mainly used for multiphase flow models to redefine field information.

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.0                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      setFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

defaultFieldValues
(
    volScalarFieldValue alpha.air 1
    volScalarFieldValue alpha.water 0
);

regions
(
    boxToCell
    {
        box (0 0 0) (0.01 0.05 0.01);//Grid cells with body centers in this range
        fieldValues
        (
            volScalarFieldValue alpha.air 0
            volScalarFieldValue alpha.water 0   
        );
    }
);

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

9. checkMesh

For checking grid quality, the output information is as follows:

[stu cavity]$ checkMesh 
/*---------------------------------------------------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.1                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
Build  : 4.1
Exec   : checkMesh
Date   : Sep 28 2020
Time   : 21:37:29
Host   : "node01"
PID    : 151764
Case   : /home/student2/OpenFOAM/student2-4.1/run/cavity
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create polyMesh for time = 0

Time = 0

Mesh stats
    points:           882
    internal points:  0
    faces:            1640
    internal faces:   760
    cells:            400
    faces per cell:   6
    boundary patches: 3
    point zones:      0
    face zones:       0
    cell zones:       0

Overall number of cells of each type:
    hexahedra:     400
    prisms:        0
    wedges:        0
    pyramids:      0
    tet wedges:    0
    tetrahedra:    0
    polyhedra:     0

Checking topology...
    Boundary definition OK.
    Cell to face addressing OK.
    Point usage OK.
    Upper triangular ordering OK.
    Face vertices OK.
    Number of regions: 1 (OK).

Checking patch topology for multiply connected surfaces...
    Patch               Faces    Points   Surface topology                  
    movingWall          20       42       ok (non-closed singly connected)  
    fixedWalls          60       122      ok (non-closed singly connected)  
    frontAndBack        800      882      ok (non-closed singly connected)  

Checking geometry...
    Overall domain bounding box (0 0 0) (0.1 0.1 0.01)
    Mesh has 2 geometric (non-empty/wedge) directions (1 1 0)
    Mesh has 2 solution (non-empty) directions (1 1 0)
    All edges aligned with or perpendicular to non-empty directions.
    Boundary openness (8.47033e-18 -8.47033e-18 -4.51751e-17) OK.
    Max cell openness = 1.35525e-16 OK.
    Max aspect ratio = 1 OK.//Aspect ratio
    Minimum face area = 2.5e-05. Maximum face area = 5e-05.  Face area magnitudes OK.
    Min volume = 2.5e-07. Max volume = 2.5e-07.  Total volume = 0.0001.  Cell volumes OK.
    Mesh non-orthogonality Max: 0 average: 0//Number of non-orthogonal grids
    Non-orthogonality check OK.
    Face pyramids OK.
    Max skewness = 1.66533e-14 OK.//Grid skew
    Coupled point location match (average 0) OK.

Mesh OK.

End

10. transformPoints

Used for grid movement, scale-up, and rotation.

  • translate+vector: moves in the direction of a given vector;
  • Rotate+ (vector vector vector): rotates a point along the first vector to the second vector;
  • scale+vector: Scale up or down the grid cells according to the specified vector.
[stu run]$ ls
cavity  
[stu run]$ cp -r cavity cavityTranslate
[stu run]$ touch cavityTranslate/cavityTranslate.OpenFAOM	//Create a file that can be opened by a paraview
[stu run]$ transformPoints -case cavityTranslate/ -translate "(0.2 0.2 0.2)" //Shift grid cells
/*---------------------------------------------------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.1                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
Build  : 4.1
Exec   : transformPoints -case cavityTranslate/ -translate (0.2 0.2 0.2)
Date   : Sep 28 2020
Time   : 22:03:41
Host   : "node01"
PID    : 152372
Case   : ./cavityTranslate
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Translating points by (0.2 0.2 0.2)
Writing points into directory "./cavityTranslate/constant/polyMesh"

End

[stu run]$ paraview	//Open paraview to compare the differences

11. createBaffles

  • Converts an internal surface to two boundary surfaces without thickness, or converts multiple boundary surfaces to one boundary surface.
  • You can add boundary conditions on this surface.

createBafflesDict

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.x                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      createBafflesDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Sample for creating baffles:
// - usually converting internal faces into two boundary faces
// - or converting boundary faces into a boundary face
//   (internalFacesOnly=false)(though should use really createPatch
//    to do this)
//
// - selection of faces (and orientation) to 'baffle' through:
//      faceZone:
//          type        faceZone;
//          zoneName    f0;
//      searchableSurface:
//          type        searchableSurface;
//          surface     triSurfaceMesh;
//          name        baffle1D.stl;
//
// - specification of patches for baffle sides in one of two modes:
//      - patchPairs : create two patches of same type, same input
//      - patches    : create patches separately, full control over what
//                     to create on what side
//                     (this mode can also create duplicate (overlapping)
//                      sets of baffles:
//                      - internalFacesOnly = false
//                      - have 4 entries in patches:
//                          - master
//                          - slave
//                          - additional master
//                          - additional slave)


// Whether to convert internal faces only (so leave boundary faces intact).
// This is only relevant if your face selection type can pick up boundary
// faces.
internalFacesOnly true;

// Optionally do not read/convert/write any fields.
//noFields true;


// Baffles to create.
baffles
{
    baffle1
    {
        //- Use surface to select faces and orientation.
        type        searchableSurface;
        surface     triSurfaceMesh;
        name        baffle1D.stl;
        //- Optional flip
        //flip        false;


        // Generate patchGroup baffle1 with two patches:
        //  - baffle1_master
        //  - baffle1_slave
        patchPairs
        {
            type            wall;
            //- Optional override of added patchfields. If not specified
            //  any added patchfields are of type calculated.
            patchFields
            {
                U
                {
                    type            fixedValue;
                    value           uniform (0 0 0);
                }
            }
        }
    }


    cyclicFaces//cyclic: periodic condition
    {
        //- Select faces and orientation through a searchableSurface
        type        searchableSurface;
        surface     searchablePlate;

        origin      (0.099 -0.006 0.004);
        span        (0 0.012 0.012);


        // Generate patches explicitly
        patches
        {
            master
            {
                //- Master side patch

                name            fan_half0;
                type            cyclic;
                neighbourPatch  fan_half1;

                patchFields
                {
                    p
                    {
                        type            fan;
                        patchType       cyclic;
                        jump            uniform 0;
                        value           uniform 0;
                        jumpTable       polynomial 1((100 0));
                    }
                }
            }
            slave
            {
                //- Slave side patch

                name            fan_half1;
                type            cyclic;
                neighbourPatch  fan_half0;

                patchFields
                {
                    p
                    {
                        type            fan;
                        patchType       cyclic;
                        value           uniform 0;
                    }
                }
            }
        }
    }
}


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

12. refineMesh

Encrypted Grid

  • You can use refineMesh directly
refineMesh -overwrite//Overwrite the original grid, rewrite the encryption so that no new folders are generated
  • You can also use refineMeshDict:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.x                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      refineMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Cells to refine; name of cell set
set c0;// Involving topoSet

// Type of coordinate system:
// - global : coordinate system same for every cell. Usually aligned with
//   x,y,z axis. Specify in globalCoeffs section below.
// - patchLocal : coordinate system different for every cell. Specify in
//   patchLocalCoeffs section below.
// - fieldBased : uses the list of field names from the directions list for
//   selecting the directions to cut. Meant to be used with geometricCut, but
//   can also be used with useHexTopology.
coordinateSystem global;
//coordinateSystem patchLocal;
//coordinateSystem fieldBased;

// .. and its coefficients. x,y in this case. (normal direction is calculated
// as tan1^tan2)
globalCoeffs
{
    tan1 (1 0 0);
    tan2 (0 1 0);
}

patchLocalCoeffs
{
    patch outside;  // Normal direction is facenormal of zero'th face of patch
    tan1 (1 0 0);
}

// List of directions to refine, if global or patchLocal
directions
(
    tan1
    tan2
    normal
);

// List of directions to refine, if "fieldBased". Keep in mind that these
// fields must be of type "vectorField", not "volVectorField".
//directions
//(
//    radialDirectionFieldName
//    angularDirectionFieldName
//    heightDirectionFieldName
//);

// Whether to use hex topology. This will
// - if patchLocal: all cells on selected patch should be hex
// - split all hexes in 2x2x2 through the middle of edges.
useHexTopology  true;

// Cut purely geometric (will cut hexes through vertices) or take topology
// into account. Incompatible with useHexTopology
geometricCut    false;

// Write meshes from intermediate steps
writeMesh       false;

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

Posted by cheatboy00 on Thu, 21 Oct 2021 23:55:11 -0700