CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

How to write a vector for each timestep

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree6Likes
  • 1 Post By niaz
  • 1 Post By niaz
  • 4 Post By bigphil

Reply
 
LinkBack Thread Tools Display Modes
Old   July 20, 2012, 08:48
Question How to write a vector for each timestep
  #1
Member
 
Stefano
Join Date: Jul 2009
Posts: 34
Rep Power: 8
Whyman is on a distinguished road
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
Whyman is offline   Reply With Quote

Old   July 20, 2012, 09:04
Default
  #2
Senior Member
 
niaz's Avatar
 
A_R
Join Date: Jun 2009
Posts: 118
Rep Power: 8
niaz is on a distinguished road
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?
niaz is offline   Reply With Quote

Old   July 20, 2012, 09:12
Default
  #3
Member
 
Stefano
Join Date: Jul 2009
Posts: 34
Rep Power: 8
Whyman is on a distinguished road
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?
Whyman is offline   Reply With Quote

Old   July 20, 2012, 09:32
Default
  #4
Senior Member
 
niaz's Avatar
 
A_R
Join Date: Jun 2009
Posts: 118
Rep Power: 8
niaz is on a distinguished road
Dear stefano
just write your consul by command like this
icoFoam > stefano.txt
then use grep command to separate your line from others.
mm.abdollahzadeh likes this.
niaz is offline   Reply With Quote

Old   July 20, 2012, 09:42
Default
  #5
Member
 
Stefano
Join Date: Jul 2009
Posts: 34
Rep Power: 8
Whyman is on a distinguished road
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
Whyman is offline   Reply With Quote

Old   July 20, 2012, 10:04
Default
  #6
Senior Member
 
niaz's Avatar
 
A_R
Join Date: Jun 2009
Posts: 118
Rep Power: 8
niaz is on a distinguished road
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
mm.abdollahzadeh likes this.
niaz is offline   Reply With Quote

Old   July 20, 2012, 12:00
Default
  #7
Senior Member
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 570
Rep Power: 19
bigphil will become famous soon enoughbigphil will become famous soon enough
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
Then put this before the time loop:
Code:
OFstream myFile("myData.txt");
Then put this inside the time loop where ever you want to do your calculation:
Code:
vector someVector(1,2,3);

myFile << "data for time " << runTime.value() << " is " << someVector << endl;
Best regards,
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 12:04. Reason: Mention parallel stuff
bigphil is offline   Reply With Quote

Old   April 20, 2015, 09:34
Post
  #8
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
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.
Attached Images
File Type: jpg Screenshot from 2015-04-20 18:31:19.jpg (50.1 KB, 7 views)
13msmemusman is offline   Reply With Quote

Reply

Tags
vector

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Restart 2-way FSI with different timestep? Lance CFX 11 April 17, 2013 00:37
Timestep and Pressure Correction Relationship in SIMPLE rks171 Main CFD Forum 23 May 4, 2012 01:04
mesh file for flow over a circular cylinder Ardalan Main CFD Forum 6 April 17, 2010 23:40
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


All times are GMT -4. The time now is 21:18.