예제 #1
0
# Define variational problem
w = TrialFunction(V)
v = TestFunction(V)
u = Function(V)
f = Constant(-6.0)

# Compute solution
solve(dot(grad(w), grad(v)) * dx == f * v * dx, u, bc)

f = r'-\nabla^{2} u=f'

########################################################### vedo
from vedo.dolfin import plot, Latex, clear, show

l = Latex(f, s=0.2, c='w').addPos(.6, .6, .1)

acts = plot(u, l, cmap='jet', scalarbar='h', returnActorsNoShow=True)

actor = acts[0]

solution = actor.pointdata[0]

print('ArrayNames', actor.pointdata.keys())
print('min', 'mean', 'max:')
print(np.min(solution), np.mean(solution), np.max(solution), len(solution))

assert np.isclose(np.min(solution), 1., atol=1e-03)
assert np.isclose(np.mean(solution), 2.0625, atol=1e-03)
assert np.isclose(np.max(solution), 4., atol=1e-03)
assert len(solution) == 81
예제 #2
0
u_0 = Expression('exp(-5*pow(x[0],2) - 5*pow(x[1],2))', degree=2)
u_n = interpolate(u_0, V)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(0)

F = u * v * dx + dt * dot(grad(u), grad(v)) * dx - (u_n + dt * f) * v * dx
a, L = lhs(F), rhs(F)

############################################################# vedo
from vedo.dolfin import plot, Latex

f = r'\frac{\partial u}{\partial t}=\nabla^2 u+f~\mathrm{in}~\Omega\times(0,T]'
formula = Latex(f, pos=(-.4, -.8, .1), s=0.6, c='w')
formula.crop(0.2, 0.4)  # crop top and bottom 20% and 40%

# Time-stepping
u = Function(V)
for n in range(num_steps):

    # Compute solution
    solve(a == L, u, bc)

    # Plot solution
    plot(u, formula, scalarbar=False, interactive=False)

    # Update previous solution
    u_n.assign(u)
예제 #3
0
파일: stokes.py 프로젝트: wroldwiedbwe/vedo
# 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)

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

##################################################################### vedo
f = r'-\nabla \cdot(\nabla u+p I)=f ~\mathrm{in}~\Omega'
formula = Latex(f, pos=(0.55, 0.45, -.05), s=0.1)

plot(u,
     formula,
     at=0,
     N=2,
     mode='mesh and arrows',
     scale=.03,
     wireframe=True,
     scalarbar=False,
     style=1)
plot(p, at=1, text="pressure", cmap='rainbow', interactive=False)

##################################################################### streamlines
# A list of seed points (can be automatic: just comment out 'probes')
ally = np.linspace(0, 1, num=100)
예제 #4
0
from dolfin import *
from mshr   import Circle, generate_mesh
from vedo.dolfin import plot, printc, Latex
# Credits:
# https://github.com/pf4d/fenics_scripts/blob/master/pi_estimate.py

domain = Circle(Point(0.0,0.0), 1.0)
   
    
for res in [2**k for k in range(7)]:
	mesh = generate_mesh(domain, res)
	A    = assemble(Constant(1) * dx(domain=mesh))
	printc("resolution = %i, \t A-pi = %.5e" % (res, A-pi))

printc('~pi is about', A, c='yellow')

l = Latex(r'\mathrm{Area}(r)=\pi=\int\int_D 1 \cdot d(x,y)', s=0.3)
l.crop(0.3,0.3).z(0.1) # crop invisible top and bottom and set at z=0.1

plot(mesh, l, alpha=0.4, ztitle='', style=1, axes=3)