CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Mesh Utilities (http://www.cfd-online.com/Forums/openfoam-meshing-utilities/)
-   -   Contribution a new utility: refine wall layer mesh based on yPlus field (http://www.cfd-online.com/Forums/openfoam-meshing-utilities/109885-contribution-new-utility-refine-wall-layer-mesh-based-yplus-field.html)

lakeat November 28, 2012 19:21

Contribution a new utility: refine wall layer mesh based on yPlus field
 
1 Attachment(s)
Dear all,


As discussed in this thread, there is a need to refine the wall layer mesh based on the yPlus or yStar information on the patch fields.

So I modified the original refineWallLayer utility and make a "smart"-refine-wall-layer-mesh utility. :)

Here it is: Attachment 17320

Most of the options are similar to the original refineWallLayer utility, only
"esgeWeight" is replaced by "stretchingRatio", which I think will make more sense. It should be larger than 1, best to be around 1~1.5, in order not to have too big stretching ratios.

The key feature here is to refine the mesh not just once, but many times based on the current yPlus file or yStar file information, so to reach a desired estimated yPlus value.

The default yPlus target value is to reach y+=1;
Of cause you can set any other y+ target;

To use this utility, please turn on the "basedOnYPlus" option.

If "basedOnYPlus" option is off, the utility behaves like original refineWallLayer utily.

I do not see a need to use "cellSet" mechanism, so by default, when the "basedOnYPlus" option is turned on, the whole wall layer is refined.

Of cause however, this method is just a rough estimation, the real flow field and the yPlus values need to you to rerun the simulation!

Code:

$ refineWallLayerSmart -help

Usage: refineWallLayerSmart [OPTIONS] <patchName> <stretchingRatio>
options:
  -basedOnYPlus    Based on y+/y* field, run these utilities first. Target
                    yPlus is unity
  -case <dir>      specify alternate case directory, default is the cwd
  -noFunctionObjects
                    do not execute functionObjects
  -overwrite        overwrite existing mesh/results files
  -refineLevel <value>
                    Manually set the refineLevel, e.g. 3
  -targetYPlus <value>
                    Manually set the target yPlus, e.g. 5 or 30
  -useSet <name>    (obsoleted) restrict cells to refine based on specified
                    cellSet name
  -srcDoc          display source code in browser
  -doc              display application documentation in browser
  -help            print the usage

A smart way to refine wall layer cells based on the y+/y* value.
Please turn on the option "basedOnYPlus"to see its effect

Examples:

Code:

refineWallLayerSmart -basedOnYPlus cyl 1.15
Refine the wall patch cells named "cyl" based on the latestTime yPlus information, the refine level is automatically calculated, in order to reach y+=1.

Code:

refineWallLayerSmart -basedOnYPlus -targetYPlus 30 cyl 1.15
refine the wall layer mesh to have a target yPlus 30 (mean yPlus value is compared in the utility.)
If "-targetYPlus 50" is larger than the mean yPlus value on that patch, error will show. That is no need to refine.

Code:

refineWallLayerSmart -basedOnYPlus -targetYPlus 30 -refineLevel 3 cyl 1.15
Same as above, but refineLevel is forced to be three, so here "-targetYPlus 50" is useless.


The following is a sample output:
Code:

$ refineWallLayerSmart -basedOnYPlus -targetYPlus 2 cyl 1.12
/*---------------------------------------------------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.1.0                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
Build  : 2.1.0-5141eb679a6c
Exec  : refineWallLayerSmart -basedOnYPlus -targetYPlus 2 cyl 1.12
Date  : Nov 28 2012
Time  : 18:29:59
Host  : "ubuntuWorkStation"
PID    : 13010
Case  : .../run/test/rectangular
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations

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

Create mesh for time = 0.01

Note: this utility default is using yPlus, if you have yStar file also in the folder,
      please double check which one you want to use, and delete the other. Thanks!

Using refineWallLayer utility in a smart way!

Mean yPlus is 19.8019, targetYPlusValue is 2, refineLevel is 4

        Originally, patch 0 named cyl
        d  : min: 0.00069375 max: 0.0008625 average: 0.000735

Selected 284 cells connected to patch cyl

Cutting:
    cells:284
    edges:568

Morphing ...
Selected 284 cells connected to patch cyl

Cutting:
    cells:284
    edges:568

Morphing ...
Selected 284 cells connected to patch cyl

Cutting:
    cells:284
    edges:568

Morphing ...
Selected 284 cells connected to patch cyl

Cutting:
    cells:284
    edges:568

Morphing ...
Writing refined morphMesh to time 0.01001

        After refining, Patch 0 named cyl
        d  : min: 5.405e-05 max: 6.7e-05 average: 5.72429e-05

End




Comments and suggestions are very welcome!
Cheers,

Bernhard November 29, 2012 04:11

Wow, you received your kudos quite fast :)

It is a nice, simple tool, especially with the loop on the refinement-levels makes life easy hopefully.

I still have some doubts on the stretchingRatio, as it will result in a thicker cell in the first layer than in the second layer, which is probably unwanted. I will see if I can think of anything slightly nicer here (except for using a value of 1 here).


I used the cellSet route, because high have patches with very high and low y+ values, but I think I will agree with you that I don't need it this way, as an additional layer will in general not add to many cells anyhow.

Maybe this utility is worth starting a Wiki-entry?

Bernhard November 29, 2012 05:03

1 Attachment(s)
I added a flad -adjacent to the utility which interprets the stretchRatio as the stretchRatio between consecutive cells. I think it is more intuitive, and it nicely scales all the cells in the wall-layer.

Bernhard December 3, 2012 03:19

Just some more thoughts. It would be really awesome if the utility was also able to move some of the nodes of second/third/fourth cell, to reduce the stretch-ratio between the first largest cell inside the layer and the smallest one outside. Does anyone have an idea or suggestion?

lakeat December 3, 2012 11:40

If I were you, I would go with some smoothing schemes, but for now, I won't integrate it into this utility. Just some thoughts.:)

vishalsacharya December 10, 2012 04:57

Hi,

When you use this utility, can it be done before any computations?
I have a case where i plan to generate a steady state RAS solution and then use that as an initial state to do a transient LES.
Can I do this utility before i do my steady state solution?
When a solution exists, how does it work? Obviously it uses the solution to get a more accurate yPlus and then refines wall layers and then writes a new mesh (and new solution interpolated?) to a new directory?
In the basedOnYplus option, which version does it use? yPlusRAS or yPlusLES?

Btw, much appreciation for writing this utility. I am yet to use the in-built refineWallLayer but when i came across your utility, I would like to directly give that a try. Mine is a axisymmetric swirl combustor with a cylindrical dump region preceded by a cylindrical annuls in which 8 swirler guide vanes are present.

Thanks !

vishalsacharya December 10, 2012 05:00

Bernhard:
The new C file and the reason for it makes sense.
If for example, the first cell is say about y+ = 1.5 and we target y+ =1, then a first step would be make a y+ =1 but the next cell then becomes smaller than this new wall cell, am i right? And i guess this is your concern?
In this case, is it not better to just move the y+ = 1.5 point to y+ =1 rather than add a new one? A check can then be made to see the cell expansion ratio near wall.
I hope im not missing something in what you mentioned or implemented, when i say the above?

Thanks

Bernhard December 10, 2012 06:55

The utility will first try to read either yPlus or yStar from the time-file. If it is not present, it will fall back to the normal refineWallLayer. I changed the code I posted in above slightly, such that I can also use refineLevel without yPlus present.

It depends on the utility that you use how -basedOnYPlus works. If you use yPlusRAS, you will not get yPlus, but yStar (see thread linked in first post). You can also use the utility in this other thread, it does not really matter for this utility.

If you use low-Re RANS models, I think the wall layer refinement is not a bad strategy, of course you can also move some nodes, but than your second cell becomes larger than the third one (probably). A combination of both approaches would be ideal (see above post), but for now I don't know how to implement this :)

This utility will by the way operate based on patch-average y+ values, which in most cases will not bring all y+ down to <1 if the average is. But as long as you keep sure that y+<3 for all cells, I don't think you will get into trouble.

vishalsacharya December 12, 2012 16:24

That makes sense.

A general question - If I have a simulation yet to run, but i want to decide if my yPlusLES is good, then can i just set the internalField for U in 0/U to be the inlet velocity everywhere? and then it calculates the yPlus based on that?
How does yPlus calculation work for the intial condition?

lakeat December 12, 2012 16:30

Not sure what you are trying to do. But y+ is simply calculated from velocity gradient, where there is velocity field, there is the y+ field. However, note that some turb models have convergence problem with a ill posed initial field. :)

vishalsacharya December 12, 2012 16:44

My thoughts exactly daniel. Imposing a uniform field like that would not be right, and i dont do it. But how do you get yPlus before you do a simulation when there is no velocity field?

lakeat December 12, 2012 16:46

So your internal field is vacuum? No fluid at all? :confused:

vishalsacharya December 12, 2012 16:56

When i have a mesh and i have just the 0/ folder, its stagnant field inside... not really vacuum :D
Before i run my LES, if i want to check my mesh to see if it has a good yPLus, then how do i do it is my question? How do i use yPlusLES before i begin my LES? so that i can refine my wall or not depending on the values?

lakeat December 12, 2012 17:03

First, I will not use this utility for doing this.

There are numerous ways to estimate first cell height needed when building initial mesh, to list a few:
1. http://www.cfd-online.com/Tools/yplus.php
2. Run on a reduced-dimensional case
3. Experience from similar flow

immortality June 6, 2013 12:29

Hi daniel
how can set all yPlus values below a specified value(like 1)
mean the maximum value be 1 not the average.
I have a shock tube like case that the flow has not reached all the channel and because the tool assumes average values it doesn't decrease yPlus due to including stationary cells that the flow has not reached them,but the maximum yPlus is 16 and I want it be smaller than 1.
thanks.
-------------------
and also it gives an error on double numbers:
Code:

Create time

Create mesh for time = 1.8e-05

Note: this utility default is using yPlus, if you have yStar file also in the folder,
      please double check which one you want to use, and delete the other. Thanks!



--> FOAM FATAL IO ERROR:
wrong token type - expected int, found on line 0 the doubleScalar 0.2

file: IStringStream.sourceFile at line 0.

    From function operator>>(Istream&, int&)
    in file primitives/ints/int/intIO.C at line 68.

FOAM exiting


wyldckat June 9, 2013 06:36

1 Attachment(s)
Greetings to all!

Attached is a modification as requested by Ehsan. It's based on Daniel's original modifications and I changed the following:
  1. Changed this:
    Code:

    args.optionLookupOrDefault("targetYPlus",1);
    to this:
    Code:

    args.optionLookupOrDefault("targetYPlus",1.0);
  2. Changed this:
    Code:

    scalar YpAvg = average(Yp);
    to this:
    Code:

    scalar YpAvg = max(Yp);
  3. After that, it's just cosmetic changes... namely changing "YpAvg" to "YpMax" and text references from "Mean" to "Maximum".
Best regards,
Bruno

immortality June 9, 2013 11:43

thanks Bruno
but why y+ doesn't display in terminal?
Code:

Hiii ...
refineLevelValue = 6
Using refineWallLayer utility in a smart way!

Maximum yPlus is 36.32381771, targetYPlusValue is 1, refineLevel is 6

        Originally, patch 2 named walls
        d  : min: 3.1116565e-06 max: 3.111656539e-06 average: 3.11165652e-06

Selected 1400 cells connected to patch walls

Cutting:
    cells:1400
    edges:2804

Morphing ...
Selected 1400 cells connected to patch walls

Cutting:
    cells:1400
    edges:2804

Morphing ...
Selected 1400 cells connected to patch walls

Cutting:
    cells:1400
    edges:2804

Morphing ...
Selected 1400 cells connected to patch walls

Cutting:
    cells:1400
    edges:2804

Morphing ...
Selected 1400 cells connected to patch walls

Cutting:
    cells:1400
    edges:2804

Morphing ...
Selected 1400 cells connected to patch walls

Cutting:
    cells:1400
    edges:2804

Morphing ...
Writing refined morphMesh to time 1.60063e-05

        After refining, Patch 2 named walls
        d  : min: 7.286986025e-08 max: 7.287e-08 average: 7.286993012e-08

End


wyldckat June 9, 2013 11:52

Hi Ehsan,

:confused: It shows the maximum "yPlus" value, the target yPlus and the refine level needed for reaching said target:
Quote:

Code:

Maximum yPlus is 36.32381771, targetYPlusValue is 1, refineLevel is 6

I forgot to mention that in my tests I used the following:
Code:

refineWallLayerSmart -basedOnYPlus -targetYPlus 0.5 defaultFaces 1.5
Note: add the option "-overwrite" is you want it to override the existing mesh.
I used it on the tutorial case "incompressible/pimpleFoam/TJunction" and used yPlusRAS to calculate the field "yPlus". I have no idea if these are good values, it was just for testing if the worked.

If you want to confirm the resulting "yPlus", I guess it's just a matter of running the "yPlus" application again... in my case, yPlusRAS.

Best regards,
Bruno

immortality June 9, 2013 12:42

thanks dear Bruno.
it seems it concentrate the mesh on near the wall not like ordinary blockMesh.its fine because avoids of increasing mesh numbers a lot.
but I can't grasp well how it works.for example when we set 1.15 its the ratio between nearest cell to wall and what?and what does -refineLevel exactly?
and it seems it keeps original mesh numbers(except of some more cells near wall)

wyldckat June 9, 2013 13:48

1 Attachment(s)
Hi Ehsan,

The "-refineLevel" sets the level manually, instead of allowing the utility to calculate the refine level for itself. This will mean that by imposing the level other than the automatically calculated, you will probably reach a y+ higher or lower than you had planned.

As for the "stretchingRatio", it is used for calculating the "weight":
Code:

const scalar weight = args.argRead<scalar>(2)
        /(args.argRead<scalar>(2)+1);

This means that if the "stretchingRatio" is 1.15, then the "weight" is ~0.5348, which means that the first split will be the distance from the patch face to the opposing cell face, times this size.

Attached is the example I'm looking at, which uses a stretch ratio of 1.5, which leads to "1.5/(1+1.5) = 0.6". Since the edge length is 0.004, then the first division will be at "0.6*0.004 = 0.0024".
Then the second division will refer to the new closest cell to the wall, therefore using "0.6*0.0024" and so on.

Best regards,
Bruno


All times are GMT -4. The time now is 01:10.