queso-0.53.0
GcmZInfo.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/GcmZInfo.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 // Case with no experiments
32 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
34  bool formCMatrix,
35  bool allOutputsAreScalar,
37  :
38  m_env (s.m_env),
39  m_z_size (s.m_w_size),
40  m_z_space (m_env, "z_", m_z_size, NULL),
41  m_Zvec_hat (m_z_space.zeroVector()),
42  m_Cmat (NULL), // to be deleted on destructor
43  m_Cmat_rank (0),
44  m_tmp_Smat_z (m_z_space.zeroVector()),
45  m_tmp_Smat_extra (m_z_space.zeroVector()),
46  m_tmp_Smat_z_hat (m_z_space.zeroVector()),
47  m_tmp_Smat_z_hat_inv(m_z_space.zeroVector())
48 {
49  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
50  *m_env.subDisplayFile() << "Entering GcmZInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(1)"
51  << std::endl;
52  }
53 
55 
56  //********************************************************************************
57  // Make checks
58  //********************************************************************************
59  queso_require_equal_to_msg(m_z_space.dimLocal(), (s.m_paper_m * s.m_paper_p_eta), "incompatible calculations for 'z' vector size (1)");
60 
62 
63  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
64  *m_env.subDisplayFile() << "Leaving GcmZInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(1)"
65  << std::endl;
66  }
67 }
68 
69 // Case with experiments, and with vector outputs
70 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
72  bool formCMatrix,
73  bool allOutputsAreScalar,
77  :
78  m_env (s.m_env),
79  m_z_size (s.m_w_size + e.m_v_size + jj.m_u_size),
80  m_z_space (m_env, "z_", m_z_size, NULL),
81  m_Zvec_hat (m_z_space.zeroVector()),
82  m_Cmat (NULL), // to be deleted on destructor
83  m_Cmat_rank (0),
84  m_tmp_Smat_z (m_z_space.zeroVector()),
85  m_tmp_Smat_extra (m_z_space.zeroVector()),
86  m_tmp_Smat_z_hat (m_z_space.zeroVector()),
87  m_tmp_Smat_z_hat_inv(m_z_space.zeroVector())
88 {
89  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
90  *m_env.subDisplayFile() << "Entering GcmZInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(2)"
91  << ": formCMatrix = " << formCMatrix
92  << std::endl;
93  }
94 
95  queso_require_msg(!allOutputsAreScalar, "'allOutputsAreScalar' should be false");
96 
97  m_Zvec_hat.cwSetConcatenated(jj.m_Zvec_hat_vu,s.m_Zvec_hat_w);
98 
99  if (formCMatrix) {
100  //********************************************************************************
101  // Form 'C' matrix
102  //********************************************************************************
103  m_Cmat = new D_M(m_env,jj.m_omega_space.map(),m_z_size);
104  m_Cmat_rank = std::min(m_Cmat->numRowsGlobal(),m_Cmat->numCols()); // Might be smaller
105 
106  //********************************************************************************
107  // Compute 'C' matrix
108  //********************************************************************************
109  m_Cmat->cwSet(0.);
110  m_Cmat->cwSet( 0, 0,*jj.m_Bmat_with_permut);
111  m_Cmat->cwSet(jj.m_Bmat_with_permut->numRowsLocal(),jj.m_Bmat_with_permut->numCols(), s.m_Kmat );
112 
113  m_Cmat_rank= m_Cmat->rank(0.,1.e-8 ); // todo: should be an option
114  unsigned int cRank14 = m_Cmat->rank(0.,1.e-14);
115  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
116  *m_env.subDisplayFile() << "In GcmZInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(2)"
117  << ": m_Cmat.numRowsLocal() = " << m_Cmat->numRowsLocal()
118  << ", m_Cmat.numCols() = " << m_Cmat->numCols()
119  << ", m_Cmat.rank(0.,1.e-8) = " << m_Cmat_rank
120  << ", m_Cmat.rank(0.,1.e-14) = " << cRank14
121  << std::endl;
122  }
123 
124  queso_require_equal_to_msg(m_Cmat_rank, (jj.m_Bmat_rank + s.m_Kmat_rank), "'m_Cmat_rank' should be the sum of 'B' and 'K' ranks");
125 
126  queso_require_greater_msg(m_Cmat->numRowsLocal(), m_Cmat->numCols(), "'m_Cmat' should be a 'vertical' rectangular matrix");
127 
128  queso_require_equal_to_msg(m_Cmat->numCols(), m_z_space.dimLocal(), "'m_Cmat' has invalid numCols");
129 
130  queso_require_less_equal_msg(m_Cmat_rank, m_Cmat->numCols(), "'m_Cmat' has invalid rank");
131  }
132 
133  //********************************************************************************
134  // Make checks
135  //********************************************************************************
136  queso_require_equal_to_msg(m_z_space.dimLocal(), (e.m_paper_n * e.m_paper_p_delta + e.m_paper_n * s.m_paper_p_eta + s.m_paper_m * s.m_paper_p_eta), "incompatible calculations for 'z' vector size (2)");
137 
139 
140  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
141  *m_env.subDisplayFile() << "Leaving GcmZInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(2)"
142  << std::endl;
143  }
144 }
145 
146 // Case with experiments, and with scalar outputs
147 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
149  bool allOutputsAreScalar,
152  :
153  m_env (s.m_env),
154  m_z_size (s.m_w_size + e.m_v_size),
155  m_z_space (m_env, "z_", m_z_size, NULL),
156  m_Zvec_hat (m_z_space.zeroVector()),
157  m_Cmat (NULL), // to be deleted on destructor
158  m_Cmat_rank (0),
159  m_tmp_Smat_z (m_z_space.zeroVector()),
160  m_tmp_Smat_extra (m_z_space.zeroVector()),
161  m_tmp_Smat_z_hat (m_z_space.zeroVector()),
162  m_tmp_Smat_z_hat_inv(m_z_space.zeroVector())
163 {
164  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
165  *m_env.subDisplayFile() << "Entering GcmZInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(3)"
166  << ": key-debug"
167  << ", some entities just created (not yet populated)"
168  << ", m_Zvec_hat.sizeLocal() = " << m_Zvec_hat.sizeLocal()
169  << std::endl;
170  }
171 
172  queso_require_msg(allOutputsAreScalar, "'allOutputsAreScalar' should be true");
173 
174  //m_Zvec_hat.cwSetConcatenated(e.m_Zvec_hat_v,s.m_Zvec_hat_w); // ppp
175 
176  //********************************************************************************
177  // Make checks
178  //********************************************************************************
179  queso_require_equal_to_msg(m_z_space.dimLocal(), (e.m_paper_n * e.m_paper_p_delta + e.m_paper_n * s.m_paper_p_eta + s.m_paper_m * s.m_paper_p_eta), "incompatible calculations for 'z' vector size (2)");
180 
182 
183  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
184  *m_env.subDisplayFile() << "Leaving GcmZInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(3)"
185  << std::endl;
186  }
187 }
188 
189 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
191 {
192  delete m_Cmat; // to be deleted on destructor
193 }
194 
195 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
196 void
198 {
199  //********************************************************************************
200  // Display information
201  //********************************************************************************
202  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
203  *m_env.subDisplayFile() << "In GcnZInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::commonConstructor()"
204  << "\n 'z' vector size = " << m_z_space.dimLocal() // = n * p_delta + n * p_eta + m * p_eta
205  << std::endl;
206  }
207 
208  return;
209 }
210 
211 } // End namespace QUESO
212 
unsigned int displayVerbosity() const
Definition: Environment.C:396
const BaseEnvironment & m_env
Definition: GcmZInfo.h:59
unsigned int dimLocal() const
Definition: VectorSpace.C:170
void commonConstructor()
Definition: GcmZInfo.C:197
const Map & map() const
Map.
Definition: VectorSpace.C:157
unsigned int m_Cmat_rank
Definition: GcmZInfo.h:65
#define queso_require_less_equal_msg(expr1, expr2, msg)
Definition: asserts.h:89
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
VectorSpace< D_V, D_M > m_z_space
Definition: GcmZInfo.h:61
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
D_M * m_Cmat
Definition: GcmZInfo.h:64
unsigned int m_Bmat_rank
Definition: GcmJointInfo.h:111
GcmZInfo(bool formCMatrix, bool allOutputsAreScalar, const GcmSimulationInfo< S_V, S_M, P_V, P_M, Q_V, Q_M > &s)
Definition: GcmZInfo.C:33
VectorSpace< D_V, D_M > m_omega_space
Definition: GcmJointInfo.h:104
#define queso_require_greater_msg(expr1, expr2, msg)
Definition: asserts.h:88
unsigned int m_z_size
Definition: GcmZInfo.h:60

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