|
[Sponsors] |
[swak4Foam] How to define boundary condition variables by using previosly defined variables? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 18, 2017, 09:04 |
How to define boundary condition variables by using previosly defined variables?
|
#1 |
New Member
Join Date: Oct 2017
Posts: 8
Rep Power: 9 |
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"; } Code:
inlet { type groovyBC; value uniform 0.5; variables ( "N2_out{outlet}=sum(N2*mag(Sf()))/sum(mag(Sf()));" ); valueExpression "0.5*N2_out"; } Code:
inlet { type groovyBC; value uniform 0.0; variables ( "N2_out{outlet}=sum(N2*mag(Sf()))/sum(mag(Sf()));" ); valueExpression "1 - N2_out"; } 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) } 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"; } 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 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; // ************************************************************************* // Best regards, pawlo |
|
October 20, 2017, 05:13 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
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" 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 |
|
October 22, 2017, 10:20 |
|
#3 |
New Member
Join Date: Oct 2017
Posts: 8
Rep Power: 9 |
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. |
|
October 22, 2017, 12:29 |
|
#4 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
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; Code:
variables "pInlet@inlet = ..." Good luck,
__________________
Keep foaming, Tobias Holzmann |
|
October 22, 2017, 13:06 |
|
#5 |
New Member
Join Date: Oct 2017
Posts: 8
Rep Power: 9 |
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()));" The variable Code:
"pOutlet2{outlet}=p;" Instead a variable like Code:
"const_1 = 1.;" |
|
October 22, 2017, 14:27 |
|
#6 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Got it, remove your whitespaces. E.g.
Code:
myVar = 1.; myVar=1.; 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;
__________________
Keep foaming, Tobias Holzmann |
|
October 22, 2017, 16:49 |
|
#7 |
New Member
Join Date: Oct 2017
Posts: 8
Rep Power: 9 |
Thank you! Removing the whitespaces helped, it works now!
Last edited by pawlo; October 24, 2017 at 06:18. |
|
January 12, 2019, 15:19 |
|
#8 |
New Member
Nilay Kulkarni
Join Date: May 2018
Posts: 24
Rep Power: 8 |
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 |
|
September 13, 2020, 12:37 |
impedance boundary condition
|
#9 |
Member
|
Dear friends,
How can I apply the impedance boundary condition in OpenFoam? |
|
Tags |
combustion, field, patchvalueexpression, swak4foam error |
|
|
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 |