queso-0.53.0
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-2015 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  queso_require_msg(m_sizes, "sizes is still NULL");
78 
79  return *m_sizes;
80 }
81 
82 template <class V, class M>
83 const V&
85 {
86  queso_require_msg(m_minPositions, "minPositions is still NULL");
87 
88  return *m_minPositions;
89 }
90 
91 template <class V, class M>
92 const V&
94 {
95  queso_require_msg(m_maxPositions, "maxPositions is still NULL");
96 
97  return *m_maxPositions;
98 }
99 
100 template <class V, class M>
101 void
103  const V& sizesVec,
104  const V& minPositionsVec,
105  const V& maxPositionsVec)
106 {
107  if (m_sizes == NULL) m_sizes = new V(sizesVec);
108  else *m_sizes = sizesVec;
109 
110  if (m_minPositions == NULL) m_minPositions = new V(minPositionsVec);
111  else *m_minPositions = minPositionsVec;
112 
113  if (m_maxPositions == NULL) m_maxPositions = new V(maxPositionsVec);
114  else *m_maxPositions = maxPositionsVec;
115 
116  char strI[65];
117  for (unsigned int i = 0; i < (unsigned int) m_oneDGrids.MyLength(); ++i) {
118  sprintf(strI,"%u_",i);
119  m_oneDGrids(i,0) = new UniformOneDGrid<double>(m_env,
120  (m_prefix+strI).c_str(),
121  (unsigned int) sizesVec[i],
122  minPositionsVec[i],
123  maxPositionsVec[i]);
124  }
125 
126  return;
127 }
128 
129 template <class V, class M>
131 ArrayOfOneDGrids<V,M>::grid(unsigned int rowId) const
132 {
133  queso_require_less_msg(rowId, m_rowSpace.dimLocal(), "rowId is out of range");
134 
135  ArrayOfOneDGrids<V,M>* tmp = const_cast<ArrayOfOneDGrids<V,M>*>(this);
136  return *(tmp->m_oneDGrids(rowId,0));
137 }
138 
139 // I/O methods----------------------------------------------------------
140 template <class V, class M>
141 void
142 ArrayOfOneDGrids<V,M>::print(std::ostream& os) const
143 {
144  ArrayOfOneDGrids<V,M>* tmp = const_cast<ArrayOfOneDGrids<V,M>*>(this);
145  for (unsigned int i = 0; i < (unsigned int) m_oneDGrids.MyLength(); ++i) {
146  os << *(tmp->m_oneDGrids(i,0))
147  << std::endl;
148  }
149 
150  return;
151 }
152 
153 } // End namespace QUESO
154 
Class to accommodate arrays of one-dimensional grid.
const V & maxPositions() const
Returns an array with the maximum position of each grid.
void print(std::ostream &os) const
Prints the values of the array of grids (points).
ArrayOfOneDGrids(const char *prefix, const VectorSpace< V, M > &rowSpace)
Default constructor.
DistArray< BaseOneDGrid< double > * > m_oneDGrids
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
#define queso_require_less_msg(expr1, expr2, msg)
Definition: asserts.h:87
Class for accommodating uniform one-dimensional grids.
const VectorSpace< V, M > & rowSpace() const
Returns the (vector) space to which the row belongs to.
const BaseOneDGrid< double > & grid(unsigned int rowId) const
Returns the grid stored in the rowId-th position of the array of grids.
const V & minPositions() const
Returns an array with the minimum position of each grid.
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.
const V & sizes() const
Returns an array with the sizes of the grids.
A class representing a vector space.
Definition: VectorSet.h:49

Generated on Thu Jun 11 2015 13:52:32 for queso-0.53.0 by  doxygen 1.8.5