[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
dealii_solver_rol_vector.hpp
1 #ifndef __DEALII_SOLVER_ROL_VECTOR_H__
2 #define __DEALII_SOLVER_ROL_VECTOR_H__
3 
4 #include "ROL_Types.hpp"
5 #include "ROL_Vector_SimOpt.hpp"
6 
7 
8 #include "optimization/rol_to_dealii_vector.hpp"
9 
11 
14 template<typename Real = double>
16 {
17 private:
19  ROL::Ptr<ROL::Vector<Real>> rol_vector_ptr;
20 
21 
23  void print(const ROL::Vector<Real> &rol_vector) const
24  {
25  const ROL::Vector_SimOpt<Real> *vec_split12 = dynamic_cast<const ROL::Vector_SimOpt<Real> *>(&rol_vector);
26  if (vec_split12 == NULL) {
27  PHiLiP::ROL_vector_to_dealii_vector_reference(rol_vector).print(std::cout,14);
28  } else {
29  const auto vec_1 = vec_split12->get_1();
30  print(*vec_1);
31  const auto vec_2 = vec_split12->get_2();
32  print(*vec_2);
33  }
34  }
35 public:
37  using value_type = Real;
38 
40 
43 
45  explicit dealiiSolverVectorWrappingROL(ROL::Ptr<ROL::Vector<Real>> input_vector)
46  : rol_vector_ptr(input_vector)
47  {};
48 
50  ROL::Ptr<ROL::Vector<Real>> getVector()
51  {
52  return rol_vector_ptr;
53  }
54 
56  ROL::Ptr<const ROL::Vector<Real>> getVector() const
57  {
58  return rol_vector_ptr;
59  }
60 
64  void reinit (const dealiiSolverVectorWrappingROL &model_vector,
65  const bool leave_elements_uninitialized = false)
66  {
67  rol_vector_ptr = model_vector.getVector()->clone();
68  if (!leave_elements_uninitialized) {
69  (*this) *= 0.0;
70  }
71  }
74  {
75  return rol_vector_ptr->dot( *(v.getVector()) );
76  }
77 
80  {
81  rol_vector_ptr->setScalar(a);
82  return *this;
83  }
84 
87  {
88  rol_vector_ptr = (x.getVector())->clone();
89  return *this;
90  }
91 
94  {
95  rol_vector_ptr->scale(a);
96  return *this;
97  }
98 
101  {
102  this->add(1.0,x);
103  }
104 
106  void add (const Real a,
108  {
109  rol_vector_ptr->axpy(a, *(x.getVector()) );
110  }
111 
113  void sadd (const Real a,
114  const Real b,
116  {
117  (*this) *= a;
118  this->add(b, x);
119  }
120 
122  void equ (const Real a,
124  {
125  rol_vector_ptr->set( *(x.getVector()) );
126  (*this) *= a;
127  }
128 
131  Real add_and_dot (const Real a,
134  {
135  this->add(a, x);
136  return (*this) * v;
137  }
138 
140  Real l2_norm () const
141  {
142  return std::sqrt( (*this) * (*this) );
143  }
144 
146  Teuchos::RCP<dealiiSolverVectorWrappingROL> basis(int i) const
147  {
148  ROL::Ptr<ROL::Vector<Real>> rol_basis = rol_vector_ptr->basis(i);
149 
150  Teuchos::RCP<dealiiSolverVectorWrappingROL> e = Teuchos::rcp(new dealiiSolverVectorWrappingROL(rol_basis));
151 
152  return e;
153  }
154 
156  int size() const
157  {
158  return rol_vector_ptr->dimension();
159  }
160 
162  void print() const
163  {
164  print(*rol_vector_ptr);
165  // const auto &vec_split12 = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(*rol_vector_ptr);
166  // const auto des = vec_split12.get_1();
167  // const auto &des_split = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(*des);
168 
169  // const auto sim_des = des_split.get_1();
170  // const auto ctl_des = des_split.get_2();
171  // const auto con = vec_split12.get_2();
172 
173  // PHiLiP::ROL_vector_to_dealii_vector_reference(*sim_des).print(std::cout,14);
174  // PHiLiP::ROL_vector_to_dealii_vector_reference(*ctl_des).print(std::cout,14);
175  // PHiLiP::ROL_vector_to_dealii_vector_reference(*con).print(std::cout,14);
176  }
177 
179 
181  Real operator [](int i) const
182  {
183  const auto &vec_split12 = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(*rol_vector_ptr);
184  const auto des = vec_split12.get_1();
185  const auto &des_split = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(*des);
186 
187  const auto sim_des = des_split.get_1();
188  const auto ctl_des = des_split.get_2();
189  const auto con = vec_split12.get_2();
190 
191  const auto n1 = sim_des->dimension();
192  const auto n2 = ctl_des->dimension() + n1;
193  //const auto n3 = con->dimension() + n2;
194 
195  if (i < n1) {
197  } else if (i < n2) {
198  return PHiLiP::ROL_vector_to_dealii_vector_reference(*ctl_des)[i-n1];
199  } else {
201  }
202  }
203 
204 };
205 
206 #endif
Real value_type
Value type of the entries.
void print() const
Print the underlying deal.II Vector.
ROL::Ptr< const ROL::Vector< Real > > getVector() const
Const accessor.
Real l2_norm() const
Return the l2 norm of the vector.
void sadd(const Real a, const Real b, const dealiiSolverVectorWrappingROL &x)
Scaled addition of vectors.
void reinit(const dealiiSolverVectorWrappingROL &model_vector, const bool leave_elements_uninitialized=false)
Wrap the ROL vector into a vector that can be used by deal.II&#39;s solver.
dealiiSolverVectorWrappingROL & operator=(const dealiiSolverVectorWrappingROL &x)
Copy assignment.
dealiiSolverVectorWrappingROL & operator*=(const Real a)
Scale the elements of the current object by a fixed value.
void equ(const Real a, const dealiiSolverVectorWrappingROL &x)
Scaled assignment of a vector.
void add(const Real a, const dealiiSolverVectorWrappingROL &x)
Scaled addition of vectors.
dealiiSolverVectorWrappingROL()=default
Constructor.
ROL::Ptr< ROL::Vector< Real > > getVector()
Accessor.
void add(const dealiiSolverVectorWrappingROL &x)
Addition of vectors.
Real operator*(const dealiiSolverVectorWrappingROL &v) const
Inner product between the current object and the argument.
Real add_and_dot(const Real a, const dealiiSolverVectorWrappingROL &x, const dealiiSolverVectorWrappingROL &v)
dealiiSolverVectorWrappingROL(ROL::Ptr< ROL::Vector< Real >> input_vector)
Constructor where data is given.
dealiiSolverVectorWrappingROL & operator=(const Real a)
Assignment of a scalar.
ROL::Ptr< ROL::Vector< Real > > rol_vector_ptr
Pointer to ROL::Vector<Real> where data is actually stored.
void print(const ROL::Vector< Real > &rol_vector) const
Prints out the vector to std::cout.
const dealii::LinearAlgebra::distributed::Vector< double > & ROL_vector_to_dealii_vector_reference(const ROL::Vector< double > &x)
Access the read-write deali.II Vector stored within the ROL::Vector.
int size() const
Obtain vector size.
Teuchos::RCP< dealiiSolverVectorWrappingROL > basis(int i) const
Returns a vector of the same size with zero entries except for the ith entry being one...
Real operator[](int i) const
Access this ith value of the vector.