Esempio n. 1
0
                 alpha=1,        # transparency of the mesh
                 lw=0.1,         # linewidth of mesh
                 scalarbar=None,
                 #lighting='plastic',
                 #elevation=-.3,
                 interactive=0)  # continue execution

    interactive()

if __name__ == "__main__":

    ot, dt, nt = 0, 1e-3, 150
    t = ot + np.arange(nt) * dt

    print("Computing wavefields over dolfin mesh")
    fpath = download("https://vedo.embl.es/examples/data/dolfin_fine.xml")
    mesh = Mesh(fpath)
    awefem(mesh, t, source_loc=(0.8, 0.8))

#    print('Computing wavefields over unit square')
#    mesh = UnitSquareMesh(100, 100)
#    u = awefem(mesh, t, source_loc=(0.8, 0.7))

#    print('Computing wavefields over unit circle')
#    domain = Circle(Point(0., 0.), 1)
#    mesh = generate_mesh(domain, 50)
#    u = awefem(mesh, t, source_time_function=sine_source)

#    print('Computing wavefields over unit cube')
#    print('need to set alpha=0.1 and warpZfactor=0')
#    mesh = UnitCubeMesh(15, 15, 15)
Esempio n. 2
0
"""
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 *
import numpy as np
from vedo.dolfin import plot, dataurl, download, Latex

# Load mesh and subdomains
fpath = download(dataurl+"dolfin_fine.xml")
mesh = Mesh(fpath)

fpath = download(dataurl+"dolfin_fine_subdomains.xml.gz")
sub_domains = MeshFunction("size_t", mesh, fpath)

# 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]
Esempio n. 3
0
#!/usr/bin/python3
#
"""Interpolate a jpg image to a mesh and plot it"""
from dolfin import *
import matplotlib.pyplot as plt
from vedo.dolfin import plot, download

scale = 0.1
fpath = download("https://vedo.embl.es/examples/data/images/embl_logo.jpg")
img = plt.imread(fpath)
print('Image shape is', img.shape)

img = img[:,:,1]
Nx, Ny = img.shape
mesh = RectangleMesh(Point(0,0,0),
                     Point(Ny*scale, Nx*scale,1), Ny, Nx)

class FE_image(UserExpression):
    def eval_cell(self, value, x, ufc_cell):
        p = Cell(mesh, ufc_cell.index).midpoint()
        i, j = int(p[1]/scale), int(p[0]/scale)
        value[:] = img[-(i+1), j]
    def value_shape(self):
        return ()

y = FE_image()
V = FunctionSpace(mesh, 'Lagrange', 1)
u = Function(V)
u.interpolate(y)

cam = dict(pos=(10.6, 3.71, 22.7),
Esempio n. 4
0
# A simple eigenvalue solver
# ==========================

from dolfin import *
from vedo.dolfin import download, plot

# Define mesh, function space
fpath = download("https://vedo.embl.es/examples/data/box_with_dent.xml.gz")
mesh = Mesh(fpath)
V = FunctionSpace(mesh, "Lagrange", 1)

# Define basis and bilinear form
u = TrialFunction(V)
v = TestFunction(V)
a = dot(grad(u), grad(v)) * dx

# Assemble stiffness form
A = PETScMatrix()
assemble(a, tensor=A)

# Create eigensolver
eigensolver = SLEPcEigenSolver(A)

# Compute all eigenvalues of A x = \lambda x
print("Computing eigenvalues. This can take a minute.")
eigensolver.solve()

# Extract largest (first) eigenpair
r, c, rx, cx = eigensolver.get_eigenpair(0)
print("Largest eigenvalue: ", r)
Esempio n. 5
0
"""
Solve the incompressible Navier-Stokes equations
on an L-shaped domain using Chorin's splitting method.
"""
from __future__ import print_function
from dolfin import *
from vedo.dolfin import ProgressBar, plot, download

# Print log messages only from the root process in parallel
parameters["std_out_all_processes"] = False

# Load mesh from file
fpath = download("https://vedo.embl.es/examples/data/lshape.xml.gz")
mesh = Mesh(fpath)

# Define function spaces (P2-P1)
V = VectorFunctionSpace(mesh, "Lagrange", 2)
Q = FunctionSpace(mesh, "Lagrange", 1)

# Define trial and test functions
u = TrialFunction(V)
p = TrialFunction(Q)
v = TestFunction(V)
q = TestFunction(Q)

# Set parameter values
dt = 0.01
T = 3
nu = 0.01

# Define time-dependent pressure boundary condition