Skip to content

Commit

Permalink
Merge pull request #719 from adtzlr/add-mpc-plot
Browse files Browse the repository at this point in the history
Add `MultiPointConstraint.plot(**kwargs)`
  • Loading branch information
adtzlr authored Mar 22, 2024
2 parents 7ba4e66 + a3f6e95 commit f66f6ea
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. The format
### Added
- Add an argument to disable the (default) expansion of the points-array of a mesh in `mesh.expand(expand_dim=True)` and `mesh.revolve(expand_dim=True)`. E.g., this allows the expansion and / or revolution of a quad-mesh with points in 3d-space.
- Add `MultiPointContact.plot(offset=0, **kwargs)` to plot the rigid contact plane(s) or line(s) at a given offset.
- Add `MultiPointConstraint.plot(**kwargs)` to plot the lines of a multi-point constraint.

### Changed
- Don't raise an error if the total angle of revolution is greater than 360 degree in `mesh.revolve(phi=361)`.
Expand Down
11 changes: 8 additions & 3 deletions examples/ex08_shear.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
mesh = fem.Rectangle((0, 0), (L, H), n=(round(L / a), round(H / a)))
mesh.update(points=np.vstack((mesh.points, [0, 2 * H])))
mesh.points_without_cells = np.array([], dtype=bool)
mesh.plot().show()

# %%
# A numeric quad-region created on the mesh in combination with a vector-valued
Expand Down Expand Up @@ -106,6 +105,10 @@
centerpoint=mesh.npoints - 1,
)

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

# %%
# The shear movement is applied in substeps, which are each solved with an iterative
# newton-rhapson procedure. Inside an iteration, the force residual vector and the
Expand Down Expand Up @@ -145,8 +148,10 @@ def callback(stepnumber, substepnumber, substep):

stretches = fem.project(np.sqrt(eigh(C)[0]), region)

plotter = field.view(point_data={"Principal Values of Stretches": stretches})
plotter.plot("Principal Values of Stretches", component=0).show()
view = field.view(point_data={"Principal Values of Stretches": stretches})
plotter = view.plot("Principal Values of Stretches", component=0)
plotter = mpc.plot(plotter=plotter)
plotter.show()

# %%
# The shear force :math:`F_x` vs. the displacements :math:`u_x` and :math:`u_y`, all
Expand Down
16 changes: 16 additions & 0 deletions src/felupe/mechanics/_multipoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ def __init__(
self.results = Results(stress=False, elasticity=False)
self.assemble = Assemble(vector=self._vector, matrix=self._matrix)

def plot(self, plotter=None, color="black", **kwargs):
import pyvista as pv

if plotter is None:
plotter = pv.Plotter()

# get deformed points
x = self.mesh.points + self.field[0].values
x = np.pad(x, ((0, 0), (0, 3 - x.shape[1])))
pointa = x[self.centerpoint]

for pointb in x[self.points]:
plotter.add_mesh(pv.Line(pointa, pointb), color=color, **kwargs)

return plotter

def _vector(self, field=None, parallel=False):
"Calculate vector of residuals with RBE2 contributions."

Expand Down
7 changes: 7 additions & 0 deletions tests/test_mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ def test_mpc_plot_2d():
except ModuleNotFoundError:
pass

mpc = fem.MultiPointConstraint(field, [0, 1], -1)

try:
mpc.plot()
except ModuleNotFoundError:
pass


if __name__ == "__main__":
test_mpc()
Expand Down

0 comments on commit f66f6ea

Please sign in to comment.