Cube to Sphere
In [1]:
Copied!
# set backend for vtk/pyvista in jupyter
import pyvista as pv
pv.set_jupyter_backend('static')
from pyvirtualdisplay import Display
#pv.start_xvfb()
# set backend for vtk/pyvista in jupyter
import pyvista as pv
pv.set_jupyter_backend('static')
from pyvirtualdisplay import Display
#pv.start_xvfb()
Matplotlib is building the font cache; this may take a moment.
In [2]:
Copied!
# cfdtools packages
import cfdtools.meshbase.simple as sm
from cfdtools.vtk import vtkMesh
# cfdtools packages
import cfdtools.meshbase.simple as sm
from cfdtools.vtk import vtkMesh
In [3]:
Copied!
cube = sm.Cube(10, 10, 10)
mesh = cube.export_mesh()
vtkmesh = vtkMesh(mesh)
cube = sm.Cube(10, 10, 10)
mesh = cube.export_mesh()
vtkmesh = vtkMesh(mesh)
In [4]:
Copied!
with Display():
vtkmesh.plot()
with Display():
vtkmesh.plot()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[4], line 2 1 with Display(): ----> 2 vtkmesh.plot() File ~/checkouts/readthedocs.org/user_builds/cfdtools/envs/latest/lib/python3.8/site-packages/cfdtools/vtk/_vtk.py:91, in vtkMesh.plot(self, background, show_edges, *args, **kwargs) 90 def plot(self, background='white', show_edges=True, *args, **kwargs): ---> 91 self.pyvista_grid().plot(background=background, show_edges=show_edges, *args, **kwargs) TypeError: 'UnstructuredGrid' object is not callable
In [5]:
Copied!
def map_to_sphere(x, y, z):
import numpy as np
# cube has side range 0 to 1, map to [-1, 1]
x1 = 2*x-1 ; y1 = 2*y-1 ; z1 = 2*z-1
x2 = x1 * np.sqrt(1-y1**2/2-z1**2/2+(y1*z1)**2/3)
y2 = y1 * np.sqrt(1-x1**2/2-z1**2/2+(x1*z1)**2/3)
z2 = z1 * np.sqrt(1-x1**2/2-y1**2/2+(x1*y1)**2/3)
return x2, y2, z2
mesh.morph(map_to_sphere)
def map_to_sphere(x, y, z):
import numpy as np
# cube has side range 0 to 1, map to [-1, 1]
x1 = 2*x-1 ; y1 = 2*y-1 ; z1 = 2*z-1
x2 = x1 * np.sqrt(1-y1**2/2-z1**2/2+(y1*z1)**2/3)
y2 = y1 * np.sqrt(1-x1**2/2-z1**2/2+(x1*z1)**2/3)
z2 = z1 * np.sqrt(1-x1**2/2-y1**2/2+(x1*y1)**2/3)
return x2, y2, z2
mesh.morph(map_to_sphere)
In [6]:
Copied!
vtkmesh = vtkMesh(mesh)
with Display():
vtkmesh.plot()
vtkmesh = vtkMesh(mesh)
with Display():
vtkmesh.plot()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[6], line 3 1 vtkmesh = vtkMesh(mesh) 2 with Display(): ----> 3 vtkmesh.plot() File ~/checkouts/readthedocs.org/user_builds/cfdtools/envs/latest/lib/python3.8/site-packages/cfdtools/vtk/_vtk.py:91, in vtkMesh.plot(self, background, show_edges, *args, **kwargs) 90 def plot(self, background='white', show_edges=True, *args, **kwargs): ---> 91 self.pyvista_grid().plot(background=background, show_edges=show_edges, *args, **kwargs) TypeError: 'UnstructuredGrid' object is not callable