Skip to content

Commit

Permalink
Use BoundaryDict in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
adtzlr committed Dec 8, 2024
1 parent b81504d commit b2e6242
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
4 changes: 3 additions & 1 deletion examples/ex01_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
dimensional vector-valued displacement field is initiated on the region.
"""

# sphinx_gallery_thumbnail_number = -1
import felupe as fem

cube = fem.Cube(a=(0, 0, 0), b=(2000, 100, 100), n=(101, 6, 6))
Expand All @@ -29,7 +30,8 @@

# %%
# A fixed boundary condition is applied on the left end of the beam.
boundaries = {"fixed": fem.dof.Boundary(displacement, fx=0)}
boundaries = fem.BoundaryDict(fixed=fem.dof.Boundary(displacement, fx=0))
boundaries.plot().show()

# %%
# The material behaviour is defined through a built-in isotropic linear-elastic material
Expand Down
3 changes: 1 addition & 2 deletions examples/ex02_plate-with-hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
mesh = fem.mesh.concatenate([face, face.mirror(normal=[-1, 1, 0]), rect])
mesh = mesh.sweep(decimals=5)

mesh.plot().show()

# %%
# A numeric quad-region created on the mesh in combination with a vector-valued
# displacement field represents the plate. The Boundary conditions for the symmetry
Expand All @@ -58,6 +56,7 @@
field = fem.FieldContainer([displacement])

boundaries = fem.dof.symmetry(displacement)
boundaries.plot().show()

# %%
# The material behaviour is defined through a built-in isotropic linear-elastic material
Expand Down
4 changes: 3 additions & 1 deletion examples/ex03_plasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
numeric region.
"""

# sphinx_gallery_thumbnail_number = -1
import numpy as np

import felupe as fem
Expand All @@ -34,7 +35,8 @@

# %%
# A fixed boundary condition is applied at :math:`x=0`.
boundaries = {"fixed": fem.dof.Boundary(displacement, fx=0)}
boundaries = fem.BoundaryDict(fixed=fem.dof.Boundary(displacement, fx=0))
boundaries.plot().show()

# %%
# The material behaviour is defined through a built-in isotropic linear-elastic plastic
Expand Down
11 changes: 5 additions & 6 deletions examples/ex05_rubber-metal-bushing.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
mesh = fem.mesh.stack(meshes.meshes)
x, y, z = mesh.points.T

mesh.plot().show()

# %%
# A global region as well as sub-regions for all materials are generated. The same
# applies to the fields, the material formulations as well as the solid bodies.
Expand All @@ -78,10 +76,11 @@
# %%
# The boundary conditions are created on the global displacement field. Masks are
# created for both the innermost and the outermost metal sheet faces.
boundaries = {
"inner": fem.dof.Boundary(field[0], mask=np.isclose(np.sqrt(y**2 + z**2), 25)),
"outer": fem.dof.Boundary(field[0], mask=np.isclose(np.sqrt(y**2 + z**2), 65)),
}
boundaries = fem.BoundaryDict(
inner=fem.dof.Boundary(field[0], mask=np.isclose(np.sqrt(y**2 + z**2), 25)),
outer=fem.dof.Boundary(field[0], mask=np.isclose(np.sqrt(y**2 + z**2), 65)),
)
boundaries.plot(show_lines=False).show()

# prescribed values for the innermost radial mesh points
table = fem.math.linsteps([0, 1], num=3)
Expand Down
5 changes: 3 additions & 2 deletions examples/ex07_engine-mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
# sub-meshes with shared points-array and a global mesh
meshes = fem.MeshContainer([metal, rubber, air], merge=True)
mesh = fem.mesh.concatenate(meshes).sweep()
meshes.plot(colors=["grey", "black", "white"]).show()

# %%
# A global region as well as sub-regions for all materials are generated. The same
Expand All @@ -65,11 +64,13 @@
inner = np.logical_and(only_cells_metal, radius <= 45)
outer = np.logical_and(only_cells_metal, radius > 45)

boundaries = dict(
boundaries = fem.BoundaryDict(
fixed=fem.Boundary(field[0], mask=outer),
u_x=fem.Boundary(field[0], mask=inner, skip=(0, 1)),
u_y=fem.Boundary(field[0], mask=inner, skip=(1, 0)),
)
plotter = meshes.plot(colors=["grey", "black", "white"])
boundaries.plot(plotter=plotter, scale=0.02).show()

# %%
# The material behaviour of the rubberlike solid is defined through a built-in hyperelastic
Expand Down
10 changes: 5 additions & 5 deletions examples/ex08_shear.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
region = fem.RegionQuad(mesh)
field = fem.FieldsMixed(region, n=3, planestrain=True)

boundaries = {
"fixed": fem.Boundary(field[0], fy=mesh.y.min()),
"control": fem.Boundary(field[0], fy=mesh.y.max(), skip=(0, 1)),
}
boundaries = fem.BoundaryDict(
fixed=fem.Boundary(field[0], fy=mesh.y.min()),
control=fem.Boundary(field[0], fy=mesh.y.max(), skip=(0, 1)),
)

dof0, dof1 = fem.dof.partition(field, boundaries)

Expand Down Expand Up @@ -97,7 +97,7 @@
centerpoint=mesh.npoints - 1,
)

plotter = mesh.plot()
plotter = boundaries.plot()
plotter = mpc.plot(plotter=plotter)
plotter.show()

Expand Down

0 comments on commit b2e6242

Please sign in to comment.