# Display center of mass with mesh

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

 LinkBack Thread Tools Display Modes
 April 11, 2015, 13:10 Display center of mass with mesh #1 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 Hye please help me i solved center of mass in (x,y,z) format now i want to watch it in paraFoam. anyone knows something about it????

 April 18, 2015, 16:07 #2 Super Moderator   Bruno Santos Join Date: Mar 2009 Location: Lisbon, Portugal Posts: 8,258 Blog Entries: 34 Rep Power: 84 Quick answer: Please provide more details, as explained here: How to give enough info to get help Because the simplest answer is this - In ParaView, you should: Go to the menu "Sources". Choose the entry "Sphere". Define the position you have gotten from the simulation. Click in the "Apply" button. Adjust the sphere radius according to the dimension you need. Click on the "Apply" button again. Repeat as needed.

 April 18, 2015, 21:48 #3 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 But sir problem is that value of center of mass is changing contonously with runtime. Thats why i want to make some change in solver to see center of mass. please help me if you can.......

April 19, 2015, 10:49
#4
Super Moderator

Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
Quote:
 Originally Posted by 13msmemusman please help me if you can.......
I or anyone else can help you, but only if you provide more details! Keep in mind that your question is too generic and we are not able to see what you are seeing.
At the very least, provide an example file of the data you want to plot and see in ParaView!

 April 19, 2015, 12:14 #5 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 Actually sir, just think about damBreak case..... In interFoam case i added CoM = sum(rho*mesh.V()*mesh.C().dimensionedInternalField ())/sum(rho*mesh.V()); and defined CoM as a vector dimensionedVector CoM("CoM", dimLength, vector::zero); now it gives me center of mass of fluid suppose in dambreak case. But it gives me in log file. in form of Vector (a,b,c). Value of center of mass of fluid changes with movement of fluid in paraFoam. I want to watch position of center of mass at every time step. so i want position of center of mass in mesh.

 April 19, 2015, 12:53 #6 Super Moderator   Bruno Santos Join Date: Mar 2009 Location: Lisbon, Portugal Posts: 8,258 Blog Entries: 34 Rep Power: 84 Quick answer: For writing to a text file, see http://www.cfd-online.com/Forums/ope...tml#post372637 - post #7 You should write in CSV format: http://en.wikipedia.org/wiki/Comma-separated_valuesI already know you're going to ask more about that, and it's already (a bit) explained here: http://stackoverflow.com/questions/2...v-files-from-c For showing the values in ParaView, you need to:Open the CSV file in ParaView. Configure the settings for loading the data from CSV. Use the filter "Table to Points". Then use the filter Glyph and choose Sphere instead of Arrow. Beyond this, I strongly suggest you read the ParaView User Guide, because I don't have enough time this week to go into more details. Good luck! Last edited by wyldckat; April 19, 2015 at 13:41. Reason: Removed "and here"

 April 19, 2015, 12:55 #7 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 Thank you sir. these things are quite informative. i like that. thanks you again

 April 19, 2015, 13:00 #8 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 sir you forget to write after (and here). The link needed

April 19, 2015, 13:43
#9
Super Moderator

Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
Quote:
 Originally Posted by 13msmemusman sir you forget to write after (and here). The link needed
Sorry, I actually forgot to remove the initial text for the 2nd reference "and here", because after searching for a while, I didn't find any good example. It's one of those so very simple coding exercises, that should be already present in one or more C++ tutorials. For example: http://www.cplusplus.com/doc/tutorial/files/

April 20, 2015, 09:33
#10
Member

Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
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
 Screenshot from 2015-04-20 18:31:19.jpg (50.1 KB, 10 views)

 April 26, 2015, 15:40 #11 Super Moderator   Bruno Santos Join Date: Mar 2009 Location: Lisbon, Portugal Posts: 8,258 Blog Entries: 34 Rep Power: 84 Hi 13msmemusman, The following took me some considerable time to program. Steps to use: In ParaView (I tested this in ParaView 4.1.0), select from the menu "Sources" the "Programmable Source". It now shows at least 3 options, which should be populated as follows:Output Data Set Type: vtkPolyData Script: Code: ```theCSVfile="test.csv" from paraview import vtk import numpy as np global arrayT, arrayX, arrayY, arrayZ def GetUpdateTimestep(algorithm): """Returns the requested time value, or None if not present""" executive = algorithm.GetExecutive() outInfo = executive.GetOutputInformation(0) if not outInfo.Has(executive.UPDATE_TIME_STEP()): return None return outInfo.Get(executive.UPDATE_TIME_STEP()) # This is the requested time-step. req_time = GetUpdateTimestep(self) try: if len(arrayT) == 0: print "arrayT is empty" except NameError: print "not defined" data = np.genfromtxt(theCSVfile, dtype=None, names=True, delimiter=',', autostrip=True) arrayT = data["Time"] arrayX = data["X"] arrayY = data["Y"] arrayZ = data["Z"] pts = vtk.vtkPoints() pdo = self.GetOutput() for i in range(0, len(arrayT)-1): if arrayT[i] <= req_time and req_time < arrayT[i+1]: pts.InsertNextPoint(arrayX[i], arrayY[i], arrayZ[i]) if req_time < arrayT[0]: pts.InsertNextPoint(arrayX[0], arrayY[0], arrayZ[0]) elif arrayT[-1] <= req_time: pts.InsertNextPoint(arrayX[-1], arrayY[-1], arrayZ[-1]) pdo.SetPoints(pts)``` Note: Change the first line to use your file name (and possibly full path as well), instead of using "test.csv". Script (Request Information): Code: ```def SetOutputTimesteps(algorithm, timesteps): executive = algorithm.GetExecutive() outInfo = executive.GetOutputInformation(0) outInfo.Remove(executive.TIME_STEPS()) for timestep in timesteps: outInfo.Append(executive.TIME_STEPS(), timestep) outInfo.Remove(executive.TIME_RANGE()) outInfo.Append(executive.TIME_RANGE(), timesteps[0]) outInfo.Append(executive.TIME_RANGE(), timesteps[-1]) SetOutputTimesteps(self, (0, 1))``` Note: This is only here as a code that will force ParaView to always update this item. Now you can click on the "Apply" button and it should work as intended. Note: The actual time limits should be given by the OpenFOAM case (i.e. with the "case.OpenFOAM" file open in ParaView). If not, you will have to change the settings in the menu: View -> Animation View. My test file "test.csv" contains this: Code: ```Time, X, Y, Z 0, 0, 0, 0 1, 0.1, 0.2, 0.3 2, 0.2, 0.3, 0.4``` Best regards, Bruno PS: I wrote this code based on the examples given here: 13msmemusman likes this. __________________ OpenFOAM: Frequently Asked Questions | Useful links for building and using Forum: How to ask for help | Posting code and output with [CODE] When will I answer questions? Check this page for dates: http://wyldckat.github.io And please: Read this before sending private messages to me

 April 27, 2015, 12:43 #12 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 thank you sir you did so much for me. but there is an error. Code: ```Traceback (most recent call last): File "", line 20, in File "", line 5, in RequestData ImportError: No module named numpy``` sir i have zero knowledge of python. please help me Last edited by wyldckat; April 27, 2015 at 15:06. Reason: Added [CODE][/CODE] markers

 April 27, 2015, 15:07 #13 Super Moderator   Bruno Santos Join Date: Mar 2009 Location: Lisbon, Portugal Posts: 8,258 Blog Entries: 34 Rep Power: 84 Hi Muhammad, Looks like "numpy" isn't installed. A few questions: Which Linux Distribution are you using? Which installation instructions did you follow for installing OpenFOAM and ParaView? Best regards, Bruno

 April 28, 2015, 11:32 #14 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 Sir now i have installed numpy and now error is Code: ```not defined Traceback (most recent call last): File "", line 20, in File "", line 28, in RequestData ValueError: field named Time not found``` This is ubuntu 14 and openfoam 2.3.1 and paraFoam 4.1.0 i followed instructions by openfoam.org Last edited by wyldckat; April 30, 2015 at 11:28. Reason: Added [CODE][/CODE] markers

 April 29, 2015, 01:50 #15 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 there was problem in file format. i have corrected. but still i have a problem. i doesn't give me error but it don't show me center of mass

May 3, 2015, 09:46
#16
Super Moderator

Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
Attached are two images, tested with the tutorial case "incompressible/icoFoam/cavity":
1. "Configuring the source.png" shows how the programmable source item is configured for reading the file named "test.csv".
2. "Configuring the Glyph.png" shows how to configure the Glyph filter that is applied to the programmable source entry.
• Note: You might need to either increase the radius size of the sphere or decrease it, depending on the geometrical dimensions of your case.
Beyond this, I'm not able to help you if you don't provide images of what you're seeing and a sample of the CSV file you're using.
Attached Images
 Configuring the source.jpg (37.7 KB, 5 views) Configuring the Glyph.jpg (32.5 KB, 6 views)

 May 3, 2015, 09:50 #17 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 Sir i am using it in interFoam.... let me try again....

 May 3, 2015, 10:01 #18 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 p, li { white-space: pre-wrap; } not defined Traceback (most recent call last): File "", line 20, in File "", line 28, in RequestData ValueError: field named Time not found Error sir.... please save the state in paraFoam and send me at 13msmemusman@smme.edu.pk

 May 3, 2015, 11:12 #19 Member   Muhammad Usman Join Date: Feb 2014 Posts: 67 Rep Power: 3 Thank you boss..... i have also done it successfully

May 3, 2015, 11:26
#20
Super Moderator

Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
Attached is a complete example case, which is the "cavity" I mentioned before case.
Unpack it and then run:
Code:
```./Allrun
pwd
paraview```
Then you can open the state file in ParaView.

When you open it, it will show a window similar to the attached image. You'll need to change the path to the folder given in the second command.
Attached Images
 Path that needs to be changed.png (19.5 KB, 3 views)
Attached Files
 cavity.tar.gz (13.4 KB, 0 views)

 Thread Tools Display Modes Linear Mode

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

 Similar Threads Thread Thread Starter Forum Replies Last Post alfaruk CFX 8 December 3, 2013 17:51 giulio.topazio OpenFOAM Native Meshers: snappyHexMesh and Others 10 August 22, 2012 09:03 chelvistero OpenFOAM 11 January 15, 2010 20:43 SSL FLUENT 2 January 26, 2008 12:55 frederic Felten Main CFD Forum 3 February 20, 2002 12:55

All times are GMT -4. The time now is 23:35.

 Contact Us - CFD Online - Top