|
[Sponsors] |
[swak4Foam] a script for changing variables in groovyBC in 0 folder |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 24, 2013, 18:36 |
a script for changing variables in groovyBC in 0 folder
|
#1 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
Hi I have some variables(theta0,theta1,...,theta8)in various variable files(p,T,U,k,omega) in 0 folder.I'm wondering if its possible to write a script to change each of these variables I want before a run starts without a need to look into each files separately.
thanks for helps. Code:
right { type groovyBC; variables ( "r=0.02325;" "rpm=32151;" "omega=rpm*pi/30;" "v_r=r*omega;" "w_cell=.004;" "n=1;" "theta0=0;" "theta4=180;" "theta5=23.72685186;" "theta6=57.87037038;" "theta7=104;" "theta8=139;" "p0_2=1023382.5;" "T0_2=907;" "p0_4=374902.5;" "T0_4=973;" "gamma=1.4;" "R=287.14;" "w_w0=n*w_cell;" "w_w3=(theta5-theta0)*r*pi/180;" "w_p2=(theta6-theta5)*r*pi/180;" "w_w4=(theta7-theta6)*r*pi/180;" "w_p4=(theta8-theta7)*r*pi/180;" "w_w5=(theta4-theta8)*r*pi/180;" "c1=(w_w3)/v_r;" "c2=(w_w3+w_p2)/v_r;" "c3=(w_w3+w_p2+w_w4)/v_r;" "c4=(w_w3+w_p2+w_w4+w_p4)/v_r;" "c5=(w_w3+w_p2+w_w4+w_p4+w_w5)/v_r;" "t1=(w_w0-pos().y)/v_r;" "t_mapped=(time()>t1) ? ((time()-t1)%(c5)+t1) : time();" );
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. |
|
May 24, 2013, 19:31 |
|
#2 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
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 |
||
May 25, 2013, 06:37 |
|
#3 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
Hi Bernhard
which examples do you talking about?
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. |
|
May 25, 2013, 06:48 |
|
#4 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37 |
Hi Ehsan,
If you go to the location of your swak4Foam installation and type the following in the command line: Code:
find ./Examples | xargs grep globalScope Good luck, Niels |
|
May 25, 2013, 06:51 |
|
#5 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
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 |
||
May 25, 2013, 06:53 |
|
#6 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37 |
You are welcome, Bernhard. Have a nice weekend.
/ Niels |
|
May 25, 2013, 07:00 |
|
#7 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
@Niels:thanks Niels,I thought Bernhard is poiting to OF examples in tutorial!
@Bernhard: wow! really?! Bernhard you should be more patient. I can't imagine what did you do if you were in place and position of me.
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. |
|
May 25, 2013, 07:37 |
|
#8 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
thanks Both Niels and Bernhard
in an example I found this in controlDict: Code:
defineState { type addGlobalVariable; outputControl timeStep; outputInterval 1; globalScope outletState; globalVariables { closed { valueType scalar; value 0; } airReachedOutletTime { valueType scalar; value -1; } shutdownTime { valueType scalar; value 1; } } } Code:
globalScopes ( outletState );
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. Last edited by immortality; May 25, 2013 at 08:43. |
|
May 25, 2013, 07:48 |
separate header of variables
|
#9 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
I also found a brilliant idea for storing many variables I have in a separate file,
then I should delete theta variables in variable file and only bring them in global variable function,true? but could anyone say what does this part of variables do?I think maybe i will need it in next time. Code:
delayedVariables ( { name outflow; delay 15; // delay 1; storeInterval 0.1; startupValue "0"; } );
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. |
|
May 25, 2013, 08:55 |
|
#10 | |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Greetings to all!
@Ehsan: Quote:
Code:
**** delayed-t-junction - Solver :: pimpleFoam - Demonstrates :: Delayed variables to simulate an inflow that depends on the value of the outflow Code:
inlet1 { type groovyBC; valueExpression "-inVel*normal()" value uniform (0 0 0); variables ( "A=sum(area());" "outFlow{outlet}=sum((U&normal())*area());" "myFlow=0.5*outFlow;" "inVel=myFlow/sum(area());" ); delayedVariables ( { name outFlow; startupValue "0"; storeInterval 0.001; delay 0.1; } ); } Best regards, Bruno
__________________
|
||
May 25, 2013, 09:09 |
|
#11 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
don't you know such a simple thing Bruno?
I knew that I should explain you that! It takes some the value in outlet and put it in inlet after a while each .001s ! after joking! but whats the role of delay there?
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. |
|
May 25, 2013, 09:35 |
|
#12 | |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Quote:
This is a simple case, where the delay can help in reach a better convergence (I think, I'm not sure here), since it's giving a time offset to a boundary condition. This BC acts similarly to OpenFOAM's "directMapped" (or something "mapped" something). The difference is that the original "mapped" will teleport the patch fields in the same time iteration or between consecutive iterations (I'm not sure on this one). The "delay" can give you more control on when the transfer is made. Another possibility - which doesn't have much to do with convergence - is the ability to emulate a longer pipe, without the need to simulate it. For example, if you're simulating a 12 meter pipe that repeats itself with a protuberance of some kind (e.g. convergent or divergence nozzle or a simple obstacle), you can simulate only 2 meters that have the protuberance and calculate the delay it takes to go through the remaining 10 meters, before repeating the flow on the other side!
__________________
|
||
May 25, 2013, 12:49 |
|
#13 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
so it takes and saves the data in output each .001s but waits and after .1s starts exerting them on inlet.right?
I didn't grasp your example exactly.could you clarify how this feature can be applicable in such situation you mentioned? thanks.
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. |
|
May 25, 2013, 13:38 |
|
#14 | ||
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Quote:
Quote:
Now, for example, we can either have a mesh with around 12 million cells, or trim it down to just 2-3 million cells and simulate only 2m worth of pipe. To fill in the gap of the missing 10m, we need to delay the outlet back into the inlet for about: 10 (m) / 1 (m/s) = 10s. With the "mapped" feature that OpenFOAM has got, you could only map after the full 12m pipe... or you could create a variant of OpenFOAM's "mapped" BC and implement the options and equations directly. But with this groovyBC's feature, there is no need for coding!
__________________
|
|||
May 25, 2013, 14:15 |
|
#15 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
Thank you so much.I figured out what you mean!
what a brilliant idea of using this feature in the example! maybe i need to use it in future.
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. |
|
May 25, 2013, 17:07 |
|
#16 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
I moved all variables to a file named variables(does it have any problem?)
and this error on wall_right occurred: Code:
Selecting turbulence model type RASModel Selecting RAS turbulence model kOmegaSST kOmegaSSTCoeffs { alphaK1 0.85034; alphaK2 1; alphaOmega1 0.5; alphaOmega2 0.85616; Prt 1; gamma1 0.5532; gamma2 0.4403; beta1 0.075; beta2 0.0828; betaStar 0.09; a1 0.31; b1 1; c1 10; F3 false; } fluxScheme: Kurganov Starting time loop swak4Foam: Setting default mesh faceSource Average_left: total faces = 20 total area = 4e-06 Mean and max Courant Numbers = 0.9922503451 4.611736676 deltaT = 2.127659574e-08 Time = 2.12766e-08 diagonal: Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0 diagonal: Solving for rhoUx, Initial residual = 0, Final residual = 0, No Iterations 0 diagonal: Solving for rhoUy, Initial residual = 0, Final residual = 0, No Iterations 0 --> FOAM Warning : From function CommonValueExpressionDriver::evaluateVariable in file CommonValueExpressionDriver.C at line 924 There is a field named omega of type IOobject found which may be shadowed by the variable of the same name. This may lead to trouble If this is OK set 'variableNameIdenticalToField' in the relevant parser [0] swak4Foam: Allocating new repository for sampledGlobalVariables [1] swak4Foam: Allocating new repository for sampledGlobalVariables [3] swak4Foam: Allocating new repository for sampledGlobalVariables [2] swak4Foam: Allocating new repository for sampledGlobalVariables --> FOAM Warning : From function ConcretePluginFunction<DriverType>::exists in file lnInclude/ConcretePluginFunction.C at line 111 Constructor table of plugin functions for PatchValueExpressionDriver is not initialized [1] [3] [0] [0] [0] --> FOAM FATAL ERROR: [0] Parser Error for driver PatchValueExpressionDriver at "1.1-10" :"field wall_right not existing or of wrong type" "wall_right ? vector(0,-v_r,0) : vector(300,0,0)" ^^^^^^^^^^ --| Context of the error: - From dictionary: /home/ehsan/Desktop/Central/nonUniformMesh/WR_Main_Central_100*10_nonMesh/processor0/0/U.boundaryField.right Evaluating expression "wall_right ? vector(0,-v_r,0) : vector(300,0,0)" [0] [0] [0] From function parsingValue [0] in file lnInclude/CommonValueExpressionDriverI.H at line 1039. [0] FOAM parallel run exiting [1] [1] --> FOAM FATAL ERROR: [1] Parser Error for driver PatchValueExpressionDriver at "1.1-10" :"field wall_right not existing or of wrong type" "wall_right ? vector(0,-v_r,0) : vector(300,0,0)" ^^^^^^^^^^ --| Context of the error: - From dictionary: /home/ehsan/Desktop/Central/nonUniformMesh/WR_Main_Central_100*10_nonMesh/processor1/0/U.boundaryField.right Evaluating expression "wall_right ? vector(0,-v_r,0) : vector(300,0,0)" [0] [1] [1] [1] From function parsingValue [1] in file lnInclude/CommonValueExpressionDriverI.H at line 1039. [1] FOAM parallel run exiting [1] [3] -------------------------------------------------------------------------- MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD with errorcode 1. NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes. You may or may not see output from other processes, depending on exactly when Open MPI kills them. -------------------------------------------------------------------------- [3] --> FOAM FATAL ERROR: [3] Parser Error for driver PatchValueExpressionDriver at "1.1-10" :"field wall_right not existing or of wrong type" "wall_right ? vector(0,-v_r,0) : vector(300,0,0)" ^^^^^^^^^^ --| Context of the error: - From dictionary: /home/ehsan/Desktop/Central/nonUniformMesh/WR_Main_Central_100*10_nonMesh/processor3/0/U.boundaryField.right Evaluating expression "wall_right ? vector(0,-v_r,0) : vector(300,0,0)" [3] [3] [3] From function parsingValue [3] in file lnInclude/CommonValueExpressionDriverI.H at line 1039. [3] FOAM parallel run exiting [3] [2] [2] [2] --> FOAM FATAL ERROR: [2] Parser Error for driver PatchValueExpressionDriver at "1.1-10" :"field wall_right not existing or of wrong type" "wall_right ? vector(0,-v_r,0) : vector(300,0,0)" ^^^^^^^^^^ --| Context of the error: - From dictionary: /home/ehsan/Desktop/Central/nonUniformMesh/WR_Main_Central_100*10_nonMesh/processor2/0/U.boundaryField.right Evaluating expression "wall_right ? vector(0,-v_r,0) : vector(300,0,0)" [2] [2] [2] From function parsingValue [2] in file lnInclude/CommonValueExpressionDriverI.H at line 1039. [2] FOAM parallel run exiting [2] -------------------------------------------------------------------------- mpirun has exited due to process rank 0 with PID 19407 on node Ehsan-com exiting without calling "finalize". This may have caused other processes in the application to be terminated by signals sent by mpirun (as reported here). -------------------------------------------------------------------------- [Ehsan-com:19403] 3 more processes have sent help message help-mpi-api.txt / mpi-abort [Ehsan-com:19403] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages Killing PID 19401 PyFoam WARNING on line 232 of file /usr/local/lib/python2.7/dist-packages/PyFoam/Execution/FoamThread.py : Process 19401 was already dead Getting LinuxMem: [Errno 2] No such file or directory: '/proc/19401/status' ---------------------------------------------------------------- I have defined the variable wall_right to be a Boolean variable according to values of time,maybe this is the source of the error?
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. |
|
May 25, 2013, 17:22 |
|
#17 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
(edit: CAUTION - this post was guessing something that apparently isn't true. The problem seems to be something else.)
I haven't tested this yet, but my guess is this: the OpenFOAM feature "#include" does not work in the same way as in C++. It (probably) does not copy-paste the contents of the mentioned file into where we tell it to place. What it (probably) does is load it into memory and process the defined variables within the file. So, I think the correct way to use this would be:
__________________
Last edited by wyldckat; May 25, 2013 at 18:28. Reason: see "edit:" |
|
May 25, 2013, 17:33 |
|
#18 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
I saw it this morning in this example of swak4Foam:Examples/other/OSCFD_cleaningtank2D/0.orig
in its U file it has come these functions: Code:
wall { type fixedValue; value uniform (0 0 0); } inlet { // type fixedValue; type groovyBC; // value uniform (0.1 0 0); value uniform (1 0 0); valueExpression "-velIn*normal()"; // valueExpression "-0.1*normal()"; #include "commonVariables" } Code:
// -*- C++ -*- variables ( "outflow{outlet}=sum(normal()&U*alpha1*area());" "targetVelIn=0.2;" "minFrac=outflow>1e-15 ? 0.25 : 0;" "minHeight=min(pts().y);" "maxHeight=max(pts().y);" "volFlow=sum(targetVelIn*area());" "volFlow=mag(volFlow)<1e-15 ? 1e-15 : volFlow;" "flowFraction=outflow>1e-15 ? outflow/volFlow : 0;" "fraction=max(minFrac,flowFraction);" "fillHeight=minHeight+fraction*(maxHeight-minHeight);" "filled=pos().y<=fillHeight ? 1 : 0;" "filledArea=sum(filled*area());" "velIn=filled>0.5 ? outflow/max(filledArea,1e-15) : 0;" ); delayedVariables ( { name outflow; delay 15; // delay 1; storeInterval 0.1; startupValue "0"; } );
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. |
|
May 25, 2013, 18:30 |
|
#19 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Hi Ehsan,
As I said, I was only guessing. Without a test case, that's all I can do Right before copying the variables list into the "variables" file, did you confirm if everything was working as intended? Best regards, Bruno
__________________
|
|
May 25, 2013, 18:53 |
|
#20 |
Senior Member
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27 |
I emailed you the case.one time before Bernhard told me something related to Boolean I don't remember,mabe its due to that.
__________________
Injustice Anywhere is a Threat for Justice Everywhere.Martin Luther King. To Be or Not To Be,Thats the Question! The Only Stupid Question Is the One that Goes Unasked. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] no change in solution by change in groovyBC variables | immortality | OpenFOAM Community Contributions | 2 | January 28, 2013 08:34 |
[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] Air Conditioned room groovyBC | Sebaj | OpenFOAM Community Contributions | 7 | October 31, 2012 15:16 |
[swak4Foam] Wall heat transfer using groovyBC (XiFoam solver) | usergk | OpenFOAM Community Contributions | 7 | February 4, 2011 14:36 |
PHI file structure | Eugene | Phoenics | 9 | November 2, 2001 23:00 |