Skip to content

Commit

Permalink
Merge pull request #739 from adtzlr/sort-principal-values
Browse files Browse the repository at this point in the history
Sort array of principal values in `Scene.plot()`
  • Loading branch information
adtzlr authored Apr 7, 2024
2 parents c98f213 + c4a078e commit 90d7548
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. The format

## [Unreleased]

### Fixed
- Sort array of principal values in descending order before plotting in `Scene.plot("Principal Values of ...")`. This ensures that the labels are matching user-defined arrays of principal values.

## [8.3.1] - 2024-04-06

### Fixed
Expand Down
8 changes: 4 additions & 4 deletions examples/ex08_shear.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ def callback(stepnumber, substepnumber, substep):
stretches = np.sqrt(eigh(C)[0])
# stretches = field.evaluate.strain(fun=lambda stretch: stretch, tensor=False)

view = field.view(
point_data={"Principal Values of Stretches": fem.project(stretches[::-1], region)}
)
stretches_at_points = fem.project(stretches, region)
stretches_at_points[-1] = 1 # mpc centerpoint

view = field.view(point_data={"Principal Values of Stretches": stretches_at_points})
plotter = view.plot(
"Principal Values of Stretches",
component=0,
clim=[stretches[-1].min(), stretches[-1].max()],
)
plotter = mpc.plot(plotter=plotter)
plotter.show()
Expand Down
2 changes: 1 addition & 1 deletion src/felupe/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "8.3.1"
__version__ = "8.4.0-dev"
9 changes: 5 additions & 4 deletions src/felupe/tools/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def plot(
}

if "Principal Values of " in data_label:
data[:] = np.flip(np.sort(data, axis=-1), axis=-1)
component_labels_dict[2] = [
"(Max. Principal)",
"(Min. Principal)",
Expand Down Expand Up @@ -434,7 +435,7 @@ def __init__(
"Principal Values of Logarithmic Strain": field.evaluate.strain(
tensor=False
)
.mean(-2)[::-1]
.mean(-2)
.T,
}
elif callable(project):
Expand All @@ -446,7 +447,7 @@ def __init__(
field.evaluate.strain(tensor=True, asvoigt=True), field.region
),
"Principal Values of Logarithmic Strain": project(
field.evaluate.strain(tensor=False)[::-1], field.region
field.evaluate.strain(tensor=False), field.region
),
}
else:
Expand Down Expand Up @@ -538,7 +539,7 @@ def __init__(
if project is None:
cell_data_from_solid[stress_label] = tovoigt(stress.mean(-2)).T
cell_data_from_solid[f"Principal Values of {stress_label}"] = (
eigvalsh(stress).mean(-2)[::-1].T
eigvalsh(stress).mean(-2).T
)
cell_data_from_solid[f"Equivalent of {stress_label}"] = (
equivalent_von_mises(stress).mean(-2).T
Expand All @@ -549,7 +550,7 @@ def __init__(
tovoigt(stress), solid.field.region
)
point_data_from_solid[f"Principal Values of {stress_label}"] = project(
eigvalsh(stress)[::-1], solid.field.region
eigvalsh(stress), solid.field.region
)
point_data_from_solid[f"Equivalent of {stress_label}"] = project(
equivalent_von_mises(stress), solid.field.region
Expand Down

0 comments on commit 90d7548

Please sign in to comment.