TDMS
Time Domain Maxwell Solver
Toggle main menu visibility
Loading...
Searching...
No Matches
interpolation_methods.h
Go to the documentation of this file.
1
/**
2
* @file interpolation_methods.h
3
* @author William Graham (ccaegra@ucl.ac.uk)
4
* @brief InterpScheme class methods and supporting functions
5
*
6
* Non InterpScheme methods are required to preserve functionality whilst
7
* testing new schemes
8
*/
9
#pragma once
10
11
#include <complex>
12
13
#include "
input_flags.h
"
14
15
/**
16
* @brief Defines our order of preference for the use of the various schemes.
17
*
18
* There should never be an instance in which we wish to use BLi to position 7 -
19
* this will take us to a point OUTSIDE the computational domain. However for
20
* completion purposes (and if we find a use for it), it is included.
21
*
22
* MODIFICATIONS TO THE ALIASED INTS WILL CHANGE THE ORDER OF SCHEME PREFERENCE!
23
*
24
* For bandlimited schemes, we have 8 equidistant datapoints and can
25
* interpolate to the midpoint of any pair of consecutive points, or "half a
26
* point spacing" to the right of the final data point. These "interpolation
27
* positions" (interp positions) are marked with "o" below: v0 v1 v2 v3 v4
28
* v5 v6 v7 o o o o o o o o We label these interp
29
* positions with the index of the point to the left: a data point at interp
30
* position 0 is effectively a data point "v0.5", being at the midpoint of v0
31
* and v1, for example.
32
*/
33
enum
scheme_value
{
34
BAND_LIMITED_0 = 4,
// use bandlimited interpolation w/ interp position = 0
35
BAND_LIMITED_1 = 6,
// use bandlimited interpolation w/ interp position = 1
36
BAND_LIMITED_2 = 8,
// use bandlimited interpolation w/ interp position = 2
37
BAND_LIMITED_3 = 9,
// use bandlimited interpolation w/ interp position = 3
38
// [Preferred method if available]
39
BAND_LIMITED_4 = 7,
// use bandlimited interpolation w/ interp position = 4
40
BAND_LIMITED_5 = 5,
// use bandlimited interpolation w/ interp position = 5
41
BAND_LIMITED_6 = 3,
// use bandlimited interpolation w/ interp position = 6
42
BAND_LIMITED_7 = 2,
// use bandlimited interpolation w/ interp position = 7
43
BAND_LIMITED_CELL_ZERO = 1,
// use bandlimited interpolation to interpolate to
44
// the centre of Yee cell 0
45
CUBIC_INTERP_MIDDLE =
46
0,
// cubic interpolation to middle 2 of 4 points (interp1)
47
CUBIC_INTERP_FIRST =
48
-1,
// cubic interpolation to first 2 of 4 points (interp2)
49
CUBIC_INTERP_LAST = -2
// cubic interpolation to last 2 of 4 points (interp3)
50
};
51
52
/** @brief Executes an interpolation scheme.
53
*
54
* The scheme that an instance executes is determined by the priority that is
55
* passed at construction.
56
*/
57
class
InterpolationScheme
{
58
private
:
59
// the "preference" or "value" of applying this scheme. It may be better to
60
// apply another scheme with a higher priority.
61
scheme_value
priority;
62
63
// the constants that will be used in the interpolation scheme.
64
double
scheme_coeffs[8];
65
66
public
:
67
/**
68
* @brief Construct a new interp Scheme object, by providing the scheme value
69
*
70
* @param value A value associtated to one of the possible schemes
71
*/
72
InterpolationScheme
(
scheme_value
value);
73
74
/* FETCH METHODS */
75
76
/**
77
* @brief Get the value object
78
*
79
* @return scheme_value
80
*/
81
scheme_value
get_priority
()
const
;
82
83
/* END FETCH METHODS */
84
85
/* The number of datapoints "to the left" of where we are planning to
86
interpolate to. For example, interpolating to interpolation position 0
87
requires 1 datapoint at a position before the location of the
88
interpolation, whilst interpolation position 6 requires there to be 7.
89
*/
90
int
number_of_datapoints_to_left;
91
92
// cubic and BLi schemes use different numbers of coefficients. To avoid
93
// switches, we store these variables.
94
int
first_nonzero_coeff, last_nonzero_coeff;
95
96
/**
97
* @brief Compute the number of non-zero coefficients in the interpolation
98
* scheme
99
*
100
* @return int Number of non-zero coefficients in the interpolation scheme
101
*/
102
int
num_nonzero_coeffs
()
const
;
103
104
/**
105
* @brief Executes the interpolation scheme on the data provided
106
*
107
* The interpolation schemes are all of the form
108
* interpolated_value = \sum_{i=0}^{7} scheme_coeffs[i] * v[i],
109
* so provided that the coefficients have been set correctly in construction
110
* (and the data gathered appropriately), we can run the same for loop for
111
* each interpolation scheme.
112
*
113
* For slight speedup, the actual sum performed loops over those i such that
114
* 0 <= first_nonzero_coeff <= i <= last_nonzero_coeff <= 7.
115
*
116
* @param v Sample datapoints to use in interpolation; v[0] should be the
117
* first of 8 values
118
* @param offset [Default 0] Read buffer from v[offset] rather than v[0]
119
* @return double Interpolated value
120
*/
121
template
<
typename
T>
122
T
interpolate
(
const
T *v,
const
int
offset = 0)
const
{
123
T interp_value = 0.;
124
for
(
int
ind = first_nonzero_coeff; ind <= last_nonzero_coeff; ind++) {
125
interp_value += scheme_coeffs[ind] * v[ind + offset];
126
}
127
return
interp_value;
128
};
129
130
/**
131
* @brief Determines whether another interpScheme has greater value than this
132
* one
133
*
134
* @param s The other interpScheme to compare against
135
* @return true This scheme has greater value
136
* @return false This scheme has lesser, or equal, value to s
137
*/
138
bool
is_better_than
(
const
InterpolationScheme
&s)
const
;
139
};
140
141
/* Constant members of the interpScheme class */
142
const
InterpolationScheme
BL0 =
InterpolationScheme
(
143
BAND_LIMITED_0);
//< Scheme performing BLi to position 0.5
144
const
InterpolationScheme
BL1 =
InterpolationScheme
(
145
BAND_LIMITED_1);
//< Scheme performing BLi to position 1.5
146
const
InterpolationScheme
BL2 =
InterpolationScheme
(
147
BAND_LIMITED_2);
//< Scheme performing BLi to position 2.5
148
const
InterpolationScheme
BL3 =
InterpolationScheme
(
149
BAND_LIMITED_3);
//< Scheme performing BLi to position 3.5
150
const
InterpolationScheme
BL4 =
InterpolationScheme
(
151
BAND_LIMITED_4);
//< Scheme performing BLi to position 4.5
152
const
InterpolationScheme
BL5 =
InterpolationScheme
(
153
BAND_LIMITED_5);
//< Scheme performing BLi to position 5.5
154
const
InterpolationScheme
BL6 =
InterpolationScheme
(
155
BAND_LIMITED_6);
//< Scheme performing BLi to position 6.5
156
const
InterpolationScheme
BL7 =
157
InterpolationScheme
(BAND_LIMITED_7);
//< Scheme performing BLi to
158
// position 7.5 (after last cell)
159
const
InterpolationScheme
BL_TO_CELL_0 =
InterpolationScheme
(
160
BAND_LIMITED_CELL_ZERO);
//< Scheme performing BLi to position -0.5
161
//(before 1st cell)
162
const
InterpolationScheme
CBFst =
InterpolationScheme
(
163
CUBIC_INTERP_FIRST);
//< Scheme performing cubic interpolation to the
164
// midpoint of the first pair of a set of 4
165
// datapoints
166
const
InterpolationScheme
CBMid =
InterpolationScheme
(
167
CUBIC_INTERP_MIDDLE);
//< Scheme performing cubic interpolation to the
168
// midpoint of the central pair of a set of 4
169
// datapoints
170
const
InterpolationScheme
CBLst =
InterpolationScheme
(
171
CUBIC_INTERP_LAST);
//< Scheme performing cubic interpolation to the
172
// midpoint of the last pair of a set of 4 datapoints
173
174
/**
175
* @brief Determine the appropriate interpolation scheme to use, given the
176
* number of datapoints available and the position to which we wish to
177
* interpolate to.
178
*
179
* @param datapts_in_direction The number of datapoints available along this
180
* axis
181
* @param interpolation_position Interpolation is to be performed to the
182
* midpoint of the datapoints indexed with (interpolation_position-1) and
183
* (interpolation_position)
184
* @param interpolation_methods The preferred interpolation methods to use
185
* @return const InterpolationScheme&
186
*/
187
const
InterpolationScheme
&
188
best_scheme
(
int
datapts_in_direction,
int
interpolation_position,
189
tdms_flags::InterpolationMethod
interpolation_methods =
190
tdms_flags::InterpolationMethod::Cubic);
InterpolationScheme
Executes an interpolation scheme.
Definition
interpolation_methods.h:57
InterpolationScheme::InterpolationScheme
InterpolationScheme(scheme_value value)
Construct a new interp Scheme object, by providing the scheme value.
Definition
interpolation_methods.cpp:9
InterpolationScheme::num_nonzero_coeffs
int num_nonzero_coeffs() const
Compute the number of non-zero coefficients in the interpolation scheme.
Definition
interpolation_methods.cpp:169
InterpolationScheme::interpolate
T interpolate(const T *v, const int offset=0) const
Executes the interpolation scheme on the data provided.
Definition
interpolation_methods.h:122
InterpolationScheme::is_better_than
bool is_better_than(const InterpolationScheme &s) const
Determines whether another interpScheme has greater value than this one.
Definition
interpolation_methods.cpp:173
InterpolationScheme::get_priority
scheme_value get_priority() const
Get the value object.
Definition
interpolation_methods.cpp:167
input_flags.h
Organises enumerated constants, names, and classes for handling flag-variables that are passed to TDM...
scheme_value
scheme_value
Defines our order of preference for the use of the various schemes.
Definition
interpolation_methods.h:33
best_scheme
const InterpolationScheme & best_scheme(int datapts_in_direction, int interpolation_position, tdms_flags::InterpolationMethod interpolation_methods=tdms_flags::InterpolationMethod::Cubic)
Determine the appropriate interpolation scheme to use, given the number of datapoints available and t...
Definition
interpolation_methods.cpp:178
tdms_flags::InterpolationMethod
InterpolationMethod
Definition
input_flags.h:37
tdms
include
interpolation_methods.h
Generated by
1.17.0