From e10333bde95a2cfa64003faccddcc1c49a84ecd8 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Sun, 2 Oct 2022 22:17:10 +0200 Subject: [PATCH 1/3] add user-callback to charact.curve --- felupe/mechanics/_curve.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/felupe/mechanics/_curve.py b/felupe/mechanics/_curve.py index 56fda933..d612a714 100644 --- a/felupe/mechanics/_curve.py +++ b/felupe/mechanics/_curve.py @@ -32,7 +32,7 @@ class CharacteristicCurve(Job): - def __init__(self, steps, boundary): + def __init__(self, steps, boundary, callback=lambda stepnumber, substepnumber, substep: None): super().__init__(steps, self._callback) @@ -40,12 +40,15 @@ def __init__(self, steps, boundary): self.x = [] self.y = [] self.res = None + self._cb = callback def _callback(self, stepnumber, substepnumber, substep): self.x.append(substep.x[0].values[self.boundary.points[0]]) self.y.append(force(substep.x, substep.fun, self.boundary)) self.res = substep + + self._cb(stepnumber, substepnumber, substep) def plot( self, From 338feb05e3e4cf620197bfa3479f966702d21336 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Sun, 2 Oct 2022 22:17:36 +0200 Subject: [PATCH 2/3] lint black --- felupe/mechanics/_curve.py | 6 ++++-- felupe/mechanics/_step.py | 2 +- felupe/mesh/_tools.py | 4 +++- tests/test_job.py | 2 +- tests/test_mesh.py | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/felupe/mechanics/_curve.py b/felupe/mechanics/_curve.py index d612a714..62ca3b61 100644 --- a/felupe/mechanics/_curve.py +++ b/felupe/mechanics/_curve.py @@ -32,7 +32,9 @@ class CharacteristicCurve(Job): - def __init__(self, steps, boundary, callback=lambda stepnumber, substepnumber, substep: None): + def __init__( + self, steps, boundary, callback=lambda stepnumber, substepnumber, substep: None + ): super().__init__(steps, self._callback) @@ -47,7 +49,7 @@ def _callback(self, stepnumber, substepnumber, substep): self.x.append(substep.x[0].values[self.boundary.points[0]]) self.y.append(force(substep.x, substep.fun, self.boundary)) self.res = substep - + self._cb(stepnumber, substepnumber, substep) def plot( diff --git a/felupe/mechanics/_step.py b/felupe/mechanics/_step.py index 5d810597..23856de9 100644 --- a/felupe/mechanics/_step.py +++ b/felupe/mechanics/_step.py @@ -48,7 +48,7 @@ def generate(self, **kwargs): "Generate all substeps." substeps = np.arange(self.nsubsteps) - + if not "x0" in kwargs.keys(): field = self.items[0].field else: diff --git a/felupe/mesh/_tools.py b/felupe/mesh/_tools.py index 60ee3eab..3038e060 100644 --- a/felupe/mesh/_tools.py +++ b/felupe/mesh/_tools.py @@ -194,7 +194,9 @@ def revolve(points, cells, cell_type, n=11, phi=180, axis=0): p = np.pad(points, ((0, 0), (0, 1))) R = rotation_matrix - points_new = np.vstack([(R(angle, dim + 1, axis=axis) @ p.T).T for angle in points_phi]) + points_new = np.vstack( + [(R(angle, dim + 1, axis=axis) @ p.T).T for angle in points_phi] + ) c = [cells + len(p) * a for a in np.arange(n)] diff --git a/tests/test_job.py b/tests/test_job.py index 5548f636..d602c60f 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -46,7 +46,7 @@ def test_job(): field, step = pre() job = fem.Job(steps=[step]) job.evaluate() - + field, step = pre() job = fem.Job(steps=[step]) job.evaluate(x0=field) diff --git a/tests/test_mesh.py b/tests/test_mesh.py index f7487d10..51a4376b 100644 --- a/tests/test_mesh.py +++ b/tests/test_mesh.py @@ -245,7 +245,7 @@ def test_runouts(): n = fe.mesh.runouts(m, values=[0.1], axis=0, centerpoint=[0, 0]) assert n.points[:, 1].max() == m.points[:, 1].max() * 1.1 - + mask = np.zeros(m.npoints, dtype=bool) n = fe.mesh.runouts(m, values=[0.1], axis=0, centerpoint=[0, 0], mask=mask) assert n.points[:, 1].max() == m.points[:, 1].max() From 6adc847731c71d11759699d37419adf491356279 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Sun, 2 Oct 2022 22:19:07 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1e32e9e2..2da36386 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ All notable changes to this project will be documented in this file. The format - Add `mesh.concatante(meshes)` to join a sequence of meshes with identical cell types. - Add `x0` argument to `Job.evaluate(x0=field)`. - Add `mask` argument to `mesh.runouts(mask=slice(None))`. +- Add `callback(stepnumber, substepnumber, substep)` argument to `CharacteristicCurve()` (like in `Job()`). ### Fixed - Fix ignored axis argument of `mesh.revolve(axis=1)`.