CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

if statement in g-file

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 4 Post By Bloerb

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 29, 2018, 04:54
Default if statement in g-file
  #1
New Member
 
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 8
hebe03364 is on a distinguished road
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);
}
but it doesn't work. Can anybody help me with this issue? Thanks in advance!
hebe03364 is offline   Reply With Quote

Old   June 29, 2018, 06:18
Default
  #2
Senior Member
 
Robert
Join Date: May 2015
Location: Bremen, GER
Posts: 292
Rep Power: 12
RobertHB is on a distinguished road
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.
RobertHB is offline   Reply With Quote

Old   June 29, 2018, 07:42
Default
  #3
New Member
 
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 8
hebe03364 is on a distinguished road
Thank you very much for your helo and the quick answer! I will try to apply your proposed solution!
hebe03364 is offline   Reply With Quote

Old   June 29, 2018, 09:24
Default
  #4
Senior Member
 
Join Date: Sep 2013
Posts: 353
Rep Power: 21
Bloerb will become famous soon enough
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")
        );
    }
}
Bloerb is offline   Reply With Quote

Old   June 29, 2018, 09:31
Default
  #5
New Member
 
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 8
hebe03364 is on a distinguished road
Thank you very much Bloerb!
hebe03364 is offline   Reply With Quote

Old   July 2, 2018, 09:55
Default
  #6
New Member
 
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 8
hebe03364 is on a distinguished road
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")
        );
mean?
And what does 1 in
Code:
        writeInterval    1;
actually mean?

Thanks in advance!
hebe03364 is offline   Reply With Quote

Old   July 2, 2018, 12:58
Default
  #7
Senior Member
 
Join Date: Sep 2013
Posts: 353
Rep Power: 21
Bloerb will become famous soon enough
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;
Bloerb is offline   Reply With Quote

Old   July 2, 2018, 13:08
Default
  #8
New Member
 
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 8
hebe03364 is on a distinguished road
Thank you very much for the answer!
hebe03364 is offline   Reply With Quote

Reply


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
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


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