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>
 
   43                       "VectorSpace<V,M>::constructor(), default",
 
   44                       "should not be used by user");
 
   48 template <
class V, 
class M>
 
   50     unsigned int dimGlobalValue,
 
   51     const std::vector<std::string>* componentsNamesVec)
 
   52   : 
VectorSet<V,M> (env,((std::string)(prefix) + 
"space_").c_str(),INFINITY),
 
   53     m_dimGlobal(dimGlobalValue),
 
   55     m_dimLocal(m_map->NumMyElements()),
 
   56     m_componentsNamesArray(NULL),
 
   57     m_componentsNamesVec(NULL),
 
   58     m_emptyComponentName(
""),
 
   59     m_zeroVector(new V(m_env,*m_map))
 
   64                             << 
"\n  m_zeroVector->sizeGlobal() = " << 
m_zeroVector->sizeGlobal()
 
   66                             << 
"\n  m_zeroVector->sizeLocal()  = " << 
m_zeroVector->sizeLocal()
 
   69                             << 
"\n  componentsNamesVec         = " << componentsNamesVec
 
   74     std::cerr << 
"In VectorSpace<V,M>::constructor(1)" 
   76               << 
": m_zeroVector->sizeGlobal() = " << 
m_zeroVector->sizeGlobal()
 
   82                       "VectorSpace<V,M>::constructor(1)",
 
   83                       "global size of 'm_zeroVector' is not equal to m_dimGlobal");
 
   86     std::cerr << 
"In VectorSpace<V,M>::constructor(1)" 
   88               << 
": m_zeroVector->sizeLocal() = " << 
m_zeroVector->sizeLocal()
 
   94                       "VectorSpace<V,M>::constructor(1)",
 
   95                       "local size of 'm_zeroVector' is not equal to m_dimLocal");
 
   97   if (componentsNamesVec != NULL) {
 
  100                         "VectorSpace<V,M>::constructor(1)",
 
  101                         "global size of 'componentsNames' is not equal to m_dimGlobal");
 
  105     for (
unsigned int i = 0; i < 
m_dimLocal; ++i) {
 
  106       (*m_componentsNamesArray)(i,0) = (*componentsNamesVec)[myFirstId+i];
 
  111                         "VectorSpace<V,M>::constructor(1)",
 
  112                         "global size of 'm_componentsNamesArray' is not equal to m_dimGlobal");
 
  115                         "VectorSpace<V,M>::constructor(1)",
 
  116                         "local size of 'm_componentsNamesArray' is not equal to m_dimLocal");
 
  127 template <
class V, 
class M>
 
  129   : 
VectorSet<V,M>(aux.env(),((std::string)(aux.m_prefix)).c_str(),INFINITY),
 
  130     m_dimGlobal(aux.m_dimGlobal),
 
  132     m_dimLocal(m_map->NumMyElements()),
 
  133     m_componentsNamesArray(NULL),
 
  134     m_componentsNamesVec(NULL),
 
  135     m_emptyComponentName(
""),
 
  136     m_zeroVector(new V(m_env,*m_map))
 
  156 template <
class V, 
class M>
 
  159   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
 
  160     *m_env.subDisplayFile() << 
"Entering VectorSpace<V,M>::destructor()" 
  164   if (m_zeroVector           != NULL) 
delete m_zeroVector;
 
  165   if (m_componentsNamesVec   != NULL) 
delete m_componentsNamesVec;
 
  166   if (m_componentsNamesArray != NULL) 
delete m_componentsNamesArray;
 
  167   if (m_map                  != NULL) 
delete m_map;
 
  169   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
 
  170     *m_env.subDisplayFile() << 
"Leaving VectorSpace<V,M>::destructor()" 
  176 template <
class V, 
class M>
 
  182 template <
class V, 
class M>
 
  187                       "VectorSpace<V,M>::map()",
 
  188                       "m_map is still NULL");
 
  192 template <
class V, 
class M>
 
  195   return m_map->Comm().NumProc();
 
  198 template <
class V, 
class M>
 
  204 template <
class V, 
class M>
 
  210 template <
class V, 
class M>
 
  213   return m_map->MinMyGID();
 
  217 template<
class V, 
class M>
 
  222                       "VectorSpace<V,M>::zeroVector()",
 
  223                       "m_zeroVector is still NULL");
 
  224   return *m_zeroVector;
 
  227 template <
class V, 
class M>
 
  230   if (v.sizeGlobal() != m_dimGlobal) 
return NULL;
 
  231   if (v.sizeLocal () != m_dimLocal ) 
return NULL;
 
  236 template <
class V, 
class M>
 
  239   if (v.sizeGlobal() != m_dimGlobal) 
return NULL;
 
  240   if (v.sizeLocal () != m_dimLocal ) 
return NULL;
 
  245 template <
class V, 
class M>
 
  248   V tmpVec(*m_zeroVector);
 
  249   for (
unsigned int i = 0; i < m_dimLocal; ++i) {
 
  250     double variance = INFINITY;
 
  251     if (varVec) variance = (*varVec)[i];
 
  252     if (m_env.subDisplayFile()) {
 
  253       *m_env.subDisplayFile() << 
"In VectorSpace<V,M>::newProposalMatrix()" 
  255                               << 
", variance = " << variance
 
  258     if ((variance == INFINITY) ||
 
  259         (variance == NAN     )) {
 
  261         tmpVec[i] = std::pow( fabs((*auxVec)[i])*0.05,2. );
 
  262         if ((tmpVec[i] == 0.      ) ||
 
  263             (tmpVec[i] == INFINITY) ||
 
  264             (tmpVec[i] == NAN     )) {
 
  272     else if (variance == 0.) {
 
  276       tmpVec[i] = variance;
 
  280   return newDiagMatrix(tmpVec);
 
  283 template <
class V, 
class M>
 
  289 template <
class V, 
class M>
 
  296 template <
class V, 
class M>
 
  299   return m_componentsNamesArray;
 
  302 template <
class V, 
class M>
 
  304     unsigned int localComponentId)
 const 
  306   if (m_componentsNamesArray == NULL) 
return m_emptyComponentName;
 
  310                       "VectorSpace<V,M>::localComponentName()",
 
  311                       "localComponentId is too big");
 
  314   return (*m_componentsNamesArray)(localComponentId,0);
 
  317 template<
class V, 
class M>
 
  319     bool printHorizontally)
 const 
  321   if (printHorizontally) {
 
  322     for (
unsigned int i = 0; i < this->dimLocal(); ++i) {
 
  323       os << 
"'" << this->localComponentName(i) << 
"'" 
  328     for (
unsigned int i = 0; i < this->dimLocal(); ++i) {
 
  329       os << 
"'" << this->localComponentName(i) << 
"'" 
  337 template <
class V, 
class M>
 
  340   os << 
"In VectorSpace<V,M>::print()" 
  341      << 
": nothing to be printed" << std::endl;
 
  348 #ifdef QUESO_HAS_TRILINOS 
V * newVector() const 
Creates an empty vector of size given by Map& map. See template specialization. 
 
int NumGlobalElements() const 
Returns the total number of elements across all processors. 
 
const Map & map() const 
Map. 
 
~VectorSpace()
Destructor. 
 
M * newProposalMatrix(const V *varVec, const V *auxVec) const 
Creates a diagonal matrix conditionally to values from vector varVec, guaranteeing that its values ar...
 
int worldRank() const 
Returns the process world rank. 
 
unsigned int dimLocal() const 
 
A templated class for handling sets. 
 
std::ofstream * subDisplayFile() const 
Access function for m_subDisplayFile (displays file on stream). 
 
unsigned int m_dimLocal
Local dimension (number of elements owned by the calling processor.). 
 
const BaseEnvironment & m_env
 
const std::string & localComponentName(unsigned int localComponentId) const 
Returns the local component names. 
 
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
 
const V & zeroVector() const 
Returns a vector filled with zeros. 
 
A class for partitioning vectors and matrices. 
 
bool contains(const V &vec) const 
Whether  vector contains vector vec. 
 
unsigned int numOfProcsForStorage() const 
Returns total number of processes. 
 
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
 
VectorSpace()
Default constructor. 
 
void print(std::ostream &os) const 
Prints only a message. 
 
DistArray< std::string > * m_componentsNamesArray
Array of strings of the type DistArray to store the names of the components. 
 
unsigned int globalIdOfFirstComponent() const 
 
M * newDiagMatrix(const V &v) const 
Creates a diagonal matrix with the elements and size of vector v. 
 
DistArray< std::string > * m_componentsNamesVec
Vector of strings of the type DistArray to store the names of the components. 
 
V * m_zeroVector
A vector of all elements equal to zero. 
 
const BaseEnvironment & env() const 
Environment. 
 
void printComponentsNames(std::ostream &os, bool printHorizontally) const 
Prints the local component names. 
 
unsigned int displayVerbosity() const 
 
A class representing a vector space. 
 
unsigned int m_dimGlobal
Global dimension. 
 
const VectorSpace< V, M > & vectorSpace() const 
Accessor method to this. Vector space to which this vector set belongs to. 
 
const DistArray< std::string > * componentsNamesArray() const 
Access to private attribute m_componentsNamesArray, which is an instance of DistArray. 
 
unsigned int dimGlobal() const