CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

setExprFields example to generate an initial velocity field for LES of channel flow

Register Blogs Community New Posts Updated Threads Search

Like Tree20Likes
  • 16 Post By fumiya
  • 2 Post By fumiya
  • 1 Post By olesen
  • 1 Post By Michael@UW

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 20, 2020, 23:34
Default setExprFields example to generate an initial velocity field for LES of channel flow
  #1
Senior Member
 
fumiya's Avatar
 
Fumiya Nozaki
Join Date: Jun 2010
Location: Yokohama, Japan
Posts: 266
Blog Entries: 1
Rep Power: 19
fumiya is on a distinguished road
As you know, perturbU utility [1] can be used
to generate an initial velocity field for large eddy simulation
of channel flow. This utility is not included in the official release
version but we can substitute setExprFields utility [2] for it.
The settings of setExprFields utility are specified in system/setExprFieldsDict file.

The following code is an implementation of perturbU by setExprFields utility
for the tutorial incompressible/pimpleFoam/LES/channel395.

You can play around with the tutorial by changing its mesh resolution.
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      setExprFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

expressions
(
    U
    {
        field       U;
        dimensions  [0 1 -1 0 0 0 0];

//        constants
//        {
//        }

        variables
        (
            "Retau = 395"
            "Ubar = 0.1335"
            "nu = 2e-05"
            "h = 1"
            "utau = Retau*nu/h"
            "y = (pos().y() <= h) ? pos().y() : 2.0*h - pos().y()"
            "yPlus = y*Retau/h"
            "xPlus = pos().x()*Retau/h"
            "zPlus = pos().z()*Retau/h"
            "duPlus = Ubar*0.25/utau"
            "betaPlus = 2.0*pi()/200.0"
            "sigma = 0.00055"
            "alphaPlus = 2.0*pi()/500.0"
            "epsilon = Ubar/200.0"
            "deviation = pos().x()/pos().x() + 0.4*(rand() - 0.5)"
        );

        condition
        #{
            (pos().x() > -10)
        #};

        expression
        #{
            vector
            (
                1.5*Ubar*pos().y()*(2.0*h - pos().y())
              + (utau*duPlus/2.0)*(yPlus/40.0)*exp(-sigma*sqr(yPlus) + 0.5)*cos(betaPlus*zPlus)*deviation,
                0.0,
                epsilon*sin(alphaPlus*xPlus)*yPlus*exp(-sigma*sqr(yPlus))*deviation
            )
        #};
    }
);

// ************************************************************************* //
The following link is an animation:
https://twitter.com/ennovacfd/status...96828440895488

[1] https://github.com/wyldckat/perturbU
[2] https://www.openfoam.com/documentati...xprFields.html

Hope this helps,
Fumiya
Attached Images
File Type: png setExprFields.png (83.1 KB, 48 views)
__________________
[Personal]
fumiya is offline   Reply With Quote

Old   September 22, 2020, 02:16
Default An additional note
  #2
Senior Member
 
fumiya's Avatar
 
Fumiya Nozaki
Join Date: Jun 2010
Location: Yokohama, Japan
Posts: 266
Blog Entries: 1
Rep Power: 19
fumiya is on a distinguished road
The setExprFields utility in OpenFOAM v2006 does not work if the entry "condition" is empty as shown below:

Code:
        condition
        #{
        #};
ndtrong and Michael@UW like this.
__________________
[Personal]
fumiya is offline   Reply With Quote

Old   April 1, 2021, 03:46
Default
  #3
Member
 
ESI
Join Date: Sep 2017
Posts: 46
Rep Power: 8
ht2017 is on a distinguished road
Quote:
Originally Posted by fumiya View Post
As you know, perturbU utility [1] can be used
to generate an initial velocity field for large eddy simulation
of channel flow. This utility is not included in the official release
version but we can substitute setExprFields utility [2] for it.
The settings of setExprFields utility are specified in system/setExprFieldsDict file.

The following code is an implementation of perturbU by setExprFields utility
for the tutorial incompressible/pimpleFoam/LES/channel395.

You can play around with the tutorial by changing its mesh resolution.
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      setExprFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

expressions
(
    U
    {
        field       U;
        dimensions  [0 1 -1 0 0 0 0];

//        constants
//        {
//        }

        variables
        (
            "Retau = 395"
            "Ubar = 0.1335"
            "nu = 2e-05"
            "h = 1"
            "utau = Retau*nu/h"
            "y = (pos().y() <= h) ? pos().y() : 2.0*h - pos().y()"
            "yPlus = y*Retau/h"
            "xPlus = pos().x()*Retau/h"
            "zPlus = pos().z()*Retau/h"
            "duPlus = Ubar*0.25/utau"
            "betaPlus = 2.0*pi()/200.0"
            "sigma = 0.00055"
            "alphaPlus = 2.0*pi()/500.0"
            "epsilon = Ubar/200.0"
            "deviation = pos().x()/pos().x() + 0.4*(rand() - 0.5)"
        );

        condition
        #{
            (pos().x() > -10)
        #};

        expression
        #{
            vector
            (
                1.5*Ubar*pos().y()*(2.0*h - pos().y())
              + (utau*duPlus/2.0)*(yPlus/40.0)*exp(-sigma*sqr(yPlus) + 0.5)*cos(betaPlus*zPlus)*deviation,
                0.0,
                epsilon*sin(alphaPlus*xPlus)*yPlus*exp(-sigma*sqr(yPlus))*deviation
            )
        #};
    }
);

// ************************************************************************* //
The following link is an animation:
https://twitter.com/ennovacfd/status...96828440895488

[1] https://github.com/wyldckat/perturbU
[2] https://www.openfoam.com/documentati...xprFields.html

Hope this helps,
Fumiya
What is the theory for this code? Because I want to simulate for channel flow but different the size with this tutorial so I need to write a new code but I don't know how to write it. could you tell me what is the theory to write the code?
thank you
ht2017 is offline   Reply With Quote

Old   April 1, 2021, 03:48
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by fumiya View Post
The setExprFields utility in OpenFOAM v2006 does not work if the entry "condition" is empty as shown below:

Code:
        condition
        #{
        #};

That should be fixed in the 2012 release, and in the 2006 maintenance branch.
fumiya likes this.
olesen is offline   Reply With Quote

Old   April 1, 2021, 06:01
Default
  #5
Member
 
ESI
Join Date: Sep 2017
Posts: 46
Rep Power: 8
ht2017 is on a distinguished road
Quote:
Originally Posted by olesen View Post
That should be fixed in the 2012 release, and in the 2006 maintenance branch.
Hi Olesen,
I have run both the case. case 1 that is a tutorial available in Openfoam chanel395 and another case (case 2) I run with create fluctuation velocity with this code. But I get the result different about velocity mean and R11. Could you tell me how to run with the code more correct result?

case2: Run with code to create fluctuation.

velocity mean magnitu


UPrime2Mean_XX (R11)



Case 1: chanel395

velocity mean magnitude



UPrime2Mean_XX (R11)
ht2017 is offline   Reply With Quote

Old   April 14, 2021, 03:38
Default
  #6
Member
 
ESI
Join Date: Sep 2017
Posts: 46
Rep Power: 8
ht2017 is on a distinguished road
Quote:
Originally Posted by fumiya View Post
As you know, perturbU utility [1] can be used
to generate an initial velocity field for large eddy simulation
of channel flow. This utility is not included in the official release
version but we can substitute setExprFields utility [2] for it.
The settings of setExprFields utility are specified in system/setExprFieldsDict file.

The following code is an implementation of perturbU by setExprFields utility
for the tutorial incompressible/pimpleFoam/LES/channel395.

You can play around with the tutorial by changing its mesh resolution.
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      setExprFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

expressions
(
    U
    {
        field       U;
        dimensions  [0 1 -1 0 0 0 0];

//        constants
//        {
//        }

        variables
        (
            "Retau = 395"
            "Ubar = 0.1335"
            "nu = 2e-05"
            "h = 1"
            "utau = Retau*nu/h"
            "y = (pos().y() <= h) ? pos().y() : 2.0*h - pos().y()"
            "yPlus = y*Retau/h"
            "xPlus = pos().x()*Retau/h"
            "zPlus = pos().z()*Retau/h"
            "duPlus = Ubar*0.25/utau"
            "betaPlus = 2.0*pi()/200.0"
            "sigma = 0.00055"
            "alphaPlus = 2.0*pi()/500.0"
            "epsilon = Ubar/200.0"
            "deviation = pos().x()/pos().x() + 0.4*(rand() - 0.5)"
        );

        condition
        #{
            (pos().x() > -10)
        #};

        expression
        #{
            vector
            (
                1.5*Ubar*pos().y()*(2.0*h - pos().y())
              + (utau*duPlus/2.0)*(yPlus/40.0)*exp(-sigma*sqr(yPlus) + 0.5)*cos(betaPlus*zPlus)*deviation,
                0.0,
                epsilon*sin(alphaPlus*xPlus)*yPlus*exp(-sigma*sqr(yPlus))*deviation
            )
        #};
    }
);

// ************************************************************************* //
The following link is an animation:
https://twitter.com/ennovacfd/status...96828440895488

[1] https://github.com/wyldckat/perturbU
[2] https://www.openfoam.com/documentati...xprFields.html

Hope this helps,
Fumiya
Do you know how to consider the sigma parameter? When I run with the meter scale may be the value 0.0005 it is well working but when I run with millimeter-scale it it not well for working.
ht2017 is offline   Reply With Quote

Old   January 20, 2022, 20:30
Default
  #7
Senior Member
 
Join Date: Jan 2019
Posts: 125
Blog Entries: 1
Rep Power: 0
Michael@UW is on a distinguished road
Quote:
Originally Posted by olesen View Post
That should be fixed in the 2012 release, and in the 2006 maintenance branch.
I tested in 2106.
If you do not need a condition, then condition block should be commented out, otherwise, it gives a syntax error.

The following does not work
Code:
        condition
        #{
            //(pos().y() > -10) && (pos().z() > -10)
        #};
Need to comment out the whole block:
Code:
        // condition
        // #{
        //     (pos().y() > -10) && (pos().z() > -10)
        // #};
Ellie-1895 likes this.
Michael@UW is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
laplacianFoam with source term Herwig OpenFOAM Running, Solving & CFD 17 November 19, 2019 13:47
Segmentation fault when using reactingFOAM for Fluids Tommy Floessner OpenFOAM Running, Solving & CFD 4 April 22, 2018 12:30
chtMultiRegionSimpleFoam turbulent case Aditya Patil OpenFOAM Running, Solving & CFD 6 April 24, 2017 22:13
Floating point exception error lpz_michele OpenFOAM Running, Solving & CFD 53 October 19, 2015 02:50
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20


All times are GMT -4. The time now is 00:58.