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

Examples of file setExprBoundaryFieldsDict

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By JayDeeUU

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 28, 2020, 11:31
Default Examples of file setExprBoundaryFieldsDict
  #1
Member
 
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5
JayDeeUU is on a distinguished road
I'm running OpenFoam2006 and from some reading I think it should be possible to use the command setExprBoundaryFields (documented at https://www.openfoam.com/documentati...aryFields.html ) to set up a spatially-variable boundary condition by way of an expression. I've managed (by trial and error) to use setExprFieldsDict to set up spatially-varying internal fields for initialization, however two or three searches for the term "setExprBoundaryFieldsDict" have turned up no informative examples. I'm a novice with OpenFoam, and I'd appreciate elementary guidance on how to set up this Dict file. Thanks, John.

Added later: I've made some progress with this, although one mystery remains. I'll attach the relevant files in case anyone should find this post in any way helpful.



As background, my flow domain is a flask, and the mesh is built from three .stl files, defining the "lid," the "sidewall" and the "base". Within snappyHexMeshDict I name three patches:

1) SnoplusAV_intfc0p75_lid, to be held at T=0
2) SnoplusAV_intfc0p75_base, to be held at T= -2.2
3) SnoplusAV_intfc0p75_sidewall. In this patch, using "setExprFields", T is initialized so as to vary from T=-2.2 at the bottom (where it joins the base) to T=0 at a specific height, z=12 [m], and above z=12 [m] the initialization is T=0. This same height-dependent pattern is also to be sustained at the wall temperature on this patch, and the wanted pattern is written to 0/T by "setExprBoundaryFields"

The sequence of commands I am using (with partial success) is:
Code:
blockMesh
surfaceFeatureExtract
snappyHexMesh
checkMesh

cp 0/pattern_holder/prior_T 0/

setExprFields
setExprBoundaryFields 
buoyantBoussinesqSimpleFoam
Note that 0/T is initially filled from prior_T, which I've attached. It then gets overwritten and becomes huge (best not to have it open in an editor, but one can look at it conveniently in vi).

The result of this process is that 0/T, as inspected in vi, has exactly the wanted initial field and (patch by patch) boundary field. For the life of me I can't get paraFoam to correctly show the wall temperature in 0/T (even with internalMesh unchecked), but, it's definitely correct in the file. The attached image is a view in paraFoam of the fluid temperature on the slice y=0, at time 0. It may not be easy to see, but the wall mesh regions are also shown, and the colouring of the lid and base if correct, but the colouring on the sidewall (a uniform red, designating T=0) is inconsistent with the wall temperature on that patch as seen in the file 0/T.

Well that's a puzzle, but there's a bigger problem: after running buoyantBoussinesqSimpleFoam, a look at the solution files, e.g. 10/T, 20/T etc., shows that the height-varying wall boundary temperature set up (by the steps above) in patch "SnoplusAV_intfc0p75_sidewall" has been lost, and the b/cond in "SnoplusAV_intfc0p75_sidewall" has reverted to what had been initially written from prior_T into 0/T. Thus it appears that whatever change setExprBoundaryFields accomplishes, it does not persist.
Attached Images
File Type: png T_wall_Tfluid_t0_28Dec2020.png (18.2 KB, 8 views)
Attached Files
File Type: txt snappyHexMeshDict.txt (9.7 KB, 8 views)
File Type: txt prior_T.txt (2.1 KB, 15 views)
File Type: txt setExprFieldsDict.txt (1.7 KB, 70 views)
File Type: txt setExprBoundaryFieldsDict.txt (1.8 KB, 91 views)

Last edited by JayDeeUU; December 28, 2020 at 18:59. Reason: Add further information
JayDeeUU is offline   Reply With Quote

Old   December 29, 2020, 11:47
Default Further information pertaining to the above
  #2
Member
 
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5
JayDeeUU is on a distinguished road
In order to show the file 0/T after running setExprFields and setExprBoundaryFields, I've attached a copy here, from which I've cut most of the data entries but left enough to indicate the pattern. Similarly, I've made a copy of 6000/T.


You can see that the wanted non-uniform internal and boundary fields are present in 0/T, but that in later files, 6000/T being the example given, the boundaryField for patch SnoplusAV_intfc0p75_sidewall has reverted to being the constant value originally present in the file ("prior_T") originally used to create 0/T.
Attached Files
File Type: txt T_time0_aftersetset_abbreviated.txt (1.6 KB, 11 views)
File Type: txt T_time6000.txt (1.4 KB, 4 views)
JayDeeUU is offline   Reply With Quote

Old   December 30, 2020, 10:18
Default Update - resolution of the problem
  #3
Member
 
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5
JayDeeUU is on a distinguished road
There may be a more elegant way to resolve the problem described above, but in the meantime I've found the following sequence of commands achieves the wanted outcome, in terms of a setup for running the solver:

Code:
blockMesh
surfaceFeatureExtract
snappyHexMesh
checkMesh
cp 0/pattern_holder/prior_T 0/T
setExprFields
setExprBoundaryFields
Now use vi to amend 0/T FROM:
Code:
    SnoplusAV_intfc0p75_sidewall
    {
        type            fixedValue;
        value           uniform 0;
        T               nonuniform List<scalar> 
302518                                             <--- (or whatever integer applies)
TO:
Code:
                             
    SnoplusAV_intfc0p75_sidewall
    {
        type            fixedValue;
        value           nonuniform List<scalar> 
302518
With this setup, I find that the wanted wall boundary condition (set up in 0/T by using setExprBoundaryFields as outlined above) DOES propagate forward and control the boundary temperature as intended.


However there remains a problem. Having set the initial (or, first guess) temperature state to match the wall temperature profile, i.e. an isothermal layer above a statically stable layer, there ought to be a matching state for p_rgh, the departure of kinematic pressure from the hydrostatic state. As I had simply initialized the latter as "uniform 0;" the first guess state could not be the steady state. What has been outlined here is how to impose a reasonably complex combination of the initial state and boundary conditions, but one has to admit the combination doesn't make sense. If this series of posts is to have value for anyone, it will be the "how," not the "why".

Last edited by JayDeeUU; December 30, 2020 at 12:29. Reason: Yet another thought to add.
JayDeeUU is offline   Reply With Quote

Old   April 19, 2022, 05:00
Default
  #4
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Quote:
Originally Posted by JayDeeUU View Post
There may be a more elegant way to resolve the problem described above, but in the meantime I've found the following sequence of commands achieves the wanted outcome, in terms of a setup for running the solver:

Code:
blockMesh
surfaceFeatureExtract
snappyHexMesh
checkMesh
cp 0/pattern_holder/prior_T 0/T
setExprFields
setExprBoundaryFields
Now use vi to amend 0/T FROM:
Code:
    SnoplusAV_intfc0p75_sidewall
    {
        type            fixedValue;
        value           uniform 0;
        T               nonuniform List<scalar> 
302518                                             <--- (or whatever integer applies)
TO:
Code:
                             
    SnoplusAV_intfc0p75_sidewall
    {
        type            fixedValue;
        value           nonuniform List<scalar> 
302518
With this setup, I find that the wanted wall boundary condition (set up in 0/T by using setExprBoundaryFields as outlined above) DOES propagate forward and control the boundary temperature as intended.


However there remains a problem. Having set the initial (or, first guess) temperature state to match the wall temperature profile, i.e. an isothermal layer above a statically stable layer, there ought to be a matching state for p_rgh, the departure of kinematic pressure from the hydrostatic state. As I had simply initialized the latter as "uniform 0;" the first guess state could not be the steady state. What has been outlined here is how to impose a reasonably complex combination of the initial state and boundary conditions, but one has to admit the combination doesn't make sense. If this series of posts is to have value for anyone, it will be the "how," not the "why".
Dear JayDeeUU,

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, 22:03
Default
  #5
Member
 
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5
JayDeeUU is on a distinguished road
Hi Sadra,


The code below should do it I think.
Code:
defaultFieldValues
(
volScalarFieldValue T 290.0  
);


expressions
(
        
  T
  {
      field  T;
      dimensions [0 0 0 1 0 0 0];
      variables
      (
          // you can define some variables for convenience
          "ymin=0.75"
          "dTdy= 0.1"  // (your "c")
      );
            
      condition
      #{
          
        1 < 2 

        // example of a more complex condiiton
        //(pos().z() >= 2.5 ) && (pos().z() <= 5.0 ) 
                
      #};
            
      expression
      #{                    
        290.0 + dTdy*(pos().y()-ymin)                
      #};
  }      
);
You'll also need to use setExprBoundaryFields to set your wanted b/conds.



It might be worthwhile to learn the method shown at https://www.youtube.com/watch?v=K-nAF3qAPTc , because it is very flexible.


Best of luck, John.
JayDeeUU is offline   Reply With Quote

Old   April 20, 2022, 02:54
Default setExprBoundaryFields
  #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 JayDeeUU View Post
Hi Sadra,


The code below should do it I think.
Code:
defaultFieldValues
(
volScalarFieldValue T 290.0  
);


expressions
(
        
  T
  {
      field  T;
      dimensions [0 0 0 1 0 0 0];
      variables
      (
          // you can define some variables for convenience
          "ymin=0.75"
          "dTdy= 0.1"  // (your "c")
      );
            
      condition
      #{
          
        1 < 2 

        // example of a more complex condiiton
        //(pos().z() >= 2.5 ) && (pos().z() <= 5.0 ) 
                
      #};
            
      expression
      #{                    
        290.0 + dTdy*(pos().y()-ymin)                
      #};
  }      
);
You'll also need to use setExprBoundaryFields to set your wanted b/conds.



It might be worthwhile to learn the method shown at https://www.youtube.com/watch?v=K-nAF3qAPTc , because it is very flexible.


Best of luck, John.
Hi John,

Thanks alot for your help. I modified the code that you shared and it works for me. You told me that "You'll also need to use setExprBoundaryFields to set your wanted b/conds". Do you mean that if I use "setExprFields", I have to use "setExprBoundaryFields" in my case (0 folder) instead of the ordinary files that I have in 0 folder?

Thanks and stay safe,
Sadra
sadra2003 is offline   Reply With Quote

Old   April 20, 2022, 11:09
Default Necessity to apply setExprBoundaryFields
  #7
Member
 
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5
JayDeeUU is on a distinguished road
Hi Sadra,


In general, one may have the situation that the initial values of a field internally, i.e. away from the boundary/ies, differ from what you want to apply at the wall. In your case apparently you want, at the initial time, T=c y. But what is to be your boundary condition? Recall this is applied patch by patch in your 0/T file. In the simplest cases you might prescribe a constant boundary value on each patch, in which case you simply set the wanted value in 0/T. But what if you wanted some more complex variation over a patch? Then you would - or could - use setExprBoundaryFields. Here's an example of the main content of a setExprBoundaryFieldsDict file, just to give an idea.
Code:
pattern
{
    field   T;

    expressions
    (
        {
            patch lid;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
        {
            patch neck;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
        {
            patch shell_top;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
        {
            patch shell_upper;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
        {
            patch shell_lower;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
        {
            patch shell_base;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
    );
}
This is a very simple example. The wall temperature varies only with coordinate y, and is constrained by the same function on each of the 6 patches.


Hope this helps.. John.
JayDeeUU is offline   Reply With Quote

Old   April 26, 2022, 03:13
Default BCs
  #8
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Quote:
Originally Posted by JayDeeUU View Post
Hi Sadra,


In general, one may have the situation that the initial values of a field internally, i.e. away from the boundary/ies, differ from what you want to apply at the wall. In your case apparently you want, at the initial time, T=c y. But what is to be your boundary condition? Recall this is applied patch by patch in your 0/T file. In the simplest cases you might prescribe a constant boundary value on each patch, in which case you simply set the wanted value in 0/T. But what if you wanted some more complex variation over a patch? Then you would - or could - use setExprBoundaryFields. Here's an example of the main content of a setExprBoundaryFieldsDict file, just to give an idea.
Code:
pattern
{
    field   T;

    expressions
    (
        {
            patch lid;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
        {
            patch neck;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
        {
            patch shell_top;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
        {
            patch shell_upper;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
        {
            patch shell_lower;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
        {
            patch shell_base;
            target  T;
            expression #{ 290.0+0.1*(pos().y()-5.0) #};
        }
    );
}
This is a very simple example. The wall temperature varies only with coordinate y, and is constrained by the same function on each of the 6 patches.


Hope this helps.. John.

Hi John,

Sorry for my late response.
I was out of my office due to a conference.
Your explanations helped me alot actually. In mt case, I woiuld need to apply a constant temperature on the walls which is not complex. So, I would not need to use setExprBoundaryFieldsDict . Anyway, thanks a lot.

Best regards,
Sadra
sadra2003 is offline   Reply With Quote

Old   April 26, 2022, 08:31
Default
  #9
Member
 
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5
JayDeeUU is on a distinguished road
Glad you've got what you need Sadra -- best wishes, John
sadra2003 likes this.
JayDeeUU is offline   Reply With Quote

Old   January 15, 2024, 09:39
Default setExprBoudaryFields for U
  #10
New Member
 
Jarlath
Join Date: Apr 2018
Posts: 12
Rep Power: 8
JMcnetee is on a distinguished road
Hi Folks

Thanks for all the info on setExprFields and setExprBoundaryFields. Its been helpful.

However, I am still hitting what seems to be a brick wall with trying to set up a variable inflow speed across a patch. The examples given are for a scalar. Are there any examples for a vector like U?

Also, having that weird issue where even if the values show up in 0/U they do not show up in paraFoam or paraview

Cheers
Jarlath
JMcnetee is offline   Reply With Quote

Old   January 16, 2024, 16:43
Default
  #11
Member
 
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5
JayDeeUU is on a distinguished road
Quote:
Originally Posted by JMcnetee View Post
Hi Folks

Thanks for all the info on setExprFields and setExprBoundaryFields. Its been helpful.

However, I am still hitting what seems to be a brick wall with trying to set up a variable inflow speed across a patch. The examples given are for a scalar. Are there any examples for a vector like U?

Also, having that weird issue where even if the values show up in 0/U they do not show up in paraFoam or paraview

Cheers
Jarlath
Hi Jarlath... I haven't checked the link, but as I noted above if you need an arbitrarily complex distribution of a variable over a patch, it can be done easily enough along the lines covered at https://www.youtube.com/watch?v=K-nAF3qAPTc . Re- the field in 0/U not showing in paraFoam, do you have the mesh de-selected? (that could be one reason).
JayDeeUU 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
how to calculate mass flow rate on patches and summation of that during the run? immortality OpenFOAM Post-Processing 104 February 16, 2021 08:46
[foam-extend.org] problem when installing foam-extend-1.6 Thomas pan OpenFOAM Installation 7 September 9, 2015 21:53
[swak4Foam] Problem installing swak_2.x for OpenFoam-2.4.0 towanda OpenFOAM Community Contributions 6 September 5, 2015 21:03
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 11:44
ParaView Compilation jakaranda OpenFOAM Installation 3 October 27, 2008 11:46


All times are GMT -4. The time now is 21:42.