CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

How to select some variables not to be written into files?

Register Blogs Community New Posts Updated Threads Search

Like Tree10Likes
  • 5 Post By olivierG
  • 4 Post By ripperjack
  • 1 Post By lucie.recurt

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 21, 2013, 23:28
Default How to select some variables not to be written into files?
  #1
Member
 
Jack
Join Date: Dec 2011
Posts: 94
Rep Power: 14
ripperjack is on a distinguished road
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
ripperjack is offline   Reply With Quote

Old   May 22, 2013, 05:18
Default
  #2
Senior Member
 
Olivier
Join Date: Jun 2009
Location: France, grenoble
Posts: 272
Rep Power: 18
olivierG is on a distinguished road
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
olivierG is offline   Reply With Quote

Old   May 22, 2013, 05:38
Default
  #3
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17
fredo490 is on a distinguished road
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
fredo490 is offline   Reply With Quote

Old   May 23, 2013, 12:19
Default
  #4
Member
 
Jack
Join Date: Dec 2011
Posts: 94
Rep Power: 14
ripperjack is on a distinguished road
Quote:
Originally Posted by fredo490 View Post
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);
    }
ripperjack is offline   Reply With Quote

Old   May 24, 2017, 19:26
Question How to set variables to NO_WRITE
  #5
New Member
 
JasonC
Join Date: May 2017
Posts: 2
Rep Power: 0
jdchristopher24 is on a distinguished road
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.
jdchristopher24 is offline   Reply With Quote

Old   March 5, 2019, 15:41
Default
  #6
Senior Member
 
Peter Shi
Join Date: Feb 2017
Location: Davis
Posts: 102
Rep Power: 9
PeterShi is on a distinguished road
Quote:
Originally Posted by ripperjack View Post
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
PeterShi is offline   Reply With Quote

Old   April 10, 2020, 09:31
Default
  #7
New Member
 
Philomène Vergnol
Join Date: Apr 2020
Posts: 11
Rep Power: 6
pvergnol is on a distinguished road
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 ?
pvergnol is offline   Reply With Quote

Old   April 10, 2020, 09:50
Default
  #8
Senior Member
 
Olivier
Join Date: Jun 2009
Location: France, grenoble
Posts: 272
Rep Power: 18
olivierG is on a distinguished road
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,
olivierG is offline   Reply With Quote

Old   April 10, 2020, 10:31
Default
  #9
New Member
 
Philomène Vergnol
Join Date: Apr 2020
Posts: 11
Rep Power: 6
pvergnol is on a distinguished road
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 ?
pvergnol is offline   Reply With Quote

Old   April 10, 2020, 10:35
Default
  #10
Senior Member
 
Olivier
Join Date: Jun 2009
Location: France, grenoble
Posts: 272
Rep Power: 18
olivierG is on a distinguished road
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,
olivierG is offline   Reply With Quote

Old   April 10, 2020, 11:07
Default
  #11
New Member
 
Philomène Vergnol
Join Date: Apr 2020
Posts: 11
Rep Power: 6
pvergnol is on a distinguished road
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 is offline   Reply With Quote

Old   April 14, 2020, 09:51
Default
  #12
New Member
 
Philomène Vergnol
Join Date: Apr 2020
Posts: 11
Rep Power: 6
pvergnol is on a distinguished road
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
pvergnol is offline   Reply With Quote

Old   August 7, 2020, 12:15
Default
  #13
New Member
 
Lucie Recurt
Join Date: Jun 2020
Posts: 17
Rep Power: 6
lucie.recurt is on a distinguished road
Quote:
Originally Posted by olivierG View Post
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
JesusJoker likes this.
lucie.recurt is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open old mesh cmdb files in ANSYS CFX v13.0 ? Sudharshani CFX 2 May 12, 2013 23:13
Compiled library vs. inInclude Files, DSMC solver crashes after run GPesch OpenFOAM Programming & Development 8 April 18, 2013 08:17
How to call FORTRAN files as UDF? Ehsan-F Fluent UDF and Scheme Programming 6 September 11, 2012 12:03
Writing Case and Data Files Using Journal/Scheme Files svp Fluent UDF and Scheme Programming 0 April 5, 2011 12:04
Results saving in CFD hawk Main CFD Forum 16 July 21, 2005 21:51


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