queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::TeuchosVector Class Reference

Class for vector operations using Teuchos (Trilinos). More...

#include <TeuchosVector.h>

Inheritance diagram for QUESO::TeuchosVector:
QUESO::Vector

Public Member Functions

Constructor/Destructor methods.
 TeuchosVector (const BaseEnvironment &env, const Map &map)
 Shaped constructor: creates an empty vector of size given by Map& map. More...
 
 TeuchosVector (const BaseEnvironment &env, const Map &map, double value)
 Shaped constructor: creates an vector of values value and of size given by Map& map. More...
 
 TeuchosVector (const BaseEnvironment &env, double d1, double d2, const Map &map)
 Shaped constructor: creates an vector of size given by Map& map and of values given by an average involving d1, d2 and the vector size. More...
 
 TeuchosVector (const TeuchosVector &v, double d1, double d2)
 Shaped constructor: creates an vector of size given by vector v and of values given by an average involving d1, d2 and vector size. More...
 
 TeuchosVector (const TeuchosVector &y)
 Copy constructor. More...
 
 ~TeuchosVector ()
 Destructor. More...
 
Set methods.
TeuchosVectoroperator= (double a)
 Set all values in the vector to a constant value. More...
 
TeuchosVectoroperator= (const TeuchosVector &rhs)
 Copies values from one vector to another. More...
 
TeuchosVectoroperator*= (double a)
 Stores in this vector the coordinate-wise multiplication of this and a. More...
 
TeuchosVectoroperator/= (double a)
 Stores in this vector the coordinate-wise division of this by a. More...
 
TeuchosVectoroperator*= (const TeuchosVector &rhs)
 Stores in this vector the coordinate-wise multiplication of this with rhs. More...
 
TeuchosVectoroperator/= (const TeuchosVector &rhs)
 Stores in this vector the coordinate-wise division of this by rhs. More...
 
TeuchosVectoroperator+= (const TeuchosVector &rhs)
 Stores in this vector the coordinate-wise addition of this and rhs. More...
 
TeuchosVectoroperator-= (const TeuchosVector &rhs)
 Stores in this vector the coordinate-wise subtraction of this and rhs. More...
 
void cwSet (double value)
 Component-wise sets all values to this with value. More...
 
void cwSet (unsigned int initialPos, const TeuchosVector &vec)
 Component-wise sets all values of this with vector vec, starting at position initialPos. More...
 
void cwExtract (unsigned int initialPos, TeuchosVector &vec) const
 Component-wise extracts all values of this with vector vec, starting at position initialPos. More...
 
void cwInvert ()
 This function inverts component-wise the element values of this. More...
 
void cwSqrt ()
 Component-wise sets the square-root of this. More...
 
void cwSetConcatenated (const TeuchosVector &v1, const TeuchosVector &v2)
 This function concatenates vectors v1 and v2 into this vector. More...
 
void cwSetGaussian (double mean, double stdDev)
 This function sets component-wise Gaussian random variates, with mean mean and standard deviation stdDev. More...
 
void cwSetGaussian (const TeuchosVector &meanVec, const TeuchosVector &stdDevVec)
 This function sets component-wise Gaussian random variates, with vectors for mean and standard deviation. More...
 
void cwSetUniform (const TeuchosVector &lowerBoundVec, const TeuchosVector &upperBoundVec)
 This function sets component-wise a number uniformly distributed in the range of elements of [lowerBoundVec,upperBoundVec]. More...
 
void cwSetBeta (const TeuchosVector &alpha, const TeuchosVector &beta)
 This function sets component-wise random variates from the Beta distribution, with vector parameters alpha and beta. More...
 
void cwSetGamma (const TeuchosVector &a, const TeuchosVector &b)
 This function sets component-wise random variates from the Inverse Gamma distribution, with parameters given by vectors a and b. More...
 
void cwSetInverseGamma (const TeuchosVector &a, const TeuchosVector &b)
 This function sets component-wise random variates from the Inverse Gamma distribution, with parameters given by vectors a and b. More...
 
Accessor methods.
double & operator[] (unsigned int i)
 Element access method (non-const). More...
 
const double & operator[] (unsigned int i) const
 Element access method (const). More...
 
Attribute methods.
unsigned int sizeLocal () const
 Returns the length of this vector. More...
 
unsigned int sizeGlobal () const
 Returns the global length of this vector. More...
 
double * values ()
 
double getMaxValue () const
 Returns the maximum value in the this vector. More...
 
double getMinValue () const
 Returns the minimum value in the this vector. More...
 
int getMaxValueIndex () const
 This function returns the index of the maximum value in the vector this. More...
 
int getMinValueIndex () const
 This function returns the index of the minimum value in the vector this. More...
 
void getMaxValueAndIndex (double &value, int &index)
 This function returns maximum value in the vector this and its the index. More...
 
void getMinValueAndIndex (double &value, int &index)
 This function returns minimum value in the vector this and its the index. More...
 
Norm methods
double norm2Sq () const
 Returns the norm of the vector, as the square root of 2-norm of this vector. More...
 
double norm2 () const
 Returns the 2-norm (Euclidean norm) of the vector. More...
 
double norm1 () const
 Returns the 1-norm of the vector. More...
 
double normInf () const
 Returns the infinity-norm (maximum norm) of the vector. More...
 
Comparison methods.
bool atLeastOneComponentSmallerThan (const TeuchosVector &rhs) const
 This function returns true if at least one component of this is smaller than the respective component of rhs. More...
 
bool atLeastOneComponentBiggerThan (const TeuchosVector &rhs) const
 This function returns true if at least one component of this is bigger than the respective component of rhs. More...
 
bool atLeastOneComponentSmallerOrEqualThan (const TeuchosVector &rhs) const
 This function returns true if at least one component of this is smaller than or equal to the respective component of rhs. More...
 
bool atLeastOneComponentBiggerOrEqualThan (const TeuchosVector &rhs) const
 This function returns true if at least one component of this is bigger than or equal to the respective component of rhs. More...
 
Miscellaneous methods.
TeuchosVector abs () const
 This function returns absolute value of all elements in this. More...
 
void copy_to_std_vector (std::vector< double > &vec)
 Copies the values of this vector (a TeuchosVector) to a std::vector structure. More...
 
void copy_from_std_vector (const std::vector< double > vec)
 Copies the values of std::vector structure to this vector (a TeuchosVector). More...
 
void sort ()
 This function sorts the elements of the vector this in ascending numerical order. More...
 
double sumOfComponents () const
 Returns the sum of the components of the vector. More...
 
void mpiBcast (int srcRank, const MpiComm &bcastComm)
 Broadcasts a message from the process with srcRank root to all other processes of the group. More...
 
void mpiAllReduce (RawType_MPI_Op mpiOperation, const MpiComm &opComm, TeuchosVector &resultVec) const
 Combines values from all processes and distributes the result back to all processes. More...
 
void mpiAllQuantile (double probability, const MpiComm &opComm, TeuchosVector &resultVec) const
 Gathers values from a group of processes and returns all quantiles. More...
 
void matlabLinearInterpExtrap (const TeuchosVector &xVec, const TeuchosVector &yVec, const TeuchosVector &xiVec)
 Reproduces MATLAB linear inter/extra-polation. More...
 
void matlabDiff (unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, TeuchosVector &outputVec) const
 
I/O methods.
void print (std::ostream &os) const
 Print method. Defines the behavior of the std::ostream << operator inherited from the Object class. More...
 
void subReadContents (const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds)
 
void subWriteContents (const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
 
- Public Member Functions inherited from QUESO::Vector
 Vector (const BaseEnvironment &env, const Map &map)
 Shaped Constructor. More...
 
virtual ~Vector ()
 Virtual Destructor. More...
 
const BaseEnvironmentenv () const
 
const Mapmap () const
 
unsigned int numOfProcsForStorage () const
 
void setPrintHorizontally (bool value) const
 Determines whether vector should be printed horizontally. More...
 
bool getPrintHorizontally () const
 Checks if vector is printed horizontally. More...
 
void setPrintScientific (bool value) const
 Determines whether vector should be printed in Scientific Notation. More...
 
bool getPrintScientific () const
 Checks if the vector should be printed in Scientific Notation. More...
 

Private Member Functions

 TeuchosVector ()
 Default Constructor. More...
 
void copy (const TeuchosVector &src)
 This function copies the elements of the vector src into this. More...
 

Private Attributes

Teuchos::SerialDenseVector
< int, double > 
m_vec
 Teuchos vector. More...
 

Additional Inherited Members

- Protected Member Functions inherited from QUESO::Vector
virtual void base_copy (const Vector &src)
 Copies base data from vector src to this vector. More...
 
- Protected Attributes inherited from QUESO::Vector
const BaseEnvironmentm_env
 Environment variable. More...
 
const Map m_map
 Mapping variable. More...
 
const Mapm_map
 Mapping variable. More...
 
bool m_printHorizontally
 Flag for either or not print this matrix horizontally. More...
 
bool m_printScientific
 Flag for either or not print this matrix in scientific notation. More...
 

Detailed Description

Class for vector operations using Teuchos (Trilinos).

This class creates and provides basic support for vectors of templated type as a specialization of Vector using Teuchos vectors (from Trilinos), which are defined by an encapsulated Teuchos::SerialDenseVector structure.

Definition at line 55 of file TeuchosVector.h.

Constructor & Destructor Documentation

QUESO::TeuchosVector::TeuchosVector ( const BaseEnvironment env,
const Map map 
)

Shaped constructor: creates an empty vector of size given by Map& map.

Definition at line 38 of file TeuchosVector.C.

References QUESO::Vector::m_map, m_vec, QUESO::Map::NumGlobalElements(), QUESO::Map::NumMyElements(), and QUESO::queso_require_equal_to_msg.

39  :
40  Vector(env,map)
41 {
42  m_vec.size(map.NumGlobalElements());
43 
44  queso_require_equal_to_msg(m_vec.length(), map.NumMyElements(), "incompatible local vec size");
45 
46  queso_require_equal_to_msg(m_vec.length(), map.NumGlobalElements(), "incompatible global vec size");
47 
48  queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size");
49 
50  //std::cout << "In TeuchosVector::constructor(env,map)"
51  // << "\n m_vec.length() = " << m_vec.length()
52  // << "\n map.NumGlobalElements() = " << map.NumGlobalElements()
53  // << "\n map.NumMyElements() = " << map.NumMyElements()
54  // << std::endl;
55 }
const Map m_map
Mapping variable.
Definition: Vector.h:122
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
const BaseEnvironment & env() const
Definition: Vector.C:54
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
const Map & map() const
Definition: Vector.C:61
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
Vector()
Default Constructor.
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
QUESO::TeuchosVector::TeuchosVector ( const BaseEnvironment env,
const Map map,
double  value 
)

Shaped constructor: creates an vector of values value and of size given by Map& map.

Definition at line 58 of file TeuchosVector.C.

References QUESO::Vector::m_map, m_vec, QUESO::Map::NumGlobalElements(), QUESO::Map::NumMyElements(), and QUESO::queso_require_equal_to_msg.

59  :
60  Vector(env,map)
61 {
62  m_vec.size(map.NumGlobalElements());
63  m_vec = value;
64 
65  queso_require_equal_to_msg(m_vec.length(), map.NumMyElements(), "incompatible local vec size");
66 
67  queso_require_equal_to_msg(m_vec.length(), map.NumGlobalElements(), "incompatible global vec size");
68 
69  queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size");
70 }
const Map m_map
Mapping variable.
Definition: Vector.h:122
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
const BaseEnvironment & env() const
Definition: Vector.C:54
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
const Map & map() const
Definition: Vector.C:61
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
Vector()
Default Constructor.
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
QUESO::TeuchosVector::TeuchosVector ( const BaseEnvironment env,
double  d1,
double  d2,
const Map map 
)

Shaped constructor: creates an vector of size given by Map& map and of values given by an average involving d1, d2 and the vector size.

Definition at line 73 of file TeuchosVector.C.

References QUESO::Vector::m_map, m_vec, QUESO::Map::NumGlobalElements(), QUESO::Map::NumMyElements(), and QUESO::queso_require_equal_to_msg.

74  :
75  Vector(env,map)
76  {
77  m_vec.size(map.NumGlobalElements());
78 
79  queso_require_equal_to_msg(m_vec.length(), map.NumMyElements(), "incompatible local vec size");
80 
81  queso_require_equal_to_msg(m_vec.length(), map.NumGlobalElements(), "incompatible global vec size");
82 
83  for (int i = 0; i < m_vec.length(); ++i) {
84  double alpha = (double) i / ((double) m_vec.length() - 1.);
85  (*this)[i] = (1.-alpha)*d1 + alpha*d2;
86  }
87 
88  queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size");
89 }
const Map m_map
Mapping variable.
Definition: Vector.h:122
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
const BaseEnvironment & env() const
Definition: Vector.C:54
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
const Map & map() const
Definition: Vector.C:61
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
Vector()
Default Constructor.
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
QUESO::TeuchosVector::TeuchosVector ( const TeuchosVector v,
double  d1,
double  d2 
)

Shaped constructor: creates an vector of size given by vector v and of values given by an average involving d1, d2 and vector size.

Definition at line 92 of file TeuchosVector.C.

References QUESO::Vector::m_map, m_vec, QUESO::Vector::map(), QUESO::Map::NumGlobalElements(), QUESO::Map::NumMyElements(), QUESO::queso_require_equal_to_msg, and sizeLocal().

93  :
94  Vector(v.env(),v.map())
95 {
96  m_vec.size(v.sizeLocal());
97 
98  queso_require_equal_to_msg(m_vec.length(), v.map().NumMyElements(), "incompatible local vec size");
99 
100  queso_require_equal_to_msg(m_vec.length(), v.map().NumGlobalElements(), "incompatible global vec size");
101 
102  for ( int i = 0; i < m_vec.length(); ++i) {
103  double alpha = (double) i / ((double) m_vec.length() - 1.);
104  (*this)[i] = (1.-alpha)*d1 + alpha*d2;
105  }
106 
107  queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size");
108 }
const Map m_map
Mapping variable.
Definition: Vector.h:122
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
Vector()
Default Constructor.
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
QUESO::TeuchosVector::TeuchosVector ( const TeuchosVector y)

Copy constructor.

Definition at line 111 of file TeuchosVector.C.

References copy(), QUESO::Vector::m_map, m_vec, QUESO::Vector::map(), QUESO::Map::NumGlobalElements(), QUESO::Map::NumMyElements(), QUESO::queso_require_equal_to_msg, and sizeLocal().

112  :
113  Vector(v.env(),v.map())
114  {
115  m_vec.size(v.sizeLocal());
116 
117  queso_require_equal_to_msg(m_vec.length(), v.map().NumMyElements(), "incompatible local vec size");
118 
119  queso_require_equal_to_msg(m_vec.length(), v.map().NumGlobalElements(), "incompatible global vec size");
120  this->copy(v);
121 
122  queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size");
123 }
const Map m_map
Mapping variable.
Definition: Vector.h:122
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
void copy(const TeuchosVector &src)
This function copies the elements of the vector src into this.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
Vector()
Default Constructor.
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
QUESO::TeuchosVector::~TeuchosVector ( )

Destructor.

Definition at line 127 of file TeuchosVector.C.

128 {
129 };
QUESO::TeuchosVector::TeuchosVector ( )
private

Default Constructor.

Creates an empty vector of no length.

Member Function Documentation

TeuchosVector QUESO::TeuchosVector::abs ( ) const

This function returns absolute value of all elements in this.

Definition at line 650 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

651 {
652  TeuchosVector abs_of_this_vec( *this );
653 
654  unsigned int size = abs_of_this_vec.sizeLocal();
655 
656  for( unsigned int i = 0; i < size; ++i )
657  {
658  abs_of_this_vec[i] = std::fabs( (*this)[i] );
659  }
660 
661  return abs_of_this_vec;
662 
663 }
TeuchosVector()
Default Constructor.
bool QUESO::TeuchosVector::atLeastOneComponentBiggerOrEqualThan ( const TeuchosVector rhs) const

This function returns true if at least one component of this is bigger than or equal to the respective component of rhs.

Definition at line 454 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, QUESO::size, and sizeLocal().

455 {
456  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
457 
458  bool result = false;
459  unsigned int i = 0;
460  unsigned int size = this->sizeLocal();
461  while ((i < size) && (result == false)) {
462  result = ( (*this)[i] >= rhs[i] ); // prudencio 2012-02-06
463  i++;
464  };
465 
466  return result;
467 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
bool QUESO::TeuchosVector::atLeastOneComponentBiggerThan ( const TeuchosVector rhs) const

This function returns true if at least one component of this is bigger than the respective component of rhs.

Definition at line 420 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, QUESO::size, and sizeLocal().

421 {
422  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
423 
424  bool result = false;
425  unsigned int i = 0;
426  unsigned int size = this->sizeLocal();
427  while ((i < size) && (result == false)) {
428  result = ( (*this)[i] > rhs[i] );
429  i++;
430  };
431 
432  return result;
433 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
bool QUESO::TeuchosVector::atLeastOneComponentSmallerOrEqualThan ( const TeuchosVector rhs) const

This function returns true if at least one component of this is smaller than or equal to the respective component of rhs.

Definition at line 437 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, QUESO::size, and sizeLocal().

438 {
439  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
440 
441  bool result = false;
442  unsigned int i = 0;
443  unsigned int size = this->sizeLocal();
444  while ((i < size) && (result == false)) {
445  result = ( (*this)[i] <= rhs[i] ); // prudencio 2012-02-06
446  i++;
447  };
448 
449  return result;
450 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
bool QUESO::TeuchosVector::atLeastOneComponentSmallerThan ( const TeuchosVector rhs) const

This function returns true if at least one component of this is smaller than the respective component of rhs.

Definition at line 403 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, QUESO::size, and sizeLocal().

404 {
405  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
406 
407  bool result = false;
408  unsigned int i = 0;
409  unsigned int size = this->sizeLocal();
410  while ((i < size) && (result == false)) {
411  result = ( (*this)[i] < rhs[i] );
412  i++;
413  };
414 
415  return result;
416 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void QUESO::TeuchosVector::copy ( const TeuchosVector src)
private

This function copies the elements of the vector src into this.

Definition at line 1149 of file TeuchosVector.C.

References QUESO::Vector::base_copy(), m_vec, and sizeLocal().

Referenced by TeuchosVector().

1150 {
1151  this->Vector::base_copy(rhs);
1152 
1153  unsigned int size1 = m_vec.length();
1154  unsigned int size2 = rhs.sizeLocal();
1155 
1156  if (size1==size2){
1157  for (unsigned int i=0;i<size1;i++){
1158  m_vec[i]=rhs[i];
1159  }
1160  }
1161  return;
1162 }
virtual void base_copy(const Vector &src)
Copies base data from vector src to this vector.
Definition: Vector.C:101
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
void QUESO::TeuchosVector::copy_from_std_vector ( const std::vector< double >  vec)

Copies the values of std::vector structure to this vector (a TeuchosVector).

With this method, after a std::vector is sorted, it may be copied to a TeuchosVector.

Definition at line 680 of file TeuchosVector.C.

References m_vec, QUESO::queso_require_equal_to_msg, and sizeLocal().

681 {
682  unsigned int size1 = vec.size(), size2= this->sizeLocal();
683 
684  queso_require_equal_to_msg(size1, size2, "vectors have different sizes");
685 
686  for (unsigned int i = 0; i < size1; ++i)
687  m_vec[i] = vec[i];
688 
689  return;
690 }
unsigned int sizeLocal() const
Returns the length of this vector.
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void QUESO::TeuchosVector::copy_to_std_vector ( std::vector< double > &  vec)

Copies the values of this vector (a TeuchosVector) to a std::vector structure.

With this method, the std::vector copy of the TeuchosVector may be sorted using std::sort.

Definition at line 667 of file TeuchosVector.C.

References m_vec, QUESO::size, and sizeLocal().

668 {
669  unsigned int size = this->sizeLocal();
670  vec.resize(size);
671 
672  for (unsigned int i = 0; i < size; ++i)
673  vec[i] = m_vec[i];
674 
675  return;
676 }
unsigned int sizeLocal() const
Returns the length of this vector.
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
void QUESO::TeuchosVector::cwExtract ( unsigned int  initialPos,
TeuchosVector vec 
) const

Component-wise extracts all values of this with vector vec, starting at position initialPos.

Definition at line 496 of file TeuchosVector.C.

References sizeLocal().

497 {
498  queso_require_less_msg(initialPos, this->sizeLocal(), "invalid initialPos");
499 
500  queso_require_less_equal_msg((initialPos +vec.sizeLocal()), this->sizeLocal(), "invalid vec.sizeLocal()");
501 
502  for (unsigned int i = 0; i < vec.sizeLocal(); ++i) {
503  vec[i] = (*this)[initialPos+i];
504  }
505 
506  return;
507 }
unsigned int sizeLocal() const
Returns the length of this vector.
void QUESO::TeuchosVector::cwInvert ( )
virtual

This function inverts component-wise the element values of this.

Implements QUESO::Vector.

Definition at line 510 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

Referenced by QUESO::operator/().

511 {
512  unsigned int size = this->sizeLocal();
513  for (unsigned int i = 0; i < size; ++i) {
514  (*this)[i] = 1./(*this)[i];
515  }
516 
517  return;
518 }
unsigned int sizeLocal() const
Returns the length of this vector.
void QUESO::TeuchosVector::cwSet ( double  value)
virtual

Component-wise sets all values to this with value.

Implements QUESO::Vector.

Definition at line 472 of file TeuchosVector.C.

Referenced by QUESO::TeuchosMatrix::inverse().

473 {
474  (*this)=value;
475 
476  return;
477 }
void QUESO::TeuchosVector::cwSet ( unsigned int  initialPos,
const TeuchosVector vec 
)

Component-wise sets all values of this with vector vec, starting at position initialPos.

Definition at line 480 of file TeuchosVector.C.

References sizeLocal().

481 {
482  queso_require_less_msg(initialPos, this->sizeLocal(), "invalid initialPos");
483 
484  queso_require_less_equal_msg((initialPos +vec.sizeLocal()), this->sizeLocal(), "invalid vec.sizeLocal()");
485 
486  for (unsigned int i = 0; i < vec.sizeLocal(); ++i) {
487  (*this)[initialPos+i] = vec[i];
488  }
489 
490  return;
491 }
unsigned int sizeLocal() const
Returns the length of this vector.
void QUESO::TeuchosVector::cwSetBeta ( const TeuchosVector alpha,
const TeuchosVector beta 
)

This function sets component-wise random variates from the Beta distribution, with vector parameters alpha and beta.

Definition at line 591 of file TeuchosVector.C.

References QUESO::RngBase::betaSample(), QUESO::BaseEnvironment::displayVerbosity(), QUESO::BaseEnvironment::fullRank(), QUESO::Vector::m_env, QUESO::queso_require_equal_to_msg, QUESO::BaseEnvironment::rngObject(), sizeLocal(), and QUESO::BaseEnvironment::subDisplayFile().

592 {
593  queso_require_equal_to_msg(this->sizeLocal(), alpha.sizeLocal(), "incompatible alpha size");
594 
595  queso_require_equal_to_msg(this->sizeLocal(), beta.sizeLocal(), "incompatible beta size");
596 
597  for (unsigned int i = 0; i < this->sizeLocal(); ++i)
598  {
599  (*this)[i] = m_env.rngObject()->betaSample(alpha[i],beta[i]);
600 
601  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99))
602  {
603  *m_env.subDisplayFile() << "In TeuchosVector::cwSetBeta()"
604  << ": fullRank " << m_env.fullRank()
605  << ", i = " << i
606  << ", alpha[i] = " << alpha[i]
607  << ", beta[i] = " << beta[i]
608  << ", sample = " << (*this)[i]
609  << std::endl;
610  }
611  }
612  return;
613 };
unsigned int sizeLocal() const
Returns the length of this vector.
virtual double betaSample(double alpha, double beta) const =0
Samples a value from a Beta distribution.
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
void QUESO::TeuchosVector::cwSetConcatenated ( const TeuchosVector v1,
const TeuchosVector v2 
)

This function concatenates vectors v1 and v2 into this vector.

Definition at line 533 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

534 {
535  queso_require_equal_to_msg(this->sizeLocal(), v1.sizeLocal() + v2.sizeLocal(), "incompatible vector sizes");
536 
537 // if ( this->sizeLocal() != v1.sizeLocal() + v2.sizeLocal() ) {
538 // std::cout << "ERROR in TeuchosVector:: cwSetConcatenated ---> the vectors' sizes are not compatible.\n";
539 // cout << " in TeuchosVector:: cwSetConcatenated ---> resizing resulting vector... new size = "
540 // << v1.sizeLocal()+v1.sizeLocal() <<endl;
541 //
542 // m_vec.resize(v1.sizeLocal()+v1.sizeLocal());
543 // }
544 
545  for (unsigned int i = 0; i < v1.sizeLocal(); ++i) {
546  (*this)[i] = v1[i];
547  }
548 
549  for (unsigned int i = 0; i < v2.sizeLocal(); ++i) {
550  (*this)[v1.sizeLocal()+i] = v2[i];
551  }
552 
553  return;
554 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void QUESO::TeuchosVector::cwSetGamma ( const TeuchosVector a,
const TeuchosVector b 
)

This function sets component-wise random variates from the Inverse Gamma distribution, with parameters given by vectors a and b.

Definition at line 617 of file TeuchosVector.C.

References QUESO::RngBase::gammaSample(), QUESO::Vector::m_env, QUESO::queso_require_equal_to_msg, QUESO::BaseEnvironment::rngObject(), and sizeLocal().

618 {
619  queso_require_equal_to_msg(this->sizeLocal(), aVec.sizeLocal(), "incompatible a size");
620 
621  queso_require_equal_to_msg(this->sizeLocal(), bVec.sizeLocal(), "incompatible b size");
622 
623  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
624  (*this)[i] = m_env.rngObject()->gammaSample(aVec[i],bVec[i]);
625  }
626  return;
627 }
unsigned int sizeLocal() const
Returns the length of this vector.
virtual double gammaSample(double a, double b) const =0
Samples a value from a Gamma distribution.
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void QUESO::TeuchosVector::cwSetGaussian ( double  mean,
double  stdDev 
)
virtual

This function sets component-wise Gaussian random variates, with mean mean and standard deviation stdDev.

Implements QUESO::Vector.

Definition at line 558 of file TeuchosVector.C.

References QUESO::RngBase::gaussianSample(), QUESO::Vector::m_env, QUESO::BaseEnvironment::rngObject(), and sizeLocal().

559 {
560  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
561  (*this)[i] = mean + m_env.rngObject()->gaussianSample(stdDev);
562  }
563  return;
564 };
virtual double gaussianSample(double stdDev) const =0
Samples a value from a Gaussian distribution with standard deviation given by stdDev.
unsigned int sizeLocal() const
Returns the length of this vector.
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
void QUESO::TeuchosVector::cwSetGaussian ( const TeuchosVector meanVec,
const TeuchosVector stdDevVec 
)

This function sets component-wise Gaussian random variates, with vectors for mean and standard deviation.

Definition at line 568 of file TeuchosVector.C.

References QUESO::RngBase::gaussianSample(), QUESO::Vector::m_env, QUESO::BaseEnvironment::rngObject(), and sizeLocal().

569 {
570  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
571  (*this)[i] = meanVec[i] + m_env.rngObject()->gaussianSample(stdDevVec[i]);
572  }
573  return;
574 };
virtual double gaussianSample(double stdDev) const =0
Samples a value from a Gaussian distribution with standard deviation given by stdDev.
unsigned int sizeLocal() const
Returns the length of this vector.
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
void QUESO::TeuchosVector::cwSetInverseGamma ( const TeuchosVector a,
const TeuchosVector b 
)

This function sets component-wise random variates from the Inverse Gamma distribution, with parameters given by vectors a and b.

Definition at line 633 of file TeuchosVector.C.

References QUESO::RngBase::gammaSample(), QUESO::Vector::m_env, QUESO::queso_require_equal_to_msg, QUESO::BaseEnvironment::rngObject(), and sizeLocal().

634 {
635  queso_require_equal_to_msg(this->sizeLocal(), alpha.sizeLocal(), "incompatible alpha size");
636 
637  queso_require_equal_to_msg(this->sizeLocal(), beta.sizeLocal(), "incompatible beta size");
638 
639  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
640  (*this)[i] = 1./m_env.rngObject()->gammaSample(alpha[i],1./beta[i]);
641  }
642  return;
643 }
unsigned int sizeLocal() const
Returns the length of this vector.
virtual double gammaSample(double a, double b) const =0
Samples a value from a Gamma distribution.
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void QUESO::TeuchosVector::cwSetUniform ( const TeuchosVector lowerBoundVec,
const TeuchosVector upperBoundVec 
)

This function sets component-wise a number uniformly distributed in the range of elements of [lowerBoundVec,upperBoundVec].

Definition at line 580 of file TeuchosVector.C.

References QUESO::Vector::m_env, QUESO::BaseEnvironment::rngObject(), sizeLocal(), and QUESO::RngBase::uniformSample().

581 {
582  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
583  (*this)[i] = aVec[i] + (bVec[i]-aVec[i])*m_env.rngObject()->uniformSample();
584  }
585  return;
586 }
unsigned int sizeLocal() const
Returns the length of this vector.
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
virtual double uniformSample() const =0
Samples a value from a uniform distribution.
void QUESO::TeuchosVector::cwSqrt ( )

Component-wise sets the square-root of this.

Definition at line 521 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

522 {
523  unsigned int size = this->sizeLocal();
524  for (unsigned int i = 0; i < size; ++i) {
525  (*this)[i] = sqrt((*this)[i]);
526  }
527 
528  return;
529 }
unsigned int sizeLocal() const
Returns the length of this vector.
double QUESO::TeuchosVector::getMaxValue ( ) const

Returns the maximum value in the this vector.

Definition at line 273 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

274 {
275  const unsigned int size = this->sizeLocal();
276  std::vector<double> aux;
277 
278  for (unsigned int i=0; i<size; i++ ) {
279  aux.push_back((*this)[i]) ;
280  }
281 
282  return *max_element (aux.begin(),aux.end());
283 }
unsigned int sizeLocal() const
Returns the length of this vector.
void QUESO::TeuchosVector::getMaxValueAndIndex ( double &  value,
int &  index 
)

This function returns maximum value in the vector this and its the index.

Definition at line 326 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

327 {
328  const unsigned int size = this->sizeLocal();
329  std::vector<double> vect;
330 
331  for (unsigned int i=0; i<size; i++ ) {
332  vect.push_back((*this)[i]) ;
333  }
334  std::vector<double>::iterator iter_max = max_element(vect.begin(), vect.end());
335 
336  max_value = *iter_max;
337  max_value_index = distance(vect.begin(), iter_max);
338 
339  return;
340 }
unsigned int sizeLocal() const
Returns the length of this vector.
int QUESO::TeuchosVector::getMaxValueIndex ( ) const

This function returns the index of the maximum value in the vector this.

Definition at line 300 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

301 {
302  const unsigned int size = this->sizeLocal();
303  std::vector<double> vect;
304 
305  for (unsigned int i=0; i<size; i++ ) {
306  vect.push_back((*this)[i]) ;
307  }
308  std::vector<double>::iterator iter_max = max_element(vect.begin(), vect.end());
309  return distance(vect.begin(), iter_max);
310 }
unsigned int sizeLocal() const
Returns the length of this vector.
double QUESO::TeuchosVector::getMinValue ( ) const

Returns the minimum value in the this vector.

Definition at line 286 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

287 {
288  const unsigned int size = this->sizeLocal();
289  std::vector<double> aux;
290 
291  for (unsigned int i=0; i<size; i++ ) {
292  aux.push_back((*this)[i]) ;
293  }
294 
295  return *min_element (aux.begin(),aux.end());
296 
297 }
unsigned int sizeLocal() const
Returns the length of this vector.
void QUESO::TeuchosVector::getMinValueAndIndex ( double &  value,
int &  index 
)

This function returns minimum value in the vector this and its the index.

Definition at line 343 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

344 {
345  const unsigned int size = this->sizeLocal();
346  std::vector<double> vect;
347 
348  for (unsigned int i=0; i<size; i++ ) {
349  vect.push_back((*this)[i]) ;
350  }
351  std::vector<double>::iterator iter_min = min_element(vect.begin(), vect.end());
352 
353  min_value = *iter_min;
354  min_value_index = distance(vect.begin(), iter_min);
355 
356  return;
357 }
unsigned int sizeLocal() const
Returns the length of this vector.
int QUESO::TeuchosVector::getMinValueIndex ( ) const

This function returns the index of the minimum value in the vector this.

Definition at line 313 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

314 {
315  const unsigned int size = this->sizeLocal();
316  std::vector<double> vect;
317 
318  for (unsigned int i=0; i<size; i++ ) {
319  vect.push_back((*this)[i]) ;
320  }
321  std::vector<double>::iterator iter_min = min_element(vect.begin(), vect.end());
322  return distance(vect.begin(), iter_min);
323 }
unsigned int sizeLocal() const
Returns the length of this vector.
void QUESO::TeuchosVector::matlabDiff ( unsigned int  firstPositionToStoreDiff,
double  valueForRemainderPosition,
TeuchosVector outputVec 
) const

Definition at line 903 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, QUESO::size, and sizeLocal().

907 {
908  unsigned int size = this->sizeLocal();
909 
910  queso_require_less_equal_msg(firstPositionToStoreDiff, 1, "invalid firstPositionToStoreDiff");
911 
912  queso_require_equal_to_msg(size, outputVec.sizeLocal(), "invalid size of outputVecs");
913 
914  for (unsigned int i = 0; i < (size-1); ++i) {
915  outputVec[firstPositionToStoreDiff+i] = (*this)[i+1]-(*this)[i];
916  }
917  if (firstPositionToStoreDiff == 0) {
918  outputVec[size-1] = valueForRemainderPosition;
919  }
920  else {
921  outputVec[0] = valueForRemainderPosition;
922  }
923 
924  return;
925 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void QUESO::TeuchosVector::matlabLinearInterpExtrap ( const TeuchosVector xVec,
const TeuchosVector yVec,
const TeuchosVector xiVec 
)

Reproduces MATLAB linear inter/extra-polation.

yiVec.matlabLinearInterpExtrap(xVec,yVec,xiVec) interpolates/extrapolates to find yiVec, the values of the underlying function yVec at the points in the vector xiVec. Thus, yVec and xVec must have the same size; and yiVec and xiVec must have the same size.

Definition at line 834 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

Referenced by QUESO::TeuchosMatrix::matlabLinearInterpExtrap().

838 {
839  queso_require_greater_msg(x1Vec.sizeLocal(), 1, "invalid 'x1' size");
840 
841  queso_require_equal_to_msg(x1Vec.sizeLocal(), y1Vec.sizeLocal(), "invalid 'x1' and 'y1' sizes");
842 
843  queso_require_equal_to_msg(x2Vec.sizeLocal(), this->sizeLocal(), "invalid 'x2' and 'this' sizes");
844 
845  for (unsigned int i = 1; i < x1Vec.sizeLocal(); ++i) { // Yes, '1'
846  queso_require_greater_msg(x1Vec[i], x1Vec[i-1], "invalid 'x1' values");
847  }
848 
849  for (unsigned int id2 = 0; id2 < x2Vec.sizeLocal(); ++id2) {
850  double x2 = x2Vec[id2];
851  unsigned int id1 = 0;
852  bool found1 = false;
853  for (id1 = 0; id1 < x1Vec.sizeLocal(); ++id1) {
854  if (x2 <= x1Vec[id1]) {
855  found1 = true;
856  break;
857  }
858  }
859  bool makeLinearModel = false;
860  double xa = 0.;
861  double xb = 0.;
862  double ya = 0.;
863  double yb = 0.;
864  if (x2 == x1Vec[id1]) {
865  (*this)[id2] = y1Vec[id1];
866  }
867  else if (x2 < x1Vec[0]) {
868  // Extrapolation case
869  makeLinearModel = true;
870  xa = x1Vec[0];
871  xb = x1Vec[1];
872  ya = y1Vec[0];
873  yb = y1Vec[1];
874  }
875  else if (found1 == true) {
876  // Interpolation case
877  makeLinearModel = true;
878  xa = x1Vec[id1-1];
879  xb = x1Vec[id1];
880  ya = y1Vec[id1-1];
881  yb = y1Vec[id1];
882  }
883  else {
884  // Extrapolation case
885  makeLinearModel = true;
886  xa = x1Vec[x1Vec.sizeLocal()-2];
887  xb = x1Vec[x1Vec.sizeLocal()-1];
888  ya = y1Vec[x1Vec.sizeLocal()-2];
889  yb = y1Vec[x1Vec.sizeLocal()-1];
890  }
891 
892  if (makeLinearModel) {
893  double rate = (yb-ya)/(xb-xa);
894  (*this)[id2] = ya + (x2-xa)*rate;
895  }
896  }
897  return;
898 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void QUESO::TeuchosVector::mpiAllQuantile ( double  probability,
const MpiComm opComm,
TeuchosVector resultVec 
) const

Gathers values from a group of processes and returns all quantiles.

Definition at line 800 of file TeuchosVector.C.

References QUESO::MpiComm::Bcast(), QUESO::MpiComm::Gather(), QUESO::MpiComm::MyPID(), QUESO::MpiComm::NumProc(), QUESO::queso_require_equal_to_msg, QUESO::size, and sizeLocal().

801 {
802  // Filter out those nodes that should not participate
803  if (opComm.MyPID() < 0) return;
804 
805  queso_require_msg(!((probability < 0.) || (1. < probability)), "invalid input");
806 
807  unsigned int size = this->sizeLocal();
808  queso_require_equal_to_msg(size, resultVec.sizeLocal(), "different vector sizes");
809 
810  for (unsigned int i = 0; i < size; ++i) {
811  double auxDouble = (int) (*this)[i];
812  std::vector<double> vecOfDoubles(opComm.NumProc(),0.);
813  opComm.Gather<double>(&auxDouble, 1, &vecOfDoubles[0], (int) 1, 0,
814  "TeuchosVector::mpiAllQuantile()",
815  "failed MPI.Gather()");
816 
817  std::sort(vecOfDoubles.begin(), vecOfDoubles.end());
818 
819  double result = vecOfDoubles[(unsigned int)( probability*((double)(vecOfDoubles.size()-1)) )];
820 
821  opComm.Bcast((void *) &result, (int) 1, RawValue_MPI_DOUBLE, 0,
822  "TeuchosVector::mpiAllQuantile()",
823  "failed MPI.Bcast()");
824 
825  resultVec[i] = result;
826  }
827 
828  return;
829 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void QUESO::TeuchosVector::mpiAllReduce ( RawType_MPI_Op  mpiOperation,
const MpiComm opComm,
TeuchosVector resultVec 
) const

Combines values from all processes and distributes the result back to all processes.

Definition at line 777 of file TeuchosVector.C.

References QUESO::MpiComm::Allreduce(), QUESO::MpiComm::MyPID(), QUESO::queso_require_equal_to_msg, QUESO::size, and sizeLocal().

778 {
779  // Filter out those nodes that should not participate
780  if (opComm.MyPID() < 0) return;
781 
782  unsigned int size = this->sizeLocal();
783  queso_require_equal_to_msg(size, resultVec.sizeLocal(), "different vector sizes");
784 
785  for (unsigned int i = 0; i < size; ++i) {
786  double srcValue = (*this)[i];
787  double resultValue = 0.;
788  opComm.Allreduce<double>(&srcValue, &resultValue, (int) 1, mpiOperation,
789  "TeuchosVector::mpiAllReduce()",
790  "failed MPI.Allreduce()");
791  resultVec[i] = resultValue;
792  }
793 
794  return;
795 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void QUESO::TeuchosVector::mpiBcast ( int  srcRank,
const MpiComm bcastComm 
)

Broadcasts a message from the process with srcRank root to all other processes of the group.

Definition at line 720 of file TeuchosVector.C.

References QUESO::MpiComm::Allreduce(), QUESO::MpiComm::Barrier(), QUESO::MpiComm::Bcast(), QUESO::MpiComm::MyPID(), QUESO::MpiComm::NumProc(), QUESO::queso_require_equal_to_msg, and sizeLocal().

721 {
722  // Filter out those nodes that should not participate
723  if (bcastComm.MyPID() < 0) return;
724 
725  // Check 'srcRank'
726  queso_require_msg(!((srcRank < 0) || (srcRank >= bcastComm.NumProc())), "invalud srcRank");
727 
728  // Check number of participant nodes
729  double localNumNodes = 1.;
730  double totalNumNodes = 0.;
731  bcastComm.Allreduce<double>(&localNumNodes, &totalNumNodes, (int) 1, RawValue_MPI_SUM,
732  "TeuchosVector::mpiBcast()",
733  "failed MPI.Allreduce() for numNodes");
734  queso_require_equal_to_msg(((int) totalNumNodes), bcastComm.NumProc(), "inconsistent numNodes");
735 
736  // Check that all participant nodes have the same vector size
737  double localVectorSize = this->sizeLocal();
738  double sumOfVectorSizes = 0.;
739  bcastComm.Allreduce<double>(&localVectorSize, &sumOfVectorSizes, (int) 1, RawValue_MPI_SUM,
740  "TeuchosVector::mpiBcast()",
741  "failed MPI.Allreduce() for vectorSize");
742 
743  if ( ((unsigned int) sumOfVectorSizes) != ((unsigned int)(totalNumNodes*localVectorSize)) ) {
744  std::cerr << "rank " << bcastComm.MyPID()
745  << ": sumOfVectorSizes = " << sumOfVectorSizes
746  << ", totalNumNodes = " << totalNumNodes
747  << ", localVectorSize = " << localVectorSize
748  << std::endl;
749  }
750  bcastComm.Barrier();
751  queso_require_equal_to_msg(((unsigned int) sumOfVectorSizes), ((unsigned int)(totalNumNodes*localVectorSize)), "inconsistent vectorSize");
752 
753  // Ok, bcast data
754  std::vector<double> dataBuffer((unsigned int) localVectorSize, 0.);
755  if (bcastComm.MyPID() == srcRank) {
756  for (unsigned int i = 0; i < dataBuffer.size(); ++i) {
757  dataBuffer[i] = (*this)[i];
758  }
759  }
760 
761  bcastComm.Bcast((void *) &dataBuffer[0], (int) localVectorSize, RawValue_MPI_DOUBLE, srcRank,
762  "TeuchosVector::mpiBcast()",
763  "failed MPI.Bcast()");
764 
765  if (bcastComm.MyPID() != srcRank) {
766  for (unsigned int i = 0; i < dataBuffer.size(); ++i) {
767  (*this)[i] = dataBuffer[i];
768  }
769  }
770 
771  return;
772 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
double QUESO::TeuchosVector::norm1 ( ) const

Returns the 1-norm of the vector.

Definition at line 373 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

374 {
375  double result = 0.;
376 
377  unsigned int size = this->sizeLocal();
378  for (unsigned int i = 0; i < size; ++i) {
379  result += fabs((*this)[i]);
380  }
381 
382  return result;
383 }
unsigned int sizeLocal() const
Returns the length of this vector.
double QUESO::TeuchosVector::norm2 ( ) const

Returns the 2-norm (Euclidean norm) of the vector.

Definition at line 367 of file TeuchosVector.C.

References norm2Sq().

Referenced by QUESO::TeuchosMatrix::invertMultiply().

368 {
369  return std::sqrt(this->norm2Sq());
370 }
double norm2Sq() const
Returns the norm of the vector, as the square root of 2-norm of this vector.
double QUESO::TeuchosVector::norm2Sq ( ) const

Returns the norm of the vector, as the square root of 2-norm of this vector.

Definition at line 361 of file TeuchosVector.C.

References m_vec.

Referenced by norm2().

362 {
363  return (m_vec).dot(m_vec );
364 }
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
double QUESO::TeuchosVector::normInf ( ) const

Returns the infinity-norm (maximum norm) of the vector.

Definition at line 386 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

387 {
388  double result = 0.;
389 
390  unsigned int size = this->sizeLocal();
391  double aux = 0.;
392  for (unsigned int i = 0; i < size; ++i) {
393  aux = fabs((*this)[i]);
394  if (aux > result) result = aux;
395  }
396 
397  return result;
398 }
unsigned int sizeLocal() const
Returns the length of this vector.
TeuchosVector & QUESO::TeuchosVector::operator*= ( double  a)

Stores in this vector the coordinate-wise multiplication of this and a.

Definition at line 158 of file TeuchosVector.C.

References m_vec.

159 {
160  m_vec.scale(a); //Scale this vector by a; *this = a*this.
161  return *this;
162 }
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
TeuchosVector & QUESO::TeuchosVector::operator*= ( const TeuchosVector rhs)

Stores in this vector the coordinate-wise multiplication of this with rhs.

Definition at line 172 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

173 {
174  unsigned int size1 = this->sizeLocal();
175  unsigned int size2 = rhs.sizeLocal();
176  queso_require_equal_to_msg(size1, size2, "the vectors do NOT have the same size.\n");
177  if (size1==size2){
178  for (unsigned int i = 0; i < size1; ++i) {
179  (*this)[i] *= rhs[i];
180  }
181  }
182  return *this;
183 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
TeuchosVector & QUESO::TeuchosVector::operator+= ( const TeuchosVector rhs)

Stores in this vector the coordinate-wise addition of this and rhs.

Definition at line 201 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

202 {
203  unsigned int size1 = this->sizeLocal();
204  unsigned int size2 = rhs.sizeLocal();
205 
206  queso_require_equal_to_msg(size1, size2, "the vectors do NOT have the same size.\n");
207 
208  if (size1==size2){
209  for (unsigned int i = 0; i < size1; ++i) {
210  (*this)[i] += rhs[i];
211  }
212  }
213  return *this;
214 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
TeuchosVector & QUESO::TeuchosVector::operator-= ( const TeuchosVector rhs)

Stores in this vector the coordinate-wise subtraction of this and rhs.

Definition at line 217 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

218 {
219  unsigned int size1 = this->sizeLocal();
220  unsigned int size2 = rhs.sizeLocal();
221 
222  queso_require_equal_to_msg(size1, size2, "the vectors do NOT have the same size.\n");
223 
224  if (size1==size2){
225  for (unsigned int i = 0; i < size1; ++i) {
226  (*this)[i] -= rhs[i];
227  }
228  }
229 
230  return *this;
231 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
TeuchosVector & QUESO::TeuchosVector::operator/= ( double  a)

Stores in this vector the coordinate-wise division of this by a.

Definition at line 165 of file TeuchosVector.C.

166 {
167  (*this) *= (1.0/a);
168  return *this;
169 }
TeuchosVector & QUESO::TeuchosVector::operator/= ( const TeuchosVector rhs)

Stores in this vector the coordinate-wise division of this by rhs.

Definition at line 186 of file TeuchosVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

187 {
188  unsigned int size1 = this->sizeLocal();
189  unsigned int size2 = rhs.sizeLocal();
190 
191  queso_require_equal_to_msg(size1, size2, "the vectors do NOT have the same size.\n");
192  if (size1==size2){
193  for (unsigned int i = 0; i < size1; ++i) {
194  (*this)[i] /= rhs[i];
195  }
196  }
197  return *this;
198 }
unsigned int sizeLocal() const
Returns the length of this vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
TeuchosVector & QUESO::TeuchosVector::operator= ( double  a)

Set all values in the vector to a constant value.

Definition at line 134 of file TeuchosVector.C.

References m_vec.

135 {
136  m_vec.putScalar(a);
137  return *this;
138 }
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
TeuchosVector & QUESO::TeuchosVector::operator= ( const TeuchosVector rhs)

Copies values from one vector to another.

Definition at line 141 of file TeuchosVector.C.

References m_vec, QUESO::queso_require_equal_to_msg, and sizeLocal().

142 {
143  unsigned int size1 = m_vec.length();
144  unsigned int size2 = rhs.sizeLocal();
145 
146  queso_require_equal_to_msg(size1, size2, "the vectors do NOT have the same size.\n");
147 
148  if (size1==size2){
149  for (unsigned int i=0;i<size1;i++){
150  m_vec[i]=rhs[i];
151  }
152  }
153 
154  return *this;
155 }
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
double & QUESO::TeuchosVector::operator[] ( unsigned int  i)

Element access method (non-const).

Definition at line 236 of file TeuchosVector.C.

References m_vec.

237 {
238  return m_vec[i];
239 }
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
const double & QUESO::TeuchosVector::operator[] ( unsigned int  i) const

Element access method (const).

Definition at line 242 of file TeuchosVector.C.

References m_vec.

243 {
244  return m_vec[i];
245 }
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
void QUESO::TeuchosVector::print ( std::ostream &  os) const
virtual

Print method. Defines the behavior of the std::ostream << operator inherited from the Object class.

Implements QUESO::Vector.

Definition at line 930 of file TeuchosVector.C.

References QUESO::Vector::m_printHorizontally, QUESO::Vector::m_printScientific, QUESO::size, and sizeLocal().

Referenced by QUESO::operator<<().

931 {
932  unsigned int size = this->sizeLocal();
933 
934  std::ostream::fmtflags curr_fmt = os.flags();
935 
936  if (m_printScientific) {
937  unsigned int savedPrecision = os.precision();
938  os.precision(16);
939 
940  if (m_printHorizontally) {
941  for (unsigned int i = 0; i < size; ++i) {
942  os << std::scientific << (*this)[i]
943  << " ";
944  }
945  }
946  else {
947  for (unsigned int i = 0; i < size; ++i) {
948  os << std::scientific << (*this)[i]
949  << std::endl;
950  }
951  }
952 
953  os.precision(savedPrecision);
954  }
955  else {
956  if (m_printHorizontally) {
957  for (unsigned int i = 0; i < size; ++i) {
958  os << std::dec << (*this)[i]
959  << " ";
960  }
961  }
962  else {
963  for (unsigned int i = 0; i < size; ++i) {
964  os << std::dec << (*this)[i]
965  << std::endl;
966  }
967  }
968  }
969 
970  os.flags(curr_fmt);
971  return;
972 }
unsigned int sizeLocal() const
Returns the length of this vector.
bool m_printHorizontally
Flag for either or not print this matrix horizontally.
Definition: Vector.h:130
bool m_printScientific
Flag for either or not print this matrix in scientific notation.
Definition: Vector.h:133
unsigned int QUESO::TeuchosVector::sizeGlobal ( ) const
virtual

Returns the global length of this vector.

Implements QUESO::Vector.

Definition at line 257 of file TeuchosVector.C.

References QUESO::Vector::m_map, m_vec, QUESO::Map::NumGlobalElements(), and QUESO::queso_require_equal_to_msg.

258 {
259  queso_require_equal_to_msg(m_vec.length(), (int) m_map.NumGlobalElements(), "incompatible vec size");
260  return m_vec.length();
261 }
const Map m_map
Mapping variable.
Definition: Vector.h:122
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
unsigned int QUESO::TeuchosVector::sizeLocal ( ) const
virtual

Returns the length of this vector.

Implements QUESO::Vector.

Definition at line 249 of file TeuchosVector.C.

References QUESO::Vector::m_map, m_vec, QUESO::Map::NumMyElements(), and QUESO::queso_require_equal_to_msg.

Referenced by abs(), atLeastOneComponentBiggerOrEqualThan(), atLeastOneComponentBiggerThan(), atLeastOneComponentSmallerOrEqualThan(), atLeastOneComponentSmallerThan(), copy(), copy_from_std_vector(), copy_to_std_vector(), cwExtract(), cwInvert(), cwSet(), cwSetBeta(), cwSetConcatenated(), cwSetGamma(), cwSetGaussian(), cwSetInverseGamma(), cwSetUniform(), cwSqrt(), QUESO::TeuchosMatrix::eigen(), QUESO::TeuchosMatrix::fillWithTensorProduct(), QUESO::TeuchosMatrix::getColumn(), getMaxValue(), getMaxValueAndIndex(), getMaxValueIndex(), getMinValue(), getMinValueAndIndex(), getMinValueIndex(), QUESO::TeuchosMatrix::getRow(), QUESO::TeuchosMatrix::invertMultiply(), QUESO::TeuchosMatrix::invertMultiplyForceLU(), QUESO::TeuchosMatrix::largestEigen(), QUESO::leftDiagScaling(), matlabDiff(), matlabLinearInterpExtrap(), QUESO::TeuchosMatrix::matlabLinearInterpExtrap(), QUESO::matrixProduct(), mpiAllQuantile(), mpiAllReduce(), mpiBcast(), QUESO::TeuchosMatrix::multiply(), norm1(), normInf(), operator*=(), operator+=(), operator-=(), operator/=(), operator=(), QUESO::operator==(), print(), QUESO::TeuchosMatrix::rank(), QUESO::rightDiagScaling(), QUESO::scalarProduct(), QUESO::TeuchosMatrix::setColumn(), QUESO::TeuchosMatrix::setRow(), QUESO::TeuchosMatrix::smallestEigen(), subReadContents(), subWriteContents(), sumOfComponents(), QUESO::TeuchosMatrix::svd(), QUESO::TeuchosMatrix::svdSolve(), QUESO::TeuchosMatrix::TeuchosMatrix(), and TeuchosVector().

250 {
251  queso_require_equal_to_msg(m_vec.length(), (int) m_map.NumMyElements(), "incompatible vec size");
252 
253  return m_vec.length();
254 }
const Map m_map
Mapping variable.
Definition: Vector.h:122
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
void QUESO::TeuchosVector::sort ( )
virtual

This function sorts the elements of the vector this in ascending numerical order.

It copies this vector to a std::vector and uses the std::sort functionality to sort it.

Implements QUESO::Vector.

Definition at line 693 of file TeuchosVector.C.

694 {
695  std::vector<double> vec;
696 
697  (*this).copy_to_std_vector(vec);
698 
699  // using default comparison (operator <):
700  std::sort (vec.begin(), vec.end());
701 
702  (*this).copy_from_std_vector(vec);
703 };
void QUESO::TeuchosVector::subReadContents ( const std::string &  fileName,
const std::string &  fileType,
const std::set< unsigned int > &  allowedSubEnvIds 
)

Definition at line 976 of file TeuchosVector.C.

References QUESO::BaseEnvironment::closeFile(), QUESO::BaseEnvironment::fullRank(), QUESO::FilePtrSetStruct::ifsVar, QUESO::Vector::m_env, QUESO::Vector::numOfProcsForStorage(), QUESO::BaseEnvironment::openInputFile(), QUESO::queso_require_equal_to_msg, sizeLocal(), QUESO::BaseEnvironment::subDisplayFile(), and QUESO::BaseEnvironment::subRank().

980 {
981  queso_require_greater_equal_msg(m_env.subRank(), 0, "unexpected subRank");
982 
983  queso_require_less_equal_msg(this->numOfProcsForStorage(), 1, "implemented just for sequential vectors for now");
984 
985  FilePtrSetStruct filePtrSet;
986  if (m_env.openInputFile(fileName,
987  fileType, // "m or hdf"
988  allowedSubEnvIds,
989  filePtrSet)) {
990  double subReadSize = this->sizeLocal();
991 
992  // In the logic below, the id of a line' begins with value 0 (zero)
993  unsigned int idOfMyFirstLine = 1;
994  unsigned int idOfMyLastLine = this->sizeLocal();
995  unsigned int numParams = 1; // Yes, just '1'
996 
997  // Read number of chain positions in the file by taking care of the first line,
998  // which resembles something like 'variable_name = zeros(n_positions,m_params);'
999  std::string tmpString;
1000 
1001  // Read 'variable name' string
1002  *filePtrSet.ifsVar >> tmpString;
1003  //std::cout << "Just read '" << tmpString << "'" << std::endl;
1004 
1005  // Read '=' sign
1006  *filePtrSet.ifsVar >> tmpString;
1007  //std::cout << "Just read '" << tmpString << "'" << std::endl;
1008  queso_require_equal_to_msg(tmpString, "=", "string should be the '=' sign");
1009 
1010  // Read 'zeros(n_positions,n_params)' string
1011  *filePtrSet.ifsVar >> tmpString;
1012  //std::cout << "Just read '" << tmpString << "'" << std::endl;
1013  unsigned int posInTmpString = 6;
1014 
1015  // Isolate 'n_positions' in a string
1016  char nPositionsString[tmpString.size()-posInTmpString+1];
1017  unsigned int posInPositionsString = 0;
1018  do {
1019  queso_require_less_msg(posInTmpString, tmpString.size(), "symbol ',' not found in first line of file");
1020  nPositionsString[posInPositionsString++] = tmpString[posInTmpString++];
1021  } while (tmpString[posInTmpString] != ',');
1022  nPositionsString[posInPositionsString] = '\0';
1023 
1024  // Isolate 'n_params' in a string
1025  posInTmpString++; // Avoid reading ',' char
1026  char nParamsString[tmpString.size()-posInTmpString+1];
1027  unsigned int posInParamsString = 0;
1028  do {
1029  queso_require_less_msg(posInTmpString, tmpString.size(), "symbol ')' not found in first line of file");
1030  nParamsString[posInParamsString++] = tmpString[posInTmpString++];
1031  } while (tmpString[posInTmpString] != ')');
1032  nParamsString[posInParamsString] = '\0';
1033 
1034  // Convert 'n_positions' and 'n_params' strings to numbers
1035  unsigned int sizeOfVecInFile = (unsigned int) strtod(nPositionsString,NULL);
1036  unsigned int numParamsInFile = (unsigned int) strtod(nParamsString, NULL);
1037  if (m_env.subDisplayFile()) {
1038  *m_env.subDisplayFile() << "In TeuchosVector::subReadContents()"
1039  << ": fullRank " << m_env.fullRank()
1040  << ", sizeOfVecInFile = " << sizeOfVecInFile
1041  << ", numParamsInFile = " << numParamsInFile
1042  << ", this->sizeLocal() = " << this->sizeLocal()
1043  << std::endl;
1044  }
1045 
1046  // Check if [size of vec in file] >= [requested sub vec size]
1047  queso_require_greater_equal_msg(sizeOfVecInFile, subReadSize, "size of vec in file is not big enough");
1048 
1049  // Check if [num params in file] == [num params in current vec]
1050  queso_require_equal_to_msg(numParamsInFile, numParams, "number of parameters of vec in file is different than number of parameters in this vec object");
1051 
1052  // Code common to any core in a communicator
1053  unsigned int maxCharsPerLine = 64*numParams; // Up to about 60 characters to represent each parameter value
1054 
1055  unsigned int lineId = 0;
1056  while (lineId < idOfMyFirstLine) {
1057  filePtrSet.ifsVar->ignore(maxCharsPerLine,'\n');
1058  lineId++;
1059  };
1060 
1061  if (m_env.subDisplayFile()) {
1062  *m_env.subDisplayFile() << "In TeuchosVector::subReadContents()"
1063  << ": beginning to read input actual data"
1064  << std::endl;
1065  }
1066 
1067  // Take care of initial part of the first data line,
1068  // which resembles something like 'variable_name = [value1 value2 ...'
1069  // Read 'variable name' string
1070  *filePtrSet.ifsVar >> tmpString;
1071  //std::cout << "Core 0 just read '" << tmpString << "'" << std::endl;
1072 
1073  // Read '=' sign
1074  *filePtrSet.ifsVar >> tmpString;
1075  //std::cout << "Core 0 just read '" << tmpString << "'" << std::endl;
1076  queso_require_equal_to_msg(tmpString, "=", "in core 0, string should be the '=' sign");
1077 
1078  // Take into account the ' [' portion
1079  std::streampos tmpPos = filePtrSet.ifsVar->tellg();
1080  filePtrSet.ifsVar->seekg(tmpPos+(std::streampos)2);
1081 
1082  if (m_env.subDisplayFile()) {
1083  *m_env.subDisplayFile() << "In TeuchosVector::subReadContents()"
1084  << ": beginning to read lines with numbers only"
1085  << ", lineId = " << lineId
1086  << ", idOfMyFirstLine = " << idOfMyFirstLine
1087  << ", idOfMyLastLine = " << idOfMyLastLine
1088  << std::endl;
1089  }
1090 
1091  while (lineId <= idOfMyLastLine) {
1092  *filePtrSet.ifsVar >> (*this)[lineId - idOfMyFirstLine];
1093  lineId++;
1094  };
1095 
1096  m_env.closeFile(filePtrSet,fileType);
1097  }
1098 
1099  return;
1100 }
unsigned int sizeLocal() const
Returns the length of this vector.
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1084
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
unsigned int numOfProcsForStorage() const
Definition: Vector.C:68
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
bool openInputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, FilePtrSetStruct &filePtrSet) const
Opens an input file.
Definition: Environment.C:896
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
void QUESO::TeuchosVector::subWriteContents ( const std::string &  varNamePrefix,
const std::string &  fileName,
const std::string &  fileType,
const std::set< unsigned int > &  allowedSubEnvIds 
) const

Definition at line 1104 of file TeuchosVector.C.

References QUESO::BaseEnvironment::closeFile(), QUESO::Vector::getPrintHorizontally(), QUESO::Vector::getPrintScientific(), QUESO::Vector::m_env, QUESO::Vector::numOfProcsForStorage(), QUESO::FilePtrSetStruct::ofsVar, QUESO::BaseEnvironment::openOutputFile(), QUESO::Vector::setPrintHorizontally(), QUESO::Vector::setPrintScientific(), sizeLocal(), QUESO::BaseEnvironment::subIdString(), and QUESO::BaseEnvironment::subRank().

1109 {
1110  queso_require_greater_equal_msg(m_env.subRank(), 0, "unexpected subRank");
1111 
1112  queso_require_less_equal_msg(this->numOfProcsForStorage(), 1, "implemented just for sequential vectors for now");
1113 
1114  FilePtrSetStruct filePtrSet;
1115  if (m_env.openOutputFile(fileName,
1116  fileType, // "m or hdf"
1117  allowedSubEnvIds,
1118  false,
1119  filePtrSet)) {
1120  *filePtrSet.ofsVar << varNamePrefix << "_sub" << m_env.subIdString() << " = zeros(" << this->sizeLocal()
1121  << "," << 1
1122  << ");"
1123  << std::endl;
1124  *filePtrSet.ofsVar << varNamePrefix << "_sub" << m_env.subIdString() << " = [";
1125 
1126  bool savedVectorPrintScientific = this->getPrintScientific();
1127  bool savedVectorPrintHorizontally = this->getPrintHorizontally();
1128  this->setPrintScientific (true);
1129  this->setPrintHorizontally(false);
1130  *filePtrSet.ofsVar << *this;
1131  //<< std::endl; // No need for 'endl' because horizontally = 'false'
1132  this->setPrintHorizontally(savedVectorPrintHorizontally);
1133  this->setPrintScientific (savedVectorPrintScientific);
1134 
1135  *filePtrSet.ofsVar << "];\n";
1136 
1137  m_env.closeFile(filePtrSet,fileType);
1138  }
1139 
1140  return;
1141 }
void setPrintScientific(bool value) const
Determines whether vector should be printed in Scientific Notation.
Definition: Vector.C:88
unsigned int sizeLocal() const
Returns the length of this vector.
bool getPrintHorizontally() const
Checks if vector is printed horizontally.
Definition: Vector.C:82
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1084
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
unsigned int numOfProcsForStorage() const
Definition: Vector.C:68
bool getPrintScientific() const
Checks if the vector should be printed in Scientific Notation.
Definition: Vector.C:95
void setPrintHorizontally(bool value) const
Determines whether vector should be printed horizontally.
Definition: Vector.C:75
const std::string & subIdString() const
Access to the attribute m_subIdString; which stores the string for the sub-environment, and it will be used, for instance, to create the output files for each sub-environment.
Definition: Environment.C:348
bool openOutputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, bool writeOver, FilePtrSetStruct &filePtrSet) const
Opens an output file for each sub-environment that was chosen to send data to the file...
Definition: Environment.C:521
double QUESO::TeuchosVector::sumOfComponents ( ) const

Returns the sum of the components of the vector.

Definition at line 706 of file TeuchosVector.C.

References QUESO::size, and sizeLocal().

707 {
708  double result = 0.;
709  unsigned int size = this->sizeLocal();
710  for (unsigned int i = 0; i < size; ++i) {
711  result += (*this)[i];
712  }
713 
714  return result;
715 }
unsigned int sizeLocal() const
Returns the length of this vector.
double * QUESO::TeuchosVector::values ( )

Definition at line 266 of file TeuchosVector.C.

References m_vec.

Referenced by QUESO::TeuchosMatrix::internalSvd(), and QUESO::TeuchosMatrix::svdSolve().

267 {
268  return m_vec.values();
269 };
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.

Member Data Documentation

Teuchos::SerialDenseVector<int,double> QUESO::TeuchosVector::m_vec
private

The documentation for this class was generated from the following files:

Generated on Tue Jun 5 2018 19:49:13 for queso-0.57.1 by  doxygen 1.8.5