CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [Other] New checkAspectRatio Utility (https://www.cfd-online.com/Forums/openfoam-community-contributions/166786-new-checkaspectratio-utility.html)

Astrodan February 16, 2016 11:33

New checkAspectRatio Utility
 
4 Attachment(s)
Servus everyone,

lately I have been running some simulations with interFoam, in which very thin layers of fluid (\Delta h \approx \mathcal{O}(0.001)\,m) in an inclined channel are involved.

As it turns out, (at least) interFoam does not like meshs with aspect ratios above a certain value (about 3), or where neighbouring cells are much bigger (probably not only interFoam's problem).

Since I stumbled upon the same problems, I decided to write a small tool to quickly (and may dirty) fix these problems:
The utility attached can:
  • Store the cell volume and approximate dimensions of the cells.
    The approximation occurs since all cells c are assumed to be rectangular, i.e. for coordinates i ist calculated by \Delta x = max(c_{x,i}) - min(c_{x,i}).
    This also means that for completely rectangular meshs the approximation is exact.
  • Check the cells aspect ratios based on above determined cell dimensions, and compare it to a reference value (quite similar to checkMesh).
    However, when a violation of a critical ratio is detected, the cells are stored in a cellSet, depending on the mesh direction (expressed by cell.x()). Since these cellSets distinguish between directions, they can be refined e.g. by the refineMesh tool in the dimension that is too large.
  • Check the cells dimensions compared to neighbouring cells based on above dimensions or cell volume.
    Again, directions are respected and stored separately.
Results of the tool:
Either it prints "Mesh OK", or it will return a number of cellSets, namely
(x|y|z)AspectCells and (x|y|z)NeighbourCells, wherein the first store the cells with a too high aspect ratio in the respective direction, and the latter to large ratios between neighbouring cells.

Process example for my channel\left.\right.^1:
Attachment 45208 Attachment 45209
0: Original mesh, refined using refineWallLayer
1: checkAspectRatio, refineMesh on xAspectCells
2: checkAspectRatio, refineMesh on yAspectCells
3: checkAspectRatio, refineMesh on yAspectCells
4. checkAspectRatio, refineMesh on xAspectCells
5. checkAspectRatio, refineMesh on zNeighbourCells
checkAspectRatio returns "Mesh OK"
Sadly it is an iterative process, since you always have to reselect a cellSet after the mesh has been changed, however the order of above stesps basically is irrelevant.

As an example of the results for my channel, it has changed the solution from the left (unrefined, 40550) picture to the right version (166500 cells). This process is probably far from optimal, but in my case it was right now the fastest way to solve the problem, and 166k cells is not too much:
Attachment 45207

I don't know if this tool really is useful, but I thought I'd share it. Just wmake all it, and it should work (tested in OF 2.3.x). And I'd appricate if you let me know if you can use this, or if you have any further ideas/find bugs.

Finally, here is a list of references, where I copied the code from and where I got some ideas/numbers:

Reason for this:
Jon Elvar Wallevik
http://www.cfd-online.com/Forums/ope...tml#post409745
and partially Matthew Denno, with an awesome looking result :)
http://www.cfd-online.com/Forums/ope...interfoam.html
Creating cellSets:
Tomislav Maric
http://www.sourceflux.de/blog/a-chan...t-in-openfoam/
Finding neighbours:
Su Junwei
http://www.cfd-online.com/Forums/ope...tml#post181929
Determining the (approximate) size of cell
Niels Gjoel Jacobsen
http://www.cfd-online.com/Forums/ope...tml#post275193
---
\left.\right.^1 Sorry I left out the axis, I had to edit the pictures a bit. the axis directions are:
x: gropund to the right
y: ground/wall to the background
z: height

Astrodan March 8, 2016 11:23

2 Attachment(s)
Hello again,

although the replies so far are sort of limited, I decided to extend the tool to do the refinement automatically, which should be easier to handle and thus more reproducible.

The new tool would be refineAspectRatio. It does the same checks as the tool above, but can perform a refinement step after each analysis.

Installation:
Use the Allwmake script. This should work, tested in OF23x.

The tool uses some mesh statistics functions that are included in checkMesh, and thus depends on symbolic links being created, since the functions are not available in any library. Should the paths be wrong or env-variables missing, you can manually create links to the checkMesh's files printMeshStats.(C|H) or put a copy of those in the directory.

Use
Quite unsurprising, the script has a -help argument:
Code:

Usage: refineAspectRatio [OPTIONS]
options:
  -basedOnVolume    Evaluate neighbouring cell sizes on volume instead of
                    (x/y/z) dimensions.
  -case <dir>      specify alternate case directory, default is the cwd
  -criticalRatio <value>
                    Set the critical aspect ratio allowed in a cell, defaults to
                    3.0.
  -maxCells <value>
                    The maximum number of cells the new mesh is supposed to
                    have, use 0 means for unlimited passes. Defaults to 0.
                    NOTE: Not precise (at the Moment)!
  -maxRefineLevel <value>
                    The maximum number of iterations for refinement in every
                    dimension, use 0 for unlimited passes. Defaults to 3.
  -neighbour        Also refine cells with bad neighbour ratios.
  -neighbourRatio <value>
                    Set the allowed ratio of neighbour cell sizes, defaults to
                    3.0. Implies -neighbour option.
  -overwrite        overwrite existing mesh/results files
  -verbose          Print more information during the refinement process. Also
                    will write even more meshes when used in combination with
                    'writeMeshes'.
  -writeMeshes      Writes the intermediate meshes to seperate time folders.
                    Overrides overwrite.
  -srcDoc          display source code in browser
  -doc              display application documentation in browser
  -help            print the usage

A tool to refine a mesh, avoiding big aspect ratios in cells and differences in dimensions to neighbouring cells.

Using: OpenFOAM-2.3.x (see www.OpenFOAM.org)
Build: 2.3.x-2f9138f6f49f

I hope most options are self explanatory. Currently no option is mandatory, default values are set as described for the checkAspectRatio utility above.

Most interesting options should be -criticalRatio <value> (defining the limit at which point cells are being refined), -maxRefineLevel <value> (defining how many refinement iterations are done) and -neighbour (activating the check for neighbour cells).

As debug output the flags -verbose and -writeMeshes can help. A combination of both will output every single meshing step, whether refinement has been done or not. -writeMeshes only will only write all changes of a complete iteration.

Internals:
In some kind of undefined pseudo-code, the following algorithm describes roughly what is actually done:
Code:

set criticalRatio;      // critical value for aspect ratio
set neighbourRatio;    // critical value for neighbouring cell sizes

while not(meshOk or maxCells or maxRefinement) {
    for (cell in cells) {
        set [x, y, z] = getCellDimensions(cell);
        if x/y or x/z is greater criticalRratio
            refine cell in x;
        ... repeat for x and y dimensions
       
        set [nX, nY, nZ] = getCellDimensions(neighbours of cell);
        if x/nX is greater neighbourRatio
            refine cell in x;
        ... continue for y and z
    }
   
    if number of cells is greater limit
        set maxCells = true;
    if number of loops is greater limit
        set maxRefinement = true;
    if no changes in mesh
        set meshOk = true;
}

The refinement is based on multiDirRefinement as used in the refineMesh utility, but with an automatically created dictionary.

Visual Process
The following pictures show the results of a run. I'm thinking about also posting the test case I used, but I'd have to remove some stuff first, so maybe when I have spare time.
Attachment 45776


All times are GMT -4. The time now is 08:34.