|
[Sponsors] |
[swak4Foam] Defining constants for funkySetFields and groovyBC |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
November 29, 2011, 16:03 |
Defining constants for funkySetFields and groovyBC
|
#1 |
New Member
Alex Naiman
Join Date: Nov 2011
Location: Menlo Park, CA
Posts: 2
Rep Power: 0 |
I'd like to set some constant values in a single file that will be used to define my velocity boundary conditions and initial conditions. I've attempted to do this by writing them as variables in a file (say, "case/0/include/constants"):
Code:
variables ( "Uref=1.0;" ); Code:
boundaryField { inlet { type groovyBC; value $internalField; #include "include/constants" valueExpression "vector(Uref, 0, 0)"; } } But I would also like to use the same constants to set the initial velocity field. I tried including the file (in "case/system/funkySetFieldsDict"): Code:
expressions ( init_U { field U; expression "vector(Uref, 0, 0)"; keepPatches 1; #include "../0/include/constants" } ); I'm not entirely clear on how parsing of the dictionary files happens - am I using the #include directive wrong? Or is this a funkySetFields bug? Thanks for any suggestions, Alex |
|
November 29, 2011, 19:01 |
|
#2 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Code:
defaultVariables ( "Uref=1.0;" ); Code:
variables $defaultVariables; |
||
November 30, 2011, 13:29 |
|
#3 | ||
New Member
Alex Naiman
Join Date: Nov 2011
Location: Menlo Park, CA
Posts: 2
Rep Power: 0 |
Quote:
Quote:
|
|||
November 30, 2011, 14:32 |
|
#4 | |||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Quote:
|
||||
October 3, 2013, 13:46 |
|
#5 |
New Member
sasan
Join Date: Sep 2013
Posts: 28
Rep Power: 13 |
Hi all
I want simulate two phase flow and I have Non-uniform initial conditions,I know,should use funkySetFields for this, and I read http://openfoamwiki.net/index.php/Co...funkySetFields but I have problem and cant write true ,I attach my equation (that show interface two phase) any body know how Write this equation with funkySetFields |
|
October 3, 2013, 14:01 |
|
#6 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Before I go on: what docu HAVE you already read? (I think that the funkySetFields and the swak-page on the Wiki should have all the information necessary for your equation. Maybe also read the reference guide which is linked from the swak-page)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
December 1, 2016, 06:34 |
funckySetFieldsDict and #include "file_with_variables"
|
#7 |
New Member
|
Hi all,
dear gschaider and anaiman, I have read your posts about the importing constants for funkySetFields. did you solved the problem? I am having a similar problem. I would like to import some variables in the funckySetFieldsDict, using the #include function in this way: ///////////////////////////////////////////////// #include "initialConditions" defaultFieldValues ( volScalarFieldValue alpha.water 0 ); expressions ( init_alpha.water { field alpha.water; expression "(((max(min((($a*cos(($omega*time())-($k*pos().x)))-pos().z),$tr/2),-$tr/2))+$tr/2)/$tr)"; condition "pos().x<=0.1"; keepPatches true; //keep the boundary conditions that were set before } ); obviously the variables called inside the expression are all included in the file InitialConditions. This code does not work at all! FOAM says me: .... --> FOAM FATAL ERROR: Entry "a" not found in ".init_alpha.water" From function CommonValueExpressionDriver::getEntryString in file CommonValueExpressionDriver.C at line 699. FOAM exiting I am stuck with it. Please could you help me to solve this issue? Thank you so much PS: I have also tried to put #include "initialConditions" inside expression, but this does not give me a good results: .... --> FOAM FATAL IO ERROR: keyword field is undefined in dictionary ".init_alpha.water" file: .init_alpha.water from line 3 to line 32. From function const Foam::entry& Foam::dictionary::lookupEntry(const Foam::word&, bool, bool) const in file db/dictionary/dictionary.C at line 441. FOAM exiting |
|
December 4, 2016, 06:37 |
|
#8 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
At first: please use the CODE-tag (that is the # in the icons of the editor). It makes it much clearer what is your text and what is OF-input/output
Quote:
Code:
foo 42; bar 666 Code:
bar 666 field alpha.water; Still there might be a problem with the macro-expansion as the semantics of that changed a bit between OF-versions so it would be important to know what that is
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
December 5, 2016, 15:14 |
|
#9 | |
New Member
|
Quote:
Dear gschaider, first of all thank you for your kind reply. I have modified the funkySetfieldDict as follow: /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: v4.x | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object funkySetFieldsDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // defaultFieldValues ( volScalarFieldValue alpha.water 0 ); expressions ( init_alpha.water { defaultVariables ( #include "initialConditions" ); variables ( "#defaultVariables;" "eta = a*cos((omega*time())-(k*pos().x))" "M1 = min(eta-pos().z,tr/2);" "M2 = max(M1,-tr/2);" ); field alpha.water; expression "(M2+0.5*tr)/tr"; condition "pos().x<=0.5"; keepPatches true; //keep the boundary conditions that were set before } ); and here it is the initialConditions file: /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: v4.x | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object initialConditions; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // h 0.5; T 6; H 0.1; a 0.05; omega 1.0472; L 13.1611; c 2.19351; k 0.477406; xmin 0; ymin 0; zmin -0.5; xmax 39; ymax 0.1; zmax 0.4; z0 0; x1 6; x2 32; pz1 0.28; pz2 0.195; pz3 0.195; pz4 0.33; ztot 0.9; Ncz 100; dz 0.009; tr 0.009; /* The dictionary works better, but there is still an error that I do not understand at all: /*---------------------------------------------------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 4.x | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ Build : 4.x-a6a964b26579 Exec : funkySetFields -time 0 Date : Dec 05 2016 Time : 20:06:30 Host : "viciolinux" PID : 6602 Case : /home/vicio/OpenFOAM/vicio-4.x/run/wave1 nProcs : 1 sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE). fileModificationChecking : Monitoring run-time modified files using timeStampMaster allowSystemOperations : Allowing user-supplied system call operations // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // swakVersion: 0.4.1 (Release date: Next release) - HG Branch: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Create time Using #calcEntry at line 28 in file "/home/vicio/OpenFOAM/vicio-4.x/run/wave1/system/controlDict" Using #codeStream with "/home/vicio/OpenFOAM/vicio-4.x/run/wave1/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_129f61639bcd524f3f670ac2b58913ef0a86 7c06.so" Create mesh for time = 0 Time = 0 Using funkySetFieldsDict Part: init_alpha.water Modifying field alpha.water of type volScalarField Putting "(M2+tr/2)/tr" into field alpha.water at t = "0" if condition "pos().x<=0.5" is true Keeping patches unaltered --> FOAM FATAL IO ERROR: wrong token type - expected string, found on line 1 the word 'FoamFile' file: .init_alpha.water.defaultVariables at line 1. From function Foam::Istream& Foam:perator>>(Foam::Istream&, Foam::string&) in file primitives/strings/string/stringIO.C at line 56. FOAM exiting Any ideas about this issue? Thank you again! Regards, Vincenzo |
||
December 8, 2016, 17:53 |
|
#10 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Please start using the CODE-tag if I ask you for it. It makes it much easier to distinguish your text and the input/output. Formatting is also nicer. It takes you only 2 seconds to click on the # but it saves me 20 seconds of head scratching ("where does this file end? Is that REALLY part of the file? Indentation would make this easier to read"). If you think that your two seconds are more valuable than my 20 seconds then I'll assume that you can answer the question yourself and ignore further postings from you
Quote:
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
December 9, 2016, 05:18 |
#include <file> doe not work
|
#11 |
New Member
|
Hi, thank you for your reply.
I think this is not the reason why the #include does not work. Actually I have used this file (initialConditions) as it is in other "applications" and OpenFOAM gives me NO errors! ...for example I used this file in groovyBC and it works, in blockMeshDict it works, in setFieldsDict works ... However, as you are suggesting me I have used the initialConditions file without the header and OpenFOAM still replies me with the same fu**** error. So, I think that the #include <file> does not work at all in the funkySetFieldDict, I mean this is bug. For a short time I thought there were an error in the expressions, so I removed the #include <file> and wrote the variables into the funkySetFieldDict file....and it works pretty good! However the #include file could have been a smart way in order to reduce some repeated variables, as you can see in the following funkySetFieldDict file. Again, thank you. code: /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 4 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object funkySetFieldsDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "initialConditions" defaultFieldValues ( volScalarFieldValue alpha.water 0; volVectorFieldValue U 0; ); expressions ( AlphaWater_Inlet { field alpha.water; expression "aw_inlet"; keepPatches false; //keep the boundary conditions that were set before patchName "inlet"; variables ( "a=0.05;" "omega=1.0472;" "tshift=-pi/2;" "eta_inlet=a*cos(omega*(tshift));" "thres=0.009;" //threshold value depends on the mesh ... improvement here "DZmin=min((eta_inlet-pos().z),0.5*thres);" "DZmax=max(DZmin,-0.5*thres);" "aw_inlet=(DZmax+0.5*thres)/thres;" //alpha water value ); } AlphaWater { field alpha.water; expression "aw"; keepPatches true; //keep the boundary conditions that were set before variables ( "a=0.05;" "omega=1.0472;" "k=0.477406;" "tshift=-pi/2;" "eta=a*cos(omega*(time()+tshift)-k*pos().x);" "thres=0.009;" "DZmin=min((eta-pos().z),0.5*thres);" "DZmax=max(DZmin,-0.5*thres);" "aw=(DZmax+0.5*thres)/thres;" //alpha water value ); } VelocityField_Inlet { field U; expression "Uw_inlet"; keepPatches false; //keep the boundary conditions that were set before patchName "inlet"; variables ( "a=0.05;" "h=0.5;" "omega=1.0472;" "k=0.477406;" "tshift=-pi/2;" "gg=vector(0,0,-9.81);" "eta_inlet=a*cos(omega*(time()+tshift));" "thres=0.009;" //threshold value depends on the mesh dimentions "DZmin=min((eta_inlet-pos().z),0.5*thres);" "DZmax=max(DZmin,-0.5*thres);" "aw_inlet=(DZmax+0.5*thres)/thres;" //alpha water value "Uwx_in=aw_inlet*(a*(mag(gg)/omega)*k*(cosh((h+pos().z)*k)/cosh(h*k))*(cos(-(omega*(time()+tshift)))));" "Uwy_in=0;" "Uwz_in=aw_inlet*(a*(mag(gg)/omega)*k*(sinh((h+pos().z)*k)/cosh(h*k))*(sin(-(omega*(time()+tshift)))));" "Uw_inlet=vector(Uwx_in, Uwy_in, Uwz_in);" ); } VelocityField { field U; expression "Uw"; keepPatches true; //keep the boundary conditions that were set before variables ( "a=0.05;" "h=0.5;"//0.5 "omega=1.0472;" "k=0.477406;" "tshift=-pi/2;" "gg=vector(0,0,-9.81);" "eta=a*cos(omega*(time()+tshift)-k*pos().x);" "thres=0.009;" //threshold value depends on the mesh dimentions "DZmin=min((eta-pos().z),0.5*thres);" "DZmax=max(DZmin,-0.5*thres);" "aw=(DZmax+0.5*thres)/thres;" //alpha water value "Uwx=aw*(a*(mag(gg)/omega)*k*(cosh((h+pos().z)*k)/cosh(h*k))*(cos(k*pos().x-(omega*(time()+tshift)))));" "Uwy=0;" "Uwz=aw*(a*(mag(gg)/omega)*k*(sinh((h+pos().z)*k)/cosh(h*k))*(sin(k*pos().x-(omega*(time()+tshift)))));" "Uw=vector(Uwx, Uwy, Uwz);" ); } ); |
|
December 13, 2016, 18:34 |
|
#12 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
This is what source code looks like with the code-environment:
Code:
dict { val 1; sub { a 1; b 2; } } dict { val 1; sub { a 1; b 2; } } The first form makes it easy for me to see what is going on. The second form I have to count brackets to see what the problem might be. It also makes it hard for me to see where the file ends and the text starts. That said: I didn't have a closer look at your post because it is unreadable Quote:
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
February 9, 2017, 12:45 |
funkySetFieldDict and variables call
|
#13 | |
New Member
|
Dear Bernhard,
I am so sorry for the piece of code I sent you ... that was so messed-up! The code is working, but i would like to use a list of variables included in the "initialConditions" instead of repeat the same variables in the fields included inside the expressions brackets. I have attached the code below. Thank you again. Vincenzo Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 4.x | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object funkySetFieldsDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "initialConditions" defaultFieldValues ( volScalarFieldValue alpha.water 0; volVectorFieldValue U (0,0,0); volScalarFieldValue p_rgh 0; ); expressions ( AlphaWater { field alpha.water; expression "aw"; keepPatches true; //keep the boundary conditions that were set before variables ( "a=0.05;" "omega=1.0472;" "k=0.477406;" "eta=a*cos(omega*time()-k*pos().x);" "thres=0.003;" //threshold value depends on the mesh ... improvement here "DZmin=min((eta-pos().z),0.5*thres);" "DZmax=max(DZmin,-0.5*thres);" "aw=(DZmax+0.5*thres)/thres;" //alpha water value ); } VelocityField { field U; expression "Uw"; keepPatches true; //keep the boundary conditions that were set before //patchName "inlet"; variables ( "a=0.05;" "h=0.5;" "omega=1.0472;" "k=0.477406;" "gg=vector(0,0,-9.81);" "eta=a*cos(omega*time()-k*pos().x);" "thres=0.003;" //threshold value depends on the mesh dimentions "DZmin=min((eta-pos().z),0.5*thres);" "DZmax=max(DZmin,-0.5*thres);" "aw=(DZmax+0.5*thres)/thres;" //alpha water value "Uwx=aw*(a*(mag(gg)/omega)*k*(cosh((h+pos().z)*k)/cosh(h*k))*cos(k*pos().x-omega*time()));" "Uwy=0;" "Uwz=aw*(a*(mag(gg)/omega)*k*(sinh((h+pos().z)*k)/cosh(h*k))*sin(k*pos().x-omega*time()));" "Uw=vector(Uwx, Uwy, Uwz);" ); } PressureField { field p_rgh; expression "pw_rgh"; keepPatches true; //keep the boundary conditions that were set before //patchName "inlet"; variables ( "a=0.05;" "h=0.5;" "omega=1.0472;" "k=0.477406;" "gg=vector(0,0,-9.81);" "ro=1000;" "eta=a*cos(omega*time()-k*pos().x);" "thres=0.003;" //threshold value depends on the mesh dimentions "DZmin=min((eta-pos().z),0.5*thres);" "DZmax=max(DZmin,-0.5*thres);" "aw=(DZmax+0.5*thres)/thres;" //alpha water value "pw=ro*mag(gg)*((eta*cosh((h+pos().z)*k)/cosh(h*k))-pos().z);" //pressure "pw_rgh=aw*(pw-ro*mag(gg)*(-h));" //pressure p_rgh = p-ro*g*z ); } ); Quote:
|
||
November 25, 2019, 23:50 |
beware the space
|
#14 | |
New Member
Sam Mallinson
Join Date: Aug 2013
Posts: 6
Rep Power: 13 |
NB: there is a space between defaultVariables and "(" - which I'm told is standard in OpenFOAM. (Thank you darrin)
Quote:
|
||
January 20, 2020, 19:37 |
Approach to #include'ing for OpenFOAM-7
|
#15 |
New Member
Sam Mallinson
Join Date: Aug 2013
Posts: 6
Rep Power: 13 |
I was looking for the answer to the problem posed in the original post, so thought I'd share what I figured out (with the assistance of Dr. D. Stephens of Applied CCM).
This works for OpenFOAM-7. Suppose you want to specify the outflow velocity on a patch called "outflow", for only part of the patch, say Y < some value, and you want to use #include so you don't repeat yourself, then: 1. the file system/funkySetBoundaryDict should look like: Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 7 | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object funkySetBoundaryDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // outflow { #include "./0.org/groovyParameters" field U; expressions ( { target value; patchName outlet; variables $varGBC; expression "pos().y<yout ? vector(0, 0, Uout) : vector(0, 0, 0)"; } ); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 2. the file 0.org/groovyParameters should look like (values below are just dummy values): Code:
varGBC ( "yout=0.5;Uout=-1.0;" ); 3. the file 0.org/U should have as its entry for the patch outlet: Code:
outlet { type fixedValue; value uniform (0 0 0); } Then, the target for the outflow patch BC is "value" which is specified in the funkySetBoundaryDict. |
|
Tags |
funkysetfields, groovybc |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] groovyBC for defining heat influx at the boundary | pradeepramesh | OpenFOAM Community Contributions | 12 | January 15, 2019 22:55 |
[swak4Foam] Change in alpha and U with groovyBC in twoPhaseEulerFoam | dani2702 | OpenFOAM Community Contributions | 0 | November 17, 2016 04:30 |
[swak4Foam] GroovyBC problem in the defining inlet velocity | iampolaris | OpenFOAM Community Contributions | 7 | October 18, 2014 10:25 |
[swak4Foam] Defining two different variables at two patch in groovyBC with the same name | immortality | OpenFOAM Community Contributions | 2 | January 9, 2013 19:03 |
[swak4Foam] Problem: Defining a linear scalar BC with groovyBC | holp | OpenFOAM Community Contributions | 3 | July 19, 2012 21:19 |