10 #ifndef THYRA_PARAMETER_DRIVEN_MULTI_VECTOR_INPUT_HPP
11 #define THYRA_PARAMETER_DRIVEN_MULTI_VECTOR_INPUT_HPP
13 #include "Thyra_MultiVectorFileIOBase.hpp"
14 #include "Thyra_DetachedVectorView.hpp"
15 #include "Thyra_MultiVectorStdOps.hpp"
16 #include "Teuchos_ParameterListAcceptor.hpp"
17 #include "Teuchos_VerboseObject.hpp"
18 #include "Teuchos_StandardCompositionMacros.hpp"
19 #include "Teuchos_implicit_cast.hpp"
56 template<
class Scalar>
142 const std::string &mvName
187 const std::string &vName
210 std::string fileNameBase_;
215 static const std::string FileNameBase_name_;
216 static const std::string FileNameBase_default_;
218 static const std::string ExplicitArray_name_;
219 static const std::string ExplicitArray_default_;
221 static const std::string ScaleBy_name_;
222 static const double ScaleBy_default_;
224 static const std::string AddScalar_name_;
225 static const double AddScalar_default_;
234 template<
class Scalar>
238 const std::string &vName,
246 return defaultVector;
253 template<
class Scalar>
258 return fileNameBase_;
261 template<
class Scalar>
266 return explicitArray_;
269 template<
class Scalar>
280 namespace PDMVIUtilityPack {
282 template<
class Scalar>
292 for(
Ordinal i = 0; i < dVec.subDim(); ++i ) {
301 template<
class Scalar>
303 ParameterDrivenMultiVectorInput<Scalar>::FileNameBase_name_ =
"File Name Base";
304 template<
class Scalar>
306 ParameterDrivenMultiVectorInput<Scalar>::FileNameBase_default_ =
"";
308 template<
class Scalar>
310 ParameterDrivenMultiVectorInput<Scalar>::ExplicitArray_name_ =
"Explicit Array";
311 template<
class Scalar>
313 ParameterDrivenMultiVectorInput<Scalar>::ExplicitArray_default_ =
"{}";
315 template<
class Scalar>
317 ParameterDrivenMultiVectorInput<Scalar>::ScaleBy_name_ =
"Scale By";
318 template<
class Scalar>
320 ParameterDrivenMultiVectorInput<Scalar>::ScaleBy_default_ = 1.0;
322 template<
class Scalar>
324 ParameterDrivenMultiVectorInput<Scalar>::AddScalar_name_ =
"Add Scalar";
325 template<
class Scalar>
327 ParameterDrivenMultiVectorInput<Scalar>::AddScalar_default_ = 0.0;
331 template<
class Scalar>
333 :fileNameBase_(FileNameBase_default_),
334 scaleBy_(ScaleBy_default_),
335 addScalar_(AddScalar_default_)
340 template<
class Scalar>
347 paramList_ = paramList;
348 fileNameBase_ = paramList_->
get(
349 FileNameBase_name_,FileNameBase_default_ );
350 explicitArray_ = Teuchos::getArrayFromStringParameter<Scalar>(
351 *paramList_,ExplicitArray_name_
355 scaleBy_ = paramList_->get(ScaleBy_name_,ScaleBy_default_);
356 addScalar_ = paramList_->get(AddScalar_name_,AddScalar_default_);
358 paramList_->validateParameters(*getValidParameters(),0);
359 #endif // TEUCHOS_DEBUG
362 template<
class Scalar>
369 template<
class Scalar>
374 _paramList = paramList_;
375 paramList_ = Teuchos::null;
379 template<
class Scalar>
386 template<
class Scalar>
390 if(!validParamList_.get()) {
394 FileNameBase_name_,FileNameBase_default_
395 ,
"Base-name of file(s) that will be used to read in the vector.\n"
396 "If this parameter is empty \"\", no file(s) will be read.\n"
397 "Note that a MultiVectorFileIOBase object and a VectorSpaceBase object\n"
398 "must be set internally for this to work."
401 ExplicitArray_name_,ExplicitArray_default_
402 ,
"The vector specified explicitly as a string interpreted as a Teuchos::Array\n"
403 "object. If this array is set, it will override the vector specified\n"
404 "by the above \"" + FileNameBase_name_ +
"\" parameter.\n"
405 "Note that a VectorSpaceBase object\n"
406 "must be set internally for this to work."
409 ScaleBy_name_,ScaleBy_default_,
410 "A factor by which the read in vector will be scaled by."
413 AddScalar_name_, AddScalar_default_,
414 "A scalar that will added to the read in vector after it\n"
417 validParamList_ = pl;
419 return validParamList_;
424 template<
class Scalar>
426 const std::string &mvName
435 out = this->getOStream();
438 bool vectorWasRead =
false;
439 if(fileNameBase_.length()) {
440 if( out.
get() && trace )
441 *out <<
"\nReading \"" << mvName <<
"\" from the file(s) with base name \""
442 << fileNameBase_ <<
"\" ...\n";
443 fileIO().readMultiVectorFromFile(fileNameBase_,mv);
444 vectorWasRead =
true;
446 if(explicitArray_.size()) {
447 if( implicit_cast<Ordinal>(explicitArray_.size()) != vecSpc().dim() ) {
449 Teuchos::getArrayFromStringParameter<Scalar>(
450 *paramList_,ExplicitArray_name_,vecSpc().dim(),
false);
453 if( out.
get() && trace )
454 *out <<
"\nSetting \"" << mvName <<
"\" directly from the parameter array "
455 << explicitArray_ <<
" ...\n";
458 ,
"Error! We can not handle reading in multi-vectors directly from"
459 " the parameter list yet!"
461 PDMVIUtilityPack::copy(explicitArray_,&*mv->
col(0));
464 vectorWasRead =
true;
466 if( scaleBy_ != ST::one() && vectorWasRead ) {
467 if( out.
get() && trace )
468 *out <<
"\nScaling \"" << mvName <<
"\" by " << scaleBy_ <<
" ...\n";
469 Vt_S(Teuchos::ptr(mv), scaleBy_);
471 if( addScalar_ != ST::zero() && vectorWasRead ) {
472 if( out.
get() && trace )
473 *out <<
"\nAdding scalar " << addScalar_ <<
" to \"" << mvName <<
"\" ...\n";
474 Vp_S(Teuchos::ptr(mv), addScalar_);
476 return vectorWasRead;
479 template<
class Scalar>
481 const std::string &vName
486 bool vectorWasRead =
false;
487 if( fileNameBase_.length() || explicitArray_.size() ) {
489 (*v) = createMember(this->vecSpc());
490 vectorWasRead = this->readMultiVector(vName, &*(*v));
492 return vectorWasRead;
495 template<
class Scalar>
498 const std::string &vName
502 const bool vectorWasRead = readVector(vName,&v);
510 #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)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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)