CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Storing previous time step data

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 2 Post By mohanamuraly
  • 2 Post By mohanamuraly

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 28, 2011, 05:47
Default Storing previous time step data
  #1
New Member
 
Mohanamuraly
Join Date: May 2009
Posts: 18
Rep Power: 17
mohanamuraly is on a distinguished road
Hi

I am writing an acoustics propagation code using OF. I have my compressible code results at given time steps sizes. I need to load the data at time i (current) and i-1 (previous time) to evaluate the time derivative of the source terms in the integral.


For getting the time derivative of pressure I did this
---------------------------------------------------------------------------
volScalarField p_cur
(
IOobject
(
"p",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

and stored the current value in a variable p_old
volScalarField p_old(p_cur);
mesh.readUpdate();

But when I try to do
volScalarField dp_dt = p_cur - p_old;

It always returns exact zero as the time derivative for pressure. Is the constructor making a reference of p_cur and not making a new copy of p_cur in p_old ? If so how do I copy and not reference.

Pavanakumar M
mohanamuraly is offline   Reply With Quote

Old   February 28, 2011, 07:30
Default
  #2
New Member
 
Mohanamuraly
Join Date: May 2009
Posts: 18
Rep Power: 17
mohanamuraly is on a distinguished road
I finally figured out the way after fiddling with the OF code. The key is the creation of as many time objects as the number of time steps required. For example, a two point stencil in time will require two time objects.

So we make two as follows :

// This stores the current time
Foam::Time runTime
(
Foam::Time::controlDictName,
args.rootPath(),
args.caseName()
);

// This stores the previous time
Foam::Time prevTime
(
Foam::Time::controlDictName,
args.rootPath(),
args.caseName()
);

And then you create the fields p_cur (current) and p_old (previous) as follows:

volScalarField p_cur
(
IOobject
(
"p",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

volScalarField p_old
(
IOobject
(
"p",
prevTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

In your code make sure that you update the runTime object first and one iteration delayed update of prevTime object. This will ensure that you maintain the current and previous time step data in your code.

I dont know if using two time objects is ok. But it is working for me.


Best,

Pavanakumar M
mm.abdollahzadeh and randolph like this.
mohanamuraly is offline   Reply With Quote

Old   October 8, 2012, 06:21
Default
  #3
Senior Member
 
mahdi abdollahzadeh
Join Date: Mar 2011
Location: Covilha,Portugal
Posts: 153
Rep Power: 15
mm.abdollahzadeh is on a distinguished road
Quote:
Originally Posted by mohanamuraly View Post

In your code make sure that you update the runTime object first and one iteration delayed update of prevTime object. M
Dear Friend

I dont know how to update the object at my runTime.

could you give me some idea please

Best
Mahdi
mm.abdollahzadeh is offline   Reply With Quote

Old   October 8, 2012, 08:00
Default
  #4
New Member
 
Mohanamuraly
Join Date: May 2009
Posts: 18
Rep Power: 17
mohanamuraly is on a distinguished road
Mahdi,

This is a very bad idea of using time objects. This will keep three copies of the entire solution at two time levels, which is bad idea. Currently I dropped this idea and decided to parse the entire solutiontime history forming a source array. I then use this source array to find the time derivatives and acoustic integrals. This also makes sense if you want to do parallel noise prediction.

I am anyway attaching the source verbatim from my old git snap-shot for your benefit ... but don't blame me for damages that it might do to you ... and I am not sure even if this works (it should but too lazy to test if this is the correct version in my git repo)

#include<.....>
Foam::Time prevTime
(
Foam::Time::controlDictName,
args.rootPath(),
args.caseName()
);
Foam::Time runTime
(
Foam::Time::controlDictName,
args.rootPath(),
args.caseName()
);
Foam::Time nextTime
(
Foam::Time::controlDictName,
args.rootPath(),
args.caseName()
);

Foam::instantList timeDirs = Foam::timeSelector::select0(runTime, args);

// This is a global counter that tell us how many time steps are currently loaded into memory
int countTimeSnaps = 0;
int prevTimeI,curTimeI,nextTimeI;
// Ffowcs Williams Hawkins Analogy
if(analogyType == "FfowcsWilliamsHawkings"){
forAll(timeDirs, timeI)
{
if( countTimeSnaps == 0 ) // First time
prevTimeI = timeI;
if( countTimeSnaps == 1 ) // Current time
curTimeI = timeI;
if( countTimeSnaps > 1 ) {
// Time step setup
nextTimeI = timeI;
prevTime.setTime(timeDirs[prevTimeI], prevTimeI);
runTime.setTime(timeDirs[curTimeI], curTimeI);
nextTime.setTime(timeDirs[nextTimeI], nextTimeI);
mesh.readUpdate();
prevTimeI = curTimeI;
curTimeI = nextTimeI;
Foam::Info << "********************************************\ n";
Foam::Info << "Previous Time : " << prevTime.timeName() << "\n";
Foam::Info << "Current Time : " << runTime.timeName() << "\n";
Foam::Info << "Next Time : " << nextTime.timeName() << "\n";
Foam::Info << "********************************************\ n";
# include "updateFWHSource.H"
}
++countTimeSnaps;
}
}


Cheers,

Mohanamuraly
mohanamuraly 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
Floating point exception error Alan OpenFOAM Running, Solving & CFD 11 July 1, 2021 22:51
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 06:36
SLTS+rhoPisoFoam: what is rDeltaT??? nileshjrane OpenFOAM Running, Solving & CFD 4 February 25, 2013 05:13
Hydrostatic Pressure and Gravity miliante OpenFOAM Running, Solving & CFD 132 October 7, 2012 23:50
AMG versus ICCG msrinath80 OpenFOAM Running, Solving & CFD 2 November 7, 2006 16:15


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