Skip to content

Commit

Permalink
component tensor is factored out from linear ROM.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer2368 committed Apr 11, 2024
1 parent c029597 commit 0eaafbf
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 131 deletions.
17 changes: 17 additions & 0 deletions include/multiblock_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,30 @@ friend class ParameterizedProblem;
void LoadSolution(const std::string &filename);
void CopySolution(BlockVector *input_sol);

virtual void AllocateROMTensorElems()
{ mfem_error("Abstract method MultiBlockSolver::AllocateROMTensorElems!\n"); }
virtual void BuildROMTensorElems()
{ mfem_error("Abstract method MultiBlockSolver::BuildROMTensorElems!\n"); }
virtual void SaveROMTensorElems(const std::string &filename)
{ mfem_error("Abstract method MultiBlockSolver::SaveROMTensorElems!\n"); }
virtual void LoadROMTensorElems(const std::string &filename)
{ mfem_error("Abstract method MultiBlockSolver::LoadROMTensorElems!\n"); }
virtual void AssembleROMTensorOper()
{ mfem_error("Abstract method MultiBlockSolver::AssembleROMTensorOper!\n"); }

virtual void AllocateROMEQPElems()
{ mfem_error("Abstract method MultiBlockSolver::AllocateROMEQPElems!\n"); }
virtual void TrainEQP(SampleGenerator *sample_generator)
{ mfem_error("Abstract method MultiBlockSolver::TrainEQP!\n"); }
virtual void SaveEQP()
{ mfem_error("Abstract method MultiBlockSolver::TrainEQP!\n"); }
virtual void LoadEQP()
{ mfem_error("Abstract method MultiBlockSolver::TrainEQP!\n"); }

void AllocateROMNlinElems();
void LoadROMNlinElems(const std::string &filename);
void AssembleROMNlinOper();

void InitROMHandler();
void GetBasisTags(std::vector<std::string> &basis_tags);

Expand Down
14 changes: 6 additions & 8 deletions include/steady_ns_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,18 @@ friend class SteadyNSOperator;
void SaveROMOperator(const std::string input_prefix="") override;
void LoadROMOperatorFromFile(const std::string input_prefix="") override;

// Component-wise assembly
void AllocateROMLinElems() override;
void BuildCompROMLinElems(Array<FiniteElementSpace *> &fes_comp) override;
// virtual void BuildBdrROMLinElems(Array<FiniteElementSpace *> &fes_comp);
// virtual void BuildItfaceROMLinElems(Array<FiniteElementSpace *> &fes_comp);
void SaveCompBdrROMLinElems(hid_t &file_id) override;
void LoadCompBdrROMLinElems(hid_t &file_id) override;

bool Solve() override;

void ProjectOperatorOnReducedBasis() override;

void SolveROM() override;

void AllocateROMTensorElems() override;
void BuildROMTensorElems() override;
void SaveROMTensorElems(const std::string &filename) override;
void LoadROMTensorElems(const std::string &filename) override;
void AssembleROMTensorOper() override;

void TrainEQP(SampleGenerator *sample_generator) override;
void SaveEQP() override;
void LoadEQP() override;
Expand Down
22 changes: 18 additions & 4 deletions src/main_workflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,14 @@ void BuildROM(MPI_Comm comm)
test->LoadReducedBasis();

TopologyHandlerMode topol_mode = test->GetTopologyMode();
ROMBuildingLevel save_operator = test->GetROMHandler()->GetBuildingLevel();
ROMHandlerBase *rom = test->GetROMHandler();
ROMBuildingLevel save_operator = rom->GetBuildingLevel();

// NOTE(kevin): global operator required only for global rom operator.
if (save_operator == ROMBuildingLevel::GLOBAL)
test->Assemble();

std::string filename = rom->GetOperatorPrefix() + ".h5";
switch (save_operator)
{
case ROMBuildingLevel::COMPONENT:
Expand All @@ -425,8 +428,14 @@ void BuildROM(MPI_Comm comm)

test->AllocateROMLinElems();
test->BuildROMLinElems();
std::string filename = test->GetROMHandler()->GetOperatorPrefix() + ".h5";
test->SaveROMLinElems(filename);

if ((test->IsNonlinear()) && (rom->GetNonlinearHandling() == NonlinearHandling::TENSOR))
{
test->AllocateROMTensorElems();
test->BuildROMTensorElems();
test->SaveROMTensorElems(filename);
}
break;
}
case ROMBuildingLevel::GLOBAL:
Expand Down Expand Up @@ -506,6 +515,7 @@ double SingleRun(MPI_Comm comm, const std::string output_file)
else
mfem_error("Unknown TopologyHandler Mode!\n");

std::string filename = rom->GetOperatorPrefix() + ".h5";
if (save_operator == ROMBuildingLevel::COMPONENT)
{
if (topol_mode == TopologyHandlerMode::SUBMESH)
Expand All @@ -514,15 +524,19 @@ double SingleRun(MPI_Comm comm, const std::string output_file)
test->AllocateROMLinElems();

printf("Loading ROM projected elements.. ");
std::string filename = rom->GetOperatorPrefix() + ".h5";
test->LoadROMLinElems(filename);
printf("Done!\n");

printf("Assembling ROM linear matrix.. ");
test->AssembleROMMat();
printf("Done!\n");


if (test->IsNonlinear())
{
test->AllocateROMNlinElems();
test->LoadROMNlinElems(filename);
test->AssembleROMNlinOper();
}
} // if (save_operator == ROMBuildingLevel::COMPONENT)
else if (save_operator == ROMBuildingLevel::GLOBAL)
{
Expand Down
45 changes: 30 additions & 15 deletions src/multiblock_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,24 +832,39 @@ void MultiBlockSolver::CopySolution(BlockVector *input_sol)
*U = *input_sol;
}

void MultiBlockSolver::InitROMHandler()
void MultiBlockSolver::AllocateROMNlinElems()
{
// std::string rom_handler_str = config.GetOption<std::string>("model_reduction/rom_handler_type", "base");
assert(nonlinear_mode);
assert(rom_handler);
NonlinearHandling rom_nlin_mode = rom_handler->GetNonlinearHandling();

rom_handler = new MFEMROMHandler(train_mode, topol_handler, var_offsets, var_names, separate_variable_basis);
if (rom_nlin_mode == NonlinearHandling::TENSOR) AllocateROMTensorElems();
// else if (rom_nlin_mode == NonlinearHandling::EQP) AllocateROMEQPElems();
}

void MultiBlockSolver::LoadROMNlinElems(const std::string &filename)
{
assert(nonlinear_mode);
assert(rom_handler);
NonlinearHandling rom_nlin_mode = rom_handler->GetNonlinearHandling();

if (rom_nlin_mode == NonlinearHandling::TENSOR) LoadROMTensorElems(filename);
// else if (rom_nlin_mode == NonlinearHandling::EQP) AllocateROMEQPElems();
}

// if (rom_handler_str == "base")
// {
// rom_handler = new ROMHandler(train_mode, topol_handler, var_offsets, var_names, separate_variable_basis);
// }
// else if (rom_handler_str == "mfem")
// {
// rom_handler = new MFEMROMHandler(train_mode, topol_handler, var_offsets, var_names, separate_variable_basis);
// }
// else
// {
// mfem_error("Unknown ROM handler type!\n");
// }
void MultiBlockSolver::AssembleROMNlinOper()
{
assert(nonlinear_mode);
assert(rom_handler);
NonlinearHandling rom_nlin_mode = rom_handler->GetNonlinearHandling();

if (rom_nlin_mode == NonlinearHandling::TENSOR) AssembleROMTensorOper();
// else if (rom_nlin_mode == NonlinearHandling::EQP) AllocateROMEQPElems();
}

void MultiBlockSolver::InitROMHandler()
{
rom_handler = new MFEMROMHandler(train_mode, topol_handler, var_offsets, var_names, separate_variable_basis);
}

void MultiBlockSolver::GetBasisTags(std::vector<std::string> &basis_tags)
Expand Down
Loading

0 comments on commit 0eaafbf

Please sign in to comment.