|
[Sponsors] |
July 19, 2009, 11:53 |
How to create points and field files?
|
#1 |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
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
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; }; Does anybody know, how this can be done?
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!" |
|
July 19, 2009, 15:34 |
|
#2 |
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
Sebastian,
I think you intended to do something like Code:
for (label k=0; k<facesSet.size(); k++) { label faceNumber = facesSet[k]; // copy data } Code:
forAllConstIter(faceSet, facesSet, f) { label faceNumber = f.key(); // copy data } Code:
const labelList faces = facesSet.toc(); for (label k=0; k<faces.size(); k++) { label faceNumber = faces[k]; // copy data } Code:
scalarField data(0); vectorField pnts(0); const labelList faces = facesSet.toc(); data.map(ps, faces); pnts.map(mesh.Cf(), faces); Henrik Last edited by henrik; July 20, 2009 at 08:48. |
|
July 19, 2009, 18:08 |
|
#3 |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
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!" |
|
July 19, 2009, 19:12 |
|
#4 |
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
Dear Sebastian,
Code:
OFstream os ("points"); os << pnts; |
|
July 20, 2009, 08:38 |
|
#5 |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
Hi Henrik.
I assume "points" is the name of the variable containing the coordinates, while Code:
os << pnts; 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] I have tried Code:
ps.Cf()[k]
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!" |
|
July 20, 2009, 09:05 |
|
#6 | ||
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
Dear Sebastian,
Quote:
"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()); @2) Try mesh.Cf()()[k] Quote:
Henrik |
|||
July 20, 2009, 09:34 |
|
#7 |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
Code:
Info<< "Cf(): "<< mesh.Cf()()[k] << endl; 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!" |
|
July 20, 2009, 09:39 |
|
#8 | |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
Quote:
Code:
OFstream os ("p"); os << faceCenterPressure; 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") 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!" |
||
July 20, 2009, 09:49 |
|
#9 |
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
You are on the right track, but you need to create the directory structure.
$FOAM_SRC/postProcessing/forces/forces/forces.C Henrik |
|
July 20, 2009, 09:54 |
|
#10 |
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
And what was the error message for mesh.Cf()[k]?
|
|
July 20, 2009, 10:07 |
|
#11 |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
There is none. Maybe there was something else wrong.
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!" |
|
July 21, 2009, 14:57 |
|
#12 | |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
Quote:
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"; Code:
error: expected ‘,’ or ‘;’ before ‘runTime’ What may be wrong?
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!" |
||
July 21, 2009, 15:09 |
|
#13 |
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
Sebastian,
the "/"-operators are overloaded for fileName. So Code:
fileName directoryP = runTime.timeName()/p; [case_dir]/[time]/p which is close to what you are looking for. Henrik |
|
July 21, 2009, 17:36 |
|
#14 |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
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...
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!" |
|
July 21, 2009, 17:48 |
|
#15 |
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
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"; Henrik |
|
July 21, 2009, 18:08 |
|
#16 | |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
Quote:
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()’
__________________
Schrödingers wife: "What did you do to the cat? It's half dead!" |
||
July 21, 2009, 19:10 |
|
#17 |
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
Yes, indeed:
Code:
fileName directoryP = runTime.path()/"data"/runTime.timeName()/"p"; |
|
July 22, 2009, 03:21 |
|
#18 |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
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!" |
|
July 22, 2009, 03:43 |
|
#19 |
Senior Member
Sebastian Gatzka
Join Date: Mar 2009
Location: Frankfurt, Germany
Posts: 729
Rep Power: 20 |
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!" |
|
July 22, 2009, 04:16 |
|
#20 |
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
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(); Code:
fileName directoryP = "/data/"runTime.timeName()"/p"; 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/* Henrik |
|
Tags |
fields, points, sample |
|
|
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 11:25 |
Field interpolation in mesh points code | jzlam | OpenFOAM Post-Processing | 2 | December 14, 2010 17:48 |
Morphing deforming surface mesh depend on some sensitivity field | sponiar | OpenFOAM Running, Solving & CFD | 3 | August 12, 2008 14:32 |
Different dimensions for FATAL ERROR | retech | OpenFOAM Running, Solving & CFD | 2 | August 14, 2007 11:17 |
Parallel LES computation stops with reason | vvqf | OpenFOAM Running, Solving & CFD | 4 | March 6, 2006 08:55 |