queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
ArrayOfOneDTables.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-2017 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/ArrayOfOneDTables.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 // Default constructor -------------------------------------------------
32 template <class V, class M>
34  const char* prefix,
35  const VectorSpace<V,M>& rowSpace)
36  :
37  m_env (rowSpace.env()),
38  m_prefix ((std::string)(prefix)+""),
39  m_rowSpace (rowSpace ),
40  m_oneDTables(m_rowSpace.map(),1)
41 {
42  for (unsigned int i = 0; i < (unsigned int) m_oneDTables.MyLength(); ++i) {
43  m_oneDTables(i,0) = NULL;
44  }
45 }
46 
47 // Destructor ----------------------------------------------------------
48 template <class V, class M>
50 {
51  for (unsigned int i = 0; i < (unsigned int) m_oneDTables.MyLength(); ++i) {
52  if (m_oneDTables(i,0)) delete m_oneDTables(i,0);
53  }
54 }
55 
56 // Math methods --------------------------------------------------------
57 template <class V, class M>
58 void
59 ArrayOfOneDTables<V,M>::setOneDTable(unsigned int rowId, const std::vector<double>& values)
60 {
61  queso_require_less_msg(rowId, (unsigned int) m_oneDTables.MyLength(), "rowId is out of range");
62 
63  if (m_oneDTables(rowId,0) == NULL) m_oneDTables(rowId,0) = new std::vector<double>(0);
64  else m_oneDTables(rowId,0)->clear();
65 
66  std::vector<double>& vec = *(m_oneDTables(rowId,0));
67  vec.resize(values.size(),0.);
68  for (unsigned int j = 0; j < values.size(); ++j) {
69  vec[j] = values[j];
70  }
71 
72  return;
73 }
74 
75 template <class V, class M>
76 const std::vector<double>&
77 ArrayOfOneDTables<V,M>::oneDTable(unsigned int rowId) const
78 {
79  queso_require_less_msg(rowId, (unsigned int) m_oneDTables.MyLength(), "rowId is out of range");
80 
81  ArrayOfOneDTables<V,M>* tmp = const_cast<ArrayOfOneDTables<V,M>*>(this);
82 
83  queso_require_msg(tmp->m_oneDTables(rowId,0), "requested row is still NULL");
84 
85  return *(tmp->m_oneDTables(rowId,0));
86 }
87 
88 // I/O methods----------------------------------------------------------
89 template <class V, class M>
90 void
91 ArrayOfOneDTables<V,M>::print(std::ostream& os) const
92 {
93  ArrayOfOneDTables<V,M>* tmp = const_cast<ArrayOfOneDTables<V,M>*>(this);
94  for (unsigned int i = 0; i < (unsigned int) m_oneDTables.MyLength(); ++i) {
95  const std::vector<double>& tmpVec = *(tmp->m_oneDTables(i,0));
96  os << m_prefix << i << "_values_sub" << m_env.subIdString() << " = zeros(" << tmpVec.size()
97  << "," << 1
98  << ");"
99  << std::endl;
100  os << m_prefix << i << "_values_sub" << m_env.subIdString() << " = [";
101  for (unsigned int j = 0; j < tmpVec.size(); ++j) {
102  os << tmpVec[j] << " ";
103  }
104  os << "];"
105  << std::endl;
106  }
107 
108  return;
109 }
110 
111 template <class V, class M>
112 std::ostream& operator<< (std::ostream& os, const ArrayOfOneDTables<V,M>& obj)
113 {
114  obj.print(os);
115  return os;
116 }
117 
118 } // End namespace QUESO
119 
A class representing a vector space.
Definition: VectorSet.h:49
Class to accommodate arrays of one-dimensional tables.
void setOneDTable(unsigned int rowId, const std::vector< double > &values)
Sets the one-dimensional table.
const std::vector< double > & oneDTable(unsigned int rowId) const
Returns the array located at position rowId of the one-dimensional table.
int MyLength() const
Returns the length of the locally owned array.
Definition: DistArray.C:118
DistArray< std::vector< double > * > m_oneDTables
~ArrayOfOneDTables()
Destructor.
ArrayOfOneDTables(const char *prefix, const VectorSpace< V, M > &rowSpace)
Default constructor.
void print(std::ostream &os) const
Prints the values in this array of tables.

Generated on Tue Jun 5 2018 19:48:55 for queso-0.57.1 by  doxygen 1.8.5