CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Operation to READ_IF_PRESENT field (https://www.cfd-online.com/Forums/openfoam-programming-development/68385-operation-read_if_present-field.html)

sega September 17, 2009 08:28

Operation to READ_IF_PRESENT field
 
Hello World.

What happens to an operation like
Code:

volVectorField us = fvc::interpolate(U)
done to to a field (U in this case) which is READ_IF_PRESENT?

Will this operation cause an error or will it just be skipped if the field is not present?!

niklas September 17, 2009 09:17

READ_IF_PRESENT just means that the field will be read from disk if it is available,
otherwise it will be set to the value given in the constructor.

mrshb4 February 12, 2011 03:39

....
 
Hi
[READ_IF_PRESENT just means that the field will be read from disk if it is available,
otherwise it will be set to the value given in the constructor. ]
What do you mean the value given in the constructor?

niklas February 14, 2011 02:14

Code:

volScalarField hTotal
(
    IOobject
    (
        "hTotal",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::AUTO_WRITE
    ),
    h+h0
);

In the above example,
if the file hTotal exists, the value will be read from that file.
Otherwise it will use the values from 'h+h0'

mrshb4 February 14, 2011 04:13

Hi Niklas
Thanks for your reply.
I have another problem, that by now I've couldn't solve that!
I'm solving an equiation with a source term, like:
ddt2(p)-laplacian(p)=q
(source term is q)
I calculate source term from another solver every 1e-5 second and bring all of them in time directories in this solver.
The time interval of this solver is 1e-8 and I want that this solver reads every q whenever it reachs its time. For example at first it reads q in 0 directory and work with that, but when it reachs 1e-5 q should be read and changed and so on.......

Do you know how should I define q to be read like this?!?

Thank you
Mohammadreza

niklas February 14, 2011 04:27

You read q at start so that volScalarField exists already, then you place the code below
just before the equation you want to solve

Code:

    IOobject qHeader
    (
        "q",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ
    );

    if (qHeader.headerOk())
    {   
        volScalarField qNew
      (
            IOobject
            (
                "q",
                runTime.timeName(),
                mesh,
                IOobject::MUST_READ,
                IOobject::NO_WRITE
            ),
            mesh
        );
        q = qNew;

    }
    // ... solve the equation with the new q

This will try and read a new field every time step, but it will only update it when it exists

mrshb4 February 15, 2011 09:57

Hi Niklas

Thank you so much for your reply...with a little modification it worked properly.

Mohammadreza


All times are GMT -4. The time now is 13:57.