[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
flow_constraints.hpp
1 #ifndef __FLOWCONSTRAINTS_H__
2 #define __FLOWCONSTRAINTS_H__
3 
4 #include <deal.II/optimization/rol/vector_adaptor.h>
5 
6 #include "Ifpack.h"
7 #include "ROL_Constraint_SimOpt.hpp"
8 #include "design_parameterization/base_parameterization.hpp"
9 #include "dg/dg_base.hpp"
10 #include "linear_solver/linear_solver.h"
11 #include "parameters/all_parameters.h"
12 
13 namespace PHiLiP {
14 
15 using dealii_Vector = dealii::LinearAlgebra::distributed::Vector<double>;
16 using AdaptVector = dealii::Rol::VectorAdaptor<dealii_Vector>;
17 
19 
25 template<int dim>
26 class FlowConstraints : public ROL::Constraint_SimOpt<double> {
27 private:
29  const int mpi_rank;
31  const bool i_print;
33  std::shared_ptr<DGBase<dim,double>> dg;
34 
36  std::shared_ptr<BaseParameterization<dim>> design_parameterization;
37 
39 
42 
44  dealii::LinearAlgebra::distributed::Vector<double> design_var;
45 
47 
48  Ifpack_Preconditioner *jacobian_prec;
50 
51  Ifpack_Preconditioner *adjoint_jacobian_prec;
52 
53 protected:
55  int i_out = 1000;
57  int iupdate = 9000;
58 
59 public:
61  dealii::TrilinosWrappers::SparseMatrix dXvdXp;
62 
64  using ROL::Constraint_SimOpt<double>::value;
65 
67  double flow_CFL_;
69  using ROL::Constraint_SimOpt<double>::applyAdjointJacobian_1;
70  //(
71  //ROL::Vector<double>& output_vector,
72  //const ROL::Vector<double>& input_vector,
73  //const ROL::Vector<double>& des_var_sim,
74  //const ROL::Vector<double>& des_var_ctl,
75  //const ROL::Vector<double>& dualv,
76  //double& /*tol*/
77  //);
79  using ROL::Constraint_SimOpt<double>::applyAdjointJacobian_2;
80 
81  // using ROL::Constraint_SimOpt<double>::applyAdjointHessian_11;
82  // using ROL::Constraint_SimOpt<double>::applyAdjointHessian_12;
83  // using ROL::Constraint_SimOpt<double>::applyAdjointHessian_21;
84  // using ROL::Constraint_SimOpt<double>::applyAdjointHessian_22;
85 
88  std::shared_ptr<DGBase<dim,double>> &_dg,
89  std::shared_ptr<BaseParameterization<dim>> _design_parameterization,
90  std::shared_ptr<dealii::TrilinosWrappers::SparseMatrix> precomputed_dXvdXp = nullptr);
91 
94 
96  void update_1( const ROL::Vector<double>& des_var_sim, bool flag = true, int iter = -1 );
97 
99 
101  void update_2( const ROL::Vector<double>& des_var_ctl, bool flag = true, int iter = -1 );
102 
104 
107  void solve(
108  ROL::Vector<double>& constraint_values,
109  ROL::Vector<double>& des_var_sim,
110  const ROL::Vector<double>& des_var_ctl,
111  double& /*tol*/
112  ) override;
113 
115  void value(
116  ROL::Vector<double>& constraint_values,
117  const ROL::Vector<double>& des_var_sim,
118  const ROL::Vector<double>& des_var_ctl,
119  double &/*tol*/
120  ) override;
121 
123  void applyJacobian_1(
124  ROL::Vector<double>& output_vector,
125  const ROL::Vector<double>& input_vector,
126  const ROL::Vector<double>& des_var_sim,
127  const ROL::Vector<double>& des_var_ctl,
128  double& /*tol*/
129  ) override;
130 
133  ROL::Vector<double>& output_vector,
134  const ROL::Vector<double>& input_vector,
135  const ROL::Vector<double>& des_var_sim,
136  const ROL::Vector<double>& des_var_ctl,
137  double& /*tol*/
138  ) override;
139 
142  ROL::Vector<double>& output_vector,
143  const ROL::Vector<double>& input_vector,
144  const ROL::Vector<double>& des_var_sim,
145  const ROL::Vector<double>& des_var_ctl,
146  double& /*tol*/
147  ) override;
148 
151  const ROL::Vector<double>& des_var_sim,
152  const ROL::Vector<double>& des_var_ctl);
153 
156 
158 
161  ROL::Vector<double>& output_vector,
162  const ROL::Vector<double>& input_vector,
163  const ROL::Vector<double>& des_var_sim,
164  const ROL::Vector<double>& des_var_ctl,
165  double& /*tol*/
166  );
167 
170  const ROL::Vector<double>& des_var_sim,
171  const ROL::Vector<double>& des_var_ctl);
172 
175 
177 
180  ROL::Vector<double>& output_vector,
181  const ROL::Vector<double>& input_vector,
182  const ROL::Vector<double>& des_var_sim,
183  const ROL::Vector<double>& des_var_ctl,
184  double& /*tol*/
185  );
186 
189  ROL::Vector<double>& output_vector,
190  const ROL::Vector<double>& input_vector,
191  const ROL::Vector<double>& des_var_sim,
192  const ROL::Vector<double>& des_var_ctl,
193  double& /*tol*/
194  ) override;
195 
197  void applyJacobian_2(
198  ROL::Vector<double>& output_vector,
199  const ROL::Vector<double>& input_vector,
200  const ROL::Vector<double>& des_var_sim,
201  const ROL::Vector<double>& des_var_ctl,
202  double& /*tol*/
203  ) override;
204 
205 
208  ROL::Vector<double>& output_vector,
209  const ROL::Vector<double>& input_vector,
210  const ROL::Vector<double>& des_var_sim,
211  const ROL::Vector<double>& des_var_ctl,
212  double& /*tol*/
213  ) override;
214 
216 
223  ROL::Vector<double> &output_vector,
224  const ROL::Vector<double> &dual,
225  const ROL::Vector<double> &input_vector,
226  const ROL::Vector<double> &des_var_sim,
227  const ROL::Vector<double> &des_var_ctl,
228  double &tol
229  ) override;
230 
232 
239  ROL::Vector<double> &output_vector,
240  const ROL::Vector<double> &dual,
241  const ROL::Vector<double> &input_vector,
242  const ROL::Vector<double> &des_var_sim,
243  const ROL::Vector<double> &des_var_ctl,
244  double &tol
245  ) override;
246 
248 
255  ROL::Vector<double> &output_vector,
256  const ROL::Vector<double> &dual,
257  const ROL::Vector<double> &input_vector,
258  const ROL::Vector<double> &des_var_sim,
259  const ROL::Vector<double> &des_var_ctl,
260  double &tol
261  ) override;
262 
264 
278  ROL::Vector<double> &output_vector,
279  const ROL::Vector<double> &dual,
280  const ROL::Vector<double> &input_vector,
281  const ROL::Vector<double> &des_var_sim,
282  const ROL::Vector<double> &des_var_ctl,
283  double &tol
284  ) override;
285 
286  // std::vector<double> solveAugmentedSystem(
287  // ROL::Vector<double> &v1,
288  // ROL::Vector<double> &v2,
289  // const ROL::Vector<double> &b1,
290  // const ROL::Vector<double> &b2,
291  // const ROL::Vector<double> &x,
292  // double & tol) override;
293  //
294  // void applyPreconditioner(ROL::Vector<double> &pv,
295  // const ROL::Vector<double> &v,
296  // const ROL::Vector<double> &x,
297  // const ROL::Vector<double> &g,
298  // double &tol) override;
299 
300 };
301 
302 } // PHiLiP namespace
303 
304 #endif
void applyAdjointJacobian_1(ROL::Vector< double > &output_vector, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &) override
Applies the Jacobian of the Constraints w. r. t. the simulation variables onto a vector.
void update_1(const ROL::Vector< double > &des_var_sim, bool flag=true, int iter=-1)
Update the simulation variables.
Parameters related to the linear solver.
void applyAdjointJacobian_2(ROL::Vector< double > &output_vector, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &) override
Applies the Jacobian of the Constraints w. r. t. the control variables onto a vector.
void applyAdjointHessian_12(ROL::Vector< double > &output_vector, const ROL::Vector< double > &dual, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &tol) override
Applies the adjoint of the Hessian of the constraints w. r. t. the simulation variables onto a vector...
Parameters::LinearSolverParam linear_solver_param
Linear solver parameters.
int i_out
ID used when outputting the flow solution.
void applyInverseAdjointJacobianPreconditioner_1(ROL::Vector< double > &output_vector, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &)
Applies the inverse Adjoint Jacobian preconditioner.
void destroy_JacobianPreconditioner_1()
Frees Jacobian preconditioner from memory;.
const bool i_print
Whether the current processor should print or not.
void destroy_AdjointJacobianPreconditioner_1()
Frees adjoint Jacobian preconditioner from memory;.
Files for the baseline physics.
Definition: ADTypes.hpp:10
void applyJacobian_2(ROL::Vector< double > &output_vector, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &) override
Applies the Jacobian of the Constraints w. r. t. the control variables onto a vector.
void applyInverseJacobian_1(ROL::Vector< double > &output_vector, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &) override
Applies the inverse Jacobian of the Constraints w. r. t. the simulation variables onto a vector...
void applyAdjointHessian_11(ROL::Vector< double > &output_vector, const ROL::Vector< double > &dual, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &tol) override
Applies the adjoint of the Hessian of the constraints w. r. t. the simulation variables onto a vector...
void applyJacobian_1(ROL::Vector< double > &output_vector, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &) override
Applies the Jacobian of the Constraints w. r. t. the simulation variables onto a vector.
const int mpi_rank
MPI rank used for printing.
void value(ROL::Vector< double > &constraint_values, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &) override
Returns the current constraint residual given a set of control and simulation variables.
void solve(ROL::Vector< double > &constraint_values, ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &) override
Solve the Simulation Constraint and returns the constraints values.
Abstract class for design parameterization. Objective function and the constraints take this class&#39;s ...
double flow_CFL_
Regularization of the constraint by adding flow_CFL_ times the mass matrix.
Use DGBase as a Simulation Constraint ROL::Constraint_SimOpt.
Ifpack_Preconditioner * adjoint_jacobian_prec
Adjoint Jacobian preconditioner.
dealii::LinearAlgebra::distributed::Vector< double > design_var
Design variables values.
int construct_AdjointJacobianPreconditioner_1(const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl)
Constructs the Adjoint Jacobian preconditioner.
void applyInverseAdjointJacobian_1(ROL::Vector< double > &output_vector, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &) override
Applies the adjoint Jacobian of the Constraints w. r. t. the simulation variables onto a vector...
Ifpack_Preconditioner * jacobian_prec
Jacobian preconditioner.
void applyInverseJacobianPreconditioner_1(ROL::Vector< double > &output_vector, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &)
Applies the inverse Jacobian preconditioner.
void applyAdjointHessian_22(ROL::Vector< double > &output_vector, const ROL::Vector< double > &dual, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &tol) override
Applies the adjoint of the Hessian of the constraints w. r. t. the simulation variables onto a vector...
int iupdate
ID used when outputting the flow solution.
void update_2(const ROL::Vector< double > &des_var_ctl, bool flag=true, int iter=-1)
Update the control variables.
std::shared_ptr< BaseParameterization< dim > > design_parameterization
Parameterization which links design variables to the volume nodes.
std::shared_ptr< DGBase< dim, double > > dg
Smart pointer to DGBase.
FlowConstraints(std::shared_ptr< DGBase< dim, double >> &_dg, std::shared_ptr< BaseParameterization< dim >> _design_parameterization, std::shared_ptr< dealii::TrilinosWrappers::SparseMatrix > precomputed_dXvdXp=nullptr)
Constructor.
void applyAdjointHessian_21(ROL::Vector< double > &output_vector, const ROL::Vector< double > &dual, const ROL::Vector< double > &input_vector, const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl, double &tol) override
Applies the adjoint of the Hessian of the constraints w. r. t. the simulation variables onto a vector...
dealii::TrilinosWrappers::SparseMatrix dXvdXp
Stores the mesh sensitivities.
DGBase is independent of the number of state variables.
Definition: dg_base.hpp:82
int construct_JacobianPreconditioner_1(const ROL::Vector< double > &des_var_sim, const ROL::Vector< double > &des_var_ctl)
Constructs the Jacobian preconditioner.