How to write a vector for each timestep
Hi foamers!
I have a question. I would like to write a dimensioned vector (the center of mass of the liquid) for each timestep that I save. How can I write the command line? Thank you Stefano |
Dear Stefano
your case is vague. you said that you have saved it. now, you want to write it? how you can saved it, without writing? |
Dear Niaz,
I would like to save on a file the value of the centre of mass (CoM) of a liquid contained in an oscillating tank. The case is unsteady, so i would like to save the vector every timestep, in order to check the time evolution. Up to now i can write the vector only on the terminal. Now i would like to save it on a file. What command line have I to write on the source code? |
Dear stefano
just write your consul by command like this icoFoam > stefano.txt then use grep command to separate your line from others. |
Niaz,
I already do this, but I would like to avoid all these passages and directly write on file by using the source code. Isn't there any other way to directly write a dimensioned vector on file, for each timestep? Stefano |
you should use pstream to do that
you can look fieldminmax as sample to create your functionobject. it is a bit hard but the sample may help you |
Hi Stefano,
If you would like to save some data to a file during your simulation, you could do something like this: Put this at the top of your file under "#include "fvCFD.H": Code:
#include "OFstream.H Code:
OFstream myFile("myData.txt"); Code:
vector someVector(1,2,3); Philip By the way, the above code is for serial simulations. For parallel simulations, it must be edited so as processors do not write to the same file. |
1 Attachment(s)
Sir i tried to do as you said. but the problem is that it shows all sphares at a time. i want to watch center of mass moving at runtime. but the method you specified gives all locations of center of mass at a time.
i am attaching the image with this thread. |
Quote:
Hi Philip, Your comment helped me a lot :) I edited my solver to write a vector into a file in each time step without considering that I am going to run it parallel. And every time I run the program the vector has been repeated 8 time. Now I know it's because I have run using 8 cores. Do you know how to fix it? I am going to look into the forces.C file to see how they have overcome this when they write the forces data into a dat file. Thanks, Methma |
Quote:
For parallel, the information should be sent to one processor and it should be the only processor to write to the file. Here is an example: At the start of the program, just the master processor should open the file: Code:
OFstream* myOutFilePtr = NULL; Code:
// Data on the current processor Philip |
Thank you very much Philip.
|
All times are GMT -4. The time now is 08:44. |