queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
ConcatenationSubset.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/VectorSet.h>
26 #include <queso/VectorSpace.h>
27 #include <queso/ConcatenationSubset.h>
28 #include <queso/GslVector.h>
29 #include <queso/GslMatrix.h>
30 
31 namespace QUESO {
32 
33 // Default, shaped constructor
34 template<class V, class M>
36  const VectorSpace<V,M>& vectorSpace,
37  const VectorSet<V,M>& set1,
38  const VectorSet<V,M>& set2)
39  : VectorSubset<V,M>(prefix, vectorSpace, set1.volume()*set2.volume()),
40  m_sets(2, (const VectorSet<V,M>*) NULL)
41 {
42  m_sets[0] = &set1;
43  m_sets[1] = &set2;
44 }
45 
46 // Default, shaped constructor
47 template<class V, class M>
49  const VectorSpace<V,M>& vectorSpace,
50  double volume,
51  const std::vector<const VectorSet<V,M>* >& sets)
52  : VectorSubset<V,M>(prefix, vectorSpace, volume),
53  m_sets(sets.size(), (const VectorSet<V,M>*) NULL)
54 {
55  for (unsigned int i = 0; i < m_sets.size(); ++i) {
56  m_sets[i] = sets[i];
57  }
58 }
59 
60 // Destructor
61 template<class V, class M>
63 {
64 }
65 
66 // Mathematical methods
67 template<class V, class M>
68 bool ConcatenationSubset<V,M>::contains(const V& vec) const
69 {
70  bool result = true;
71 
72  std::vector<V*> vecs(m_sets.size(),(V*) NULL);
73  for (unsigned int i = 0; i < vecs.size(); ++i) {
74  vecs[i] = new V(m_sets[i]->vectorSpace().zeroVector());
75  }
76 
77  unsigned int cummulativeSize = 0;
78  for (unsigned int i = 0; i < vecs.size(); ++i) {
79  vec.cwExtract(cummulativeSize,*(vecs[i]));
80  cummulativeSize += vecs[i]->sizeLocal();
81  }
82 
83  queso_require_equal_to_msg(vec.sizeLocal(), cummulativeSize, "incompatible vector sizes");
84 
85  for (unsigned int i = 0; i < m_sets.size(); ++i) {
86  result = result && m_sets[i]->contains(*(vecs[i]));
87  }
88  for (unsigned int i = 0; i < vecs.size(); ++i) {
89  delete vecs[i];
90  }
91 
92  return (result);
93 }
94 
95 template<class V, class M>
97 {
98  unsigned int cumulativeSize = 0;
99  for (unsigned int i = 0; i < m_sets.size(); ++i) {
100  V subvec(m_sets[i]->vectorSpace().zeroVector());
101  m_sets[i]->centroid(subvec);
102  vec.cwSet(cumulativeSize,subvec);
103 
104  cumulativeSize += subvec.sizeLocal();
105  }
106 
107  queso_require_equal_to_msg(vec.sizeLocal(), cumulativeSize, "incompatible vector sizes");
108 }
109 
110 template<class V, class M>
112 {
113  unsigned int cumulativeSize = 0;
114  for (unsigned int i = 0; i < m_sets.size(); ++i) {
115  const Map & map = m_sets[i]->vectorSpace().map();
116  const unsigned int n_columns = map.NumGlobalElements();
117  M submat(m_sets[i]->vectorSpace().env(),
118  map, n_columns);
119  m_sets[i]->moments(submat);
120  mat.cwSet(cumulativeSize,cumulativeSize,submat);
121 
122  cumulativeSize += n_columns;
123  }
124 
125  queso_require_equal_to_msg(mat.numCols(), cumulativeSize, "incompatible vector sizes");
126 }
127 
128 // I/O methods
129 template <class V, class M>
130 void ConcatenationSubset<V,M>::print(std::ostream& os) const
131 {
132  os << "In ConcatenationSubset<V,M>::print()"
133  << ": m_sets.size() = " << m_sets.size()
134  << std::endl;
135  for (unsigned int i = 0; i < m_sets.size(); ++i) {
136  os << "m_sets[" << i << "] = " << *(m_sets[i]);
137  if (i < (m_sets.size()-1)) {
138  os << ", ";
139  }
140  }
141  os << std::endl;
142 
143  return;
144 }
145 
146 } // End namespace QUESO
147 
virtual void moments(M &mat) const
Returns the set moments of inertia in the matrix mat.
bool contains(const V &vec) const
Determines whether each one of the subsets m_sets (class&#39; private attributes) contains vector vec...
A class for partitioning vectors and matrices.
Definition: Map.h:49
A class representing a vector space.
Definition: VectorSet.h:49
A templated class representing the concatenation of two vector subsets.
ConcatenationSubset(const char *prefix, const VectorSpace< V, M > &vectorSpace, const VectorSet< V, M > &set1, const VectorSet< V, M > &set2)
Constructor - two sets only.
A templated class for handling subsets.
Definition: VectorSubset.h:46
virtual void centroid(V &vec) const
Returns the set centroid in the vector vec.
A templated class for handling sets.
Definition: VectorSet.h:52
void print(std::ostream &os) const
Prints the subsets (via protected attribute m_sets).
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
std::vector< const VectorSet< V, M > * > m_sets

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