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

How to create points and field files?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 19, 2009, 10:53
Default How to create points and field files?
  #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.

Can somebody tell me how I can manage to create points files and field files?
I looked through the sample tool, which can create foamFile outputs, but I haven't found the corresponding code.

What I want to do, is to
  • read a field value at different specific location inside the domain,
  • put the value inside a field file
  • and its location in a points file
So, the first problem I'm searching a solution for is how to store the values obtained from this loop:

Code:
    surfaceScalarField ps = fvc::interpolate(p);

    for (label k=0; k<facesSet.size(); k++)
    {
        int faceNumber = faces[k];
        Info<< "Entry " << k << " equals "<< ps[faceNumber]<< endl;
    };
I want the different values of ps[faceNumber] to be stored and somehow transfered to the mentioned field file and its corresponding points file.

Does anybody know, how this can be done?
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 19, 2009, 14:34
Default
  #2
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
Sebastian,

I think you intended to do something like

Code:
for (label k=0; k<facesSet.size(); k++)
{
     label faceNumber = facesSet[k];
    // copy data
}
but a faceSet is a labelHash. Therefore, you better use iterators

Code:
forAllConstIter(faceSet, facesSet, f)
{
    label faceNumber = f.key();
    // copy data
}
OR ask for the table of content

Code:
const labelList faces = facesSet.toc();
for (label k=0; k<faces.size(); k++)
{
    label faceNumber = faces[k];
    // copy data
}
OR do something foamish like:

Code:
scalarField data(0);
vectorField pnts(0);
const labelList faces = facesSet.toc();
data.map(ps, faces);
pnts.map(mesh.Cf(), faces);
I haven't tested any of this and knowing myself none of this will work straightaway. But it should work along these principals.

Henrik

Last edited by henrik; July 20, 2009 at 07:48.
henrik is offline   Reply With Quote

Old   July 19, 2009, 17:08
Default
  #3
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
Dear Henrik.

Maybe we are misunderstanding each other.
I already have a way of accessing the field data of interest.

My question is how I can manage to make my tool output these field data and its corresponding coordinates into a single points file and a single field value file.
Similar to the sample tools foamFile output.

Hope this makes my interest a little bit clearer.
S.
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 19, 2009, 18:12
Default
  #4
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
Dear Sebastian,

Code:
OFstream os ("points");
os << pnts;
Henrik
henrik is offline   Reply With Quote

Old   July 20, 2009, 07:38
Default
  #5
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 henrik View Post
Dear Sebastian,

Code:
OFstream os ("points");
os << pnts;
Henrik
Hi Henrik.

I assume "points" is the name of the variable containing the coordinates, while
Code:
os << pnts;
outputs the file?

If this is correct it will lead to two further questions:

1) If I work through the above loop which contains some different face values how do I store them in an appropriate array before outputting them to a file?

I would do this in some kind of MATLAB style:
Code:
// creating an empty field
scalarField pf(0);

// accessing the new field with the loop index k
// and putting the previous read value into this new place
pf[k] = ps[faceNumber]
2) What is the code for the faceCenter coordinate?
I have tried
Code:
ps.Cf()[k]
but this doesn't seem to be right?
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 20, 2009, 08:05
Default
  #6
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
Dear Sebastian,

Quote:
I assume "points" is the name of the variable containing the coordinates, while outputs the file?
C++ variable names are never enclosed in brackets!

"points" is the name of the file at the other end of that OFstream (os). pnts is the name of the variable to be output to this stream (or file).

@1) There is a DynamicList container in OF, but I suggest you allocate the memory and then fill the array because you know how long the Field will be.

Code:
vectorField pnts(facesSet.size());
scalarField data(facesSet.size());
The good thing about map in the third exaple is that it will do the resizing for you.

@2) Try mesh.Cf()()[k]

Quote:
I already have a way of accessing the field data of interest.
Are you sure?

Henrik
henrik is offline   Reply With Quote

Old   July 20, 2009, 08:34
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
Quote:
Originally Posted by henrik View Post
Try mesh.Cf()()[k]
Code:
Info<< "Cf(): "<< mesh.Cf()()[k] << endl;
Leads to this message while compiling:

Code:
error: no match for call to ‘(const Foam::GeometricField<Foam::Vector<double>, Foam::fvsPatchField, Foam::surfaceMesh>) ()’
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 20, 2009, 08:39
Default
  #8
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 henrik View Post
"points" is the name of the file at the other end of that OFstream (os). pnts is the name of the variable to be output to this stream (or file).
Looks like this is working, but
Code:
        OFstream os ("p");
        os << faceCenterPressure;
Just gives me a single file in the case directory, which is overwritten at each timestep.

How can I manage to put it inside of separate subdirectory, which contains also the time step name?!


Something like
Code:
     OFstream os("data/" + runTime.timeName() + "/p")
didn't work out which means there is no file written.
Maybe the runTime.timeName() has to be rewritten into a string?!
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 20, 2009, 08:49
Default
  #9
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
You are on the right track, but you need to create the directory structure.

$FOAM_SRC/postProcessing/forces/forces/forces.C

Henrik
henrik is offline   Reply With Quote

Old   July 20, 2009, 08:54
Default
  #10
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
And what was the error message for mesh.Cf()[k]?
henrik is offline   Reply With Quote

Old   July 20, 2009, 09:07
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 henrik View Post
And what was the error message for mesh.Cf()[k]?
There is none. Maybe there was something else wrong.
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 21, 2009, 13:57
Default
  #12
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 henrik View Post
You are on the right track, but you need to create the directory structure.

$FOAM_SRC/postProcessing/forces/forces/forces.C

Henrik
Ok Henrik.
I had a look into the forces.C file, but in spite of thinking I got it, I didn't.

I'm not able to handle the expression for the directory structure.

Code:
fileName directoryP = "/data/"runTime.timeName()"/p";
is my best guess, which is not working
Code:
error: expected ‘,’ or ‘;’ before ‘runTime’
even with a comma before and/or after...

What may be wrong?
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 21, 2009, 14:09
Default
  #13
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
Sebastian,

the "/"-operators are overloaded for fileName. So

Code:
fileName directoryP = runTime.timeName()/p;
is NOT a division, but will - on a single processor run - yield something like

[case_dir]/[time]/p

which is close to what you are looking for.

Henrik
henrik is offline   Reply With Quote

Old   July 21, 2009, 16:36
Default
  #14
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 henrik View Post
yield something like

[case_dir]/[time]/p
Unfortunately not. This exact statement outputs the attached message while compiling.

What if I want to add some directory before the time-step name?
Something like

[Case-Dir]/data/0.01/p

so the written file will not interfere with the actual timesteps...
Attached Files
File Type: txt wmakeoutput.txt (5.8 KB, 9 views)
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 21, 2009, 16:48
Arrow
  #15
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
Sebastian,

you had too many and I was missing some . Very foamish error message, thus . Let's settle for a compromise

Code:
fileName directoryP = runTime.path()/"data"/runTime.time()/"p";
Make sure to create the directory!

Henrik
henrik is offline   Reply With Quote

Old   July 21, 2009, 17:08
Default
  #16
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 henrik View Post

Code:
fileName directoryP = runTime.path()/"data"/runTime.time()/"p";
Nope.
Code:
error: no match for ‘operator/’ in ‘Foam::operator/(const Foam::string&, const Foam::string&)(((const Foam::string&)(& Foam::string(((const char*)"data"))))) / runTime.Foam::Time::<anonymous>.Foam::objectRegistry::time()’
I think we should reconsider in the morning ...
Attached Files
File Type: txt wmakeoutput.txt (6.0 KB, 4 views)
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 21, 2009, 18:10
Default
  #17
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
Yes, indeed:

Code:
fileName directoryP = runTime.path()/"data"/runTime.timeName()/"p";
henrik is offline   Reply With Quote

Old   July 22, 2009, 02:21
Default
  #18
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 its working!
Great work!

Tell me, is this basic C++ or OpenFOAM related knowledge?
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!"
sega is offline   Reply With Quote

Old   July 22, 2009, 02:43
Default
  #19
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
If you don't mind I will draw you attention to my post about file headers, which is connected to the matters discussed here:
http://www.cfd-online.com/Forums/ope...tml#post223590
__________________
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:16
Default
  #20
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
Sebastian,

first of all, I have the feeling, that the error messages make little sense to you. Maybe you could go back, break this code and analyse the error messages.

Have a look into forces.C again. In fact, this statement looks very similar to what you where looking for.
Code:
forcesDir = obr_.time().path()/name_/obr_.time().timeName();
Ask yourself, what went wrong when I modified it to
Code:
fileName directoryP = "/data/"runTime.timeName()"/p";
Where are the operators?

The next problem, and you are not alone, is how to find your way in the library. There are many options. For example Doxygen or you can try:
Code:
egrep \:\:timeName $FOAM_SRC/OpenFOAM/lnInclude/*
This outputs a little more than you need, but try and find the function's declaration and the associated code.

Henrik
henrik is offline   Reply With Quote

Reply

Tags
fields, points, sample


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
TimeVaryingMappedFixedValue best practice to extract subset points and fields podallaire OpenFOAM Running, Solving & CFD 6 May 21, 2014 10:25
Field interpolation in mesh points code jzlam OpenFOAM Post-Processing 2 December 14, 2010 16:48
Morphing deforming surface mesh depend on some sensitivity field sponiar OpenFOAM Running, Solving & CFD 3 August 12, 2008 13:32
Different dimensions for FATAL ERROR retech OpenFOAM Running, Solving & CFD 2 August 14, 2007 10:17
Parallel LES computation stops with reason vvqf OpenFOAM Running, Solving & CFD 4 March 6, 2006 07:55


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