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.

PeterShi March 5, 2019 14:41

Quote:

Originally Posted by ripperjack (Post 429545)
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);
    }


Hi,

It has been a while, but I wonder when you replace AUTO_WRITE with NO_WRITE, did you recompile your solver? For me, I am using OpenFOAM 6.0, I made modifications in createFields.H, and I added lines in controlDict. However, the code still outputs all variables for me. I feel like I need to recompile it to make it work.

Also, in createFields.H, I only see p and U, but I have turbulent variables such as omega and nut, is replacing AUTO_WRITE with NO_WRITE for p and U enough to prevent those turbulent variables from being written as well?

Thank you so much, and I really appreciate it.

Best,
Peter

pvergnol April 10, 2020 08:31

Hello, I have the exact same problem. Did you solve it ?
I am currently going through all .H files trying to find where I can change to NO_WRITE for the variables I want to stop writing.
I think I have to recompile after having done all that.
Can someone confirm ?

olivierG April 10, 2020 08:50

Hello,
Don't change aAUTO_WRITE to NO_WRITE in core, or you should recomplie it.


Simpler way is tu use function Object "writeObjects, like:
Code:

writeObjects1
    {
        type        writeObjects;
        libs        ("libutilityFunctionObjects.so");
      //writeControl writeTime;

        ...
        objects    (obj1 obj2);// i.e fields you don't want
        writeOption noWrite;//anyWrite;autoWrite
    }

You may also look at removeRegisteredObject for some case.

regards,

pvergnol April 10, 2020 09:31

Hello olivierG, thank you so much for your quick and clear reply.
I added in controlDict :

Code:

writeObjects1
    {
        type        writeObjects;
        libs        ("libutilityFunctionObjects.so");
        objects    (rho nut alphat T.air T.water);
        writeOption noWrite;
    }

But when I look in the output time directories, those fields are still written.
Am I missing something ?

olivierG April 10, 2020 09:35

Hello,
Which OF version do you use ? (i.e writeObjects compatible ?)

with this function, you could do the opposite:
in controlDict, set writeInterval to something big, then use writeObjects to write fields when you want.
Regards,

pvergnol April 10, 2020 10:07

Hello,

I use OpenFOAM v7, and I saw here : https://cfd.direct/openfoam/user-gui...processing-cli/ that it is indeed compatible.

Actually, I forgot before to write the functions keyword at first, that's why it didn't work.
With the writeObjects function, it does work, only it removes all of the fields, even the ones I wanted to keep.

So I added a second function such that my controlDict is now :

Code:

functions
{
        writeObjects1
                {
                        type        writeObjects;
                        libs        ("libutilityFunctionObjects.so");
                        objects    (rho nut alphat alphaPhi0.water phi T.air T.water);
                        writeOption noWrite;
                }
        writeObjects2
                {
                        type        writeObjects;
                        libs        ("libutilityFunctionObjects.so");
                        objects    (U p T alpha.water);
                        writeOption autoWrite;
                }
}

It works, I only have the fields that I want now. Problem solved, thank you so much olivierG !

Have a great day,
Best regards :)

pvergnol April 14, 2020 08:51

Hello,
I have a follow-up question :
So with this solution I managed to write only the fields I wanted to write.
But to reduce the total output size, I want to reduce the writing frequency. I tried changing writeControl in controlDict using adjustableRunTime (I use adjustTimeStep)but it has no effect : they are still written. So I figured I had to change this parameter within the functions :

Code:

functions
{
        writeObjects1
                {
                        type                        writeObjects;
                        libs                        ("libutilityFunctionObjects.so");
                        objects                    (rho nut alphat alphaPhi0.water phi T.air T.water);
                        writeOption                noWrite;
                        writeControl            adjustableRunTime;
                        writeInterval                  0.01;

                }
        writeObjects2
                {
                        type                        writeObjects;
                        libs                        ("libutilityFunctionObjects.so");
                        objects                    (U p T alpha.water);
                        writeOption                autoWrite;
                        writeControl            adjustableRunTime;
                        writeInterval                  0.01;

                }
}

With this, time directories are created every 0,01 s of simulated time, just like I want. But in these directories, each field is written, not only the ones from writeObjects2.

When I remove
Code:

writeControl            adjustableRunTime;
writeInterval                  0.01;

in writeObjects1, it is the same as before, except an empty time directory is also created at every timestep.

I can't seem to be able to write the fields I want at the frequency I want.
Does someone know how to make this work ?

Thank you in advance

lucie.recurt August 7, 2020 11:15

Quote:

Originally Posted by olivierG (Post 429117)
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


I don't really understand how to write that.. is it possible to have an example? thank you in advance


All times are GMT -4. The time now is 16:25.