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))
130 template <
class V,
class M>
133 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
134 *m_env.subDisplayFile() <<
"Entering VectorSpace<V,M>::destructor()"
138 if (m_zeroVector != NULL)
delete m_zeroVector;
139 if (m_componentsNamesVec != NULL)
delete m_componentsNamesVec;
140 if (m_componentsNamesArray != NULL)
delete m_componentsNamesArray;
141 if (m_map != NULL)
delete m_map;
143 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
144 *m_env.subDisplayFile() <<
"Leaving VectorSpace<V,M>::destructor()"
150 template <
class V,
class M>
156 template <
class V,
class M>
163 template <
class V,
class M>
166 return m_map->Comm().NumProc();
169 template <
class V,
class M>
175 template <
class V,
class M>
181 template <
class V,
class M>
184 return m_map->MinMyGID();
188 template<
class V,
class M>
192 return *m_zeroVector;
195 template <
class V,
class M>
198 if (v.sizeGlobal() != m_dimGlobal)
return NULL;
199 if (v.sizeLocal () != m_dimLocal )
return NULL;
204 template <
class V,
class M>
207 if (v.sizeGlobal() != m_dimGlobal)
return NULL;
208 if (v.sizeLocal () != m_dimLocal )
return NULL;
213 template <
class V,
class M>
216 V tmpVec(*m_zeroVector);
217 for (
unsigned int i = 0; i < m_dimLocal; ++i) {
218 double variance = INFINITY;
219 if (varVec) variance = (*varVec)[i];
220 if (m_env.subDisplayFile()) {
221 *m_env.subDisplayFile() <<
"In VectorSpace<V,M>::newProposalMatrix()"
223 <<
", variance = " << variance
226 if ((variance == INFINITY) ||
227 (variance == NAN )) {
229 tmpVec[i] = std::pow( fabs((*auxVec)[i])*0.05,2. );
230 if ((tmpVec[i] == 0. ) ||
231 (tmpVec[i] == INFINITY) ||
232 (tmpVec[i] == NAN )) {
240 else if (variance == 0.) {
244 tmpVec[i] = variance;
248 return newDiagMatrix(tmpVec);
251 template <
class V,
class M>
257 template <
class V,
class M>
264 template <
class V,
class M>
267 return m_componentsNamesArray;
270 template <
class V,
class M>
272 unsigned int localComponentId)
const
274 if (m_componentsNamesArray == NULL)
return m_emptyComponentName;
279 return (*m_componentsNamesArray)(localComponentId,0);
282 template<
class V,
class M>
284 bool printHorizontally)
const
286 if (printHorizontally) {
287 for (
unsigned int i = 0; i < this->dimLocal(); ++i) {
288 os <<
"'" << this->localComponentName(i) <<
"'"
293 for (
unsigned int i = 0; i < this->dimLocal(); ++i) {
294 os <<
"'" << this->localComponentName(i) <<
"'"
302 template <
class V,
class M>
305 os <<
"In VectorSpace<V,M>::print()"
306 <<
": nothing to be printed" << std::endl;
313 #ifdef QUESO_HAS_TRILINOS
unsigned int displayVerbosity() const
unsigned int dimLocal() const
int GlobalLength() const
Returns the global length of the array.
void printComponentsNames(std::ostream &os, bool printHorizontally) const
Prints the local component names.
A templated class for handling sets.
const VectorSpace< V, M > & vectorSpace() const
Accessor method to this. Vector space to which this vector set belongs to.
void print(std::ostream &os) const
Prints only a message.
const Map & map() const
Map.
unsigned int m_dimGlobal
Global dimension.
VectorSpace()
Default constructor.
#define queso_require_less_equal_msg(expr1, expr2, msg)
DistArray< std::string > * m_componentsNamesVec
Vector of strings of the type DistArray to store the names of the components.
int MyLength() const
Returns the length of the locally owned array.
const V & zeroVector() const
Returns a vector filled with zeros.
unsigned int dimGlobal() const
#define queso_require_equal_to_msg(expr1, expr2, msg)
V * newVector() const
Creates an empty vector of size given by Map& map. See template specialization.
unsigned int globalIdOfFirstComponent() const
const std::string & localComponentName(unsigned int localComponentId) const
Returns the local component names.
V * m_zeroVector
A vector of all elements equal to zero.
#define queso_require_msg(asserted, msg)
const BaseEnvironment & env() const
Environment.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
M * newDiagMatrix(const V &v) const
Creates a diagonal matrix with the elements and size of vector v.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
const DistArray< std::string > * componentsNamesArray() const
Access to private attribute m_componentsNamesArray, which is an instance of DistArray.
unsigned int m_dimLocal
Local dimension (number of elements owned by the calling processor.).
~VectorSpace()
Destructor.
bool contains(const V &vec) const
Whether vector contains vector vec.
A class for partitioning vectors and matrices.
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 representing a vector space.
unsigned int numOfProcsForStorage() const
Returns total number of processes.
int NumGlobalElements() const
Returns the total number of elements across all processors.
DistArray< std::string > * m_componentsNamesArray
Array of strings of the type DistArray to store the names of the components.
const BaseEnvironment & m_env