Register hybrid method for Hybrid Newton iteration

SCAKS supports more Pythonic way to register your own hybrid method to our Hybrid Newton iteration flow.

SCAKS provides a hybrid_method_register Python decorator for you to define and register your custom hybrid method to generate new initial coverages for next Newton’s iteration. For example, if you have create a micro-kinetc model model, you can

@model.hybrid_method_register
def ODE_integration(model, N):
    if model.log_allowed:
        model.logger.info('Use ODE integration to get new initial coverages...')

    end = 10
    span = 1e-2
    init_cvgs = model.solver.coverages

    new_cvgs = model.solver.solve_ode(time_end=end,
                                      time_span=span,
                                      initial_cvgs=init_cvgs)[-1]

    if model.log_allowed:
        model.logger.info('generate new initial coverages - success')

    return new_cvgs

Here there are two arguments for any hybrid method:

  1. model: current micro-kinetic model instance You can obtain different components like parser, solver … to give you essential data for new coverages guess.
  2. N: hybrid method attemp times Sometimes the coverages guess is related to the guess attemp time, e.g. the ODE integration strategy, N could be used for this purpose.

The return value must be a list containing new coverages guess.

Then when the model starts to run, the registered hybrid method would be invoked everytime the Newton’s method fails to converge.