1 #include "rom_test_location.h" 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> 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> 20 namespace ProperOrthogonalDecomposition {
22 template <
int dim,
int nstate>
28 template <
int dim,
int nstate>
31 this->
pcout <<
"Computing adjoint-based error estimate between initial ROM and updated ROM..." << std::endl;
33 dealii::ParameterHandler dummy_handler;
35 flow_solver->dg->solution = this->
rom_solution->solution;
36 const bool compute_dRdW =
true;
37 flow_solver->dg->assemble_residual(compute_dRdW);
39 const Epetra_CrsMatrix epetra_pod_basis = pod_updated->getPODBasis()->trilinos_matrix();
40 const Epetra_CrsMatrix epetra_system_matrix_transpose = flow_solver->dg->system_matrix_transpose.trilinos_matrix();
42 Epetra_CrsMatrix epetra_petrov_galerkin_basis(Epetra_DataAccess::Copy, epetra_system_matrix_transpose.DomainMap(), pod_updated->getPODBasis()->n());
43 EpetraExt::MatrixMatrix::Multiply(epetra_system_matrix_transpose,
true, epetra_pod_basis,
false, epetra_petrov_galerkin_basis,
true);
45 Epetra_Vector epetra_gradient(epetra_pod_basis.RowMap());
48 for (
unsigned int i = 0; i < this->
rom_solution->gradient.local_size(); ++i){
49 epetra_gradient.ReplaceMyValue(static_cast<int>(i), 0, this->
rom_solution->gradient.local_element(i));
52 Epetra_Vector epetra_reduced_gradient(epetra_pod_basis.DomainMap());
54 epetra_pod_basis.Multiply(
true, epetra_gradient, epetra_reduced_gradient);
56 Epetra_CrsMatrix epetra_reduced_jacobian_transpose(Epetra_DataAccess::Copy, epetra_petrov_galerkin_basis.DomainMap(), pod_updated->getPODBasis()->n());
57 EpetraExt::MatrixMatrix::Multiply(epetra_petrov_galerkin_basis,
true, epetra_petrov_galerkin_basis,
false, epetra_reduced_jacobian_transpose);
59 Epetra_Vector epetra_reduced_adjoint(epetra_reduced_jacobian_transpose.DomainMap());
60 epetra_reduced_gradient.Scale(-1);
61 if (this->
rom_solution->params.reduced_order_param.residual_error_bool ==
true){
62 epetra_reduced_adjoint.PutScalar(0);
65 Epetra_LinearProblem linearProblem(&epetra_reduced_jacobian_transpose, &epetra_reduced_adjoint, &epetra_reduced_gradient);
67 Amesos_Lapack Solver(linearProblem);
69 Teuchos::ParameterList List;
70 Solver.SetParameters(List);
71 Solver.SymbolicFactorization();
72 Solver.NumericFactorization();
76 Epetra_Vector epetra_reduced_residual(epetra_petrov_galerkin_basis.DomainMap());
77 Epetra_Vector epetra_residual(Epetra_DataAccess::Copy, epetra_petrov_galerkin_basis.RangeMap(),
const_cast<double *
>(flow_solver->dg->right_hand_side.begin()));
78 epetra_petrov_galerkin_basis.Multiply(
true, epetra_residual, epetra_reduced_residual);
ROMTestLocation(const RowVectorXd ¶meter, std::unique_ptr< ROMSolution< dim, nstate >> rom_solution)
Constructor.
Base class for a ROM/HROM point, differences would be in the second DWR error indicator.
Files for the baseline physics.
RowVectorXd parameter
Parameter.
Class to compute and store adjoint-based error estimates.
dealii::ConditionalOStream pcout
ConditionalOStream.
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.
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_initial_rom_to_final_rom_error(std::shared_ptr< ProperOrthogonalDecomposition::PODBase< dim >> pod_updated) override
Compute error between initial ROM and final ROM.