BTSpline1D.hh
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef BTSPLINE1D_H
00026 #define BTSPLINE1D_H
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #ifdef BTSpline_DESIGN
00050
00051 The BTSpline1D class is an object representing the transformation between some
00052 value x and a value phi, based on tables of values and gradients (derivatives).
00053 The values and gradients are computed (or supplied) at a set of points
00054 (we call these node points) upon construction. These node points may be
00055 irregularly spaced.
00056
00057 From then on, the user can invoke the () operator supplying the value of x;
00058 the operator returns the value of the function phi, based on an interpolating
00059 function which exactly matches the values and slopes at every node point.
00060
00061 A given instance of a BTSpline is constructed from:
00062
00063 (1) An integer extent of the array defining the node points.
00064 (2) An array of N numbers representing the coordinates of each node points.
00065 (3) The values and optionally the gradients of phi at those node points.
00066
00067 For convenience, the value and gradient information can be supplied in
00068 any of several ways:
00069
00070 * A pointer to a function returning a double which takes a double x. If this
00071 is supplied, then the constructor will call the function however many times
00072 to fill in the tables of values at the node points. It will then compute
00073 the gradients needed for continuity in the second derivative, using "natural"
00074 boundary conditions (second derivative zero at both ends).
00075
00076 * A single table containing the value for each point. Again, derivatives are
00077 comuted using "natural" boundary conditions.
00078
00079 * Either a pointer to a function or a table, as above, followed by two
00080 additional arguments which represent the values of slope at the beginnng
00081 and end boundaries;
00082
00083 * A table of values and a separate table of one gradients (derivative) per
00084 point.
00085
00086 * A pointer to a function returning a void, which takes a double x and
00087 two pointers to value and gradient. If this is supplied, then the
00088 constructor will call the function however many times to fill in the
00089 tables of values and gradients at the node points.
00090
00091 The tables are captured in the class instance data, and may be discarded after
00092 construction.
00093
00094 The only user-relevant method other than the constructor is
00095 double operator() ( double x ) const;
00096 that is, supplying a x for the desired sample point and receiving a double
00097 value
00098 of phi. The value returned is a cubic function in each interval which will
00099 match the values and the gradients at every node.
00100
00101 The class does NOT verify that x lies within the domain defined by the node
00102 points; if it is outside, then the value obtained is still a valid
00103 approximation, but one which will get worse as the distance from the nearest
00104 node grows large.
00105
00106 #endif
00107
00108 class BTSpline1D {
00109
00110
00111
00112
00113
00114 typedef double Data_t;
00115
00116
00117
00118 public:
00119
00120
00121
00122 double operator() ( double x ) const;
00123
00124
00125
00126 BTSpline1D ( const BTSpline1D & s );
00127 BTSpline1D ( );
00128
00129
00130
00131
00132
00133
00134
00135 #ifdef FUTURE
00136
00137 BTSpline1D (
00138 const std::vector<Data_t> nodes,
00139 const std::vector<Data_t> values
00140 );
00141
00142 BTSpline1D (
00143 const std::vector<Data_t> nodes,
00144 const std::vector<Data_t> values,
00145 Data_t slope0, Data_t slopeN
00146 );
00147
00148 #endif // FUTURE
00149
00150 BTSpline1D (
00151 int extent,
00152 const Data_t* nodes,
00153 const Data_t* values
00154 );
00155
00156 BTSpline1D (
00157 int extent,
00158 const Data_t* nodes,
00159 double values_function (double x)
00160 );
00161
00162 BTSpline1D (
00163 int extent,
00164 const Data_t* nodes,
00165 const Data_t* values,
00166 Data_t slope0, Data_t slopeN
00167 );
00168
00169 BTSpline1D (
00170 int extent,
00171 const Data_t* nodes,
00172 double values_function (double x),
00173 Data_t slope0, Data_t slopeN
00174 );
00175
00176
00177
00178 #ifdef FUTURE
00179
00180 BTSpline1D (
00181 const std::vector<Data_t> nodes,
00182 const std::vector<Data_t> values,
00183 const std::vector<Data_t> gradients
00184 );
00185
00186
00187
00188 #endif // FUTURE
00189
00190 BTSpline1D (
00191 int extent,
00192 const Data_t* nodes,
00193 const Data_t* values,
00194 const Data_t* gradients
00195
00196
00197 );
00198
00199 BTSpline1D (
00200 int extent,
00201 const Data_t* nodes,
00202 void values_grads_function (
00203 double x,
00204 double* val,
00205 double* grads)
00206
00207
00208 );
00209
00210 ~BTSpline1D();
00211
00212 protected:
00213
00214
00215
00216 int extent_;
00217 Data_t* nodePoints_;
00218 Data_t* distances_;
00219 Data_t* values_;
00220 Data_t* grads_;
00221 Data_t* secondDerivs_;
00222
00223 bool naturalBoundaryConditions;
00224 Data_t slope0_;
00225 Data_t slopeN_;
00226
00227
00228
00229 void captureGrid( int extent, const Data_t* nodes );
00230 void captureValues( int extent, const Data_t* values );
00231 void fillValues( int extent, double values_function(double x));
00232 void computeSecondDerivs();
00233
00234 };
00235
00236 #endif // BTSPLINE1D_H
00237