queso-0.51.1
SampledVectorCdf.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/SampledVectorCdf.h>
26 
27 namespace QUESO {
28 
29 // Default constructor -----------------------------
30 template<class V,class M>
32  const char* prefix,
33  const ArrayOfOneDGrids <V,M>& oneDGrids,
34  const ArrayOfOneDTables<V,M>& cdfValues)
35  :
36  BaseVectorCdf<V,M>(prefix,oneDGrids.rowSpace()),
37  m_cdfs(m_pdfSupport.vectorSpace().map(),1)
38 {
39  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
40  *m_env.subDisplayFile() << "Entering SampledVectorCdf<V,M>::constructor()"
41  << ": prefix = " << m_prefix
42  << std::endl;
43  }
44 
45  char strI[65];
46  for (unsigned int i = 0; i < (unsigned int) m_cdfs.MyLength(); ++i) {
47  sprintf(strI,"%u_",i);
49  ((std::string)(m_prefix)+strI).c_str(),
50  oneDGrids.grid(i),
51  cdfValues.oneDTable(i));
52  }
53 
54  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
55  *m_env.subDisplayFile() << "Leaving SampledVectorCdf<V,M>::constructor()"
56  << ": prefix = " << m_prefix
57  << std::endl;
58  }
59 }
60 // Destructor ---------------------------------------
61 template<class V,class M>
63 {
64  for (unsigned int i = 0; i < (unsigned int) m_cdfs.MyLength(); ++i) {
65  if (m_cdfs(i,0)) delete m_cdfs(i,0);
66  }
67 }
68 // Math methods--------------------------------------
69 template<class V, class M>
70 void
72  const V& paramValues,
73  V& cdfVec) const
74 {
76  m_env.worldRank(),
77  "SampledVectorCdf<V,M>::cdfVec()",
78  "incomplete code");
79  return;
80 }
81 // --------------------------------------------------
82 template<class V, class M>
84 SampledVectorCdf<V,M>::cdf(unsigned int rowId) const
85 {
86  UQ_FATAL_TEST_MACRO(rowId >= m_pdfSupport.vectorSpace().dimLocal(),
87  m_env.worldRank(),
88  "SampledVectorCdf<T>::cdf()",
89  "rowId is out of range");
90 
91  SampledVectorCdf<V,M>* tmp = const_cast<SampledVectorCdf<V,M>*>(this);
92  return *(tmp->m_cdfs(rowId,0));
93 
94 }
95 // I/O methods---------------------------------------
96 template <class V, class M>
97 void
98 SampledVectorCdf<V,M>::print(std::ostream& os) const
99 {
100  SampledVectorCdf<V,M>* tmp = const_cast<SampledVectorCdf<V,M>*>(this);
101  for (unsigned int i = 0; i < (unsigned int) m_cdfs.MyLength(); ++i) {
102  os << (*tmp->m_cdfs(i,0))
103  << std::endl;
104  }
105 
106  return;
107 }
108 //---------------------------------------------------
109 template<class V, class M>
110 void
112  const std::string& varNamePrefix,
113  const std::string& fileName,
114  const std::string& fileType,
115  const std::set<unsigned int>& allowedSubEnvIds) const
116 {
117  UQ_FATAL_TEST_MACRO(m_env.subRank() < 0,
118  m_env.worldRank(),
119  "SampledVectorCdf<V,M>::subWriteContents()",
120  "unexpected subRank");
121 
122  SampledVectorCdf<V,M>* tmp = const_cast<SampledVectorCdf<V,M>*>(this);
123  char compId[16+1];
124  for (unsigned int i = 0; i < (unsigned int) m_cdfs.MyLength(); ++i) {
125  sprintf(compId,"%d",i);
126  tmp->m_cdfs(i,0)->subWriteContents(varNamePrefix+"comp"+compId,fileName,fileType,allowedSubEnvIds);
127  }
128 
129  return;
130 }
131 
132 } // End namespace QUESO
Class to accommodate arrays of one-dimensional grid.
A templated (base) class for handling CDFs of vector functions.
Definition: VectorCdf.h:56
const std::vector< double > & oneDTable(unsigned int rowId) const
Returns the array located at position rowId of the one-dimensional table.
std::string m_prefix
Definition: VectorCdf.h:102
const BaseEnvironment & m_env
Definition: VectorCdf.h:101
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
A templated (base) class for handling CDFs.
Definition: ScalarCdf.h:56
void subWriteContents(const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
Writes the CDF of an allowed sub-environment to a file.
A class for handling sampled vector CDFs.
void values(const V &paramValues, V &cdfVec) const
TODO: Returns the values of the vector CDF at each element of paramValues.
A class for handling sampled CDFs.
DistArray< SampledScalarCdf< double > * > m_cdfs
void print(std::ostream &os) const
Prints the vector CDF (values of the grid points and of the CDF at such grid points).
~SampledVectorCdf()
Destructor.
Class to accommodate arrays of one-dimensional tables.
SampledVectorCdf(const char *prefix, const ArrayOfOneDGrids< V, M > &oneDGrids, const ArrayOfOneDTables< V, M > &cdfValues)
Default constructor.
const BaseScalarCdf< double > & cdf(unsigned int rowId) const
Returns a scalar CDF stored at row rowId of the vector CDF.
unsigned int displayVerbosity() const
Definition: Environment.C:436
#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.

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