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

Eqp train #48

Merged
merged 28 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
469fb2b
SteadyNSSolver::InitROMHandler
dreamer2368 Jun 19, 2024
1544fde
separated InitROMHandler from InitVariables
dreamer2368 Jun 19, 2024
41afdd2
cleaning up top-level routines. need some more thoughts on ROM elemen…
dreamer2368 Jun 20, 2024
91b3b2a
add random boundary on eqp test.
dreamer2368 Jun 20, 2024
497ca6e
LF flux does not work with constant rhs
dreamer2368 Jun 20, 2024
b09e152
BasisTag struct
dreamer2368 Jun 20, 2024
e9ef814
hdf5_utils::Read/WriteAttributes for BasisTag
dreamer2368 Jun 21, 2024
41b96a2
Sample collection by port files
dreamer2368 Jun 21, 2024
3de19aa
interface test with periodic config.
dreamer2368 Jun 21, 2024
9d2a7cf
ROMInterfaceForm takes component basis and fes. subdomain basis and f…
dreamer2368 Jun 25, 2024
bfece76
SteadyNSSolver::TrainEQPElems
dreamer2368 Jun 25, 2024
4f047da
minor fix on face integraton rule.
dreamer2368 Jun 26, 2024
54d4fe2
Read/WriteDataset for Array<SampleInfo>
dreamer2368 Jun 26, 2024
ae3d14d
ChannelFlow minor fix
dreamer2368 Jun 26, 2024
2981d67
ROMInterfaceForm::SaveEQPForIntegrator
dreamer2368 Jun 26, 2024
14bcbbd
ROMInterfaceForm::LoadEQPForIntegrator
dreamer2368 Jun 27, 2024
e43a952
Plug in rom interface form into SteadyNSEQPROM. Still needs to handle…
dreamer2368 Jun 27, 2024
a8426b7
SampleInfo consolidated el, be, face, itf into el.
dreamer2368 Jul 2, 2024
d29bf00
ROMNonlinearForm::GetEQPforIntegrator
dreamer2368 Jul 2, 2024
2de776d
ROMNonlinearForm: decided to own bfnfi_markers, as opposed to the par…
dreamer2368 Jul 2, 2024
b9bb274
SteadyNSSolver::AssembleROMEQPOper. need verification..
dreamer2368 Jul 3, 2024
852ad80
lid driven cavity problem
dreamer2368 Jul 3, 2024
98d94ad
randomizing rom nonlinear solve initial guess.
dreamer2368 Jul 3, 2024
d71942a
SteadyNSSolver LF test without interface.
dreamer2368 Jul 3, 2024
21828a2
interface eqp verified. interface to self is not working and needs a …
dreamer2368 Jul 3, 2024
256b02f
workflow with multiple port file verified.
dreamer2368 Jul 3, 2024
20af75a
error flag for self interface
dreamer2368 Jul 3, 2024
d7cfef3
adjusted threshold
dreamer2368 Jul 3, 2024
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
Prev Previous commit
Next Next commit
SteadyNSSolver LF test without interface.
dreamer2368 committed Jul 3, 2024
commit d71942af5874c949e5746e5332565383c9f732b0
17 changes: 12 additions & 5 deletions include/hdf5_utils.hpp
Original file line number Diff line number Diff line change
@@ -87,8 +87,11 @@ void ReadDataset(hid_t &source, std::string dataset, Array<T> &value)
assert(errf >= 0);

value.SetSize(dims[0]);
hid_t dataType = hdf5_utils::GetType(value[0]);
H5Dread(dset_id, dataType, H5S_ALL, H5S_ALL, H5P_DEFAULT, value.Write());
if (dims[0] > 0)
{
hid_t dataType = hdf5_utils::GetType(value[0]);
H5Dread(dset_id, dataType, H5S_ALL, H5S_ALL, H5P_DEFAULT, value.Write());
}

errf = H5Dclose(dset_id);
assert(errf >= 0);
@@ -134,7 +137,8 @@ void WriteDataset(hid_t &source, std::string dataset, const Array<T> &value)
{
herr_t errf = 0;

hid_t dataType = hdf5_utils::GetType(value[0]);
T tmp;
hid_t dataType = hdf5_utils::GetType(tmp);
hsize_t dims[1];
dims[0] = value.Size();

@@ -144,8 +148,11 @@ void WriteDataset(hid_t &source, std::string dataset, const Array<T> &value)
hid_t dset_id = H5Dcreate2(source, dataset.c_str(), dataType, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
assert(dset_id >= 0);

errf = H5Dwrite(dset_id, dataType, H5S_ALL, H5S_ALL, H5P_DEFAULT, value.Read());
assert(errf >= 0);
if (dims[0] > 0)
{
errf = H5Dwrite(dset_id, dataType, H5S_ALL, H5S_ALL, H5P_DEFAULT, value.Read());
assert(errf >= 0);
}

errf = H5Dclose(dset_id);
assert(errf >= 0);
6 changes: 3 additions & 3 deletions include/parameterized_problem.hpp
Original file line number Diff line number Diff line change
@@ -359,11 +359,11 @@ class PeriodicFlowPastArray : public FlowProblem
PeriodicFlowPastArray();
};

class ForceDrivenCavity : public PeriodicFlowPastArray
class ForceDrivenCorner : public PeriodicFlowPastArray
{
public:
ForceDrivenCavity();
virtual ~ForceDrivenCavity() {};
ForceDrivenCorner();
virtual ~ForceDrivenCorner() {};
};

class LinElastProblem : public ParameterizedProblem
10 changes: 6 additions & 4 deletions src/parameterized_problem.cpp
Original file line number Diff line number Diff line change
@@ -517,9 +517,9 @@ ParameterizedProblem* InitParameterizedProblem()
{
problem = new LidDrivenCavity();
}
else if (problem_name == "force_driven_cavity")
else if (problem_name == "force_driven_corner")
{
problem = new ForceDrivenCavity();
problem = new ForceDrivenCorner();
}
else if (problem_name == "periodic_flow_past_array")
{
@@ -988,17 +988,19 @@ PeriodicFlowPastArray::PeriodicFlowPastArray()
}

/*
ForceDrivenCavity
ForceDrivenCorner
*/

ForceDrivenCavity::ForceDrivenCavity()
ForceDrivenCorner::ForceDrivenCorner()
: PeriodicFlowPastArray()
{
battr.SetSize(5);
for (int b = 0; b < 5; b++)
battr[b] = b+1;
bdr_type.SetSize(5);
bdr_type = BoundaryType::ZERO;
bdr_type[2] = BoundaryType::NEUMANN;
bdr_type[3] = BoundaryType::NEUMANN;

// pointer to static function.
vector_bdr_ptr.SetSize(5);
2 changes: 1 addition & 1 deletion src/rom_handler.cpp
Original file line number Diff line number Diff line change
@@ -575,7 +575,7 @@ void MFEMROMHandler::NonlinearSolve(Operator &oper, BlockVector* U, Solver *prec
else
{
for (int k = 0; k < reduced_sol->Size(); k++)
(*reduced_sol)(k) = UniformRandom();
(*reduced_sol)(k) = 1.0e-1 * UniformRandom();
}

int maxIter = config.GetOption<int>("solver/max_iter", 100);
2 changes: 1 addition & 1 deletion src/rom_nonlinearform.cpp
Original file line number Diff line number Diff line change
@@ -752,6 +752,7 @@ void ROMNonlinearForm::TrainEQPForIntegrator(
// void SolveNNLS(const int rank, const double nnls_tol, const int maxNNLSnnz,
// CAROM::Vector const& w, CAROM::Matrix & Gt,
// CAROM::Vector & sol)
const double normRHS = rhs_Gw.norm();
double nnls_tol = 1.0e-11;
int maxNNLSnnz = 0;
CAROM::Vector eqpSol(Gt.numRows(), true);
@@ -804,7 +805,6 @@ void ROMNonlinearForm::TrainEQPForIntegrator(
Gt.transposeMult(eqpSol, res);

const double normGsol = res.norm();
const double normRHS = rhs_Gw.norm();

res -= rhs_Gw;
const double relNorm = res.norm() / std::max(normGsol, normRHS);
2 changes: 2 additions & 0 deletions test/gmsh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -7,8 +7,10 @@ file(COPY square.mesh DESTINATION ${CMAKE_BINARY_DIR}/test/gmsh/)
file(COPY square.tri.mesh DESTINATION ${CMAKE_BINARY_DIR}/test/gmsh/)
file(COPY test.multi_comp.h5 DESTINATION ${CMAKE_BINARY_DIR}/test/gmsh/)
file(COPY box-channel.1x1.periodic.h5 DESTINATION ${CMAKE_BINARY_DIR}/test/gmsh/)
file(COPY box-channel.1x2.h5 DESTINATION ${CMAKE_BINARY_DIR}/test/gmsh/)
file(COPY test.component.yml DESTINATION ${CMAKE_BINARY_DIR}/test/gmsh/)
file(COPY stokes.component.yml DESTINATION ${CMAKE_BINARY_DIR}/test/gmsh/)
file(COPY steadyns.lf.yml DESTINATION ${CMAKE_BINARY_DIR}/test/gmsh/)
file(COPY steadyns.interface_eqp.yml DESTINATION ${CMAKE_BINARY_DIR}/test/gmsh/)

ADD_CUSTOM_COMMAND(
Binary file added test/gmsh/box-channel.1x2.h5
Binary file not shown.
80 changes: 80 additions & 0 deletions test/gmsh/steadyns.lf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
main:
#mode: run_example/sample_generation/build_rom/single_run
mode: single_run
use_rom: true
solver: steady-ns

navier-stokes:
operator-type: lf

mesh:
type: component-wise
component-wise:
global_config: "box-channel.1x2.h5"
components:
- name: "square-circle"
file: "square-circle.msh.mfem"

domain-decomposition:
type: interior_penalty

discretization:
order: 1
full-discrete-galerkin: true

solver:
direct_solve: true

visualization:
enable: false
output_dir: dd_mms_output

parameterized_problem:
name: force_driven_corner

single_run:
force_driven_corner:
nu: 1.1
fx: 0.
fy: -0.5

sample_generation:
maximum_number_of_snapshots: 400
component_sampling: false
file_path:
prefix: "stokes"
parameters:
- key: single_run/force_driven_corner/nu
type: double
sample_size: 3
minimum: 1.0
maximum: 1.2

sample_collection:
mode: port

basis:
prefix: "stokes"
number_of_basis: 6
svd:
save_spectrum: true
update_right_sv: false
visualization:
enabled: false

model_reduction:
separate_variable_basis: true
rom_handler_type: mfem
# individual/universal
subdomain_training: universal
nonlinear_handling: eqp
eqp:
relative_tolerance: 1.0e-11
precompute: true
save_operator:
level: component
prefix: "test.rom_elem"
compare_solution:
enabled: true
linear_solver_type: direct
linear_system_type: us
33 changes: 31 additions & 2 deletions test/gmsh/test_multi_comp_workflow.cpp
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ using namespace mfem;

static const double threshold = 1.0e-14;
static const double stokes_threshold = 2.0e-12;
static const double ns_threshold = 1.0e-9;
static const double ns_threshold = 1.0e-7;

/**
* Simple smoke test to make sure Google Test is properly linked
@@ -219,6 +219,35 @@ TEST(ComponentWiseTest, SteadyNSTest_SeparateVariable_EQP)
return;
}

TEST(SteadyNS_Workflow, LF)
{
config = InputParser("steadyns.lf.yml");

printf("\nSample Generation \n\n");

config.dict_["main"]["mode"] = "sample_generation";
GenerateSamples(MPI_COMM_WORLD);

config.dict_["main"]["mode"] = "train_rom";
TrainROM(MPI_COMM_WORLD);

config.dict_["main"]["mode"] = "train_eqp";
TrainEQP(MPI_COMM_WORLD);

printf("\nBuild ROM \n\n");

config.dict_["main"]["mode"] = "build_rom";
BuildROM(MPI_COMM_WORLD);

config.dict_["main"]["mode"] = "single_run";
double error = SingleRun(MPI_COMM_WORLD, "test_output.h5");

// This reproductive case must have a very small error at the level of finite-precision.
printf("Error: %.15E\n", error);
EXPECT_TRUE(error < ns_threshold);

return;
}

TEST(SteadyNS_Workflow, InterfaceEQP)
{
@@ -245,7 +274,7 @@ TEST(SteadyNS_Workflow, InterfaceEQP)

// // This reproductive case must have a very small error at the level of finite-precision.
// printf("Error: %.15E\n", error);
// EXPECT_TRUE(error < stokes_threshold);
// EXPECT_TRUE(error < ns_threshold);

return;
}