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

Accessing old fields: lookupObject at user defined time

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 2, 2019, 13:41
Default Accessing old fields: lookupObject at user defined time
  #1
New Member
 
Emily
Join Date: Nov 2017
Posts: 24
Rep Power: 8
em17 is on a distinguished road
Hi all,

I would like to look up an object (e.g. U) from a user-defined time previously. I cannot hard code this as the number will change from simulation to simulation.

If I am to define this number N, in a constant/*Properties file, then I would like to define something like lookupObject<volVectorField>("U") (at time: current time - N).
For example, say the current time is 1s, then I would like to lookup the velocity field at 0.7s by using current time (1) minus user-defined time, N (in this case, N=0.3). Does anyone know how I can do this?

Thank you,
Emily
em17 is offline   Reply With Quote

Old   October 3, 2019, 12:05
Default
  #2
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 9
frobaux is on a distinguished road
Hello,

You can do it by using the function

Code:
 runtime.timeName()
for your example:
Code:
volScalarField Phi
(
    IOobject
    (
        "Phi",
        runTime.timeName(0.7),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
     ),
     mesh
 );
should work as intended
frobaux is offline   Reply With Quote

Old   October 3, 2019, 12:53
Default
  #3
New Member
 
Emily
Join Date: Nov 2017
Posts: 24
Rep Power: 8
em17 is on a distinguished road
Hi,

Thanks for your reply. I should have mentioned that I am trying to write a functionObject so I don't think I can use runTime. I can however use some variant of obr_.time().something . Do you know if can get the equivalent of runTime.timeName(0.7) using obr_.time()?

Thanks
em17 is offline   Reply With Quote

Old   October 4, 2019, 05:34
Default
  #4
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 9
frobaux is on a distinguished road
Well, I'm sorry I don't know. I'm not familiar at all with the functionObjects.
What is the type of obr_?
The function Foam::Time::timeName() is pretty simple, maybe it would be possible to recode it. The only problem would be the label "precision", which describe the maximum number of decimals.
Note that this precision is set at the begining then updated if needed in order to discernate the differents results.



Code:
Foam::word Foam::Time::timeName(const scalar t, const int precision)
{

   std::ostringstream buf;
    buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
    buf.precision(precision);
    buf << t;
    return buf.str();
}
frobaux is offline   Reply With Quote

Old   October 7, 2019, 08:10
Default
  #5
New Member
 
Emily
Join Date: Nov 2017
Posts: 24
Rep Power: 8
em17 is on a distinguished road
I figured out how to do it using obr_.time().timeName(0.7) in case anyone else comes across this problem.

Thanks again for your help.
em17 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
courant number increases to rather large values 6863523 OpenFOAM Running, Solving & CFD 22 July 6, 2023 00:48
LES, Courant Number, Crash, Sudden Alhasan OpenFOAM Running, Solving & CFD 5 November 22, 2019 03:05
High Courant Number @ icoFoam Artex85 OpenFOAM Running, Solving & CFD 11 February 16, 2017 14:40
a reconstructPar issue immortality OpenFOAM Post-Processing 8 June 16, 2013 12:25
IcoFoam parallel woes msrinath80 OpenFOAM Running, Solving & CFD 9 July 22, 2007 03:58


All times are GMT -4. The time now is 09:18.