![]() |
How to create points and field files?
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);Does anybody know, how this can be done? |
Sebastian,
I think you intended to do something like Code:
for (label k=0; k<facesSet.size(); k++)Code:
forAllConstIter(faceSet, facesSet, f)Code:
const labelList faces = facesSet.toc();Code:
scalarField data(0);Henrik |
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. |
Dear Sebastian,
Code:
OFstream os ("points"); |
Quote:
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 fieldI have tried Code:
ps.Cf()[k] |
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());@2) Try mesh.Cf()()[k] Quote:
Henrik |
Quote:
Code:
Info<< "Cf(): "<< mesh.Cf()()[k] << endl;Code:
error: no match for call to ‘(const Foam::GeometricField<Foam::Vector<double>, Foam::fvsPatchField, Foam::surfaceMesh>) ()’ |
Quote:
Code:
OFstream os ("p");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?! |
You are on the right track, but you need to create the directory structure.
$FOAM_SRC/postProcessing/forces/forces/forces.C Henrik |
And what was the error message for mesh.Cf()[k]?
|
Quote:
|
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? |
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 |
1 Attachment(s)
Quote:
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... |
Sebastian,
you had too many and I was missing some :). Very foamish error message, thus :D. Let's settle for a compromise ;) Code:
fileName directoryP = runTime.path()/"data"/runTime.time()/"p";Henrik |
1 Attachment(s)
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()’ |
Yes, indeed:
Code:
fileName directoryP = runTime.path()/"data"/runTime.timeName()/"p"; |
Yes its working!
Great work! Tell me, is this basic C++ or OpenFOAM related knowledge? |
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 |
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 |
| All times are GMT -4. The time now is 14:20. |