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

time varying gravity for interFoam in OpenFOAM 6

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By clapointe
  • 1 Post By clapointe

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 19, 2020, 15:52
Default time varying gravity for interFoam in OpenFOAM 6
  #1
Senior Member
 
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 9
joshmccraney is on a distinguished road
Hi FOAMers!

Do you know how to change gravity to a function of time? I read a thread here but this is very dated. If anyone knows how to change this I'd be very grateful!
joshmccraney is offline   Reply With Quote

Old   May 19, 2020, 18:17
Default
  #2
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
I've done something similar a long time ago, but I think the following should point you in the right direction. If you look at solvers with buoyancy you'll see

Code:
#include "readGravitationalAcceleration.H"
#include "gh.H"
in createFields. As gravity is usually constant, these lines are clearly only read once -- during simulation initialization. For gravity to very with time, though, code similar to that in the includes will need to be used every iteration.

So something like :

Create the field g and (initial) gh in create fields. Then inside the solver (probably after updating time with runTime++) something like

Code:
g = cos(t)*dimensionedScalar(gmag,dimVelocity*dimVelocity,9.81) *vector(1,0,0) + sin(t)*dimensionedScalar(gmag,dimVelocity*dimVelocity,9.81) *vector(0,1,0) //update g
//update gh, ghf
gh = g & mesh.C();
ghf = g & mesh.Cf();
Note I've not tested this, but a scan of the old thread suggests this could work. Also make sure the trig is correct!

Caelan

Last edited by clapointe; May 19, 2020 at 20:48.
clapointe is offline   Reply With Quote

Old   May 20, 2020, 02:12
Default
  #3
Senior Member
 
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 9
joshmccraney is on a distinguished road
Quote:
Originally Posted by clapointe View Post
I've done something similar a long time ago, but I think the following should point you in the right direction. If you look at solvers with buoyancy you'll see

Code:
#include "readGravitationalAcceleration.H"
#include "gh.H"
in createFields. As gravity is usually constant, these lines are clearly only read once -- during simulation initialization. For gravity to very with time, though, code similar to that in the includes will need to be used every iteration.

So something like :

Create the field g and (initial) gh in create fields. Then inside the solver (probably after updating time with runTime++) something like

Code:
g = cos(t)*dimensionedScalar(gmag,dimVelocity*dimVelocity,9.81) *vector(1,0,0) + sin(t)*dimensionedScalar(gmag,dimVelocity*dimVelocity,9.81) *vector(0,1,0) //update g
//update gh, ghf
gh = g & mesh.C();
ghf = g & mesh.Cf();
Note I've not tested this, but a scan of the old thread suggests this could work. Also make sure the trig is correct!

Caelan
Thanks for the response. After discussing with peers, it seems perhaps an easier approach than altering gravity is to include a body force source term. To do this, I created a new solver (copied interFoam folder and made my own titled bfInterFoam).

The UEqn.H looks like this

Code:
    MRF.correctBoundaryVelocity(U);
    
    # define omega 0.05

    const dimensionedVector mySource("mySource", dimensionSet(0,1,-2,0,0,0,0), 10*Foam::sin(runTime.value()*omega)*vector(0,1,0));

    fvVectorMatrix UEqn
    (
        fvm::ddt(rho, U) + fvm::div(rhoPhi, U)
      + MRF.DDt(rho, U)
      + turbulence->divDevRhoReff(rho, U)
     ==
        fvOptions(rho, U)
      + mysource
    );

    UEqn.relax();
.
.
.
(green is what I added). When running wmake I get the error
Code:
In file included from bfInterFoam.C:142:0:
UEqn.H: In function ‘int main(int, char**)’:
UEqn.H:14:9: error: ‘mysource’ was not declared in this scope
       + mysource
         ^~~~~~~~
UEqn.H:14:9: note: suggested alternative: ‘mySource’
       + mysource
         ^~~~~~~~
         mySource
/opt/openfoam6/wmake/rules/General/transform:25: recipe for target '/opt/openfoam6/platforms/linux64GccDPInt32Opt/applications/solvers/multiphase/bfInterFoam/bfInterFoam.o' failed
make: *** [/opt/openfoam6/platforms/linux64GccDPInt32Opt/applications/solvers/multiphase/bfInterFoam/bfInterFoam.o] Error 1
Any idea how to declare 'mysource'?
joshmccraney is offline   Reply With Quote

Old   May 20, 2020, 11:40
Default
  #4
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
There's a typo -- as the error message says try replacing "mysource" with "mySource".

Caelan
joshmccraney likes this.
clapointe is offline   Reply With Quote

Old   May 20, 2020, 12:23
Default
  #5
Senior Member
 
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 9
joshmccraney is on a distinguished road
Quote:
Originally Posted by clapointe View Post
There's a typo -- as the error message says try replacing "mysource" with "mySource".

Caelan
I feel so stupid missing mistakes like these. How did you know, so that in the future I can diagnose the issue?
joshmccraney is offline   Reply With Quote

Old   May 20, 2020, 12:37
Default
  #6
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
The error messages are always a good place to start -- and are usually pretty helpful. Using your case as an example, the relevant bit of the message read "note: suggested alternative: ‘mySource’". Otherwise carefully looking at the new code is good practice.. there's probably a post or guide floating around with more comprehensive debugging information.

Caelan
joshmccraney likes this.
clapointe is offline   Reply With Quote

Old   May 20, 2020, 13:06
Default
  #7
Senior Member
 
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 9
joshmccraney is on a distinguished road
Quote:
Originally Posted by clapointe View Post
The error messages are always a good place to start -- and are usually pretty helpful. Using your case as an example, the relevant bit of the message read "note: suggested alternative: ‘mySource’". Otherwise carefully looking at the new code is good practice.. there's probably a post or guide floating around with more comprehensive debugging information.

Caelan
Got it! Thanks for your help!
joshmccraney 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
pressure in incompressible solvers e.g. simpleFoam chrizzl OpenFOAM Running, Solving & CFD 13 March 28, 2017 06:49
High Courant Number @ icoFoam Artex85 OpenFOAM Running, Solving & CFD 11 February 16, 2017 14:40
Micro Scale Pore, icoFoam gooya_kabir OpenFOAM Running, Solving & CFD 2 November 2, 2013 14:58
mixerVesselAMI2D's mass is not balancing sharonyue OpenFOAM Running, Solving & CFD 6 June 10, 2013 10:34
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 19:07


All times are GMT -4. The time now is 21:27.