|
[Sponsors] |
July 20, 2012, 09:48 |
How to write a vector for each timestep
|
#1 |
Member
Stefano
Join Date: Jul 2009
Posts: 36
Rep Power: 17 |
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 |
|
July 20, 2012, 10:04 |
|
#2 |
Senior Member
A_R
Join Date: Jun 2009
Posts: 122
Rep Power: 17 |
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? |
|
July 20, 2012, 10:12 |
|
#3 |
Member
Stefano
Join Date: Jul 2009
Posts: 36
Rep Power: 17 |
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? |
|
July 20, 2012, 10:32 |
|
#4 |
Senior Member
A_R
Join Date: Jun 2009
Posts: 122
Rep Power: 17 |
Dear stefano
just write your consul by command like this icoFoam > stefano.txt then use grep command to separate your line from others. |
|
July 20, 2012, 10:42 |
|
#5 |
Member
Stefano
Join Date: Jul 2009
Posts: 36
Rep Power: 17 |
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 |
|
July 20, 2012, 11:04 |
|
#6 |
Senior Member
A_R
Join Date: Jun 2009
Posts: 122
Rep Power: 17 |
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 |
|
July 20, 2012, 13:00 |
|
#7 |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,097
Rep Power: 34 |
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); myFile << "data for time " << runTime.value() << " is " << someVector << endl; 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. Last edited by bigphil; July 20, 2012 at 13:04. Reason: Mention parallel stuff |
|
April 20, 2015, 10:34 |
|
#8 |
Member
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0 |
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. |
|
November 5, 2015, 22:09 |
|
#9 | |
Member
methma Rajamuni
Join Date: Jul 2015
Location: Victoria, Australia
Posts: 40
Rep Power: 11 |
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 |
||
November 12, 2015, 13:33 |
|
#10 | |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,097
Rep Power: 34 |
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; if (Pstream::master()) { // Open the file myOutFilePtr = new OFstream("myFile.txt"); } Code:
// Data on the current processor scalar myLocalData = 2; // Sync data to the master (in this, I will get the max) reduce(myLocalData, maxOp<scalar>()); // Now myLocalData contains the global max i.e. the max on all processors // We will now get the master to write to the file if (Pstream::master()) { OFstream& myOutFile = *myOutFilePtr; myOutFile << "The data is " << myLocalData << ends; } Philip |
||
November 15, 2015, 19:49 |
|
#11 |
Member
methma Rajamuni
Join Date: Jul 2015
Location: Victoria, Australia
Posts: 40
Rep Power: 11 |
Thank you very much Philip.
|
|
Tags |
vector |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
mesh file for flow over a circular cylinder | Ardalan | Main CFD Forum | 7 | December 15, 2020 14:06 |
Restart 2-way FSI with different timestep? | Lance | CFX | 10 | April 17, 2013 01:37 |
Timestep and Pressure Correction Relationship in SIMPLE | rks171 | Main CFD Forum | 23 | May 4, 2012 02:04 |
Phase locked average in run time | panara | OpenFOAM | 2 | February 20, 2008 15:37 |
write a xy data file every timestep | pieter brodeoux | FLUENT | 1 | December 5, 2007 18:30 |