CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   if statement in g-file (https://www.cfd-online.com/Forums/openfoam-solving/203492-if-statement-g-file.html)

hebe03364 June 29, 2018 03:54

if statement in g-file
 
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!

RobertHB June 29, 2018 05:18

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.

hebe03364 June 29, 2018 06:42

Thank you very much for your helo and the quick answer! I will try to apply your proposed solution!

Bloerb June 29, 2018 08:24

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")
        );
    }
}


hebe03364 June 29, 2018 08:31

Thank you very much Bloerb!

hebe03364 July 2, 2018 08:55

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!

Bloerb July 2, 2018 11:58

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;


hebe03364 July 2, 2018 12:08

Thank you very much for the answer!


All times are GMT -4. The time now is 00:42.