CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   [OpenFOAM] Paraview slice type - cylinder? (https://www.cfd-online.com/Forums/paraview/117815-paraview-slice-type-cylinder.html)

acocic May 15, 2013 12:46

Paraview slice type - cylinder?
 
Hello to everybody,

I computed the flow in axial fan, in one blade passage and I want see the flow structure in meridian section - so I need to make a slice with cylindrical surface over the blades, and then to "flatten" that surface.

Is it possibly to do that in Paraview (paraFoam)? Any help would be more that welcome. Thanks in advance.

Alex.

wyldckat May 18, 2013 14:51

Greetings Alex and welcome to the forum!

It's possible, but it requires two things:
  1. That you are using ParaView 3.12 or 3.14, including the Python capabilities inside ParaView. The reason for this is that in ParaView 3.98, the necessary VTK filter is not present.
  2. That you use the "Programmable Filter" instead of the normal "Slice" filter. The reason for this is because the "Cylinder" is an implicit function that for some reason they forgot to include in ParaView :(
Reference: http://www.paraview.org/pipermail/pa...ry/016019.html

Instructions:
  1. Apply the "Programmable Filter" to the item you want to cut.
  2. Use the following code in the first text edit box:
    Code:

    input = self.GetInputDataObject(0, 0)
    inp_copy = input.NewInstance()
    inp_copy.ShallowCopy(input)
    inp_copy.UnRegister(None)
    cutter = vtk.vtkCutter()
    transf = vtk.vtkTransform()
    transf.RotateX(90)
    cyl = vtk.vtkCylinder()
    cyl.SetCenter(0,0,0)
    cyl.SetRadius(0.4)
    cyl.SetTransform(transf)
    cutter.SetCutFunction(cyl)
    cutter.SetInput(inp_copy)
    cutter.Update()
    self.GetOutputDataObject(0).ShallowCopy(cutter.GetOutputDataObject(0))

  3. Notes on important details:
    • The cylinder is infinite, because it's an implicit function.
    • "cyl.SetRadius(0.4)" - defines the radius.
    • "cyl.SetCenter(0,0,0)" - defines the centre of the cylinder.
    • The transformation is done with these lines of code:
      Code:

      transf = vtk.vtkTransform()
      transf.RotateX(90)

    • If more transformations are needed, see the list of methods here: http://www.vtk.org/doc/release/5.10/...Transform.html
Best regards,
Bruno

acocic May 20, 2013 05:10

Hey Bruno,

It works just perfect!! Thank you very much! By default, I didn't have "Programmable filter" and Python support (I'm using OpenFOAM-1.6-ext and ParaView 3.12.0 which I compiled without Python support, I guess).

I downloaded then Paraview 3.12 again with

wget http://www.paraview.org/files/v3.12/...-x86_64.tar.gz

extract the files, and tried your code with "new" paraview on VTK data which I previously generated with foamToVTK. And then I got perfect cylindrical slice :).

What is left for me is to connect this version of paraview with OpenFOAM, to be called with paraFoam.

Thanks to your other link

http://www.cfd-online.com/Forums/blo...-openfoam.html

it won't be a problem ;)!

Best regards,
Alex.

acocic May 21, 2013 06:31

Hello once again,

I just wanted to add some new insights on this topic. Actually, we don't have to modify paraFoam script, and OpenFOAM bashrc file. This paraView version I mentioned in previous thread supports OpenFOAM files, and you can open files with *.foam extension.

So I just created aliases, something like paraViewWithPython, which points to binary of new paraview. When you start this command in the root of the case, it won't automatically load the case data, but you can open *.foam file which is there, and then use Programmable filter.

Best regards,
Alex.

wyldckat May 21, 2013 17:40

Hi Alex,

You use the following alias:
Code:

alias paraViewWP='touch case.foam && /long/path/to/ParaView-3.12.0/bin/paraview --data=case.foam'
It was based on the one shown here:http://openfoamwiki.net/index.php/Ho...using_ParaView

Best regards,
Bruno

acocic May 22, 2013 02:31

Hi Bruno,

Once again, it works perfect! Now the data are automatically loaded, and Programmable filter & mighty Python support are there!

Thank you once again for all your support and answers!

Best regards,
Alex.

akashjangid June 16, 2013 16:02

Cylindrical Slice in Paraveiw
 
Hello,

I computed the flow through a rotor(Diameter -1m) which is placed inside a wind tunnel.
Now i want to analyze flow at different span length of blades. So for that i need a cylindrical slice.
I am using 3.12.0 ParaVeiw version
I used this code but it does not show any output

input = self.GetInputDataObject(0, 0)
inp_copy = input.NewInstance() inp_copy.ShallowCopy(input)
inp_copy.UnRegister(None)
cutter = vtk.vtkCutter()
transf = vtk.vtkTransform()
transf.RotateX(90)
cyl = vtk.vtkCylinder()
cyl.SetCenter(0,0,0)
cyl.SetRadius(0.4)
cyl.SetTransform(transf)
cutter.SetCutFunction(cyl)
cutter.SetInput(inp_copy)
cutter.Update() self.GetOutputDataObject(0).ShallowCopy(cutter.Get OutputDataObject(0))

Can someone tell me why?
Thanks a lot!!

wyldckat June 16, 2013 16:15

Hi Akash and welcome to the forum!

(I forgot to welcome you to the forum, when I replied to the message you had sent me!)

And thank you for posting your question here!
But there is one big question left unanswered: where exactly in space is your rotor?

Because this code assumes that the rotor is centred in "0,0,0" and its axis is aligned with Z.

If you don't know exactly where the rotor is in space, you can use the source "Cylinder" and move this cylinder to the location where your rotor is. This source is located in the menu "Sources -> Cylinder".

Then, knowing the position of this cylinder, it'll be easier to configure the script to do the section-cut in the right place!

Best regards,
Bruno

akashjangid June 16, 2013 23:36

Hi wyldckat,

Yes my rotor is located at (0,0,0) and is rotating along z axis.

acocic June 17, 2013 02:58

Hello Akash,

I think that you made some mistakes in the code, or it's just because of copying. For me Bruno's code works perfectly. So if you compare with it, there are slight differences. These are the paraview messages for your code, and possible solutions

Remark 1:
File "<string>", line 3
inp_copy = input.NewInstance() inp_copy.ShallowCopy(input)
^
SyntaxError: invalid syntax

This should be two lines,
Code:

inp_copy = input.NewInstance()
inp_copy.ShallowCopy(input)

Remark 2:
File "<string>", line 15
cutter.Update() self.GetOutputDataObject(0).ShallowCopy(cutter.Get OutputDataObject(0))
^
SyntaxError: invalid syntax

Also two lines:
Code:

cutter.Update()
self.GetOutputDataObject(0).ShallowCopy(cutter.Get OutputDataObject(0)

Remark 3: no space in last line
NOT
Code:

self.GetOutputDataObject(0).ShallowCopy(cutter.Get  OutputDataObject(0))
BUT
Code:

self.GetOutputDataObject(0).ShallowCopy(cutter.GetOutputDataObject(0))
If you used foamToVTK, and you analyze VTK data, you should choose vtkPolyData instead "Same as Input" in Output Data Set Type (just bellow Apply Reset Delete)

Best regards,
Alex.

akashjangid June 17, 2013 04:23

Hello acocic,

I did the changes in the script as told by you.
But it is still showing some errors

Traceback (most recent call last):
File "<string>", line 21, in <module>
File "<string>", line 14, in RequestData
AttributeError: SetInput

Actually I'm a beginner in scripting python for ParaView.
Please help me with this ? Do i have to add any vtk modules for this ?

akashjangid June 17, 2013 13:24

hey,

I installed paraveiw 3.14 and in that the script worked correctly
Thanks !!

akashjangid June 18, 2013 00:44

Hello,

I got the cylindrical slice, now i want to flatten that surface
any idea how to do that ?
Thanks

wyldckat June 20, 2013 16:57

Hi Akash,

The ParaView filter "Warp by vector" comes to mind, but I think I've never used it :(

Best regards,
Bruno

Nephi July 6, 2013 10:52

empty output
 
hello
i have to do almoust the same task as Aleksandar and was verry happy to find your post and so i tried out the programmable filter on a dummycylinder that ist orientated along the y-axis as default and copied in the code into the programmable filter. there are no errors comming up but i do not get any results. the output geometry has 0 points and 0 cells.
is there anythig special i have to be aware of?
i am using paraview 3.14 on linux and on windows
with best regards
Christian

acocic July 7, 2013 05:09

Sharing some experience :-)
 
4 Attachment(s)
Hello Christian,

For me, it was very straightforward. Main flow was in Z-direction, so the axis of the cylinder matched with Z-axis, and Bruno's original code worked perfectly. After it I tried the code with my other case (LES in pipe, where X-axis was the symmetry), and the code didn't work. The solution was to change to rotational axis in

Code:

transf.RotateX(90)
to

Code:

transf.RotateZ(90)
and to put (leave) the center of cylinder at (0, 0, 0), which is actually pipe inlet. The length of the pipe was 0.1m and if I put the center of cylinder in the middle of the domain, (0.05, 0, 0), I also got nothing, On the other hand, if I delete "transform.Rotate" line, I've got cylinder which axis is parallel to Y, and which is shown no matter where the center is located.

So basically, you just have to play around with two lines of the code (cylinder center and axis of rotation) and see what's the most suitable in your case. Maybe, first delete the line with transf.Rotate and see what you'll get (the axis of cylinder should be in Y-dir).

Best regards,
Alex.

Nephi July 7, 2013 12:29

Hi Alex
thank you for your fast reply. But unfortunatly it still does not work.
I tryed out all rotations and all cylinders are centered in 0,0,0
with best regards
Christian

wyldckat July 7, 2013 14:24

Greetings to all!

@Christian: could you please give some indications are to where your geometry/data is located in 3D space? As well as the limits of said geometry/data?

Best regards,
Bruno

Nephi July 8, 2013 03:45

Hi Bruno,
i just added da cylindersurce centered at 0,0,0 with high 1 and a radius of 0.5 , which is symmetric around the y-axis.
I tried cutting with a rotation around x-axis, z-axis and wothout rotarion. I also changed the radius to 0.5, were i expected to get the whole cylindersurface as result.
with best regards
Christian

wyldckat July 10, 2013 16:29

Hi Christian,

Oddly enough, it does not work with a cylinder source. I have no idea why :(

But it does work with a sphere source! You can use the default settings and it will work!

Best regards,
Bruno

Nephi July 11, 2013 07:18

hi
thanks for your reply. I´m going to try this.
meanwhile i got a hint to use the calculator filter to add an radius column to each point an then use the contour filter for only showing data at a certain radius.
after i got that i flattened the "slice" with an caltulater doing something like this
Code:

0*iHat+(asin(coordsY/(coordsX^2+coordsY^2)^(1/2))*(coordsX^2+coordsY^2)^(1/2))*jHat+coordsZ*kHat
this works verry well for me while i will never analyse more than a half cylinder because i just look at one blade.
with best regards
Christian

waynezw0618 July 22, 2013 23:56

1 Attachment(s)
p, li { white-space: pre-wrap; } Hi
it works for me here.
try this

Code:

from paraview import vtk
import numpy as np 
 
pdi = self.GetPolyDataInput()
 
c2p=vtkCellDataToPointData()
c2p.SetInputData(pdi)
c2p.Update()
pdi.GetPointData().AddArray(c2p.GetOutput().GetPointData().GetArray(0))
 
pdo =  self.GetPolyDataOutput()
newPoints = vtk.vtkPoints()
numPoints = pdi.GetNumberOfPoints()
 
for i in range(0, numPoints):
    coord = pdi.GetPoint(i)
    x, y, z = coord[:3]
    if x > 0:
      r = np.sqrt(x*x+y*y)
      t = np.arctan(x/y) + 0.5 * np.pi
      if y < 0:
        t = t + 1* np.pi
    else :
      r = np.sqrt(x*x+y*y)
      t = np.arctan(x/y) +  1.5* np.pi
      if y > 0:
        t = t - 1* np.pi
    newPoints.InsertPoint(i, r, t, 12*z)
pdo.SetPoints(newPoints)
#pdo.GetCellData().AddArray(pdi.GetCellData().GetArray(0))
pdo.GetPointData().AddArray(pdi.GetPointData().GetArray(0))

here I export my result on a cyliner surface to a vtk file by "sample" utility. what I got is data in cell so I convert it to the point. so if you just load OF result directly, you just need to comment some of same

waynezw0618 July 23, 2013 04:57

this is the results
 
1 Attachment(s)
here is the results from the code
Quote:

Originally Posted by waynezw0618 (Post 441349)
p, li { white-space: pre-wrap; } Hi
it works for me here.
try this

Code:

from paraview import vtk
import numpy as np 
 
pdi = self.GetPolyDataInput()
 
c2p=vtkCellDataToPointData()
c2p.SetInputData(pdi)
c2p.Update()
pdi.GetPointData().AddArray(c2p.GetOutput().GetPointData().GetArray(0))
 
pdo =  self.GetPolyDataOutput()
newPoints = vtk.vtkPoints()
numPoints = pdi.GetNumberOfPoints()
 
for i in range(0, numPoints):
    coord = pdi.GetPoint(i)
    x, y, z = coord[:3]
    if x > 0:
      r = np.sqrt(x*x+y*y)
      t = np.arctan(x/y) + 0.5 * np.pi
      if y < 0:
        t = t + 1* np.pi
    else :
      r = np.sqrt(x*x+y*y)
      t = np.arctan(x/y) +  1.5* np.pi
      if y > 0:
        t = t - 1* np.pi
    newPoints.InsertPoint(i, r, t, 12*z)
pdo.SetPoints(newPoints)
#pdo.GetCellData().AddArray(pdi.GetCellData().GetArray(0))
pdo.GetPointData().AddArray(pdi.GetPointData().GetArray(0))

here I export my result on a cyliner surface to a vtk file by "sample" utility. what I got is data in cell so I convert it to the point. so if you just load OF result directly, you just need to comment some of same


AS_allways October 23, 2013 06:30

Slice with geometry
 
Hi all,
first of all, i am a beginner in using paraview.
here at work i have to do some postprocessing for a motor flow simulation. Actually i have to test how to slice with a geometry. I have seen and also successfully tried to cylinder-slice the flow using the programmable filter as shown at the beginning of this thread.
Since the programmable filter can not handle complex geometries i am wondering if i can use a CAD-Geometry (the bend cylinder is an .stl geometry file) to slice with.

best regards,
Abdalla

wyldckat October 26, 2013 10:42

Greetings Abdalla and welcome to the forum!

The programmable filter is only used because the cylinder shape is not present in the "Slice" filter.

In your case, it's different and somewhat easier to do. Simply load up both data sets (the CFD results and the slice surface) and use the "Resample with DataSet" filter.

I've finished just now writing the following post, which explains in more detail how to do this: http://www.cfd-online.com/Forums/par...tml#post459139 post #4

Best regards,
Bruno

gerble February 11, 2014 09:18

Get time in a Programmable Filter paraview 3.14
 
Hi to everyone. I'm new in Paraview (start learning this month for an intership) and I have some complications. I need to program a filter to change over time. I used
Code:

t = inputs[0].GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP()
in paraview 3.98. But in paraview 3.14 doesn't work and I couldn't found a way of fixing this "mistake". The reason for using paraview 3.14 is that I need to clip a cylinder.

Thank you very much, and I'm sorry if I have any spelling/gramatical mistakes

wyldckat February 11, 2014 14:43

Greetings gerble and welcome to the forum!

I don't have time to test this right now, but some time ago I wrote/updated this post: http://www.cfd-online.com/Forums/ope...tml#post446333 post #6

After some further developments on the topic, the resulting conclusion was that the only guaranteed way to get the time in all ParaView versions was to use this:
Code:

GetAnimationScene().TimeKeeper.Time
Problem is that this might depend on where it's being used. You might need to add this line to your code in the filter, before everything else:
Code:

from paraview.simple import *
Please let us know if either one of these worked.

Best regards,
Bruno

gerble February 11, 2014 22:50

Unfortunatly it doesn't work out. I have tried in a Windows 7 system and in a Debian base computer. What happen is that when executing the paraview.simple import this messages appears: "<string>:1: SyntaxWarning: import * only allowed at module level" and the result of GetAnimationScene().TimeKeeper.Time is 0.0 . Before writing in this forum I tried another sentences that requieres this definition and this error always appears. If I don't write that sentece, if I only try to get the time an error appears informing that 'GetAnimationScene' is not defined.

On the other hand, I was thinking on define a variable in the python code so I can later modified through the "Animation View". It would consume more memory to make de animations (I think) but it will probably work equally to what I was trying. Is there a way of doing this? Sorry if I changed the issue of the Thread too much.

Thank you very much for your answer!

wyldckat February 16, 2014 12:10

Hi German,

After doing some trial-and-error-and-research, this programmable filter seems to work in ParaView 3.12.0:
Code:

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_STEPS()):
      return None
    return outInfo.Get(executive.UPDATE_TIME_STEPS(),0)
 

 # This is the requested time-step. This may not be exactly equal to the
 # timesteps published in RequestInformation(). Your code must handle that
 # correctly
 req_time = GetUpdateTimestep(self)
 

 input = self.GetInputDataObject(0, 0)
 inp_copy = input.NewInstance()
 inp_copy.ShallowCopy(input)
 inp_copy.UnRegister(None)
 cutter = vtk.vtkCutter()
 transf = vtk.vtkTransform()
 transf.RotateX(90)
 cyl = vtk.vtkCylinder()
 cyl.SetCenter(0,0,0)
 cyl.SetRadius(0.1*(0.5+req_time))
 cyl.SetTransform(transf)
 cutter.SetCutFunction(cyl)
 cutter.SetInput(inp_copy)
 cutter.Update()
 self.GetOutputDataObject(0).ShallowCopy(cutter.GetOutputDataObject(0))

It's based on these sources of information:
The "req_time" variable is the current time snapshot.


As for global variables, they simply don't work, because the Python workspaces are completely independent, namely the ones on each filter and on the main Python shell.

Best regards,
Bruno

CROS May 26, 2014 08:07

Hello everyone,
I was looking for a possibility to create radial cuts and the solution presented by Bruno seemed to be a good solution. Using Paraview 4.1.0 I got the same error like akashjangid

Quote:

Originally Posted by akashjangid (Post 434396)
Traceback (most recent call last):
File "<string>", line 21, in <module>
File "<string>", line 14, in RequestData
AttributeError: SetInput

Replacing
Code:

cutter.SetInput(inp_copy)
with

Code:

cutter.SetInputData(inp_copy)
keeps the code running in Paraview 4.1.0.

Thanks to all of you.

Christoph

mbgnfsr2 August 7, 2014 07:59

hi Bruno
i have also try this scirpt, but in my case is not working. My output is in ensight format and i had to modify the script in order to deal with Multiblock Dataset. With the following script i don't get any error but the output is empty.

Here my code
Code:

def cut_cylinder(input_block, output_block):
    inp_copy = input_block.NewInstance()
    inp_copy.ShallowCopy(input_block.VTKObject)
    inp_copy.UnRegister(None)
    cutter = vtk.vtkCutter()
    transf = vtk.vtkTransform()
    transf.RotateX(90)
    cyl = vtk.vtkCylinder()
    cyl.SetCenter(0,0,0)
    cyl.SetRadius(0.04)
    cyl.SetTransform(transf)
    cutter.SetCutFunction(cyl)
    #cutter.SetInputConnection(inp_copy.GetOutputPort())
    cutter.SetInput(inp_copy)
    #cutter.SetInputData(inp_copy)
    #cutter.ShallowCopy(inp_copy)
    cutter.Update()
    self.GetOutputDataObject(0).ShallowCopy(cutter.GetOutputDataObject(0))
    #output_block.ShallowCopy(cutter.GetOutputDataObject(0))


#============================================================================================
from paraview import vtk
from paraview.vtk.dataset_adapter import MultiCompositeDataIterator
import math
from paraview.numpy_support import vtk_to_numpy
from paraview.vtk.dataset_adapter import numpyTovtkDataArray, vtkDataArrayToVTKArray
import numpy as np

iter = MultiCompositeDataIterator([inputs[0], output])

for input_block, output_block in iter:
    cut_cylinder(input_block,output_block)

If i change from

Code:

cutter.SetInput(inp_copy)
to
Code:

cutter.SetInputData(inp_copy)
i simply get the parent geometry, but not the cut.
Does anyone know how i can make this script working.

Thanks very much

Stefano


I get

wyldckat August 16, 2014 13:01

Greetings Stefano and welcome to the forum!

Can you provide a small example file with which I can reproduce this error?

In addition, I suggest that you use the "Merge Blocks" filter before applying this particular programmable filter, so that it makes it easier to at least test this programmable filter.

Beyond this, I suspect the problem is that you did not properly calibrate the settings for the position of the cylinder, namely these values were not changed:
Code:

transf.RotateX(90)
cyl.SetCenter(0,0,0)
cyl.SetRadius(0.04)

Best regards,
Bruno

mbgnfsr2 August 18, 2014 13:30

1 Attachment(s)
Dear Bruno
thanks very much for your replay. I check the centre, radius and axis and all are ok (The axis is z and the radius should be between 0.029 and 0.05).
I also try to use the filter merge block and after i applied your filter that posted at the top and still the result is the same of the input with no cut.
I manage to get something similar to what i was looking for using a coordinate transformation from Cartesian to cylindrical and after using the plane cut on the new geometry. but, in any case, would be nice to have also this filter working.
In attachment the small case as you have requested and if you manage to get something let me know. In the input there is only the mesh, but no variables.
Just to be clear at the moment i'm using Paraview 4.0 and i don’t know if the version is the source of the problem.
Thanks very much for your help

Best wishes

Stefano

deandrade November 13, 2014 07:51

Hello everybody,

have you managed to find a solution for this problem in version 4.0?

I have the same problem as Stefano, changing that line makes the script work but it gives the parent geometry back.

Cheers!

lourencosm December 2, 2014 11:35

Is there a way to auto-update the time step function,
So that the programmable filter finds the new values in paraview "play mode"??

Thank you,
Lourenço

wyldckat April 5, 2015 12:20

Greetings to all!

I'll answer to all 3 posts here:

------------

@Stefano:
Quote:

Originally Posted by mbgnfsr2 (Post 506507)
In attachment the small case as you have requested and if you manage to get something let me know. In the input there is only the mesh, but no variables.

My apologies for taking so very long to come back to your issue, but only today did I finally managed to take a look into this.

I tested with ParaView 4.1.0 with the following code and it worked just fine with the test case you provided:
Code:

input = self.GetInputDataObject(0, 0)
inp_copy = input.NewInstance()
inp_copy.ShallowCopy(input)
inp_copy.UnRegister(None)
cutter = vtk.vtkCutter()
transf = vtk.vtkTransform()
transf.RotateX(90)
cyl = vtk.vtkCylinder()
cyl.SetCenter(0,0,0)
cyl.SetRadius(0.04)
cyl.SetTransform(transf)
cutter.SetCutFunction(cyl)
cutter.SetInputData(inp_copy)
cutter.Update()
self.GetOutputDataObject(0).ShallowCopy(cutter.GetOutputDataObject(0))

Note: When I tried to use the "Merge Blocks" filter and then applied the programmable filter to it, then ParaView would crash :(

I've tested as well with ParaView 4.0.1 64-bit, which I downloaded as one of the pre-built packages from ParaView.org, and it worked as well.

Do notice that the critical detail here is that the radius needs to be changed from "0.4" to "0.04":
Code:

cyl.SetRadius(0.04)
I hope you managed to solve you problem a long time ago... it took me 8 months to get back to you :(

----------

@Jacopo:
Quote:

Originally Posted by deandrade (Post 518972)
have you managed to find a solution for this problem in version 4.0?

I have the same problem as Stefano, changing that line makes the script work but it gives the parent geometry back.

As shown in the code above, this code does work.
By the way, I hope you're using the "Programmable Filter", not the "Programmable Source".

----------

@Lourenço:
Quote:

Originally Posted by lourencosm (Post 522133)
Is there a way to auto-update the time step function,
So that the programmable filter finds the new values in paraview "play mode"??

Doesn't post #29 have the answer to your question?
If not, you'll have to provide more details, because I can't figure out what exactly you're looking for.

Best regards,
Bruno

openfoammaofnepo April 25, 2016 09:08

Dear Bruno,

Which command here is for defining the axis direction of the cylindrical slice before is it flattened? Thanks.

Quote:

Originally Posted by wyldckat (Post 428465)
Greetings Alex and welcome to the forum!

It's possible, but it requires two things:
  1. That you are using ParaView 3.12 or 3.14, including the Python capabilities inside ParaView. The reason for this is that in ParaView 3.98, the necessary VTK filter is not present.
  2. That you use the "Programmable Filter" instead of the normal "Slice" filter. The reason for this is because the "Cylinder" is an implicit function that for some reason they forgot to include in ParaView :(
Reference: http://www.paraview.org/pipermail/pa...ry/016019.html

Instructions:
  1. Apply the "Programmable Filter" to the item you want to cut.
  2. Use the following code in the first text edit box:
    Code:

    input = self.GetInputDataObject(0, 0)
    inp_copy = input.NewInstance()
    inp_copy.ShallowCopy(input)
    inp_copy.UnRegister(None)
    cutter = vtk.vtkCutter()
    transf = vtk.vtkTransform()
    transf.RotateX(90)
    cyl = vtk.vtkCylinder()
    cyl.SetCenter(0,0,0)
    cyl.SetRadius(0.4)
    cyl.SetTransform(transf)
    cutter.SetCutFunction(cyl)
    cutter.SetInput(inp_copy)
    cutter.Update()
    self.GetOutputDataObject(0).ShallowCopy(cutter.GetOutputDataObject(0))

  3. Notes on important details:
    • The cylinder is infinite, because it's an implicit function.
    • "cyl.SetRadius(0.4)" - defines the radius.
    • "cyl.SetCenter(0,0,0)" - defines the centre of the cylinder.
    • The transformation is done with these lines of code:
      Code:

      transf = vtk.vtkTransform()
      transf.RotateX(90)

    • If more transformations are needed, see the list of methods here: http://www.vtk.org/doc/release/5.10/...Transform.html
Best regards,
Bruno


wyldckat May 1, 2016 19:14

Quote:

Originally Posted by openfoammaofnepo (Post 596600)
Which command here is for defining the axis direction of the cylindrical slice before is it flattened? Thanks.

Quick answer:
Code:

transf.RotateX(90)
Try without it and you will see the default orientation. You can also use the "Cylinder" source: menu -> Sources -> Cylinder - to test things with it.

haha July 21, 2019 22:50

Hi waynezw0618,

I know it's been a long time ago. I recently have this problem about unwrapping an openfoam simulation in a cylinder annulus to a 2D plane. I have an error after running your code: AttributeError:'vtkCommonDataModelPython.vtkMultiB lockDataSet' object has no attribute 'GetPoint'. It seems it is related with multiblocks but I have no idea how to solve this issue. Could you please help me with that if you happen to know? by the way, in your code, why you use 12*z as the third coordinate? Thank you very much.



Quote:

Originally Posted by waynezw0618 (Post 441349)
p, li { white-space: pre-wrap; } Hi
it works for me here.
try this

Code:

from paraview import vtk
import numpy as np 
 
pdi = self.GetPolyDataInput()
 
c2p=vtkCellDataToPointData()
c2p.SetInputData(pdi)
c2p.Update()
pdi.GetPointData().AddArray(c2p.GetOutput().GetPointData().GetArray(0))
 
pdo =  self.GetPolyDataOutput()
newPoints = vtk.vtkPoints()
numPoints = pdi.GetNumberOfPoints()
 
for i in range(0, numPoints):
    coord = pdi.GetPoint(i)
    x, y, z = coord[:3]
    if x > 0:
      r = np.sqrt(x*x+y*y)
      t = np.arctan(x/y) + 0.5 * np.pi
      if y < 0:
        t = t + 1* np.pi
    else :
      r = np.sqrt(x*x+y*y)
      t = np.arctan(x/y) +  1.5* np.pi
      if y > 0:
        t = t - 1* np.pi
    newPoints.InsertPoint(i, r, t, 12*z)
pdo.SetPoints(newPoints)
#pdo.GetCellData().AddArray(pdi.GetCellData().GetArray(0))
pdo.GetPointData().AddArray(pdi.GetPointData().GetArray(0))

here I export my result on a cyliner surface to a vtk file by "sample" utility. what I got is data in cell so I convert it to the point. so if you just load OF result directly, you just need to comment some of same



All times are GMT -4. The time now is 13:48.