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

Variation of gravity with time

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 24, 2011, 09:31
Default OpenFoam 1.7.x, Gravity rotation for interFoam
  #21
Senior Member
 
Jon Elvar Wallevik
Join Date: Nov 2010
Location: Reykjavik, ICELAND
Posts: 103
Rep Power: 20
JonW will become famous soon enough
Dear all
For OF 1.7.x, my "interFoam.C" looks like this with comments for my self (had to change it sligtly relative to the above discussion) Hope this is of help to someone!
NOTE: // a: //b: etc. marks the changes.

---------------------------------------------------------
#include "fvCFD.H"
#include "MULES.H"
#include "subCycle.H"
#include "interfaceProperties.H"
#include "twoPhaseMixture.H"
#include "turbulenceModel.H"
#include "interpolationTable.H"

// a:
#define pi 3.141592653589793238

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{

// b:
const dimensionedScalar gunits("gunits", dimensionSet(0,1,-2,0,0,0,0), 9.81);

#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"
#include "readPISOControls.H"
#include "initContinuityErrs.H"
#include "createFields.H"


#include "readTimeControls.H"
#include "correctPhi.H"
#include "CourantNo.H"
#include "setInitialDeltaT.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Info<< "\nStarting time loop\n" << endl;

while (runTime.run())
{
#include "readPISOControls.H"
#include "readTimeControls.H"
#include "CourantNo.H"
#include "alphaCourantNo.H"
#include "setDeltaT.H"

runTime++;

Info<< "Time = " << runTime.timeName() << nl << endl;

// ------------------
// kemur fra creatFields.H, virdist breyta litlu ad hafa thetta a:
// dimensionedVector g0(g);
// ------------------

// c:
// the file ./constants/g seems to be overwritten or ignored.
// Have tested by setting gravity to -0.05 m/s2 as well as -99.8 m/s2 in
// ./constants/g => same result is produced regardless! I.e. the line
// below seems to dominate over anything that is written in ./constants/g.
g=gunits*Foam::sin(runTime.value()*pi/2.0)*vector(1,0,0)-gunits*Foam::cos(runTime.value()*pi/2.0)*vector(0,0,1);

// ------------------
// Comes from creatFields.H, virdist breyta litlu ad hafa thetta a:
// dimensionedVector g0(g);
// ------------------

// --------- from createFields.H
// d:
// Comes from the file createFields.H. You dont have to delete the lines
// in createFields.H. The field gh is just initilaized there.
Info<< "Calculating field g.h\n" << endl;
volScalarField gh("gh", g & mesh.C());
surfaceScalarField ghf("ghf", g & mesh.Cf());
// -------------------------------------


twoPhaseProperties.correct();

#include "alphaEqnSubCycle.H"

#include "UEqn.H"

// --- PISO loop
for (int corr=0; corr<nCorr; corr++)
{
#include "pEqn.H"
}

turbulence->correct();

runTime.write();

Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;
}

Info<< "End\n" << endl;

return 0;
}
JonW is offline   Reply With Quote

Old   May 14, 2012, 10:06
Default
  #22
Member
 
Join Date: Mar 2012
Posts: 51
Rep Power: 14
callahance is on a distinguished road
This thread is a bit old but hopefully someone could help....

i have the same problem, wanna change g and make it as a function of time. I have OF 2.1 and in interFoam solver file i cant find the file : readGravitationalAcceleration.C ... I tried to change the interFoam.C file like diescribed above but it didnt work (i ran interfoam as normal on a test case and it just takes the constant value of g in "constant" file)... i tried to write the codes in creatFields.H but it didnt work either (again interFoam runs normal with no changes as if i didnt change anything in the code).

I would really appreciate some help or advice

Thanks
callahance is offline   Reply With Quote

Old   May 14, 2012, 10:40
Default interFoam 2.1.x Rotation
  #23
Senior Member
 
Jon Elvar Wallevik
Join Date: Nov 2010
Location: Reykjavik, ICELAND
Posts: 103
Rep Power: 20
JonW will become famous soon enough
Hi Callahance

I just compiled gravity rotation into interFoam 2.1.x. The files needed to be changed/modified are the interFoam.C and the UEqn.H

here are my modifications (search for VVPF in interFoam.C and UEqn.H) to see the changes.

Note that this compile without any problems, but I haven't had time to test the binaries. Hope this is enough to get you started

cheers
JonW
Attached Files
File Type: c interFoam.C (4.4 KB, 168 views)
File Type: h UEqn.H (1.7 KB, 143 views)
JonW is offline   Reply With Quote

Old   May 14, 2012, 15:24
Default
  #24
Member
 
Join Date: Mar 2012
Posts: 51
Rep Power: 14
callahance is on a distinguished road
JonW... all what i could say is : THANKS... ill try it out and give a feedback... thanks very much again
callahance is offline   Reply With Quote

Old   February 24, 2015, 20:50
Default
  #25
Member
 
Pruthvi
Join Date: Feb 2014
Posts: 41
Rep Power: 12
pruthvi1991 is on a distinguished road
Hey Claus,

Hello. This is a very old post. Its feels quite strange to ask a question now. Please bear with me. I want to know how the code worked since you never defined the variable 'g'. I'm trying to do something similar for a plunging airfoil. I get an error " In function ‘int main(int, char**)’: , ‘g’ was not declared in this scope "

If you no longer remember thats OK.

Thanks,
Pru.
pruthvi1991 is offline   Reply With Quote

Old   February 25, 2015, 15:54
Default
  #26
Senior Member
 
Jon Elvar Wallevik
Join Date: Nov 2010
Location: Reykjavik, ICELAND
Posts: 103
Rep Power: 20
JonW will become famous soon enough
you have to define g in createFields.H with the #include "readGravitationalAccelation.H" - thingi (see the createFields.H in the interFoam solver).

If you are going to use gravity in a single phase fluid, check out
http://www.cfd-online.com/Forums/ope...interfoam.html

J.
JonW is offline   Reply With Quote

Old   February 25, 2015, 17:26
Default Heaving reference frame
  #27
Member
 
Pruthvi
Join Date: Feb 2014
Posts: 41
Rep Power: 12
pruthvi1991 is on a distinguished road
Hey john thanks for the reply!

I'm simulating a flapping airfoil and I want to use a heaving reference frame instead of using a deforming mesh. This means that the fluid should accelerate up and down in a sinusoidal motion. So I changed the Ueqn as follows

Code:
solve(UEqn() == g -fvc::grad(p));

g = max_acceleration*Foam::sin(runTime.value()*2*pi*frequency)*vector(0,1,0);
I defined max_ acceleration and frequency in createFields.H as follows

Code:
Info<< "\nReading reference frame parameters" << endl;

IOdictionary heavingReferenceFrame
(
    IOobject
    (
        "heavingReferenceFrame",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ_IF_MODIFIED,
        IOobject::NO_WRITE
    )
);

const dimensionedScalar max_acceleration(heavingReferenceFrame.lookup("max_acceleration"));
const dimensionedScalar frequency(heavingReferenceFrame.lookup("frequency"));
When I do wmake I get the following error.
Code:
In function ‘int main(int, char**)’:
inertial_pimpleFoam.C:79:2: error: ‘g’ was not declared in this scope
However Claus managed to run his code.

Code:
Thanks All!

PROBLEM SOLVED, MISSION ACCOMPLISHED:

#include "fvCFD.H"
#include "MULES.H"
#include "subCycle.H"
#include "interfaceProperties.H"
#include "twoPhaseMixture.H"
#include "turbulenceModel.H"

#define pi 3.141592653589793238


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{

const dimensionedScalar gunits("gunits", dimensionSet(0,1,-2,0,0,0,0), 9.81);


#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"
#include "readGravitationalAcceleration.H"
#include "readPISOControls.H"
#include "initContinuityErrs.H"
#include "createFields.H"
#include "readTimeControls.H"
#include "correctPhi.H"
#include "CourantNo.H"
#include "setInitialDeltaT.H"


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Info<< "\nStarting time loop\n" << endl;

while (runTime.run())
{
#include "readPISOControls.H"
#include "readTimeControls.H"
#include "CourantNo.H"
#include "setDeltaT.H"

runTime++;

g=gunits*Foam::sin(runTime.value()*pi/4.0)*vector(1,0,0)-gunits*Foam::cos(runTime.value()*pi/4.0)*vector(0,0,1);


Info<< "Time = " << runTime.timeName() << nl << endl;

Kinda regards!

Claus
I want to know where I went wrong in the process. I will check out the link you mentioned.
pruthvi1991 is offline   Reply With Quote

Old   March 29, 2015, 10:28
Post
  #28
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
i made it whyman........ simply enter following code in your creatFields.H


// Read the data file and initialise the interpolation table
interpolationTable<vector> timeSeriesAcceleration
(
runTime.path()/runTime.caseConstant()/"acceleration.dat"
);
g.value() = timeSeriesAcceleration(runTime.value());

compile it

and then make an acceleration.dat file in your constants case directory in following format

4
(
(0 (1000 0 0))
(3 (1000 0 0))
(4 (1000 0 0))
(5 (12000 0 0))
)

run the case and enjoy
Quote:
Originally Posted by Whyman View Post
My only problem is that i'm not so expert yet to change the code. I'm still studying it, but it's still quite complicate for me.

Moreover the interpolation file is used (i think) only to interpolate between two values: but how does the code read the file, select the right value for each flowtime and change the value in its calculation?



Regards

Stefano
13msmemusman is offline   Reply With Quote

Old   March 29, 2015, 14:31
Post
  #29
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
I tried to specify acceleration from file acceleration.dat file. but there is a problem. solver gets only first value of acceleration and after that it dont read acceleration.dat file. i added following code in interfoam creatFields.h

// Read the data file and initialise the interpolation table
interpolationTable<vector> timeSeriesAcceleration
(
runTime.path()/runTime.caseSystem()/"acceleration.dat"
);
g.value() = timeSeriesAcceleration(runTime.value());

please try and help me too......
Quote:
Originally Posted by Whyman View Post
My only problem is that i'm not so expert yet to change the code. I'm still studying it, but it's still quite complicate for me.

Moreover the interpolation file is used (i think) only to interpolate between two values: but how does the code read the file, select the right value for each flowtime and change the value in its calculation?



Regards

Stefano
13msmemusman is offline   Reply With Quote

Old   March 29, 2015, 17:27
Default
  #30
Member
 
Join Date: May 2012
Posts: 55
Rep Power: 15
styleworker is on a distinguished road
createFields.H is just read at the beginning of the simulation. You should update g.value() at each time step
styleworker is offline   Reply With Quote

Old   March 30, 2015, 12:19
Post ya i know problem is creatfields.h is read once but......
  #31
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
yes boss i know creatFields.H is read just once. and i have to update g.value at each time step.... but the problem is how to do it..... i have tried by adding while loop in creatFields for g.value() but it doesnt work. as you said creatFields is read only once. if i take out g.value form creatFields.H and place it in interFoam g.value does not replace g vector specified in constants directory of the case. please suggest if you have an idea.....
Quote:
Originally Posted by styleworker View Post
createFields.H is just read at the beginning of the simulation. You should update g.value() at each time step
13msmemusman is offline   Reply With Quote

Old   March 30, 2015, 13:45
Default
  #32
Member
 
Join Date: May 2012
Posts: 55
Rep Power: 15
styleworker is on a distinguished road
While loops in createFields.H doesn't make sense, since the timeStep isn't updated. Update g.value() in runTime while loop (interFoam.C).

For example:

Code:
while (runTime.run())
{
    #include "readTimeControls.H"
    #include "CourantNo.H"
    #include "alphaCourantNo.H"
    #include "setDeltaT.H"

    runTime++;

    Info<< "Time = " << runTime.timeName() << nl << endl;

    g.value() = timeSeriesAcceleration(runTime.value());

    twoPhaseProperties.correct();

    #include "alphaEqnSubCycle.H"
    interface.correct();
...
}
styleworker is offline   Reply With Quote

Old   March 30, 2015, 13:52
Post
  #33
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
sir i tried this but it doesnt solve for acceleration from acceleration.dat instead it solves from g file. i have already tried this.....
13msmemusman is offline   Reply With Quote

Old   March 30, 2015, 13:56
Post
  #34
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
i have tried it by keeping g.value() = timeSeriesAcceleration(runTime.value()); at the same place as you kept... but doing this solver stops taking value from acceleration.dat it takes g value from g file. as it solves g in creatFields for gh and p_gh both gets g value.....
13msmemusman is offline   Reply With Quote

Old   March 30, 2015, 14:03
Default
  #35
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
any other suggestion sir???
Quote:
Originally Posted by styleworker View Post
While loops in createFields.H doesn't make sense, since the timeStep isn't updated. Update g.value() in runTime while loop (interFoam.C).

For example:

Code:
while (runTime.run())
{
    #include "readTimeControls.H"
    #include "CourantNo.H"
    #include "alphaCourantNo.H"
    #include "setDeltaT.H"

    runTime++;

    Info<< "Time = " << runTime.timeName() << nl << endl;

    g.value() = timeSeriesAcceleration(runTime.value());

    twoPhaseProperties.correct();

    #include "alphaEqnSubCycle.H"
    interface.correct();
...
}
13msmemusman is offline   Reply With Quote

Old   March 30, 2015, 14:16
Default
  #36
Member
 
Join Date: May 2012
Posts: 55
Rep Power: 15
styleworker is on a distinguished road
Quote:
Originally Posted by 13msmemusman View Post
i have tried it by keeping g.value() = timeSeriesAcceleration(runTime.value()); at the same place as you kept... but doing this solver stops taking value from acceleration.dat it takes g value from g file. as it solves g in creatFields for gh and p_gh both gets g value.....
then you should update gh and ghf, too.

Code:
gh = g & mesh.C();
ghf = g & mesh.Cf();
styleworker is offline   Reply With Quote

Old   March 30, 2015, 14:35
Wink
  #37
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
thank you sir it works
Quote:
Originally Posted by styleworker View Post
then you should update gh and ghf, too.

Code:
gh = g & mesh.C();
ghf = g & mesh.Cf();
13msmemusman is offline   Reply With Quote

Old   August 3, 2020, 02:30
Smile
  #38
New Member
 
Qiong-yao Wang
Join Date: Apr 2014
Posts: 18
Rep Power: 12
hellowqy is on a distinguished road
Quote:
Originally Posted by idrama View Post
Thanks All!

PROBLEM SOLVED, MISSION ACCOMPLISHED:

#include "fvCFD.H"
#include "MULES.H"
#include "subCycle.H"
#include "interfaceProperties.H"
#include "twoPhaseMixture.H"
#include "turbulenceModel.H"

#define pi 3.141592653589793238


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{

const dimensionedScalar gunits("gunits", dimensionSet(0,1,-2,0,0,0,0), 9.81);


#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"
#include "readGravitationalAcceleration.H"
#include "readPISOControls.H"
#include "initContinuityErrs.H"
#include "createFields.H"
#include "readTimeControls.H"
#include "correctPhi.H"
#include "CourantNo.H"
#include "setInitialDeltaT.H"


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Info<< "\nStarting time loop\n" << endl;

while (runTime.run())
{
#include "readPISOControls.H"
#include "readTimeControls.H"
#include "CourantNo.H"
#include "setDeltaT.H"

runTime++;

g=gunits*Foam::sin(runTime.value()*pi/4.0)*vector(1,0,0)-gunits*Foam::cos(runTime.value()*pi/4.0)*vector(0,0,1);


Info<< "Time = " << runTime.timeName() << nl << endl;

Kinda regards!

Claus
Hi,clause. Your answer to changable acceleration seems correct, but how can I handle the g file in const folder. Thanks in advance.
hellowqy is offline   Reply With Quote

Old   November 15, 2022, 23:54
Default no match for operator error in implementing variable gravity
  #39
New Member
 
Tamil Nadu
Join Date: Nov 2022
Posts: 2
Rep Power: 0
RamJedi is on a distinguished road
Based on the direction given in this thread,

I tried using the line
g=gunits*vector(0,Foam::sin(runTime.value()*pi*2.0 *freq),1) for sinusoidal lateral acceleration


I get an error

interFoam2.C:114:3: error: no match for âoperator=â (operand types are âconst Foam::meshObjects::gravityâ and âFoam::dimensioned<Foam::Vector<double> >â)
g=gunits*vector(0,Foam::sin(runTime.value()*pi*2.0 *freq),1);

I also tried the line given in the thread as such to test. That too gave a similar error. Am I missing some step? I do hope I get a response considering that this is an very old thread.

I am using v1812
RamJedi is offline   Reply With Quote

Old   November 17, 2022, 12:40
Default
  #40
Senior Member
 
Jon Elvar Wallevik
Join Date: Nov 2010
Location: Reykjavik, ICELAND
Posts: 103
Rep Power: 20
JonW will become famous soon enough
I dont think you can put the "Foam::"-thingi into vector()
Rather try this,...
g=gunits*Foam::sin(runTime.value()*pi*2.0*freq)*ve ctor(0,1,0) + gunits*vector(0,0,1);


If this is indeed gravity, make sure that abs(g) = 9.81. Like this vector is now, then its not the case.
Hope this helps.
JonW is offline   Reply With Quote

Reply

Tags
gravity, time, variation


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
Time step size and max iterations per time step pUl| FLUENT 31 October 23, 2020 23:50
Simulation of sloshing by time varying gravity Manoj Kumar FLUENT 3 June 13, 2011 04:34
PostChannel maka OpenFOAM Post-Processing 5 July 22, 2009 10:15
Problems with simulating TurbFOAM barath.ezhilan OpenFOAM 13 July 16, 2009 06:55
variation of gravity with time rajani FLUENT 0 February 16, 2005 03:45


All times are GMT -4. The time now is 06:54.