File: RK45Stepper.py

package info (click to toggle)
xmds2 2.2.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 53,384 kB
  • ctags: 7,223
  • sloc: python: 54,076; cpp: 3,929; ansic: 1,463; makefile: 135; sh: 20
file content (649 lines) | stat: -rw-r--r-- 33,046 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
#!/usr/bin/env python




##################################################
## 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 xpdeint.Segments.Integrators._Stepper import _Stepper

##################################################
## MODULE CONSTANTS
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.4.4'
__CHEETAH_versionTuple__ = (2, 4, 4, 'development', 0)
__CHEETAH_genTime__ = 1413234540.119409
__CHEETAH_genTimestamp__ = 'Tue Oct 14 08:09:00 2014'
__CHEETAH_src__ = '/Users/graham/Library/XMDS/src/xmds2/admin/staging/xmds-2.2.2/xpdeint/Segments/Integrators/RK45Stepper.tmpl'
__CHEETAH_srcLastModified__ = 'Mon Oct 21 12:39:43 2013'
__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 24, 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(u'''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 33, 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(u'''
// 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 130, 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)) # u'${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 133, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 133, col 1.
        write(u'''
// a_k = y1
''')
        _v = VFFSL(SL,"copyVectors",False)(VFFSL(SL,"integrationVectors",True), '_akfield') # u"${copyVectors($integrationVectors, '_akfield')}" on line 136, col 1
        if _v is not None: write(_filter(_v, rawExpr=u"${copyVectors($integrationVectors, '_akfield')}")) # from line 136, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"callFunction",False)('nonconstantIPFields', arguments, _exponent = 1, parentFunction=function) # u"${callFunction('nonconstantIPFields', arguments, _exponent = 1, parentFunction=function)}" on line 138, col 1
        if _v is not None: write(_filter(_v, rawExpr=u"${callFunction('nonconstantIPFields', arguments, _exponent = 1, parentFunction=function)}")) # from line 138, col 1.
        write(u'''

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

// a_k = D(a_2*dt)[a_k]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +1, parentFunction=function) # u"${callFunction('ipEvolve', arguments, _exponent = +1, parentFunction=function)}" on line 158, col 1
        if _v is not None: write(_filter(_v, rawExpr=u"${callFunction('ipEvolve', arguments, _exponent = +1, parentFunction=function)}")) # from line 158, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # u'${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 159, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 159, col 1.
        write(u'''
''')
        _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=u'${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 161, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"propagationDimension",True) # u'${propagationDimension}' on line 170, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${propagationDimension}')) # from line 170, col 1.
        write(u''' += _a[2] * _step;

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

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

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

''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +2, parentFunction=function) # u"${callFunction('ipEvolve', arguments, _exponent = +2, parentFunction=function)}" on line 179, col 1
        if _v is not None: write(_filter(_v, rawExpr=u"${callFunction('ipEvolve', arguments, _exponent = +2, parentFunction=function)}")) # from line 179, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # u'${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 180, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 180, col 1.
        write(u'''
// 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=u'${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 183, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"propagationDimension",True) # u'${propagationDimension}' on line 188, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${propagationDimension}')) # from line 188, col 1.
        write(u''' += _a[3] * _step;

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

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

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

// a_j = D(-(a_3 - a_2)*dt)[a_j]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +3, parentFunction=function) # u"${callFunction('ipEvolve', arguments, _exponent = +3, parentFunction=function)}" on line 203, col 1
        if _v is not None: write(_filter(_v, rawExpr=u"${callFunction('ipEvolve', arguments, _exponent = +3, parentFunction=function)}")) # from line 203, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # u'${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 204, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 204, col 1.
        write(u'''
''')
        _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=u'${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 206, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"propagationDimension",True) # u'${propagationDimension}' on line 215, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${propagationDimension}')) # from line 215, col 1.
        write(u''' += _a[4] * _step;

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

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

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

// a_l = D(-(a_4 - a_2)*dt)[a_l]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +4, parentFunction=function) # u"${callFunction('ipEvolve', arguments, _exponent = +4, parentFunction=function)}" on line 230, col 1
        if _v is not None: write(_filter(_v, rawExpr=u"${callFunction('ipEvolve', arguments, _exponent = +4, parentFunction=function)}")) # from line 230, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # u'${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 231, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 231, col 1.
        write(u'''
''')
        _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=u'${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 233, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"propagationDimension",True) # u'${propagationDimension}' on line 242, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${propagationDimension}')) # from line 242, col 1.
        write(u''' += _a[5] * _step;

// a_l = G[a_l, t + aa_5*dt]
''')
        _v = VFFSL(SL,"callFunction",False)('deltaA', arguments, parentFunction=function) # u"${callFunction('deltaA', arguments, parentFunction=function)}" on line 245, col 1
        if _v is not None: write(_filter(_v, rawExpr=u"${callFunction('deltaA', arguments, parentFunction=function)}")) # from line 245, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # u'${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 246, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 246, col 1.
        write(u'''
// 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=u'${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 249, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"propagationDimension",True) # u'${propagationDimension}' on line 256, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${propagationDimension}')) # from line 256, col 1.
        write(u''' += _a[6] * _step;

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

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

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

// a_l = D(-(a_6 - a_2)*dt)[a_l]
''')
        _v = VFFSL(SL,"callFunction",False)('ipEvolve', arguments, _exponent = +5, parentFunction=function) # u"${callFunction('ipEvolve', arguments, _exponent = +5, parentFunction=function)}" on line 267, col 1
        if _v is not None: write(_filter(_v, rawExpr=u"${callFunction('ipEvolve', arguments, _exponent = +5, parentFunction=function)}")) # from line 267, col 1.
        write(u'''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"integrationVectors",True), VFFSL(SL,"homeBasis",True)) # u'${transformVectorsToBasis($integrationVectors, $homeBasis)}' on line 268, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${transformVectorsToBasis($integrationVectors, $homeBasis)}')) # from line 268, col 1.
        write(u'''
// 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=u'${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 271, col 1.
        write(u'''
// t -> t + dt
''')
        _v = VFFSL(SL,"propagationDimension",True) # u'${propagationDimension}' on line 279, col 1
        if _v is not None: write(_filter(_v, rawExpr=u'${propagationDimension}')) # from line 279, col 1.
        write(u''' -= _a[6]*_step;

''')
        for vector in VFFSL(SL,"integrationVectors",True): # generated from line 281, col 3
            write(u'''_active_''')
            _v = VFFSL(SL,"vector.id",True) # u'${vector.id}' on line 282, col 9
            if _v is not None: write(_filter(_v, rawExpr=u'${vector.id}')) # from line 282, col 9.
            write(u''' = _checkfield_''')
            _v = VFFSL(SL,"vector.id",True) # u'${vector.id}' on line 282, col 36
            if _v is not None: write(_filter(_v, rawExpr=u'${vector.id}')) # from line 282, col 36.
            write(u''';
''')
        write(u'''
''')
        for vector in VFFSL(SL,"integrationVectors",True): # generated from line 285, col 3
            write(u'''_active_''')
            _v = VFFSL(SL,"vector.id",True) # u'${vector.id}' on line 286, col 9
            if _v is not None: write(_filter(_v, rawExpr=u'${vector.id}')) # from line 286, col 9.
            write(u''' = _''')
            _v = VFFSL(SL,"vector.id",True) # u'${vector.id}' on line 286, col 25
            if _v is not None: write(_filter(_v, rawExpr=u'${vector.id}')) # from line 286, col 25.
            write(u''';
''')
        write(u'''
''')
        # 
        
        ########################################
        ## 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
        
        # 
        # 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(u'''




''')
        # 
        #   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 http://www.CheetahTemplate.org/

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