Skip to content

Commit

Permalink
ROMNonlinearForm::Get/Save/LoadEQPForIntegrator with general integrat…
Browse files Browse the repository at this point in the history
…or type.
  • Loading branch information
dreamer2368 committed Feb 12, 2024
1 parent f35c382 commit fcf4ef7
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 18 deletions.
14 changes: 11 additions & 3 deletions include/rom_nonlinearform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
namespace mfem
{

enum IntegratorType
{
DOMAIN,
INTERIORFACE,
BDRFACE,
NUM_INTEG_TYPE
};

class ROMNonlinearForm : public NonlinearForm
{
private:
Expand Down Expand Up @@ -71,9 +79,9 @@ class ROMNonlinearForm : public NonlinearForm
void SetupEQPSystemForBdrFaceIntegrator(const CAROM::Matrix &snapshots, HyperReductionIntegrator *nlfi,
const Array<int> &bdr_attr_marker, CAROM::Matrix &Gt, CAROM::Vector &rhs_Gw, Array<int> &bidxs);

void GetEQPForDomainIntegrator(const int k, Array<int> &sample_el, Array<int> &sample_qp, Array<double> &sample_qw);
void SaveEQPForDomainIntegrator(const int k, hid_t file_id, const std::string &dsetname);
void LoadEQPForDomainIntegrator(const int k, hid_t file_id, const std::string &dsetname);
void GetEQPForIntegrator(const IntegratorType type, const int k, Array<int> &sample_el, Array<int> &sample_qp, Array<double> &sample_qw);
void SaveEQPForIntegrator(const IntegratorType type, const int k, hid_t file_id, const std::string &dsetname);
void LoadEQPForIntegrator(const IntegratorType type, const int k, hid_t file_id, const std::string &dsetname);

/// Adds new Domain Integrator.
void AddDomainIntegrator(HyperReductionIntegrator *nlfi)
Expand Down
83 changes: 70 additions & 13 deletions src/rom_nonlinearform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,31 +1147,70 @@ void ROMNonlinearForm::SetupEQPSystemForBdrFaceIntegrator(
return;
}

void ROMNonlinearForm::GetEQPForDomainIntegrator(
const int k, Array<int> &el, Array<int> &qp, Array<double> &qw)
void ROMNonlinearForm::GetEQPForIntegrator(
const IntegratorType type, const int k, Array<int> &el, Array<int> &qp, Array<double> &qw)
{
assert((k >= 0) && (k < dnfi.Size()));
assert(dnfi.Size() == dnfi_sample.Size());
Array<SampleInfo> *sample = NULL;
switch (type)
{
case IntegratorType::DOMAIN:
{
assert((k >= 0) && (k < dnfi.Size()));
assert(dnfi.Size() == dnfi_sample.Size());
sample = dnfi_sample[k];
}
break;
case IntegratorType::INTERIORFACE:
{
assert((k >= 0) && (k < fnfi.Size()));
assert(fnfi.Size() == fnfi_sample.Size());
sample = fnfi_sample[k];
}
break;
case IntegratorType::BDRFACE:
{
assert((k >= 0) && (k < bfnfi.Size()));
assert(bfnfi.Size() == bfnfi_sample.Size());
sample = bfnfi_sample[k];
}
break;
default:
mfem_error("Unknown Integrator type!\n");
}

el.SetSize(0);
qp.SetSize(0);
qw.SetSize(0);

Array<SampleInfo> *sample = dnfi_sample[k];

for (int s = 0; s < sample->Size(); s++)
{
el.Append((*sample)[s].el);
switch (type)
{
case IntegratorType::DOMAIN: el.Append((*sample)[s].el); break;
case IntegratorType::INTERIORFACE: el.Append((*sample)[s].face); break;
case IntegratorType::BDRFACE: el.Append((*sample)[s].be); break;
}
qp.Append((*sample)[s].qp);
qw.Append((*sample)[s].qw);
}
}

void ROMNonlinearForm::SaveEQPForDomainIntegrator(const int k, hid_t file_id, const std::string &dsetname)
void ROMNonlinearForm::SaveEQPForIntegrator(
const IntegratorType type, const int k, hid_t file_id, const std::string &dsetname)
{
std::string eldset;
switch (type)
{
case IntegratorType::DOMAIN: eldset = "elem"; break;
case IntegratorType::INTERIORFACE: eldset = "face"; break;
case IntegratorType::BDRFACE: eldset = "be"; break;
default:
mfem_error("ROMNonlinearForm::SaveEQPForIntegrator- Unknown IntegratorType!\n");
}

Array<int> el, qp;
Array<double> qw;
GetEQPForDomainIntegrator(k, el, qp, qw);
GetEQPForIntegrator(type, k, el, qp, qw);

assert(file_id >= 0);
hid_t grp_id;
Expand All @@ -1180,7 +1219,7 @@ void ROMNonlinearForm::SaveEQPForDomainIntegrator(const int k, hid_t file_id, co
grp_id = H5Gcreate(file_id, dsetname.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
assert(grp_id >= 0);

hdf5_utils::WriteDataset(grp_id, "elem", el);
hdf5_utils::WriteDataset(grp_id, eldset, el);
hdf5_utils::WriteDataset(grp_id, "quad-pt", qp);
hdf5_utils::WriteDataset(grp_id, "quad-wt", qw);

Expand All @@ -1189,8 +1228,19 @@ void ROMNonlinearForm::SaveEQPForDomainIntegrator(const int k, hid_t file_id, co
return;
}

void ROMNonlinearForm::LoadEQPForDomainIntegrator(const int k, hid_t file_id, const std::string &dsetname)
void ROMNonlinearForm::LoadEQPForIntegrator(
const IntegratorType type, const int k, hid_t file_id, const std::string &dsetname)
{
std::string eldset;
switch (type)
{
case IntegratorType::DOMAIN: eldset = "elem"; break;
case IntegratorType::INTERIORFACE: eldset = "face"; break;
case IntegratorType::BDRFACE: eldset = "be"; break;
default:
mfem_error("ROMNonlinearForm::LoadEQPForIntegrator- Unknown IntegratorType!\n");
}

Array<int> el, qp;
Array<double> qw;

Expand All @@ -1201,14 +1251,21 @@ void ROMNonlinearForm::LoadEQPForDomainIntegrator(const int k, hid_t file_id, co
grp_id = H5Gopen2(file_id, dsetname.c_str(), H5P_DEFAULT);
assert(grp_id >= 0);

hdf5_utils::ReadDataset(grp_id, "elem", el);
hdf5_utils::ReadDataset(grp_id, eldset, el);
hdf5_utils::ReadDataset(grp_id, "quad-pt", qp);
hdf5_utils::ReadDataset(grp_id, "quad-wt", qw);

errf = H5Gclose(grp_id);
assert(errf >= 0);

UpdateDomainIntegratorSampling(k, el, qp, qw);
switch (type)
{
case IntegratorType::DOMAIN: UpdateDomainIntegratorSampling(k, el, qp, qw); break;
case IntegratorType::INTERIORFACE: UpdateInteriorFaceIntegratorSampling(k, el, qp, qw); break;
case IntegratorType::BDRFACE: UpdateBdrFaceIntegratorSampling(k, el, qp, qw); break;
default:
mfem_error("ROMNonlinearForm::LoadEQPForIntegrator- Unknown IntegratorType!\n");
}
return;
}

Expand Down
6 changes: 4 additions & 2 deletions src/steady_ns_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,8 @@ void SteadyNSSolver::SaveEQP()
{
assert(comp_eqps[c]);
dset_name = GetBasisTagForComponent(c, train_mode, topol_handler);
comp_eqps[c]->SaveEQPForDomainIntegrator(0, file_id, dset_name);
// only one integrator exists in each nonlinear form.
comp_eqps[c]->SaveEQPForIntegrator(IntegratorType::DOMAIN, 0, file_id, dset_name);
}

errf = H5Fclose(file_id);
Expand Down Expand Up @@ -812,7 +813,8 @@ void SteadyNSSolver::LoadEQP()
{
assert(comp_eqps[c]);
dset_name = GetBasisTagForComponent(c, train_mode, topol_handler);
comp_eqps[c]->LoadEQPForDomainIntegrator(0, file_id, dset_name);
// only one integrator exists in each nonlinear form.
comp_eqps[c]->LoadEQPForIntegrator(IntegratorType::DOMAIN, 0, file_id, dset_name);

if (comp_eqps[c]->PrecomputeMode())
comp_eqps[c]->PrecomputeCoefficients();
Expand Down

0 comments on commit fcf4ef7

Please sign in to comment.