openmc icon indicating copy to clipboard operation
openmc copied to clipboard

Add capability for second guess (x1) to search_for_keff secant solve

Open lewisgross1296 opened this issue 5 months ago • 0 comments

Description

OpenMC uses scipy.optimize.newton to perform it's secant solve in search_for_keff. Typically secant solves require an initial guess (x0) and a next guess (x1) to define the equation of a line and do the secant solve to get the first computed value in the root finding algorithm. The scipy method will generate a second guess for you that is close to the first if you do not specify it

    else:
        # Secant method
        method = "secant"
        if x1 is not None:
            if x1 == x0:
                raise ValueError("x1 and x0 must be different")
            p1 = x1
        else:
            eps = 1e-4
            p1 = x0 * (1 + eps)
            p1 += (eps if p1 >= 0 else -eps)

Currently, we support only specifying x0, but some people may want to control the secant solve more by specifying x1 as well. See our discussion on the forum

Of course this opens up the possibility of defining bad searches, but I'd argue that already exists -- you kind of need to know what ballpark your in to do a good secant solve.

I propose to add an optional x1 that could be passed to the kwargs below -- in the case that it's not specified, just fallback and do what we currently do. https://github.com/openmc-dev/openmc/blob/9d9dcc26c5a6f7b8e06335cfe7a88d296db48710/openmc/search.py#L180-L202

Alternatives

Do nothing and allow scipy to pick the second guess as shown above

Compatibility

Only an addition to the API

lewisgross1296 avatar Jul 25 '25 18:07 lewisgross1296