STORMM Source Documentation
Loading...
Searching...
No Matches
log_scale_spline.h
1// -*-c++-*-
2#ifndef STORMM_LOG_SCALE_SPLINE_H
3#define STORMM_LOG_SCALE_SPLINE_H
4
5#include <cmath>
6#include <vector>
7#include "copyright.h"
8#include "Accelerator/gpu_details.h"
9#include "Accelerator/hybrid.h"
10#include "Constants/behavior.h"
11#include "Constants/symbol_values.h"
12#include "DataTypes/common_types.h"
13#include "DataTypes/stormm_vector_types.h"
14#include "Math/matrix_ops.h"
15#include "Parsing/parse.h"
16#include "Parsing/parsing_enumerators.h"
17#include "Potential/pme_util.h"
18#include "Reporting/error_format.h"
19#include "math_enumerators.h"
20
21namespace stormm {
22namespace stmath {
23
24using card::GpuDetails;
25using card::Hybrid;
26using card::HybridTargetLevel;
27using constants::ExceptionResponse;
28using constants::PrecisionModel;
29using symbols::amber_ancient_bioq;
30using energy::minimum_ewald_coefficient;
31using energy::maximum_ewald_coefficient;
32using parse::minimalRealFormat;
33using parse::NumberFormat;
34using parse::realToString;
35
39constexpr int default_logtab_mantissa_bits = 5;
40constexpr double default_logtab_max_range = 64.0;
41constexpr double default_logtab_min_range = 0.00390625;
43
46template <typename T4> struct LogSplineTable {
47
50 LogSplineTable(BasisFunctions basis_in, TableIndexing lookup_in, int detail_bits_in,
51 int index_bound_in, uint sp_detail_mask_in, ullint dp_detail_mask_in,
52 const float arg_offset_in, const T4* table_in);
53
57 LogSplineTable(const LogSplineTable &original) = default;
58 LogSplineTable(LogSplineTable &&original) = default;
60
65 const BasisFunctions basis;
66
69 const TableIndexing lookup;
70
76 const int detail_bits;
77
79 const int index_bound;
80
100 const uint sp_detail_mask;
101 const ullint dp_detail_mask;
103
108 const float arg_offset;
109
111 const T4* table;
112};
113
139template <typename T4> class LogScaleSpline {
140public:
141
158 LogScaleSpline(LogSplineForm target_form_in, double ewald_coefficient_in,
159 double coulomb_constant_in = amber_ancient_bioq,
160 int mantissa_bits_in = default_logtab_mantissa_bits,
161 double max_range_in = default_logtab_max_range,
162 double min_range_in = default_logtab_min_range,
163 TableIndexing indexing_method_in = TableIndexing::SQUARED_ARG,
164 BasisFunctions basis_set_in = BasisFunctions::POLYNOMIAL,
165 int ulp_optimization_depth_in = 2,
166 float indexing_offset_in = 0.0,
167 ExceptionResponse policy = ExceptionResponse::DIE);
168
169 LogScaleSpline(LogSplineForm target_form_in,
170 const std::vector<std::vector<double2>> &custom_form_in,
171 int mantissa_bits_in = default_logtab_mantissa_bits,
172 double max_range_in = default_logtab_max_range,
173 double min_range_in = default_logtab_min_range,
174 TableIndexing indexing_method_in = TableIndexing::SQUARED_ARG,
175 BasisFunctions basis_set_in = BasisFunctions::POLYNOMIAL,
176 int ulp_optimization_depth_in = 2,
177 float indexing_offset_in = 0.0,
178 ExceptionResponse policy = ExceptionResponse::WARN);
180
187 LogScaleSpline(const LogScaleSpline &original) = default;
188 LogScaleSpline(LogScaleSpline &&original) = default;
189 LogScaleSpline& operator=(const LogScaleSpline &original) = default;
190 LogScaleSpline& operator=(LogScaleSpline &&original) = default;
192
194 LogSplineForm getForm() const;
195
198 TableIndexing getIndexingMethod() const;
199
201 BasisFunctions getBasisSet() const;
202
204 int getBitStride() const;
205
208 int getSplineDensity() const;
209
212 double getEwaldCoefficient() const;
213
216 double getCoulombConstant() const;
217
219 double getMaximumRange() const;
220
222 double getMinimumRange() const;
223
225 float getIndexingOffset() const;
226
229
235 int getSplineIndex(double r) const;
236
242 int getSplineIndexByRealArg(double r) const;
243
256 double3 getErrorEstimate(double r) const;
258
264 double interpolateByValue(double r) const;
265
271 double interpolateBySquaredValue(double r2) const;
272
278 double evaluate(double r) const;
279
286 double evaluateByRealArg(double r) const;
287
292 const LogSplineTable<T4> data(HybridTargetLevel tier = HybridTargetLevel::HOST) const;
293
296 templateFreeData(HybridTargetLevel tier = HybridTargetLevel::HOST) const;
297
300
301#ifdef STORMM_USE_HPC
303 void upload();
304
306 void download();
307#endif
313 void setMinimumSignificantRange(double min_range_in);
314
315private:
316 LogSplineForm target_form;
318 TableIndexing indexing_method;
320 BasisFunctions basis_set;
324 int mantissa_bits;
327 ullint dp_detail_bitmask;
336 uint sp_detail_bitmask;
337 int segments_per_stride;
341 double ewald_coefficient;
343 double coulomb_constant;
345 double maximum_range;
347 double minimum_absolute_range;
357 double minimum_significant_range;
365 float indexing_offset;
372 int ulp_optimization_depth;
377 PrecisionModel precision;
381 Hybrid<T4> table;
387 double mean_overall_error;
389 double stdev_overall_error;
391 double max_overall_error;
393 std::vector<double> mean_segment_error;
396 std::vector<double> stdev_segment_error;
398 std::vector<double> max_segment_error;
399
401 void setPrecisionModel();
402
408 void setTargetForm(LogSplineForm target_form_in,
409 const std::vector<std::vector<double2>> &custom_form_in = {});
410
416 void setEwaldCoefficient(double ewald_coefficient_in,
417 ExceptionResponse policy = ExceptionResponse::DIE);
418
423 void setMantissaBits(int mantissa_bits_in,
424 ExceptionResponse policy = ExceptionResponse::WARN);
425
433 void setMinimumAbsoluteRange(double min_range_in);
434
440 void setULPDepth(int ulp_optimization_depth_in);
441
446 float checkIndexingOffset(float indexing_offset_in);
447
454 void allocate(double max_range_in, const std::vector<std::vector<double2>> &custom_form_in = {},
455 const ExceptionResponse policy = ExceptionResponse::WARN);
456
458 void evaluatePrescribedTable();
459
463 void evaluateCustomTable();
464
474 void evaluateTargetInSegment(std::vector<double> *bwrk, std::vector<double> *bref, double r2_i,
475 double width);
476
487 void evaluateSplineInSegment(std::vector<double> *estm, const T4 spl_tmp, double r2_i,
488 double width);
489
491 void evaluateOverallError();
492};
493
498ullint doublePrecisionSplineDetailMask(int mantissa_bits);
499
504uint singlePrecisionSplineDetailMask(int mantissa_bits);
505
514double doublePrecisionSplineArgument(double arg, int mantissa_bits, ullint detail_mask);
515
519float singlePrecisionSplineArgument(float arg, int mantissa_bits, uint detail_mask);
520
526template <typename T4> LogSplineTable<T4> restoreType(const LogSplineTable<void> *rasa);
527
528template <typename T4> LogSplineTable<T4> restoreType(const LogSplineTable<void> &rasa);
530
531} // namespace stmath
532} // namespace stormm
533
534#include "log_scale_spline.tpp"
535
536#endif
An evolution of GpuBuffer in pmemd.cuda, the Composite array has elements that are accessible from ei...
Definition hybrid.h:202
LogScaleSpline(LogSplineForm target_form_in, double ewald_coefficient_in, double coulomb_constant_in=amber_ancient_bioq, int mantissa_bits_in=default_logtab_mantissa_bits, double max_range_in=default_logtab_max_range, double min_range_in=default_logtab_min_range, TableIndexing indexing_method_in=TableIndexing::SQUARED_ARG, BasisFunctions basis_set_in=BasisFunctions::POLYNOMIAL, int ulp_optimization_depth_in=2, float indexing_offset_in=0.0, ExceptionResponse policy=ExceptionResponse::DIE)
The constructor needs an indication of the functional form to render. The number of bits will be deci...
float getIndexingOffset() const
Get the indexing offset.
double getEwaldCoefficient() const
Get the Ewald coefficient in use for this spline table. A check will be made to ensure that the splin...
void setMinimumSignificantRange(double min_range_in)
Set the minimum significant range. This is purely for error analysis and will not affect the array in...
int getOptimizationDepth() const
Get the optimization depth.
double evaluateByRealArg(double r) const
Evaluate the underlying function represented by the spline at a point on the natural axis of the unde...
int getBitStride() const
Get the number of leading bits in the mantissa used to determine the array index.
int getSplineIndexByRealArg(double r) const
Get the spline index for a particular value of the argument of the tabulated function....
BasisFunctions getBasisSet() const
Get the basis functions used to construt each spline.
double getMinimumRange() const
Get the minimum absolute range of the spline.
double interpolateByValue(double r) const
Get the value of the underlying function based on a value of the function argument....
double3 getErrorEstimate() const
Get the estimated error as a function of the distance at which the splines are evaluated....
double getMaximumRange() const
Get the maximum range of the spline.
double evaluate(double r) const
Evaluate the underlying function represented by the spline at a point expressed in the object's nativ...
LogSplineForm getForm() const
Get the target form of the function represented by the table.
const LogSplineTable< T4 > data(HybridTargetLevel tier=HybridTargetLevel::HOST) const
Get the object's abstract for the CPU host or GPU device in either of two precision modes.
int getSplineDensity() const
Get the number of spline segments per stride. This is two raised to the power of the result of getBit...
const LogSplineTable< void > templateFreeData(HybridTargetLevel tier=HybridTargetLevel::HOST) const
Get the object's abstract with templating removed.
LogScaleSpline(LogSplineForm target_form_in, double ewald_coefficient_in, double coulomb_constant_in=amber_ancient_bioq, int mantissa_bits_in=default_logtab_mantissa_bits, double max_range_in=default_logtab_max_range, double min_range_in=default_logtab_min_range, TableIndexing indexing_method_in=TableIndexing::SQUARED_ARG, BasisFunctions basis_set_in=BasisFunctions::POLYNOMIAL, int ulp_optimization_depth_in=2, float indexing_offset_in=0.0, ExceptionResponse policy=ExceptionResponse::DIE)
The constructor needs an indication of the functional form to render. The number of bits will be deci...
LogScaleSpline(const LogScaleSpline &original)=default
With no pointers to repair and no const members, the default copy and move constructors as well as as...
const LogScaleSpline< T4 > * getSelfPointer() const
Get a pointer to the original object.
double interpolateBySquaredValue(double r2) const
Get the value of the underlying function based on a squared value of the function argument....
int getSplineIndex(double r) const
Get the spline index for a particular value of the argument of the tabulated function which has alrea...
TableIndexing getIndexingMethod() const
Get the method of indexing the table, an expression based on the target function's argument,...
double getCoulombConstant() const
Get the value of Coulomb's constant in use by the spline. A check will be made to ensure that the spl...
Definition stormm_vector_types.h:117
LogSplineTable(BasisFunctions basis_in, TableIndexing lookup_in, int detail_bits_in, int index_bound_in, uint sp_detail_mask_in, ullint dp_detail_mask_in, const float arg_offset_in, const T4 *table_in)
As with other abstracts, the constructor takes a straight list of inputs for each member variable.
Abstract for the logarithmic splined function object, containing the table and critical constants for...
Definition log_scale_spline.h:46
const BasisFunctions basis
Definition log_scale_spline.h:65
const int index_bound
The maximum index of the table, for bounds checking.
Definition log_scale_spline.h:79
LogSplineTable(const LogSplineTable &original)=default
The const-ness of member variables implicitly deletes the copy and move assignment operators,...
const T4 * table
The table of cubic spline coefficients.
Definition log_scale_spline.h:111
const TableIndexing lookup
Definition log_scale_spline.h:69
const int detail_bits
Definition log_scale_spline.h:76
const uint sp_detail_mask
Definition log_scale_spline.h:100
LogSplineTable(BasisFunctions basis_in, TableIndexing lookup_in, int detail_bits_in, int index_bound_in, uint sp_detail_mask_in, ullint dp_detail_mask_in, const float arg_offset_in, const T4 *table_in)
As with other abstracts, the constructor takes a straight list of inputs for each member variable.
const float arg_offset
Definition log_scale_spline.h:108