42 #ifndef THYRA_PARAMETER_DRIVEN_MULTI_VECTOR_INPUT_HPP
43 #define THYRA_PARAMETER_DRIVEN_MULTI_VECTOR_INPUT_HPP
45 #include "Thyra_MultiVectorFileIOBase.hpp"
46 #include "Thyra_DetachedVectorView.hpp"
47 #include "Thyra_MultiVectorStdOps.hpp"
48 #include "Teuchos_ParameterListAcceptor.hpp"
49 #include "Teuchos_VerboseObject.hpp"
50 #include "Teuchos_StandardCompositionMacros.hpp"
51 #include "Teuchos_implicit_cast.hpp"
88 template<
class Scalar>
174 const std::string &mvName
219 const std::string &vName
242 std::string fileNameBase_;
247 static const std::string FileNameBase_name_;
248 static const std::string FileNameBase_default_;
250 static const std::string ExplicitArray_name_;
251 static const std::string ExplicitArray_default_;
253 static const std::string ScaleBy_name_;
254 static const double ScaleBy_default_;
256 static const std::string AddScalar_name_;
257 static const double AddScalar_default_;
266 template<
class Scalar>
270 const std::string &vName,
278 return defaultVector;
285 template<
class Scalar>
290 return fileNameBase_;
293 template<
class Scalar>
298 return explicitArray_;
301 template<
class Scalar>
312 namespace PDMVIUtilityPack {
314 template<
class Scalar>
324 for(
Ordinal i = 0; i < dVec.subDim(); ++i ) {
333 template<
class Scalar>
335 ParameterDrivenMultiVectorInput<Scalar>::FileNameBase_name_ =
"File Name Base";
336 template<
class Scalar>
338 ParameterDrivenMultiVectorInput<Scalar>::FileNameBase_default_ =
"";
340 template<
class Scalar>
342 ParameterDrivenMultiVectorInput<Scalar>::ExplicitArray_name_ =
"Explicit Array";
343 template<
class Scalar>
345 ParameterDrivenMultiVectorInput<Scalar>::ExplicitArray_default_ =
"{}";
347 template<
class Scalar>
349 ParameterDrivenMultiVectorInput<Scalar>::ScaleBy_name_ =
"Scale By";
350 template<
class Scalar>
352 ParameterDrivenMultiVectorInput<Scalar>::ScaleBy_default_ = 1.0;
354 template<
class Scalar>
356 ParameterDrivenMultiVectorInput<Scalar>::AddScalar_name_ =
"Add Scalar";
357 template<
class Scalar>
359 ParameterDrivenMultiVectorInput<Scalar>::AddScalar_default_ = 0.0;
363 template<
class Scalar>
365 :fileNameBase_(FileNameBase_default_),
366 scaleBy_(ScaleBy_default_),
367 addScalar_(AddScalar_default_)
372 template<
class Scalar>
379 paramList_ = paramList;
380 fileNameBase_ = paramList_->
get(
381 FileNameBase_name_,FileNameBase_default_ );
382 explicitArray_ = Teuchos::getArrayFromStringParameter<Scalar>(
383 *paramList_,ExplicitArray_name_
387 scaleBy_ = paramList_->get(ScaleBy_name_,ScaleBy_default_);
388 addScalar_ = paramList_->get(AddScalar_name_,AddScalar_default_);
390 paramList_->validateParameters(*getValidParameters(),0);
391 #endif // TEUCHOS_DEBUG
394 template<
class Scalar>
401 template<
class Scalar>
406 _paramList = paramList_;
407 paramList_ = Teuchos::null;
411 template<
class Scalar>
418 template<
class Scalar>
422 if(!validParamList_.get()) {
426 FileNameBase_name_,FileNameBase_default_
427 ,
"Base-name of file(s) that will be used to read in the vector.\n"
428 "If this parameter is empty \"\", no file(s) will be read.\n"
429 "Note that a MultiVectorFileIOBase object and a VectorSpaceBase object\n"
430 "must be set internally for this to work."
433 ExplicitArray_name_,ExplicitArray_default_
434 ,
"The vector specified explicitly as a string interpreted as a Teuchos::Array\n"
435 "object. If this array is set, it will override the vector specified\n"
436 "by the above \"" + FileNameBase_name_ +
"\" parameter.\n"
437 "Note that a VectorSpaceBase object\n"
438 "must be set internally for this to work."
441 ScaleBy_name_,ScaleBy_default_,
442 "A factor by which the read in vector will be scaled by."
445 AddScalar_name_, AddScalar_default_,
446 "A scalar that will added to the read in vector after it\n"
449 validParamList_ = pl;
451 return validParamList_;
456 template<
class Scalar>
458 const std::string &mvName
467 out = this->getOStream();
470 bool vectorWasRead =
false;
471 if(fileNameBase_.length()) {
472 if( out.
get() && trace )
473 *out <<
"\nReading \"" << mvName <<
"\" from the file(s) with base name \""
474 << fileNameBase_ <<
"\" ...\n";
475 fileIO().readMultiVectorFromFile(fileNameBase_,mv);
476 vectorWasRead =
true;
478 if(explicitArray_.size()) {
479 if( implicit_cast<Ordinal>(explicitArray_.size()) != vecSpc().dim() ) {
481 Teuchos::getArrayFromStringParameter<Scalar>(
482 *paramList_,ExplicitArray_name_,vecSpc().dim(),
false);
485 if( out.
get() && trace )
486 *out <<
"\nSetting \"" << mvName <<
"\" directly from the parameter array "
487 << explicitArray_ <<
" ...\n";
490 ,
"Error! We can not handle reading in multi-vectors directly from"
491 " the parameter list yet!"
493 PDMVIUtilityPack::copy(explicitArray_,&*mv->
col(0));
496 vectorWasRead =
true;
498 if( scaleBy_ != ST::one() && vectorWasRead ) {
499 if( out.
get() && trace )
500 *out <<
"\nScaling \"" << mvName <<
"\" by " << scaleBy_ <<
" ...\n";
501 Vt_S(Teuchos::ptr(mv), scaleBy_);
503 if( addScalar_ != ST::zero() && vectorWasRead ) {
504 if( out.
get() && trace )
505 *out <<
"\nAdding scalar " << addScalar_ <<
" to \"" << mvName <<
"\" ...\n";
506 Vp_S(Teuchos::ptr(mv), addScalar_);
508 return vectorWasRead;
511 template<
class Scalar>
513 const std::string &vName
518 bool vectorWasRead =
false;
519 if( fileNameBase_.length() || explicitArray_.size() ) {
521 (*v) = createMember(this->vecSpc());
522 vectorWasRead = this->readMultiVector(vName, &*(*v));
524 return vectorWasRead;
527 template<
class Scalar>
530 const std::string &vName
534 const bool vectorWasRead = readVector(vName,&v);
542 #endif // THYRA_PARAMETER_DRIVEN_MULTI_VECTOR_INPUT_HPP
bool is_null(const boost::shared_ptr< T > &p)
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Abstract interface for objects that represent a space for vectors.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
Create an explicit mutable (non-const) view of a VectorBase object.
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
Abstract strategy interface for reading and writing (multi)vector objects to and from files...
TypeTo implicit_cast(const TypeFrom &t)
Abstract interface for finite-dimensional dense vectors.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)