Skip to content

Squared singular values to calculate POD variance #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions examples/prom/mixed_nonlinear_diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ CAROM::Matrix* GetFirstColumns(const int N, const CAROM::Matrix* A)

// TODO: move this to the library?
void MergeBasis(const int dimFOM, const int nparam, const int max_num_snapshots,
std::string name)
std::string name, bool squareSV)
{
MFEM_VERIFY(nparam > 0, "Must specify a positive number of parameter sets");

Expand All @@ -448,7 +448,7 @@ void MergeBasis(const int dimFOM, const int nparam, const int max_num_snapshots,
generator.endSamples(); // save the merged basis file

int cutoff = 0;
generator.finalSummary(1e-4, cutoff, "mergedSV_" + name);
generator.finalSummary(1e-4, cutoff, "mergedSV_" + name, 0, squareSV);
}

// TODO: move this to the library?
Expand Down Expand Up @@ -512,6 +512,7 @@ int main(int argc, char *argv[])
bool use_eqp = false;
bool writeSampleMesh = false;
int num_samples_req = -1;
bool squareSV = true;

bool pointwiseSnapshots = false;
int pwx = 0;
Expand Down Expand Up @@ -577,6 +578,8 @@ int main(int argc, char *argv[])
"Enable or disable the online phase.");
args.AddOption(&merge, "-merge", "--merge", "-no-merge", "--no-merge",
"Enable or disable the merge phase.");
args.AddOption(&squareSV, "-sqsv", "--square-sv", "-no-sqsv", "--no-square-sv",
"Use singular values squared in energy fraction.");
args.AddOption(&samplingType, "-hrtype", "--hrsamplingtype",
"Sampling type for hyperreduction.");
args.AddOption(&num_samples_req, "-nsr", "--nsr",
Expand Down Expand Up @@ -705,13 +708,13 @@ int main(int argc, char *argv[])
totalTimer.Clear();
totalTimer.Start();

MergeBasis(R_space.GetTrueVSize(), nsets, max_num_snapshots, "R");
MergeBasis(R_space.GetTrueVSize(), nsets, max_num_snapshots, "FR");
MergeBasis(W_space.GetTrueVSize(), nsets, max_num_snapshots, "W");
MergeBasis(R_space.GetTrueVSize(), nsets, max_num_snapshots, "R", squareSV);
MergeBasis(R_space.GetTrueVSize(), nsets, max_num_snapshots, "FR", squareSV);
MergeBasis(W_space.GetTrueVSize(), nsets, max_num_snapshots, "W", squareSV);

if (hyperreduce_source)
{
MergeBasis(W_space.GetTrueVSize(), nsets, max_num_snapshots, "S");
MergeBasis(W_space.GetTrueVSize(), nsets, max_num_snapshots, "S", squareSV);
}

totalTimer.Stop();
Expand Down
13 changes: 8 additions & 5 deletions examples/prom/nonlinear_elasticity_global_rom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ CAROM::Matrix *GetFirstColumns(const int N, const CAROM::Matrix *A)

// TODO: move this to the library?
void MergeBasis(const int dimFOM, const int nparam, const int max_num_snapshots,
std::string name)
std::string name, bool squareSV)
{
MFEM_VERIFY(nparam > 0, "Must specify a positive number of parameter sets");

Expand All @@ -328,7 +328,7 @@ void MergeBasis(const int dimFOM, const int nparam, const int max_num_snapshots,
generator.endSamples(); // save the merged basis file

int cutoff = 0;
generator.finalSummary(1e-7, cutoff, "mergedSV_" + name + ".txt");
generator.finalSummary(1e-7, cutoff, "mergedSV_" + name + ".txt", 0, squareSV);
}

const CAROM::Matrix *GetSnapshotMatrix(const int dimFOM, const int nparam,
Expand Down Expand Up @@ -416,6 +416,7 @@ int main(int argc, char *argv[])
bool x_base_only = false;
int num_samples_req = -1;
const char *samplingType = "gnat";
bool squareSV = true;

int nsets = 0;
int id_param = 0;
Expand Down Expand Up @@ -478,6 +479,8 @@ int main(int argc, char *argv[])
"Enable or disable the online phase.");
args.AddOption(&merge, "-merge", "--merge", "-no-merge", "--no-merge",
"Enable or disable the merge phase.");
args.AddOption(&squareSV, "-sqsv", "--square-sv", "-no-sqsv", "--no-square-sv",
"Use singular values squared in energy fraction.");
args.AddOption(&samplingType, "-hrtype", "--hrsamplingtype",
"Sampling type for hyperreduction.");
args.AddOption(&num_samples_req, "-nsr", "--nsr",
Expand Down Expand Up @@ -643,11 +646,11 @@ int main(int argc, char *argv[])
// Merge bases
if (x_base_only == false)
{
MergeBasis(true_size, nsets, max_num_snapshots, "V");
MergeBasis(true_size, nsets, max_num_snapshots, "V", squareSV);
}

MergeBasis(true_size, nsets, max_num_snapshots, "X");
MergeBasis(true_size, nsets, max_num_snapshots, "H");
MergeBasis(true_size, nsets, max_num_snapshots, "X", squareSV);
MergeBasis(true_size, nsets, max_num_snapshots, "H", squareSV);

totalTimer.Stop();
if (myid == 0)
Expand Down
8 changes: 5 additions & 3 deletions lib/linalg/BasisGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ BasisGenerator::finalSummary(
const double energyFractionThreshold,
int & cutoff,
const std::string & cutoffOutputPath,
const int first_sv)
const int first_sv, const bool squareSV)
{
const int rom_dim = getSpatialBasis()->numColumns();
const Vector* sing_vals = getSingularValues();
Expand All @@ -321,7 +321,8 @@ BasisGenerator::finalSummary(

double sum = 0.0;
for (int sv = first_sv; sv < sing_vals->dim(); ++sv) {
sum += (*sing_vals)(sv);
const double s = (*sing_vals)(sv);
sum += squareSV ? s * s : s;
}

int p = std::floor(-std::log10(energyFractionThreshold));
Expand All @@ -345,7 +346,8 @@ BasisGenerator::finalSummary(
}

for (int sv = first_sv; sv < sing_vals->dim(); ++sv) {
partialSum += (*sing_vals)(sv);
const double s = (*sing_vals)(sv);
partialSum += squareSV ? s * s : s;
for (int i = count; i < p; ++i)
{
if (partialSum / sum > 1.0 - std::pow(10, -1 - i))
Expand Down
2 changes: 1 addition & 1 deletion lib/linalg/BasisGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class BasisGenerator
const double energyFractionThreshold,
int & cutoff,
const std::string & cutoffOutputPath = "",
const int first_sv = 0);
const int first_sv = 0, const bool squareSV = true);

protected:
/**
Expand Down