CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Pre-Processing

setExprFields

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 29, 2021, 09:03
Default setExprFields
  #1
Member
 
Callum Guy
Join Date: Dec 2019
Location: Scotland
Posts: 44
Rep Power: 6
CallumG is on a distinguished road
Hi Foamers,

I would like to utise the setExprFieldsDict in a multiphase (air & water) solver. What I would like to do is apply a shear current in the water phase using the seventh power law something like:

u = U_inf * (z/h)^(1/7)

Firstly, is it possible to setExprFields to just one phase? And secondly is there any one who could help me with the syntax for applying this?

All the best,
Callum
CallumG is offline   Reply With Quote

Old   November 1, 2021, 06:11
Default Update: Solved setExprFieldsDict example for multiphase
  #2
Member
 
Callum Guy
Join Date: Dec 2019
Location: Scotland
Posts: 44
Rep Power: 6
CallumG is on a distinguished road
Hi all,

I just wanted to update you on resolving my issue. Here's a copy of the setExprFieldsDict I used, and I hope it serves as a good example for anyone looking to do similar. I replaced my setFieldsDict with the below setExprFieldsDict, so instead of running the setFields command I just ran setExprFields.

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1912                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      setExprFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
defaultFieldValues
(
    volScalarFieldValue alpha.water 0
    volVectorFieldValue U           (0. 0. 0.)
);

expressions
(
    alpha.water
    {
        field       alpha.water;

        constants
        {
            water_level (0 0 0.4);
        }

        variables
        (
        );

        condition
        #{
            pos().z() < $[(vector)constants.water_level].z()
        #};

        expression
        #{
            1
        #};
    }
    U
    {
        field       U;
        dimensions  [0 1 -1 0 0 0 0];

        constants
        {
            water_level (0 0 0.4);
        }

        variables
        (
            "alpha = 7.0"
            "beta = 0.4"
            "height = pos().z()"
            "u_inf = 0.75"
        );

        condition
        #{
            pos().z() < $[(vector)constants.water_level].z()
        #};

        expression
        #{
            vector(pow(u_inf*(height/(beta*$[(vector)constants.water_level].z())),(1/alpha)),0,0)
        #};
    }
);


// ************************************************************************* //
CallumG is offline   Reply With Quote

Old   November 1, 2021, 12:04
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Since your water level is only in 'z' it would be more efficient to define that as a scalar value "0.4" in constants and use ${constant.water_level} as a text replacement. Also, no reason to define height as a variable. Just use drop it straight into the expression as pos().z()
CallumG likes this.
olesen is offline   Reply With Quote

Old   November 1, 2021, 13:37
Default
  #4
Member
 
Callum Guy
Join Date: Dec 2019
Location: Scotland
Posts: 44
Rep Power: 6
CallumG is on a distinguished road
Hi Olesen,

quite right. I did actually do as you suggested after posting, this one was copied from an already working file from elsewhere. Thanks for the advice!

All the best,
Callum
CallumG is offline   Reply With Quote

Old   April 19, 2022, 04:57
Red face Using setExprFieldsDict
  #5
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Quote:
Originally Posted by CallumG View Post
Hi Foamers,

I would like to utise the setExprFieldsDict in a multiphase (air & water) solver. What I would like to do is apply a shear current in the water phase using the seventh power law something like:

u = U_inf * (z/h)^(1/7)

Firstly, is it possible to setExprFields to just one phase? And secondly is there any one who could help me with the syntax for applying this?

All the best,
Callum
Dear Callum,

I would like to use setExprFieldsDict in my silulations for setting a non-uniform distribution of temperature (T= c Y) in which C is a constant in my whole domain which is a box. I am actually new in openFoam and I cannot find examples in this regards to define it. Would you please let me know if you know how to define a box in setExprFieldsDict?

I have found a code for defining a circle in which the temperatue is increasing . I would need the same code but for a box,not a circle.

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1912 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object setExprFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


expressions
(
T
{
field T;
dimensions [0 0 0 1 0 0 0];

constants
{
centre (0 0 0);
}

variables
(
"radius = 1.0"
);

condition
#{
(mag(pos() - $[(vector)constants.centre]) < radius)
#};

expression
#{

1 - pos().y()
#};
}
);

Best regards,
Sadra
sadra2003 is offline   Reply With Quote

Old   April 19, 2022, 04:58
Default
  #6
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Quote:
Originally Posted by olesen View Post
Since your water level is only in 'z' it would be more efficient to define that as a scalar value "0.4" in constants and use ${constant.water_level} as a text replacement. Also, no reason to define height as a variable. Just use drop it straight into the expression as pos().z()
Dear olesen,

I would like to use setExprFieldsDict in my silulations for setting a non-uniform distribution of temperature (T= c Y) in which C is a constant in my whole domain which is a box. I am actually new in openFoam and I cannot find examples in this regards to define it. Would you please let me know if you know how to define a box in setExprFieldsDict?

I have found a code for defining a circle in which the temperatue is increasing . I would need the same code but for a box,not a circle.

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1912 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object setExprFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


expressions
(
T
{
field T;
dimensions [0 0 0 1 0 0 0];

constants
{
centre (0 0 0);
}

variables
(
"radius = 1.0"
);

condition
#{
(mag(pos() - $[(vector)constants.centre]) < radius)
#};

expression
#{

1 - pos().y()
#};
}
);

Best regards,
Sadra
sadra2003 is offline   Reply With Quote

Old   May 26, 2022, 09:25
Default
  #7
Member
 
Callum Guy
Join Date: Dec 2019
Location: Scotland
Posts: 44
Rep Power: 6
CallumG is on a distinguished road
Hi Sandra,

sorry for the late reply, I've only just seen this. Truth be told, I'm not sure how you would go about this. What you might do, although definitely not the most efficient way, is to add multiple conditions to make your box. i.e.

condition
#{
(pos().z() < 10) && (pos().z() > -10) && (pos().y() < 10) && (pos().y() > -10) && (pos().x() < 10) && (pos().x() > -10)
#};
CallumG is offline   Reply With Quote

Old   May 26, 2022, 09:40
Default SetExpFiels
  #8
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Hi guy,

Thank you so much for your reply. I did the same and it worked.

Best,
Sadra
sadra2003 is offline   Reply With Quote

Old   November 9, 2022, 12:01
Default Small caveat for future readers
  #9
New Member
 
Join Date: Jun 2019
Location: United States
Posts: 15
Rep Power: 6
ryanc6 is on a distinguished road
Quote:
Originally Posted by olesen View Post
Since your water level is only in 'z' it would be more efficient to define that as a scalar value "0.4" in constants and use ${constant.water_level} as a text replacement. Also, no reason to define height as a variable. Just use drop it straight into the expression as pos().z()

Defining the height directly in the expression by pos().z() instead of a variable has a slight nuance that I've recently discovered. I'm posting my discovery here in case anyone in the future has this same problem.

In this instance the pos().z() can be directly replaced. However, by placing it directly in the expression and not in the variable section first, it retains the dimensionedScalar properties and can cause dimensional problems if the expression is more complex. For example if you're trying to initialize a field as a function of position via an interpolated polynomial and you have to raise the cell center positions by a scalar power. (This is what I was trying to do when I learned about these dimensional caveats.) In this case the dimensions are problematic and the method around that is to specify the pos().z() within the variables section. This returns just the scalar without a dimensional vector attached and the pow(base,exponent) function works properly.
ryanc6 is offline   Reply With Quote

Old   March 7, 2023, 05:28
Default
  #10
New Member
 
Chris
Join Date: Jan 2022
Posts: 22
Rep Power: 4
Chris T is on a distinguished road
Is the setExprFields utility available in OpenFoam v9 as well? I tried to find cases from the tutorials and information from https://cpp.openfoam.org/v9/ and I got nothing.
Chris T is offline   Reply With Quote

Old   March 7, 2023, 05:48
Default
  #11
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Hi chris T,

I dont think that this feature is available in OF9. You can use OF 2112 for instance to generate this file and use it in OF9 simultions.
sadra2003 is offline   Reply With Quote

Old   March 8, 2023, 02:51
Default
  #12
New Member
 
Chris
Join Date: Jan 2022
Posts: 22
Rep Power: 4
Chris T is on a distinguished road
Hi Sandra. Is it not at all present or it could be present with a different name or merged with another utility? This things happen from version to version. Like how chtMultiregionFoam and chtMultiregionSimpleFoam where merged.
In any case I just learned to use codeStream I will use that for now.
Chris T is offline   Reply With Quote

Old   March 8, 2023, 03:05
Default
  #13
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Hi Chris,

I am not sure about OF9 but I know that it is not available in OF8. Thats why I installed OFV2112 to generate the file and use it for the simulations with OF8.

Best regards,
Sadra
sadra2003 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
setExprFields example to generate an initial velocity field for LES of channel flow fumiya OpenFOAM Running, Solving & CFD 6 January 20, 2022 20:30
problem of using setExprFields qi.yang@polimi.it OpenFOAM Pre-Processing 1 May 25, 2021 15:15
Reading fields in setExprFields aeroengprof OpenFOAM Programming & Development 6 February 27, 2021 14:44


All times are GMT -4. The time now is 20:59.