Skip to content

Commit e60c27c

Browse files
Merge pull request #216 from EXP-code/covarUpdate
Restore covariance for stomping merge.
2 parents 6cbd08f + e880c64 commit e60c27c

5 files changed

Lines changed: 569 additions & 274 deletions

File tree

expui/BasisFactory.H

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "OrthoFunction.H"
1111
#include "Coefficients.H"
1212
#include "PseudoAccel.H"
13+
#include "Covariance.H"
1314
#include "YamlCheck.H"
1415
#include "localmpi.H"
1516
#include "exputils.H"
@@ -135,6 +136,32 @@ namespace BasisClasses
135136
Eigen::MatrixXd p_accel;
136137
//@}
137138

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+
138165
//! Number of center points in acceleration estimator
139166
int Naccel = 0;
140167

@@ -291,6 +318,46 @@ namespace BasisClasses
291318

292319
//! Get the basis expansion center
293320
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+
294361
};
295362

296363
using BasisPtr = std::shared_ptr<Basis>;

expui/BiorthBasis.H

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "BiorthBess.H"
2222
#include "BasisFactory.H"
2323
#include "BiorthCube.H"
24-
#include "Covariance.H"
2524
#include "sltableMP2.H"
2625
#include "SLGridMP2.H"
2726
#include "YamlCheck.H"
@@ -104,32 +103,6 @@ namespace BasisClasses
104103
RowMatrixXd varray;
105104
//@}
106105

107-
//! Coefficient variance computation enabled
108-
bool pcavar = false;
109-
110-
//@{
111-
//! Sample counts and masses for covariance computation
112-
Eigen::VectorXi sampleCounts;
113-
Eigen::VectorXd sampleMasses;
114-
//@}
115-
116-
//! Covariance storage instance
117-
std::shared_ptr<SubsampleCovariance> covarStore;
118-
119-
//! Round time key to emulated fixed-point arithmetic
120-
double roundTime(double time)
121-
{
122-
// Eight decimal places should be enough here...
123-
const double multiplier = 1.0e+08; // std::pow(10.0, 8);
124-
return std::floor(time * multiplier + 0.5) / multiplier;
125-
}
126-
127-
//! Store covariance matrix?
128-
bool covar = true;
129-
130-
//! Store summed covariance only?
131-
bool scovr = true;
132-
133106
public:
134107

135108
//! Basis identifier string
@@ -273,41 +246,6 @@ namespace BasisClasses
273246
return varray;
274247
}
275248

276-
//!! Sample counts, masses, coefficients, and covariance
277-
SubsampleCovariance::CovarData getCoefCovariance(double time)
278-
{ return covarStore->getCoefCovariance(time); }
279-
280-
//! Write coefficient covariance data to an HDF5 file
281-
virtual void writeCoefCovariance(const std::string& compname, const std::string& runtag,
282-
double time=0.0)
283-
{
284-
// Must be overriden; base implementation throws error
285-
throw std::runtime_error("BiorthBasis::writeCoefCovariance: "
286-
"Not implemented for this basis");
287-
}
288-
289-
//! Make covariance after accumulation
290-
virtual void makeCoefCovariance(void) {}
291-
292-
//! Enable covariance computation with optional sample time
293-
virtual void enableCoefCovariance(bool pcavar, int sampT_in, bool ftype, bool covar_in)
294-
{
295-
// Must be overriden; base implementation throws error
296-
throw std::runtime_error("BiorthBasis::enableCoefCovariance: "
297-
"Not implemented for this basis");
298-
}
299-
300-
//! HDF5 compression settings
301-
void setCovarH5Compress(unsigned level, unsigned chunksize, bool shuffle,
302-
bool szip=false)
303-
{
304-
if (covarStore) {
305-
covarStore->setCovarH5Compress(level, chunksize, shuffle, szip);
306-
} else {
307-
throw std::runtime_error("BiorthBasis::setCovarH5Compress: covariance storage not initialized");
308-
}
309-
}
310-
311249
//! Evaluate acceleration in Cartesian coordinates in centered
312250
//! coordinate system for a collections of points
313251
virtual RowMatrixXd& getAccel(Eigen::Ref<const RowMatrixXd> pos)

0 commit comments

Comments
 (0)