diff --git a/examples/prom/mixed_nonlinear_diffusion.cpp b/examples/prom/mixed_nonlinear_diffusion.cpp index 236e0ca2f..7d8d17c43 100644 --- a/examples/prom/mixed_nonlinear_diffusion.cpp +++ b/examples/prom/mixed_nonlinear_diffusion.cpp @@ -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"); @@ -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? @@ -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; @@ -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", @@ -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(); diff --git a/examples/prom/nonlinear_elasticity_global_rom.cpp b/examples/prom/nonlinear_elasticity_global_rom.cpp index f645c3558..204a386e8 100644 --- a/examples/prom/nonlinear_elasticity_global_rom.cpp +++ b/examples/prom/nonlinear_elasticity_global_rom.cpp @@ -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"); @@ -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, @@ -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; @@ -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", @@ -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) diff --git a/lib/linalg/BasisGenerator.cpp b/lib/linalg/BasisGenerator.cpp index 9e2cec4ae..c0a3f2273 100644 --- a/lib/linalg/BasisGenerator.cpp +++ b/lib/linalg/BasisGenerator.cpp @@ -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(); @@ -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)); @@ -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)) diff --git a/lib/linalg/BasisGenerator.h b/lib/linalg/BasisGenerator.h index 87604447e..a5bf6ab1a 100644 --- a/lib/linalg/BasisGenerator.h +++ b/lib/linalg/BasisGenerator.h @@ -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: /**