|
[Sponsors] |
![]() |
![]() |
#1 |
Member
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5 ![]() |
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 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. Last edited by JayDeeUU; December 28, 2020 at 18:59. Reason: Add further information |
|
![]() |
![]() |
![]() |
![]() |
#2 |
Member
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5 ![]() |
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. |
|
![]() |
![]() |
![]() |
![]() |
#3 |
Member
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5 ![]() |
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 Code:
SnoplusAV_intfc0p75_sidewall { type fixedValue; value uniform 0; T nonuniform List<scalar> 302518 <--- (or whatever integer applies) Code:
SnoplusAV_intfc0p75_sidewall { type fixedValue; value nonuniform List<scalar> 302518 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. |
|
![]() |
![]() |
![]() |
![]() |
#4 | |
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 |
||
![]() |
![]() |
![]() |
![]() |
#5 |
Member
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5 ![]() |
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) #}; } ); 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. |
|
![]() |
![]() |
![]() |
![]() |
#6 | |
Member
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5 ![]() |
Quote:
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 |
||
![]() |
![]() |
![]() |
![]() |
#7 |
Member
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5 ![]() |
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) #}; } ); } Hope this helps.. John. |
|
![]() |
![]() |
![]() |
![]() |
#8 | |
Member
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5 ![]() |
Quote:
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 |
||
![]() |
![]() |
![]() |
![]() |
#9 |
Member
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5 ![]() |
Glad you've got what you need Sadra -- best wishes, John
|
|
![]() |
![]() |
![]() |
![]() |
#10 |
New Member
Jarlath
Join Date: Apr 2018
Posts: 12
Rep Power: 8 ![]() |
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 |
|
![]() |
![]() |
![]() |
![]() |
#11 | |
Member
J.D. Wilson
Join Date: Nov 2020
Location: Edmonton, Canada
Posts: 34
Rep Power: 5 ![]() |
Quote:
|
||
![]() |
![]() |
![]() |
|
|
![]() |
||||
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 |