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

Display center of mass with mesh

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

Like Tree1Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   April 11, 2015, 13:10
Post Display center of mass with mesh
  #1
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
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????
13msmemusman is offline   Reply With Quote

Old   April 18, 2015, 16:07
Default
  #2
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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:
  1. Go to the menu "Sources".
  2. Choose the entry "Sphere".
  3. Define the position you have gotten from the simulation.
  4. Click in the "Apply" button.
  5. Adjust the sphere radius according to the dimension you need.
  6. Click on the "Apply" button again.
  7. Repeat as needed.
wyldckat is offline   Reply With Quote

Old   April 18, 2015, 21:48
Post
  #3
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
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.......
13msmemusman is offline   Reply With Quote

Old   April 19, 2015, 10:49
Default
  #4
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Quote:
Originally Posted by 13msmemusman View Post
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!
wyldckat is offline   Reply With Quote

Old   April 19, 2015, 12:14
Post
  #5
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
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.
13msmemusman is offline   Reply With Quote

Old   April 19, 2015, 12:53
Default
  #6
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Quick answer:
  1. For writing to a text file, see http://www.cfd-online.com/Forums/ope...tml#post372637 - post #7
  2. You should write in CSV format: http://en.wikipedia.org/wiki/Comma-separated_values
  3. For showing the values in ParaView, you need to:
    1. Open the CSV file in ParaView.
    2. Configure the settings for loading the data from CSV.
    3. Use the filter "Table to Points".
    4. 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"
wyldckat is offline   Reply With Quote

Old   April 19, 2015, 12:55
Default
  #7
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
Thank you sir. these things are quite informative. i like that. thanks you again
13msmemusman is offline   Reply With Quote

Old   April 19, 2015, 13:00
Default
  #8
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
sir you forget to write after (and here). The link needed
13msmemusman is offline   Reply With Quote

Old   April 19, 2015, 13:43
Default
  #9
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Quote:
Originally Posted by 13msmemusman View Post
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/
wyldckat is offline   Reply With Quote

Old   April 20, 2015, 09:33
Post
  #10
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, 10 views)
13msmemusman is offline   Reply With Quote

Old   April 26, 2015, 15:40
Default
  #11
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Hi 13msmemusman,

The following took me some considerable time to program.

Steps to use:
  1. In ParaView (I tested this in ParaView 4.1.0), select from the menu "Sources" the "Programmable Source".
  2. 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.
  3. 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.
wyldckat is offline   Reply With Quote

Old   April 27, 2015, 12:43
Post
  #12
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
thank you sir you did so much for me. but there is an error.

Code:
Traceback (most recent call last):
   File "<string>", line 20, in <module>
   File "<string>", 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
13msmemusman is offline   Reply With Quote

Old   April 27, 2015, 15:07
Default
  #13
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Hi Muhammad,

Looks like "numpy" isn't installed. A few questions:
  1. Which Linux Distribution are you using?
  2. Which installation instructions did you follow for installing OpenFOAM and ParaView?
Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   April 28, 2015, 11:32
Post
  #14
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
Sir now i have installed numpy and now error is
Code:
not defined
 Traceback (most recent call last):
   File "<string>", line 20, in <module>
   File "<string>", 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
13msmemusman is offline   Reply With Quote

Old   April 29, 2015, 01:50
Post
  #15
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
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
13msmemusman is offline   Reply With Quote

Old   May 3, 2015, 09:46
Default
  #16
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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
File Type: jpg Configuring the source.jpg (37.7 KB, 5 views)
File Type: jpg Configuring the Glyph.jpg (32.5 KB, 6 views)
wyldckat is offline   Reply With Quote

Old   May 3, 2015, 09:50
Default
  #17
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
Sir i am using it in interFoam.... let me try again....
13msmemusman is offline   Reply With Quote

Old   May 3, 2015, 10:01
Post
  #18
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
p, li { white-space: pre-wrap; } not defined
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "<string>", 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
13msmemusman is offline   Reply With Quote

Old   May 3, 2015, 11:12
Post
  #19
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 67
Rep Power: 3
13msmemusman is on a distinguished road
Thank you boss..... i have also done it successfully
13msmemusman is offline   Reply With Quote

Old   May 3, 2015, 11:26
Default
  #20
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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
File Type: png Path that needs to be changed.png (19.5 KB, 3 views)
Attached Files
File Type: gz cavity.tar.gz (13.4 KB, 0 views)
wyldckat is offline   Reply With Quote

Reply

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
Difficulty in calculating angular velocity of Savonius turbine simulation alfaruk CFX 8 December 3, 2013 17:51
Layers:problem with curvature giulio.topazio OpenFOAM Native Meshers: snappyHexMesh and Others 10 August 22, 2012 09:03
external flow with snappyHexMesh chelvistero OpenFOAM 11 January 15, 2010 20:43
fluent add additional zones for the mesh file SSL FLUENT 2 January 26, 2008 12:55
center of mass for naca airfoil frederic Felten Main CFD Forum 3 February 20, 2002 12:55


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