|
[Sponsors] |
October 29, 2021, 09:03 |
setExprFields
|
#1 |
Member
Callum Guy
Join Date: Dec 2019
Location: Scotland
Posts: 44
Rep Power: 6 |
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 |
|
November 1, 2021, 06:11 |
Update: Solved setExprFieldsDict example for multiphase
|
#2 |
Member
Callum Guy
Join Date: Dec 2019
Location: Scotland
Posts: 44
Rep Power: 6 |
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) #}; } ); // ************************************************************************* // |
|
November 1, 2021, 12:04 |
|
#3 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40 |
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()
|
|
November 1, 2021, 13:37 |
|
#4 |
Member
Callum Guy
Join Date: Dec 2019
Location: Scotland
Posts: 44
Rep Power: 6 |
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 |
|
April 19, 2022, 04:57 |
Using setExprFieldsDict
|
#5 | |
Member
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5 |
Quote:
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 |
||
April 19, 2022, 04:58 |
|
#6 | |
Member
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5 |
Quote:
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 |
||
May 26, 2022, 09:25 |
|
#7 |
Member
Callum Guy
Join Date: Dec 2019
Location: Scotland
Posts: 44
Rep Power: 6 |
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) #}; |
|
May 26, 2022, 09:40 |
SetExpFiels
|
#8 |
Member
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5 |
Hi guy,
Thank you so much for your reply. I did the same and it worked. Best, Sadra |
|
November 9, 2022, 12:01 |
Small caveat for future readers
|
#9 | |
New Member
Join Date: Jun 2019
Location: United States
Posts: 15
Rep Power: 6 |
Quote:
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. |
||
March 7, 2023, 05:28 |
|
#10 |
New Member
Chris
Join Date: Jan 2022
Posts: 22
Rep Power: 4 |
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.
|
|
March 7, 2023, 05:48 |
|
#11 |
Member
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5 |
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. |
|
March 8, 2023, 02:51 |
|
#12 |
New Member
Chris
Join Date: Jan 2022
Posts: 22
Rep Power: 4 |
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. |
|
March 8, 2023, 03:05 |
|
#13 |
Member
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5 |
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 |
|
|
|
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 |