Skip to content

Commit

Permalink
BasisGenerator: removed the concept of time interval.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer2368 committed Feb 17, 2024
1 parent ff15bf3 commit c1d49a9
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 28 deletions.
13 changes: 5 additions & 8 deletions lib/linalg/BasisGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BasisGenerator::BasisGenerator(
d_write_snapshots(options.write_snapshots)
{
CAROM_VERIFY(options.dim > 0);
CAROM_VERIFY(options.samples_per_time_interval > 0);
CAROM_VERIFY(options.max_num_samples > 0);
CAROM_VERIFY(options.singular_value_tol >= 0);
CAROM_VERIFY(options.max_time_intervals == -1
|| options.max_time_intervals > 0);
Expand Down Expand Up @@ -135,14 +135,12 @@ BasisGenerator::takeSample(
bool add_without_increase)
{
CAROM_VERIFY(u_in != 0);
CAROM_VERIFY(time >= 0);
CAROM_VERIFY(d_svd->getNumSamples() < d_svd->getMaxNumSamples());

// Check that u_in is not non-zero.
Vector u_vec(u_in, getDim(), true);
if (u_vec.norm() == 0.0) {
printf("WARNING: BasisGenerator::takeSample skipped trivial sample at time %.4E\n",
time);
printf("WARNING: BasisGenerator::takeSample skipped trivial sample.\n");
return false;
}

Expand All @@ -161,16 +159,15 @@ BasisGenerator::loadSamples(const std::string& base_file_name,
if (d_basis_reader) delete d_basis_reader;

d_basis_reader = new BasisReader(base_file_name, db_format);
double time = 0.0;
const Matrix* mat;
const Vector* singular_vals;

if (kind == "basis") {
mat = d_basis_reader->getSpatialBasis(time);
singular_vals = d_basis_reader->getSingularValues(time);
mat = d_basis_reader->getSpatialBasis();
singular_vals = d_basis_reader->getSingularValues();
}
else if (kind == "snapshot") {
mat = d_basis_reader->getSnapshotMatrix(time);
mat = d_basis_reader->getSnapshotMatrix();
}

int num_rows = mat->numRows();
Expand Down
13 changes: 5 additions & 8 deletions lib/linalg/BasisReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ BasisReader::~BasisReader()
}

Matrix*
BasisReader::getSpatialBasis(
double time)
BasisReader::getSpatialBasis()
{
d_last_basis_idx = 0;
int num_rows = getDim("basis");
Expand Down Expand Up @@ -142,8 +141,7 @@ BasisReader::getSpatialBasis(
}

Matrix*
BasisReader::getTemporalBasis(
double time)
BasisReader::getTemporalBasis()
{
d_last_basis_idx = 0;
int num_rows = getDim("temporal_basis");
Expand Down Expand Up @@ -327,12 +325,11 @@ BasisReader::getNumSamples(
}

Matrix*
BasisReader::getSnapshotMatrix(
double time)
BasisReader::getSnapshotMatrix()
{
d_last_basis_idx = 0;
int num_rows = getDim("snapshot",time);
int num_cols = getNumSamples("snapshot",time);
int num_rows = getDim("snapshot");
int num_cols = getNumSamples("snapshot");

char tmp[100];
Matrix* snapshots = new Matrix(num_rows, num_cols, false);
Expand Down
42 changes: 39 additions & 3 deletions lib/linalg/BasisReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,21 @@ class BasisReader {
return (d_last_basis_idx == -1);
}

/**
*
* @brief Returns the spatial basis vectors as a Matrix.
*
* @return The spatial basis vectors.
*/
Matrix*
getSpatialBasis();

/**
*
* @brief Returns the spatial basis vectors for the requested time as a
* Matrix.
* NOTE: this function is obsolete and remains only for backward compatibility.
* Will be removed in future.
*
* @param[in] time Time for which we want the basis vectors.
* NOTE: this argument is obsolete and remains only for backward compatibility.
Expand All @@ -88,7 +99,8 @@ class BasisReader {
*/
Matrix*
getSpatialBasis(
double time);
double time)
{ return getSpatialBasis(); }

/**
*
Expand Down Expand Up @@ -155,6 +167,18 @@ class BasisReader {
* @brief Returns the temporal basis vectors for the requested time as
* a Matrix.
*
* @return The temporal basis vectors for the requested time.
*/
Matrix*
getTemporalBasis();

/**
*
* @brief Returns the temporal basis vectors for the requested time as
* a Matrix.
* NOTE: this function is obsolete and remains only for backward compatibility.
* Will be removed in future.
*
* @param[in] time Time for which we want the basis vectors.
* NOTE: this argument is obsolete and remains only for backward compatibility.
* Will be removed in future.
Expand All @@ -163,7 +187,8 @@ class BasisReader {
*/
Matrix*
getTemporalBasis(
double time);
double time)
{ return getTemporalBasis(); }

/**
*
Expand Down Expand Up @@ -332,6 +357,16 @@ class BasisReader {
*
* @brief Returns the snapshot matrix for the requested time.
*
* @return The snapshot matrix for the requested time.
*/
Matrix*
getSnapshotMatrix();

/**
*
* @brief Returns the snapshot matrix for the requested time.
* NOTE: this function is obsolete and remains only for backward compatibility.
* Will be removed in future.
*
* @param[in] time Time for which we want the basis vectors.
* NOTE: this argument is obsolete and remains only for backward compatibility.
Expand All @@ -341,7 +376,8 @@ class BasisReader {
*/
Matrix*
getSnapshotMatrix(
double time);
double time)
{ return getSnapshotMatrix(); }

/**
*
Expand Down
15 changes: 8 additions & 7 deletions lib/linalg/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class Options
* @brief Constructor.
*
* @pre dim_ > 0
* @pre samples_per_time_interval_ > 0
* @pre max_num_samples_ > 0
* @pre max_time_intervals == -1 || max_time_intervals > 0
*
* @param[in] dim_ The dimension of the system on this processor.
* @param[in] samples_per_time_interval_ The maximum number of samples in
* @param[in] max_num_samples_ The maximum number of samples in
* each time interval.
* @param[in] max_time_intervals_ The maximum number of time intervals.
* @param[in] update_right_SV_ Whether to update the right SV or not.
Expand All @@ -43,13 +43,13 @@ class Options
*
*/
Options(int dim_,
int samples_per_time_interval_,
int max_num_samples_,
int max_time_intervals_ = 1,
bool update_right_SV_ = false,
bool write_snapshots_ = false
): dim(dim_),
max_basis_dimension(samples_per_time_interval_),
samples_per_time_interval(samples_per_time_interval_),
max_basis_dimension(max_num_samples_),
max_num_samples(max_num_samples_),
max_time_intervals(max_time_intervals_),
update_right_SV(update_right_SV_),
write_snapshots(write_snapshots_)
Expand Down Expand Up @@ -226,12 +226,13 @@ class Options
int dim = -1;

/**
* @brief The number of samples per time interval.
* @brief The maximum number of samples.
*/
int samples_per_time_interval = -1;
int max_num_samples = -1;

/**
* @brief The maximum number of time intervals.
* NOTE: this variable is obsolte and will be removed in future.
*/
int max_time_intervals = -1;

Expand Down
4 changes: 2 additions & 2 deletions lib/linalg/svd/SVD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SVD::SVD(
Options options) :
d_dim(options.dim),
d_num_samples(0),
d_max_num_samples(options.samples_per_time_interval),
d_max_num_samples(options.max_num_samples),
d_basis(NULL),
d_basis_right(NULL),
d_U(NULL),
Expand All @@ -29,7 +29,7 @@ SVD::SVD(
d_debug_algorithm(options.debug_algorithm)
{
CAROM_VERIFY(options.dim > 0);
CAROM_VERIFY(options.samples_per_time_interval > 0);
CAROM_VERIFY(options.max_num_samples > 0);
}

SVD::~SVD()
Expand Down

0 comments on commit c1d49a9

Please sign in to comment.