CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   [OpenFOAM] Display center of mass with mesh (https://www.cfd-online.com/Forums/paraview/151482-display-center-mass-mesh.html)

13msmemusman April 11, 2015 13:10

Display center of mass with mesh
 
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????

wyldckat April 18, 2015 16:07

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.

13msmemusman April 18, 2015 21:48

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.......

wyldckat April 19, 2015 10:49

Quote:

Originally Posted by 13msmemusman (Post 542487)
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!

13msmemusman April 19, 2015 12:14

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.

wyldckat April 19, 2015 12:53

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!

13msmemusman April 19, 2015 12:55

Thank you sir. these things are quite informative. i like that. thanks you again

13msmemusman April 19, 2015 13:00

sir you forget to write after (and here). The link needed

wyldckat April 19, 2015 13:43

Quote:

Originally Posted by 13msmemusman (Post 542570)
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/

13msmemusman April 20, 2015 09:33

1 Attachment(s)
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.

wyldckat April 26, 2015 15:40

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 April 27, 2015 12:43

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

wyldckat April 27, 2015 15:07

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

13msmemusman April 28, 2015 11:32

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

13msmemusman April 29, 2015 01:50

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

wyldckat May 3, 2015 09:46

2 Attachment(s)
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.

13msmemusman May 3, 2015 09:50

Sir i am using it in interFoam.... let me try again....

13msmemusman May 3, 2015 10:01

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 May 3, 2015 11:12

Thank you boss..... i have also done it successfully

wyldckat May 3, 2015 11:26

2 Attachment(s)
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.

13msmemusman May 3, 2015 12:04

Thank you sir it has already been successful. Thanks a lot for this kind help.
Sincerely
Usman

Hale_812 June 12, 2018 20:43

Quote:

Originally Posted by wyldckat (Post 543810)
...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:

My test file "test.csv" contains this:


Dear wyldckat.


I have similar goal of loading datalogger-style time-voltage readings .csv table as time-varying data source.


Surprisingly, ParaView still does not have this fundamental featureж I mean, interpreting time data. Upon searching with Google, I found your post from 2015.


Unfortunately, I am not a programmer, and have little Idea about Paraview Python API, so I can not make your script working on my system.
And my system is ParavView 5.5.0 x64 for Win64, official build.


First, using manuals, I tried tweaking it for time-voltage 2-column data file. But I could create just 2 timesteps, "0" and "1", with wrong values not present in the table.
Then I just tried executing your example with your test-file without change. And got this error message:


Traceback (most recent call last): File "<string>", line 19, in <module>
File "<string>", line 44, in RequestData
NameError: global name 'arrayX' is not defined



Can you please help solving this problem?

Hale_812 June 12, 2018 21:14

Oh, Increadible! I just got an idea why didn't it work with your example.
ParaView 5 can execute Python programmable Source ONLY ONCE! After that, it should be closed and restarted. So weird.


Anyway, I see, your code can load only 2 timesteps "0", and "1" from the whole table.


I tried my table with 770 values from 0 to 7.714910349e-009 s.
And it loaded the final value only. I guess, because it did not find 1s timestep, and obeyed directive "elif arrayT[-1] <= req_time:"


When calling SetOutputTimesteps(self, (0, 7.6147167081e-009)) with 7.6147167081e-009s timestep as an argument, it reads the value for time=0 instead. But the added time is 7.61472e-009.


So, is there a way to import all the timesteps with float-format time data?
And a way of resetting the numpy environment before the script is executed, so I don't have to restart ParaView every time?


All times are GMT -4. The time now is 07:49.