[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
functional.h
1 #ifndef __FUNCTIONAL_H__
2 #define __FUNCTIONAL_H__
3 
4 /* includes */
5 #include <deal.II/differentiation/ad/sacado_math.h>
6 #include <deal.II/differentiation/ad/sacado_number_types.h>
7 #include <deal.II/differentiation/ad/sacado_product_types.h>
8 #include <deal.II/fe/fe_q.h>
9 #include <deal.II/fe/fe_values.h>
10 #include <deal.II/lac/la_parallel_vector.h>
11 
12 #include <Sacado.hpp>
13 #include <iostream>
14 #include <vector>
15 
16 #include "dg/dg_base.hpp"
17 #include "physics/physics.h"
18 
19 namespace PHiLiP {
20 
22 
38 #if PHILIP_DIM==1
39 template <int dim, int nstate, typename real, typename MeshType = dealii::Triangulation<dim>>
40 #else
41 template <int dim, int nstate, typename real, typename MeshType = dealii::parallel::distributed::Triangulation<dim>>
42 #endif
43 class Functional
44 {
45  using FadType = Sacado::Fad::DFad<real>;
46  using FadFadType = Sacado::Fad::DFad<FadType>;
47 
48 public:
50  std::shared_ptr<DGBase<dim,real,MeshType>> dg;
51 
52 protected:
54  std::shared_ptr<Physics::PhysicsBase<dim,nstate,FadFadType>> physics_fad_fad;
55 
56 public:
58  virtual ~Functional() = default;
65  explicit Functional(
66  std::shared_ptr<PHiLiP::DGBase<dim,real,MeshType>> _dg,
67  const bool _uses_solution_values = true,
68  const bool _uses_solution_gradient = true);
69 
72  Functional(
73  std::shared_ptr<PHiLiP::DGBase<dim,real,MeshType>> _dg,
74  std::shared_ptr<PHiLiP::Physics::PhysicsBase<dim,nstate,Sacado::Fad::DFad<Sacado::Fad::DFad<real>> >> _physics_fad_fad,
75  const bool _uses_solution_values = true,
76  const bool _uses_solution_gradient = true);
77 
78 public:
80  void set_state(const dealii::LinearAlgebra::distributed::Vector<real> &solution_set);
82  void set_geom(const dealii::LinearAlgebra::distributed::Vector<real> &volume_nodes_set);
83 
85 
98  virtual real evaluate_functional(
99  const bool compute_dIdW = false,
100  const bool compute_dIdX = false,
101  const bool compute_d2I = false);
102 
104  dealii::LinearAlgebra::distributed::Vector<real> evaluate_dIdw_finiteDifferences(
107  const double stepsize);
108 
110  dealii::LinearAlgebra::distributed::Vector<real> evaluate_dIdX_finiteDifferences(
113  const double stepsize);
114 
117 
119  dealii::LinearAlgebra::distributed::Vector<real> dIdw;
121  dealii::LinearAlgebra::distributed::Vector<real> dIdX;
122 
124  std::shared_ptr<dealii::TrilinosWrappers::SparseMatrix> d2IdWdW;
126  std::shared_ptr<dealii::TrilinosWrappers::SparseMatrix> d2IdWdX;
128  std::shared_ptr<dealii::TrilinosWrappers::SparseMatrix> d2IdXdX;
129 
130 private:
133  void init_vectors();
136  dealii::LinearAlgebra::distributed::Vector<double> solution_value;
139  dealii::LinearAlgebra::distributed::Vector<double> volume_nodes_value;
140 
143  dealii::LinearAlgebra::distributed::Vector<double> solution_dIdW;
146  dealii::LinearAlgebra::distributed::Vector<double> volume_nodes_dIdW;
147 
150  dealii::LinearAlgebra::distributed::Vector<double> solution_dIdX;
153  dealii::LinearAlgebra::distributed::Vector<double> volume_nodes_dIdX;
154 
157  dealii::LinearAlgebra::distributed::Vector<double> solution_d2I;
160  dealii::LinearAlgebra::distributed::Vector<double> volume_nodes_d2I;
161 
162 protected:
164 
165  void allocate_derivatives(const bool compute_dIdW, const bool compute_dIdX, const bool compute_d2I);
166 
168 
169  void allocate_dIdX(dealii::LinearAlgebra::distributed::Vector<real> &dIdX) const;
170 
172 
173  void set_derivatives(
174  const bool compute_dIdW, const bool compute_dIdX, const bool compute_d2I,
175  const Sacado::Fad::DFad<Sacado::Fad::DFad<real>> volume_local_sum,
176  std::vector<dealii::types::global_dof_index> cell_soln_dofs_indices,
177  std::vector<dealii::types::global_dof_index> cell_metric_dofs_indices);
178 
179 protected:
181 
184  void need_compute(bool &compute_value, bool &compute_dIdW, bool &compute_dIdX, bool &compute_d2I);
185 
187  template <typename real2>
190  const std::vector< real2 > &soln_coeff,
191  const dealii::FESystem<dim> &fe_solution,
192  const std::vector< real2 > &coords_coeff,
193  const dealii::FESystem<dim> &fe_metric,
194  const dealii::Quadrature<dim> &volume_quadrature) const;
195 
197  virtual real evaluate_volume_cell_functional(
199  const std::vector< real > &soln_coeff,
200  const dealii::FESystem<dim> &fe_solution,
201  const std::vector< real > &coords_coeff,
202  const dealii::FESystem<dim> &fe_metric,
203  const dealii::Quadrature<dim> &volume_quadrature) const;
204 
206  virtual Sacado::Fad::DFad<Sacado::Fad::DFad<real>> evaluate_volume_cell_functional(
207  const Physics::PhysicsBase<dim,nstate,Sacado::Fad::DFad<Sacado::Fad::DFad<real>>> &physics_fad_fad,
208  const std::vector< Sacado::Fad::DFad<Sacado::Fad::DFad<real>> > &soln_coeff,
209  const dealii::FESystem<dim> &fe_solution,
210  const std::vector< Sacado::Fad::DFad<Sacado::Fad::DFad<real>> > &coords_coeff,
211  const dealii::FESystem<dim> &fe_metric,
212  const dealii::Quadrature<dim> &volume_quadrature) const;
213 
214  // /// Virtual function for computation of cell boundary functional term
215  // /** Used only in the computation of evaluate_function(). If not overriden returns 0. */
216  // virtual real evaluate_cell_boundary(
217  // const PHiLiP::Physics::PhysicsBase<dim,nstate,real> &/*physics*/,
218  // const unsigned int /*boundary_id*/,
219  // const dealii::FEFaceValues<dim,dim> &/*fe_values_boundary*/,
220  // const std::vector<real> &/*local_solution*/) const
221  // { return (real) 0.0; }
222 
223  // /// Virtual function for Sacado computation of cell boundary functional term and derivatives
224  // /** Used only in the computation of evaluate_dIdw(). If not overriden returns 0. */
225  // virtual FadFadType evaluate_cell_boundary(
226  // const PHiLiP::Physics::PhysicsBase<dim,nstate,FadFadType> &/*physics*/,
227  // const unsigned int /*boundary_id*/,
228  // const dealii::FEFaceValues<dim,dim> &/*fe_values_boundary*/,
229  // const std::vector<FadFadType> &/*local_solution*/) const
230  // { return (FadFadType) 0.0; }
231 
233  template <typename real2>
236  const unsigned int boundary_id,
237  const std::vector< real2 > &soln_coeff,
238  const dealii::FESystem<dim> &fe_solution,
239  const std::vector< real2 > &coords_coeff,
240  const dealii::FESystem<dim> &fe_metric,
241  const unsigned int face_number,
242  const dealii::Quadrature<dim-1> &face_quadrature) const;
243 
247  const unsigned int boundary_id,
248  const std::vector< real > &soln_coeff,
249  const dealii::FESystem<dim> &fe_solution,
250  const std::vector< real > &coords_coeff,
251  const dealii::FESystem<dim> &fe_metric,
252  const unsigned int face_number,
253  const dealii::Quadrature<dim-1> &face_quadrature) const;
254 
256  virtual Sacado::Fad::DFad<Sacado::Fad::DFad<real>> evaluate_boundary_cell_functional(
257  const Physics::PhysicsBase<dim,nstate,Sacado::Fad::DFad<Sacado::Fad::DFad<real>>> &physics_fad_fad,
258  const unsigned int boundary_id,
259  const std::vector< Sacado::Fad::DFad<Sacado::Fad::DFad<real>> > &soln_coeff,
260  const dealii::FESystem<dim> &fe_solution,
261  const std::vector< Sacado::Fad::DFad<Sacado::Fad::DFad<real>> > &coords_coeff,
262  const dealii::FESystem<dim> &fe_metric,
263  const unsigned int face_number,
264  const dealii::Quadrature<dim-1> &face_quadrature) const;
265 
267 
270  const dealii::Point<dim,real> &/*phys_coord*/,
271  const std::array<real,nstate> &/*soln_at_q*/,
272  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_at_q*/) const
273  { return (real) 0.0; }
274 
276 
279  const dealii::Point<dim,FadFadType> &/*phys_coord*/, const std::array<FadFadType,nstate> &/*soln_at_q*/,
280  const std::array<dealii::Tensor<1,dim,FadFadType>,nstate> &/*soln_grad_at_q*/) const
281  { return (real) 0.0; }
282 
284 
287  const unsigned int /*boundary_id*/,
288  const dealii::Point<dim,real> &/*phys_coord*/,
289  const dealii::Tensor<1,dim,real> &/*normal*/,
290  const std::array<real,nstate> &/*soln_at_q*/,
291  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_at_q*/) const
292  { return (real) 0.0; }
293 
295 
298  const unsigned int /*boundary_id*/,
299  const dealii::Point<dim,FadFadType> &/*phys_coord*/,
300  const dealii::Tensor<1,dim,FadFadType> &/*normal*/,
301  const std::array<FadFadType,nstate> &/*soln_at_q*/,
302  const std::array<dealii::Tensor<1,dim,FadFadType>,nstate> &/*soln_grad_at_q*/) const
303  { return (FadFadType) 0.0; }
304 
305 
306 protected:
308  const dealii::UpdateFlags volume_update_flags = dealii::update_values | dealii::update_gradients | dealii::update_quadrature_points | dealii::update_JxW_values;
310  const dealii::UpdateFlags face_update_flags = dealii::update_values | dealii::update_gradients | dealii::update_quadrature_points | dealii::update_JxW_values | dealii::update_normal_vectors;
311 
312 
313 protected:
314  const bool uses_solution_values;
316 
317  dealii::ConditionalOStream pcout;
318 
319 }; // TargetFunctional class
320 
322 
328 #if PHILIP_DIM==1
329 template <int dim, int nstate, typename real, typename MeshType = dealii::Triangulation<dim>>
330 #else
331 template <int dim, int nstate, typename real, typename MeshType = dealii::parallel::distributed::Triangulation<dim>>
332 #endif
333 class FunctionalNormLpVolume : public Functional<dim,nstate,real,MeshType>
334 {
335  using FadType = Sacado::Fad::DFad<real>;
336  using FadFadType = Sacado::Fad::DFad<FadType>;
337 public:
339  const double _normLp,
340  std::shared_ptr<DGBase<dim,real,MeshType>> _dg,
341  const bool _uses_solution_values = true,
342  const bool _uses_solution_gradient = false);
343 
344  template <typename real2>
347  const dealii::Point<dim,real2> & phys_coord,
348  const std::array<real2,nstate> & soln_at_q,
349  const std::array<dealii::Tensor<1,dim,real2>,nstate> &soln_grad_at_q) const;
350 
353  const dealii::Point<dim,real> & phys_coord,
354  const std::array<real,nstate> & soln_at_q,
355  const std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_at_q) const override
356  {
357  return evaluate_volume_integrand<>(physics, phys_coord, soln_at_q, soln_grad_at_q);
358  }
359 
362  const dealii::Point<dim,FadFadType> & phys_coord,
363  const std::array<FadFadType,nstate> & soln_at_q,
364  const std::array<dealii::Tensor<1,dim,FadFadType>,nstate> &soln_grad_at_q) const override
365  {
366  return evaluate_volume_integrand<>(physics, phys_coord, soln_at_q, soln_grad_at_q);
367  }
368 
369 protected:
371  const double normLp;
372 };
373 
375 
384 #if PHILIP_DIM==1
385 template <int dim, int nstate, typename real, typename MeshType = dealii::Triangulation<dim>>
386 #else
387 template <int dim, int nstate, typename real, typename MeshType = dealii::parallel::distributed::Triangulation<dim>>
388 #endif
389 class FunctionalNormLpBoundary : public Functional<dim,nstate,real,MeshType>
390 {
391  using FadType = Sacado::Fad::DFad<real>;
392  using FadFadType = Sacado::Fad::DFad<FadType>;
393 public:
395  const double _normLp,
396  std::vector<unsigned int> _boundary_vector,
397  const bool _use_all_boundaries,
398  std::shared_ptr<DGBase<dim,real,MeshType>> _dg,
399  const bool _uses_solution_values = true,
400  const bool _uses_solution_gradient = false);
401 
402  template <typename real2>
405  const unsigned int boundary_id,
406  const dealii::Point<dim,real2> & phys_coord,
407  const dealii::Tensor<1,dim,real2> & normal,
408  const std::array<real2,nstate> & soln_at_q,
409  const std::array<dealii::Tensor<1,dim,real2>,nstate> &soln_grad_at_q) const;
410 
413  const unsigned int boundary_id,
414  const dealii::Point<dim,real> & phys_coord,
415  const dealii::Tensor<1,dim,real> & normal,
416  const std::array<real,nstate> & soln_at_q,
417  const std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_at_q) const override
418  {
419  return evaluate_boundary_integrand<>(physics, boundary_id, phys_coord, normal, soln_at_q, soln_grad_at_q);
420  }
421 
424  const unsigned int boundary_id,
425  const dealii::Point<dim,FadFadType> & phys_coord,
426  const dealii::Tensor<1,dim,FadFadType> & normal,
427  const std::array<FadFadType,nstate> & soln_at_q,
428  const std::array<dealii::Tensor<1,dim,FadFadType>,nstate> &soln_grad_at_q) const override
429  {
430  return evaluate_boundary_integrand<>(physics, boundary_id, phys_coord, normal, soln_at_q, soln_grad_at_q);
431  }
432 
433 protected:
435  const double normLp;
437  std::vector<unsigned int> boundary_vector;
439  const bool use_all_boundaries;
440 };
441 
443 
451 #if PHILIP_DIM==1
452 template <int dim, int nstate, typename real, typename MeshType = dealii::Triangulation<dim>>
453 #else
454 template <int dim, int nstate, typename real, typename MeshType = dealii::parallel::distributed::Triangulation<dim>>
455 #endif
456 class FunctionalWeightedIntegralVolume : public Functional<dim,nstate,real,MeshType>
457 {
458  using FadType = Sacado::Fad::DFad<real>;
459  using FadFadType = Sacado::Fad::DFad<FadType>;
460 public:
462  std::shared_ptr<ManufacturedSolutionFunction<dim,real>> _weight_function_double,
463  std::shared_ptr<ManufacturedSolutionFunction<dim,FadFadType>> _weight_function_adtype,
464  const bool _use_weight_function_laplacian,
465  std::shared_ptr<DGBase<dim,real,MeshType>> _dg,
466  const bool _uses_solution_values = true,
467  const bool _uses_solution_gradient = false);
468 
469  template <typename real2>
472  const dealii::Point<dim,real2> & phys_coord,
473  const std::array<real2,nstate> & soln_at_q,
474  const std::array<dealii::Tensor<1,dim,real2>,nstate> & soln_grad_at_q,
475  std::shared_ptr<ManufacturedSolutionFunction<dim,real2>> weight_function) const;
476 
479  const dealii::Point<dim,real> & phys_coord,
480  const std::array<real,nstate> & soln_at_q,
481  const std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_at_q) const override
482  {
483  return evaluate_volume_integrand<>(physics, phys_coord, soln_at_q, soln_grad_at_q, this->weight_function_double);
484  }
485 
488  const dealii::Point<dim,FadFadType> & phys_coord,
489  const std::array<FadFadType,nstate> & soln_at_q,
490  const std::array<dealii::Tensor<1,dim,FadFadType>,nstate> &soln_grad_at_q) const override
491  {
492  return evaluate_volume_integrand<>(physics, phys_coord, soln_at_q, soln_grad_at_q, this->weight_function_adtype);
493  }
494 
495 protected:
497  std::shared_ptr<ManufacturedSolutionFunction<dim,real>> weight_function_double;
499  std::shared_ptr<ManufacturedSolutionFunction<dim,FadFadType>> weight_function_adtype;
502 };
503 
505 
516 #if PHILIP_DIM==1
517 template <int dim, int nstate, typename real, typename MeshType = dealii::Triangulation<dim>>
518 #else
519 template <int dim, int nstate, typename real, typename MeshType = dealii::parallel::distributed::Triangulation<dim>>
520 #endif
521 class FunctionalWeightedIntegralBoundary : public Functional<dim,nstate,real,MeshType>
522 {
523  using FadType = Sacado::Fad::DFad<real>;
524  using FadFadType = Sacado::Fad::DFad<FadType>;
525 public:
527  std::shared_ptr<ManufacturedSolutionFunction<dim,real>> _weight_function_double,
528  std::shared_ptr<ManufacturedSolutionFunction<dim,FadFadType>> _weight_function_adtype,
529  const bool _use_weight_function_laplacian,
530  std::vector<unsigned int> _boundary_vector,
531  const bool _use_all_boundaries,
532  std::shared_ptr<DGBase<dim,real,MeshType>> _dg,
533  const bool _uses_solution_values = true,
534  const bool _uses_solution_gradient = false);
535 
536  template <typename real2>
539  const unsigned int boundary_id,
540  const dealii::Point<dim,real2> & phys_coord,
541  const dealii::Tensor<1,dim,real2> & normal,
542  const std::array<real2,nstate> & soln_at_q,
543  const std::array<dealii::Tensor<1,dim,real2>,nstate> & soln_grad_at_q,
544  std::shared_ptr<ManufacturedSolutionFunction<dim,real2>> weight_function) const;
545 
548  const unsigned int boundary_id,
549  const dealii::Point<dim,real> & phys_coord,
550  const dealii::Tensor<1,dim,real> & normal,
551  const std::array<real,nstate> & soln_at_q,
552  const std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_at_q) const override
553  {
554  return evaluate_boundary_integrand<>(physics, boundary_id, phys_coord, normal, soln_at_q, soln_grad_at_q, this->weight_function_double);
555  }
556 
559  const unsigned int boundary_id,
560  const dealii::Point<dim,FadFadType> & phys_coord,
561  const dealii::Tensor<1,dim,FadFadType> & normal,
562  const std::array<FadFadType,nstate> & soln_at_q,
563  const std::array<dealii::Tensor<1,dim,FadFadType>,nstate> &soln_grad_at_q) const override
564  {
565  return evaluate_boundary_integrand<>(physics, boundary_id, phys_coord, normal, soln_at_q, soln_grad_at_q, this->weight_function_adtype);
566  }
567 
568 protected:
570  std::shared_ptr<ManufacturedSolutionFunction<dim,real>> weight_function_double;
572  std::shared_ptr<ManufacturedSolutionFunction<dim,FadFadType>> weight_function_adtype;
576  std::vector<unsigned int> boundary_vector;
578  const bool use_all_boundaries;
579 };
580 
582 
589 #if PHILIP_DIM==1
590 template <int dim, int nstate, typename real, typename MeshType = dealii::Triangulation<dim>>
591 #else
592 template <int dim, int nstate, typename real, typename MeshType = dealii::parallel::distributed::Triangulation<dim>>
593 #endif
594 class FunctionalErrorNormLpVolume : public Functional<dim,nstate,real,MeshType>
595 {
596  using FadType = Sacado::Fad::DFad<real>;
597  using FadFadType = Sacado::Fad::DFad<FadType>;
598 public:
600  const double _normLp,
601  std::shared_ptr<DGBase<dim,real,MeshType>> _dg,
602  const bool _uses_solution_values = true,
603  const bool _uses_solution_gradient = false);
604 
605  template <typename real2>
608  const dealii::Point<dim,real2> & phys_coord,
609  const std::array<real2,nstate> & soln_at_q,
610  const std::array<dealii::Tensor<1,dim,real2>,nstate> &soln_grad_at_q) const;
611 
614  const dealii::Point<dim,real> & phys_coord,
615  const std::array<real,nstate> & soln_at_q,
616  const std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_at_q) const override
617  {
618  return evaluate_volume_integrand<>(physics, phys_coord, soln_at_q, soln_grad_at_q);
619  }
620 
623  const dealii::Point<dim,FadFadType> & phys_coord,
624  const std::array<FadFadType,nstate> & soln_at_q,
625  const std::array<dealii::Tensor<1,dim,FadFadType>,nstate> &soln_grad_at_q) const override
626  {
627  return evaluate_volume_integrand<>(physics, phys_coord, soln_at_q, soln_grad_at_q);
628  }
629 
630 protected:
632  const double normLp;
633 };
634 
636 
646 #if PHILIP_DIM==1
647 template <int dim, int nstate, typename real, typename MeshType = dealii::Triangulation<dim>>
648 #else
649 template <int dim, int nstate, typename real, typename MeshType = dealii::parallel::distributed::Triangulation<dim>>
650 #endif
651 class FunctionalErrorNormLpBoundary : public Functional<dim,nstate,real,MeshType>
652 {
653  using FadType = Sacado::Fad::DFad<real>;
654  using FadFadType = Sacado::Fad::DFad<FadType>;
655 public:
657  const double _normLp,
658  std::vector<unsigned int> _boundary_vector,
659  const bool _use_all_boundaries,
660  std::shared_ptr<DGBase<dim,real,MeshType>> _dg,
661  const bool _uses_solution_values = true,
662  const bool _uses_solution_gradient = false);
663 
664  template <typename real2>
667  const unsigned int boundary_id,
668  const dealii::Point<dim,real2> & phys_coord,
669  const dealii::Tensor<1,dim,real2> & normal,
670  const std::array<real2,nstate> & soln_at_q,
671  const std::array<dealii::Tensor<1,dim,real2>,nstate> &soln_grad_at_q) const;
672 
675  const unsigned int boundary_id,
676  const dealii::Point<dim,real> & phys_coord,
677  const dealii::Tensor<1,dim,real> & normal,
678  const std::array<real,nstate> & soln_at_q,
679  const std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_at_q) const override
680  {
681  return evaluate_boundary_integrand<>(physics, boundary_id, phys_coord, normal, soln_at_q, soln_grad_at_q);
682  }
683 
686  const unsigned int boundary_id,
687  const dealii::Point<dim,FadFadType> & phys_coord,
688  const dealii::Tensor<1,dim,FadFadType> & normal,
689  const std::array<FadFadType,nstate> & soln_at_q,
690  const std::array<dealii::Tensor<1,dim,FadFadType>,nstate> &soln_grad_at_q) const override
691  {
692  return evaluate_boundary_integrand<>(physics, boundary_id, phys_coord, normal, soln_at_q, soln_grad_at_q);
693  }
694 
695 protected:
697  const double normLp;
699  std::vector<unsigned int> boundary_vector;
701  const bool use_all_boundaries;
702 };
703 
705 #if PHILIP_DIM==1
706  template <int dim, int nstate, typename real, typename MeshType = dealii::Triangulation<dim>>
707 #else
708  template <int dim, int nstate, typename real, typename MeshType = dealii::parallel::distributed::Triangulation<dim>>
709 #endif
710 class SolutionIntegral : public Functional<dim,nstate,real,MeshType>
711 {
712 public:
713  using FadType = Sacado::Fad::DFad<real>;
714  using FadFadType = Sacado::Fad::DFad<FadType>;
715 public:
718  std::shared_ptr<PHiLiP::DGBase<dim,real, MeshType>> dg_input,
719  std::shared_ptr<PHiLiP::Physics::PhysicsBase<dim,nstate,FadFadType>> _physics_fad_fad,
720  const bool uses_solution_values = true,
721  const bool uses_solution_gradient = false)
722  : PHiLiP::Functional<dim,nstate,real,MeshType>(dg_input,_physics_fad_fad,uses_solution_values,uses_solution_gradient)
723  {}
724 
726  template <typename real2>
729  const dealii::Point<dim,real2> &phys_coord,
730  const std::array<real2,nstate> &soln_at_q,
731  const std::array<dealii::Tensor<1,dim,real2>,nstate> &soln_grad_at_q) const;
732 
736  const dealii::Point<dim,real> &phys_coord,
737  const std::array<real,nstate> &soln_at_q,
738  const std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_at_q) const override
739  {
740  return evaluate_volume_integrand<>(physics, phys_coord, soln_at_q, soln_grad_at_q);
741  }
742 
746  const dealii::Point<dim,FadFadType> &phys_coord,
747  const std::array<FadFadType,nstate> &soln_at_q,
748  const std::array<dealii::Tensor<1,dim,FadFadType>,nstate> &soln_grad_at_q) const override
749  {
750  return evaluate_volume_integrand<>(physics, phys_coord, soln_at_q, soln_grad_at_q);
751  }
752 };
753 
757 template <int dim, int nstate, typename real, typename MeshType = dealii::parallel::distributed::Triangulation<dim>>
758 class OutletPressureIntegral : public Functional<dim,nstate,real,MeshType>
759 {
760  using FadType = Sacado::Fad::DFad<real>;
761  using FadFadType = Sacado::Fad::DFad<FadType>;
762 public:
764  std::shared_ptr<PHiLiP::DGBase<dim,real, MeshType>> dg_input,
765  const bool uses_solution_values = true,
766  const bool uses_solution_gradient = false);
767 
769  template <typename real2>
772  const unsigned int boundary_id,
773  const dealii::Point<dim,real2> & phys_coord,
774  const dealii::Tensor<1,dim,real2> & normal,
775  const std::array<real2,nstate> & soln_at_q,
776  const std::array<dealii::Tensor<1,dim,real2>,nstate> &soln_grad_at_q) const;
777 
781  const unsigned int boundary_id,
782  const dealii::Point<dim,real> & phys_coord,
783  const dealii::Tensor<1,dim,real> & normal,
784  const std::array<real,nstate> & soln_at_q,
785  const std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_at_q) const override
786  {
787  return evaluate_boundary_integrand<>(physics, boundary_id, phys_coord, normal, soln_at_q, soln_grad_at_q);
788  }
789 
793  const unsigned int boundary_id,
794  const dealii::Point<dim,FadFadType> & phys_coord,
795  const dealii::Tensor<1,dim,FadFadType> & normal,
796  const std::array<FadFadType,nstate> & soln_at_q,
797  const std::array<dealii::Tensor<1,dim,FadFadType>,nstate> &soln_grad_at_q) const override
798  {
799  return evaluate_boundary_integrand<>(physics, boundary_id, phys_coord, normal, soln_at_q, soln_grad_at_q);
800  }
801 };
802 
804 
808 #if PHILIP_DIM==1
809 template <int dim, int nstate, typename real, typename MeshType = dealii::Triangulation<dim>>
810 #else
811 template <int dim, int nstate, typename real, typename MeshType = dealii::parallel::distributed::Triangulation<dim>>
812 #endif
814 {
815 public:
817  static std::shared_ptr< Functional<dim,nstate,real,MeshType> >
818  create_Functional(
819  PHiLiP::Parameters::AllParameters const *const param,
820  std::shared_ptr< PHiLiP::DGBase<dim,real,MeshType> > dg);
821 
823  static std::shared_ptr< Functional<dim,nstate,real,MeshType> >
824  create_Functional(
826  std::shared_ptr< PHiLiP::DGBase<dim,real,MeshType> > dg);
827 };
828 
829 } // PHiLiP namespace
830 
831 #endif // __FUNCTIONAL_H__
std::shared_ptr< dealii::TrilinosWrappers::SparseMatrix > d2IdXdX
Sparse matrix for storing the functional partial second derivatives.
Definition: functional.h:128
const bool use_weight_function_laplacian
Flag to enable using the weight function laplacian.
Definition: functional.h:501
Weighted volume norm functional class.
Definition: functional.h:456
FadFadType evaluate_boundary_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType > &physics, const unsigned int boundary_id, const dealii::Point< dim, FadFadType > &phys_coord, const dealii::Tensor< 1, dim, FadFadType > &normal, const std::array< FadFadType, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, FadFadType >, nstate > &soln_grad_at_q) const override
Virtual function for Sacado computation of cell boundary functional term and derivatives.
Definition: functional.h:557
const bool uses_solution_gradient
Will evaluate solution gradient at quadrature points.
Definition: functional.h:315
const double normLp
Norm exponent value.
Definition: functional.h:371
Lp volume norm functional class.
Definition: functional.h:333
dealii::LinearAlgebra::distributed::Vector< real > dIdX
Vector for storing the derivatives with respect to each grid DoF.
Definition: functional.h:121
Sacado::Fad::DFad< double > FadType
Sacado AD type for first derivatives.
Definition: functional.h:45
const double normLp
Norm exponent value.
Definition: functional.h:435
std::vector< unsigned int > boundary_vector
Ids of selected boundaries for integration.
Definition: functional.h:437
const bool uses_solution_values
Will evaluate solution values at quadrature points.
Definition: functional.h:314
dealii::LinearAlgebra::distributed::Vector< double > solution_dIdX
Definition: functional.h:150
void set_state(const dealii::LinearAlgebra::distributed::Vector< real > &solution_set)
Definition: functional.cpp:376
dealii::LinearAlgebra::distributed::Vector< double > volume_nodes_value
Definition: functional.h:139
dealii::LinearAlgebra::distributed::Vector< real > dIdw
Vector for storing the derivatives with respect to each solution DoF.
Definition: functional.h:119
Base class from which Advection, Diffusion, ConvectionDiffusion, and Euler is derived.
Definition: physics.h:34
dealii::LinearAlgebra::distributed::Vector< double > solution_dIdW
Definition: functional.h:143
Manufactured solution used for grid studies to check convergence orders.
real evaluate_volume_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &physics, const dealii::Point< dim, real > &phys_coord, const std::array< real, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_at_q) const override
Virtual function for computation of cell volume functional term.
Definition: functional.h:351
std::vector< unsigned int > boundary_vector
Ids of selected boundaries for integration.
Definition: functional.h:699
real evaluate_boundary_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &physics, const unsigned int boundary_id, const dealii::Point< dim, real > &phys_coord, const dealii::Tensor< 1, dim, real > &normal, const std::array< real, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_at_q) const override
Virtual function for computation of cell boundary functional term.
Definition: functional.h:411
std::shared_ptr< dealii::TrilinosWrappers::SparseMatrix > d2IdWdW
Sparse matrix for storing the functional partial second derivatives.
Definition: functional.h:124
virtual real evaluate_boundary_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &, const unsigned int, const dealii::Point< dim, real > &, const dealii::Tensor< 1, dim, real > &, const std::array< real, nstate > &, const std::array< dealii::Tensor< 1, dim, real >, nstate > &) const
Virtual function for computation of cell boundary functional term.
Definition: functional.h:285
std::shared_ptr< ManufacturedSolutionFunction< dim, real > > weight_function_double
Manufactured solution weighting function of double return type.
Definition: functional.h:497
real evaluate_boundary_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &physics, const unsigned int boundary_id, const dealii::Point< dim, real > &phys_coord, const dealii::Tensor< 1, dim, real > &normal, const std::array< real, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_at_q) const override
Virtual function for computation of cell boundary functional term.
Definition: functional.h:546
const dealii::UpdateFlags face_update_flags
Update flags needed at face points.
Definition: functional.h:310
Sacado::Fad::DFad< FadType > FadFadType
Sacado AD type that allows 2nd derivatives.
Definition: functional.h:46
Files for the baseline physics.
Definition: ADTypes.hpp:10
std::shared_ptr< ManufacturedSolutionFunction< dim, FadFadType > > weight_function_adtype
Manufactured solution weighting function of adtype return type.
Definition: functional.h:572
SolutionIntegral(std::shared_ptr< PHiLiP::DGBase< dim, real, MeshType >> dg_input, std::shared_ptr< PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType >> _physics_fad_fad, const bool uses_solution_values=true, const bool uses_solution_gradient=false)
Constructor.
Definition: functional.h:717
Functional to take the integral of the solution.
Definition: functional.h:710
FadFadType evaluate_volume_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType > &physics, const dealii::Point< dim, FadFadType > &phys_coord, const std::array< FadFadType, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, FadFadType >, nstate > &soln_grad_at_q) const override
Virtual function for Sacado computation of cell volume functional term and derivatives.
Definition: functional.h:486
Main parameter class that contains the various other sub-parameter classes.
virtual real evaluate_volume_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &, const dealii::Point< dim, real > &, const std::array< real, nstate > &, const std::array< dealii::Tensor< 1, dim, real >, nstate > &) const
Virtual function for computation of cell volume functional term.
Definition: functional.h:268
Lp boundary norm functional class.
Definition: functional.h:389
Sacado::Fad::DFad< FadType > FadFadType
Sacado AD type that allows 2nd derivatives.
Definition: functional.h:459
void allocate_dIdX(dealii::LinearAlgebra::distributed::Vector< real > &dIdX) const
Allocate and setup the derivative dIdX vector.
Definition: functional.cpp:388
std::vector< unsigned int > boundary_vector
Ids of selected boundaries for integration.
Definition: functional.h:576
dealii::LinearAlgebra::distributed::Vector< double > volume_nodes_dIdW
Definition: functional.h:146
FadFadType evaluate_boundary_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType > &physics, const unsigned int boundary_id, const dealii::Point< dim, FadFadType > &phys_coord, const dealii::Tensor< 1, dim, FadFadType > &normal, const std::array< FadFadType, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, FadFadType >, nstate > &soln_grad_at_q) const override
Non-template functions to override the template classes.
Definition: functional.h:791
Factory class to construct default functional types.
Definition: functional.h:813
FadFadType evaluate_volume_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType > &physics, const dealii::Point< dim, FadFadType > &phys_coord, const std::array< FadFadType, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, FadFadType >, nstate > &soln_grad_at_q) const override
Non-template functions to override the template classes.
Definition: functional.h:744
real2 evaluate_boundary_cell_functional(const Physics::PhysicsBase< dim, nstate, real2 > &physics, const unsigned int boundary_id, const std::vector< real2 > &soln_coeff, const dealii::FESystem< dim > &fe_solution, const std::vector< real2 > &coords_coeff, const dealii::FESystem< dim > &fe_metric, const unsigned int face_number, const dealii::Quadrature< dim-1 > &face_quadrature) const
Templated function to evaluate a cell&#39;s boundary functional.
Definition: functional.cpp:565
dealii::LinearAlgebra::distributed::Vector< real > evaluate_dIdw_finiteDifferences(DGBase< dim, real, MeshType > &dg, const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &physics, const double stepsize)
Definition: functional.cpp:984
FadFadType evaluate_boundary_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType > &physics, const unsigned int boundary_id, const dealii::Point< dim, FadFadType > &phys_coord, const dealii::Tensor< 1, dim, FadFadType > &normal, const std::array< FadFadType, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, FadFadType >, nstate > &soln_grad_at_q) const override
Virtual function for Sacado computation of cell boundary functional term and derivatives.
Definition: functional.h:684
FadFadType evaluate_volume_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType > &physics, const dealii::Point< dim, FadFadType > &phys_coord, const std::array< FadFadType, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, FadFadType >, nstate > &soln_grad_at_q) const override
Virtual function for Sacado computation of cell volume functional term and derivatives.
Definition: functional.h:621
dealii::LinearAlgebra::distributed::Vector< real > evaluate_dIdX_finiteDifferences(DGBase< dim, real, MeshType > &dg, const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &physics, const double stepsize)
dealii::LinearAlgebra::distributed::Vector< double > volume_nodes_dIdX
Definition: functional.h:153
Parameterse related to the functional object.
Lp volume error norm functional class.
Definition: functional.h:594
const bool use_weight_function_laplacian
Flag to enable using the weight function laplacian.
Definition: functional.h:574
const bool use_all_boundaries
Flag to use all domain boundaries.
Definition: functional.h:701
FadFadType evaluate_boundary_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType > &physics, const unsigned int boundary_id, const dealii::Point< dim, FadFadType > &phys_coord, const dealii::Tensor< 1, dim, FadFadType > &normal, const std::array< FadFadType, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, FadFadType >, nstate > &soln_grad_at_q) const override
Virtual function for Sacado computation of cell boundary functional term and derivatives.
Definition: functional.h:422
virtual FadFadType evaluate_volume_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType > &, const dealii::Point< dim, FadFadType > &, const std::array< FadFadType, nstate > &, const std::array< dealii::Tensor< 1, dim, FadFadType >, nstate > &) const
Virtual function for Sacado computation of cell volume functional term and derivatives.
Definition: functional.h:277
real current_functional_value
Store the functional value from the last time evaluate_functional() was called.
Definition: functional.h:116
void need_compute(bool &compute_value, bool &compute_dIdW, bool &compute_dIdX, bool &compute_d2I)
Checks which derivatives actually need to be recomputed.
Definition: functional.cpp:690
Functional(std::shared_ptr< PHiLiP::DGBase< dim, real, MeshType >> _dg, const bool _uses_solution_values=true, const bool _uses_solution_gradient=true)
const bool use_all_boundaries
Flag to use all domain boundaries.
Definition: functional.h:439
Weighted boundary norm functional class.
Definition: functional.h:521
dealii::LinearAlgebra::distributed::Vector< double > volume_nodes_d2I
Definition: functional.h:160
std::shared_ptr< Physics::PhysicsBase< dim, nstate, FadFadType > > physics_fad_fad
Physics that should correspond to the one in DGBase.
Definition: functional.h:54
FadFadType evaluate_volume_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType > &physics, const dealii::Point< dim, FadFadType > &phys_coord, const std::array< FadFadType, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, FadFadType >, nstate > &soln_grad_at_q) const override
Virtual function for Sacado computation of cell volume functional term and derivatives.
Definition: functional.h:360
std::shared_ptr< dealii::TrilinosWrappers::SparseMatrix > d2IdWdX
Sparse matrix for storing the functional partial second derivatives.
Definition: functional.h:126
Sacado::Fad::DFad< FadType > FadFadType
Sacado AD type that allows 2nd derivatives.
Definition: functional.h:524
virtual ~Functional()=default
Destructor.
dealii::LinearAlgebra::distributed::Vector< double > solution_d2I
Definition: functional.h:157
const double normLp
Norm exponent value.
Definition: functional.h:632
Functional base class.
Definition: functional.h:43
virtual FadFadType evaluate_boundary_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, FadFadType > &, const unsigned int, const dealii::Point< dim, FadFadType > &, const dealii::Tensor< 1, dim, FadFadType > &, const std::array< FadFadType, nstate > &, const std::array< dealii::Tensor< 1, dim, FadFadType >, nstate > &) const
Virtual function for Sacado computation of cell boundary functional term and derivatives.
Definition: functional.h:296
std::shared_ptr< DGBase< dim, real, MeshType > > dg
Smart pointer to DGBase.
Definition: functional.h:50
dealii::LinearAlgebra::distributed::Vector< double > solution_value
Definition: functional.h:136
std::shared_ptr< ManufacturedSolutionFunction< dim, FadFadType > > weight_function_adtype
Manufactured solution weighting function of adtype return type.
Definition: functional.h:499
const double normLp
Norm exponent value.
Definition: functional.h:697
DGBase is independent of the number of state variables.
Definition: dg_base.hpp:82
real evaluate_volume_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &physics, const dealii::Point< dim, real > &phys_coord, const std::array< real, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_at_q) const override
Virtual function for computation of cell volume functional term.
Definition: functional.h:612
Lp boundary error norm functional class.
Definition: functional.h:651
void allocate_derivatives(const bool compute_dIdW, const bool compute_dIdX, const bool compute_d2I)
Allocate and setup the derivative vectors/matrices.
Definition: functional.cpp:400
virtual real evaluate_functional(const bool compute_dIdW=false, const bool compute_dIdX=false, const bool compute_d2I=false)
Evaluates the functional derivative with respect to the solution variable.
Definition: functional.cpp:795
real evaluate_volume_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &physics, const dealii::Point< dim, real > &phys_coord, const std::array< real, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_at_q) const override
Non-template functions to override the template classes.
Definition: functional.h:734
void set_derivatives(const bool compute_dIdW, const bool compute_dIdX, const bool compute_d2I, const Sacado::Fad::DFad< Sacado::Fad::DFad< real >> volume_local_sum, std::vector< dealii::types::global_dof_index > cell_soln_dofs_indices, std::vector< dealii::types::global_dof_index > cell_metric_dofs_indices)
Set the derivative vectors/matrices.
Definition: functional.cpp:436
const bool use_all_boundaries
Flag to use all domain boundaries.
Definition: functional.h:578
std::shared_ptr< ManufacturedSolutionFunction< dim, real > > weight_function_double
Manufactured solution weighting function of double return type.
Definition: functional.h:570
const dealii::UpdateFlags volume_update_flags
Update flags needed at volume points.
Definition: functional.h:308
real evaluate_boundary_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &physics, const unsigned int boundary_id, const dealii::Point< dim, real > &phys_coord, const dealii::Tensor< 1, dim, real > &normal, const std::array< real, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_at_q) const override
Non-template functions to override the template classes.
Definition: functional.h:779
real evaluate_volume_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &physics, const dealii::Point< dim, real > &phys_coord, const std::array< real, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_at_q) const override
Virtual function for computation of cell volume functional term.
Definition: functional.h:477
void set_geom(const dealii::LinearAlgebra::distributed::Vector< real > &volume_nodes_set)
Definition: functional.cpp:382
real evaluate_boundary_integrand(const PHiLiP::Physics::PhysicsBase< dim, nstate, real > &physics, const unsigned int boundary_id, const dealii::Point< dim, real > &phys_coord, const dealii::Tensor< 1, dim, real > &normal, const std::array< real, nstate > &soln_at_q, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_at_q) const override
Virtual function for computation of cell boundary functional term.
Definition: functional.h:673
dealii::ConditionalOStream pcout
Parallel std::cout that only outputs on mpi_rank==0.
Definition: functional.h:317
real2 evaluate_volume_cell_functional(const Physics::PhysicsBase< dim, nstate, real2 > &physics, const std::vector< real2 > &soln_coeff, const dealii::FESystem< dim > &fe_solution, const std::vector< real2 > &coords_coeff, const dealii::FESystem< dim > &fe_metric, const dealii::Quadrature< dim > &volume_quadrature) const
Templated function to evaluate a cell&#39;s volume functional.
Definition: functional.cpp:504