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

New expression version of Function1

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 2 Post By olesen
  • 3 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 10, 2020, 06:43
Default New expression version of Function1
  #1
New Member
 
Joe
Join Date: Oct 2016
Posts: 15
Rep Power: 9
OOTB is on a distinguished road
Hi all...


I'm looking to set a boundary condition on an inlet patch as to specify alpha.water = 1 below a certain z position (interFoam). Using the expression version of Function 1 as per the OpenFoam documentation I tried the following:


alpha.water
Quote:
inlet
{
type uniformFixedValue;
uniformValue
{
type expression;
expression #{ (pos().z < 38.2) ? 1 : 0 #};
}
}
It however gives a syntax error just after pos().z


Does anyone perhaps know the correct syntax for using pos()?

Last edited by OOTB; September 10, 2020 at 08:03. Reason: added quote tags
OOTB is offline   Reply With Quote

Old   September 10, 2020, 07:53
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
In which OpenFOAM version can one apply this syntax? Is it implemented in the ESI version? In any case, I guess you cannot use the pos() function out of the box, because you need a reference to an object. You even did not specify the error message so it is a bit hard to give valuable feedback.

Nevertheless, as you showed the condition you set (please use code tags - update your post), it seems to be somehow similar to the codedMixed boundary condition. If I am right, you need an object first. An example:

Code:
inlet
{
    type uniformFixedValue;
    uniformValue
    {
        type         expression;
        expression 
        #{
                // Actual time   --> t is an object of type scalar
                const scalar t = *this->db().time().runTime();
        #};
}
However, while checking your code, I found that you had a missing simicolon at the end of your if-else condition:

Code:
inlet
{
    type uniformFixedValue;
    uniformValue
    {
        type         expression;
        expression 
        #{
                   (pos().z < 38.2) ? 1 : 0      // << ; missing
        #};
}
However, as I donīt know this kind of implementation, I am not sure if my hints are fine or totally wrong. But on the other hand, you did not provide enough information.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   September 10, 2020, 08:20
Default
  #3
New Member
 
Joe
Join Date: Oct 2016
Posts: 15
Rep Power: 9
OOTB is on a distinguished road
Hi Tobi, thanks for the reply.
I'm using OpenFoam v2006. They have an example here (attached a clip) https://www.openfoam.com/releases/openfoam-v2006/pre-processing.php

The error code is generated when running setFields and is as follows:

Quote:
--> FOAM FATAL IO ERROR:

Syntax error in expression at position:9
<<<<
pos().z < 38.2 ? 1 : 0;

.............^^^^ near here
>>>>
Attached Images
File Type: png Screenshot from 2020-09-10 14-08-06.png (44.2 KB, 37 views)
OOTB is offline   Reply With Quote

Old   September 11, 2020, 10:11
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 OOTB View Post
Hi all...


I'm looking to set a boundary condition on an inlet patch as to specify alpha.water = 1 below a certain z position (interFoam). Using the expression version of Function 1 as per the OpenFoam documentation I tried the following:


alpha.water

It however gives a syntax error just after pos().z


Does anyone perhaps know the correct syntax for using pos()?

The documentation : https://www.openfoam.com/documentati...on-syntax.html

In swak4foam I think you could have '.z', but for the OpenFOAM expressions you need '.z()' for the component. This makes it looks more like C++ code, and also makes the parser more deterministic.
For a similar reason we have 'pi()', which looks like a function call, but actually maps to a constant value. For things like 'degToRad()' you can have both versions, as a constant or a function. Eg,


Code:
    45 * degToRad()



    degToRad(45)
avk1985 and petros like this.
olesen is offline   Reply With Quote

Old   September 11, 2020, 10:16
Default
  #5
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 Tobi View Post
In which OpenFOAM version can one apply this syntax? Is it implemented in the ESI version? In any case, I guess you cannot use the pos() function out of the box, because you need a reference to an object.
The 'pos()' will be defined if you are using an expressionPatchFunction1, since it already knows that it associated with a patch. In this context it will mean the face centres.
Quote:
Originally Posted by Tobi View Post

...
However, while checking your code, I found that you had a missing simicolon at the end of your if-else condition:

Code:
inlet
{
    type uniformFixedValue;
    uniformValue
    {
        type         expression;
        expression 
        #{
                   (pos().z < 38.2) ? 1 : 0      // << ; missing
        #};
}
However, as I donīt know this kind of implementation, I am not sure if my hints are fine or totally wrong. But on the other hand, you did not provide enough information.
The expressions are self-contained, so they do not have a semi-colon.
Tobi, avk1985 and petros like this.
olesen is offline   Reply With Quote

Old   September 13, 2020, 06:46
Default
  #6
New Member
 
Joe
Join Date: Oct 2016
Posts: 15
Rep Power: 9
OOTB is on a distinguished road
Thank you Mark.. it worked! Its much appreciated.
OOTB is offline   Reply With Quote

Old   September 14, 2020, 08:21
Default
  #7
Senior Member
 
JNSN's Avatar
 
Jan
Join Date: Jul 2009
Location: Hamburg
Posts: 137
Rep Power: 19
JNSN is on a distinguished road
Hi,


just for sake of completeness: You could achive same much simpler by just using fixedValue BC and initialize with setFields (as done e.g in the DTCHull tutorial). Or initialization with setWaves tool would even allow to set alpha values indipendent of the cell coordinates, giving you "correct" vof values between 0 and 1 for partially filled cells.


Best,
Jan
JNSN is offline   Reply With Quote

Old   September 14, 2020, 09:14
Default
  #8
New Member
 
Joe
Join Date: Oct 2016
Posts: 15
Rep Power: 9
OOTB is on a distinguished road
Thank you Jan,

I want to set different fixed levels on the inlet and outlet patches.. I'm not sure how to do it with setFields.

regards
OOTB is offline   Reply With Quote

Old   September 14, 2020, 09:25
Default
  #9
Senior Member
 
JNSN's Avatar
 
Jan
Join Date: Jul 2009
Location: Hamburg
Posts: 137
Rep Power: 19
JNSN is on a distinguished road
you can define separate boxes, including only inlet or outlet. Values for the patches are set within the boxToFace block. However, no idea how to ensure consistent initialization within the domain. But I think you have same problem when using the uniformFixedValue BC in combination with expression.


Best,
Jan
JNSN is offline   Reply With Quote

Reply

Tags
function1


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
OpenFOAM.com versus OpenFOAM.org: Which version to use? wyldckat OpenFOAM 19 March 25, 2023 07:50
CEL expression in CFX pre Jane92 Main CFD Forum 1 June 3, 2016 02:48
libz.so.1: no version information available dmaz OpenFOAM Running, Solving & CFD 3 January 4, 2015 16:54
[Matlab] - Add toolbox to version R2012b. darkluix88 Lounge 2 October 23, 2014 10:23
CGNS lib and Fortran compiler manaliac Main CFD Forum 2 November 29, 2010 06:25


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