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/)
-   -   Reading old time step (https://www.cfd-online.com/Forums/openfoam-solving/58711-reading-old-time-step.html)

markc July 12, 2008 04:07

Hi All, I am trying to modi
 
Hi All,

I am trying to modify interFoam solver to my needs.
It is necessary for the new solver to perform an initialisation step (include"initialise.H"). Here, from time = 0 the p field is needed to perform some tasks.
Now my question is: how to make it always reading this time =0?
I tried many things:
In initialise.H add:
//volScalarField p
(
IOobject
(
"p",
runTime.timeName(0),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);

This compiles but when running it reads from the startTime stated in controldict anyway.
Uncommenting the line volScalarField p gives compiler error: p already declared. That is correct, this is done with createrFields.

I moved around with the location in the main solver of the initialisation step, without succes.

I think it is really something trivial, however, not for me apparently.
A more general question (as I have similar questions more often): anyone has advice as where to find some good basic C-programming reading, except for the user manal?

Thanks in advance,

Mark

wenterodt July 14, 2008 03:20

Hi Mark, isn't the pressure
 
Hi Mark,

isn't the pressure in interFoam called pd? This field is created in createFields.H, you can initialize it right there.

Also when you specify IOobject::MUST_READ, the solver will attempt to read the field upon start. Maybe the combination IOobject::NO_READ, IOobject::AUTO_WRITE is what you are looking for?

Regards,

Tammo

markc July 14, 2008 04:29

Hello Tammo, Thanks for you
 
Hello Tammo,

Thanks for your reply. Yes, you are right, pd is usualy used in interFoam. However I created an extra field p which contains hydrostatic pressure. However, this does not matter here. I initialised this in createFields.H as with other fields.
The problem is simply that I can only read it once and that it always uses the startTime from the controlDict, as usual. However I want to read one field (p) one more time but at a different time (always "0" instead of "startTime"). I feel a bit dump about it because I suspect it is really something simple for experienced OF-ers.

Brgds,

Mark

wenterodt July 14, 2008 04:57

How about copying your p-file
 
How about copying your p-file to "constant" and then use runTime.constant()?

markc July 14, 2008 06:01

Hello Tammo, I think I foun
 
Hello Tammo,

I think I found the problem.
The code snippet I posted in the 1st message does not contain the word mesh just before the final bracket.
Now I added this word and it seems to work.
The structure now is:
solver.C
int main(int etc etc)
-
-
#include "createFields.H"
etc etc
#include "initialise.H" (extra header file)
This header file contains amongst others:
(
IOobject
(
"p",
runTime.timeName(0),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);

back to solver.C
and further.

It seems to work.
Thanks for your advice,

Mark

markc July 14, 2008 07:41

Recall: no it did not work. In
 
Recall: no it did not work. In this setup "initialise.H" still seems to work with the timestep which is stated as "startTime" instead of "0".
We continue trying...
Mark

wenterodt July 14, 2008 08:27

1. Did you give the runTime.co
 
1. Did you give the runTime.constant() idea a shot?
2. how about (this is not pretty but might work) creating a field pConst with IOobject::AUTO_WRITE, from which you make a copy "p" (which you can alter as you like) whenever you need it ? The solver should then always find a pConst in the actual time-directory.

Any good?

markc July 14, 2008 10:00

Hello Tammo, 1. Not yet, wi
 
Hello Tammo,

1. Not yet, will try asap.
2. Will keep that as emergency exit.

Thanks for your advice,

Mark

markc July 22, 2008 15:11

Hello All, This did the tri
 
Hello All,

This did the trick:
>>>
# include "addTimeOptions.H"
# include "setRootCase.H"
# include "createTime.H"

// Get times list
instantList Times = runTime.times();

// set startTime and endTime depending on -time and -latestTime options
# include "checkTimeOptions.H"

runTime.setTime(Times[startTime], 0);
# include "createMesh.H"
# include "createFields.H"
createfields e.g.:
>>>
Info<< "Reading field pd\n" << endl;
volScalarField pd
(
IOobject
(
"pd",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
<<<
<<<
Brgds,

Mark


All times are GMT -4. The time now is 10:38.