[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
hyper_reduced_adaptive_sampling.cpp
1 #include "hyper_reduced_adaptive_sampling.h"
2 #include <iostream>
3 #include <filesystem>
4 #include "functional/functional.h"
5 #include <deal.II/lac/trilinos_sparse_matrix.h>
6 #include <deal.II/lac/vector_operation.h>
7 #include "reduced_order/reduced_order_solution.h"
8 #include "flow_solver/flow_solver.h"
9 #include "flow_solver/flow_solver_factory.h"
10 #include <cmath>
11 #include "reduced_order/rbf_interpolation.h"
12 #include "ROL_Algorithm.hpp"
13 #include "ROL_LineSearchStep.hpp"
14 #include "ROL_StatusTest.hpp"
15 #include "ROL_Stream.hpp"
16 #include "ROL_Bounds.hpp"
17 #include "reduced_order/halton.h"
18 #include "reduced_order/min_max_scaler.h"
19 #include "pod_adaptive_sampling.h"
20 #include "assemble_ECSW_residual.h"
21 #include "assemble_ECSW_jacobian.h"
22 #include "linear_solver/NNLS_solver.h"
23 #include "linear_solver/helper_functions.h"
24 
25 namespace PHiLiP {
26 
27 template<int dim, int nstate>
29  const dealii::ParameterHandler &parameter_handler_input)
30  : AdaptiveSamplingBase<dim, nstate>(parameters_input, parameter_handler_input)
31 { }
32 
33 template <int dim, int nstate>
35 {
36  this->pcout << "Starting adaptive sampling process" << std::endl;
37  auto stream = this->pcout;
38  dealii::TimerOutput timer(stream,dealii::TimerOutput::summary,dealii::TimerOutput::wall_times);
39  int iteration = 0;
40  timer.enter_subsection ("Iteration " + std::to_string(iteration));
41 
42  std::unique_ptr<FlowSolver::FlowSolver<dim,nstate>> flow_solver = FlowSolver::FlowSolverFactory<dim,nstate>::select_flow_case(this->all_parameters, this->parameter_handler);
43 
44  this->placeInitialSnapshots();
45  this->current_pod->computeBasis();
46 
47  auto ode_solver_type_HROM = Parameters::ODESolverParam::ODESolverEnum::hyper_reduced_petrov_galerkin_solver;
48 
49  // Find C and d for NNLS Problem
50  Epetra_MpiComm Comm( MPI_COMM_WORLD );
51  this->pcout << "Construct instance of Assembler..."<< std::endl;
52  std::unique_ptr<HyperReduction::AssembleECSWBase<dim,nstate>> constructor_NNLS_problem;
53  if (this->all_parameters->hyper_reduction_param.training_data == "residual")
54  constructor_NNLS_problem = std::make_unique<HyperReduction::AssembleECSWRes<dim,nstate>>(this->all_parameters, this->parameter_handler, flow_solver->dg, this->current_pod, this->snapshot_parameters, ode_solver_type_HROM, Comm);
55  else {
56  constructor_NNLS_problem = std::make_unique<HyperReduction::AssembleECSWJac<dim,nstate>>(this->all_parameters, this->parameter_handler, flow_solver->dg, this->current_pod, this->snapshot_parameters, ode_solver_type_HROM, Comm);
57  }
58 
59  for (int k = 0; k < this->snapshot_parameters.rows(); k++){
60  constructor_NNLS_problem->update_snapshots(std::move(this->fom_locations[k]));
61  }
62 
63  this->pcout << "Build Problem..."<< std::endl;
64  constructor_NNLS_problem->build_problem();
65 
66  // Transfer b vector (RHS of NNLS problem) to Epetra structure
67  const int rank = Comm.MyPID();
68  int rows = (constructor_NNLS_problem->A_T->trilinos_matrix()).NumGlobalCols();
69  Epetra_Map bMap(rows, (rank == 0) ? rows: 0, 0, Comm);
70  Epetra_Vector b_Epetra(bMap);
71  auto b = constructor_NNLS_problem->b;
72  unsigned int local_length = bMap.NumMyElements();
73  for(unsigned int i = 0 ; i < local_length ; i++){
74  b_Epetra[i] = b(i);
75  }
76 
77  // Solve NNLS Problem for ECSW weights
78  this->pcout << "Create NNLS problem..."<< std::endl;
79  NNLSSolver NNLS_prob(this->all_parameters, this->parameter_handler, constructor_NNLS_problem->A_T->trilinos_matrix(), true, Comm, b_Epetra);
80  this->pcout << "Solve NNLS problem..."<< std::endl;
81  bool exit_con = NNLS_prob.solve();
82  this->pcout << exit_con << std::endl;
83 
84  ptr_weights = std::make_shared<Epetra_Vector>(NNLS_prob.get_solution());
85 
86  MatrixXd rom_points = this->nearest_neighbors->kPairwiseNearestNeighborsMidpoint();
87  this->pcout << "ROM Points"<< std::endl;
88  this->pcout << rom_points << std::endl;
89 
90  this->placeROMLocations(rom_points, *ptr_weights);
91 
92  RowVectorXd max_error_params = this->getMaxErrorROM();
93 
94  RowVectorXd functional_ROM = this->readROMFunctionalPoint();
95 
96  this->pcout << "Solving FOM at " << functional_ROM << std::endl;
97 
98  Parameters::AllParameters params = this->reinit_params(functional_ROM);
99  std::unique_ptr<FlowSolver::FlowSolver<dim,nstate>> flow_solver_FOM = FlowSolver::FlowSolverFactory<dim,nstate>::select_flow_case(&params, this->parameter_handler);
100 
101  // Solve implicit solution
102  auto ode_solver_type = Parameters::ODESolverParam::ODESolverEnum::implicit_solver;
103  flow_solver_FOM->ode_solver = PHiLiP::ODE::ODESolverFactory<dim, double>::create_ODESolver_manual(ode_solver_type, flow_solver_FOM->dg);
104  flow_solver_FOM->ode_solver->allocate_ode_system();
105  flow_solver_FOM->run();
106 
107  // Create functional
108  std::shared_ptr<Functional<dim,nstate,double>> functional_FOM = FunctionalFactory<dim,nstate,double>::create_Functional(params.functional_param, flow_solver_FOM->dg);
109  this->pcout << "FUNCTIONAL FROM FOM" << std::endl;
110  this->pcout << functional_FOM->evaluate_functional(false, false) << std::endl;
111 
112  solveFunctionalHROM(functional_ROM, *ptr_weights);
113 
114  while(this->max_error > this->all_parameters->reduced_order_param.adaptation_tolerance){
115  Epetra_Vector local_weights = allocateVectorToSingleCore(*ptr_weights);
116  this->outputIterationData(std::to_string(iteration));
117  std::unique_ptr<dealii::TableHandler> weights_table = std::make_unique<dealii::TableHandler>();
118  for(int i = 0 ; i < local_weights.MyLength() ; i++){
119  weights_table->add_value("ECSW Weights", local_weights[i]);
120  weights_table->set_precision("ECSW Weights", 16);
121  }
122 
123  std::ofstream weights_table_file("weights_table_iteration_" + std::to_string(iteration) + ".txt");
124  weights_table->write_text(weights_table_file, dealii::TableHandler::TextOutputFormat::org_mode_table);
125  weights_table_file.close();
126 
127  dealii::Vector<double> weights_dealii(local_weights.MyLength());
128  for(int j = 0 ; j < local_weights.MyLength() ; j++){
129  weights_dealii[j] = local_weights[j];
130  }
131  flow_solver->dg->reduced_mesh_weights = weights_dealii;
132  flow_solver->dg->output_results_vtk(iteration);
133 
134  timer.leave_subsection();
135  timer.enter_subsection ("Iteration " + std::to_string(iteration+1));
136 
137  this->pcout << "Sampling snapshot at " << max_error_params << std::endl;
138  dealii::LinearAlgebra::distributed::Vector<double> fom_solution = this->solveSnapshotFOM(max_error_params);
139  this->snapshot_parameters.conservativeResize(this->snapshot_parameters.rows()+1, this->snapshot_parameters.cols());
140  this->snapshot_parameters.row(this->snapshot_parameters.rows()-1) = max_error_params;
141  this->nearest_neighbors->update_snapshots(this->snapshot_parameters, fom_solution);
142  this->current_pod->addSnapshot(fom_solution);
143  this->fom_locations.emplace_back(fom_solution);
144  this->current_pod->computeBasis();
145 
146  // Find C and d for NNLS Problem
147  this->pcout << "Update Assembler..."<< std::endl;
148  constructor_NNLS_problem->update_POD_snaps(this->current_pod, this->snapshot_parameters);
149  constructor_NNLS_problem->update_snapshots(fom_solution);
150  this->pcout << "Build Problem..."<< std::endl;
151  constructor_NNLS_problem->build_problem();
152 
153  // Transfer b vector (RHS of NNLS problem) to Epetra structure
154  int rows = (constructor_NNLS_problem->A_T->trilinos_matrix()).NumGlobalCols();
155  Epetra_Map bMap(rows, (rank == 0) ? rows: 0, 0, Comm);
156  Epetra_Vector b_Epetra(bMap);
157  auto b = constructor_NNLS_problem->b;
158  unsigned int local_length = bMap.NumMyElements();
159  for(unsigned int i = 0 ; i < local_length ; i++){
160  b_Epetra[i] = b(i);
161  }
162 
163  // Solve NNLS Problem for ECSW weights
164  this->pcout << "Create NNLS problem..."<< std::endl;
165  NNLSSolver NNLS_prob (this->all_parameters, this->parameter_handler, constructor_NNLS_problem->A_T->trilinos_matrix(), true, Comm, b_Epetra);
166  this->pcout << "Solve NNLS problem..."<< std::endl;
167  bool exit_con = NNLS_prob.solve();
168  this->pcout << exit_con << std::endl;
169 
170  ptr_weights = std::make_shared<Epetra_Vector>(NNLS_prob.get_solution());
171 
172  // Update previous ROM errors with updated current_pod
173  for(auto it = this->rom_locations.begin(); it != this->rom_locations.end(); ++it){
174  it->get()->compute_initial_rom_to_final_rom_error(this->current_pod);
175  it->get()->compute_total_error();
176  }
177 
178  this->updateNearestExistingROMs(max_error_params, *ptr_weights);
179 
180  rom_points = this->nearest_neighbors->kNearestNeighborsMidpoint(max_error_params);
181  this->pcout << rom_points << std::endl;
182 
183  this->placeROMLocations(rom_points, *ptr_weights);
184 
185  // Update max error
186  max_error_params = this->getMaxErrorROM();
187 
188  this->pcout << "Max error is: " << this->max_error << std::endl;
189 
190  solveFunctionalHROM(functional_ROM, *ptr_weights);
191 
192  this->pcout << "FUNCTIONAL FROM ROMs" << std::endl;
193  std::ofstream output_file("rom_functional" + std::to_string(iteration+1) +".txt");
194 
195  std::ostream_iterator<double> output_iterator(output_file, "\n");
196  std::copy(std::begin(rom_functional), std::end(rom_functional), output_iterator);
197 
198  iteration++;
199 
200  // Exit statement for loop if the total number of iterations is greater than the FOM dimension N (i.e. the reduced-order basis dimension n is equal to N)
201  if (iteration > local_weights.MyLength()){
202  break;
203  }
204  }
205 
206  Epetra_Vector local_weights = allocateVectorToSingleCore(*ptr_weights);
207  this->outputIterationData("final");
208  std::unique_ptr<dealii::TableHandler> weights_table = std::make_unique<dealii::TableHandler>();
209  for(int i = 0 ; i < local_weights.MyLength() ; i++){
210  weights_table->add_value("ECSW Weights", local_weights[i]);
211  weights_table->set_precision("ECSW Weights", 16);
212  }
213 
214  dealii::Vector<double> weights_dealii(local_weights.MyLength());
215  for(int j = 0 ; j < local_weights.MyLength() ; j++){
216  weights_dealii[j] = local_weights[j];
217  }
218  std::ofstream weights_table_file("weights_table_iteration_final.txt");
219  weights_table->write_text(weights_table_file, dealii::TableHandler::TextOutputFormat::org_mode_table);
220  weights_table_file.close();
221 
222  flow_solver->dg->reduced_mesh_weights = weights_dealii;
223  flow_solver->dg->output_results_vtk(iteration);
224 
225  timer.leave_subsection();
226 
227  this->pcout << "FUNCTIONAL FROM ROMs" << std::endl;
228  std::ofstream output_file("rom_functional.txt");
229 
230  std::ostream_iterator<double> output_iterator(output_file, "\n");
231  std::copy(std::begin(rom_functional), std::end(rom_functional), output_iterator);
232 
233  return 0;
234 }
235 
236 template <int dim, int nstate>
237 bool HyperreducedAdaptiveSampling<dim, nstate>::placeROMLocations(const MatrixXd& rom_points, Epetra_Vector weights) const{
238  bool error_greater_than_tolerance = false;
239  for(auto midpoint : rom_points.rowwise()){
240 
241  // Check if ROM point already exists as another ROM point
242  auto element = std::find_if(this->rom_locations.begin(), this->rom_locations.end(), [&midpoint](std::unique_ptr<ProperOrthogonalDecomposition::ROMTestLocation<dim,nstate>>& location){ return location->parameter.isApprox(midpoint);} );
243 
244  // Check if ROM point already exists as a snapshot
245  bool snapshot_exists = false;
246  for(auto snap_param : this->snapshot_parameters.rowwise()){
247  if(snap_param.isApprox(midpoint)){
248  snapshot_exists = true;
249  }
250  }
251 
252  if(element == this->rom_locations.end() && snapshot_exists == false){
253  std::unique_ptr<ProperOrthogonalDecomposition::ROMSolution<dim, nstate>> rom_solution = solveSnapshotROM(midpoint, weights);
254  this->rom_locations.emplace_back(std::make_unique<ProperOrthogonalDecomposition::ROMTestLocation<dim,nstate>>(midpoint, std::move(rom_solution)));
255  if(abs(this->rom_locations.back()->total_error) > this->all_parameters->reduced_order_param.adaptation_tolerance){
256  error_greater_than_tolerance = true;
257  }
258  }
259  else{
260  this->pcout << "ROM already computed." << std::endl;
261  }
262  }
263  return error_greater_than_tolerance;
264 }
265 
266 template <int dim, int nstate>
267 void HyperreducedAdaptiveSampling<dim, nstate>::trueErrorROM(const MatrixXd& rom_points, Epetra_Vector weights) const{
268 
269  std::unique_ptr<dealii::TableHandler> rom_table = std::make_unique<dealii::TableHandler>();
270 
271  for(auto rom : rom_points.rowwise()){
272  for(int i = 0 ; i < rom_points.cols() ; i++){
273  rom_table->add_value(this->all_parameters->reduced_order_param.parameter_names[i], rom(i));
274  rom_table->set_precision(this->all_parameters->reduced_order_param.parameter_names[i], 16);
275  }
276  double error = solveSnapshotROMandFOM(rom, weights);
277  this->pcout << "Error in the functional: " << error << std::endl;
278  rom_table->add_value("ROM_errors", error);
279  rom_table->set_precision("ROM_errors", 16);
280  }
281 
282  std::ofstream rom_table_file("true_error_table_iteration_HROM_post_sampling.txt");
283  rom_table->write_text(rom_table_file, dealii::TableHandler::TextOutputFormat::org_mode_table);
284  rom_table_file.close();
285 }
286 
287 template <int dim, int nstate>
288 double HyperreducedAdaptiveSampling<dim, nstate>::solveSnapshotROMandFOM(const RowVectorXd& parameter, Epetra_Vector weights) const{
289  this->pcout << "Solving HROM at " << parameter << std::endl;
290  Parameters::AllParameters params = this->reinit_params(parameter);
291 
292  std::unique_ptr<FlowSolver::FlowSolver<dim,nstate>> flow_solver_ROM = FlowSolver::FlowSolverFactory<dim,nstate>::select_flow_case(&params, this->parameter_handler);
293 
294  // Solve implicit solution
295  auto ode_solver_type_ROM = Parameters::ODESolverParam::ODESolverEnum::hyper_reduced_petrov_galerkin_solver;
296  flow_solver_ROM->ode_solver = PHiLiP::ODE::ODESolverFactory<dim, double>::create_ODESolver_manual(ode_solver_type_ROM, flow_solver_ROM->dg, this->current_pod, weights);
297  flow_solver_ROM->ode_solver->allocate_ode_system();
298  flow_solver_ROM->ode_solver->steady_state();
299 
300  this->pcout << "Done solving HROM." << std::endl;
301 
302  // Create functional
303  std::shared_ptr<Functional<dim,nstate,double>> functional_ROM = FunctionalFactory<dim,nstate,double>::create_Functional(params.functional_param, flow_solver_ROM->dg);
304 
305  this->pcout << "Solving FOM at " << parameter << std::endl;
306 
307  std::unique_ptr<FlowSolver::FlowSolver<dim,nstate>> flow_solver_FOM = FlowSolver::FlowSolverFactory<dim,nstate>::select_flow_case(&params, this->parameter_handler);
308 
309  // Solve implicit solution
310  auto ode_solver_type = Parameters::ODESolverParam::ODESolverEnum::implicit_solver;
311  flow_solver_FOM->ode_solver = PHiLiP::ODE::ODESolverFactory<dim, double>::create_ODESolver_manual(ode_solver_type, flow_solver_FOM->dg);
312  flow_solver_FOM->ode_solver->allocate_ode_system();
313  flow_solver_FOM->run();
314 
315  // Create functional
316  std::shared_ptr<Functional<dim,nstate,double>> functional_FOM = FunctionalFactory<dim,nstate,double>::create_Functional(params.functional_param, flow_solver_FOM->dg);
317 
318  this->pcout << "Done solving FOM." << std::endl;
319  return functional_ROM->evaluate_functional(false, false) - functional_FOM->evaluate_functional(false, false);
320 }
321 
322 template <int dim, int nstate>
323 void HyperreducedAdaptiveSampling<dim, nstate>::solveFunctionalHROM(const RowVectorXd& parameter, Epetra_Vector weights) const{
324  this->pcout << "Solving HROM at " << parameter << std::endl;
325  Parameters::AllParameters params = this->reinit_params(parameter);
326 
327  std::unique_ptr<FlowSolver::FlowSolver<dim,nstate>> flow_solver_ROM = FlowSolver::FlowSolverFactory<dim,nstate>::select_flow_case(&params, this->parameter_handler);
328 
329  // Solve
330  auto ode_solver_type_ROM = Parameters::ODESolverParam::ODESolverEnum::hyper_reduced_petrov_galerkin_solver;
331  flow_solver_ROM->ode_solver = PHiLiP::ODE::ODESolverFactory<dim, double>::create_ODESolver_manual(ode_solver_type_ROM, flow_solver_ROM->dg, this->current_pod, weights);
332  flow_solver_ROM->ode_solver->allocate_ode_system();
333  flow_solver_ROM->ode_solver->steady_state();
334 
335  this->pcout << "Done solving HROM." << std::endl;
336 
337  // Create functional
338  std::shared_ptr<Functional<dim,nstate,double>> functional_ROM = FunctionalFactory<dim,nstate,double>::create_Functional(params.functional_param, flow_solver_ROM->dg);
339 
340  rom_functional.emplace_back(functional_ROM->evaluate_functional(false, false));
341 }
342 
343 template <int dim, int nstate>
344 void HyperreducedAdaptiveSampling<dim, nstate>::updateNearestExistingROMs(const RowVectorXd& /*parameter*/, Epetra_Vector weights) const{
345 
346  this->pcout << "Verifying ROM points for recomputation." << std::endl;
347  // Assemble ROM points in a matrix
348  MatrixXd rom_points(0,0);
349  for(auto it = this->rom_locations.begin(); it != this->rom_locations.end(); ++it){
350  rom_points.conservativeResize(rom_points.rows()+1, it->get()->parameter.cols());
351  rom_points.row(rom_points.rows()-1) = it->get()->parameter;
352  }
353 
354  // Get distances between each ROM point and all other ROM points
355  for(auto point : rom_points.rowwise()) {
357  MatrixXd scaled_rom_points = scaler.fit_transform(rom_points);
358  RowVectorXd scaled_point = scaler.transform(point);
359 
360  VectorXd distances = (scaled_rom_points.rowwise() - scaled_point).rowwise().squaredNorm();
361 
362  std::vector<int> index(distances.size());
363  std::iota(index.begin(), index.end(), 0);
364 
365  std::sort(index.begin(), index.end(),
366  [&](const int &a, const int &b) {
367  return distances[a] < distances[b];
368  });
369 
370  this->pcout << "Searching ROM points near: " << point << std::endl;
371  double local_mean_error = 0;
372  for (int i = 1; i < rom_points.cols() + 2; i++) {
373  local_mean_error = local_mean_error + std::abs(this->rom_locations[index[i]]->total_error);
374  }
375  local_mean_error = local_mean_error / (rom_points.cols() + 1);
376  if ((std::abs(this->rom_locations[index[0]]->total_error) > this->all_parameters->reduced_order_param.recomputation_coefficient * local_mean_error) || (std::abs(this->rom_locations[index[0]]->total_error) < (1/this->all_parameters->reduced_order_param.recomputation_coefficient) * local_mean_error)) {
377  this->pcout << "Total error greater than tolerance. Recomputing ROM solution" << std::endl;
378  std::unique_ptr<ProperOrthogonalDecomposition::ROMSolution<dim, nstate>> rom_solution = solveSnapshotROM(this->rom_locations[index[0]]->parameter, weights);
379  std::unique_ptr<ProperOrthogonalDecomposition::ROMTestLocation<dim, nstate>> rom_location = std::make_unique<ProperOrthogonalDecomposition::ROMTestLocation<dim, nstate>>(this->rom_locations[index[0]]->parameter, std::move(rom_solution));
380  this->rom_locations[index[0]] = std::move(rom_location);
381  }
382  }
383 }
384 
385 template <int dim, int nstate>
386 std::unique_ptr<ProperOrthogonalDecomposition::ROMSolution<dim,nstate>> HyperreducedAdaptiveSampling<dim, nstate>::solveSnapshotROM(const RowVectorXd& parameter, Epetra_Vector weights) const{
387  this->pcout << "Solving ROM at " << parameter << std::endl;
388  Parameters::AllParameters params = this->reinit_params(parameter);
389 
390  std::unique_ptr<FlowSolver::FlowSolver<dim,nstate>> flow_solver = FlowSolver::FlowSolverFactory<dim,nstate>::select_flow_case(&params, this->parameter_handler);
391 
392  // Solve implicit solution
393  auto ode_solver_type_HROM = Parameters::ODESolverParam::ODESolverEnum::hyper_reduced_petrov_galerkin_solver;
394  flow_solver->ode_solver = PHiLiP::ODE::ODESolverFactory<dim, double>::create_ODESolver_manual(ode_solver_type_HROM, flow_solver->dg, this->current_pod, weights);
395  flow_solver->ode_solver->allocate_ode_system();
396  flow_solver->ode_solver->steady_state();
397 
398  // Create functional
399  std::shared_ptr<Functional<dim,nstate,double>> functional = FunctionalFactory<dim,nstate,double>::create_Functional(params.functional_param, flow_solver->dg);
400  functional->evaluate_functional( true, false, false);
401 
402  dealii::LinearAlgebra::distributed::Vector<double> solution(flow_solver->dg->solution);
403  dealii::LinearAlgebra::distributed::Vector<double> gradient(functional->dIdw);
404 
405  std::unique_ptr<ProperOrthogonalDecomposition::ROMSolution<dim,nstate>> rom_solution = std::make_unique<ProperOrthogonalDecomposition::ROMSolution<dim, nstate>>(params, solution, gradient);
406  this->pcout << "Done solving ROM." << std::endl;
407 
408  return rom_solution;
409 }
410 
411 template <int dim, int nstate>
413  // Gather Vector Information
414  const Epetra_SerialComm sComm;
415  const int b_size = b.GlobalLength();
416  // Create new map for one core and gather old map
417  Epetra_Map single_core_b (b_size, b_size, 0, sComm);
418  Epetra_BlockMap old_map_b = b.Map();
419  // Create Epetra_importer object
420  Epetra_Import b_importer(single_core_b, old_map_b);
421  // Create new b vector
422  Epetra_Vector b_temp (single_core_b);
423  // Load the data from vector b (Multi core) into b_temp (Single core)
424  b_temp.Import(b, b_importer, Epetra_CombineMode::Insert);
425  return b_temp;
426 }
427 
428 #if PHILIP_DIM==1
430 #endif
431 
432 #if PHILIP_DIM!=1
434 #endif
435 
436 }
static std::shared_ptr< ODESolverBase< dim, real, MeshType > > create_ODESolver_manual(Parameters::ODESolverParam::ODESolverEnum ode_solver_type, std::shared_ptr< DGBase< dim, real, MeshType > > dg_input)
Creates either implicit or explicit ODE solver based on manual input (no POD basis given) ...
const dealii::ParameterHandler & parameter_handler
Parameter handler for storing the .prm file being ran.
std::vector< std::string > parameter_names
Names of parameters.
void solveFunctionalHROM(const RowVectorXd &parameter, Epetra_Vector weights) const
Solve ROM and track functional.
dealii::ConditionalOStream pcout
ConditionalOStream.
RowVectorXd readROMFunctionalPoint() const
Find point to solve for functional from param file.
std::shared_ptr< ProperOrthogonalDecomposition::NearestNeighbors > nearest_neighbors
Nearest neighbors of snapshots.
std::vector< double > rom_functional
Functional value predicted by the rom at each sammpling iteration at parameter location specified in ...
dealii::LinearAlgebra::distributed::Vector< double > solveSnapshotFOM(const RowVectorXd &parameter) const
Solve full-order snapshot.
Files for the baseline physics.
Definition: ADTypes.hpp:10
double solveSnapshotROMandFOM(const RowVectorXd &parameter, Epetra_Vector weights) const
Solve FOM and ROM, return error in functional between the models.
ReducedOrderModelParam reduced_order_param
Contains parameters for the Reduced-Order model.
Main parameter class that contains the various other sub-parameter classes.
Class to compute and store adjoint-based error estimates.
MatrixXd fit_transform(const MatrixXd &snapshot_parameters)
Fit and transform data.
static std::unique_ptr< FlowSolver< dim, nstate > > select_flow_case(const Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler &parameter_handler_input)
Factory to return the correct flow solver given input file.
int recomputation_coefficient
Recomputation parameter for adaptive sampling algorithm.
Parameters::AllParameters reinit_params(const RowVectorXd &parameter) const
Reinitialize parameters.
HyperreducedAdaptiveSampling(const PHiLiP::Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler &parameter_handler_input)
Constructor.
std::shared_ptr< ProperOrthogonalDecomposition::OnlinePOD< dim > > current_pod
Most up to date POD basis.
bool placeROMLocations(const MatrixXd &rom_points, Epetra_Vector weights) const
Placement of ROMs.
virtual void outputIterationData(std::string iteration) const
Output for each iteration.
void placeInitialSnapshots() const
Placement of initial snapshots.
std::unique_ptr< ProperOrthogonalDecomposition::ROMSolution< dim, nstate > > solveSnapshotROM(const RowVectorXd &parameter, Epetra_Vector weights) const
Solve reduced-order solution.
std::string training_data
Training data (Residual-based vs Jacobian-based)
static std::shared_ptr< Functional< dim, nstate, real, MeshType > > create_Functional(PHiLiP::Parameters::AllParameters const *const param, std::shared_ptr< PHiLiP::DGBase< dim, real, MeshType > > dg)
Create standard functional object from constant parameter file.
MatrixXd transform(const MatrixXd &snapshot_parameters)
Transform data to previously fitted dataset.
std::vector< dealii::LinearAlgebra::distributed::Vector< double > > fom_locations
Vector of parameter-ROMTestLocation pairs.
Epetra_Vector allocateVectorToSingleCore(const Epetra_Vector &b) const
Copy all elements in matrix A to all cores.
FunctionalParam functional_param
Contains parameters for functional.
MatrixXd snapshot_parameters
Matrix of snapshot parameters.
std::shared_ptr< Epetra_Vector > ptr_weights
Ptr vector of ECSW Weights.
double adaptation_tolerance
Tolerance for POD adaptation.
HyperReductionParam hyper_reduction_param
Contains parameters for Hyperreduction.
const Parameters::AllParameters *const all_parameters
Pointer to all parameters.
void trueErrorROM(const MatrixXd &rom_points, Epetra_Vector weights) const
Compute true/actual error at all ROM points (error in functional between FOM and ROM solution) ...
void updateNearestExistingROMs(const RowVectorXd &parameter, Epetra_Vector weights) const
Updates nearest ROM points to snapshot if error discrepancy is above tolerance.
std::vector< std::unique_ptr< ProperOrthogonalDecomposition::ROMTestLocation< dim, nstate > > > rom_locations
Vector of parameter-ROMTestLocation pairs.
virtual RowVectorXd getMaxErrorROM() const
Compute RBF and find max error.