Skip to content
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

ROMHandler::SaveRomSystem. #16

Merged
merged 1 commit into from
Feb 13, 2024
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
5 changes: 2 additions & 3 deletions include/rom_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ class ROMHandlerBase
*/
Array<int> rom_varblock_offsets;

CAROM::Vector *reduced_rhs = NULL;
CAROM::Vector *reduced_sol = NULL;

CAROM::Options* rom_options;
CAROM::BasisGenerator *basis_generator;
CAROM::BasisReader *basis_reader;
Expand Down Expand Up @@ -169,6 +166,7 @@ class ROMHandlerBase
virtual void SaveOperator(const std::string input_prefix="") = 0;
virtual void LoadOperatorFromFile(const std::string input_prefix="") = 0;
virtual void SetRomMat(BlockMatrix *input_mat) = 0;
virtual void SaveRomSystem(const std::string &input_prefix, const std::string type="mm") = 0;

virtual void SaveBasisVisualization(const Array<FiniteElementSpace *> &fes, const std::vector<std::string> &var_names) = 0;

Expand Down Expand Up @@ -254,6 +252,7 @@ class MFEMROMHandler : public ROMHandlerBase
virtual void SaveOperator(const std::string input_prefix="");
virtual void LoadOperatorFromFile(const std::string input_prefix="");
virtual void SetRomMat(BlockMatrix *input_mat);
virtual void SaveRomSystem(const std::string &input_prefix, const std::string type="mm");

virtual void SaveBasisVisualization(const Array<FiniteElementSpace *> &fes, const std::vector<std::string> &var_names);

Expand Down
8 changes: 8 additions & 0 deletions src/main_workflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,14 @@ double SingleRun(MPI_Comm comm, const std::string output_file)
else
fom_solve = solveTimer.RealTime();

/* save the ROM system for analysis/debug */
bool save_rom = config.GetOption<bool>("model_reduction/save_linear_system/enabled", false);
if (save_rom)
{
std::string rom_prefix = config.GetRequiredOption<std::string>("model_reduction/save_linear_system/prefix");
rom->SaveRomSystem(rom_prefix);
}

bool compare_sol = config.GetOption<bool>("model_reduction/compare_solution/enabled", false);
bool load_sol = config.GetOption<bool>("model_reduction/compare_solution/load_solution", false);
if (test->UseRom() && compare_sol)
Expand Down
26 changes: 24 additions & 2 deletions src/rom_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ ROMHandlerBase::ROMHandlerBase(

ROMHandlerBase::~ROMHandlerBase()
{
delete reduced_rhs;
delete reduced_sol;
DeletePointers(carom_ref_basis);
}

void ROMHandlerBase::ParseInputs()
Expand Down Expand Up @@ -909,6 +908,29 @@ void MFEMROMHandler::SetRomMat(BlockMatrix *input_mat)
operator_loaded = true;
}

void MFEMROMHandler::SaveRomSystem(const std::string &input_prefix, const std::string type)
{
if (!romMat_mono)
{
assert(romMat);
romMat_mono = romMat->CreateMonolithic();
}
assert(reduced_rhs);
assert(reduced_sol);

PrintVector(*reduced_rhs, input_prefix + "_rhs.txt");
PrintVector(*reduced_sol, input_prefix + "_sol.txt");

std::string matfile = input_prefix + "_mat." + type;
std::ofstream file(matfile.c_str());
if (type == "mm")
romMat_mono->PrintMM(file);
else if (type == "matlab")
romMat_mono->PrintMatlab(file);
else
mfem_error("MFEMROMHandler::SaveRomSystem - unknown matrix format type!\n");
}

void MFEMROMHandler::SaveBasisVisualization(
const Array<FiniteElementSpace *> &fes, const std::vector<std::string> &var_names)
{
Expand Down
Loading