CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Mesh Utilities

New checkAspectRatio Utility

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   February 16, 2016, 12:33
Default New checkAspectRatio Utility
  #1
Member
 
Timm Severin
Join Date: Mar 2014
Location: Munich
Posts: 60
Rep Power: 4
Astrodan is on a distinguished road
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:
steps-1.png steps-2.png
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:
comparison.jpg

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
Attached Files
File Type: zip checkAspectRatio.zip (6.2 KB, 0 views)
Astrodan is offline   Reply With Quote

Old   March 8, 2016, 12:23
Default
  #2
Member
 
Timm Severin
Join Date: Mar 2014
Location: Munich
Posts: 60
Rep Power: 4
Astrodan is on a distinguished road
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.
refineAspectRatio.png
Attached Files
File Type: zip refineAspectRatio.zip (8.2 KB, 5 views)
__________________
PhD Student at the Institute of Biochemical Engineering at TU München
Modelling of fluid dynamics in open photobioreactors.

System:
OpenFOAM 2.3.x, 64bit, 8 Core Xeon Workstation
Astrodan is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
mirrorMesh utility preserving regions zfaraday OpenFOAM Mesh Utilities 1 November 7, 2016 22:51
Something doens't work with wallHeatFlux utility or externalWallHeatFluxTemperat BC!! zfaraday OpenFOAM Post-Processing 0 February 5, 2015 17:47
Contribution a new utility: refine wall layer mesh based on yPlus field lakeat OpenFOAM Mesh Utilities 57 February 1, 2015 09:25
StreamFunction utility titio OpenFOAM Post-Processing 0 May 19, 2010 16:04
Sample Utility not working in OpenFoam 1.6 titio OpenFOAM Post-Processing 0 February 5, 2010 13:12


All times are GMT -4. The time now is 05:37.