16 #ifndef dealii_optimization_rol_vector_adaptor_h 17 #define dealii_optimization_rol_vector_adaptor_h 19 #include <deal.II/base/config.h> 21 #ifdef DEAL_II_TRILINOS_WITH_ROL 22 #include <ROL_Vector.hpp> 24 #include <deal.II/base/exceptions.h> 25 #include <deal.II/lac/vector.h> 27 #include <type_traits> 30 DEAL_II_NAMESPACE_OPEN
114 template<
typename VectorType>
133 static_assert (std::is_convertible<real_type, value_type>::value,
134 "The real_type of the current VectorType is not " 135 "convertible to the value_type.");
156 Teuchos::RCP<VectorType> getVector ();
161 Teuchos::RCP<const VectorType> getVector ()
const;
166 int dimension ()
const;
176 void set (
const ROL::Vector<value_type> &rol_vector);
181 void plus (
const ROL::Vector<value_type> &rol_vector);
188 const ROL::Vector<value_type> &rol_vector);
198 value_type dot (
const ROL::Vector<value_type> &rol_vector)
const;
214 Teuchos::RCP<ROL::Vector<value_type>> clone()
const;
221 Teuchos::RCP<ROL::Vector<value_type>> basis (
const int i)
const;
226 void applyUnary (
const ROL::Elementwise::UnaryFunction<value_type> &f);
232 void applyBinary (
const ROL::Elementwise::BinaryFunction<value_type> &f,
233 const ROL::Vector<value_type> &rol_vector);
239 value_type reduce (
const ROL::Elementwise::ReductionOp<value_type> &r)
const;
244 void print (std::ostream &outStream)
const;
253 template<
typename VectorType>
257 vector_ptr (vector_ptr)
262 template<
typename VectorType>
263 Teuchos::RCP<VectorType>
271 template<
typename VectorType>
272 Teuchos::RCP<const VectorType>
280 template<
typename VectorType>
284 const VectorAdaptor &vector_adaptor =
285 Teuchos::dyn_cast<
const VectorAdaptor>(rol_vector);
287 (*vector_ptr) = *(vector_adaptor.getVector());
292 template<
typename VectorType>
296 Assert (this->dimension() == rol_vector.dimension(),
299 const VectorAdaptor &vector_adaptor =
300 Teuchos::dyn_cast<
const VectorAdaptor>(rol_vector);
302 *vector_ptr += *(vector_adaptor.getVector());
307 template<
typename VectorType>
310 const ROL::Vector<value_type> &rol_vector)
312 Assert (this->dimension() == rol_vector.dimension(),
315 const VectorAdaptor &vector_adaptor =
316 Teuchos::dyn_cast<
const VectorAdaptor>(rol_vector);
318 vector_ptr->add (alpha, *(vector_adaptor.getVector()));
323 template<
typename VectorType>
327 Assert (vector_ptr->size() < std::numeric_limits<int>::max(),
328 ExcMessage(
"The size of the vector being used is greater than " 329 "largest value of type int."));
330 return static_cast<int>(vector_ptr->size());
335 template<
typename VectorType>
339 (*vector_ptr) *= alpha;
344 template<
typename VectorType>
345 typename VectorType::value_type
347 dot (
const ROL::Vector<value_type> &rol_vector)
const 349 Assert (this->dimension() == rol_vector.dimension(),
352 const VectorAdaptor &vector_adaptor =
353 Teuchos::dyn_cast<
const VectorAdaptor>(rol_vector);
355 return (*vector_ptr) * (*vector_adaptor.getVector());
360 template<
typename VectorType>
361 typename VectorType::value_type
364 return vector_ptr->l2_norm();
369 template<
typename VectorType>
370 Teuchos::RCP<ROL::Vector<typename VectorType::value_type> >
373 Teuchos::RCP< VectorType> vec_ptr = Teuchos::rcp (
new VectorType);
374 (*vec_ptr) = (*vector_ptr);
376 return Teuchos::rcp (
new VectorAdaptor (vec_ptr));
381 template<
typename VectorType>
382 Teuchos::RCP<ROL::Vector<typename VectorType::value_type> >
385 Teuchos::RCP<VectorType> vec_ptr = Teuchos::rcp (
new VectorType);
388 vec_ptr->reinit(*vector_ptr,
false);
390 if (vector_ptr->locally_owned_elements().is_element(i))
391 vec_ptr->operator[](i) = 1.;
395 Teuchos::RCP<VectorAdaptor>
e = Teuchos::rcp (
new VectorAdaptor(vec_ptr));
402 template<
typename VectorType>
405 applyUnary (
const ROL::Elementwise::UnaryFunction<value_type> &f)
407 const typename VectorType::iterator vend = vector_ptr->end();
409 for (
typename VectorType::iterator
410 iterator = vector_ptr->begin();
413 *iterator = f.apply(*iterator);
420 template<
typename VectorType>
423 applyBinary (
const ROL::Elementwise::BinaryFunction<value_type> &f,
424 const ROL::Vector<value_type> &rol_vector)
426 Assert (this->dimension() == rol_vector.dimension(),
429 const VectorAdaptor &vector_adaptor =
430 Teuchos::dyn_cast<
const VectorAdaptor>(rol_vector);
432 const VectorType &given_rol_vector = *(vector_adaptor.getVector());
434 const typename VectorType::iterator vend = vector_ptr->end();
435 const typename VectorType::const_iterator rolend = given_rol_vector.end();
437 typename VectorType::const_iterator r_iterator = given_rol_vector.begin();
438 for (
typename VectorType::iterator l_iterator = vector_ptr->begin();
439 l_iterator != vend && r_iterator != rolend;
440 l_iterator++, r_iterator++)
441 *l_iterator = f.apply(*l_iterator, *r_iterator);
448 template<
typename VectorType>
449 typename VectorType::value_type
451 reduce (
const ROL::Elementwise::ReductionOp<value_type> &r)
const 453 typename VectorType::value_type result = r.initialValue();
455 const typename VectorType::iterator vend = vector_ptr->end();
457 for (
typename VectorType::iterator
458 iterator = vector_ptr->begin();
461 r.reduce(*iterator, result);
469 template<
typename VectorType>
473 vector_ptr->print(outStream);
483 DEAL_II_NAMESPACE_CLOSE
486 #endif // DEAL_II_TRILINOS_WITH_ROL 488 #endif // dealii_optimization_rol_vector_adaptor_h SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
void applyBinary(const ROL::Elementwise::BinaryFunction< value_type > &f, const ROL::Vector< value_type > &rol_vector)
Teuchos::RCP< ROL::Vector< value_type > > clone() const
Teuchos::RCP< VectorType > getVector()
void applyUnary(const ROL::Elementwise::UnaryFunction< value_type > &f)
Teuchos::RCP< VectorType > vector_ptr
typename VectorType::value_type value_type
static ::ExceptionBase & ExcMessage(std::string arg1)
void plus(const ROL::Vector< value_type > &rol_vector)
#define Assert(cond, exc)
value_type dot(const ROL::Vector< value_type > &rol_vector) const
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void print(std::ostream &outStream) const
value_type reduce(const ROL::Elementwise::ReductionOp< value_type > &r) const
Teuchos::RCP< ROL::Vector< value_type > > basis(const int i) const
typename VectorType::real_type real_type
typename VectorType::size_type size_type
void axpy(const value_type alpha, const ROL::Vector< value_type > &rol_vector)
void set(const ROL::Vector< value_type > &rol_vector)
void scale(const value_type alpha)