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>
28 # include <type_traits>
111 template <
typename VectorType>
130 "The real_type of the current VectorType is not "
131 "convertible to the value_type.");
150 Teuchos::RCP<VectorType>
156 Teuchos::RCP<const VectorType>
174 set(
const ROL::Vector<value_type> &rol_vector);
180 plus(
const ROL::Vector<value_type> &rol_vector);
187 axpy(
const value_type alpha,
const ROL::Vector<value_type> &rol_vector);
199 dot(
const ROL::Vector<value_type> &rol_vector)
const;
216 Teuchos::RCP<ROL::Vector<value_type>>
224 Teuchos::RCP<ROL::Vector<value_type>>
225 basis(
const int i)
const;
231 applyUnary(
const ROL::Elementwise::UnaryFunction<value_type> &f);
238 applyBinary(
const ROL::Elementwise::BinaryFunction<value_type> &f,
239 const ROL::Vector<value_type> & rol_vector);
246 reduce(
const ROL::Elementwise::ReductionOp<value_type> &r)
const;
252 print(std::ostream &outStream)
const;
260 template <
typename VectorType>
262 const Teuchos::RCP<VectorType> &vector_ptr)
263 : vector_ptr(vector_ptr)
268 template <
typename VectorType>
269 Teuchos::RCP<VectorType>
277 template <
typename VectorType>
278 Teuchos::RCP<const VectorType>
286 template <
typename VectorType>
290 const VectorAdaptor &vector_adaptor =
291 Teuchos::dyn_cast<const VectorAdaptor>(rol_vector);
293 (*vector_ptr) = *(vector_adaptor.getVector());
298 template <
typename VectorType>
302 Assert(this->dimension() == rol_vector.dimension(),
305 const VectorAdaptor &vector_adaptor =
306 Teuchos::dyn_cast<const VectorAdaptor>(rol_vector);
308 *vector_ptr += *(vector_adaptor.getVector());
313 template <
typename VectorType>
316 const ROL::Vector<value_type> &rol_vector)
318 Assert(this->dimension() == rol_vector.dimension(),
321 const VectorAdaptor &vector_adaptor =
322 Teuchos::dyn_cast<const VectorAdaptor>(rol_vector);
324 vector_ptr->add(alpha, *(vector_adaptor.getVector()));
329 template <
typename VectorType>
334 ExcMessage(
"The size of the vector being used is greater than "
335 "largest value of type int."));
336 return static_cast<int>(vector_ptr->size());
341 template <
typename VectorType>
345 (*vector_ptr) *= alpha;
350 template <
typename VectorType>
351 typename VectorType::value_type
353 const ROL::Vector<value_type> &rol_vector)
const
355 Assert(this->dimension() == rol_vector.dimension(),
358 const VectorAdaptor &vector_adaptor =
359 Teuchos::dyn_cast<const VectorAdaptor>(rol_vector);
361 return (*vector_ptr) * (*vector_adaptor.getVector());
366 template <
typename VectorType>
367 typename VectorType::value_type
370 return vector_ptr->l2_norm();
375 template <
typename VectorType>
376 Teuchos::RCP<ROL::Vector<typename VectorType::value_type>>
379 Teuchos::RCP<VectorType> vec_ptr = Teuchos::rcp(
new VectorType);
380 (*vec_ptr) = (*vector_ptr);
382 return Teuchos::rcp(
new VectorAdaptor(vec_ptr));
387 template <
typename VectorType>
388 Teuchos::RCP<ROL::Vector<typename VectorType::value_type>>
391 Teuchos::RCP<VectorType> vec_ptr = Teuchos::rcp(
new VectorType);
394 vec_ptr->reinit(*vector_ptr,
false);
396 if (vector_ptr->locally_owned_elements().is_element(i))
397 vec_ptr->operator[](i) = 1.;
399 if (vec_ptr->has_ghost_elements())
401 vec_ptr->update_ghost_values();
408 Teuchos::RCP<VectorAdaptor>
e = Teuchos::rcp(
new VectorAdaptor(vec_ptr));
415 template <
typename VectorType>
418 const ROL::Elementwise::UnaryFunction<value_type> &f)
420 const typename VectorType::iterator vend = vector_ptr->end();
422 for (
typename VectorType::iterator iterator = vector_ptr->begin();
425 *iterator = f.apply(*iterator);
427 if (vector_ptr->has_ghost_elements())
429 vector_ptr->update_ghost_values();
439 template <
typename VectorType>
442 const ROL::Elementwise::BinaryFunction<value_type> &f,
443 const ROL::Vector<value_type> & rol_vector)
445 Assert(this->dimension() == rol_vector.dimension(),
448 const VectorAdaptor &vector_adaptor =
449 Teuchos::dyn_cast<const VectorAdaptor>(rol_vector);
451 const VectorType &given_rol_vector = *(vector_adaptor.getVector());
453 const typename VectorType::iterator vend = vector_ptr->end();
454 const typename VectorType::const_iterator rolend = given_rol_vector.end();
456 typename VectorType::const_iterator r_iterator = given_rol_vector.begin();
457 for (
typename VectorType::iterator l_iterator = vector_ptr->begin();
458 l_iterator != vend && r_iterator != rolend;
459 l_iterator++, r_iterator++)
460 *l_iterator = f.apply(*l_iterator, *r_iterator);
462 if (vector_ptr->has_ghost_elements())
464 vector_ptr->update_ghost_values();
474 template <
typename VectorType>
475 typename VectorType::value_type
477 const ROL::Elementwise::ReductionOp<value_type> &r)
const
479 typename VectorType::value_type result = r.initialValue();
481 const typename VectorType::iterator vend = vector_ptr->end();
483 for (
typename VectorType::iterator iterator = vector_ptr->begin();
486 r.reduce(*iterator, result);
494 template <
typename VectorType>
498 vector_ptr->print(outStream);
511 #endif // DEAL_II_TRILINOS_WITH_ROL
513 #endif // dealii_optimization_rol_vector_adaptor_h