CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Output file with OpenFOAM header

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 20, 2009, 10:12
Default Output file with OpenFOAM header
  #1
Senior Member
 
sega's Avatar
 
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20
sega is on a distinguished road
Hello again.

Is there a way of putting the standard OpenFOAM file header on top of an output file I created with something like this?
Code:
OFstream os ("p");
os << faceCenterPressure;
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 22, 2009, 03:41
Default
  #2
Senior Member
 
sega's Avatar
 
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20
sega is on a distinguished road
Sorry I have to push this, but this problem is crucial in one of my efforts.
I'm producing a lot of files with a home-made tool.
Editing these files by copy&pasting file headers inside is critically affecting the whole performance ...

What I'm searching for is a possibilty to put the OpenFOAM header on top of an output file. Furthermore I need to specify the class and object entry!
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 22, 2009, 08:29
Default
  #3
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by sega View Post
Sorry I have to push this, but this problem is crucial in one of my efforts.
I'm producing a lot of files with a home-made tool.
Editing these files by copy&pasting file headers inside is critically affecting the whole performance ...

What I'm searching for is a possibilty to put the OpenFOAM header on top of an output file. Furthermore I need to specify the class and object entry!
The functionality you require is in the IOobject-class (that is why you always have to construct one when you add a new field). Go to the Doxygen and there click yourself down the inheritance-tree until you find a class that does what you want (IOList or IOdictionary might be what you need)

Bernhard
gschaider is offline   Reply With Quote

Old   July 22, 2009, 08:45
Default
  #4
Senior Member
 
sega's Avatar
 
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20
sega is on a distinguished road
I'm not familiar with this Doxygen thing but I haven't found an "inheritence tree".
Just some crypical "class reference".
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 22, 2009, 08:50
Default
  #5
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
Have a look at:

IOobject::writeHeader or IOobjectWriteHeader.C

That should give you enough information.

To use Doxygen, have a look here:

http://foam.sourceforge.net/doc/Doxy...1IOobject.html

And scroll down to the public member functions section.

Oh, and look at:

http://foam.sourceforge.net/doc/Doxy...ph_legend.html

to see how the diagrams work.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   July 22, 2009, 12:27
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by sega View Post
I'm not familiar with this Doxygen thing but I haven't found an "inheritence tree".
Just some crypical "class reference".
And in the class reference you find an inheritance-diagram. In that you find that only one class inherits from IOobject but if you click on that all the "grandchildren" is revealed. But I don't want to spoil the whole fun for you, as you'll probably want to familiarize yourself with Doxygen if you want to do any serious programming in OpenFOAM

Bernhard
gschaider is offline   Reply With Quote

Old   July 27, 2009, 12:15
Default
  #7
Senior Member
 
sega's Avatar
 
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20
sega is on a distinguished road
I'm afraid I can't solve this mystery on my own.
I toyed around with some strange commands.

Code:
        OFstream osP (directory/"p");
        faceCenterPressure.writeHeader(osP);
        osP << faceCenterPressure;
is my best guess, but it's not working:

Code:
error: ‘class Foam::scalarField’ has no member named ‘writeHeader’
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 28, 2009, 09:49
Default
  #8
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by sega View Post
I'm afraid I can't solve this mystery on my own.
I toyed around with some strange commands.

Code:
        OFstream osP (directory/"p");
        faceCenterPressure.writeHeader(osP);
        osP << faceCenterPressure;
is my best guess, but it's not working:

Code:
error: ‘class Foam::scalarField’ has no member named ‘writeHeader’
What kind of "thing" is faceCenterPressure, anyway? Let's assume it is a scalarList. Then try something like (I'm only doing this from the Information available in the Doxygen, the details may be wrong)
Code:
IOList<scalar> faceCenterPressure(
  IOobject(
            "faceCenterPressure",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        )
 );
that should be read if present (zero-size otherwise) and automagically written whenever all the other stuff is written. WITH A HEADER. And you can use it like any other scalarList
gschaider is offline   Reply With Quote

Old   July 28, 2009, 10:25
Default
  #9
Senior Member
 
sega's Avatar
 
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20
sega is on a distinguished road
This faceCenterPressure is a scalarField!

Code:
scalarField faceCenterPressure(facesSet.size());
which is collecting pressure values at specific face centers and is written to a file with OFstream!
Have a look:
(Note: surfaceScalarField ps = fvc::interpolate(p);)

Code:
for (label k=0; k<facesSet.size(); k++)
    {
        int faceNumber = faces[k];
        faceCenterPressure[k] = ps[faceNumber];

        fileName directory = runTime.path()/"boundaryData"/setName/runTime.timeName();
        mkDir(directory);

        OFstream osP (directory/"p");
        osP << faceCenterPressure;
   }
If I put your suggested code snipped anywhere inside the {}-brackets I get this error:

Code:
Make/linux64GccDPOpt/listFaceSet.o: In function `Foam::IOList<double>::type() const':
listFaceSet.C:(.text._ZNK4Foam6IOListIdE4typeEv[Foam::IOList<double>::type() const]+0x3): undefined reference to `Foam::IOList<double>::typeName'
Make/linux64GccDPOpt/listFaceSet.o: In function `Foam::IOList<double>::IOList(Foam::IOobject const&)':
listFaceSet.C:(.text._ZN4Foam6IOListIdEC1ERKNS_8IOobjectE[Foam::IOList<double>::IOList(Foam::IOobject const&)]+0x46): undefined reference to `Foam::IOList<double>::typeName'
collect2: ld returned 1 exit status
I assume there is something wrong with the "type" of field (scalarList, scalarField, or??) which is causing this error.

Still big question: Will your suggestion render this OFstream-output-command useless ?!
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 28, 2009, 13:40
Default
  #10
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by sega View Post
This faceCenterPressure is a scalarField!
My example was done without knowing this

Quote:
Originally Posted by sega View Post
I assume there is something wrong with the "type" of field (scalarList, scalarField, or??) which is causing this error.
Please go to the inheritance diagram in Doxygen. You will find that IOList ist a List with IO stuff added. How a Field with added IO would be called is left as an exercise to the reader.

Quote:
Originally Posted by sega View Post
Still big question: Will your suggestion render this OFstream-output-command useless ?!
Definitly. Use it the way stuff in the createFields.H of any solver is used
gschaider is offline   Reply With Quote

Old   July 28, 2009, 14:45
Default
  #11
Senior Member
 
sega's Avatar
 
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20
sega is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Please go to the inheritance diagram in Doxygen. You will find that IOList ist a List with IO stuff added. How a Field with added IO would be called is left as an exercise to the reader.
Dear Bernhard.

I appreciate your didactic intention.
But this inheritance diagram is filling two pages on my screen.
I have to confess I'm totally swamped with this.
Maybe this is not the right choice for starting to learn how to read the Doxygen guide.

I don't even have the slightest idea where to look, not to talk about finding a solution...

Sorry, I need further input ...
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 28, 2009, 14:59
Default
  #12
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
This is the way I would see it (correct if I'm wrong).

scalarField is just a typedef: Field<scalar>.

If you look at the inheritance diagrams, you should be able to see that all the dimensioned fields, IOList, IOField and other things all inherit from regIOobject which inherits from IOobject.

So you may have:
scalarField faceCentrePressure(IOobject..blah..);
IOField<scalar> faceCentrePressure(IOobject..blah..);

Does that help?
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   July 28, 2009, 15:22
Default
  #13
Senior Member
 
sega's Avatar
 
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20
sega is on a distinguished road
Yes.

Code:
IOField<scalar> faceCentrePressure(IOobject..blah..);
is compiling. But it's not doing what I want.
When running my code
Code:
    surfaceScalarField ps = fvc::interpolate(p);

    scalarField faceCenterPressure(facesSet.size());
      
    for (label k=0; k<facesSet.size(); k++)
    {
        int faceNumber = faces[k];

        faceCenterPressure[k] = ps[faceNumber];

        fileName directory = runTime.path()/"boundaryData"/setName/runTime.timeName();
        mkDir(directory);

        IOField<scalar> faceCenterPressure
        (
          IOobject
          (
        "faceCenterPressure",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::AUTO_WRITE
          )
        );

        OFstream osP (directory/"p");
        osP << faceCenterPressure;
        }

    };
on a case it tries to read the file faceCenterPressure in the time step directories instead of writing the faceCenterPressure scalarField into a corresponding (and equally named) file...
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 29, 2009, 06:19
Default
  #14
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by sega View Post
Yes.

Code:
IOField<scalar> faceCentrePressure(IOobject..blah..);
is compiling. But it's not doing what I want.
When running my code
Code:
    surfaceScalarField ps = fvc::interpolate(p);

    scalarField faceCenterPressure(facesSet.size());
      
    for (label k=0; k<facesSet.size(); k++)
    {
        int faceNumber = faces[k];

        faceCenterPressure[k] = ps[faceNumber];

        fileName directory = runTime.path()/"boundaryData"/setName/runTime.timeName();
        mkDir(directory);

        IOField<scalar> faceCenterPressure
        (
          IOobject
          (
        "faceCenterPressure",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::AUTO_WRITE
          )
        );

        OFstream osP (directory/"p");
        osP << faceCenterPressure;
        }

    };
Quote:
Originally Posted by sega View Post
on a case it tries to read the file faceCenterPressure in the time step directories
That's what READ_IF_PRESENT does
Quote:
Originally Posted by sega View Post
instead of writing the faceCenterPressure scalarField into a corresponding (and equally named) file...
That is what IOobjects do with the write()-method (to find methods "that should be there" click in the Doxygen on "List all members" and browse)

And currently you're writing stuff at every iteration of the loop. Basically you only need one faceCenterPressure (outside the loop)
Code:
        
IOField<scalar> faceCenterPressure
        (
          IOobject
          (
        "faceCenterPressure",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
          )
       ,facesSet.size()
        );
In the loop get rid of all the writing stuff and after the loop do
Code:
faceCenterPressure.write()
It writes to the current time-directory. How to get the stuff to the directory you want should be possible but I'd have to go to the Doxygen myself to see how to do that
gschaider is offline   Reply With Quote

Old   July 29, 2009, 10:48
Default
  #15
Senior Member
 
sega's Avatar
 
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20
sega is on a distinguished road
Yes. Thats working. Just great!
The files containing the correct values from the faceCenterPressure variable are written in the time directories with headers!

If you can point out to me how to write these files into a different location, this would round up this part of the problem.

The next problem is the following:
The output file hast to have two specific entries in its header
  • class: scalarAveragedField
  • object: values
How can I manage this?!
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 30, 2009, 07:47
Default
  #16
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
Does changing the second argument of IOobject to the folder you want the field to be saved to not work? So instead of runTime.timeName() having, say, "thisFolder".

Not sure how you would write different entries to your header. You could either change the IOobjectWriteHeader.C file or write to the file directly.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   July 31, 2009, 12:42
Default
  #17
Senior Member
 
sega's Avatar
 
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20
sega is on a distinguished road
Quote:
Originally Posted by l_r_mcglashan View Post
Does changing the second argument of IOobject to the folder you want the field to be saved to not work? So instead of runTime.timeName() having, say, "thisFolder".
I have toyed around with this entry, but haven't found a way of managing a different directory so far.

Quote:
Not sure how you would write different entries to your header. You could either change the IOobjectWriteHeader.C file or write to the file directly.
If I change anything in IOobjectWriteHeader.C will this be a "global" effect?
So all other fields will also be written in the manner I specify there?
Thats definitefly not what I intend to do, as this should be limited to the special case I'm working with ...

So, what do you mean by "writing directly to the file"?
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega 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
UDF with output text file manu Fluent UDF and Scheme Programming 18 December 12, 2018 23:46
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 20:08
Statically Compiling OpenFOAM Issues herzfeldd OpenFOAM Installation 21 January 6, 2009 10:38
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 19:07
Reduce output file size!! Jonac CFX 1 September 15, 2000 04:24


All times are GMT -4. The time now is 22:19.