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

[swak4Foam] How to define boundary condition variables by using previosly defined variables?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Tobi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 18, 2017, 09:04
Default How to define boundary condition variables by using previosly defined variables?
  #1
New Member
 
Join Date: Oct 2017
Posts: 8
Rep Power: 9
pawlo is on a distinguished road
Hello everyone!

I am new to OpenFOAM (v 2.3.0) and swak4Foam ( v 0.4.1) and i have a problem in defining new variables in boundary conditions by using already existing variables.

What i want to do is a combustion simulation where the mass fraction of 5 species (+1 inert) at my inlet needs to by adjustet by the mass fractions at the outlet in every time step. The species are CO, CO2, H2O, O2, N2 and a inert specie "A" with the same properties as N2 (i will explain later why i need A and N2 is not the actual inert specie).

So basically i have a function f, taking the arguments:

CO@outlet
CO2@outlet
H2O@outlet
O2@outlet
N2@outlet
Temperature@outlet

and giving me a new value SPECIE_i_@inlet for all the mentioned species and a new overall massflux dM@inlet. My function f is consistent in means of always giving mass fractions that sum up to 1.

To test if i could implement such a simulation i set up a very simple 2D case with swak4Foam and restricted the number of species to 4, i.e. CO, H2O, N2 and inert A, and turned off combustion/reactions. The geometry is just a square with the inlet on the left and outlet on the right, top and bottom are walls.

At the beginning at t = 0 the internalField is filled only with N2. The BC on the inlet for CO, H2O, N2 are the following:

File: 0/CO

Code:
 inlet
    {
        type            groovyBC;
        value            uniform 0.5;
        variables (
            "N2_out{outlet}=sum(N2*mag(Sf()))/sum(mag(Sf()));"
        );
        valueExpression "0.5*N2_out";
    }
File: 0/H2O

Code:
inlet
    {
        type            groovyBC;
        value           uniform 0.5;
        variables (
            "N2_out{outlet}=sum(N2*mag(Sf()))/sum(mag(Sf()));"
        );
        valueExpression "0.5*N2_out";
    }
File : 0/N2

Code:
inlet
    {
        type            groovyBC;
        value           uniform 0.0;
        variables (
            "N2_out{outlet}=sum(N2*mag(Sf()))/sum(mag(Sf()));"
        );
        valueExpression "1 - N2_out";
    }
The outlet BC for all three above species is of type inletOutlet with inletValue = value = 0 for CO and H2O, and inletValue = value = 1 for N2. The mass fraction of inert A is set to zero for all fields for all times.

In this constellation my simulation works very nice, the mass fractions at the inlet change during my simulation, always summing up to 1. And here is why i need the inert specie A:

First i did not had specie A, and N2 was the inert specie. Unfortunately the above inlet BC for N2 does not work when N2 is inert. The mass fraction of N2 at the inlet is not changing during the simulation, it stays at the value given by "value uniform 0.0;". Furthermore this causes the mass fractions at the inlet to not sum up to 1. So i had to overcome this by adding another specie witch is actually not used (mass fraction = 0 everywhere for all times) during the simulation. Maybe you know a better way to solve this issue?

But my main problem is the following:

After the successfull test of the above simulation i startet implementing my function f in the BC files. In my function i
1) first need to define some constants, then
2) read the mass fractions and temperature at the outlet and store them in variables
3) define some variables by arithmetic operations between constants from step 1) and variables from step 2). And finally
4) calculate the final result for a certain specie.

So all in all the inlet entry in the BC file for one species, lets say CO, would look like this:

Code:
inlet
    {
        type            groovyBC;
        value           uniform 0.5;
        variables (
            "const_1 = 1.;"  // step 1)
            "const_2 = 2.;"  // step 1)
            "N2_out{outlet}=sum(N2*mag(Sf()))/sum(mag(Sf()));"  // step 2)
            "var_1 = const_1 * N2_out;"  // step 3)
        );
        valueExpression "const_2 - N2_out";  // step 4)
    }
Unfortunately this does not work and boils down to the following Problem: (inlet entry simplyfied even more)

Code:
inlet
    {
        type            groovyBC;
        value           uniform 0.5;
        variables (
            "const_1 = 1.;"
            "N2_out{outlet}=sum(N2*mag(Sf()))/sum(mag(Sf()));"

        );
        valueExpression "const_1 * N2_out";
    }
witch gives the following error message:

Code:
/*---------------------------------------------------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
Build  : 2.3.0-f5222ca19ce6
Exec   : rhoReactingFoam
Date   : Oct 18 2017
Time   : 10:56:53
Host   : BLANKED OUT
PID    : 40007
Case   : BLANKET OUT/T1_Prototyp_RB
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0


Reading g
Creating reaction model

Selecting combustion model PaSR<rhoChemistryCombustion>
Selecting chemistry type 
{
    chemistrySolver EulerImplicit;
    chemistryThermo rho;
}

Selecting thermodynamics package 
{
    type            heRhoThermo;
    mixture         reactingMixture;
    transport       sutherland;
    thermo          janaf;
    energy          sensibleEnthalpy;
    equationOfState perfectGas;
    specie          specie;
}

Selecting chemistryReader foamChemistryReader
chemistryModel: Number of species = 6 and reactions = 0
    using integrated reaction rate
Reading field U

Reading/calculating face flux field phi

Creating turbulence model.

Selecting turbulence model type laminar
Creating field dpdt

Creating field kinetic energy K

No finite volume options present

Courant Number mean: 2.389033178511972e-07 max: 7.167099535536555e-05

PIMPLE: Operating solver in PISO mode


Starting time loop

Courant Number mean: 2.388985398803996e-07 max: 7.166956196412627e-05
deltaT = 1.199961601228761e-06
Time = 1.199961601228761e-06

diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
swak4Foam: Setting default mesh
swak4Foam: Allocating new repository for sampledGlobalVariables
--> FOAM Warning : 
    From function ConcretePluginFunction<DriverType>::exists
    in file lnInclude/ConcretePluginFunction.C at line 121
    Constructor table of plugin functions for PatchValueExpressionDriver is not initialized


--> FOAM FATAL ERROR: 
 Parser Error for driver PatchValueExpressionDriver at "1.1-2" :"field const_1 not existing or of wrong type"
"const1*N2_out"
  ^^^^^^^
--| 

Context of the error:


- From dictionary: /home/BLANKED OUT/OpenFOAM/T1_Prototyp_RB/0/CO.boundaryField.inlet
  Evaluating expression "const1*N2_out"


    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 1247.

FOAM exiting
This message tells me that my const_1 is somehow of a wrong type (why is it assumed to be a field?) and unknown to the line of code right underneath the definition of const_1.

I also read a lot of other threads about similar problems, but non of them could help me. In the swak4Foam documumentation the definition of a variable looks like this in the most simple way: <variable_name> = <expression> . So maybe it is not possible to pass a variable to the RHS of a new variable because an expression is expected. If so, how can i convert a variable into an expression?

Moreover i read something about function objects in the controlDict file and looked inside some of the example cases in the swak4Foam folder (mainly ../groovyBC/pulsedPitzDaily). At this time (i am working just about 2 weeks now with OpenFOAM and swak4Foam) i do not know a lot about function objects and the function objects inside the example's controlDict file does not seem to be correlated to the contents of the BC files at first sight.

This is the content of my controlDict:

Code:
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

libs (
    "libOpenFOAM.so"
    "libgroovyBC.so"
    "libswakFunctionObjects.so"
    "libsimpleSwakFunctionObjects.so"
    "libfieldFunctionObjects.so"
) ;

application     rhoReactingFoam;

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         1;

deltaT          1e-6;

writeControl    adjustableRunTime;

writeInterval   0.05;

purgeWrite      0;

writeFormat     ascii;

writePrecision  16;

writeCompression off;

timeFormat      general;

timePrecision   16;

runTimeModifiable true;

adjustTimeStep  yes;

maxCo           0.4;


// ************************************************************************* //
Could you please help me with my problem?

Best regards,
pawlo
pawlo is offline   Reply With Quote

Old   October 20, 2017, 05:13
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
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
Hi Pawlo,

its a while ago that I used the tool from Bernhard but maybe the parser does not like your underscores as we can see in the output:
Code:
--> FOAM FATAL ERROR: 
 Parser Error for driver PatchValueExpressionDriver at "1.1-2" :"field const_1 not existing or of wrong type"
"const1*N2_out"
  ^^^^^^^
--| 

Context of the error:


- From dictionary: /home/BLANKED OUT/OpenFOAM/T1_Prototyp_RB/0/CO.boundaryField.inlet
  Evaluating expression "const1*N2_out"
As we can see, the field const_1 does somehow not exist which should be and in the next lines we do not have an underscore in the variable name. That is just a guess right now but try it and give us feedback.
Otherwise let me know and I can check the Groovy stuff.

The other two questions. a) You can use variables to define other. That is possible and does not make trouble. b) the function libs - as you mentioned - are not function objects. The thing you are talking about is the inclusion of new new libraries for the solver in order to tell FOAM: Look, there is the the library you need during the run. This libraries have to be set because they were not put into the compilation during the solver and offers us flexibility. Function objects are something else. E.g. the postProcess libraries such as the forceCoeffs, streamlines ... Here we define a new function object which can be used during calculation. Thats why a passive scalar equation can be included into each solver using function objects instead of hard-coding it to the solver and recompile it again. By the way, well explained post! Thumbs up.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   October 22, 2017, 10:20
Default
  #3
New Member
 
Join Date: Oct 2017
Posts: 8
Rep Power: 9
pawlo is on a distinguished road
Hi Tobi,

thank you for looking at my problem! The underscore is not the problem, the missing underscore in const1 in the error message was a copy paste mistake
( I ran the simulation on linux and copied the error message from the terminal into a file. Then i created this thread using copy paste in windows, maybe i accidently changed the file while copying...).

So there is no difference between a variable called "const_1" and lets say "c1", it is still the same error.
pawlo is offline   Reply With Quote

Old   October 22, 2017, 12:29
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
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
Hi,

I was checking the syntax. I was using that one on my pressure field
Code:
    outlet                                                                      
    {                                                                           
        type            groovyBC;                                               
        value           uniform 0;                                              
                                                                                
       valueExpression "0.5*(pInlet+pOutlet2)";                                 
              variables "pInlet{inlet}=sum(p*mag(Sf()))/sum(mag(Sf()));pOutlet2{outlet}=p;";
                     value uniform 100010;
That is working fine for me. However, you are using an old FOAM version right, OpenFOAM 2.3.0. Therefore the syntax might be different. Check your swak4Foam folder -> examples. In previous versions it was the »@« literal for referring to patches. E.g.
Code:
variables "pInlet@inlet = ..."
see also: https://openfoamwiki.net/index.php/Contrib/groovyBC

Good luck,
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   October 22, 2017, 13:06
Default
  #5
New Member
 
Join Date: Oct 2017
Posts: 8
Rep Power: 9
pawlo is on a distinguished road
Hi,

the syntax with {outlet} is working in my case, just as the pInlet{inlet} and pOutlet2{outlet} variables in your example.
The problem is, that whenever i try to define a variable that is not created by a function from a patch/internalField, etc. ,
or is not created by an assignment of a property at the relevant patch, that variable is unknown/not existent to other variables.
Maybe this is a bit confusing, so here is an example based on your example with your outlet entry:

The variable

Code:
"pInlet{inlet}=sum(p*mag(Sf()))/sum(mag(Sf()));"
is created by calling the functions sum(), mag(), Sf() on the outlet patch property "p".

The variable

Code:
"pOutlet2{outlet}=p;"
is created by direct assignment of the outlet property "p".

Instead a variable like
Code:
"const_1 = 1.;"
in my case, has nothing to do with any patches, properties, and functions that operate on these.
pawlo is offline   Reply With Quote

Old   October 22, 2017, 14:27
Default
  #6
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
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
Got it, remove your whitespaces. E.g.

Code:
myVar = 1.;
myVar=1.;
Let me know if it works. I tried it with the code given in the wiki page:
Code:
type            groovyBC;                                               
value           uniform 0;                                              
                                                                                
variables "myVar=1.;pInlet{inlet}=sum(p*mag(Sf()))/sum(mag(Sf()));pOutlet2{outlet}=p;";
valueExpression "0.5*(pInlet+pOutlet2)*myVar";                          
value uniform 100010;
petros likes this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   October 22, 2017, 16:49
Default
  #7
New Member
 
Join Date: Oct 2017
Posts: 8
Rep Power: 9
pawlo is on a distinguished road
Thank you! Removing the whitespaces helped, it works now!

Last edited by pawlo; October 24, 2017 at 06:18.
pawlo is offline   Reply With Quote

Old   January 12, 2019, 15:19
Default
  #8
New Member
 
Nilay Kulkarni
Join Date: May 2018
Posts: 24
Rep Power: 8
neilk is on a distinguished road
Hello,

I have a doubt regarding mixed boundary condition. I'm trying to apply a mixed BC to a wall to simulate mass transfer across it such that the mass transfer varies along the wall according to local mass gradients. I have attached the boundary condition equation below where Cmucus is the mass concentration which undergoes convection-diffusion and the coefficients of Cmucus are constants.

Attachment 67717

Thank you
neilk is offline   Reply With Quote

Old   September 13, 2020, 12:37
Default impedance boundary condition
  #9
Member
 
Arash Mahboubidoust
Join Date: Jun 2013
Location: Iran
Posts: 58
Rep Power: 13
arashfluid is on a distinguished road
Send a message via Yahoo to arashfluid
Dear friends,
How can I apply the impedance boundary condition in OpenFoam?
Attached Images
File Type: jpg impedanceBC.jpg (2.9 KB, 19 views)
arashfluid is offline   Reply With Quote

Reply

Tags
combustion, field, patchvalueexpression, swak4foam error


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
CFD analaysis of Pelton turbine amodpanthee CFX 31 April 19, 2018 19:02
Robin boundary condition containing two dependent variables babakflame OpenFOAM Programming & Development 0 February 25, 2017 20:04
Basic Nozzle-Expander Design karmavatar CFX 20 March 20, 2016 09:44
Free surface boudary conditions with SOLA-VOF Fan Main CFD Forum 10 September 9, 2006 13:24
UDF FOR UNSTEADY TIME STEP mayur FLUENT 3 August 9, 2006 11:19


All times are GMT -4. The time now is 18:36.