Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Mar 27, 2019
1 parent fddd3c3 commit 282360f
Show file tree
Hide file tree
Showing 25 changed files with 336 additions and 262 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
author = 'Marco Musy'

# The short X.Y version
version = '2019.1.1'
version = '2019.1.2'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/fitplanes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""
from vtkplotter import *

vp = Plotter(verbose=0, axes=0)
vp = Plotter(verbose=0, axes=0, bg='w')

s = vp.load(datadir+"shapes/cow.vtk").alpha(0.3).subdivide() # remesh

Expand Down
2 changes: 1 addition & 1 deletion examples/basic/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
with open("basic/align1.py") as fname:
t = fname.read()

actor2d = Text(t, pos=3, s=1.2, bg="lb", font="courier")
actor2d = Text(t, pos=3, s=1.2, c='k', bg="lb", font="courier")

show(actor2d, verbose=0, axes=0)
2 changes: 1 addition & 1 deletion examples/basic/carcrash.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
rate=10 limits the speed of the loop to maximum 10 fps
"""
from __future__ import division, print_function
from vtkplotter import Plotter, Plane, Text
from vtkplotter import Plotter, Plane, Text, datadir

vp = Plotter(interactive=0, axes=0)

Expand Down
2 changes: 1 addition & 1 deletion examples/basic/rotateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Normal jpg/png images can be
loaded and rendered as any vtkImageActor
"""
from vtkplotter import Plotter, Text
from vtkplotter import Plotter, Text, datadir

vp = Plotter(axes=3, verbose=0)

Expand Down
2 changes: 1 addition & 1 deletion examples/basic/texturecubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
any jpg file can be used as texture.
"""
from vtkplotter import Plotter, Cube, Text
from vtkplotter.utils import textures, textures_path
from vtkplotter.settings import textures, textures_path

print(__doc__)
print(textures_path)
Expand Down
3 changes: 2 additions & 1 deletion examples/basic/trail.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Example usage of addTrail(). Add a triling line to a moving object.
Example usage of addTrail().
Add a trailing line to a moving object.
"""
print(__doc__)
from vtkplotter import Plotter, sin, Sphere, Point
Expand Down
4 changes: 4 additions & 0 deletions examples/other/dolfin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ python example.py # on mac OSX try 'pythonw' instead
| [![stokes](https://user-images.githubusercontent.com/32848391/53044917-95838100-348c-11e9-9a94-aa10b8f1658c.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/ex07_stokes-iterative.py)<br/> `ex07_stokes-iterative.py` | Stokes equations with an iterative solver. |
| | |
| [![elastodyn](https://user-images.githubusercontent.com/32848391/54932788-bd4a8680-4f1b-11e9-9326-33645171a45e.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/elastodynamics.py)<br/> `elastodynamics.py` | Perform time integration of transient elastodynamics using the generalized-alpha method. |
| | |
| [![stokes](https://user-images.githubusercontent.com/32848391/55098209-aba0e480-50bd-11e9-8842-42d3f0b2d9c8.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/stokes.py)<br/> `stokes.py` | Solve 2D navier-stokes equations with boundary conditions. |


8 changes: 1 addition & 7 deletions examples/other/dolfin/ascalarbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,5 @@
################################## vtkplotter
from vtkplotter.dolfin import plot

plot(u, mode='color', vmin=-6, vmax=6, style=1, text=__doc__)
plot(u, mode='color', vmin=-3, vmax=3, style=1, text=__doc__)


################################# pylab
#import pylab as plt
#c = plot(u, mode='color', vmin=-3, vmax=3)
#plt.colorbar(c)
#plt.show()
43 changes: 43 additions & 0 deletions examples/other/dolfin/calc_surface_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from dolfin import *
import sympy as sp
# Credits:
# https://github.com/pf4d/fenics_scripts/calc_surface_area.py

x, y = sp.symbols('x, y')

# surface :
def s(x,y): return sp.exp(x)

# x-derivative of surface
def dsdx(x,y): return s(x,y).diff(x, 1)

# y-derivative of surface
def dsdy(x,y): return s(x,y).diff(y, 1)

# outward-pointing-normal-vector magnitude at surface :
def n_mag_s(x,y): return sp.sqrt(1 + dsdx(x,y)**2 + dsdy(x,y)**2)

# surface area of surface :
def area(x,y): return sp.integrate(n_mag_s(x,y), (x,0,1), (y,0,1))

A_exact = area(x,y)

for n in [5,10,100,500]:
mesh = UnitSquareMesh(n,n)
Q = FunctionSpace(mesh, "CG", 1)
e = Expression('exp(x[0])', degree=2)
f = interpolate(e, Q)
A_num = assemble( sqrt(f.dx(0)**2 + f.dx(1)**2 + 1) * dx)
print('for n = %i -- error = %.2e' % (n, abs(A_exact.evalf()-A_num)))

n = 10
mesh = UnitSquareMesh(n,n)
Q = FunctionSpace(mesh, "CG", 1)
e = Expression('exp(x[0])', degree=2)
f = interpolate(e, Q)
A_vector = project( sqrt(f.dx(0)**2 + f.dx(1)**2 + 1), Q)


from vtkplotter.dolfin import plot
plot(A_vector)

1 change: 1 addition & 0 deletions examples/other/dolfin/elastodynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Time-integration of the
elastodynamics equation
'''
from __future__ import division, print_function
from dolfin import *
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions examples/other/dolfin/ex04_mixed-poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Solving Poisson equation using
a mixed (two-field) formulation.
"""
# needs python3
# https://fenicsproject.org/docs/dolfin/2018.1.0/python/demos/mixed-poisson
from dolfin import *

Expand Down
15 changes: 15 additions & 0 deletions examples/other/dolfin/pi_estimate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from dolfin import *
from mshr import Circle, generate_mesh
from vtkplotter.dolfin import plot, printc
# Credits:
# https://github.com/pf4d/fenics_scripts/pi_estimate.py

domain = Circle(Point(0.0,0.0), 1.0)

for res in [2**k for k in range(8)]:
mesh = generate_mesh(domain, res)
A = assemble(Constant(1) * dx(domain=mesh))
printc("resolution = %i, \t |A - pi| = %.5e" % (res, abs(A-pi)))
printc('~pi is about', A, c='yellow')

plot(mesh, style=1, axes=3)
8 changes: 8 additions & 0 deletions examples/other/dolfin/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@ python ascalarbar.py
echo Running collisions.py
python collisions.py

echo Running calc_surface_area.py
python calc_surface_area.py

echo Running markmesh.py
python markmesh.py

echo Running elastodynamics.py
python elastodynamics.py

echo Running pi_estimate.py
python pi_estimate.py

echo Running stokes.py
python stokes.py



Expand Down
52 changes: 52 additions & 0 deletions examples/other/dolfin/stokes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
This demo solves the Stokes equations, using quadratic elements for
the velocity and first degree elements for the pressure (Taylor-Hood elements).
"""
# Credits:
# https://github.com/pf4d/fenics_scripts/blob/master/cbc_block/stokes.py
from dolfin import *
from time import time
from vtkplotter.dolfin import plot, datadir

t0 = time()
print("calculating... please wait...")

# Load mesh and subdomains
mesh = Mesh(datadir+"dolfin_fine.xml")
sub_domains = MeshFunction("size_t", mesh,
datadir+"dolfin_fine_subdomains.xml.gz")

# Define function spaces
P2 = VectorElement("Lagrange", mesh.ufl_cell(), 2)
P1 = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
TH = P2 * P1
W = FunctionSpace(mesh, TH)

# No-slip boundary condition for velocity
noslip = Constant((0, 0))
bc0 = DirichletBC(W.sub(0), noslip, sub_domains, 0)

# Inflow boundary condition for velocity
inflow = Expression(("-sin(x[1]*pi)", "0.0"), degree=2)
bc1 = DirichletBC(W.sub(0), inflow, sub_domains, 1)
bcs = [bc0, bc1]

# Define variational problem
(u, p) = TrialFunctions(W)
(v, q) = TestFunctions(W)
f = Constant((0, 0))
a = (inner(grad(u), grad(v)) - div(v)*p + q*div(u))*dx
L = inner(f, v)*dx
w = Function(W)

solve(a == L, w, bcs, solver_parameters={'linear_solver' : 'mumps'})
tf = time()
print("time to solve:", tf-t0)

# Split the mixed solution using a shallow copy
(u, p) = w.split()

##################################
plot(u, at=0, N=2, text="velocity", mode='mesh and arrows',
scale=.03, wire=1, scalarbar=False, style=1)
plot(p, at=1, text="pressure", cmap='jet')
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='vtkplotter',
version='2019.1.1', # change also in vtkplotter/__init__.py and docs/source/conf.py
version='2019.1.2', # change also in vtkplotter/__init__.py and docs/source/conf.py
packages=['vtkplotter'],
scripts=['bin/vtkplotter', 'bin/vtkconvert'],
install_requires=['vtk'],
Expand Down Expand Up @@ -78,8 +78,7 @@
# open build/html/index.html
#
# mount_staging
# cp to ~/Projects/StagingServer/var/www/html/vtkplotter.embl.es
#
# cp -r build/html/* ~/Projects/StagingServer/var/www/html/vtkplotter.embl.es/



Loading

0 comments on commit 282360f

Please sign in to comment.