1 #include "hyper_reduction_post_sampling.h" 2 #include "reduced_order/pod_basis_offline.h" 3 #include "parameters/all_parameters.h" 4 #include "flow_solver/flow_solver.h" 5 #include "flow_solver/flow_solver_factory.h" 6 #include "ode_solver/ode_solver_factory.h" 7 #include "reduced_order/assemble_ECSW_residual.h" 8 #include "reduced_order/assemble_ECSW_jacobian.h" 9 #include "linear_solver/NNLS_solver.h" 10 #include "linear_solver/helper_functions.h" 11 #include "reduced_order/pod_adaptive_sampling.h" 12 #include "reduced_order/hyper_reduced_adaptive_sampling.h" 13 #include "reduced_order/multi_core_helper_functions.h" 14 #include "rom_import_helper_functions.h" 15 #include <eigen/Eigen/Dense> 23 template <
int dim,
int nstate>
25 const dealii::ParameterHandler ¶meter_handler_input)
27 , parameter_handler(parameter_handler_input)
30 template <
int dim,
int nstate>
39 template <
int dim,
int nstate>
42 pcout <<
"Starting hyperreduction test..." << std::endl;
44 Epetra_MpiComm Comm( MPI_COMM_WORLD );
47 auto ode_solver_type = Parameters::ODESolverParam::ODESolverEnum::hyper_reduced_petrov_galerkin_solver;
51 parameter_sampling->run_sampling();
54 std::cout <<
"Construct instance of Assembler..."<< std::endl;
55 std::shared_ptr<HyperReduction::AssembleECSWBase<dim,nstate>> constructor_NNLS_problem;
56 if (this->all_parameters->hyper_reduction_param.training_data ==
"residual")
57 constructor_NNLS_problem = std::make_shared<HyperReduction::AssembleECSWRes<dim,nstate>>(
all_parameters,
parameter_handler, flow_solver_hyper_reduced_petrov_galerkin->dg, parameter_sampling->current_pod, parameter_sampling->snapshot_parameters, ode_solver_type, Comm);
59 constructor_NNLS_problem = std::make_shared<HyperReduction::AssembleECSWJac<dim,nstate>>(
all_parameters,
parameter_handler, flow_solver_hyper_reduced_petrov_galerkin->dg, parameter_sampling->current_pod, parameter_sampling->snapshot_parameters, ode_solver_type, Comm);
61 for (
unsigned int j = 0 ; j < parameter_sampling->fom_locations.size() ; j++ ){
62 constructor_NNLS_problem->update_snapshots(parameter_sampling->fom_locations[j]);
64 std::cout <<
"Build Problem..."<< std::endl;
65 constructor_NNLS_problem->build_problem();
68 const int rank = Comm.MyPID();
69 int rows = (constructor_NNLS_problem->A_T->trilinos_matrix()).NumGlobalCols();
70 Epetra_Map bMap(rows, (rank == 0) ? rows: 0, 0, Comm);
71 Epetra_Vector b_Epetra(bMap);
72 auto b = constructor_NNLS_problem->b;
73 unsigned int local_length = bMap.NumMyElements();
74 for(
unsigned int i = 0 ; i < local_length ; i++){
79 std::cout <<
"Create NNLS problem..."<< std::endl;
80 NNLSSolver NNLS_prob(all_parameters, parameter_handler, constructor_NNLS_problem->A_T->trilinos_matrix(),
true, Comm, b_Epetra);
81 std::cout <<
"Solve NNLS problem..."<< std::endl;
82 bool exit_con = NNLS_prob.
solve();
83 std::cout << exit_con << std::endl;
85 std::shared_ptr<Epetra_Vector> ptr_weights = std::make_shared<Epetra_Vector>(NNLS_prob.get_solution());
86 std::cout <<
"ECSW Weights"<< std::endl;
87 std::cout << *ptr_weights << std::endl;
89 Epetra_Vector local_weights = allocate_vector_to_single_core(*ptr_weights);
90 std::unique_ptr<dealii::TableHandler> weights_table = std::make_unique<dealii::TableHandler>();
91 for(
int i = 0 ; i < local_weights.MyLength() ; i++){
92 weights_table->add_value(
"ECSW Weights", local_weights[i]);
93 weights_table->set_precision(
"ECSW Weights", 16);
95 std::ofstream weights_table_file(
"weights_table_iteration_HROM_post_sampling.txt");
96 weights_table->write_text(weights_table_file, dealii::TableHandler::TextOutputFormat::org_mode_table);
97 weights_table_file.close();
100 std::shared_ptr<HyperreducedAdaptiveSampling<dim,nstate>> hyper_reduced_ROM_solver = std::make_unique<HyperreducedAdaptiveSampling<dim,nstate>>(
all_parameters,
parameter_handler);
101 hyper_reduced_ROM_solver->current_pod = parameter_sampling->current_pod;
102 hyper_reduced_ROM_solver->snapshot_parameters = parameter_sampling->snapshot_parameters;
103 MatrixXd rom_points(0, hyper_reduced_ROM_solver->snapshot_parameters.cols());
104 for(
auto it = parameter_sampling->rom_locations.begin(); it != parameter_sampling->rom_locations.end(); ++it){
105 rom_points.conservativeResize(rom_points.rows()+1, rom_points.cols());
106 Eigen::RowVectorXd rom = it->get()->parameter;
107 rom_points.row(rom_points.rows()-1) = rom;
109 hyper_reduced_ROM_solver->placeROMLocations(rom_points, *ptr_weights);
110 hyper_reduced_ROM_solver->outputIterationData(
"HROM_post_sampling");
113 MatrixXd rom_true_error_points(0,0);
114 getROMPoints(rom_true_error_points, all_parameters);
115 parameter_sampling->trueErrorROM(rom_true_error_points);
116 hyper_reduced_ROM_solver->trueErrorROM(rom_true_error_points, *ptr_weights);
const dealii::ParameterHandler & parameter_handler
Dummy parameter handler because flowsolver requires it.
int run_test() const override
Conduct hyperreduction and evaluate HROM at ROM points.
Files for the baseline physics.
HyperReductionPostSampling(const Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler ¶meter_handler_input)
Constructor.
Main parameter class that contains the various other sub-parameter classes.
ODESolverParam ode_solver_param
Contains parameters for ODE solver.
static std::unique_ptr< FlowSolver< dim, nstate > > select_flow_case(const Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler ¶meter_handler_input)
Factory to return the correct flow solver given input file.
const Parameters::AllParameters *const all_parameters
Pointer to all parameters.
Parameters::AllParameters reinit_params(const int max_iter) const
Reinitialize parameters.
dealii::ConditionalOStream pcout
ConditionalOStream.
bool solve()
Call to solve NNLS problem.
unsigned int nonlinear_max_iterations
Maximum number of iterations.
Base class of all the tests.