Skip to content

Commit

Permalink
Removal of time interval and closing files within BasisWriter::writeB…
Browse files Browse the repository at this point in the history
…asis (#261)

* BasisWriter::writeBasis create/open a file and closes the file at the end.

* stylization.

* HDFDatabase::putIntegerArray - overwrites if the dataset exists.

* enforce single time interval in Options.

* HDFDatabase::putIntegerArray does not allow overwrite.

* BasisWriter::writeBasis always create the file, which will overwrite the exisiting file.

* add a header and stylization.

* remove increase time interval test, as time interval is fixed to 1.

* add an error message for a guidance.

* remove test_SVD from ci workflow.

* SVD::increaseTimeInterval - allow the initial time interval.

* minor fix in test_IncrementalSVDBrand.

* reflecting the comments.

* removed the concept of time interval in BasisReader. time argument remains for backward compatibility.

* BasisWriter: removed the concept of time interval.

* minor fix in BasisReader.

* SVD: removed the concept of time intervals.

* BasisGenerator: removed the concept of time interval.

* add test_SVD.cpp for resolving conflict.

* stylization.

* changed function signature of BasisGenerator::takeSample.

* rebased to resolve conflict.

* changed function signature for BasisReader::getSpatialBasis.

* changed function signature for BasisReader::getTemporalBasis.

* changed function signature for BasisReader::getSingularValues.

* changed function signature for BasisReader::getSnapshotMatrix.

* removed Options::max_time_intervals

* SVD::isNewSample -> isFirstSample

* update comments for StaticSVD::isBasisCurrent

* minor comment updates.

* stylization.

* update dataset names and added python script for dataset name update.

* fixed the ci workflow

* minor fix in ci workflow.

* minor fix

* removed BasisReader:isNewBasis

* minor doxygen comment update
  • Loading branch information
dreamer2368 authored and andersonw1 committed Apr 2, 2024
1 parent 9a1e42b commit fde345c
Show file tree
Hide file tree
Showing 56 changed files with 465 additions and 774 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/run_tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ runs:
- name: Run unit tests
run: |
cd ${GITHUB_WORKSPACE}/build
./tests/test_SVD
./tests/test_Vector
./tests/test_Matrix
mpirun -n 3 --oversubscribe ./tests/test_Matrix
Expand All @@ -24,7 +23,15 @@ runs:
mpirun -n 3 --oversubscribe tests/test_StaticSVD
./tests/test_IncrementalSVDBrand
mpirun -n 3 --oversubscribe tests/test_IncrementalSVDBrand
shell: bash
- name: Basis dataset update test
run: |
cd ${GITHUB_WORKSPACE}/build/tests
cp ${GITHUB_WORKSPACE}/unit_tests/baselines/basis_conversion/* ./
cp ${GITHUB_WORKSPACE}/scripts/data/update_basis_format.py ./
python3 update_basis_format.py test_basis.000000
python3 update_basis_format.py test_basis_snapshot.000000
./test_basis_conversion
shell: bash

- name: Run regression tests
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ if(GTEST_FOUND)
GNAT
QDEIM
S_OPT
SVD
StaticSVD
RandomizedSVD
IncrementalSVD
IncrementalSVDBrand
GreedyCustomSampler)
GreedyCustomSampler
basis_conversion)
foreach(stem IN LISTS unit_test_stems)
add_executable(test_${stem} unit_tests/test_${stem}.cpp)
target_link_libraries(test_${stem} PRIVATE ROM
Expand Down
6 changes: 3 additions & 3 deletions examples/misc/combine_samples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ int main(int argc, char* argv[])
for (const auto& sample_name: sample_names) {
CAROM::BasisReader reader(sample_name);

dim = reader.getDim(kind, 0);
snaps += reader.getNumSamples(kind, 0);
dim = reader.getDim(kind);
snaps += reader.getNumSamples(kind);
if (dimFirst == 0) dimFirst = dim;

CAROM_VERIFY(dim ==
Expand Down Expand Up @@ -180,7 +180,7 @@ int main(int argc, char* argv[])
CAROM::Vector snap_cur(num_rows, true);
for (int col = 0; col < num_cols; col++) {
snap_cur = *snapshots->getColumn(col);
static_basis_generator2->takeSample(snap_cur.getData(), 0.0, false);
static_basis_generator2->takeSample(snap_cur.getData(), false);
}

/*-- Compute SVD and save file --*/
Expand Down
8 changes: 4 additions & 4 deletions examples/prom/de_parametric_maxwell_greedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ double simulation()
// 12. Set BasisGenerator if offline
if (offline)
{
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots, 1,
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots,
update_right_SV);
if (myid == 0) cout << "Saving basis to: " << saveBasisName << endl;
generator = new CAROM::BasisGenerator(*options, isIncremental, saveBasisName);
Expand Down Expand Up @@ -316,7 +316,7 @@ double simulation()
// 19. take and write snapshot for ROM
if (offline)
{
bool addSample = generator->takeSample(X.GetData(), 0.0, 0.01);
bool addSample = generator->takeSample(X.GetData());
generator->writeSnapshot();
basisIdentifiers.push_back(saveBasisName);
delete generator;
Expand All @@ -329,7 +329,7 @@ double simulation()
// 21. read the reduced basis
assembleTimer.Start();
CAROM::BasisReader reader(loadBasisName);
spatialbasis = reader.getSpatialBasis(0.0);
spatialbasis = reader.getSpatialBasis();
numRowRB = spatialbasis->numRows();
numColumnRB = spatialbasis->numColumns();

Expand Down Expand Up @@ -513,7 +513,7 @@ double simulation()
{
mergeTimer.Start();
std::unique_ptr<CAROM::BasisGenerator> basis_generator;
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots, 1,
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots,
update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, loadBasisName);
for (int i = 0; i < basisIdentifiers.size(); ++i)
Expand Down
12 changes: 6 additions & 6 deletions examples/prom/dg_advection_global_rom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,19 +692,19 @@ int main(int argc, char *argv[])
// 10. Set BasisGenerator if offline
if (offline)
{
options = new CAROM::Options(U->Size(), max_num_snapshots, 1, update_right_SV);
options = new CAROM::Options(U->Size(), max_num_snapshots, update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, basisFileName);
Vector u_curr(*U);
Vector u_centered(U->Size());
subtract(u_curr, u_init, u_centered);
bool addSample = generator->takeSample(u_centered.GetData(), t, dt);
bool addSample = generator->takeSample(u_centered.GetData());
}

// 11. The merge phase
if (merge)
{
mergeTimer.Start();
options = new CAROM::Options(U->Size(), max_num_snapshots, 1, update_right_SV);
options = new CAROM::Options(U->Size(), max_num_snapshots, update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, basisName);
for (int paramID=0; paramID<nsets; ++paramID)
{
Expand All @@ -731,11 +731,11 @@ int main(int argc, char *argv[])
CAROM::BasisReader reader(basisName);
if (rdim != -1)
{
spatialbasis = reader.getSpatialBasis(0.0, rdim);
spatialbasis = reader.getSpatialBasis(rdim);
}
else
{
spatialbasis = reader.getSpatialBasis(0.0, ef);
spatialbasis = reader.getSpatialBasis(ef);
}
numRowRB = spatialbasis->numRows();
numColumnRB = spatialbasis->numColumns();
Expand Down Expand Up @@ -831,7 +831,7 @@ int main(int argc, char *argv[])
Vector u_curr(*U);
Vector u_centered(U->Size());
subtract(u_curr, u_init, u_centered);
bool addSample = generator->takeSample(u_centered.GetData(), t, dt);
bool addSample = generator->takeSample(u_centered.GetData());
}

if (done || ti % vis_steps == 0)
Expand Down
12 changes: 6 additions & 6 deletions examples/prom/dg_advection_local_rom_matrix_interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,12 @@ int main(int argc, char *argv[])
// 10. Set BasisGenerator if offline
if (offline)
{
options = new CAROM::Options(U->Size(), max_num_snapshots, 1, update_right_SV);
options = new CAROM::Options(U->Size(), max_num_snapshots, update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, basisName);
Vector u_curr(*U);
Vector u_centered(U->Size());
subtract(u_curr, u_init, u_centered);
bool addSample = generator->takeSample(u_centered.GetData(), t, dt);
bool addSample = generator->takeSample(u_centered.GetData());
}

if (online)
Expand All @@ -723,11 +723,11 @@ int main(int argc, char *argv[])
CAROM::BasisReader reader(basisName);
if (rdim != -1)
{
spatialbasis = reader.getSpatialBasis(0.0, rdim);
spatialbasis = reader.getSpatialBasis(rdim);
}
else
{
spatialbasis = reader.getSpatialBasis(0.0, ef);
spatialbasis = reader.getSpatialBasis(ef);
}
numRowRB = spatialbasis->numRows();
numColumnRB = spatialbasis->numColumns();
Expand Down Expand Up @@ -819,7 +819,7 @@ int main(int argc, char *argv[])
CAROM::BasisReader reader(parametricBasisName);

MFEM_VERIFY(rdim != -1, "rdim must be used for interpolation.");
CAROM::Matrix* parametricSpatialBasis = reader.getSpatialBasis(0.0, rdim);
CAROM::Matrix* parametricSpatialBasis = reader.getSpatialBasis(rdim);
numRowRB = parametricSpatialBasis->numRows();
numColumnRB = parametricSpatialBasis->numColumns();
bases.push_back(parametricSpatialBasis);
Expand Down Expand Up @@ -932,7 +932,7 @@ int main(int argc, char *argv[])
Vector u_curr(*U);
Vector u_centered(U->Size());
subtract(u_curr, u_init, u_centered);
bool addSample = generator->takeSample(u_centered.GetData(), t, dt);
bool addSample = generator->takeSample(u_centered.GetData());
}

if (done || ti % vis_steps == 0)
Expand Down
8 changes: 4 additions & 4 deletions examples/prom/grad_div_global_rom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ int main(int argc, char *argv[])
// 10. Set BasisGenerator if offline
if (offline)
{
options = new CAROM::Options(fespace.GetTrueVSize(), max_num_snapshots, 1,
options = new CAROM::Options(fespace.GetTrueVSize(), max_num_snapshots,
update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, basisFileName);
}
Expand All @@ -234,7 +234,7 @@ int main(int argc, char *argv[])
if (merge)
{
mergeTimer.Start();
options = new CAROM::Options(fespace.GetTrueVSize(), max_num_snapshots, 1,
options = new CAROM::Options(fespace.GetTrueVSize(), max_num_snapshots,
update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, basisName);
for (int paramID=0; paramID<nsets; ++paramID)
Expand Down Expand Up @@ -358,7 +358,7 @@ int main(int argc, char *argv[])
// 18. take and write snapshot for ROM
if (offline)
{
generator->takeSample(X.GetData(), 0.0, 0.01);
generator->takeSample(X.GetData());
generator->writeSnapshot();
delete generator;
delete options;
Expand All @@ -370,7 +370,7 @@ int main(int argc, char *argv[])
// 20. read the reduced basis
assembleTimer.Start();
CAROM::BasisReader reader(basisName);
const CAROM::Matrix* spatialbasis = reader.getSpatialBasis(0.0);
const CAROM::Matrix* spatialbasis = reader.getSpatialBasis();
const int numRowRB = spatialbasis->numRows();
const int numColumnRB = spatialbasis->numColumns();
if (myid == 0) printf("spatial basis dimension is %d x %d\n", numRowRB,
Expand Down
8 changes: 4 additions & 4 deletions examples/prom/linear_elasticity_global_rom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ int main(int argc, char* argv[])
// 10. Set BasisGenerator if offline
if (offline)
{
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots, 1,
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots,
update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, basisFileName);
}
Expand All @@ -244,7 +244,7 @@ int main(int argc, char* argv[])
if (merge)
{
mergeTimer.Start();
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots, 1,
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots,
update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, basisName);
for (int paramID = 0; paramID < nsets; ++paramID)
Expand Down Expand Up @@ -367,7 +367,7 @@ int main(int argc, char* argv[])
// 18. take and write snapshot for ROM
if (offline)
{
bool addSample = generator->takeSample(X.GetData(), 0.0, 0.01);
bool addSample = generator->takeSample(X.GetData());
generator->writeSnapshot();
delete generator;
delete options;
Expand All @@ -379,7 +379,7 @@ int main(int argc, char* argv[])
// 20. read the reduced basis
assembleTimer.Start();
CAROM::BasisReader reader(basisName);
const CAROM::Matrix* spatialbasis = reader.getSpatialBasis(0.0);
const CAROM::Matrix* spatialbasis = reader.getSpatialBasis();
numRowRB = spatialbasis->numRows();
numColumnRB = spatialbasis->numColumns();
printf("On rank %d, spatial basis dimension is %d x %d\n", myid,
Expand Down
8 changes: 4 additions & 4 deletions examples/prom/maxwell_global_rom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ int main(int argc, char *argv[])
// 10. Set BasisGenerator if offline
if (offline)
{
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots, 1,
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots,
update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, basisFileName);
}
Expand All @@ -238,7 +238,7 @@ int main(int argc, char *argv[])
if (merge)
{
mergeTimer.Start();
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots, 1,
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots,
update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, basisName);
for (int paramID=0; paramID<nsets; ++paramID)
Expand Down Expand Up @@ -348,7 +348,7 @@ int main(int argc, char *argv[])
// 18. take and write snapshot for ROM
if (offline)
{
bool addSample = generator->takeSample(X.GetData(), 0.0, 0.01);
bool addSample = generator->takeSample(X.GetData());
generator->writeSnapshot();
delete generator;
delete options;
Expand All @@ -360,7 +360,7 @@ int main(int argc, char *argv[])
// 20. read the reduced basis
assembleTimer.Start();
CAROM::BasisReader reader(basisName);
spatialbasis = reader.getSpatialBasis(0.0);
spatialbasis = reader.getSpatialBasis();
numRowRB = spatialbasis->numRows();
numColumnRB = spatialbasis->numColumns();
if (myid == 0) printf("spatial basis dimension is %d x %d\n", numRowRB,
Expand Down
8 changes: 4 additions & 4 deletions examples/prom/maxwell_local_rom_greedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ int main(int argc, char *argv[])
// 12. Set BasisGenerator if offline
if (offline)
{
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots, 1,
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots,
update_right_SV);
if (myid == 0) cout << "Saving basis to: " << saveBasisName << endl;
generator = new CAROM::BasisGenerator(*options, isIncremental, saveBasisName);
Expand Down Expand Up @@ -469,7 +469,7 @@ int main(int argc, char *argv[])
// 19. take and write snapshot for ROM
if (offline)
{
bool addSample = generator->takeSample(X.GetData(), 0.0, 0.01);
bool addSample = generator->takeSample(X.GetData());
generator->writeSnapshot();
basisIdentifiers.push_back(saveBasisName);
delete generator;
Expand All @@ -482,7 +482,7 @@ int main(int argc, char *argv[])
// 21. read the reduced basis
assembleTimer.Start();
CAROM::BasisReader reader(loadBasisName);
spatialbasis = reader.getSpatialBasis(0.0);
spatialbasis = reader.getSpatialBasis();
numRowRB = spatialbasis->numRows();
numColumnRB = spatialbasis->numColumns();
if (myid == 0) printf("spatial basis dimension is %d x %d\n", numRowRB,
Expand Down Expand Up @@ -635,7 +635,7 @@ int main(int argc, char *argv[])
{
mergeTimer.Start();
std::unique_ptr<CAROM::BasisGenerator> basis_generator;
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots, 1,
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots,
update_right_SV);
generator = new CAROM::BasisGenerator(*options, isIncremental, loadBasisName);
for (int i = 0; i < basisIdentifiers.size(); ++i)
Expand Down
Loading

0 comments on commit fde345c

Please sign in to comment.