ukaea/PROCESS

Errror in calculation of temperature margin [BUG]

Closed this issue · 1 comments

A run-time error occurs in the calculation of the superconductor temperature margin, because a negative temperature thelium was sent to itersc in superconductors.py.

There are two different root finders used for calculating temperature margins - we know that neither is reliable. (They are the Newton-Raphson method in supercon in sctfcoil.py and secant_solve in maths_library.py.) It would be best to replace both by a root finder that works within preset bounds - for example scipy.optimize.brentq.

Temporary fix

I have corrected the test in the code, which previously was:

                if ttest <= 0:
                    error_handling.idiags[0] = lap
                    error_handling.fdiags[0] = ttest
                    error_handling.report_error(157)
                    break

to

                if ttest <= delt:
                    error_handling.idiags[0] = lap
                    error_handling.fdiags[0] = ttest
                    error_handling.report_error(157)
                    break

This escapes from the loop when the quantity ttestm = ttest - delt is less than zero, and sometimes allows Process to converge. Funnily enough, the error 157 is then not displayed.

Steps to reproduce

Expected behaviour

The root finder to calculate the temperature margin should never send a negative temperature for evaluation of the superconductor properties.

Evidence

The diagnostic print statement gives thelium and tc0eps.

Line 154 6.261 15.776698285176671
Line 154 0.002806361859818196 15.776698285176671
Line 154 -0.007193638140181804 15.776698285176671
/home/mkovari/PROCESS/process/superconductors.py:170: RuntimeWarning: invalid value encountered in scalar power
  bcrit = bc20eps * (1.0 - t**1.52)
/home/mkovari/PROCESS/process/superconductors.py:187: RuntimeWarning: invalid value encountered in scalar power
  jc2 = (1.0 - t**1.52) * (1.0 - t**2)  # t must be < 1 to avoid NaNs
Line 154 0.012806361859818196 15.776698285176671
Line 154 nan 15.776698285176671

Note that t = min(thelium / tc0eps, 0.9999).

Environment

  • Ubuntu 20.04.6 LTS

Additional context

The temperature margin is the difference between the current-sharing temperature and the operating temperature.
The current-sharing temperature is the temperature at which the critical current equals the operating current, at the operating field.

I have replaced the Newton-Raphson method in superconductors.py by scipy.optimize.brentq. Seems to work OK. The result object from brentq looks like this when full_output=True:

      converged: True
           flag: 'converged'
 function_calls: 7
     iterations: 6
           root: 6.252952820916195

There are 9 different superconductor options - I have only tested two, using the large tokamak scenario and SPR-45.

I now need to replace the secant solver used elsewhere in the code with brentq.