1 #include "HROM_error_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 "rom_import_helper_functions.h" 14 #include <eigen/Eigen/Dense> 17 #include <Epetra_CrsMatrix.h> 18 #include <Epetra_Map.h> 19 #include <Epetra_Vector.h> 25 template <
int dim,
int nstate>
27 const dealii::ParameterHandler ¶meter_handler_input)
29 , parameter_handler(parameter_handler_input)
32 template <
int dim,
int nstate>
41 template <
int dim,
int nstate>
43 bool file_found =
false;
44 Epetra_MpiComm epetra_comm(MPI_COMM_WORLD);
49 std::vector<std::filesystem::path> files_in_directory;
50 std::copy(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator(), std::back_inserter(files_in_directory));
51 std::sort(files_in_directory.begin(), files_in_directory.end());
53 for (
const auto & entry : files_in_directory){
54 if(std::string(entry.filename()).std::string::find(
"weights") != std::string::npos){
55 pcout <<
"Processing " << entry << std::endl;
57 std::ifstream myfile(entry);
60 pcout <<
"Error opening file." << std::endl;
65 while(std::getline(myfile, line)){
66 std::istringstream stream(line);
68 while (getline(stream, field,
' ')) {
83 weights_eig.resize(rows);
88 while(std::getline(myfile, line)){
89 std::istringstream stream(line);
91 while (getline(stream, field,
' ')) {
97 double num_string = std::stod(field);
98 weights_eig(row) = num_string;
110 Epetra_CrsMatrix epetra_system_matrix = dg->system_matrix.trilinos_matrix();
111 const int n_quad_pts = dg->volume_quadrature_collection[dg->all_parameters->flow_solver_param.poly_degree].size();
112 const int length = epetra_system_matrix.NumMyRows()/(nstate*n_quad_pts);
113 int *local_elements =
new int[length];
115 for (
const auto &cell : dg->dof_handler.active_cell_iterators())
117 if (cell->is_locally_owned()){
118 local_elements[ctr] = cell->active_cell_index();
123 Epetra_Map ColMap(rows, length, local_elements, 0, epetra_comm);
124 ColMap.Print(std::cout);
125 Epetra_Vector weights(ColMap);
126 for(
int i = 0; i < length; i++){
127 int global_ind = local_elements[i];
128 weights[i] = weights_eig(global_ind);
131 ptr_weights = std::make_shared<Epetra_Vector>(weights);
135 template <
int dim,
int nstate>
138 pcout <<
"Starting error analysis for HROM..." << std::endl;
143 std::shared_ptr<ProperOrthogonalDecomposition::OfflinePOD<dim>> pod_petrov_galerkin = std::make_shared<ProperOrthogonalDecomposition::OfflinePOD<dim>>(flow_solver_hyper_reduced_petrov_galerkin->dg);
144 std::shared_ptr<HyperreducedAdaptiveSampling<dim,nstate>> hyper_reduced_ROM_solver = std::make_unique<HyperreducedAdaptiveSampling<dim,nstate>>(
all_parameters,
parameter_handler);
145 hyper_reduced_ROM_solver->current_pod->basis = pod_petrov_galerkin->basis;
146 hyper_reduced_ROM_solver->current_pod->referenceState = pod_petrov_galerkin->referenceState;
147 hyper_reduced_ROM_solver->current_pod->snapshotMatrix = pod_petrov_galerkin->snapshotMatrix;
149 std::string path = all_parameters->reduced_order_param.path_to_search;
153 std::cout <<
"snapshot_parameters" << std::endl;
157 std::cout <<
"File with snapshots not found in folder" << std::endl;
161 std::cout <<
"ROM Locations" << std::endl;
164 bool weights_found =
getWeightsFromFile(flow_solver_hyper_reduced_petrov_galerkin->dg);
166 std::cout <<
"ECSW Weights" << std::endl;
170 std::cout <<
"File with weights not found in folder" << std::endl;
HROMErrorPostSampling(const Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler ¶meter_handler_input)
Constructor.
Files for the baseline physics.
ReducedOrderModelParam reduced_order_param
Contains parameters for the Reduced-Order model.
std::string path_to_search
Path to search for snapshots or saved POD basis.
Main parameter class that contains the various other sub-parameter classes.
const dealii::ParameterHandler & parameter_handler
Dummy parameter handler because flowsolver requires it.
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.
MatrixXd snapshot_parameters
Matrix of snapshot parameters.
MatrixXd rom_points
Matrix of error sampling points.
bool getWeightsFromFile(std::shared_ptr< DGBase< dim, double >> &dg) const
Read ECSW weights from the text file.
int run_test() const override
Evaluate and output the "true" error at ROM Points.
dealii::ConditionalOStream pcout
ConditionalOStream.
Parameters::AllParameters reinit_params(std::string path) const
Reinitialize parameters.
std::shared_ptr< Epetra_Vector > ptr_weights
Ptr vector of ECSW Weights.
DGBase is independent of the number of state variables.
Base class of all the tests.