Skip to content

Commit

Permalink
3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Jun 24, 2019
1 parent 6fbcdbf commit 3a9f2ca
Show file tree
Hide file tree
Showing 25 changed files with 465 additions and 452 deletions.
2 changes: 1 addition & 1 deletion examples/basic/clustering.py
Expand Up @@ -22,4 +22,4 @@
# find back their identity through clustering
cl = cluster(pts, radius=0.1) # returns a vtkAssembly

show(cl, Text(__doc__), axes=1, verbose=0)
show(cl, Text(__doc__), axes=1, viewup='z')
7 changes: 2 additions & 5 deletions examples/basic/mesh_sharemap.py
Expand Up @@ -2,7 +2,6 @@
How to share the same color map
across different meshes.
"""
print(__doc__)
from vtkplotter import load, Text, show, datadir


Expand All @@ -11,13 +10,11 @@
scals = man1.coordinates()[:, 2] * 5 + 27 # pick z coordinates [18->34]

man1.pointColors(scals, cmap="jet", vmin=18, vmax=44)
man1.show(N=2, at=0, axes=0, elevation=-80)

#####################################
man2 = load(datadir+"man.vtk").addScalarBar()
man2 = load(datadir+"man.vtk")
scals = man2.coordinates()[:, 2] * 5 + 37 # pick z coordinates [28->44]

man2.pointColors(scals, cmap="jet", vmin=18, vmax=44)
# man2.show(at=1, interactive=0)

show(man2, Text(__doc__), at=1, interactive=1)
show([[man1, Text(__doc__)], man2], N=2, elevation=-40)
4 changes: 2 additions & 2 deletions examples/notebooks/sphere.ipynb
Expand Up @@ -2,13 +2,13 @@
"cells": [
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1c932fd2f6124207afb7e72f40dff52a",
"model_id": "e80883391eaf46d0b90e212fe2a35414",
"version_major": 2,
"version_minor": 0
},
Expand Down
68 changes: 68 additions & 0 deletions examples/other/dolfin/curl2d.py
@@ -0,0 +1,68 @@
#Magnetostatic equation that solves for magnetic vector potential,
#where the reluctivity matrix can be defined as inverse of permeability matrix..
#https://fenicsproject.discourse.group/t/anisotropic-material-definition-and-results-issue/1051
from dolfin import *
from mshr import *
from scipy import constants
from vtkplotter.dolfin import plot

domain = Rectangle(Point(-10, -10), Point(10, 10))
mesh = generate_mesh(domain, 64)

# function space
V = FunctionSpace(mesh, "P", 1)

# boundary conditions
walls = "on_boundary && (near(abs(x[0]), 10.0) || near(abs(x[1]), 10.0))"
bc = DirichletBC(V, Constant(0.0), walls)

tol = 1e-6

# Wire
class Omega_0(SubDomain):
def inside(self, x, on_boundary):
return x[0] ** 2 + x[1] ** 2 <= 4 - tol

# Space
class Omega_1(SubDomain):
def inside(self, x, on_boundary):
return x[0] ** 2 + x[1] ** 2 > 4 + tol

def curl2D(v):
return as_vector((v.dx(1), -v.dx(0)))


materials = MeshFunction("size_t", mesh, mesh.topology().dim())

subdomain_0 = Omega_0()
subdomain_1 = Omega_1()
subdomain_0.mark(materials, 0)
subdomain_1.mark(materials, 1)

dx = Measure("dx", domain=mesh, subdomain_data=materials)

A_z = Function(V) # magnetic vector potential
v = TestFunction(V)

J = 5.0e6
# anisotropic material parameters, reluctivity = 1/constants.mu_0
reluctivity = as_matrix(
((1 / (constants.mu_0 * 1000), 0),
(0, 1 / (constants.mu_0 * 1)))
)

F = inner(reluctivity * curl2D(A_z), curl2D(v)) * dx - J * v * dx(0)
solve(F == 0, A_z, bc)

W = VectorFunctionSpace(mesh, "P", 1)

Bx = A_z.dx(1)
By = -A_z.dx(0)
B = project(as_vector((Bx, By)), W)

plot(B, mode='mesh and arrows',
style=2,
scale=0.01,
lw=0,
warpZfactor=-0.01,
)
6 changes: 4 additions & 2 deletions examples/other/dolfin/magnetostatics.py
Expand Up @@ -88,5 +88,7 @@ def eval_cell(self, values, x, cell):
plot(A_z, at=0, N=2, # draw on the first of 2 renderers
lw=0, # linewidth of mesh
bg='white',
isolines={'n':20, 'lw':1.5, 'c':'black'})
plot(B, at=1, text=__doc__) # draw on the second renderer
isolines={'n':20, 'lw':1.5, 'c':'black'},
scalarbar=False,
)
plot(B, at=1, scalarbar=False, text=__doc__) # draw on the second renderer
2 changes: 2 additions & 0 deletions examples/other/dolfin/run_all.sh
Expand Up @@ -38,6 +38,8 @@ python elasticbeam.py
echo Running magnetostatics.py
python magnetostatics.py

echo Running curl2d.py
python curl2d.py

######################################
echo Running ex01_show-mesh.py
Expand Down
16 changes: 9 additions & 7 deletions examples/basic/qt_window.py → examples/other/qt_window.py
@@ -1,12 +1,14 @@
"""
A sort of minimal example of how to embed a rendering window
into a qt application.
"""
print(__doc__)
import sys
from PyQt5 import Qt
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor

from vtkplotter import Plotter, Cone

# settings.usingQt = True <-- not needed anymore, automatically triggered by passing a qtWidget to Plotter


class MainWindow(Qt.QMainWindow):
def __init__(self, parent=None):

Expand All @@ -16,19 +18,19 @@ def __init__(self, parent=None):
self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
self.vl.addWidget(self.vtkWidget)

vp = Plotter(qtWidget=self.vtkWidget, axes=4, verbose=False)
vp = Plotter(qtWidget=self.vtkWidget, axes=4, bg='white')

vp += Cone()
vp.show() # to create renderer and add the actors
vp.show() # create renderer and add the actors

# set-up the rest of the Qt window
self.frame.setLayout(self.vl)
self.setCentralWidget(self.frame)

self.show() # <--- show the Qt Window
self.show() # <--- show the Qt Window


if __name__ == "__main__":
app = Qt.QApplication(sys.argv)
window = MainWindow()
app.exec_()
app.exec_()
Expand Up @@ -10,8 +10,6 @@

from vtkplotter import Plotter, Cube, Torus, Cone, settings

settings.usingQt = True


class MainWindow(Qt.QMainWindow):
def __init__(self, parent=None):
Expand All @@ -22,7 +20,7 @@ def __init__(self, parent=None):
self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
self.vl.addWidget(self.vtkWidget)

vp = Plotter(offscreen=1, interactive=0, axes=2, N=2)
vp = Plotter(qtWidget=self.vtkWidget, axes=2, N=2)

cn = Cone()
cc = Cube().pos(1, 1, 1).color("pink")
Expand Down
3 changes: 2 additions & 1 deletion examples/other/self_org_maps2d.py
Expand Up @@ -47,7 +47,8 @@ def learn(self, n_epoch=10000, sigma=(0.25,0.01), lrate=(0.5,0.01)):
# Draw network
if i>500 and not i%20 or i==n_epoch-1:
x, y, z = [self.codebook[:,i].reshape(n,n) for i in range(3)]
grd = Grid(resx=n-1, resy=n-1).wire(False).lw(0.5).bc('lightblue')
grd = Grid(resx=n-1, resy=n-1)
grd.wireframe(False).lw(0.5).bc('lightblue').flat()
for i in range(n):
for j in range(n):
grd.setPoint(i*n+j, (x[i,j], y[i,j], z[i,j]))
Expand Down
7 changes: 5 additions & 2 deletions examples/run_all.sh
Expand Up @@ -352,8 +352,11 @@ python other/icon.py
echo Running other/inset.py
python other/inset.py

echo Running other/qt_embed.py # needs qt5
python other/qt_embed.py
echo Running other/qt_window.py # needs qt5
python other/qt_window.py

echo Running other/qt_window_split.py # needs qt5
python other/qt_window_split.py

echo Running other/self_org_maps2d.py
python other/self_org_maps2d.py
Expand Down
2 changes: 0 additions & 2 deletions examples/simulations/README.md
Expand Up @@ -25,8 +25,6 @@ python example.py # on mac OSX try 'pythonw' instead
| | |
| [![mpend](https://user-images.githubusercontent.com/32848391/50738892-db380300-11d8-11e9-807c-fb320c7b7917.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/multiple_pendulum.py)<br/> `multiple_pendulum.py` | Simulation of an elastic multiple pendulums with viscous friction. |
| | |
| [![pendulum](https://user-images.githubusercontent.com/32848391/55420020-51e56200-5576-11e9-8513-4a5d93913b17.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/pendulum.py)<br/> `pendulum.py` | Visualize the phase space of a simple pendulum (from [3Blue1Brown](https://www.youtube.com/watch?v=p_di4Zn4wz4)). |
| | |
| [![hanoi](https://user-images.githubusercontent.com/32848391/56989284-58c1bd80-6b92-11e9-8f82-1ce95813f846.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/hanoi3d.py)<br/> `hanoi3d.py` | Solve the Tower of Hanoi puzzle (contributed by [G. Jacquenot](https://github.com/Gjacquenot)). |
| | |
| [![airplanes](https://user-images.githubusercontent.com/32848391/57341963-b8910900-713c-11e9-898a-84b6d3712bce.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/airplanes.py)<br/> `airplanes.py` | Two acrobatic planes casting shadows and leaving a trail. |
Expand Down

0 comments on commit 3a9f2ca

Please sign in to comment.