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 #endif
00106
00107 class BTSpline1D {
00108
00109
00110
00111
00112
00113 typedef double Data_t;
00114
00115
00116
00117 public:
00118
00119
00120
00121 double operator() ( double x ) const;
00122
00123
00124
00125 BTSpline1D ( const BTSpline1D & s );
00126 BTSpline1D ( );
00127
00128
00129
00130
00131
00132 #ifdef FUTURE
00133
00134 BTSpline1D (
00135 const std::vector<Data_t> nodes,
00136 const std::vector<Data_t> values
00137 );
00138
00139 BTSpline1D (
00140 const std::vector<Data_t> nodes,
00141 const std::vector<Data_t> values,
00142 Data_t slope0, Data_t slopeN
00143 );
00144 #endif // FUTURE
00145
00146 BTSpline1D (
00147 int extent,
00148 const Data_t* nodes,
00149 const Data_t* values
00150 );
00151
00152 BTSpline1D (
00153 int extent,
00154 const Data_t* nodes,
00155 double values_function (double x)
00156 );
00157
00158 BTSpline1D (
00159 int extent,
00160 const Data_t* nodes,
00161 const Data_t* values,
00162 Data_t slope0, Data_t slopeN
00163 );
00164
00165 BTSpline1D (
00166 int extent,
00167 const Data_t* nodes,
00168 double values_function (double x),
00169 Data_t slope0, Data_t slopeN
00170 );
00171
00172
00173
00174 #ifdef FUTURE
00175
00176 BTSpline1D (
00177 const std::vector<Data_t> nodes,
00178 const std::vector<Data_t> values,
00179 const std::vector<Data_t> gradients
00180 );
00181
00182
00183 #endif // FUTURE
00184
00185 BTSpline1D (
00186 int extent,
00187 const Data_t* nodes,
00188 const Data_t* values,
00189 const Data_t* gradients
00190
00191
00192 );
00193
00194 BTSpline1D (
00195 int extent,
00196 const Data_t* nodes,
00197 void values_grads_function (
00198 double x,
00199 double* val,
00200 double* grads)
00201
00202
00203 );
00204
00205 ~BTSpline1D();
00206
00207 protected:
00208
00209
00210
00211 int extent_;
00212 Data_t* nodePoints_;
00213 Data_t* distances_;
00214 Data_t* values_;
00215 Data_t* grads_;
00216 Data_t* secondDerivs_;
00217
00218 bool naturalBoundaryConditions;
00219 Data_t slope0_;
00220 Data_t slopeN_;
00221
00222
00223
00224 void captureGrid( int extent, const Data_t* nodes );
00225 void captureValues( int extent, const Data_t* values );
00226 void fillValues( int extent, double values_function(double x));
00227 void computeSecondDerivs();
00228
00229 };
00230 #endif // BTSPLINE1D_H