CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Writting fields separately (http://www.cfd-online.com/Forums/openfoam-programming-development/112280-writting-fields-separately.html)

JimKnopf January 25, 2013 05:43

Writting fields separately
 
Hello there!

At the end of my calculation i create several (let's say 50 additional) volVectorFields from my solution and write them to the hard drive.

Right now I create a prtList<volVectorField> foo

and put all my vectorFields in there.

Code:

forAll(foo, fooI)
{
/* writte data to U field*/

  foo.set
    (
    fooI,
    new volVectorField
    (
      IOobject
      (
      "bar"+Foam::name(fooI),
      mesh.time().timeName(),
      mesh,
      IOobject::NO_READ,
      IOobject::AUTO_WRITE
      ),
      U
      )   
    );

}

Then data is written via runTime.write().

Well this works but it's very costly in terms of RAM. So is there a way to force the writing?

Like

0. compute field i
1. create field
2. write field
3. delete field
4. goto 0 and repeat

What I'm looking for ist a method "write this field now to time N".

Anyone got any idea?

Thanks and best regards
Jim

kmooney January 25, 2013 18:32

Hi Jim,

If I understand your question you could take the writing responsibilities from the runTime.write() call and take it into your own hands.

You could set the fields to be NO_WRITE instead of AUTO_WRITE when declaring the IOobject.

Then you can write on demand (and only when you demand) with:

Code:

if(runTime.write())
{
      fooI.write();
}

or without the IF conditional if you just want to write every timeStep.

Is that what you were looking for?

Hisham January 26, 2013 07:50

Quote:

Originally Posted by kmooney (Post 404104)
Hi Jim,

If I understand your question you could take the writing responsibilities from the runTime.write() call and take it into your own hands.

You could set the fields to be NO_WRITE instead of AUTO_WRITE when declaring the IOobject.

Then you can write on demand (and only when you demand) with:

Code:

if(runTime.write())
{
      fooI.write();
}

or without the IF conditional if you just want to write every timeStep.

Is that what you were looking for?

Hi

Adding to this, if you create the volFields inside the if(runTime.write()) block you can keep your RAM free until write time at which the Fields are created, written then deleted (automatically go out of scope).

Hisham

JimKnopf January 28, 2013 04:19

Hi,

thank you, that was what I was looking for. I just didn't find the write() method of the IOobject, although it's obvious.

Greets
Jim


All times are GMT -4. The time now is 00:59.