queso-0.53.0
Private Member Functions | Private Attributes | List of all members
QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M > Class Template Reference

A templated class that implements a Monte Carlo generator of samples. More...

#include <MonteCarloSG.h>

Collaboration diagram for QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 MonteCarloSG (const char *prefix, const McOptionsValues *alternativeOptionsValues, const BaseVectorRV< P_V, P_M > &paramRv, const BaseVectorFunction< P_V, P_M, Q_V, Q_M > &qoiFunction)
 Constructor. More...
 
 ~MonteCarloSG ()
 Destructor. More...
 
Statistical methods
void generateSequence (BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq)
 Generates the QoI (output) sequence, it calls internGenerateSequence(). More...
 

Private Member Functions

void internGenerateSequence (const BaseVectorRV< P_V, P_M > &paramRv, BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq)
 Generates the QoI (output) sequence; it calls actualGenerateSequence(). More...
 
void actualGenerateSequence (const BaseVectorRV< P_V, P_M > &paramRv, BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq, unsigned int seqSize)
 This method actually generates the QoI sequence. More...
 
void actualReadSequence (const BaseVectorRV< P_V, P_M > &paramRv, const std::string &dataInputFileName, const std::string &dataInputFileType, BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq, unsigned int seqSize)
 Reads the sequence. More...
 

Private Attributes

const BaseEnvironmentm_env
 
const BaseVectorRV< P_V, P_M > & m_paramRv
 
const BaseVectorFunction< P_V,
P_M, Q_V, Q_M > & 
m_qoiFunction
 
const VectorSpace< P_V, P_M > & m_paramSpace
 
const VectorSpace< Q_V, Q_M > & m_qoiSpace
 
const
VectorFunctionSynchronizer
< P_V, P_M, Q_V, Q_M > * 
m_qoiFunctionSynchronizer
 
unsigned int m_numPsNotSubWritten
 
unsigned int m_numQsNotSubWritten
 
const McOptionsValuesm_optionsObj
 
bool m_userDidNotProvideOptions
 

I/O methods

void print (std::ostream &os) const
 Prints the sequence. More...
 
std::ostream & operator<< (std::ostream &os, const MonteCarloSG< P_V, P_M, Q_V, Q_M > &obj)
 

Detailed Description

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
class QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >

A templated class that implements a Monte Carlo generator of samples.

This class implements a Monte Carlo generator of samples. 'SG' stands for 'Sequence Generator'. Options reading is handled by class 'MonteCarloOptions'. If options request data to be written in the output file (MATLAB .m format only, for now), the user can check which MATLAB variables are defined and set by running 'grep zeros <OUTPUT file="" name>="">' after the solution procedures ends. The names of the variables are self explanatory.

Definition at line 52 of file MonteCarloSG.h.

Constructor & Destructor Documentation

template<class P_V , class P_M , class Q_V , class Q_M >
QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::MonteCarloSG ( const char *  prefix,
const McOptionsValues alternativeOptionsValues,
const BaseVectorRV< P_V, P_M > &  paramRv,
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > &  qoiFunction 
)

Constructor.

Requirements: 1) the image set of the vector random variable 'paramRv' and 2) the domain set of the QoI function 'qoiFunction' should belong to vector spaces of equal dimensions. If the requirements are satisfied, the constructor then reads input options that begin with the string '<prefix>_mc_'. For instance, if 'prefix' is 'pROblem_775_fp_', then the constructor will read all options that begin with 'pROblem_775_fp_mc_'. Options reading is handled by class 'MonteCarloOptions'.

Parameters
prefixPrefix
alternativeOptionsValuesOptions (if no input file)
paramRvThe parameter RV
qoiFunctionThe QoI function

Definition at line 33 of file MonteCarloSG.C.

References queso_require_equal_to_msg.

38  :
39  m_env (paramRv.env()),
40  m_paramRv (paramRv),
41  m_qoiFunction (qoiFunction),
43  m_qoiSpace (m_qoiFunction.imageSet().vectorSpace()),
44  m_qoiFunctionSynchronizer (new VectorFunctionSynchronizer<P_V,P_M,Q_V,Q_M>(m_qoiFunction,m_paramRv.imageSet().vectorSpace().zeroVector(),m_qoiFunction.imageSet().vectorSpace().zeroVector())),
47  m_optionsObj (alternativeOptionsValues),
49 {
50  if (m_env.subDisplayFile()) {
51  *m_env.subDisplayFile() << "Entering MonteCarloSG<P_V,P_M,Q_V,Q_M>::constructor()"
52  << ": prefix = " << prefix
53  << ", alternativeOptionsValues = " << alternativeOptionsValues
54  << ", m_env.optionsInputFileName() = " << m_env.optionsInputFileName()
55  << std::endl;
56  }
57 
58  // If NULL, we create one
59  if (m_optionsObj == NULL) {
60  McOptionsValues * tempOptions = new McOptionsValues(&m_env, prefix);
61 
62  // We did this dance because scanOptionsValues is not a const method, but
63  // m_optionsObj is a pointer to const
64  m_optionsObj = tempOptions;
65 
66  // We do this so we don't delete the user's object in the dtor
68  }
69 
70  if (m_optionsObj->m_help != "") {
71  if (m_env.subDisplayFile()) {
72  *m_env.subDisplayFile() << (*m_optionsObj) << std::endl;
73  }
74  }
75 
76  queso_require_equal_to_msg(paramRv.imageSet().vectorSpace().dimLocal(), qoiFunction.domainSet().vectorSpace().dimLocal(), "'paramRv' and 'qoiFunction' are related to vector spaces of different dimensions");
77 
78  if (m_env.subDisplayFile()) {
79  *m_env.subDisplayFile() << "Leaving MonteCarloSG<P_V,P_M,Q_V,Q_M>::constructor()"
80  << std::endl;
81  }
82 }
unsigned int dimLocal() const
Definition: VectorSpace.C:170
const BaseEnvironment & m_env
Definition: MonteCarloSG.h:124
const BaseEnvironment & env() const
QUESO environment; access to private attribute m_env.
Definition: VectorRV.C:72
const VectorSpace< Q_V, Q_M > & m_qoiSpace
Definition: MonteCarloSG.h:128
const BaseVectorRV< P_V, P_M > & m_paramRv
Definition: MonteCarloSG.h:125
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:189
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:307
const VectorSpace< P_V, P_M > & m_paramSpace
Definition: MonteCarloSG.h:127
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
unsigned int m_numQsNotSubWritten
Definition: MonteCarloSG.h:131
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > & m_qoiFunction
Definition: MonteCarloSG.h:126
std::string m_help
If non-empty string, print options and values to output file.
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
const McOptionsValues * m_optionsObj
Definition: MonteCarloSG.h:133
const VectorFunctionSynchronizer< P_V, P_M, Q_V, Q_M > * m_qoiFunctionSynchronizer
Definition: MonteCarloSG.h:129
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
unsigned int m_numPsNotSubWritten
Definition: MonteCarloSG.h:130
template<class P_V , class P_M , class Q_V , class Q_M >
QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::~MonteCarloSG ( )

Destructor.

Definition at line 85 of file MonteCarloSG.C.

86 {
88  delete m_optionsObj;
89  }
90 
92 }
const McOptionsValues * m_optionsObj
Definition: MonteCarloSG.h:133
const VectorFunctionSynchronizer< P_V, P_M, Q_V, Q_M > * m_qoiFunctionSynchronizer
Definition: MonteCarloSG.h:129

Member Function Documentation

template<class P_V , class P_M , class Q_V , class Q_M >
void QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::actualGenerateSequence ( const BaseVectorRV< P_V, P_M > &  paramRv,
BaseVectorSequence< P_V, P_M > &  workingPSeq,
BaseVectorSequence< Q_V, Q_M > &  workingQSeq,
unsigned int  seqSize 
)
private

This method actually generates the QoI sequence.

Requirements: 1) the vector space containing the domain set of the QoI function 'm_qoiFunction' should have dimension equal to the size of a vector in 'workingPSeq' and 2) the vector space containing the image set of the qoi function 'm_qoiFunction' should have dimension equal to the size of a vector in 'workingQSeq'. If the requirements are satisfied, this operation sets the size and the contents of 'workingPSeq' and 'workingQSeq' using the algorithm options set in the constructor.

Definition at line 334 of file MonteCarloSG.C.

References QUESO::BaseVectorSequence< V, M >::getPositionValues(), QUESO::MiscGetEllapsedSeconds(), QUESO::BaseVectorSequence< V, M >::name(), QUESO::BaseVectorRealizer< V, M >::realization(), QUESO::BaseVectorRV< V, M >::realizer(), QUESO::BaseVectorSequence< V, M >::resizeSequence(), QUESO::BaseVectorSequence< V, M >::setPositionValues(), QUESO::BaseVectorSequence< V, M >::subSequenceSize(), QUESO::BaseVectorSequence< V, M >::subWriteContents(), and QUESO::UQ_OK_RC.

339 {
340  if (m_env.subDisplayFile()) {
341  *m_env.subDisplayFile() << "Starting the generation of qoi sequence " << workingQSeq.name()
342  << ", with " << requestedSeqSize
343  << " samples..."
344  << std::endl;
345  }
346 
347  int iRC = UQ_OK_RC;
348  struct timeval timevalSeq;
349  struct timeval timevalQoIFunction;
350 
351  double seqRunTime = 0;
352  double qoiFunctionRunTime = 0;
353 
354  iRC = gettimeofday(&timevalSeq, NULL);
355  if (iRC) {}; // just to remover compiler warning
356 
357  workingPSeq.resizeSequence(requestedSeqSize);
359  workingQSeq.resizeSequence(requestedSeqSize);
361 
362  P_V tmpP(m_paramSpace.zeroVector());
363  Q_V tmpQ(m_qoiSpace.zeroVector());
364 
365  unsigned int actualSeqSize = 0;
366  for (unsigned int i = 0; i < requestedSeqSize; ++i) {
367  paramRv.realizer().realization(tmpP);
368 
369  if (m_optionsObj->m_qseqMeasureRunTimes) iRC = gettimeofday(&timevalQoIFunction, NULL);
370  m_qoiFunctionSynchronizer->callFunction(&tmpP,NULL,&tmpQ,NULL,NULL,NULL); // Might demand parallel environment
371  if (m_optionsObj->m_qseqMeasureRunTimes) qoiFunctionRunTime += MiscGetEllapsedSeconds(&timevalQoIFunction);
372 
373  bool allQsAreFinite = true;
374  for (unsigned int j = 0; j < tmpQ.sizeLocal(); ++j) {
375  if ((tmpQ[j] == INFINITY) || (tmpQ[j] == -INFINITY)) {
376  std::cerr << "WARNING In MonteCarloSG<P_V,P_M,Q_V,Q_M>::actualGenerateSequence()"
377  << ", worldRank " << m_env.worldRank()
378  << ", fullRank " << m_env.fullRank()
379  << ", subEnvironment " << m_env.subId()
380  << ", subRank " << m_env.subRank()
381  << ", inter0Rank " << m_env.inter0Rank()
382  << ": i = " << i
383  << ", tmpQ[" << j << "] = " << tmpQ[j]
384  << ", tmpP = " << tmpP
385  << ", tmpQ = " << tmpQ
386  << std::endl;
387  allQsAreFinite = false;
388 
389  if (i > 0) {
390  workingPSeq.getPositionValues(i-1,tmpP); // FIXME: temporary code
391  workingQSeq.getPositionValues(i-1,tmpQ); // FIXME: temporary code
392  }
393 
394  break;
395  }
396  }
397  if (allQsAreFinite) {}; // just to remover compiler warning
398 
399  //if (allQsAreFinite) { // FIXME: this will cause different processors to have sequences of different sizes
400  workingPSeq.setPositionValues(i,tmpP);
402  if ((m_optionsObj->m_pseqDataOutputPeriod > 0 ) &&
403  (((i+1) % m_optionsObj->m_pseqDataOutputPeriod) == 0 ) &&
410  if (m_env.subDisplayFile()) {
411  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::actualGenerateSequence()"
412  << ": just wrote pseq positions (per period request)"
413  << std::endl;
414  }
416  }
417 
418  workingQSeq.setPositionValues(i,tmpQ);
420  if ((m_optionsObj->m_qseqDataOutputPeriod > 0 ) &&
421  (((i+1) % m_optionsObj->m_qseqDataOutputPeriod) == 0 ) &&
428  if (m_env.subDisplayFile()) {
429  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::actualGenerateSequence()"
430  << ": just wrote qseq positions (per period request)"
431  << std::endl;
432  }
434  }
435 
436  actualSeqSize++;
437 
438  //}
439 
440  if ((m_optionsObj->m_qseqDisplayPeriod > 0) &&
441  (((i+1) % m_optionsObj->m_qseqDisplayPeriod) == 0)) {
442  if (m_env.subDisplayFile()) {
443  *m_env.subDisplayFile() << "Finished generating " << i+1
444  << " qoi samples"
445  << std::endl;
446  }
447  }
448  }
449 
450  //if (actualSeqSize != requestedSeqSize) {
451  // workingPSeq.resizeSequence(actualSeqSize);
452  // workingQSeq.resizeSequence(actualSeqSize);
453  //}
454 
455  seqRunTime = MiscGetEllapsedSeconds(&timevalSeq);
456 
457  if (m_env.subDisplayFile()) {
458  *m_env.subDisplayFile() << "Finished the generation of qoi sequence " << workingQSeq.name()
459  << ", with sub " << workingQSeq.subSequenceSize()
460  << " samples"
461  << "\nSome information about this sequence:"
462  << "\n Sequence run time = " << seqRunTime
463  << " seconds"
464  << "\n\n Breaking of the seq run time:\n"
465  << "\n QoI function run time = " << qoiFunctionRunTime
466  << " seconds (" << 100.*qoiFunctionRunTime/seqRunTime
467  << "%)"
468  << std::endl;
469  }
470 
471  return;
472 }
const BaseVectorRealizer< V, M > & realizer() const
Finds a realization (sample) of the PDF of this vector RV; access to private attribute m_realizer...
Definition: VectorRV.C:95
int subRank() const
Access function for sub-rank.
Definition: Environment.C:241
const BaseEnvironment & m_env
Definition: MonteCarloSG.h:124
virtual void subWriteContents(unsigned int initialPos, unsigned int numPos, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const =0
Writes info of the sub-sequence to a file. See template specialization.
int fullRank() const
Returns the process full rank.
Definition: Environment.C:222
const VectorSpace< Q_V, Q_M > & m_qoiSpace
Definition: MonteCarloSG.h:128
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:261
std::set< unsigned int > m_pseqDataOutputAllowedSet
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:189
virtual void realization(V &nextValues) const =0
Performs a realization (sample) from a probability density function. See template specialization...
double MiscGetEllapsedSeconds(struct timeval *timeval0)
const VectorSpace< P_V, P_M > & m_paramSpace
Definition: MonteCarloSG.h:127
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:295
const int UQ_OK_RC
Definition: Defines.h:76
unsigned int m_numQsNotSubWritten
Definition: MonteCarloSG.h:131
const std::string & name() const
Access to protected attribute m_name: name of the sequence of vectors.
virtual void getPositionValues(unsigned int posId, V &vec) const =0
Gets the values of the sequence at position posId and stores them at vec. See template specialization...
virtual void resizeSequence(unsigned int newSubSequenceSize)=0
Resize the sequence. See template specialization.
const McOptionsValues * m_optionsObj
Definition: MonteCarloSG.h:133
const VectorFunctionSynchronizer< P_V, P_M, Q_V, Q_M > * m_qoiFunctionSynchronizer
Definition: MonteCarloSG.h:129
std::set< unsigned int > m_qseqDataOutputAllowedSet
int worldRank() const
Returns the process world rank.
Definition: Environment.C:216
virtual unsigned int subSequenceSize() const =0
Size of the sub-sequence of vectors. See template specialization.
unsigned int m_numPsNotSubWritten
Definition: MonteCarloSG.h:130
virtual void setPositionValues(unsigned int posId, const V &vec)=0
Set the values in vec at position posId of the sequence. See template specialization.
template<class P_V , class P_M , class Q_V , class Q_M >
void QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::actualReadSequence ( const BaseVectorRV< P_V, P_M > &  paramRv,
const std::string &  dataInputFileName,
const std::string &  dataInputFileType,
BaseVectorSequence< P_V, P_M > &  workingPSeq,
BaseVectorSequence< Q_V, Q_M > &  workingQSeq,
unsigned int  seqSize 
)
private

Reads the sequence.

Definition at line 476 of file MonteCarloSG.C.

References QUESO::BaseVectorRealizer< V, M >::realization(), QUESO::BaseVectorRV< V, M >::realizer(), QUESO::BaseVectorSequence< V, M >::resizeSequence(), QUESO::BaseVectorSequence< V, M >::setPositionValues(), and QUESO::BaseVectorSequence< V, M >::unifiedReadContents().

483 {
484  workingPSeq.resizeSequence(requestedSeqSize);
485  P_V tmpP(m_paramSpace.zeroVector());
486  for (unsigned int i = 0; i < requestedSeqSize; ++i) {
487  paramRv.realizer().realization(tmpP);
488  workingPSeq.setPositionValues(i,tmpP);
489  }
490 
491  workingQSeq.unifiedReadContents(dataInputFileName,dataInputFileType,requestedSeqSize);
492 
493  return;
494 }
const BaseVectorRealizer< V, M > & realizer() const
Finds a realization (sample) of the PDF of this vector RV; access to private attribute m_realizer...
Definition: VectorRV.C:95
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:189
virtual void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)=0
Reads info of the unified sequence from a file. See template specialization.
virtual void realization(V &nextValues) const =0
Performs a realization (sample) from a probability density function. See template specialization...
const VectorSpace< P_V, P_M > & m_paramSpace
Definition: MonteCarloSG.h:127
virtual void resizeSequence(unsigned int newSubSequenceSize)=0
Resize the sequence. See template specialization.
virtual void setPositionValues(unsigned int posId, const V &vec)=0
Set the values in vec at position posId of the sequence. See template specialization.
template<class P_V , class P_M , class Q_V , class Q_M >
void QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::generateSequence ( BaseVectorSequence< P_V, P_M > &  workingPSeq,
BaseVectorSequence< Q_V, Q_M > &  workingQSeq 
)

Generates the QoI (output) sequence, it calls internGenerateSequence().

This method checks for a parallel environment (and uses it if available) and calls the private member function internGenerateSequence() to generate a sequence of values of the Quantity of interest (QoI).

Definition at line 96 of file MonteCarloSG.C.

References queso_require_equal_to_msg, and QUESO::BaseVectorSequence< V, M >::vectorSizeLocal().

99 {
100  queso_require_equal_to_msg(m_qoiFunction.domainSet().vectorSpace().dimLocal(), workingPSeq.vectorSizeLocal(), "'m_qoiFunction.domainSet' and 'workingPSeq' are related to vector spaces of different dimensions");
101 
102  queso_require_equal_to_msg(m_qoiFunction.imageSet().vectorSpace().dimLocal(), workingQSeq.vectorSizeLocal(), "'m_qoiFunction.imageSet' and 'workingQSeq' are related to vector spaces of different dimensions");
103 
104  MiscCheckTheParallelEnvironment<P_V,Q_V>(m_paramRv.imageSet().vectorSpace().zeroVector(),
105  m_qoiFunction.imageSet().vectorSpace().zeroVector());
106  internGenerateSequence(m_paramRv,workingPSeq,workingQSeq);
107 
108  return;
109 }
unsigned int vectorSizeLocal() const
Local dimension (size) of the vector space.
void internGenerateSequence(const BaseVectorRV< P_V, P_M > &paramRv, BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq)
Generates the QoI (output) sequence; it calls actualGenerateSequence().
Definition: MonteCarloSG.C:120
const BaseVectorRV< P_V, P_M > & m_paramRv
Definition: MonteCarloSG.h:125
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:189
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > & m_qoiFunction
Definition: MonteCarloSG.h:126
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
template<class P_V , class P_M , class Q_V , class Q_M >
void QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::internGenerateSequence ( const BaseVectorRV< P_V, P_M > &  paramRv,
BaseVectorSequence< P_V, P_M > &  workingPSeq,
BaseVectorSequence< Q_V, Q_M > &  workingQSeq 
)
private

Generates the QoI (output) sequence; it calls actualGenerateSequence().

This method calls the private member actualGenerateSequence() to actually generate a sequence of values of the Quantity of interest (QoI). It writes both the QoI and the parameter sequences to output files. If a parallel environment is available, the user has the choice of (via the input options file) which sub-environment will write data to files. The unified sequence of data (QoI and/or Parameter sequences) of all the sub-environments (or of the single environment, in case of a serial run) is also written to files.

Definition at line 120 of file MonteCarloSG.C.

References QUESO::BaseVectorSequence< V, M >::name(), QUESO::FilePtrSetStruct::ofsVar, queso_require_equal_to_msg, QUESO::BaseVectorRV< V, M >::realizer(), QUESO::BaseVectorSequence< V, M >::setName(), QUESO::BaseVectorRealizer< V, M >::subPeriod(), QUESO::BaseVectorSequence< V, M >::subSequenceSize(), QUESO::BaseVectorSequence< V, M >::subWriteContents(), QUESO::BaseVectorSequence< V, M >::unifiedWriteContents(), UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT, and UQ_MOC_SG_FILENAME_FOR_NO_FILE.

124 {
125  workingPSeq.setName(m_optionsObj->m_prefix+"ParamSeq");
126  workingQSeq.setName(m_optionsObj->m_prefix+"QoiSeq");
127 
128  //****************************************************
129  // Generate sequence of QoI values
130  //****************************************************
131  unsigned int subActualSizeBeforeGeneration = std::min(m_optionsObj->m_qseqSize,paramRv.realizer().subPeriod());
132  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
133  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
134  << ": m_optionsObj->m_qseqSize = " << m_optionsObj->m_qseqSize
135  << ", paramRv.realizer().subPeriod() = " << paramRv.realizer().subPeriod()
136  << ", about to call actualGenerateSequence() with subActualSize = " << subActualSizeBeforeGeneration
137  << std::endl;
138  }
140  actualGenerateSequence(paramRv,
141  workingPSeq,
142  workingQSeq,
143  subActualSizeBeforeGeneration);
144  }
145  else {
146  actualReadSequence(paramRv,
149  workingPSeq,
150  workingQSeq,
151  subActualSizeBeforeGeneration);
152  }
153  unsigned int subActualSizeAfterGeneration = workingPSeq.subSequenceSize();
154  queso_require_equal_to_msg(subActualSizeAfterGeneration, workingQSeq.subSequenceSize(), "P and Q sequences should have the same size!");
155 
156  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
157  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
158  << ": returned from call to actualGenerateSequence() with subActualSize = " << subActualSizeAfterGeneration
159  << std::endl;
160  }
161 
162  //****************************************************
163  // Open generic output file
164  //****************************************************
165  if (m_env.subDisplayFile()) {
166  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
167  << ", prefix = " << m_optionsObj->m_prefix
168  << ": checking necessity of opening generic output file (qseq name is " << workingQSeq.name()
169  << ") ..."
170  << std::endl;
171  }
172  FilePtrSetStruct genericFilePtrSet;
174  UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT, // Yes, always ".m"
176  false,
177  genericFilePtrSet);
178 
179  //****************************************************
180  // Eventually:
181  // --> write parameter sequence
182  // --> compute statistics on it
183  //****************************************************
184  if (m_env.subDisplayFile()) {
185  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
186  << ", prefix = " << m_optionsObj->m_prefix
187  << ": checking necessity of opening output files for pseq " << workingPSeq.name()
188  << "..."
189  << std::endl;
190  }
191 
192  // Take "sub" care of pseq
193  if ((m_numPsNotSubWritten > 0 ) &&
195  workingPSeq.subWriteContents(subActualSizeBeforeGeneration - m_numPsNotSubWritten,
200  if (m_env.subDisplayFile()) {
201  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::internGenerateSequence()"
202  << ": just wrote remaining pseq positions (per period request)"
203  << std::endl;
204  }
206  //if (m_env.subDisplayFile()) {
207  // *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
208  // << ", prefix = " << m_optionsObj->m_prefix
209  // << ": closed data output file '" << m_optionsObj->m_pseqDataOutputFileName
210  // << "' for pseq " << workingPSeq.name()
211  // << std::endl;
212  //}
213  }
214 
215  // Take "unified" care of pseq
218  if (m_env.subDisplayFile()) {
219  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
220  << ", prefix = " << m_optionsObj->m_prefix
221  << ": closed unified data output file '" << m_optionsObj->m_pseqDataOutputFileName
222  << "' for pseq " << workingPSeq.name()
223  << std::endl;
224  }
225  }
226 
227  // Take case of other aspects of pseq
228 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
229  if (m_optionsObj->m_pseqComputeStats) {
230  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
231  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
232  << ": about to call 'workingPSeq.computeStatistics()'"
233  << std::endl;
234  }
235  workingPSeq.computeStatistics(*m_optionsObj->m_pseqStatisticalOptionsObj,
236  genericFilePtrSet.ofsVar);
237  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
238  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
239  << ": returned from call to 'workingPSeq.computeStatistics()'"
240  << std::endl;
241  }
242  }
243 #endif
244  //****************************************************
245  // Eventually:
246  // --> write QoI sequence
247  // --> compute statistics on it
248  //****************************************************
249  if (m_env.subDisplayFile()) {
250  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
251  << ", prefix = " << m_optionsObj->m_prefix
252  << ": checking necessity of opening output files for qseq " << workingQSeq.name()
253  << "..."
254  << std::endl;
255  }
256 
257  // Take "sub" care of qseq
258  if ((m_numQsNotSubWritten > 0 ) &&
260  workingQSeq.subWriteContents(subActualSizeBeforeGeneration - m_numQsNotSubWritten,
265  if (m_env.subDisplayFile()) {
266  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::internGenerateSequence()"
267  << ": just wrote remaining qseq positions (per period request)"
268  << std::endl;
269  }
271  //if (m_env.subDisplayFile()) {
272  // *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
273  // << ", prefix = " << m_optionsObj->m_prefix
274  // << ": closed data output file '" << m_optionsObj->m_qseqDataOutputFileName
275  // << "' for qseq " << workingQSeq.name()
276  // << std::endl;
277  //}
278  }
279 
280  // Take "unified" care of qseq
283  if (m_env.subDisplayFile()) {
284  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
285  << ", prefix = " << m_optionsObj->m_prefix
286  << ": closed unified data output file '" << m_optionsObj->m_qseqDataOutputFileName
287  << "' for qseq " << workingQSeq.name()
288  << std::endl;
289  }
290  }
291 
292  // Take case of other aspects of qseq
293 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
294  if (m_optionsObj->m_qseqComputeStats) {
295  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
296  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
297  << ": about to call 'workingQSeq.computeStatistics()'"
298  << std::endl;
299  }
300  workingQSeq.computeStatistics(*m_optionsObj->m_qseqStatisticalOptionsObj,
301  genericFilePtrSet.ofsVar);
302  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
303  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
304  << ": returned from call to 'workingQSeq.computeStatistics()'"
305  << std::endl;
306  }
307  }
308 #endif
309  //****************************************************
310  // Close generic output file
311  //****************************************************
312  if (genericFilePtrSet.ofsVar) {
313  //std::cout << "TODAY 000" << std::endl;
314  delete genericFilePtrSet.ofsVar;
315  //genericFilePtrSet.ofsVar->close();
316  //std::cout << "TODAY 001" << std::endl;
317  if (m_env.subDisplayFile()) {
318  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
319  << ", prefix = " << m_optionsObj->m_prefix
320  << ": closed generic data output file '" << m_optionsObj->m_dataOutputFileName
321  << "' for QoI sequence " << workingQSeq.name()
322  << std::endl;
323  }
324  }
325  if (m_env.subDisplayFile()) {
326  *m_env.subDisplayFile() << std::endl;
327  }
328 
329  return;
330 }
unsigned int displayVerbosity() const
Definition: Environment.C:396
const BaseVectorRealizer< V, M > & realizer() const
Finds a realization (sample) of the PDF of this vector RV; access to private attribute m_realizer...
Definition: VectorRV.C:95
#define UQ_MOC_SG_FILENAME_FOR_NO_FILE
const BaseEnvironment & m_env
Definition: MonteCarloSG.h:124
virtual void subWriteContents(unsigned int initialPos, unsigned int numPos, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const =0
Writes info of the sub-sequence to a file. See template specialization.
void actualGenerateSequence(const BaseVectorRV< P_V, P_M > &paramRv, BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq, unsigned int seqSize)
This method actually generates the QoI sequence.
Definition: MonteCarloSG.C:334
unsigned int subPeriod() const
Sub-period of the realization. Access to protected attribute m_subPeriod.
std::set< unsigned int > m_pseqDataOutputAllowedSet
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
void actualReadSequence(const BaseVectorRV< P_V, P_M > &paramRv, const std::string &dataInputFileName, const std::string &dataInputFileType, BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq, unsigned int seqSize)
Reads the sequence.
Definition: MonteCarloSG.C:476
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
Definition: Defines.h:89
unsigned int m_numQsNotSubWritten
Definition: MonteCarloSG.h:131
virtual void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const =0
Writes info of the unified sequence to a file. See template specialization.
const std::string & name() const
Access to protected attribute m_name: name of the sequence of vectors.
const McOptionsValues * m_optionsObj
Definition: MonteCarloSG.h:133
bool openOutputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, bool writeOver, FilePtrSetStruct &filePtrSet) const
Opens an output file for each sub-environment that was chosen to send data to the file...
Definition: Environment.C:467
std::set< unsigned int > m_dataOutputAllowedSet
std::set< unsigned int > m_qseqDataOutputAllowedSet
virtual unsigned int subSequenceSize() const =0
Size of the sub-sequence of vectors. See template specialization.
unsigned int m_numPsNotSubWritten
Definition: MonteCarloSG.h:130
void setName(const std::string &newName)
Changes the name of the sequence of vectors.
template<class P_V , class P_M , class Q_V , class Q_M >
void QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::print ( std::ostream &  os) const

Prints the sequence.

Definition at line 113 of file MonteCarloSG.C.

114 {
115  return;
116 }

Friends And Related Function Documentation

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
std::ostream& operator<< ( std::ostream &  os,
const MonteCarloSG< P_V, P_M, Q_V, Q_M > &  obj 
)
friend

Definition at line 86 of file MonteCarloSG.h.

87  {
88  obj.print(os);
89  return os;
90  }

Member Data Documentation

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
const BaseEnvironment& QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_env
private

Definition at line 124 of file MonteCarloSG.h.

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
unsigned int QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_numPsNotSubWritten
private

Definition at line 130 of file MonteCarloSG.h.

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
unsigned int QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_numQsNotSubWritten
private

Definition at line 131 of file MonteCarloSG.h.

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
const McOptionsValues* QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_optionsObj
private

Definition at line 133 of file MonteCarloSG.h.

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
const BaseVectorRV<P_V,P_M>& QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_paramRv
private

Definition at line 125 of file MonteCarloSG.h.

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
const VectorSpace<P_V,P_M>& QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_paramSpace
private

Definition at line 127 of file MonteCarloSG.h.

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
const BaseVectorFunction<P_V,P_M,Q_V,Q_M>& QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_qoiFunction
private

Definition at line 126 of file MonteCarloSG.h.

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
const VectorFunctionSynchronizer<P_V,P_M,Q_V,Q_M>* QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_qoiFunctionSynchronizer
private

Definition at line 129 of file MonteCarloSG.h.

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
const VectorSpace<Q_V,Q_M>& QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_qoiSpace
private

Definition at line 128 of file MonteCarloSG.h.

template<class P_V = GslVector, class P_M = GslMatrix, class Q_V = GslVector, class Q_M = GslMatrix>
bool QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_userDidNotProvideOptions
private

Definition at line 135 of file MonteCarloSG.h.


The documentation for this class was generated from the following files:

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