Ejemplo n.º 1
0
def test_save():
    mesh = get_mesh(3)
    filename = Path("mesh.html")
    if filename.is_file():
        filename.unlink()

    plot(mesh, filename=filename, show=False)
    assert filename.is_file()
    filename.unlink()
Ejemplo n.º 2
0
def test_plot_dirichlet_bc(dim, wireframe):
    mesh = get_mesh(dim)

    # Mark the first subdomain with value 1
    fixed = df.CompiledSubDomain("near(x[0], 0) && on_boundary")

    V = df.VectorFunctionSpace(mesh, "CG", 2)
    zero = df.Constant((0.0, 0.0)) if dim == 2 else df.Constant(
        (0.0, 0.0, 0.0))
    bc = df.DirichletBC(V, zero, fixed)

    plot(bc, wireframe=wireframe, show=False)
Ejemplo n.º 3
0
def test_plot_cell_function(dim, wireframe):
    mesh = get_mesh(3)
    ffun = df.MeshFunction("size_t", mesh, dim)
    ffun.set_all(1)

    # left = df.CompiledSubDomain("x[0] < 0.5")
    # left_marker = 1
    # Not needed since they are allready set to 1
    # left.mark(ffun, left_marker)

    # Mark the second subdomain with value 2
    right = df.CompiledSubDomain("x[0] >= 0.5")
    right_marker = 2
    right.mark(ffun, right_marker)
    plot(ffun, show=False)
Ejemplo n.º 4
0
def test_plot_cellfunction():
    mesh = get_mesh(3)
    ffun = df.MeshFunction("size_t", mesh, 2)
    ffun.set_all(0)

    # Mark the first subdomain with value 1
    fixed = df.CompiledSubDomain("near(x[0], 0) && on_boundary")
    fixed_marker = 1
    fixed.mark(ffun, fixed_marker)

    # Mark the second subdomain with value 2
    free = df.CompiledSubDomain("near(x[0], 1) && on_boundary")
    free_marker = 2
    free.mark(ffun, free_marker)
    plot(ffun, show=False)
Ejemplo n.º 5
0
def test_plot_vector_cg_function(dim, wireframe, norm, normalize, degree,
                                 component):
    mesh = get_mesh(dim)
    V = df.VectorFunctionSpace(mesh, "CG", degree)
    u = df.Function(V)
    if dim == 2:
        u.interpolate(df.Expression(("1 + x[0]*x[0]", "x[1]*x[1]"), degree=1))
        if component == "z":
            return
    else:
        u.interpolate(
            df.Expression(("1 + x[0]*x[0]", "x[1]*x[1]", "x[2]*x[2]"),
                          degree=1))

    plot(
        u,
        norm=norm,
        wireframe=wireframe,
        show=False,
        component=component,
        normalize=normalize,
    )
Ejemplo n.º 6
0
# Make Dirichlet boundary conditions
def dirichlet_bc(W):
    V = W if W.sub(0).num_sub_spaces() == 0 else W.sub(0)
    return DirichletBC(V, Constant((0.0, 0.0, 0.0)), fixed)


# Make Neumann boundary conditions
neumann_bc = pulse.NeumannBC(traction=Constant(0.0), marker=free_marker)

# Collect Boundary Conditions
bcs = pulse.BoundaryConditions(dirichlet=(dirichlet_bc,), neumann=(neumann_bc,))

# Create problem
problem = pulse.MechanicsProblem(geometry, material, bcs)

# Solve problem
pulse.iterate.iterate(problem, activation, 0.1)

# Get displacement and hydrostatic pressure
u, p = problem.state.split(deepcopy=True)

V = dolfin.VectorFunctionSpace(mesh, "CG", 1)
u_int = interpolate(u, V)
new_mesh = Mesh(mesh)
dolfin.ALE.move(new_mesh, u_int)

fig = plot(mesh, show=False)
fig.add_plot(plot(new_mesh, color="red", show=False))
fig.show()
Ejemplo n.º 7
0
import pulse

geometry = pulse.HeartGeometry.from_file(pulse.mesh_paths["simple_ellipsoid"])
# geometry = pulse.geometries.prolate_ellipsoid_geometry(mesh_size_factor=3.0)
material = pulse.NeoHookean()
# material = pulse.Guccione()

# Parameter for the cardiac boundary conditions
bcs_parameters = pulse.MechanicsProblem.default_bcs_parameters()
bcs_parameters["base_spring"] = 1.0
bcs_parameters["base_bc"] = "fix_x"

# Create the problem
problem = pulse.MechanicsProblem(geometry,
                                 material,
                                 bcs_parameters=bcs_parameters)

# Suppose geometry is loaded with a pressure of 1 kPa
# and create the unloader
unloader = pulse.FixedPointUnloader(problem=problem, pressure=3.0)

# Unload the geometry
unloader.unload()

# Get the unloaded geometry
unloaded_geometry = unloader.unloaded_geometry

fig = plot(geometry.mesh, opacity=0.0, show=False)
fig.add_plot(plot(unloaded_geometry.mesh, color="red", show=False))
fig.show()
Ejemplo n.º 8
0
def test_plot_scalar_cg_function_space(dim, wireframe, degree):
    mesh = get_mesh(dim)
    V = df.FunctionSpace(mesh, "CG", degree)
    plot(V, wireframe=wireframe, show=False)
Ejemplo n.º 9
0
def test_plot_scalar_cg_function(dim, wireframe, scatter, degree):
    mesh = get_mesh(dim)
    V = df.FunctionSpace(mesh, "CG", degree)
    p = df.Function(V)
    p.interpolate(df.Expression("sin(x[0])", degree=1))
    plot(p, scatter=scatter, wireframe=wireframe, show=False)
Ejemplo n.º 10
0
def test_plot_two_mesh():
    mesh1 = df.UnitCubeMesh(2, 2, 2)
    mesh2 = df.BoxMesh(df.MPI.comm_world, df.Point(0.0, 0.0, 0.0),
                       df.Point(1.2, 0.5, 1.3), 3, 3, 3)
    fig = plot(mesh1, show=False)
    fig.add_plot(plot(mesh2, color="red", show=False))
Ejemplo n.º 11
0
def test_plot_mesh(dim, wireframe):
    mesh = get_mesh(dim)
    plot(mesh, wireframe=wireframe, show=False)
Ejemplo n.º 12
0
# Collect boundary conditions
bcs = pulse.BoundaryConditions(
    dirichlet=dirichlet_bc,
    neumann=neumann_bc,
    robin=robin_bc,
)

# Create the problem
problem = pulse.MechanicsProblem(geometry, material, bcs)

problem.solve()

# Solve the problem
pulse.iterate.iterate(problem, (lvp, activation), (1.0, 0.2))

# Get the solution
u, p = problem.state.split(deepcopy=True)

volume = geometry.cavity_volume(u=u)
print(f"Cavity volume = {volume}")

# Move mesh accoring to displacement
u_int = interpolate(u, dolfin.VectorFunctionSpace(geometry.mesh, "CG", 1))
mesh = Mesh(geometry.mesh)
dolfin.ALE.move(mesh, u_int)

fig = plot(geometry.mesh, color="red", show=False)
fig.add_plot(plot(mesh, show=False))
fig.show()
Ejemplo n.º 13
0
geometry = pulse.Geometry(
    mesh=mesh,
    microstructure=microstructure,
)
# -

activation = Function(dolfin.FunctionSpace(geometry.mesh, "R", 0))
activation.assign(Constant(0.2))
matparams = pulse.HolzapfelOgden.default_parameters()
material = pulse.HolzapfelOgden(
    activation=activation,
    parameters=matparams,
    f0=geometry.f0,
    s0=geometry.s0,
    n0=geometry.n0,
)

problem = RigidMotionProblem(geometry, material)

problem.solve()

u = problem.state.split(deepcopy=True)[1]
V = dolfin.VectorFunctionSpace(mesh, "CG", 1)
u_int = interpolate(u, V)
new_mesh = Mesh(mesh)
dolfin.ALE.move(new_mesh, u_int)

fig = plot(geometry.mesh, opacity=0.4, show=False)
fig.add_plot(plot(new_mesh, color="red", show=False))
fig.show()
Ejemplo n.º 14
0
# dolfin.ALE.move(mesh, u_int)

# +
# Get the solution
# u, p = problem.state.split(deepcopy=True)
# dolfin.File("u.pvd") << u
# -

W = dolfin.FunctionSpace(geometry.mesh, "CG", 1)
F = pulse.kinematics.DeformationGradient(u)
E = pulse.kinematics.GreenLagrangeStrain(F)
# Green strain normal to fiber direction
Ef = project(dolfin.inner(E * geometry.f0, geometry.f0), W)
# Save to file for visualization in paraview
# dolfin.File("Ef.pvd") << Ef
plot(Ef)

P = material.FirstPiolaStress(F, p)
# First piola stress normal to fiber direction
Pf = project(dolfin.inner(P * geometry.f0, geometry.f0), W)
# Save to file for visualization in paraview
# dolfin.File("Pf.pvd") << Pf
plot(Pf, colorscale="viridis")

T = material.CauchyStress(F, p)
f = F * geometry.f0
# Cauchy fiber stress
Tf = dolfin.project(dolfin.inner(T * f, f), W)
# Save to file for visualization in paraview
# dolfin.File("Tf.pvd") << Tf
plot(Tf, colorscale="jet")