|
[Sponsors] |
June 29, 2018, 04:54 |
if statement in g-file
|
#1 |
New Member
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 8 |
Hello!
I would like to set the gravitation g in my simulation in the first 0.5 seconds to (0,0,0). Aftwerwards it should switch to (0,0,9.81). I tried it by the us of an if-statement in my g-file with Code:
if(runTime<0.5) { value (0 0 0); } else { value (0 0 9.81); } |
|
June 29, 2018, 06:18 |
|
#2 |
Senior Member
Robert
Join Date: May 2015
Location: Bremen, GER
Posts: 292
Rep Power: 12 |
I'm afraid you can't use code in OpenFOAM dictionaries, at least in most of them. What you could do instead is run your simulation with value (0 0 0); for 0.5 sec., then change your gravitiy to value (0 0 -9.81); and resume your simulation.
Disclaimer: I'm not sure if the following idea works, it's really just a quick idea: If you dont want to stop/resume your simulation you could try setting g in its dictionary to value (0 0 0);. Then use a vectorSource in fvOptions,choose selectionMode all; and add a startTime and duration to the source. |
|
June 29, 2018, 07:42 |
|
#3 |
New Member
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 8 |
Thank you very much for your helo and the quick answer! I will try to apply your proposed solution!
|
|
June 29, 2018, 09:24 |
|
#4 |
Senior Member
Join Date: Sep 2013
Posts: 353
Rep Power: 21 |
simply use the timeactivatedfileupdate functionObject. Add this to your controlDict (requires a recent version of OF) and create two files g.A and g.B with the desired values.
Code:
functions { fileUpdate1 { type timeActivatedFileUpdate; libs ("libutilityFunctionObjects.so"); writeControl timeStep; writeInterval 1; fileToUpdate "$FOAM_CASE/constant/g"; timeVsFile ( (-1 "$FOAM_CASE/constant/g.A") (0.5 "$FOAM_CASE/constant/g.B") ); } } |
|
June 29, 2018, 09:31 |
|
#5 |
New Member
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 8 |
Thank you very much Bloerb!
|
|
July 2, 2018, 09:55 |
|
#6 |
New Member
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 8 |
Hello,
i have just one question concerning the code above. What does -1 in Code:
timeVsFile ( (-1 "$FOAM_CASE/constant/g.A") (0.5 "$FOAM_CASE/constant/g.B") ); And what does 1 in Code:
writeInterval 1; Thanks in advance! |
|
July 2, 2018, 12:58 |
|
#7 |
Senior Member
Join Date: Sep 2013
Posts: 353
Rep Power: 21 |
instead of -1 you could use 0. The update function object reads in the current time. And once your time is bigger than the listed value it replaces the file. At the start of your simulation (t=0) you are already above (t=-1) hence your g file is replaced with g.A.
These two lines are probably not needed. They state though, that this function object should execute its write function every time step. The write function here is the one replacing the file. Code:
writeControl timeStep; writeInterval 1; |
|
July 2, 2018, 13:08 |
|
#8 |
New Member
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 8 |
Thank you very much for the answer!
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to calculate mass flow rate on patches and summation of that during the run? | immortality | OpenFOAM Post-Processing | 104 | February 16, 2021 09:46 |
[swak4Foam] funkyDoCalc with OF2.3 massflow | NiFl | OpenFOAM Community Contributions | 14 | November 25, 2020 04:30 |
[foam-extend.org] problem when installing foam-extend-1.6 | Thomas pan | OpenFOAM Installation | 7 | September 9, 2015 22:53 |
"parabolicVelocity" in OpenFoam 2.1.0 ? | sawyer86 | OpenFOAM Running, Solving & CFD | 21 | February 7, 2012 12:44 |
ParaView Compilation | jakaranda | OpenFOAM Installation | 3 | October 27, 2008 12:46 |