make_post_step_hook seems to be not-working #675
Unanswered
VarvaraGordeeva
asked this question in
Q&A
Replies: 2 comments 4 replies
-
What exactly are you asking? It would be helpful to have a minimal self-contained example with a clear description of the expected behavior. |
Beta Was this translation helpful? Give feedback.
4 replies
-
Thank you very much for your help!
пт, 14 мар. 2025 г. в 18:06, David Zwicker ***@***.***>:
… I had a brief look and can reproduce the problem. The problem could be
fixed on my side by replacing np.clip(state_data,0,1) by
np.clip(state_data,0,1,out=state_data) so state_data is replaced
in-place. However, note that py-pde version 0.21.0 is severely outdated,
so if you run into issues, please first update to a more up-to-date version.
—
Reply to this email directly, view it on GitHub
<#675 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BNILDLQPTRQOQO3Z2YHMPZT2ULH6HAVCNFSM6AAAAABY5EWJB2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENJQGA4DGOA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there,
I tried to use the hook function in my calculations. I found only two exapmles and description that the method "post_step_hook" will start after every time step. In both examples, I see solution which I need: if some values of the solved field are higher that one, they become equal to one (in my case it is mass fraction, which must be less or equal one but becomes slightly higher because of calculation error). My case is a little more complex: my "state" is a FieldCollection, and the mass fraction is one of the fields. I tried few variants (under "reaction" I mean that the mass fraction has no values higher than one):
def make_post_step_hook(self, state):
"""Create a hook function that is called after every time step."""
def post_step_hook(state_data, t, post_step_data):
"""Limit state 1 and abort when standard deviation exceeds 1."""
i = state_data > 1 # get violating entries
overshoot = (state_data[i] - 1).sum() # get total correction
state_data [i] = 1 # limit data entries
post_step_data += overshoot # accumulate total correction
if post_step_data > 400:
# Abort simulation when correction exceeds 400
# Note that the
post_step_data
of the previous step will be returned.raise StopIteration
return post_step_hook, 0.0 # hook function and initial value for data
4,5,6) used numpy.clip(state...,0,1) with the same variants: state_data, state, state[0] - no reaction
I see two variants here: either I use/write the class/method in wrong way, or the method is not working.
Beta Was this translation helpful? Give feedback.
All reactions