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/)
-   -   How to select some variables not to be written into files? (https://www.cfd-online.com/Forums/openfoam-programming-development/118156-how-select-some-variables-not-written-into-files.html)

ripperjack May 21, 2013 22:28

How to select some variables not to be written into files?
 
Hi all,

I have defined so many variables in my solver and my mesh number is really huge, so I do not want to write some of my variables into output files. I know I can do this by setting the variables output option to NO_WRITE instead of AUTO_WRITE. But I do not want to modify my solver because sometime I want them to be written and sometime not to. So is there any other ways that I can do this? e.g. by add some lines in controlDict or other files.

Many thanks!

Ping

olivierG May 22, 2013 04:18

hello,

If you are using 2.1 or later (not sure for older one), you can set to NO_WRITE almost all the variable, then using function Objects in controlDict, you can use the "writeRegisteredObject" to write the variable you want.

regards,
olivier

fredo490 May 22, 2013 04:38

Hello, I've done somthing similar to your request but it is a very simple/quick solution that doesn't look good:

1) create a library in the createFields and some "debug" variables:
Code:

    IOdictionary ExportData
    (
        IOobject
        (
            "ExportData",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    );

    dimensionedScalar ExportDataThermo(IcingProperties.lookup("ExportDataThermo"));
    dimensionedScalar ExportDataMomentum(IcingProperties.lookup("ExportDataMomentum"));

2) Set your fields as NO_WRITE

3) In your code (at the end of your time loop for example) add:
if the time step correspond to the writing time (= export of your case) and if your debut variable equal 1, then write the field "MyField1" and "MyField2".
Code:

        if((runTime.write()) && (ExportDataThermo.value() == 1))
        {
        MyField1.write();
        }

        if((runTime.write()) && (ExportDataMomentum.value() == 1))
        {
        MyField2.write();
        }

4) In you case, you need to add a new file in the Constant folder. This file has to take the name of your library (ExportData in this case) and put the following code inside:
Quote:

ExportDataThermo ExportDataThermo[ 0 0 0 0 0 0 0 ] 1;
ExportDataMomentum ExportDataMomentum[ 0 0 0 0 0 0 0 ] 0;


My solution works but it is not beautiful !! It's just a quick coding

ripperjack May 23, 2013 11:19

Quote:

Originally Posted by fredo490 (Post 429122)
Hello, I've done somthing similar to your request but it is a very simple/quick solution that doesn't look good:

1) create a library in the createFields and some "debug" variables:
Code:

    IOdictionary ExportData
    (
        IOobject
        (
            "ExportData",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    );

    dimensionedScalar ExportDataThermo(IcingProperties.lookup("ExportDataThermo"));
    dimensionedScalar ExportDataMomentum(IcingProperties.lookup("ExportDataMomentum"));

2) Set your fields as NO_WRITE

3) In your code (at the end of your time loop for example) add:
if the time step correspond to the writing time (= export of your case) and if your debut variable equal 1, then write the field "MyField1" and "MyField2".
Code:

        if((runTime.write()) && (ExportDataThermo.value() == 1))
        {
        MyField1.write();
        }

        if((runTime.write()) && (ExportDataMomentum.value() == 1))
        {
        MyField2.write();
        }

4) In you case, you need to add a new file in the Constant folder. This file has to take the name of your library (ExportData in this case) and put the following code inside:




My solution works but it is not beautiful !! It's just a quick coding



Hi HECKMANN,

Thanks very much for your code! I have tried the method suggestion by Olivier, it works and it is also simple to do it. I just need to set the all variables to NO_WRITE, and add the following lines in the controlDict to output the ones I need! Thanks anyway!

Code:

    dumpObjects
    {
        // Forcibly write registered objects. E.g. fields that have been
        // created with NO_WRITE.

        type            writeRegisteredObject;

        // Where to load it from
        functionObjectLibs ("libIOFunctionObjects.so");

        // Execute upon outputTime
        outputControl  outputTime;

        // Objects to write
        objectNames    (U T p);
    }


jdchristopher24 May 24, 2017 18:26

How to set variables to NO_WRITE
 
I see in the process described above they suggest setting variables to NO_WRITE. Where do I do that? I don't see that option (or AUTO_WRITE) in any of my setup files for OpenFOAM, so do I need to create a new file in the system directory? I get how to then write the files by adding an object to my controlDict file... just now how to turn off writing them in the first place.


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