[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
identity_parameterization.cpp
1 #include "identity_parameterization.hpp"
2 #include <deal.II/dofs/dof_tools.h>
3 #include <deal.II/lac/dynamic_sparsity_pattern.h>
4 #include <deal.II/lac/sparsity_tools.h>
5 
6 namespace PHiLiP {
7 
8 template<int dim>
10  std::shared_ptr<HighOrderGrid<dim,double>> _high_order_grid)
11  : BaseParameterization<dim>(_high_order_grid)
12  {}
13 
14 template<int dim>
16 {
17  design_var = this->high_order_grid->volume_nodes; // Copies both the values and parallel distribution layout.
18  current_volume_nodes = design_var;
19  design_var.update_ghost_values();
20  current_volume_nodes.update_ghost_values();
21 }
22 
23 template<int dim>
25 {
26  // This might not be the best way to create parallel partitioned Identity matrix. To be updated if found.
27  const dealii::IndexSet &volume_range = this->high_order_grid->volume_nodes.get_partitioner()->locally_owned_range();
28  const unsigned int n_vol_nodes = this->high_order_grid->volume_nodes.size();
29  dealii::DynamicSparsityPattern dsp(n_vol_nodes, n_vol_nodes, volume_range);
30 
31  for(unsigned int i=0; i<n_vol_nodes; ++i)
32  {
33  if(!volume_range.is_element(i)) continue;
34  dsp.add(i,i);
35  }
36 
37  dealii::IndexSet locally_relevant_dofs;
38  dealii::DoFTools::extract_locally_relevant_dofs(this->high_order_grid->dof_handler_grid, locally_relevant_dofs);
39 
40  dealii::SparsityTools::distribute_sparsity_pattern(dsp, volume_range, this->mpi_communicator, locally_relevant_dofs);
41 
42  dXv_dXp.reinit(volume_range, volume_range, dsp, this->mpi_communicator);
43 
44  for(unsigned int i=0; i<n_vol_nodes; ++i)
45  {
46  if(!volume_range.is_element(i)) continue;
47  dXv_dXp.set(i,i,1.0);
48  }
49 
50  dXv_dXp.compress(dealii::VectorOperation::insert);
51 }
52 
53 template<int dim>
55  const MatrixType &dXv_dXp,
56  const VectorType &design_var)
57 {
58  AssertDimension(dXv_dXp.n(), design_var.size());
59 
60  bool design_variable_has_changed = this->has_design_variable_been_updated(current_volume_nodes, design_var);
61  bool mesh_updated;
62  if(!(design_variable_has_changed))
63  {
64  mesh_updated = false;
65  return mesh_updated;
66  }
67 
68  current_volume_nodes = design_var;
69  dXv_dXp.vmult(this->high_order_grid->volume_nodes, design_var);
70  this->high_order_grid->volume_nodes.update_ghost_values();
71  mesh_updated = true;
72  return mesh_updated;
73 }
74 
75 template<int dim>
77 {
78  return this->high_order_grid->volume_nodes.size();
79 }
80 
82 } // namespace PHiLiP
bool has_design_variable_been_updated(const VectorType &current_design_var, const VectorType &updated_design_var) const
Checks if the design variable has changed.
void compute_dXv_dXp(MatrixType &dXv_dXp) const override
Computes the derivative of volume nodes w.r.t. design parameters. Overrides the virtual function in b...
Files for the baseline physics.
Definition: ADTypes.hpp:10
dealii::TrilinosWrappers::SparseMatrix MatrixType
Alias for dealii::TrilinosWrappers::SparseMatrix.
Abstract class for design parameterization. Objective function and the constraints take this class&#39;s ...
bool update_mesh_from_design_variables(const MatrixType &dXv_dXp, const VectorType &design_var) override
Checks if the design variables have changed and updates volume nodes.
unsigned int get_number_of_design_variables() const override
Returns the number of design variables (i.e. total no. of volume nodes on all processors).
Identity design parameterization. Control variables are all volume nodes.
MPI_Comm mpi_communicator
Alias for MPI_COMM_WORLD.
std::shared_ptr< HighOrderGrid< dim, double > > high_order_grid
Pointer to high order grid.
dealii::LinearAlgebra::distributed::Vector< double > VectorType
Alias for dealii&#39;s parallel distributed vector.
void initialize_design_variables(VectorType &design_var) override
Initializes design variables with volume nodes and set locally owned and ghost indices. Overrides the virtual function in base class.
IdentityParameterization(std::shared_ptr< HighOrderGrid< dim, double >> _high_order_grid)
Constructor.