#!/usr/bin/env python3




##################################################
## DEPENDENCIES
import sys
import os
import os.path
try:
    import builtins as builtin
except ImportError:
    import __builtin__ as builtin
from os.path import getmtime, exists
import time
import types
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import *
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
from Cheetah.compat import unicode
from xpdeint.Segments.Integrators._Stepper import _Stepper

##################################################
## MODULE CONSTANTS
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '3.2.6.post2'
__CHEETAH_versionTuple__ = (3, 2, 6, 'post', 2)
__CHEETAH_genTime__ = 1634954792.8235543
__CHEETAH_genTimestamp__ = 'Sat Oct 23 13:06:32 2021'
__CHEETAH_src__ = '/home/mattias/xmds-3.0.0/admin/staging/xmds-3.1.0/xpdeint/Segments/Integrators/RK45Stepper.tmpl'
__CHEETAH_srcLastModified__ = 'Thu Apr  4 16:29:24 2019'
__CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'

if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
    raise AssertionError(
      'This template was compiled with Cheetah version'
      ' %s. Templates compiled before version %s must be recompiled.'%(
         __CHEETAH_version__, RequiredCheetahVersion))

##################################################
## CLASSES

class RK45Stepper(_Stepper):

    ##################################################
    ## CHEETAH GENERATED METHODS


    def __init__(self, *args, **KWs):

        super(RK45Stepper, self).__init__(*args, **KWs)
        if not self._CHEETAH__instanceInitialized:
            cheetahKWArgs = {}
            allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
            for k,v in KWs.items():
                if k in allowedKWs: cheetahKWArgs[k] = v
            self._initCheetahInstance(**cheetahKWArgs)
        

    def name(self, **KWS):



        ## Generated from @def name: RK45 at line 26, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        write('''RK45''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def localInitialise(self, **KWS):


        """
        Initialise all of the Cash-Karp coefficients, etc.
        """

        ## CHEETAH: generated from @def localInitialise at line 35, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        _v = super(RK45Stepper, self).localInitialise()
        if _v is not None: write(_filter(_v))
        # 
        write('''
// Cash-Karp coefficients
real _a_raw[7];
real _a[7];
real _b[7][7];
real _c[7];
real _cs[7];
// linear combinations for the (k_i)s
real _d[4];
real _e[5];
real _f[6];
real _g[7];

_a_raw[0]=0.0;
_a_raw[1]=0.0;
_a_raw[2]=1.0/5;
_a_raw[3]=3.0/10;
_a_raw[4]=3.0/5;
_a_raw[5]=1.0;
_a_raw[6]=7.0/8.0;

_a[0]=0.0;
_a[1]=0.0;
for(long _i0 = 2; _i0 < 7; _i0++)
  _a[_i0] = _a_raw[_i0] - _a_raw[_i0-1];

_b[2][1]=1.0/5;
_b[3][1]=3.0/40;
_b[3][2]=9.0/40;
_b[4][1]=3.0/10;
_b[4][2]=-9.0/10;
_b[4][3]=6.0/5;
_b[5][1]=-11.0/54;
_b[5][2]=5.0/2;
_b[5][3]=-70.0/27;
_b[5][4]=35.0/27;
_b[6][1]=1631.0/55296;
_b[6][2]=175.0/512;
_b[6][3]=575.0/13824;
_b[6][4]=44275.0/110592;
_b[6][5]=253.0/4096;

_c[0]=0.0;
_c[1]=37.0/378;
_c[2]=0.0;
_c[3]=250.0/621;
_c[4]=125.0/594;
_c[5]=0.0;
_c[6]=512.0/1771;

_cs[0]=0.0;
_cs[1]=2825.0/27648;
_cs[2]=0.0;
_cs[3]=18575.0/48384;
_cs[4]=13525.0/55296;
_cs[5]=277.0/14336;
_cs[6]=1.0/4;

_d[0]=0.0;
_d[1]=1.0-_b[3][1]/_c[1];
_d[2]=_b[3][1]/_c[1];
_d[3]=_b[3][2];

_e[0]=0.0;
_e[1]=1.0-_b[4][1]/_c[1];
_e[2]=_b[4][1]/_c[1];
_e[3]=_b[4][2];
_e[4]=_b[4][3];

_f[0]=0.0;
_f[1]=1.0-_b[5][1]/_c[1];
_f[2]=_b[5][1]/_c[1];
_f[3]=_b[5][2];
_f[4]=_b[5][3]-_b[5][1]/_c[1]*_c[3];
_f[5]=_b[5][4]-_b[5][1]/_c[1]*_c[4];

real _den=_c[1]*_cs[4]-_cs[1]*_c[4];
_g[0]=0.0;
_g[1]=( _b[6][4]*(_cs[1]-_c[1]) + _b[6][1]*(_c[4]-_cs[4]) )/_den + 1.0;
_g[2]=  _b[6][2];
_g[3]=( _b[6][4]*(_cs[1]*_c[3] - _c[1]*_cs[3]) + _b[6][1]*(_cs[3]*_c[4] - _c[3]*_cs[4]) )/_den + _b[6][3];
_g[4]=( _b[6][1]*_cs[4]-_b[6][4]*_cs[1] )/_den;
_g[5]=  _b[6][5] + _cs[5]*( _b[6][1]*_c[4]-_b[6][4]*_c[1] )/_den;
_g[6]=( -_b[6][1]*_c[4]+_b[6][4]*_c[1] )/_den;
''')
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def singleIntegrationStep(self, function, **KWS):



        ## CHEETAH: generated from @def singleIntegrationStep($function) at line 132, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        arguments = {'_step': '_step'}
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # '${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 135, col 1
        if _v is not None: write(_filter(_v, rawExpr='${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 135, col 1.
        write('''
// a_k = y1
''')
        _v = VFFSL(SL,"copyVectors",False)(VFFSL(SL,"integrationVectors",True), '_akfield') # "${copyVectors($integrationVectors, '_akfield')}" on line 138, col 1
        if _v is not None: write(_filter(_v, rawExpr="${copyVectors($integrationVectors, '_akfield')}")) # from line 138, col 1.
        write('''
''')
        _v = VFFSL(SL,"callFunction",False)('nonconstantIPFields', arguments, _exponent = 1, parentFunction=function) # "${callFunction('nonconstantIPFields', arguments, _exponent = 1, parentFunction=function)}" on line 140, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('nonconstantIPFields', arguments, _exponent = 1, parentFunction=function)}")) # from line 140, col 1.
        write('''

// a_i = D(a_2*dt)[y1]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +1, parentFunction=function) # "${callFunction('ipEvolve', arguments, _exponent = +1, parentFunction=function)}" on line 143, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('ipEvolve', arguments, _exponent = +1, parentFunction=function)}")) # from line 143, col 1.
        write('''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # '${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 144, col 1
        if _v is not None: write(_filter(_v, rawExpr='${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 144, col 1.
        write('''
// y2 = y1
''')
        _v = VFFSL(SL,"copyVectors",False)(VFFSL(SL,"integrationVectors",True), '_checkfield') # "${copyVectors($integrationVectors, '_checkfield')}" on line 147, col 1
        if _v is not None: write(_filter(_v, rawExpr="${copyVectors($integrationVectors, '_checkfield')}")) # from line 147, col 1.
        write('''
// a_i = y1
''')
        _v = VFFSL(SL,"copyVectors",False)(VFFSL(SL,"integrationVectors",True), '_aifield') # "${copyVectors($integrationVectors, '_aifield')}" on line 150, col 1
        if _v is not None: write(_filter(_v, rawExpr="${copyVectors($integrationVectors, '_aifield')}")) # from line 150, col 1.
        write('''
''')
        for vector in VFFSL(SL,"integrationVectors",True): # generated from line 152, col 3
            write('''_active_''')
            _v = VFFSL(SL,"vector.id",True) # '${vector.id}' on line 153, col 9
            if _v is not None: write(_filter(_v, rawExpr='${vector.id}')) # from line 153, col 9.
            write(''' = _akfield_''')
            _v = VFFSL(SL,"vector.id",True) # '${vector.id}' on line 153, col 33
            if _v is not None: write(_filter(_v, rawExpr='${vector.id}')) # from line 153, col 33.
            write(''';
''')
        write('''
// a_k = G[a_k, t]
''')
        _v = VFFSL(SL,"callFunction",False)('deltaA', arguments, parentFunction=function) # "${callFunction('deltaA', arguments, parentFunction=function)}" on line 157, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('deltaA', arguments, parentFunction=function)}")) # from line 157, col 1.
        write('''

// a_k = D(a_2*dt)[a_k]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +1, parentFunction=function) # "${callFunction('ipEvolve', arguments, _exponent = +1, parentFunction=function)}" on line 160, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('ipEvolve', arguments, _exponent = +1, parentFunction=function)}")) # from line 160, col 1.
        write('''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # '${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 161, col 1
        if _v is not None: write(_filter(_v, rawExpr='${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 161, col 1.
        write('''
''')
        _v = VFFSL(SL,"loopOverVectorsWithInnerContentTemplate",False)(VFFSL(SL,"integrationVectors",True),
"""// y1 = y1 + c_1*a_k
_${vector.id}[$index] += _c[1]*_akfield_${vector.id}[$index];
// y2 = y2 + cs_1*a_k
_checkfield_${vector.id}[$index] += _cs[1]*_akfield_${vector.id}[$index];
// a_k = a_i + b_21*a_k
_akfield_${vector.id}[$index] = _aifield_${vector.id}[$index] + _b[2][1]*_akfield_${vector.id}[$index];
""", basis = VFFSL(SL,"homeBasis",True))
        if _v is not None: write(_filter(_v, rawExpr='${loopOverVectorsWithInnerContentTemplate($integrationVectors,\n"""// y1 = y1 + c_1*a_k\n_${vector.id}[$index] += _c[1]*_akfield_${vector.id}[$index];\n// y2 = y2 + cs_1*a_k\n_checkfield_${vector.id}[$index] += _cs[1]*_akfield_${vector.id}[$index];\n// a_k = a_i + b_21*a_k\n_akfield_${vector.id}[$index] = _aifield_${vector.id}[$index] + _b[2][1]*_akfield_${vector.id}[$index];\n""", basis = $homeBasis)}')) # from line 163, col 1.
        write('''
''')
        _v = VFFSL(SL,"propagationDimension",True) # '${propagationDimension}' on line 172, col 1
        if _v is not None: write(_filter(_v, rawExpr='${propagationDimension}')) # from line 172, col 1.
        write(''' += _a[2] * _step;

''')
        _v = VFFSL(SL,"callFunction",False)('nonconstantIPFields', arguments, _exponent = 2, parentFunction=function) # "${callFunction('nonconstantIPFields', arguments, _exponent = 2, parentFunction=function)}" on line 174, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('nonconstantIPFields', arguments, _exponent = 2, parentFunction=function)}")) # from line 174, col 1.
        write('''

''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = -2, parentFunction=function) # "${callFunction('ipEvolve', arguments, _exponent = -2, parentFunction=function)}" on line 176, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('ipEvolve', arguments, _exponent = -2, parentFunction=function)}")) # from line 176, col 1.
        write('''

// a_k = G[a_k, t + aa_2*dt]
''')
        _v = VFFSL(SL,"callFunction",False)('deltaA', arguments, parentFunction=function) # "${callFunction('deltaA', arguments, parentFunction=function)}" on line 179, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('deltaA', arguments, parentFunction=function)}")) # from line 179, col 1.
        write('''

''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +2, parentFunction=function) # "${callFunction('ipEvolve', arguments, _exponent = +2, parentFunction=function)}" on line 181, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('ipEvolve', arguments, _exponent = +2, parentFunction=function)}")) # from line 181, col 1.
        write('''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # '${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 182, col 1
        if _v is not None: write(_filter(_v, rawExpr='${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 182, col 1.
        write('''
// c_2 == cs_2 == 0
''')
        _v = VFFSL(SL,"loopOverVectorsWithInnerContentTemplate",False)(VFFSL(SL,"integrationVectors",True),
"""// a_j = d_1*a_i + d_2*y1 + d_3*a_k
_ajfield_${vector.id}[$index] = _d[1]*_aifield_${vector.id}[$index] + _d[2]*_${vector.id}[$index] + _d[3]*_akfield_${vector.id}[$index];
""", basis = VFFSL(SL,"homeBasis",True))
        if _v is not None: write(_filter(_v, rawExpr='${loopOverVectorsWithInnerContentTemplate($integrationVectors,\n"""// a_j = d_1*a_i + d_2*y1 + d_3*a_k\n_ajfield_${vector.id}[$index] = _d[1]*_aifield_${vector.id}[$index] + _d[2]*_${vector.id}[$index] + _d[3]*_akfield_${vector.id}[$index];\n""", basis = $homeBasis)}')) # from line 185, col 1.
        write('''
''')
        _v = VFFSL(SL,"propagationDimension",True) # '${propagationDimension}' on line 190, col 1
        if _v is not None: write(_filter(_v, rawExpr='${propagationDimension}')) # from line 190, col 1.
        write(''' += _a[3] * _step;

''')
        for vector in VFFSL(SL,"integrationVectors",True): # generated from line 192, col 3
            write('''_active_''')
            _v = VFFSL(SL,"vector.id",True) # '${vector.id}' on line 193, col 9
            if _v is not None: write(_filter(_v, rawExpr='${vector.id}')) # from line 193, col 9.
            write(''' = _ajfield_''')
            _v = VFFSL(SL,"vector.id",True) # '${vector.id}' on line 193, col 33
            if _v is not None: write(_filter(_v, rawExpr='${vector.id}')) # from line 193, col 33.
            write(''';
''')
        write('''
''')
        _v = VFFSL(SL,"callFunction",False)('nonconstantIPFields', arguments, _exponent = 3, parentFunction=function) # "${callFunction('nonconstantIPFields', arguments, _exponent = 3, parentFunction=function)}" on line 196, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('nonconstantIPFields', arguments, _exponent = 3, parentFunction=function)}")) # from line 196, col 1.
        write('''

// a_j = D((a_3 - a_2)*dt)[a_j]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = -3, parentFunction=function) # "${callFunction('ipEvolve', arguments, _exponent = -3, parentFunction=function)}" on line 199, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('ipEvolve', arguments, _exponent = -3, parentFunction=function)}")) # from line 199, col 1.
        write('''

// a_j = G[a_j, t + aa_3*dt]
''')
        _v = VFFSL(SL,"callFunction",False)('deltaA', arguments, parentFunction=function) # "${callFunction('deltaA', arguments, parentFunction=function)}" on line 202, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('deltaA', arguments, parentFunction=function)}")) # from line 202, col 1.
        write('''

// a_j = D(-(a_3 - a_2)*dt)[a_j]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +3, parentFunction=function) # "${callFunction('ipEvolve', arguments, _exponent = +3, parentFunction=function)}" on line 205, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('ipEvolve', arguments, _exponent = +3, parentFunction=function)}")) # from line 205, col 1.
        write('''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # '${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 206, col 1
        if _v is not None: write(_filter(_v, rawExpr='${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 206, col 1.
        write('''
''')
        _v = VFFSL(SL,"loopOverVectorsWithInnerContentTemplate",False)(VFFSL(SL,"integrationVectors",True),
"""// a_l = e_1*a_i + e_2*y1 + e_3*a_k + e_4*a_j
_alfield_${vector.id}[$index] = _e[1]*_aifield_${vector.id}[$index] + _e[2]*_${vector.id}[$index] + _e[3]*_akfield_${vector.id}[$index] + _e[4]*_ajfield_${vector.id}[$index];
// y1 = y1 + c_3*a_j
_${vector.id}[$index] += _c[3]*_ajfield_${vector.id}[$index];
// y2 = y2 + cs_3*a_j
_checkfield_${vector.id}[$index] += _cs[3]*_ajfield_${vector.id}[$index];
""", basis = VFFSL(SL,"homeBasis",True))
        if _v is not None: write(_filter(_v, rawExpr='${loopOverVectorsWithInnerContentTemplate($integrationVectors,\n"""// a_l = e_1*a_i + e_2*y1 + e_3*a_k + e_4*a_j\n_alfield_${vector.id}[$index] = _e[1]*_aifield_${vector.id}[$index] + _e[2]*_${vector.id}[$index] + _e[3]*_akfield_${vector.id}[$index] + _e[4]*_ajfield_${vector.id}[$index];\n// y1 = y1 + c_3*a_j\n_${vector.id}[$index] += _c[3]*_ajfield_${vector.id}[$index];\n// y2 = y2 + cs_3*a_j\n_checkfield_${vector.id}[$index] += _cs[3]*_ajfield_${vector.id}[$index];\n""", basis = $homeBasis)}')) # from line 208, col 1.
        write('''
''')
        _v = VFFSL(SL,"propagationDimension",True) # '${propagationDimension}' on line 217, col 1
        if _v is not None: write(_filter(_v, rawExpr='${propagationDimension}')) # from line 217, col 1.
        write(''' += _a[4] * _step;

''')
        for vector in VFFSL(SL,"integrationVectors",True): # generated from line 219, col 3
            write('''_active_''')
            _v = VFFSL(SL,"vector.id",True) # '${vector.id}' on line 220, col 9
            if _v is not None: write(_filter(_v, rawExpr='${vector.id}')) # from line 220, col 9.
            write(''' = _alfield_''')
            _v = VFFSL(SL,"vector.id",True) # '${vector.id}' on line 220, col 33
            if _v is not None: write(_filter(_v, rawExpr='${vector.id}')) # from line 220, col 33.
            write(''';
''')
        write('''
''')
        _v = VFFSL(SL,"callFunction",False)('nonconstantIPFields', arguments, _exponent = 4, parentFunction=function) # "${callFunction('nonconstantIPFields', arguments, _exponent = 4, parentFunction=function)}" on line 223, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('nonconstantIPFields', arguments, _exponent = 4, parentFunction=function)}")) # from line 223, col 1.
        write('''

// a_l = D((a_4 - a_2)*dt)[a_l]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = -4, parentFunction=function) # "${callFunction('ipEvolve', arguments, _exponent = -4, parentFunction=function)}" on line 226, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('ipEvolve', arguments, _exponent = -4, parentFunction=function)}")) # from line 226, col 1.
        write('''

// a_l = G[a_l, t + aa_4*dt]
''')
        _v = VFFSL(SL,"callFunction",False)('deltaA', arguments, parentFunction=function) # "${callFunction('deltaA', arguments, parentFunction=function)}" on line 229, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('deltaA', arguments, parentFunction=function)}")) # from line 229, col 1.
        write('''

// a_l = D(-(a_4 - a_2)*dt)[a_l]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +4, parentFunction=function) # "${callFunction('ipEvolve', arguments, _exponent = +4, parentFunction=function)}" on line 232, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('ipEvolve', arguments, _exponent = +4, parentFunction=function)}")) # from line 232, col 1.
        write('''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # '${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 233, col 1
        if _v is not None: write(_filter(_v, rawExpr='${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 233, col 1.
        write('''
''')
        _v = VFFSL(SL,"loopOverVectorsWithInnerContentTemplate",False)(VFFSL(SL,"integrationVectors",True),
"""// y1 = y1 + c_4*a_l
_${vector.id}[$index] += _c[4]*_alfield_${vector.id}[$index];
// y2 = y2 + cs_4*a_l
_checkfield_${vector.id}[$index] += _cs[4]*_alfield_${vector.id}[$index];
// a_l = f_1*a_i + f_2*y1 + f_3*a_k + f_4*a_j + f_5*a_l
_alfield_${vector.id}[$index] = _f[1]*_aifield_${vector.id}[$index] + _f[2]*_${vector.id}[$index] + _f[3]*_akfield_${vector.id}[$index] + _f[4]*_ajfield_${vector.id}[$index] + _f[5]*_alfield_${vector.id}[$index];
""", basis = VFFSL(SL,"homeBasis",True))
        if _v is not None: write(_filter(_v, rawExpr='${loopOverVectorsWithInnerContentTemplate($integrationVectors,\n"""// y1 = y1 + c_4*a_l\n_${vector.id}[$index] += _c[4]*_alfield_${vector.id}[$index];\n// y2 = y2 + cs_4*a_l\n_checkfield_${vector.id}[$index] += _cs[4]*_alfield_${vector.id}[$index];\n// a_l = f_1*a_i + f_2*y1 + f_3*a_k + f_4*a_j + f_5*a_l\n_alfield_${vector.id}[$index] = _f[1]*_aifield_${vector.id}[$index] + _f[2]*_${vector.id}[$index] + _f[3]*_akfield_${vector.id}[$index] + _f[4]*_ajfield_${vector.id}[$index] + _f[5]*_alfield_${vector.id}[$index];\n""", basis = $homeBasis)}')) # from line 235, col 1.
        write('''
''')
        _v = VFFSL(SL,"propagationDimension",True) # '${propagationDimension}' on line 244, col 1
        if _v is not None: write(_filter(_v, rawExpr='${propagationDimension}')) # from line 244, col 1.
        write(''' += _a[5] * _step;

// a_l = G[a_l, t + aa_5*dt]
''')
        _v = VFFSL(SL,"callFunction",False)('deltaA', arguments, parentFunction=function) # "${callFunction('deltaA', arguments, parentFunction=function)}" on line 247, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('deltaA', arguments, parentFunction=function)}")) # from line 247, col 1.
        write('''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # '${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 248, col 1
        if _v is not None: write(_filter(_v, rawExpr='${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 248, col 1.
        write('''
// c_5 == 0
''')
        _v = VFFSL(SL,"loopOverVectorsWithInnerContentTemplate",False)(VFFSL(SL,"integrationVectors",True),
"""// y2 = y2 + cs_5*a_l
_checkfield_${vector.id}[$index] += _cs[5]*_alfield_${vector.id}[$index];
// a_l = g_1*a_i + g_2*a_k + g_3*a_j + g_4*y_1 + g_5*a_l + g_6*y2
_alfield_${vector.id}[$index] = _g[1]*_aifield_${vector.id}[$index] + _g[2]*_akfield_${vector.id}[$index] + _g[3]*_ajfield_${vector.id}[$index] + _g[4]*_${vector.id}[$index] + _g[5]*_alfield_${vector.id}[$index] + _g[6]*_checkfield_${vector.id}[$index];
""", basis = VFFSL(SL,"homeBasis",True))
        if _v is not None: write(_filter(_v, rawExpr='${loopOverVectorsWithInnerContentTemplate($integrationVectors,\n"""// y2 = y2 + cs_5*a_l\n_checkfield_${vector.id}[$index] += _cs[5]*_alfield_${vector.id}[$index];\n// a_l = g_1*a_i + g_2*a_k + g_3*a_j + g_4*y_1 + g_5*a_l + g_6*y2\n_alfield_${vector.id}[$index] = _g[1]*_aifield_${vector.id}[$index] + _g[2]*_akfield_${vector.id}[$index] + _g[3]*_ajfield_${vector.id}[$index] + _g[4]*_${vector.id}[$index] + _g[5]*_alfield_${vector.id}[$index] + _g[6]*_checkfield_${vector.id}[$index];\n""", basis = $homeBasis)}')) # from line 251, col 1.
        write('''
''')
        _v = VFFSL(SL,"propagationDimension",True) # '${propagationDimension}' on line 258, col 1
        if _v is not None: write(_filter(_v, rawExpr='${propagationDimension}')) # from line 258, col 1.
        write(''' += _a[6] * _step;

''')
        _v = VFFSL(SL,"callFunction",False)('nonconstantIPFields', arguments, _exponent = 5, parentFunction=function) # "${callFunction('nonconstantIPFields', arguments, _exponent = 5, parentFunction=function)}" on line 260, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('nonconstantIPFields', arguments, _exponent = 5, parentFunction=function)}")) # from line 260, col 1.
        write('''

// a_l = D((a_6 - a_2)*dt)[a_l]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = -5, parentFunction=function) # "${callFunction('ipEvolve', arguments, _exponent = -5, parentFunction=function)}" on line 263, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('ipEvolve', arguments, _exponent = -5, parentFunction=function)}")) # from line 263, col 1.
        write('''

// a_l = G[a_l, t + aa_6*dt]
''')
        _v = VFFSL(SL,"callFunction",False)('deltaA', arguments, parentFunction=function) # "${callFunction('deltaA', arguments, parentFunction=function)}" on line 266, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('deltaA', arguments, parentFunction=function)}")) # from line 266, col 1.
        write('''

// a_l = D(-(a_6 - a_2)*dt)[a_l]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +5, parentFunction=function) # "${callFunction('ipEvolve', arguments, _exponent = +5, parentFunction=function)}" on line 269, col 1
        if _v is not None: write(_filter(_v, rawExpr="${callFunction('ipEvolve', arguments, _exponent = +5, parentFunction=function)}")) # from line 269, col 1.
        write('''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # '${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 270, col 1
        if _v is not None: write(_filter(_v, rawExpr='${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 270, col 1.
        write('''
// c_5 == 0
''')
        _v = VFFSL(SL,"loopOverVectorsWithInnerContentTemplate",False)(VFFSL(SL,"integrationVectors",True),
"""// y1 = y1 + c_6*a_l
_${vector.id}[$index] += _c[6]*_alfield_${vector.id}[$index];
// y2 = y2 + cs_6*a_l
_checkfield_${vector.id}[$index] += _cs[6]*_alfield_${vector.id}[$index];
""", basis = VFFSL(SL,"homeBasis",True))
        if _v is not None: write(_filter(_v, rawExpr='${loopOverVectorsWithInnerContentTemplate($integrationVectors,\n"""// y1 = y1 + c_6*a_l\n_${vector.id}[$index] += _c[6]*_alfield_${vector.id}[$index];\n// y2 = y2 + cs_6*a_l\n_checkfield_${vector.id}[$index] += _cs[6]*_alfield_${vector.id}[$index];\n""", basis = $homeBasis)}')) # from line 273, col 1.
        write('''
// t -> t + dt
''')
        _v = VFFSL(SL,"propagationDimension",True) # '${propagationDimension}' on line 281, col 1
        if _v is not None: write(_filter(_v, rawExpr='${propagationDimension}')) # from line 281, col 1.
        write(''' -= _a[6]*_step;

''')
        for vector in VFFSL(SL,"integrationVectors",True): # generated from line 283, col 3
            write('''_active_''')
            _v = VFFSL(SL,"vector.id",True) # '${vector.id}' on line 284, col 9
            if _v is not None: write(_filter(_v, rawExpr='${vector.id}')) # from line 284, col 9.
            write(''' = _checkfield_''')
            _v = VFFSL(SL,"vector.id",True) # '${vector.id}' on line 284, col 36
            if _v is not None: write(_filter(_v, rawExpr='${vector.id}')) # from line 284, col 36.
            write(''';
''')
        write('''
''')
        for vector in VFFSL(SL,"integrationVectors",True): # generated from line 287, col 3
            write('''_active_''')
            _v = VFFSL(SL,"vector.id",True) # '${vector.id}' on line 288, col 9
            if _v is not None: write(_filter(_v, rawExpr='${vector.id}')) # from line 288, col 9.
            write(''' = _''')
            _v = VFFSL(SL,"vector.id",True) # '${vector.id}' on line 288, col 25
            if _v is not None: write(_filter(_v, rawExpr='${vector.id}')) # from line 288, col 25.
            write(''';
''')
        write('''
''')
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def writeBody(self, **KWS):



        ## CHEETAH: main method generated for this template
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        write('''
''')
        # 
        # RK45Stepper.tmpl
        # 
        # Created by Graham Dennis on 2007-11-16.
        # 
        # Copyright (c) 2007-2012, Graham Dennis
        # 
        # This program is free software: you can redistribute it and/or modify
        # it under the terms of the GNU General Public License as published by
        # the Free Software Foundation, either version 2 of the License, or
        # (at your option) any later version.
        # 
        # This program is distributed in the hope that it will be useful,
        # but WITHOUT ANY WARRANTY; without even the implied warranty of
        # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        # GNU General Public License for more details.
        # 
        # You should have received a copy of the GNU General Public License
        # along with this program.  If not, see <http://www.gnu.org/licenses/>.
        # 
        write('''




''')
        # 
        #   Single integration step (ARK45)
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        
    ##################################################
    ## CHEETAH GENERATED ATTRIBUTES


    _CHEETAH__instanceInitialized = False

    _CHEETAH_version = __CHEETAH_version__

    _CHEETAH_versionTuple = __CHEETAH_versionTuple__

    _CHEETAH_genTime = __CHEETAH_genTime__

    _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__

    _CHEETAH_src = __CHEETAH_src__

    _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__

    ipPropagationStepFractions = ['1.0', '4.0/5.0', '7.0/10.0', '2.0/5.0', '1.0/8.0']

    extraIntegrationArrayNames = ['akfield', 'aifield', 'ajfield', 'alfield', 'checkfield']

    errorFieldName = 'checkfield'

    resetFieldName = 'aifield'

    integrationOrder = 5.0

    _mainCheetahMethod_for_RK45Stepper = 'writeBody'

## END CLASS DEFINITION

if not hasattr(RK45Stepper, '_initCheetahAttributes'):
    templateAPIClass = getattr(RK45Stepper,
                               '_CHEETAH_templateClass',
                               Template)
    templateAPIClass._addCheetahPlumbingCodeToClass(RK45Stepper)


# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit https://cheetahtemplate.org/

##################################################
## if run from command line:
if __name__ == '__main__':
    from Cheetah.TemplateCmdLineIface import CmdLineIface
    CmdLineIface(templateObj=RK45Stepper()).run()


