Skip to content

Commit d8cc32c

Browse files
authored
Squared singular values to calculate POD variance (#306)
* Squared singular values * Added command line option for squared singular values * Added command line options for nonlinear elasticity * Fixed typos * astyle * comma spacing * added missing spaces before comma
1 parent 5f9dacd commit d8cc32c

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

Diff for: examples/prom/mixed_nonlinear_diffusion.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ void BroadcastUndistributedRomVector(CAROM::Vector* v)
391391

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

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

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

417417
std::shared_ptr<const CAROM::Matrix>
@@ -471,6 +471,7 @@ int main(int argc, char *argv[])
471471
bool use_eqp = false;
472472
bool writeSampleMesh = false;
473473
int num_samples_req = -1;
474+
bool squareSV = true;
474475

475476
bool pointwiseSnapshots = false;
476477
int pwx = 0;
@@ -536,6 +537,8 @@ int main(int argc, char *argv[])
536537
"Enable or disable the online phase.");
537538
args.AddOption(&merge, "-merge", "--merge", "-no-merge", "--no-merge",
538539
"Enable or disable the merge phase.");
540+
args.AddOption(&squareSV, "-sqsv", "--square-sv", "-no-sqsv", "--no-square-sv",
541+
"Use singular values squared in energy fraction.");
539542
args.AddOption(&samplingType, "-hrtype", "--hrsamplingtype",
540543
"Sampling type for hyperreduction.");
541544
args.AddOption(&num_samples_req, "-nsr", "--nsr",
@@ -664,13 +667,13 @@ int main(int argc, char *argv[])
664667
totalTimer.Clear();
665668
totalTimer.Start();
666669

667-
MergeBasis(R_space.GetTrueVSize(), nsets, max_num_snapshots, "R");
668-
MergeBasis(R_space.GetTrueVSize(), nsets, max_num_snapshots, "FR");
669-
MergeBasis(W_space.GetTrueVSize(), nsets, max_num_snapshots, "W");
670+
MergeBasis(R_space.GetTrueVSize(), nsets, max_num_snapshots, "R", squareSV);
671+
MergeBasis(R_space.GetTrueVSize(), nsets, max_num_snapshots, "FR", squareSV);
672+
MergeBasis(W_space.GetTrueVSize(), nsets, max_num_snapshots, "W", squareSV);
670673

671674
if (hyperreduce_source)
672675
{
673-
MergeBasis(W_space.GetTrueVSize(), nsets, max_num_snapshots, "S");
676+
MergeBasis(W_space.GetTrueVSize(), nsets, max_num_snapshots, "S", squareSV);
674677
}
675678

676679
totalTimer.Stop();

Diff for: examples/prom/nonlinear_elasticity_global_rom.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ void visualize(ostream &out, ParMesh *mesh, ParGridFunction *deformed_nodes,
295295

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

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

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

321321
const CAROM::Matrix *GetSnapshotMatrix(const int dimFOM, const int nparam,
@@ -403,6 +403,7 @@ int main(int argc, char *argv[])
403403
bool x_base_only = false;
404404
int num_samples_req = -1;
405405
const char *samplingType = "gnat";
406+
bool squareSV = true;
406407

407408
int nsets = 0;
408409
int id_param = 0;
@@ -465,6 +466,8 @@ int main(int argc, char *argv[])
465466
"Enable or disable the online phase.");
466467
args.AddOption(&merge, "-merge", "--merge", "-no-merge", "--no-merge",
467468
"Enable or disable the merge phase.");
469+
args.AddOption(&squareSV, "-sqsv", "--square-sv", "-no-sqsv", "--no-square-sv",
470+
"Use singular values squared in energy fraction.");
468471
args.AddOption(&samplingType, "-hrtype", "--hrsamplingtype",
469472
"Sampling type for hyperreduction.");
470473
args.AddOption(&num_samples_req, "-nsr", "--nsr",
@@ -630,11 +633,11 @@ int main(int argc, char *argv[])
630633
// Merge bases
631634
if (x_base_only == false)
632635
{
633-
MergeBasis(true_size, nsets, max_num_snapshots, "V");
636+
MergeBasis(true_size, nsets, max_num_snapshots, "V", squareSV);
634637
}
635638

636-
MergeBasis(true_size, nsets, max_num_snapshots, "X");
637-
MergeBasis(true_size, nsets, max_num_snapshots, "H");
639+
MergeBasis(true_size, nsets, max_num_snapshots, "X", squareSV);
640+
MergeBasis(true_size, nsets, max_num_snapshots, "H", squareSV);
638641

639642
totalTimer.Stop();
640643
if (myid == 0)

Diff for: lib/linalg/BasisGenerator.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ BasisGenerator::finalSummary(
299299
const double energyFractionThreshold,
300300
int & cutoff,
301301
const std::string & cutoffOutputPath,
302-
const int first_sv)
302+
const int first_sv, const bool squareSV)
303303
{
304304
const int rom_dim = getSpatialBasis()->numColumns();
305305
std::shared_ptr<const Vector> sing_vals = getSingularValues();
@@ -308,7 +308,8 @@ BasisGenerator::finalSummary(
308308

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

314315
int p = std::floor(-std::log10(energyFractionThreshold));
@@ -332,7 +333,8 @@ BasisGenerator::finalSummary(
332333
}
333334

334335
for (int sv = first_sv; sv < sing_vals->dim(); ++sv) {
335-
partialSum += (*sing_vals)(sv);
336+
const double s = (*sing_vals)(sv);
337+
partialSum += squareSV ? s * s : s;
336338
for (int i = count; i < p; ++i)
337339
{
338340
if (partialSum / sum > 1.0 - std::pow(10, -1 - i))

Diff for: lib/linalg/BasisGenerator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class BasisGenerator
260260
const double energyFractionThreshold,
261261
int & cutoff,
262262
const std::string & cutoffOutputPath = "",
263-
const int first_sv = 0);
263+
const int first_sv = 0, const bool squareSV = true);
264264

265265
protected:
266266
/**

0 commit comments

Comments
 (0)