Skip to content

Commit

Permalink
Merge pull request #290 from adtzlr/add-job-curve-callback
Browse files Browse the repository at this point in the history
Add `callback` argument to `CharacteristicCurve()`
  • Loading branch information
adtzlr authored Oct 2, 2022
2 parents abc12cd + 6adc847 commit 8729153
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`.
Expand Down
7 changes: 6 additions & 1 deletion felupe/mechanics/_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,26 @@


class CharacteristicCurve(Job):
def __init__(self, steps, boundary):
def __init__(
self, steps, boundary, callback=lambda stepnumber, substepnumber, substep: None
):

super().__init__(steps, self._callback)

self.boundary = 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,
xaxis=0,
Expand Down
2 changes: 1 addition & 1 deletion felupe/mechanics/_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion felupe/mesh/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8729153

Please sign in to comment.