Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback mechanism to Newton-Raphson solvers #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jnbrunet
Copy link
Member

Solvers inheriting Caribou's Newton Raphson solver class can now register callbacks at different steps of a Newton iteration.

For example, the following C++ code prints the stiffness matrix just after the latter as been assembled:

using E = SofaCaribou::ode::NewtonRaphsonSolver::Event;
using NR = SofaCaribou::ode::NewtonRaphsonSolver;

solver->register_callback(E::MATRIX_ASSEMBLED, [](const NR & solver) {
    std::cout << solver.A();
});

Or to get the solution vector once solved in python

from SofaCaribou import NewtonRaphsonSolver
E = NewtonRaphsonSolver.Event

root.solver.register_callback(
    E.INCREMENT_SOLVED,   
    lambda s: print(s.dx())
)

The following events are available:

enum class Event : unsigned int {
    /** Event triggered at the very beginning of the Newton iteration. */
    ITERATION_BEGIN = 0,

    /** Event triggered after the system matrix has been assembled. */
    MATRIX_ASSEMBLED,
 
    /** Event triggered after the system matrix has been analyzed. */
    MATRIX_ANALYZED,

    /** Event triggered after the system matrix has been factorized. */
    MATRIX_FACTORIZED,

    /** Event triggered after the system solution vector has been solved. */
    INCREMENT_SOLVED,

    /** Event triggered after the system solution vector has been propagated through mappings. */
    INCREMENT_PROPAGATED,

    /** Event triggered after the system force vector has been updated. */
    RESIDUAL_UPDATED,

    /** Event triggered at the very end of the Newton iteration. */
    ITERATION_END,
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant