File: ErrorCheck.tmpl

package info (click to toggle)
xmds2 3.0.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 52,068 kB
  • sloc: python: 63,652; javascript: 9,230; cpp: 3,929; ansic: 1,463; makefile: 121; sh: 54
file content (166 lines) | stat: -rw-r--r-- 5,483 bytes parent folder | download | duplicates (3)
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
@shBang #!/usr/bin/env python3

@*
ErrorCheck.tmpl

Created by Graham Dennis on 2007-08-26.

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/>.

*@
@extends xpdeint.Features._ErrorCheck

@def description: error check
@attr $featureName = 'ErrorCheck'

@def globals
  @#
  @super
  @#
bool _half_step;
  @for $momentGroup in $momentGroups
    @set $momentGroupOutputField = $momentGroup.outputField

// Arrays for full- and half-step moment group results
real* _${momentGroupOutputField.name}_fullstep;
  @end for
  @#
@end def

@def topLevelSequenceBegin($dict)
  @#
  @# Loop over moment groups allocating half step array
  @# and saving the pointer to the original array
  @# Note that we allocate the half step array now and not
  @# later when we actually need it so that if allocating it would
  @# cause us to run out of virtual memory, we do that at the *start*
  @# of the simulation, not half way through
  @for $momentGroup in $momentGroups
    @set $momentGroupOutputField = $momentGroup.outputField

_${momentGroupOutputField.name}_fullstep = _${momentGroup.processedVector.id};
// _${momentGroupOutputField.name}_halfstep has already been allocated
  @end for

for (_half_step = false; ; _half_step = true)
{
  if (!_half_step) {
    _LOG(_SIMULATION_LOG_LEVEL, "Beginning full step integration ...\n");
  @# Loop over the moment groups setting the output field to the fullstep fiel
  @for $momentGroup in $momentGroups
    @set $momentGroupOutputField = $momentGroup.outputField
    
    _active_${momentGroup.processedVector.id} = _${momentGroupOutputField.name}_fullstep;
  @end for
  }
  else {
    _LOG(_SIMULATION_LOG_LEVEL, "Beginning half step integration ...\n");
  @# Loop over the moment groups setting the output field to the already-allocated halfstep field
  @for $momentGroup in $momentGroups
    @set $momentGroupOutputField = $momentGroup.outputField
    
    @for aliasName in momentGroup.processedVector.aliases
      @if not aliasName==c"_${momentGroupOutputField.name}_halfstep"
    _active_${momentGroup.processedVector.id} = $aliasName;
    ${momentGroup.processedVector.functions['initialise'].call()}
      @end if
    @end for
    
    _active_${momentGroup.processedVector.id} = _${momentGroupOutputField.name}_halfstep;
  @end for
  }
  
  @silent $dict['extraIndent'] += 2
  @#
@end def

@def topLevelSequenceEnd($dict)
  
  if (_half_step)
      break;
}
  @silent $dict['extraIndent'] -= 2
@end def


@*
  This function returns a Cheetah template string suitable for passing to loopOverVectorsWithInnerContentTemplate
*@
@def writeOutFunctionImplementationBegin($dict)
  @#
  @set $momentGroup = dict['caller']
  @set $dependentVariables = dict['dependentVariables']
  @set $fieldName = $momentGroup.outputField.name
  @#
  @# So our job is to create 'error_' versions of all of the variables in the momentGroup's outputField.
  @set $newVariableDict = {'vector': $momentGroup.processedVector,
                           'arrayName': c'_${fieldName}_fullstep',
                           'components': ['error_' + component for component in $momentGroup.processedVector.components],
                          }
  @silent dependentVariables.append(newVariableDict)
  @#
  @# Now return the template that will be used to create the error vector
// Copy the error into the fullstep array
_${fieldName}_fullstep[\$index] = _${fieldName}_fullstep[\$index] - _${fieldName}_halfstep[\$index];
  @#
@end def

@def createFixedStepVariable($dict)

// If we are doing half-step integration, divide the step size by 2
if (_half_step)
  _step /= 2.0;
// Regardless, the step size for generated noise is the half-step
_noiseStep /= 2.0;
@end def

@def createToleranceVariable($dict)

// If we are doing half-step integration, divide the tolerance by 16
if (_half_step)
  _tolerance /= 16.0;
@end def

@def integrateFixedStepInnerLoopBegin($dict)
  @#
  @set $integrator = dict['caller']

// If we are doing half-step integration, then we need to do each integrate step twice (but with half the step size)
for (int _error_check_loop_iter = (_half_step ? 2 : 1); _error_check_loop_iter > 0; _error_check_loop_iter--) {
  @silent $dict['extraIndent'] += 2
  @#
@end def

@def integrateFixedStepInnerLoopEnd($dict)
  @#
}
  @silent $dict['extraIndent'] -= 2
  @#
@end def

@def writeOutFunctionImplementationBody($dict)
  @set $momentGroup = dict['caller']
  @set $processedVector = $momentGroup.processedVector
  @set $outputFieldName = momentGroup.outputField.name
_active_${processedVector.id} = _${outputFieldName}_fullstep;

${processedVector.findMaximum('_max_step_error', basis = momentGroup.outputBasis)}@slurp

// Restore active pointer for processed vector
_active_${processedVector.id} = _${outputFieldName}_halfstep;

_LOG(_SIMULATION_LOG_LEVEL, "Maximum step error in moment group ${momentGroup.number+1} was %e\n", _max_step_error);
@end def