[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
test_location_base.cpp
1 #include "test_location_base.h"
2 #include <iostream>
3 #include <filesystem>
4 #include <deal.II/base/conditional_ostream.h>
5 #include <deal.II/lac/trilinos_sparse_matrix.h>
6 #include "parameters/all_parameters.h"
7 #include "pod_basis_base.h"
8 #include "reduced_order_solution.h"
9 #include "linear_solver/linear_solver.h"
10 #include <Epetra_Vector.h>
11 #include <EpetraExt_MatrixMatrix.h>
12 #include <Epetra_LinearProblem.h>
13 #include "Amesos.h"
14 #include <Amesos_Lapack.h>
15 #include "flow_solver/flow_solver.h"
16 #include "flow_solver/flow_solver_factory.h"
17 #include <deal.II/base/parameter_handler.h>
18 
19 namespace PHiLiP {
20 namespace ProperOrthogonalDecomposition {
21 
22 template <int dim, int nstate>
23 TestLocationBase<dim, nstate>::TestLocationBase(const RowVectorXd& parameter, std::unique_ptr<ROMSolution<dim, nstate>> rom_solution)
24  : parameter(parameter)
25  , rom_solution(std::move(rom_solution))
26  , mpi_communicator(MPI_COMM_WORLD)
27  , mpi_rank(dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD))
28  , pcout(std::cout, mpi_rank==0)
29 {
30  pcout << "Creating ROM test location..." << std::endl;
34 
35  pcout << "ROM test location created. Error estimate updated." << std::endl;
36 }
37 
38 template <int dim, int nstate>
40  pcout << "Computing adjoint-based error estimate between ROM and FOM..." << std::endl;
41 
42  dealii::ParameterHandler dummy_handler;
43  std::unique_ptr<FlowSolver::FlowSolver<dim,nstate>> flow_solver = FlowSolver::FlowSolverFactory<dim,nstate>::select_flow_case(&rom_solution->params, dummy_handler);
44  flow_solver->dg->solution = rom_solution->solution;
45  const bool compute_dRdW = true;
46  flow_solver->dg->assemble_residual(compute_dRdW);
47  dealii::TrilinosWrappers::SparseMatrix system_matrix_transpose = dealii::TrilinosWrappers::SparseMatrix();
48  system_matrix_transpose.copy_from(flow_solver->dg->system_matrix_transpose);
49 
50  // Initialize with same parallel layout as dg->right_hand_side
51  dealii::LinearAlgebra::distributed::Vector<double> adjoint(flow_solver->dg->right_hand_side);
52 
53  dealii::LinearAlgebra::distributed::Vector<double> gradient(rom_solution->gradient);
54 
55  Parameters::LinearSolverParam linear_solver_param;
56 
57  if (rom_solution->params.reduced_order_param.FOM_error_linear_solver_type == Parameters::ReducedOrderModelParam::LinearSolverEnum::gmres){
58  linear_solver_param.max_iterations = 1000;
59  linear_solver_param.restart_number = 200;
60  linear_solver_param.linear_residual = 1e-17;
61  linear_solver_param.ilut_fill = 50;
62  linear_solver_param.ilut_drop = 1e-8;
63  linear_solver_param.ilut_atol = 1e-5;
64  linear_solver_param.ilut_rtol = 1.0+1e-2;
65  linear_solver_param.linear_solver_type = Parameters::LinearSolverParam::LinearSolverEnum::gmres;
66  }
67  else{
68  linear_solver_param.linear_solver_type = Parameters::LinearSolverParam::direct;
69  }
70  if (rom_solution->params.reduced_order_param.residual_error_bool == true){
71  adjoint*=0;
72  adjoint.add(1);
73  }
74  else{
75  solve_linear(system_matrix_transpose, gradient*=-1.0, adjoint, linear_solver_param);
76  }
77 
78  //Compute dual weighted residual
80  fom_to_initial_rom_error = -(adjoint * flow_solver->dg->right_hand_side);
81 
82  pcout << "Parameter: " << parameter << ". Error estimate between ROM and FOM: " << fom_to_initial_rom_error << std::endl;
83 }
84 
85 template <int dim, int nstate>
87  pcout << "Computing total error estimate between FOM and updated ROM..." << std::endl;
89  pcout << "Parameter: " << parameter << ". Total error estimate between FOM and updated ROM: " << total_error << std::endl;
90 }
91 
92 #if PHILIP_DIM==1
94 #endif
95 
96 #if PHILIP_DIM!=1
98 #endif
99 
100 }
101 }
double ilut_drop
Threshold to drop terms close to zero.
Parameters related to the linear solver.
double fom_to_initial_rom_error
Error between FOM and initial ROM.
Base class for a ROM/HROM point, differences would be in the second DWR error indicator.
std::pair< unsigned int, double > solve_linear(const dealii::TrilinosWrappers::SparseMatrix &system_matrix, dealii::LinearAlgebra::distributed::Vector< double > &right_hand_side, dealii::LinearAlgebra::distributed::Vector< double > &solution, const Parameters::LinearSolverParam &param)
double ilut_atol
Add ilu_rtol to diagonal for more diagonal dominance.
Files for the baseline physics.
Definition: ADTypes.hpp:10
int restart_number
Number of iterations before restarting GMRES.
TestLocationBase(const RowVectorXd &parameter, std::unique_ptr< ROMSolution< dim, nstate >> rom_solution)
Constructor.
double linear_residual
Tolerance for linear residual.
void compute_FOM_to_initial_ROM_error()
Compute adjoint error estimate between FOM and initial ROM.
dealii::ConditionalOStream pcout
ConditionalOStream.
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.
LinearSolverEnum linear_solver_type
direct or gmres.
double ilut_rtol
Multiplies diagonal by ilut_rtol for more diagonal dominance.
int max_iterations
Maximum number of linear iteration.
double initial_rom_to_final_rom_error
Error from initial ROM to final ROM.
std::unique_ptr< ROMSolution< dim, nstate > > rom_solution
ROM solution.
Class to hold information about the reduced-order solution.
void compute_total_error()
Compute total error between final ROM and FOM.