16#ifndef dealii_optimization_rol_vector_adaptor_h
17#define dealii_optimization_rol_vector_adaptor_h
21#ifdef DEAL_II_TRILINOS_WITH_ROL
26# include <ROL_Vector.hpp>
29# include <type_traits>
110 template <
typename VectorType>
128 static_assert(std::is_convertible<real_type, value_type>::value,
129 "The real_type of the current VectorType is not "
130 "convertible to the value_type.");
149 Teuchos::RCP<VectorType>
155 Teuchos::RCP<const VectorType>
173 set(
const ROL::Vector<value_type> &rol_vector);
179 plus(
const ROL::Vector<value_type> &rol_vector);
198 dot(
const ROL::Vector<value_type> &rol_vector)
const;
215 Teuchos::RCP<ROL::Vector<value_type>>
223 Teuchos::RCP<ROL::Vector<value_type>>
230 applyUnary(
const ROL::Elementwise::UnaryFunction<value_type> &f);
237 applyBinary(
const ROL::Elementwise::BinaryFunction<value_type> &f,
238 const ROL::Vector<value_type> & rol_vector);
245 reduce(
const ROL::Elementwise::ReductionOp<value_type> &r)
const;
251 print(std::ostream &outStream)
const;
259 template <
typename VectorType>
261 const Teuchos::RCP<VectorType> &vector_ptr)
262 : vector_ptr(vector_ptr)
267 template <
typename VectorType>
268 Teuchos::RCP<VectorType>
276 template <
typename VectorType>
277 Teuchos::RCP<const VectorType>
285 template <
typename VectorType>
289 const VectorAdaptor &vector_adaptor =
290 Teuchos::dyn_cast<const VectorAdaptor>(rol_vector);
292 (*vector_ptr) = *(vector_adaptor.getVector());
297 template <
typename VectorType>
301 Assert(this->dimension() == rol_vector.dimension(),
304 const VectorAdaptor &vector_adaptor =
305 Teuchos::dyn_cast<const VectorAdaptor>(rol_vector);
307 *vector_ptr += *(vector_adaptor.getVector());
312 template <
typename VectorType>
315 const ROL::Vector<value_type> &rol_vector)
317 Assert(this->dimension() == rol_vector.dimension(),
320 const VectorAdaptor &vector_adaptor =
321 Teuchos::dyn_cast<const VectorAdaptor>(rol_vector);
323 vector_ptr->add(alpha, *(vector_adaptor.getVector()));
328 template <
typename VectorType>
332 Assert(vector_ptr->size() < std::numeric_limits<int>::max(),
333 ExcMessage(
"The size of the vector being used is greater than "
334 "largest value of type int."));
335 return static_cast<int>(vector_ptr->size());
340 template <
typename VectorType>
344 (*vector_ptr) *= alpha;
349 template <
typename VectorType>
350 typename VectorType::value_type
352 const ROL::Vector<value_type> &rol_vector)
const
354 Assert(this->dimension() == rol_vector.dimension(),
357 const VectorAdaptor &vector_adaptor =
358 Teuchos::dyn_cast<const VectorAdaptor>(rol_vector);
360 return (*vector_ptr) * (*vector_adaptor.getVector());
365 template <
typename VectorType>
366 typename VectorType::value_type
369 return vector_ptr->l2_norm();
374 template <
typename VectorType>
375 Teuchos::RCP<ROL::Vector<typename VectorType::value_type>>
378 Teuchos::RCP<VectorType> vec_ptr = Teuchos::rcp(
new VectorType);
379 (*vec_ptr) = (*vector_ptr);
381 return Teuchos::rcp(
new VectorAdaptor(vec_ptr));
386 template <
typename VectorType>
387 Teuchos::RCP<ROL::Vector<typename VectorType::value_type>>
390 Teuchos::RCP<VectorType> vec_ptr = Teuchos::rcp(
new VectorType);
393 vec_ptr->reinit(*vector_ptr,
false);
395 if (vector_ptr->locally_owned_elements().is_element(i))
396 vec_ptr->operator[](i) = 1.;
398 if (vec_ptr->has_ghost_elements())
400 vec_ptr->update_ghost_values();
407 Teuchos::RCP<VectorAdaptor>
e = Teuchos::rcp(
new VectorAdaptor(vec_ptr));
414 template <
typename VectorType>
417 const ROL::Elementwise::UnaryFunction<value_type> &f)
419 const typename VectorType::iterator vend = vector_ptr->end();
421 for (
typename VectorType::iterator iterator = vector_ptr->begin();
424 *iterator = f.apply(*iterator);
426 if (vector_ptr->has_ghost_elements())
428 vector_ptr->update_ghost_values();
438 template <
typename VectorType>
441 const ROL::Elementwise::BinaryFunction<value_type> &f,
442 const ROL::Vector<value_type> & rol_vector)
444 Assert(this->dimension() == rol_vector.dimension(),
447 const VectorAdaptor &vector_adaptor =
448 Teuchos::dyn_cast<const VectorAdaptor>(rol_vector);
450 const VectorType &given_rol_vector = *(vector_adaptor.getVector());
452 const typename VectorType::iterator vend = vector_ptr->end();
453 const typename VectorType::const_iterator rolend = given_rol_vector.end();
455 typename VectorType::const_iterator r_iterator = given_rol_vector.begin();
456 for (
typename VectorType::iterator l_iterator = vector_ptr->begin();
457 l_iterator != vend && r_iterator != rolend;
458 l_iterator++, r_iterator++)
459 *l_iterator = f.apply(*l_iterator, *r_iterator);
461 if (vector_ptr->has_ghost_elements())
463 vector_ptr->update_ghost_values();
473 template <
typename VectorType>
474 typename VectorType::value_type
476 const ROL::Elementwise::ReductionOp<value_type> &r)
const
478 typename VectorType::value_type result = r.initialValue();
480 const typename VectorType::iterator vend = vector_ptr->end();
482 for (
typename VectorType::iterator iterator = vector_ptr->begin();
485 r.reduce(*iterator, result);
493 template <
typename VectorType>
497 vector_ptr->print(outStream);
void applyBinary(const ROL::Elementwise::BinaryFunction< value_type > &f, const ROL::Vector< value_type > &rol_vector)
Teuchos::RCP< ROL::Vector< value_type > > clone() const
void scale(const value_type alpha)
value_type dot(const ROL::Vector< value_type > &rol_vector) const
void applyUnary(const ROL::Elementwise::UnaryFunction< value_type > &f)
Teuchos::RCP< VectorType > vector_ptr
Teuchos::RCP< VectorType > getVector()
typename VectorType::value_type value_type
VectorAdaptor(const Teuchos::RCP< VectorType > &vector_ptr)
typename VectorType::real_type real_type
void print(std::ostream &outStream) const
typename VectorType::size_type size_type
void set(const ROL::Vector< value_type > &rol_vector)
Teuchos::RCP< const VectorType > getVector() const
void plus(const ROL::Vector< value_type > &rol_vector)
Teuchos::RCP< ROL::Vector< value_type > > basis(const int i) const
void axpy(const value_type alpha, const ROL::Vector< value_type > &rol_vector)
value_type reduce(const ROL::Elementwise::ReductionOp< value_type > &r) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)