queso-0.57.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
QUESO::GslVector Class Reference

Class for vector operations using GSL library. More...

#include <GslVector.h>

Inheritance diagram for QUESO::GslVector:
Inheritance graph
[legend]
Collaboration diagram for QUESO::GslVector:
Collaboration graph
[legend]

Public Member Functions

void sort ()
 This function sorts the elements of the vector this in ascending numerical order. More...
 
void matlabDiff (unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, GslVector &outputVec) const
 
void matlabLinearInterpExtrap (const GslVector &x1Vec, const GslVector &y1Vec, const GslVector &x2Vec)
 
void mpiBcast (int srcRank, const MpiComm &bcastComm)
 
void mpiAllReduce (RawType_MPI_Op mpiOperation, const MpiComm &opComm, GslVector &resultVec) const
 
void mpiAllQuantile (double probability, const MpiComm &opComm, GslVector &resultVec) const
 
void subWriteContents (const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
 
void subReadContents (const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds)
 
gsl_vector * data () const
 
Constructor/Destructor methods.
 GslVector (const BaseEnvironment &env, const Map &map)
 Construct a zero vector. More...
 
 GslVector (const BaseEnvironment &env, const Map &map, double value)
 Construct a vector with all entries set to value. More...
 
 GslVector (const BaseEnvironment &env, double d1, double d2, const Map &map)
 Construct a vector linearly interpolating from d1 to d2,. More...
 
 GslVector (const GslVector &v, double start, double end)
 Construct a vector, with length the same as v, with evenly spaced numbers from start to end, inclusive. More...
 
 GslVector (const GslVector &y)
 Construct a vector equal to y. More...
 
 ~GslVector ()
 Destructor. More...
 
Set methods.
GslVectoroperator= (const GslVector &rhs)
 Copies values from vector rhs to this. More...
 
GslVectoroperator*= (double a)
 Stores in this the coordinate-wise multiplication of this and a. More...
 
GslVectoroperator/= (double a)
 Stores in this the coordinate-wise division of this by a. More...
 
GslVectoroperator*= (const GslVector &rhs)
 Stores in this the coordinate-wise multiplication of this with rhs. More...
 
GslVectoroperator/= (const GslVector &rhs)
 Stores in this the coordinate-wise division of this by rhs. More...
 
GslVectoroperator+= (const GslVector &rhs)
 Stores in this the coordinate-wise addition of this and rhs. More...
 
GslVectoroperator-= (const GslVector &rhs)
 Stores in this the coordinate-wise subtraction of this by rhs. More...
 
void cwSet (double value)
 Component-wise sets all values to this with value. 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 GslVector &meanVec, const GslVector &stdDevVec)
 This function sets component-wise Gaussian random variates, with vectors for mean and standard deviation. More...
 
void cwSetUniform (const GslVector &aVec, const GslVector &bVec)
 This function sets component-wise a number uniformly distributed in the range of elements of [aVec,bVec]. More...
 
void cwSetBeta (const GslVector &alpha, const GslVector &beta)
 This function returns a random variate from the beta distribution, with vector parameters alpha and beta. More...
 
void cwSetGamma (const GslVector &a, const GslVector &b)
 This function returns a random variate from the gamma distribution with vector parameters a and b. More...
 
void cwSetInverseGamma (const GslVector &alpha, const GslVector &beta)
 This function returns a random variate from the inverse gamma distribution with vector parameters alpha and beta. More...
 
void cwSetConcatenated (const GslVector &v1, const GslVector &v2)
 This function concatenates GslVector v1 and GslVector v2 into this. More...
 
void cwSetConcatenated (const std::vector< const GslVector * > &vecs)
 This function concatenates vectors v1 and v2 into this vector. More...
 
void cwSet (unsigned int initialPos, const GslVector &vec)
 This function sets the vector vec into this starting at position initialPos. More...
 
void cwExtract (unsigned int initialPos, GslVector &vec) const
 This function sets the values of this starting at position initialPos ans saves them in vector vec. More...
 
void cwInvert ()
 This function inverts component-wise the element values of this. More...
 
void cwSqrt ()
 This function returns component-wise the square-root of this. 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 getMaxValue () const
 Returns the maximum value in the vector this. More...
 
double getMinValue () const
 Returns minimum value in the vector this. 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...
 
GslVector abs () const
 This function returns absolute value of elements in this. More...
 
Mathematical methods.
double norm2Sq () const
 Returns the 2-norm squared 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...
 
double sumOfComponents () const
 Returns the sum of the components of the vector. More...
 
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...
 
Comparison methods.
bool atLeastOneComponentSmallerThan (const GslVector &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 GslVector &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 GslVector &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 GslVector &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...
 
- 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

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

Private Attributes

gsl_vector * m_vec
 GSL 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 GSL library.

This class creates and provides basic support for vectors of templated type as a specialization of Vector using GSL vectors, which are defined by an encapsulated gsl_vector structure.

Definition at line 49 of file GslVector.h.

Constructor & Destructor Documentation

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

Construct a zero vector.

Definition at line 34 of file GslVector.C.

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

35  :
36  Vector(env,map),
37  m_vec (gsl_vector_calloc(map.NumGlobalElements()))
38 {
39  //std::cout << "Entering GslVector::constructor(1)" << std::endl;
40 
41  queso_require_msg(m_vec, "null vector generated");
42 
43  queso_require_equal_to_msg(m_vec->size, (unsigned int) map.NumMyElements(), "incompatible local vec size");
44 
45  queso_require_equal_to_msg(m_vec->size, (unsigned int) map.NumGlobalElements(), "incompatible global vec size");
46 
47  queso_require_equal_to_msg(m_vec->size, (unsigned int) m_map.NumMyElements(), "incompatible own vec size");
48 
49  //std::cout << "In GslVector::constructor(env,map)"
50  // << "\n m_vec->size = " << m_vec->size
51  // << "\n map.NumGlobalElements() = " << map.NumGlobalElements()
52  // << "\n map.NumMyElements() = " << map.NumMyElements()
53  // << std::endl;
54 
55 }
Vector()
Default Constructor.
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
const Map & map() const
Definition: Vector.C:61
const BaseEnvironment & env() const
Definition: Vector.C:54
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
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"))
const Map m_map
Mapping variable.
Definition: Vector.h:122
QUESO::GslVector::GslVector ( const BaseEnvironment env,
const Map map,
double  value 
)

Construct a vector with all entries set to value.

Definition at line 57 of file GslVector.C.

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

58  :
59  Vector(env,map),
60  m_vec (gsl_vector_calloc(map.NumGlobalElements()))
61 {
62  //std::cout << "Entering GslVector::constructor(2)" << std::endl;
63 
64  queso_require_msg(m_vec, "null vector generated");
65 
66  queso_require_equal_to_msg(m_vec->size, (unsigned int) map.NumMyElements(), "incompatible local vec size");
67 
68  queso_require_equal_to_msg(m_vec->size, (unsigned int) map.NumGlobalElements(), "incompatible global vec size");
69 
70  this->cwSet(value);
71 
72  queso_require_equal_to_msg(m_vec->size, (unsigned int) m_map.NumMyElements(), "incompatible own vec size");
73 
74  //std::cout << "Leaving GslVector::constructor(2)" << std::endl;
75 }
Vector()
Default Constructor.
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
void cwSet(double value)
Component-wise sets all values to this with value.
Definition: GslVector.C:327
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
const Map & map() const
Definition: Vector.C:61
const BaseEnvironment & env() const
Definition: Vector.C:54
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
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"))
const Map m_map
Mapping variable.
Definition: Vector.h:122
QUESO::GslVector::GslVector ( const BaseEnvironment env,
double  d1,
double  d2,
const Map map 
)

Construct a vector linearly interpolating from d1 to d2,.

Definition at line 77 of file GslVector.C.

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

78  :
79  Vector(env,map),
80  m_vec (gsl_vector_calloc(map.NumGlobalElements()))
81 {
82  //std::cout << "Entering GslVector::constructor(3)" << std::endl;
83 
84  queso_require_msg(m_vec, "null vector generated");
85 
86  queso_require_equal_to_msg(m_vec->size, (unsigned int) map.NumMyElements(), "incompatible local vec size");
87 
88  queso_require_equal_to_msg(m_vec->size, (unsigned int) map.NumGlobalElements(), "incompatible global vec size");
89 
90  for (unsigned int i = 0; i < m_vec->size; ++i) {
91  double alpha = (double) i / ((double) m_vec->size - 1.);
92  (*this)[i] = (1.-alpha)*d1 + alpha*d2;
93  }
94 
95  queso_require_equal_to_msg(m_vec->size, (unsigned int) m_map.NumMyElements(), "incompatible own vec size");
96 
97  //std::cout << "Leaving GslVector::constructor(3)" << std::endl;
98 }
Vector()
Default Constructor.
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
const Map & map() const
Definition: Vector.C:61
const BaseEnvironment & env() const
Definition: Vector.C:54
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
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"))
const Map m_map
Mapping variable.
Definition: Vector.h:122
QUESO::GslVector::GslVector ( const GslVector v,
double  start,
double  end 
)

Construct a vector, with length the same as v, with evenly spaced numbers from start to end, inclusive.

Definition at line 100 of file GslVector.C.

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

101  :
102  Vector(v.env(),v.map()),
103  m_vec (gsl_vector_calloc(v.sizeLocal()))
104 {
105  //std::cout << "Entering GslVector::constructor(4)" << std::endl;
106 
107  queso_require_msg(m_vec, "null vector generated");
108 
109  queso_require_equal_to_msg(m_vec->size, (unsigned int) v.map().NumMyElements(), "incompatible local vec size");
110 
111  queso_require_equal_to_msg(m_vec->size, (unsigned int) v.map().NumGlobalElements(), "incompatible global vec size");
112 
113  for (unsigned int i = 0; i < m_vec->size; ++i) {
114  double alpha = (double) i / ((double) m_vec->size - 1.);
115  (*this)[i] = (1. - alpha) * start + alpha * end;
116  }
117 
118  queso_require_equal_to_msg(m_vec->size, (unsigned int) m_map.NumMyElements(), "incompatible own vec size");
119 
120  //std::cout << "Leaving GslVector::constructor(4)" << std::endl;
121 }
Vector()
Default Constructor.
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
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"))
const Map m_map
Mapping variable.
Definition: Vector.h:122
QUESO::GslVector::GslVector ( const GslVector y)

Construct a vector equal to y.

Definition at line 123 of file GslVector.C.

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

124  :
125  Vector(v.env(),v.map()),
126  m_vec (gsl_vector_calloc(v.sizeLocal()))
127 {
128  //std::cout << "Entering GslVector::constructor(5)" << std::endl;
129 
130  // prudenci 2010-06-17 mox
131  queso_require_msg(m_vec, "null vector generated");
132 
133  queso_require_equal_to_msg(m_vec->size, (unsigned int) v.map().NumMyElements(), "incompatible local vec size");
134 
135  queso_require_equal_to_msg(m_vec->size, (unsigned int) v.map().NumGlobalElements(), "incompatible global vec size");
136 
137  this->copy(v);
138 
139  queso_require_equal_to_msg(m_vec->size, (unsigned int) m_map.NumMyElements(), "incompatible own vec size");
140 
141  //std::cout << "Leaving GslVector::constructor(5)" << std::endl;
142 }
Vector()
Default Constructor.
void copy(const GslVector &src)
This function copies the elements of the vector src into this.
Definition: GslVector.C:230
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
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"))
const Map m_map
Mapping variable.
Definition: Vector.h:122
QUESO::GslVector::~GslVector ( )

Destructor.

Definition at line 144 of file GslVector.C.

References m_vec.

145 {
146  if (m_vec) gsl_vector_free(m_vec);
147 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
QUESO::GslVector::GslVector ( )
private

Default Constructor.

Creates an empty vector of no length.

Member Function Documentation

GslVector QUESO::GslVector::abs ( ) const

This function returns absolute value of elements in this.

Definition at line 1082 of file GslVector.C.

References QUESO::size, and sizeLocal().

Referenced by QUESO::GslMatrix::largestEigen(), and QUESO::GslMatrix::smallestEigen().

1083 {
1084  GslVector abs_of_this_vec( *this );
1085 
1086  unsigned int size = abs_of_this_vec.sizeLocal();
1087 
1088  for( unsigned int i = 0; i < size; ++i )
1089  {
1090  abs_of_this_vec[i] = std::fabs( (*this)[i] );
1091  }
1092 
1093  return abs_of_this_vec;
1094 }
GslVector()
Default Constructor.
bool QUESO::GslVector::atLeastOneComponentBiggerOrEqualThan ( const GslVector 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 1024 of file GslVector.C.

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

1025 {
1026  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
1027 
1028  bool result = false;
1029  unsigned int i = 0;
1030  unsigned int size = this->sizeLocal();
1031  while ((i < size) && (result == false)) {
1032  result = ( (*this)[i] >= rhs[i] ); // prudencio 2012-02-06
1033  i++;
1034  };
1035 
1036  return result;
1037 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
bool QUESO::GslVector::atLeastOneComponentBiggerThan ( const GslVector rhs) const

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

Definition at line 992 of file GslVector.C.

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

993 {
994  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
995 
996  bool result = false;
997  unsigned int i = 0;
998  unsigned int size = this->sizeLocal();
999  while ((i < size) && (result == false)) {
1000  result = ( (*this)[i] > rhs[i] );
1001  i++;
1002  };
1003 
1004  return result;
1005 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
bool QUESO::GslVector::atLeastOneComponentSmallerOrEqualThan ( const GslVector 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 1008 of file GslVector.C.

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

1009 {
1010  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
1011 
1012  bool result = false;
1013  unsigned int i = 0;
1014  unsigned int size = this->sizeLocal();
1015  while ((i < size) && (result == false)) {
1016  result = ( (*this)[i] <= rhs[i] ); // prudencio 2012-02-06
1017  i++;
1018  };
1019 
1020  return result;
1021 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
bool QUESO::GslVector::atLeastOneComponentSmallerThan ( const GslVector rhs) const

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

Definition at line 976 of file GslVector.C.

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

977 {
978  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
979 
980  bool result = false;
981  unsigned int i = 0;
982  unsigned int size = this->sizeLocal();
983  while ((i < size) && (result == false)) {
984  result = ( (*this)[i] < rhs[i] );
985  i++;
986  };
987 
988  return result;
989 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::copy ( const GslVector src)
private

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

Definition at line 230 of file GslVector.C.

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

Referenced by GslVector(), and operator=().

231 {
232  this->Vector::base_copy(src);
233  int iRC;
234  iRC = gsl_vector_memcpy(this->m_vec, src.m_vec);
235  queso_require_msg(!(iRC), "failed");
236 
237  return;
238 }
virtual void base_copy(const Vector &src)
Copies base data from vector src to this vector.
Definition: Vector.C:101
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
void QUESO::GslVector::cwExtract ( unsigned int  initialPos,
GslVector vec 
) const

This function sets the values of this starting at position initialPos ans saves them in vector vec.

Definition at line 496 of file GslVector.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.
Definition: GslVector.C:241
void QUESO::GslVector::cwInvert ( )
virtual

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

Implements QUESO::Vector.

Definition at line 510 of file GslVector.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.
Definition: GslVector.C:241
void QUESO::GslVector::cwSet ( double  value)
virtual

Component-wise sets all values to this with value.

Implements QUESO::Vector.

Definition at line 327 of file GslVector.C.

References QUESO::size, and sizeLocal().

Referenced by QUESO::GslOptimizer::GslOptimizer(), GslVector(), QUESO::GslMatrix::inverse(), and QUESO::GslOptimizer::setFstepSize().

328 {
329  unsigned int size = this->sizeLocal();
330  for (unsigned int i = 0; i < size; ++i) {
331  (*this)[i] = value;
332  }
333 
334  return;
335 }
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::cwSet ( unsigned int  initialPos,
const GslVector vec 
)

This function sets the vector vec into this starting at position initialPos.

Definition at line 482 of file GslVector.C.

References sizeLocal().

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

This function returns a random variate from the beta distribution, with vector parameters alpha and beta.

Definition at line 366 of file GslVector.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().

367 {
368  queso_require_equal_to_msg(this->sizeLocal(), alpha.sizeLocal(), "incompatible alpha size");
369 
370  queso_require_equal_to_msg(this->sizeLocal(), beta.sizeLocal(), "incompatible beta size");
371 
372  double tmpSample = 0.;
373  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
374  tmpSample = m_env.rngObject()->betaSample(alpha[i],beta[i]);
375  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
376  *m_env.subDisplayFile() << "In GslVector::cwSetBeta()"
377  << ": fullRank " << m_env.fullRank()
378  << ", i = " << i
379  << ", alpha[i] = " << alpha[i]
380  << ", beta[i] = " << beta[i]
381  << ", sample = " << tmpSample
382  << std::endl;
383  }
384  if ((alpha[i] == 1. ) &&
385  (beta [i] == 0.1)) {
386  if (tmpSample == 1.) {
387  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
388  *m_env.subDisplayFile() << "Hitting 'sampe = 1' in GslVector::cwSetBeta()"
389  << ": fullRank " << m_env.fullRank()
390  << ", i = " << i
391  << ", alpha[i] = " << alpha[i]
392  << ", beta[i] = " << beta[i]
393  << ", sample = " << tmpSample
394  << std::endl;
395  }
396 #if 1
397  std::cerr << "Hitting 'sample = 1' in GslVector::cwSetBeta()"
398  << ": fullRank " << m_env.fullRank()
399  << ", i = " << i
400  << ", alpha[i] = " << alpha[i]
401  << ", beta[i] = " << beta[i]
402  << ", sample = " << tmpSample
403  << std::endl;
404  do {
405  tmpSample = m_env.rngObject()->betaSample(alpha[i],beta[i]);
406  } while (tmpSample == 1.);
407  std::cerr << "Code was able to get 'sample != 1' in GslVector::cwSetBeta()"
408  << ": fullRank " << m_env.fullRank()
409  << ", i = " << i
410  << ", alpha[i] = " << alpha[i]
411  << ", beta[i] = " << beta[i]
412  << ", sample = " << tmpSample
413  << std::endl;
414  }
415 #endif
416  }
417  (*this)[i] = tmpSample;
418  }
419  return;
420 }
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
virtual double betaSample(double alpha, double beta) const =0
Samples a value from a Beta distribution.
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"))
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
unsigned int displayVerbosity() const
Definition: Environment.C:450
void QUESO::GslVector::cwSetConcatenated ( const GslVector v1,
const GslVector v2 
)

This function concatenates GslVector v1 and GslVector v2 into this.

Definition at line 449 of file GslVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

450 {
451  queso_require_equal_to_msg(this->sizeLocal(), v1.sizeLocal() + v2.sizeLocal(), "incompatible vector sizes");
452 
453  for (unsigned int i = 0; i < v1.sizeLocal(); ++i) {
454  (*this)[i] = v1[i];
455  }
456 
457  for (unsigned int i = 0; i < v2.sizeLocal(); ++i) {
458  (*this)[v1.sizeLocal()+i] = v2[i];
459  }
460 
461  return;
462 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::cwSetConcatenated ( const std::vector< const GslVector * > &  vecs)

This function concatenates vectors v1 and v2 into this vector.

Definition at line 465 of file GslVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

466 {
467  unsigned int cummulativeSize = 0;
468  for (unsigned int i = 0; i < vecs.size(); ++i) {
469  GslVector tmpVec(*(vecs[i]));
470  for (unsigned int j = 0; j < vecs[i]->sizeLocal(); ++j) {
471  (*this)[cummulativeSize+j] = tmpVec[j];
472  }
473  cummulativeSize += vecs[i]->sizeLocal();
474  }
475 
476  queso_require_equal_to_msg(this->sizeLocal(), cummulativeSize, "incompatible vector sizes");
477  return;
478 }
GslVector()
Default Constructor.
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::cwSetGamma ( const GslVector a,
const GslVector b 
)

This function returns a random variate from the gamma distribution with vector parameters a and b.

Definition at line 423 of file GslVector.C.

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

424 {
425  queso_require_equal_to_msg(this->sizeLocal(), a.sizeLocal(), "incompatible a size");
426 
427  queso_require_equal_to_msg(this->sizeLocal(), b.sizeLocal(), "incompatible b size");
428 
429  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
430  (*this)[i] = m_env.rngObject()->gammaSample(a[i],b[i]);
431  }
432  return;
433 }
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"))
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::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 338 of file GslVector.C.

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

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

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

Definition at line 348 of file GslVector.C.

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

349 {
350  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
351  (*this)[i] = meanVec[i] + m_env.rngObject()->gaussianSample(stdDevVec[i]);
352  }
353  return;
354 }
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
virtual double gaussianSample(double stdDev) const =0
Samples a value from a Gaussian distribution with standard deviation given by stdDev.
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::cwSetInverseGamma ( const GslVector alpha,
const GslVector beta 
)

This function returns a random variate from the inverse gamma distribution with vector parameters alpha and beta.

Definition at line 436 of file GslVector.C.

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

437 {
438  queso_require_equal_to_msg(this->sizeLocal(), alpha.sizeLocal(), "incompatible alpha size");
439 
440  queso_require_equal_to_msg(this->sizeLocal(), beta.sizeLocal(), "incompatible beta size");
441 
442  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
443  (*this)[i] = 1./m_env.rngObject()->gammaSample(alpha[i],1./beta[i]);
444  }
445  return;
446 }
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"))
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::cwSetUniform ( const GslVector aVec,
const GslVector bVec 
)

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

Definition at line 357 of file GslVector.C.

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

358 {
359  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
360  (*this)[i] = aVec[i] + (bVec[i]-aVec[i])*m_env.rngObject()->uniformSample();
361  }
362  return;
363 }
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.
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::cwSqrt ( )

This function returns component-wise the square-root of this.

Definition at line 521 of file GslVector.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.
Definition: GslVector.C:241
gsl_vector * QUESO::GslVector::data ( ) const
double QUESO::GslVector::getMaxValue ( ) const

Returns the maximum value in the vector this.

Definition at line 1040 of file GslVector.C.

References m_vec.

Referenced by getMaxValueAndIndex().

1041 {
1042  return gsl_vector_max( m_vec );
1043 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
void QUESO::GslVector::getMaxValueAndIndex ( double &  value,
int &  index 
)

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

Definition at line 1064 of file GslVector.C.

References getMaxValue(), and getMaxValueIndex().

1065 {
1066  max_value = this->getMaxValue();
1067  max_value_index = this->getMaxValueIndex();
1068 
1069  return;
1070 }
double getMaxValue() const
Returns the maximum value in the vector this.
Definition: GslVector.C:1040
int getMaxValueIndex() const
This function returns the index of the maximum value in the vector this.
Definition: GslVector.C:1052
int QUESO::GslVector::getMaxValueIndex ( ) const

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

Definition at line 1052 of file GslVector.C.

References m_vec.

Referenced by getMaxValueAndIndex().

1053 {
1054  return gsl_vector_max_index( m_vec );
1055 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
double QUESO::GslVector::getMinValue ( ) const

Returns minimum value in the vector this.

Definition at line 1046 of file GslVector.C.

References m_vec.

Referenced by getMinValueAndIndex().

1047 {
1048  return gsl_vector_min( m_vec );
1049 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
void QUESO::GslVector::getMinValueAndIndex ( double &  value,
int &  index 
)

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

Definition at line 1073 of file GslVector.C.

References getMinValue(), and getMinValueIndex().

1074 {
1075  min_value = this->getMinValue();
1076  min_value_index = this->getMinValueIndex();
1077 
1078  return;
1079 }
int getMinValueIndex() const
This function returns the index of the minimum value in the vector this.
Definition: GslVector.C:1058
double getMinValue() const
Returns minimum value in the vector this.
Definition: GslVector.C:1046
int QUESO::GslVector::getMinValueIndex ( ) const

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

Definition at line 1058 of file GslVector.C.

References m_vec.

Referenced by getMinValueAndIndex().

1059 {
1060  return gsl_vector_min_index( m_vec );
1061 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
void QUESO::GslVector::matlabDiff ( unsigned int  firstPositionToStoreDiff,
double  valueForRemainderPosition,
GslVector outputVec 
) const

Definition at line 532 of file GslVector.C.

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

536 {
537  unsigned int size = this->sizeLocal();
538 
539  queso_require_less_equal_msg(firstPositionToStoreDiff, 1, "invalid firstPositionToStoreDiff");
540 
541  queso_require_equal_to_msg(size, outputVec.sizeLocal(), "invalid size of outputVecs");
542 
543  for (unsigned int i = 0; i < (size-1); ++i) {
544  outputVec[firstPositionToStoreDiff+i] = (*this)[i+1]-(*this)[i];
545  }
546  if (firstPositionToStoreDiff == 0) {
547  outputVec[size-1] = valueForRemainderPosition;
548  }
549  else {
550  outputVec[0] = valueForRemainderPosition;
551  }
552 
553  return;
554 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::matlabLinearInterpExtrap ( const GslVector x1Vec,
const GslVector y1Vec,
const GslVector x2Vec 
)

Definition at line 557 of file GslVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

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

561 {
562  queso_require_greater_msg(x1Vec.sizeLocal(), 1, "invalid 'x1' size");
563 
564  queso_require_equal_to_msg(x1Vec.sizeLocal(), y1Vec.sizeLocal(), "invalid 'x1' and 'y1' sizes");
565 
566  queso_require_equal_to_msg(x2Vec.sizeLocal(), this->sizeLocal(), "invalid 'x2' and 'this' sizes");
567 
568  for (unsigned int i = 1; i < x1Vec.sizeLocal(); ++i) { // Yes, '1'
569  queso_require_greater_msg(x1Vec[i], x1Vec[i-1], "invalid 'x1' values");
570  }
571 
572  for (unsigned int id2 = 0; id2 < x2Vec.sizeLocal(); ++id2) {
573  double x2 = x2Vec[id2];
574  unsigned int id1 = 0;
575  bool found1 = false;
576  for (id1 = 0; id1 < x1Vec.sizeLocal(); ++id1) {
577  if (x2 <= x1Vec[id1]) {
578  found1 = true;
579  break;
580  }
581  }
582  bool makeLinearModel = false;
583  double xa = 0.;
584  double xb = 0.;
585  double ya = 0.;
586  double yb = 0.;
587  if (x2 == x1Vec[id1]) {
588  (*this)[id2] = y1Vec[id1];
589  }
590  else if (x2 < x1Vec[0]) {
591  // Extrapolation case
592  makeLinearModel = true;
593  xa = x1Vec[0];
594  xb = x1Vec[1];
595  ya = y1Vec[0];
596  yb = y1Vec[1];
597  }
598  else if (found1 == true) {
599  // Interpolation case
600  makeLinearModel = true;
601  xa = x1Vec[id1-1];
602  xb = x1Vec[id1];
603  ya = y1Vec[id1-1];
604  yb = y1Vec[id1];
605  }
606  else {
607  // Extrapolation case
608  makeLinearModel = true;
609  xa = x1Vec[x1Vec.sizeLocal()-2];
610  xb = x1Vec[x1Vec.sizeLocal()-1];
611  ya = y1Vec[x1Vec.sizeLocal()-2];
612  yb = y1Vec[x1Vec.sizeLocal()-1];
613  }
614 
615  if (makeLinearModel) {
616  double rate = (yb-ya)/(xb-xa);
617  (*this)[id2] = ya + (x2-xa)*rate;
618  }
619  }
620 
621 
622 
623  return;
624 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::mpiAllQuantile ( double  probability,
const MpiComm opComm,
GslVector resultVec 
) const

Definition at line 711 of file GslVector.C.

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

712 {
713  // Filter out those nodes that should not participate
714  if (opComm.MyPID() < 0) return;
715 
716  queso_require_msg(!((probability < 0.) || (1. < probability)), "invalid input");
717 
718  unsigned int size = this->sizeLocal();
719  queso_require_equal_to_msg(size, resultVec.sizeLocal(), "different vector sizes");
720 
721  for (unsigned int i = 0; i < size; ++i) {
722  double auxDouble = (int) (*this)[i];
723  std::vector<double> vecOfDoubles(opComm.NumProc(),0.);
724  opComm.Gather<double>(&auxDouble, 1, &vecOfDoubles[0], (int) 1, 0,
725  "GslVector::mpiAllQuantile()",
726  "failed MPI.Gather()");
727 
728  std::sort(vecOfDoubles.begin(), vecOfDoubles.end());
729 
730  double result = vecOfDoubles[(unsigned int)( probability*((double)(vecOfDoubles.size()-1)) )];
731 
732  opComm.Bcast((void *) &result, (int) 1, RawValue_MPI_DOUBLE, 0,
733  "GslVector::mpiAllQuantile()",
734  "failed MPI.Bcast()");
735 
736  resultVec[i] = result;
737  }
738 
739  return;
740 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::mpiAllReduce ( RawType_MPI_Op  mpiOperation,
const MpiComm opComm,
GslVector resultVec 
) const

Definition at line 690 of file GslVector.C.

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

691 {
692  // Filter out those nodes that should not participate
693  if (opComm.MyPID() < 0) return;
694 
695  unsigned int size = this->sizeLocal();
696  queso_require_equal_to_msg(size, resultVec.sizeLocal(), "different vector sizes");
697 
698  for (unsigned int i = 0; i < size; ++i) {
699  double srcValue = (*this)[i];
700  double resultValue = 0.;
701  opComm.Allreduce<double>(&srcValue, &resultValue, (int) 1, mpiOperation,
702  "GslVector::mpiAllReduce()",
703  "failed MPI.Allreduce()");
704  resultVec[i] = resultValue;
705  }
706 
707  return;
708 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
void QUESO::GslVector::mpiBcast ( int  srcRank,
const MpiComm bcastComm 
)

Definition at line 635 of file GslVector.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().

636 {
637  // Filter out those nodes that should not participate
638  if (bcastComm.MyPID() < 0) return;
639 
640  // Check 'srcRank'
641  queso_require_msg(!((srcRank < 0) || (srcRank >= bcastComm.NumProc())), "invalud srcRank");
642 
643  // Check number of participant nodes
644  double localNumNodes = 1.;
645  double totalNumNodes = 0.;
646  bcastComm.Allreduce<double>(&localNumNodes, &totalNumNodes, (int) 1, RawValue_MPI_SUM,
647  "GslVector::mpiBcast()",
648  "failed MPI.Allreduce() for numNodes");
649  queso_require_equal_to_msg(((int) totalNumNodes), bcastComm.NumProc(), "inconsistent numNodes");
650 
651  // Check that all participant nodes have the same vector size
652  double localVectorSize = this->sizeLocal();
653  double sumOfVectorSizes = 0.;
654  bcastComm.Allreduce<double>(&localVectorSize, &sumOfVectorSizes, (int) 1, RawValue_MPI_SUM,
655  "GslVector::mpiBcast()",
656  "failed MPI.Allreduce() for vectorSize");
657 
658  if ( ((unsigned int) sumOfVectorSizes) != ((unsigned int)(totalNumNodes*localVectorSize)) ) {
659  std::cerr << "rank " << bcastComm.MyPID()
660  << ": sumOfVectorSizes = " << sumOfVectorSizes
661  << ", totalNumNodes = " << totalNumNodes
662  << ", localVectorSize = " << localVectorSize
663  << std::endl;
664  }
665  bcastComm.Barrier();
666  queso_require_equal_to_msg(((unsigned int) sumOfVectorSizes), ((unsigned int)(totalNumNodes*localVectorSize)), "inconsistent vectorSize");
667 
668  // Ok, bcast data
669  std::vector<double> dataBuffer((unsigned int) localVectorSize, 0.);
670  if (bcastComm.MyPID() == srcRank) {
671  for (unsigned int i = 0; i < dataBuffer.size(); ++i) {
672  dataBuffer[i] = (*this)[i];
673  }
674  }
675 
676  bcastComm.Bcast((void *) &dataBuffer[0], (int) localVectorSize, RawValue_MPI_DOUBLE, srcRank,
677  "GslVector::mpiBcast()",
678  "failed MPI.Bcast()");
679 
680  if (bcastComm.MyPID() != srcRank) {
681  for (unsigned int i = 0; i < dataBuffer.size(); ++i) {
682  (*this)[i] = dataBuffer[i];
683  }
684  }
685 
686  return;
687 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
double QUESO::GslVector::norm1 ( ) const

Returns the 1-norm of the vector.

Definition at line 287 of file GslVector.C.

References QUESO::size, and sizeLocal().

288 {
289  double result = 0.;
290 
291  unsigned int size = this->sizeLocal();
292  for (unsigned int i = 0; i < size; ++i) {
293  result += fabs((*this)[i]);
294  }
295 
296  return result;
297 }
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
double QUESO::GslVector::norm2 ( ) const

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

Definition at line 281 of file GslVector.C.

References norm2Sq().

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

282 {
283  return std::sqrt(this->norm2Sq());
284 }
double norm2Sq() const
Returns the 2-norm squared of this vector.
Definition: GslVector.C:275
double QUESO::GslVector::norm2Sq ( ) const

Returns the 2-norm squared of this vector.

Definition at line 275 of file GslVector.C.

References QUESO::scalarProduct().

Referenced by norm2().

276 {
277  return scalarProduct(*this,*this);
278 }
double scalarProduct(const GslVector &x, const GslVector &y)
Definition: GslVector.C:1137
double QUESO::GslVector::normInf ( ) const

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

Definition at line 300 of file GslVector.C.

References QUESO::size, and sizeLocal().

301 {
302  double result = 0.;
303 
304  unsigned int size = this->sizeLocal();
305  double aux = 0.;
306  for (unsigned int i = 0; i < size; ++i) {
307  aux = fabs((*this)[i]);
308  if (aux > result) result = aux;
309  }
310 
311  return result;
312 }
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
GslVector & QUESO::GslVector::operator*= ( double  a)

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

Definition at line 166 of file GslVector.C.

References m_vec.

167 {
168  int iRC;
169  iRC = gsl_vector_scale(m_vec,a);
170  queso_require_msg(!(iRC), "failed");
171  return *this;
172 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
GslVector & QUESO::GslVector::operator*= ( const GslVector rhs)

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

Definition at line 183 of file GslVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

184 {
185  unsigned int size1 = this->sizeLocal();
186  unsigned int size2 = rhs.sizeLocal();
187  queso_require_equal_to_msg(size1, size2, "different sizes of this and rhs");
188 
189  for (unsigned int i = 0; i < size1; ++i) {
190  (*this)[i] *= rhs[i];
191  }
192 
193  return *this;
194 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
GslVector & QUESO::GslVector::operator+= ( const GslVector rhs)

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

Definition at line 211 of file GslVector.C.

References m_vec.

212 {
213  int iRC;
214  iRC = gsl_vector_add(m_vec,rhs.m_vec);
215  queso_require_msg(!(iRC), "failed");
216  return *this;
217 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
GslVector & QUESO::GslVector::operator-= ( const GslVector rhs)

Stores in this the coordinate-wise subtraction of this by rhs.

Definition at line 220 of file GslVector.C.

References m_vec.

221 {
222  int iRC;
223  iRC = gsl_vector_sub(m_vec,rhs.m_vec);
224  queso_require_msg(!(iRC), "failed");
225 
226  return *this;
227 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
GslVector & QUESO::GslVector::operator/= ( double  a)

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

Definition at line 175 of file GslVector.C.

176 {
177  *this *= (1./a);
178 
179  return *this;
180 }
GslVector & QUESO::GslVector::operator/= ( const GslVector rhs)

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

Definition at line 197 of file GslVector.C.

References QUESO::queso_require_equal_to_msg, and sizeLocal().

198 {
199  unsigned int size1 = this->sizeLocal();
200  unsigned int size2 = rhs.sizeLocal();
201  queso_require_equal_to_msg(size1, size2, "different sizes of this and rhs");
202 
203  for (unsigned int i = 0; i < size1; ++i) {
204  (*this)[i] /= rhs[i];
205  }
206 
207  return *this;
208 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
GslVector & QUESO::GslVector::operator= ( const GslVector rhs)

Copies values from vector rhs to this.

Definition at line 150 of file GslVector.C.

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

151 {
152  //std::cout << "In GslVector::operator=()" // mox
153  // << ": setting size1"
154  // << std::endl;
155  unsigned int size1 = this->sizeLocal();
156  //std::cout << "In GslVector::operator=()" // mox
157  // << ": setting size2"
158  // << std::endl;
159  unsigned int size2 = rhs.sizeLocal();
160  queso_require_equal_to_msg(size1, size2, "sizes are not compatible");
161  this->copy(rhs);
162  return *this;
163 }
void copy(const GslVector &src)
This function copies the elements of the vector src into this.
Definition: GslVector.C:230
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
double & QUESO::GslVector::operator[] ( unsigned int  i)
inline

Element access method (non-const).

Returns the i-th element if x[i] is specified, the expression x(i) will return the same element.

Definition at line 271 of file GslVector.h.

References m_vec.

272 {
273  return *gsl_vector_ptr(m_vec,i);
274 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
const double & QUESO::GslVector::operator[] ( unsigned int  i) const
inline

Element access method (const).

Returns the i-th element if x[i] is specified, the expression x(i) will return the same element.

Definition at line 279 of file GslVector.h.

References m_vec.

280 {
281  return *gsl_vector_const_ptr(m_vec,i);
282 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
void QUESO::GslVector::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 743 of file GslVector.C.

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

Referenced by QUESO::operator<<().

744 {
745  //std::cout << "In GslVector::print(): before sizelocal()"
746  // << std::endl;
747  unsigned int size = this->sizeLocal();
748  //std::cout << "In GslVector::print(): after sizelocal()"
749  // << std::endl;
750 
751  //std::cout << "In GslVector::print(): before os.flags()"
752  // << std::endl;
753  std::ostream::fmtflags curr_fmt = os.flags();
754  //std::cout << "In GslVector::print(): after os.flags()"
755  // << std::endl;
756 
757  if (m_printScientific) {
758  unsigned int savedPrecision = os.precision();
759  os.precision(16);
760 
761  if (m_printHorizontally) {
762  for (unsigned int i = 0; i < size; ++i) {
763  os << std::scientific << (*this)[i]
764  << " ";
765  }
766  }
767  else {
768  for (unsigned int i = 0; i < size; ++i) {
769  os << std::scientific << (*this)[i]
770  << std::endl;
771  }
772  }
773 
774  os.precision(savedPrecision);
775  }
776  else {
777  if (m_printHorizontally) {
778  //std::cout << "In GslVector::print(): where expected"
779  // << std::endl;
780  for (unsigned int i = 0; i < size; ++i) {
781  os << std::dec << (*this)[i]
782  << " ";
783  }
784  }
785  else {
786  for (unsigned int i = 0; i < size; ++i) {
787  os << std::dec << (*this)[i]
788  << std::endl;
789  }
790  }
791  }
792 
793  //std::cout << "In GslVector::print(): before os.flags(curr_fmt)"
794  // << std::endl;
795  os.flags(curr_fmt);
796  //std::cout << "In GslVector::print(): after os.flags(curr_fmt)"
797  // << std::endl;
798 
799  return;
800 }
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
unsigned int QUESO::GslVector::sizeGlobal ( ) const
virtual

Returns the global length of this vector.

Implements QUESO::Vector.

Definition at line 267 of file GslVector.C.

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

268 {
269  queso_require_equal_to_msg(m_vec->size, (unsigned int) m_map.NumGlobalElements(), "incompatible vec size");
270 
271  return m_vec->size;
272 }
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
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"))
const Map m_map
Mapping variable.
Definition: Vector.h:122
unsigned int QUESO::GslVector::sizeLocal ( ) const
virtual

Returns the length of this vector.

Implements QUESO::Vector.

Definition at line 241 of file GslVector.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(), cwExtract(), cwInvert(), cwSet(), cwSetBeta(), cwSetConcatenated(), cwSetGamma(), cwSetGaussian(), cwSetInverseGamma(), cwSetUniform(), cwSqrt(), QUESO::GslMatrix::eigen(), QUESO::GslMatrix::fillWithTensorProduct(), QUESO::GslMatrix::getColumn(), QUESO::GslMatrix::getRow(), QUESO::GslMatrix::GslMatrix(), QUESO::GslBlockMatrix::invertMultiply(), QUESO::GslMatrix::invertMultiply(), QUESO::GslMatrix::invertMultiplyForceLU(), QUESO::GslMatrix::largestEigen(), QUESO::leftDiagScaling(), matlabDiff(), matlabLinearInterpExtrap(), QUESO::GslMatrix::matlabLinearInterpExtrap(), QUESO::matrixProduct(), mpiAllQuantile(), mpiAllReduce(), mpiBcast(), QUESO::GslMatrix::multiply(), norm1(), normInf(), operator*=(), operator/=(), operator=(), QUESO::operator==(), print(), QUESO::GslMatrix::rank(), QUESO::rightDiagScaling(), QUESO::scalarProduct(), QUESO::GslMatrix::setColumn(), QUESO::GslOptimizer::setInitialPoint(), QUESO::GslMatrix::setRow(), QUESO::GslMatrix::smallestEigen(), subReadContents(), subWriteContents(), sumOfComponents(), QUESO::GslMatrix::svd(), and QUESO::GslMatrix::svdSolve().

242 {
243  // mox
244  //std::cout << "Entering GslVector::sizeLocal()"
245  // << ": &m_map = " << &m_map
246  // << std::endl;
247  //std::cout << ", m_map.NumMyElements() = " << m_map.NumMyElements()
248  // << std::endl;
249  //std::cout << ", m_vec = " << m_vec
250  // << std::endl;
251  //std::cout << ", m_vec->size = " << m_vec->size
252  // << std::endl;
253 
254  queso_require_equal_to_msg(m_vec->size, (unsigned int) m_map.NumMyElements(), "incompatible vec size");
255 
256  //std::cout << "Leaving GslVector::sizeLocal()"
257  // << ": m_vec = " << m_vec
258  // << ", m_vec->size = " << m_vec->size
259  // << ", &m_map = " << &m_map
260  // << ", m_map.NumMyElements() = " << m_map.NumMyElements()
261  // << std::endl;
262 
263  return m_vec->size;
264 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
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"))
const Map m_map
Mapping variable.
Definition: Vector.h:122
void QUESO::GslVector::sort ( )
virtual

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

Implements QUESO::Vector.

Definition at line 627 of file GslVector.C.

References m_vec.

628 {
629  gsl_sort_vector(m_vec);
630 
631  return;
632 }
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
void QUESO::GslVector::subReadContents ( const std::string &  fileName,
const std::string &  fileType,
const std::set< unsigned int > &  allowedSubEnvIds 
)

Definition at line 843 of file GslVector.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().

847 {
848  queso_require_greater_equal_msg(m_env.subRank(), 0, "unexpected subRank");
849 
850  queso_require_less_equal_msg(this->numOfProcsForStorage(), 1, "implemented just for sequential vectors for now");
851 
852  FilePtrSetStruct filePtrSet;
853  if (m_env.openInputFile(fileName,
854  fileType, // "m or hdf"
855  allowedSubEnvIds,
856  filePtrSet)) {
857  double subReadSize = this->sizeLocal();
858 
859  // In the logic below, the id of a line' begins with value 0 (zero)
860  unsigned int idOfMyFirstLine = 1;
861  unsigned int idOfMyLastLine = this->sizeLocal();
862  unsigned int numParams = 1; // Yes, just '1'
863 
864  // Read number of chain positions in the file by taking care of the first line,
865  // which resembles something like 'variable_name = zeros(n_positions,m_params);'
866  std::string tmpString;
867 
868  // Read 'variable name' string
869  *filePtrSet.ifsVar >> tmpString;
870  //std::cout << "Just read '" << tmpString << "'" << std::endl;
871 
872  // Read '=' sign
873  *filePtrSet.ifsVar >> tmpString;
874  //std::cout << "Just read '" << tmpString << "'" << std::endl;
875  queso_require_equal_to_msg(tmpString, std::string("="), std::string("string should be the '=' sign"));
876 
877  // Read 'zeros(n_positions,n_params)' string
878  *filePtrSet.ifsVar >> tmpString;
879  //std::cout << "Just read '" << tmpString << "'" << std::endl;
880  unsigned int posInTmpString = 6;
881 
882  // Isolate 'n_positions' in a string
883  char nPositionsString[tmpString.size()-posInTmpString+1];
884  unsigned int posInPositionsString = 0;
885  do {
886  queso_require_less_msg(posInTmpString, tmpString.size(), "symbol ',' not found in first line of file");
887  nPositionsString[posInPositionsString++] = tmpString[posInTmpString++];
888  } while (tmpString[posInTmpString] != ',');
889  nPositionsString[posInPositionsString] = '\0';
890 
891  // Isolate 'n_params' in a string
892  posInTmpString++; // Avoid reading ',' char
893  char nParamsString[tmpString.size()-posInTmpString+1];
894  unsigned int posInParamsString = 0;
895  do {
896  queso_require_less_msg(posInTmpString, tmpString.size(), "symbol ')' not found in first line of file");
897  nParamsString[posInParamsString++] = tmpString[posInTmpString++];
898  } while (tmpString[posInTmpString] != ')');
899  nParamsString[posInParamsString] = '\0';
900 
901  // Convert 'n_positions' and 'n_params' strings to numbers
902  unsigned int sizeOfVecInFile = (unsigned int) strtod(nPositionsString,NULL);
903  unsigned int numParamsInFile = (unsigned int) strtod(nParamsString, NULL);
904  if (m_env.subDisplayFile()) {
905  *m_env.subDisplayFile() << "In GslVector::subReadContents()"
906  << ": fullRank " << m_env.fullRank()
907  << ", sizeOfVecInFile = " << sizeOfVecInFile
908  << ", numParamsInFile = " << numParamsInFile
909  << ", this->sizeLocal() = " << this->sizeLocal()
910  << std::endl;
911  }
912 
913  // Check if [size of vec in file] >= [requested sub vec size]
914  queso_require_greater_equal_msg(sizeOfVecInFile, subReadSize, "size of vec in file is not big enough");
915 
916  // Check if [num params in file] == [num params in current vec]
917  queso_require_equal_to_msg(numParamsInFile, numParams, "number of parameters of vec in file is different than number of parameters in this vec object");
918 
919  // Code common to any core in a communicator
920  unsigned int maxCharsPerLine = 64*numParams; // Up to about 60 characters to represent each parameter value
921 
922  unsigned int lineId = 0;
923  while (lineId < idOfMyFirstLine) {
924  filePtrSet.ifsVar->ignore(maxCharsPerLine,'\n');
925  lineId++;
926  };
927 
928  if (m_env.subDisplayFile()) {
929  *m_env.subDisplayFile() << "In GslVector::subReadContents()"
930  << ": beginning to read input actual data"
931  << std::endl;
932  }
933 
934  // Take care of initial part of the first data line,
935  // which resembles something like 'variable_name = [value1 value2 ...'
936  // Read 'variable name' string
937  *filePtrSet.ifsVar >> tmpString;
938  //std::cout << "Core 0 just read '" << tmpString << "'" << std::endl;
939 
940  // Read '=' sign
941  *filePtrSet.ifsVar >> tmpString;
942  //std::cout << "Core 0 just read '" << tmpString << "'" << std::endl;
943  queso_require_equal_to_msg(tmpString, std::string("="), std::string("in core 0, string should be the '=' sign"));
944 
945  // Take into account the ' [' portion
946  std::streampos tmpPos = filePtrSet.ifsVar->tellg();
947  filePtrSet.ifsVar->seekg(tmpPos+(std::streampos)2);
948 
949  if (m_env.subDisplayFile()) {
950  *m_env.subDisplayFile() << "In GslVector::subReadContents()"
951  << ": beginning to read lines with numbers only"
952  << ", lineId = " << lineId
953  << ", idOfMyFirstLine = " << idOfMyFirstLine
954  << ", idOfMyLastLine = " << idOfMyLastLine
955  << std::endl;
956  }
957 
958  while (lineId <= idOfMyLastLine) {
959  *filePtrSet.ifsVar >> (*this)[lineId - idOfMyFirstLine];
960  lineId++;
961  };
962 
963  m_env.closeFile(filePtrSet,fileType);
964  }
965 
966  return;
967 }
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
unsigned int numOfProcsForStorage() const
Definition: Vector.C:68
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1084
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 sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
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
void QUESO::GslVector::subWriteContents ( const std::string &  varNamePrefix,
const std::string &  fileName,
const std::string &  fileType,
const std::set< unsigned int > &  allowedSubEnvIds 
) const

Definition at line 803 of file GslVector.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().

808 {
809  queso_require_greater_equal_msg(m_env.subRank(), 0, "unexpected subRank");
810 
811  queso_require_less_equal_msg(this->numOfProcsForStorage(), 1, "implemented just for sequential vectors for now");
812 
813  FilePtrSetStruct filePtrSet;
814  if (m_env.openOutputFile(fileName,
815  fileType, // "m or hdf"
816  allowedSubEnvIds,
817  false,
818  filePtrSet)) {
819  *filePtrSet.ofsVar << varNamePrefix << "_sub" << m_env.subIdString() << " = zeros(" << this->sizeLocal()
820  << "," << 1
821  << ");"
822  << std::endl;
823  *filePtrSet.ofsVar << varNamePrefix << "_sub" << m_env.subIdString() << " = [";
824 
825  bool savedVectorPrintScientific = this->getPrintScientific();
826  bool savedVectorPrintHorizontally = this->getPrintHorizontally();
827  this->setPrintScientific (true);
828  this->setPrintHorizontally(false);
829  *filePtrSet.ofsVar << *this;
830  //<< std::endl; // No need for 'endl' because horizontally = 'false'
831  this->setPrintHorizontally(savedVectorPrintHorizontally);
832  this->setPrintScientific (savedVectorPrintScientific);
833 
834  *filePtrSet.ofsVar << "];\n";
835 
836  m_env.closeFile(filePtrSet,fileType);
837  }
838 
839  return;
840 }
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
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
void setPrintScientific(bool value) const
Determines whether vector should be printed in Scientific Notation.
Definition: Vector.C:88
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
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
unsigned int numOfProcsForStorage() const
Definition: Vector.C:68
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1084
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
bool getPrintHorizontally() const
Checks if vector is printed horizontally.
Definition: Vector.C:82
double QUESO::GslVector::sumOfComponents ( ) const

Returns the sum of the components of the vector.

Definition at line 315 of file GslVector.C.

References QUESO::size, and sizeLocal().

316 {
317  double result = 0.;
318  unsigned int size = this->sizeLocal();
319  for (unsigned int i = 0; i < size; ++i) {
320  result += (*this)[i];
321  }
322 
323  return result;
324 }
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241

Member Data Documentation

gsl_vector* QUESO::GslVector::m_vec
private

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

Generated on Sat Apr 22 2017 14:04:39 for queso-0.57.0 by  doxygen 1.8.5