CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Visualization & Post-Processing Software > ParaView

[OpenFOAM] Display center of mass with mesh

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 11, 2015, 14:10
Post Display center of mass with mesh
  #1
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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, 17:07
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer: Please provide more details, as explained here: http://www.cfd-online.com/Forums/ope...-get-help.html

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, 22:48
Post
  #3
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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, 11:49
Default
  #4
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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, 13:14
Post
  #5
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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, 13:53
Default
  #6
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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 14:41. Reason: Removed "and here"
wyldckat is offline   Reply With Quote

Old   April 19, 2015, 13:55
Default
  #7
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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, 14:00
Default
  #8
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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, 14:43
Default
  #9
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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, 10:33
Post
  #10
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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, 70 views)
13msmemusman is offline   Reply With Quote

Old   April 26, 2015, 16:40
Default
  #11
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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, 13:43
Post
  #12
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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 16:06. Reason: Added [CODE][/CODE] markers
13msmemusman is offline   Reply With Quote

Old   April 27, 2015, 16:07
Default
  #13
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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, 12:32
Post
  #14
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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 12:28. Reason: Added [CODE][/CODE] markers
13msmemusman is offline   Reply With Quote

Old   April 29, 2015, 02:50
Post
  #15
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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, 10:46
Default
  #16
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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, 46 views)
File Type: jpg Configuring the Glyph.jpg (32.5 KB, 32 views)
wyldckat is offline   Reply With Quote

Old   May 3, 2015, 10:50
Default
  #17
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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, 11:01
Post
  #18
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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, 12:12
Post
  #19
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
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, 12:26
Default
  #20
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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, 36 views)
Attached Files
File Type: gz cavity.tar.gz (13.4 KB, 17 views)
wyldckat is offline   Reply With Quote

Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
decomposePar problem: Cell 0contains face labels out of range vaina74 OpenFOAM Pre-Processing 37 July 20, 2020 06:38
Prescribed Translating Cylinder Mesh for Added Mass Problem (Transient FSI) Lloyd Sullivan CFX 5 August 7, 2018 09:11
Gambit problems Althea FLUENT 22 January 4, 2017 04:19
Star CCM Overset Mesh Error (Rotating Turbine) thezack Siemens 7 October 12, 2016 12:14
How to control Minximum mesh space? hung FLUENT 7 April 18, 2005 10:38


All times are GMT -4. The time now is 05:17.