Check solver iteration from goal object

Is there a way to obtain the current solver iteration from within a goal object?

I am writing a custom goal to do sphere-solid collision with an additional calculation to prevent tunnelling. The goal saves the particle positions in both the current and previous iterations to do this calculation.

The issue I’m having is to do with resetting the solver. The list of positions in the previous iteration is saved as a goal property, and I initialise this property in the constructor. I need to re-initialise this list when the solver is reset, and resetting doesn’t call the goal’s constructor again. I think the best way to do this is probably check the solver iteration in the Calculate method, and if it is zero, re-initialise the list. However, I haven’t found a way to get solver properties from within a goal.

@DanielPiker Any thoughts?

Hi @hkit.yong

This is a reasonable thing to want, but unfortunately there isn’t currently a way to get the solver iteration count or Reset events from within a goal, and I don’t see a way to change this without a change to the solver.

I faced a similar issue when making the LiveSoap goal (since it needs to reset its topology when the solver is reset). The way I resolved it there was to add a Reset input to the goal component, which then needs to be connected to the same parameter that is feeding into the Reset of the main solver.
If you know when resets happen, you can also count iterations by calls to the Calculate method of the goal.

I realise it’s not ideal though - I’ll have another look at making a way to access solver properties from within a goal (it’s easy enough to change, the harder part is doing so in a way that maintains compatibility with all the existing stuff).

I see. I should be able to work with having Reset connected to the goal for now as you suggested. Thanks!

1 Like