25 #include <queso/VectorSpace.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 #include <queso/TeuchosVector.h>
29 #include <queso/TeuchosMatrix.h>
30 #include <queso/DistArray.h>
31 #include <queso/Map.h>
37 template <
class V,
class M>
39 unsigned int dimGlobalValue,
40 const std::vector<std::string>* componentsNamesVec)
41 :
VectorSet<V,M> (env,((std::string)(prefix) +
"space_").c_str(),INFINITY),
42 m_dimGlobal(dimGlobalValue),
44 m_dimLocal(m_map->NumMyElements()),
45 m_componentsNamesArray(NULL),
46 m_componentsNamesVec(NULL),
47 m_emptyComponentName(
""),
48 m_zeroVector(new V(m_env,*m_map))
53 <<
"\n m_zeroVector->sizeGlobal() = " <<
m_zeroVector->sizeGlobal()
55 <<
"\n m_zeroVector->sizeLocal() = " <<
m_zeroVector->sizeLocal()
58 <<
"\n componentsNamesVec = " << componentsNamesVec
63 std::cerr <<
"In VectorSpace<V,M>::constructor(1)"
65 <<
": m_zeroVector->sizeGlobal() = " <<
m_zeroVector->sizeGlobal()
72 std::cerr <<
"In VectorSpace<V,M>::constructor(1)"
74 <<
": m_zeroVector->sizeLocal() = " <<
m_zeroVector->sizeLocal()
80 if (componentsNamesVec != NULL) {
85 for (
unsigned int i = 0; i <
m_dimLocal; ++i) {
86 (*m_componentsNamesArray)(i,0) = (*componentsNamesVec)[myFirstId+i];
101 template <
class V,
class M>
103 :
VectorSet<V,M>(aux.env(),((std::string)(aux.m_prefix)).c_str(),INFINITY),
104 m_dimGlobal(aux.m_dimGlobal),
106 m_dimLocal(m_map->NumMyElements()),
107 m_componentsNamesArray(NULL),
108 m_componentsNamesVec(NULL),
109 m_emptyComponentName(
""),
110 m_zeroVector(new V(m_env,*m_map))
115 template <
class V,
class M>
118 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
119 *m_env.subDisplayFile() <<
"Entering VectorSpace<V,M>::destructor()"
123 if (m_zeroVector != NULL)
delete m_zeroVector;
124 if (m_componentsNamesVec != NULL)
delete m_componentsNamesVec;
125 if (m_componentsNamesArray != NULL)
delete m_componentsNamesArray;
126 if (m_map != NULL)
delete m_map;
128 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
129 *m_env.subDisplayFile() <<
"Leaving VectorSpace<V,M>::destructor()"
135 template <
class V,
class M>
141 template <
class V,
class M>
144 queso_require_msg(m_map,
"m_map is still NULL");
148 template <
class V,
class M>
151 return m_map->Comm().NumProc();
154 template <
class V,
class M>
160 template <
class V,
class M>
166 template <
class V,
class M>
169 return m_map->MinMyGID();
173 template<
class V,
class M>
176 queso_require_msg(m_zeroVector,
"m_zeroVector is still NULL");
177 return *m_zeroVector;
180 template <
class V,
class M>
183 if (v.sizeGlobal() != m_dimGlobal)
return NULL;
184 if (v.sizeLocal () != m_dimLocal )
return NULL;
189 template <
class V,
class M>
192 if (v.sizeGlobal() != m_dimGlobal)
return NULL;
193 if (v.sizeLocal () != m_dimLocal )
return NULL;
198 template <
class V,
class M>
201 V tmpVec(*m_zeroVector);
202 for (
unsigned int i = 0; i < m_dimLocal; ++i) {
203 double variance = INFINITY;
204 if (varVec) variance = (*varVec)[i];
205 if (m_env.subDisplayFile()) {
206 *m_env.subDisplayFile() <<
"In VectorSpace<V,M>::newProposalMatrix()"
208 <<
", variance = " << variance
211 if ((variance == INFINITY) ||
212 (variance == NAN )) {
214 tmpVec[i] = std::pow( fabs((*auxVec)[i])*0.05,2. );
215 if ((tmpVec[i] == 0. ) ||
216 (tmpVec[i] == INFINITY) ||
217 (tmpVec[i] == NAN )) {
225 else if (variance == 0.) {
229 tmpVec[i] = variance;
233 return newDiagMatrix(tmpVec);
236 template <
class V,
class M>
242 template <
class V,
class M>
248 template <
class V,
class M>
251 queso_assert_equal_to (m_dimLocal, vec.sizeLocal());
253 for (
unsigned int i = 0; i < m_dimLocal; ++i) {
258 template <
class V,
class M>
261 queso_assert_equal_to (m_dimLocal, mat.numCols());
265 for (
unsigned int i = 0; i < m_dimLocal; ++i) {
270 template <
class V,
class M>
273 return m_componentsNamesArray;
276 template <
class V,
class M>
278 unsigned int localComponentId)
const
280 if (m_componentsNamesArray == NULL)
return m_emptyComponentName;
282 queso_require_less_equal_msg(localComponentId, m_dimLocal,
"localComponentId is too big");
285 return (*m_componentsNamesArray)(localComponentId,0);
288 template<
class V,
class M>
290 bool printHorizontally)
const
292 if (printHorizontally) {
293 for (
unsigned int i = 0; i < this->dimLocal(); ++i) {
294 os <<
"'" << this->localComponentName(i) <<
"'"
299 for (
unsigned int i = 0; i < this->dimLocal(); ++i) {
300 os <<
"'" << this->localComponentName(i) <<
"'"
308 template <
class V,
class M>
311 os <<
"In VectorSpace<V,M>::print()"
312 <<
": nothing to be printed" << std::endl;
319 #ifdef QUESO_HAS_TRILINOS
void printComponentsNames(std::ostream &os, bool printHorizontally) const
Prints the local component names.
void print(std::ostream &os) const
Prints only a message.
const V & zeroVector() const
Returns a vector filled with zeros.
const DistArray< std::string > * componentsNamesArray() const
Access to private attribute m_componentsNamesArray, which is an instance of DistArray.
unsigned int dimGlobal() const
M * newProposalMatrix(const V *varVec, const V *auxVec) const
Creates a diagonal matrix conditionally to values from vector varVec, guaranteeing that its values ar...
A class for partitioning vectors and matrices.
A class representing a vector space.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
const std::string & localComponentName(unsigned int localComponentId) const
Returns the local component names.
unsigned int numOfProcsForStorage() const
Returns total number of processes.
const BaseEnvironment & env() const
Environment.
A templated class for handling sets.
bool contains(const V &vec) const
Whether vector contains vector vec.
unsigned int m_dimLocal
Local dimension (number of elements owned by the calling processor.).
const BaseEnvironment & m_env
V * newVector() const
Creates an empty vector of size given by Map& map. See template specialization.
~VectorSpace()
Destructor.
DistArray< std::string > * m_componentsNamesArray
Array of strings of the type DistArray to store the names of the components.
int NumGlobalElements() const
Returns the total number of elements across all processors.
unsigned int globalIdOfFirstComponent() const
unsigned int dimLocal() const
int GlobalLength() const
Returns the global length of the array.
int MyLength() const
Returns the length of the locally owned array.
VectorSpace()
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"))
void centroid(V &vec) const
The (INFINITY/nonexistent) centroid of the space.
const Map & map() const
Map.
V * m_zeroVector
A vector of all elements equal to zero.
unsigned int displayVerbosity() const
const VectorSpace< V, M > & vectorSpace() const
Accessor method to this. Vector space to which this vector set belongs to.
void moments(M &vec) const
The (INFINITY/nonexistent) matrix of second moments of the space.
unsigned int m_dimGlobal
Global dimension.
M * newDiagMatrix(const V &v) const
Creates a diagonal matrix with the elements and size of vector v.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).