queso-0.51.1
ArrayOfOneDGrids.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008,2009,2010,2011,2012,2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/OneDGrid.h>
26 #include <queso/UniformOneDGrid.h>
27 #include <queso/ArrayOfOneDGrids.h>
28 #include <queso/GslVector.h>
29 #include <queso/GslMatrix.h>
30 
31 namespace QUESO {
32 
33 // Default constructor -------------------------------------------------
34 template <class V, class M>
36  const char* prefix,
37  const VectorSpace<V,M>& rowSpace)
38  :
39  m_env (rowSpace.env() ),
40  m_prefix ((std::string)(prefix)+""),
41  m_rowSpace (rowSpace ),
42  m_oneDGrids (m_rowSpace.map(),1),
43  m_sizes (NULL),
44  m_minPositions(NULL),
45  m_maxPositions(NULL)
46 {
47  for (unsigned int i = 0; i < (unsigned int) m_oneDGrids.MyLength(); ++i) {
48  m_oneDGrids(i,0) = NULL;
49  }
50 }
51 
52 // Destructor ----------------------------------------------------------
53 template <class V, class M>
55 {
56  if (m_maxPositions) delete m_maxPositions;
57  if (m_minPositions) delete m_minPositions;
58  if (m_sizes ) delete m_sizes;
59 
60  for (unsigned int i = 0; i < (unsigned int) m_oneDGrids.MyLength(); ++i) {
61  if (m_oneDGrids(i,0)) delete m_oneDGrids(i,0);
62  }
63 }
64 
65 // Property methods-----------------------------------------------------
66 template <class V, class M>
67 const VectorSpace<V,M>&
69 {
70  return m_rowSpace;
71 }
72 
73 template <class V, class M>
74 const V&
76 {
77  UQ_FATAL_TEST_MACRO(m_sizes == NULL,
78  m_env.worldRank(),
79  "ArrayOfOneDGrids<T>::sizes()",
80  "sizes is still NULL");
81 
82  return *m_sizes;
83 }
84 
85 template <class V, class M>
86 const V&
88 {
89  UQ_FATAL_TEST_MACRO(m_minPositions == NULL,
90  m_env.worldRank(),
91  "ArrayOfOneDGrids<T>::minPositions()",
92  "minPositions is still NULL");
93 
94  return *m_minPositions;
95 }
96 
97 template <class V, class M>
98 const V&
100 {
101  UQ_FATAL_TEST_MACRO(m_maxPositions == NULL,
102  m_env.worldRank(),
103  "ArrayOfOneDGrids<T>::maxPositions()",
104  "maxPositions is still NULL");
105 
106  return *m_maxPositions;
107 }
108 
109 template <class V, class M>
110 void
112  const V& sizesVec,
113  const V& minPositionsVec,
114  const V& maxPositionsVec)
115 {
116  if (m_sizes == NULL) m_sizes = new V(sizesVec);
117  else *m_sizes = sizesVec;
118 
119  if (m_minPositions == NULL) m_minPositions = new V(minPositionsVec);
120  else *m_minPositions = minPositionsVec;
121 
122  if (m_maxPositions == NULL) m_maxPositions = new V(maxPositionsVec);
123  else *m_maxPositions = maxPositionsVec;
124 
125  char strI[65];
126  for (unsigned int i = 0; i < (unsigned int) m_oneDGrids.MyLength(); ++i) {
127  sprintf(strI,"%u_",i);
128  m_oneDGrids(i,0) = new UniformOneDGrid<double>(m_env,
129  (m_prefix+strI).c_str(),
130  (unsigned int) sizesVec[i],
131  minPositionsVec[i],
132  maxPositionsVec[i]);
133  }
134 
135  return;
136 }
137 
138 template <class V, class M>
140 ArrayOfOneDGrids<V,M>::grid(unsigned int rowId) const
141 {
142  UQ_FATAL_TEST_MACRO(rowId >= m_rowSpace.dimLocal(),
143  m_env.worldRank(),
144  "ArrayOfOneDUnformGrids<T>::grid()",
145  "rowId is out of range");
146 
147  ArrayOfOneDGrids<V,M>* tmp = const_cast<ArrayOfOneDGrids<V,M>*>(this);
148  return *(tmp->m_oneDGrids(rowId,0));
149 }
150 
151 // I/O methods----------------------------------------------------------
152 template <class V, class M>
153 void
154 ArrayOfOneDGrids<V,M>::print(std::ostream& os) const
155 {
156  ArrayOfOneDGrids<V,M>* tmp = const_cast<ArrayOfOneDGrids<V,M>*>(this);
157  for (unsigned int i = 0; i < (unsigned int) m_oneDGrids.MyLength(); ++i) {
158  os << *(tmp->m_oneDGrids(i,0))
159  << std::endl;
160  }
161 
162  return;
163 }
164 
165 } // End namespace QUESO
166 
void print(std::ostream &os) const
Prints the values of the array of grids (points).
Class to accommodate arrays of one-dimensional grid.
const VectorSpace< V, M > & rowSpace() const
Returns the (vector) space to which the row belongs to.
Base class for accommodating one-dimensional grids.
Definition: OneDGrid.h:46
void setUniformGrids(const V &sizesVec, const V &minPositionsVec, const V &maxPositionsVec)
Sets an array of uniform grids.
~ArrayOfOneDGrids()
Destructor.
Class for accommodating uniform one-dimensional grids.
const V & minPositions() const
Returns an array with the minimum position of each grid.
const V & sizes() const
Returns an array with the sizes of the grids.
DistArray< BaseOneDGrid< double > * > m_oneDGrids
A class representing a vector space.
Definition: VectorSet.h:46
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
const BaseOneDGrid< double > & grid(unsigned int rowId) const
Returns the grid stored in the rowId-th position of the array of grids.
ArrayOfOneDGrids(const char *prefix, const VectorSpace< V, M > &rowSpace)
Default constructor.
const V & maxPositions() const
Returns an array with the maximum position of each grid.

Generated on Thu Apr 23 2015 19:26:15 for queso-0.51.1 by  doxygen 1.8.5