|
10 | 10 | #include "OrthoFunction.H" |
11 | 11 | #include "Coefficients.H" |
12 | 12 | #include "PseudoAccel.H" |
| 13 | +#include "Covariance.H" |
13 | 14 | #include "YamlCheck.H" |
14 | 15 | #include "localmpi.H" |
15 | 16 | #include "exputils.H" |
@@ -135,6 +136,32 @@ namespace BasisClasses |
135 | 136 | Eigen::MatrixXd p_accel; |
136 | 137 | //@} |
137 | 138 |
|
| 139 | + //@{ |
| 140 | + //! Sample counts and masses for covariance computation |
| 141 | + Eigen::VectorXi sampleCounts; |
| 142 | + Eigen::VectorXd sampleMasses; |
| 143 | + //@} |
| 144 | + |
| 145 | + //! Covariance storage instance |
| 146 | + std::shared_ptr<SubsampleCovariance> covarStore; |
| 147 | + |
| 148 | + //! Coefficient variance computation enabled |
| 149 | + bool pcavar = false; |
| 150 | + |
| 151 | + //! Round time key to emulated fixed-point arithmetic |
| 152 | + double roundTime(double time) |
| 153 | + { |
| 154 | + // Eight decimal places should be enough here... |
| 155 | + const double multiplier = 1.0e+08; // std::pow(10.0, 8); |
| 156 | + return std::floor(time * multiplier + 0.5) / multiplier; |
| 157 | + } |
| 158 | + |
| 159 | + //! Store covariance matrix? |
| 160 | + bool covar = true; |
| 161 | + |
| 162 | + //! Store summed covariance only? |
| 163 | + bool scovr = true; |
| 164 | + |
138 | 165 | //! Number of center points in acceleration estimator |
139 | 166 | int Naccel = 0; |
140 | 167 |
|
@@ -291,6 +318,46 @@ namespace BasisClasses |
291 | 318 |
|
292 | 319 | //! Get the basis expansion center |
293 | 320 | RowMatrix3d getRotation() { return coefrot; } |
| 321 | + |
| 322 | + //!! Sample counts, masses, coefficients, and covariance |
| 323 | + virtual SubsampleCovariance::CovarData getCoefCovariance(double time) |
| 324 | + { |
| 325 | + if (!covarStore) |
| 326 | + throw std::runtime_error("Basis::getCoefCovariance: covariance storage not initialized"); |
| 327 | + return covarStore->getCoefCovariance(time); |
| 328 | + } |
| 329 | + |
| 330 | + //! Write coefficient covariance data to an HDF5 file |
| 331 | + virtual void writeCoefCovariance(const std::string& compname, const std::string& runtag, |
| 332 | + double time=0.0) |
| 333 | + { |
| 334 | + // Must be overriden; base implementation throws error |
| 335 | + throw std::runtime_error("Basis::writeCoefCovariance: " |
| 336 | + "Not implemented for this basis"); |
| 337 | + } |
| 338 | + |
| 339 | + //! Make covariance after accumulation |
| 340 | + virtual void makeCoefCovariance(void) {} |
| 341 | + |
| 342 | + //! Enable covariance computation with optional sample time |
| 343 | + virtual void enableCoefCovariance(bool pcavar, int sampT_in, bool ftype, bool total, bool covar_in) |
| 344 | + { |
| 345 | + // Must be overriden; base implementation throws error |
| 346 | + throw std::runtime_error("Basis::enableCoefCovariance: " |
| 347 | + "Not implemented for this basis"); |
| 348 | + } |
| 349 | + |
| 350 | + //! HDF5 compression settings |
| 351 | + void setCovarH5Compress(unsigned level, unsigned chunksize, bool shuffle, |
| 352 | + bool szip=false) |
| 353 | + { |
| 354 | + if (covarStore) { |
| 355 | + covarStore->setCovarH5Compress(level, chunksize, shuffle, szip); |
| 356 | + } else { |
| 357 | + throw std::runtime_error("Basis::setCovarH5Compress: covariance storage not initialized"); |
| 358 | + } |
| 359 | + } |
| 360 | + |
294 | 361 | }; |
295 | 362 |
|
296 | 363 | using BasisPtr = std::shared_ptr<Basis>; |
|
0 commit comments