queso-0.51.1
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
 
McOptionsValues m_alternativeOptionsValues
 
MonteCarloSGOptionsm_optionsObj
 

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, class P_M, class Q_V, class Q_M>
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 49 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 UQ_FATAL_TEST_MACRO.

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 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
48  m_alternativeOptionsValues(NULL,NULL),
49 #else
51 #endif
52  m_optionsObj (NULL)
53 {
54  if (m_env.subDisplayFile()) {
55  *m_env.subDisplayFile() << "Entering MonteCarloSG<P_V,P_M,Q_V,Q_M>::constructor()"
56  << ": prefix = " << prefix
57  << ", alternativeOptionsValues = " << alternativeOptionsValues
58  << ", m_env.optionsInputFileName() = " << m_env.optionsInputFileName()
59  << std::endl;
60  }
61 
62  if (alternativeOptionsValues) m_alternativeOptionsValues = *alternativeOptionsValues;
63  if (m_env.optionsInputFileName() == "") {
64  m_optionsObj = new MonteCarloSGOptions(m_env,prefix,m_alternativeOptionsValues);
65  }
66  else {
67  m_optionsObj = new MonteCarloSGOptions(m_env,prefix);
69  }
70 
71  UQ_FATAL_TEST_MACRO(paramRv.imageSet().vectorSpace().dimLocal() != qoiFunction.domainSet().vectorSpace().dimLocal(),
72  m_env.worldRank(),
73  "MonteCarloSG<P_V,P_M,Q_V,Q_M>::constructor()",
74  "'paramRv' and 'qoiFunction' are related to vector spaces of different dimensions");
75 
76  if (m_env.subDisplayFile()) {
77  *m_env.subDisplayFile() << "Leaving MonteCarloSG<P_V,P_M,Q_V,Q_M>::constructor()"
78  << std::endl;
79  }
80 }
unsigned int dimLocal() const
Definition: VectorSpace.C:199
const BaseEnvironment & m_env
Definition: MonteCarloSG.h:121
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
const VectorSpace< P_V, P_M > & m_paramSpace
Definition: MonteCarloSG.h:124
unsigned int m_numQsNotSubWritten
Definition: MonteCarloSG.h:128
const VectorSpace< Q_V, Q_M > & m_qoiSpace
Definition: MonteCarloSG.h:125
const VectorFunctionSynchronizer< P_V, P_M, Q_V, Q_M > * m_qoiFunctionSynchronizer
Definition: MonteCarloSG.h:126
void scanOptionsValues()
It scans the option values from the options input file.
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:341
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > & m_qoiFunction
Definition: MonteCarloSG.h:123
MonteCarloSGOptions * m_optionsObj
Definition: MonteCarloSG.h:131
const BaseEnvironment & env() const
QUESO environment; access to private attribute m_env.
Definition: VectorRV.C:72
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:218
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
McOptionsValues m_alternativeOptionsValues
Definition: MonteCarloSG.h:130
const BaseVectorRV< P_V, P_M > & m_paramRv
Definition: MonteCarloSG.h:122
unsigned int m_numPsNotSubWritten
Definition: MonteCarloSG.h:127
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 83 of file MonteCarloSG.C.

84 {
85  if (m_optionsObj ) delete m_optionsObj;
87 }
const VectorFunctionSynchronizer< P_V, P_M, Q_V, Q_M > * m_qoiFunctionSynchronizer
Definition: MonteCarloSG.h:126
MonteCarloSGOptions * m_optionsObj
Definition: MonteCarloSG.h:131

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 338 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.

343 {
344  if (m_env.subDisplayFile()) {
345  *m_env.subDisplayFile() << "Starting the generation of qoi sequence " << workingQSeq.name()
346  << ", with " << requestedSeqSize
347  << " samples..."
348  << std::endl;
349  }
350 
351  int iRC = UQ_OK_RC;
352  struct timeval timevalSeq;
353  struct timeval timevalQoIFunction;
354 
355  double seqRunTime = 0;
356  double qoiFunctionRunTime = 0;
357 
358  iRC = gettimeofday(&timevalSeq, NULL);
359  if (iRC) {}; // just to remover compiler warning
360 
361  workingPSeq.resizeSequence(requestedSeqSize);
363  workingQSeq.resizeSequence(requestedSeqSize);
365 
366  P_V tmpP(m_paramSpace.zeroVector());
367  Q_V tmpQ(m_qoiSpace.zeroVector());
368 
369  unsigned int actualSeqSize = 0;
370  for (unsigned int i = 0; i < requestedSeqSize; ++i) {
371  paramRv.realizer().realization(tmpP);
372 
373  if (m_optionsObj->m_ov.m_qseqMeasureRunTimes) iRC = gettimeofday(&timevalQoIFunction, NULL);
374  m_qoiFunctionSynchronizer->callFunction(&tmpP,NULL,&tmpQ,NULL,NULL,NULL); // Might demand parallel environment
375  if (m_optionsObj->m_ov.m_qseqMeasureRunTimes) qoiFunctionRunTime += MiscGetEllapsedSeconds(&timevalQoIFunction);
376 
377  bool allQsAreFinite = true;
378  for (unsigned int j = 0; j < tmpQ.sizeLocal(); ++j) {
379  if ((tmpQ[j] == INFINITY) || (tmpQ[j] == -INFINITY)) {
380  std::cerr << "WARNING In MonteCarloSG<P_V,P_M,Q_V,Q_M>::actualGenerateSequence()"
381  << ", worldRank " << m_env.worldRank()
382  << ", fullRank " << m_env.fullRank()
383  << ", subEnvironment " << m_env.subId()
384  << ", subRank " << m_env.subRank()
385  << ", inter0Rank " << m_env.inter0Rank()
386  << ": i = " << i
387  << ", tmpQ[" << j << "] = " << tmpQ[j]
388  << ", tmpP = " << tmpP
389  << ", tmpQ = " << tmpQ
390  << std::endl;
391  allQsAreFinite = false;
392 
393  if (i > 0) {
394  workingPSeq.getPositionValues(i-1,tmpP); // FIXME: temporary code
395  workingQSeq.getPositionValues(i-1,tmpQ); // FIXME: temporary code
396  }
397 
398  break;
399  }
400  }
401  if (allQsAreFinite) {}; // just to remover compiler warning
402 
403  //if (allQsAreFinite) { // FIXME: this will cause different processors to have sequences of different sizes
404  workingPSeq.setPositionValues(i,tmpP);
407  (((i+1) % m_optionsObj->m_ov.m_pseqDataOutputPeriod) == 0 ) &&
414  if (m_env.subDisplayFile()) {
415  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::actualGenerateSequence()"
416  << ": just wrote pseq positions (per period request)"
417  << std::endl;
418  }
420  }
421 
422  workingQSeq.setPositionValues(i,tmpQ);
425  (((i+1) % m_optionsObj->m_ov.m_qseqDataOutputPeriod) == 0 ) &&
432  if (m_env.subDisplayFile()) {
433  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::actualGenerateSequence()"
434  << ": just wrote qseq positions (per period request)"
435  << std::endl;
436  }
438  }
439 
440  actualSeqSize++;
441 
442  //}
443 
444  if ((m_optionsObj->m_ov.m_qseqDisplayPeriod > 0) &&
445  (((i+1) % m_optionsObj->m_ov.m_qseqDisplayPeriod) == 0)) {
446  if (m_env.subDisplayFile()) {
447  *m_env.subDisplayFile() << "Finished generating " << i+1
448  << " qoi samples"
449  << std::endl;
450  }
451  }
452  }
453 
454  //if (actualSeqSize != requestedSeqSize) {
455  // workingPSeq.resizeSequence(actualSeqSize);
456  // workingQSeq.resizeSequence(actualSeqSize);
457  //}
458 
459  seqRunTime = MiscGetEllapsedSeconds(&timevalSeq);
460 
461  if (m_env.subDisplayFile()) {
462  *m_env.subDisplayFile() << "Finished the generation of qoi sequence " << workingQSeq.name()
463  << ", with sub " << workingQSeq.subSequenceSize()
464  << " samples"
465  << "\nSome information about this sequence:"
466  << "\n Sequence run time = " << seqRunTime
467  << " seconds"
468  << "\n\n Breaking of the seq run time:\n"
469  << "\n QoI function run time = " << qoiFunctionRunTime
470  << " seconds (" << 100.*qoiFunctionRunTime/seqRunTime
471  << "%)"
472  << std::endl;
473  }
474 
475  return;
476 }
std::set< unsigned int > m_pseqDataOutputAllowedSet
int subRank() const
Access function for sub-rank.
Definition: Environment.C:263
std::set< unsigned int > m_qseqDataOutputAllowedSet
const BaseEnvironment & m_env
Definition: MonteCarloSG.h:121
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:289
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
const VectorSpace< P_V, P_M > & m_paramSpace
Definition: MonteCarloSG.h:124
unsigned int m_numQsNotSubWritten
Definition: MonteCarloSG.h:128
const VectorSpace< Q_V, Q_M > & m_qoiSpace
Definition: MonteCarloSG.h:125
const VectorFunctionSynchronizer< P_V, P_M, Q_V, Q_M > * m_qoiFunctionSynchronizer
Definition: MonteCarloSG.h:126
virtual void setPositionValues(unsigned int posId, const V &vec)=0
Set the values in vec at position posId of the sequence. See template specialization.
unsigned int m_pseqDataOutputPeriod
std::string m_pseqDataOutputFileType
virtual void resizeSequence(unsigned int newSubSequenceSize)=0
Resize the sequence. See template specialization.
const std::string & name() const
Access to protected attribute m_name: name of the sequence of vectors.
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.
MonteCarloSGOptions * m_optionsObj
Definition: MonteCarloSG.h:131
virtual unsigned int subSequenceSize() const =0
Size of the sub-sequence of vectors. See template specialization.
int fullRank() const
Returns the process full rank.
Definition: Environment.C:241
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:98
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:218
const int UQ_OK_RC
Definition: Defines.h:76
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:329
double MiscGetEllapsedSeconds(struct timeval *timeval0)
std::string m_pseqDataOutputFileName
unsigned int m_numPsNotSubWritten
Definition: MonteCarloSG.h:127
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 realization(V &nextValues) const =0
Performs a realization (sample) from a probability density function. 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 480 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().

487 {
488  workingPSeq.resizeSequence(requestedSeqSize);
489  P_V tmpP(m_paramSpace.zeroVector());
490  for (unsigned int i = 0; i < requestedSeqSize; ++i) {
491  paramRv.realizer().realization(tmpP);
492  workingPSeq.setPositionValues(i,tmpP);
493  }
494 
495  workingQSeq.unifiedReadContents(dataInputFileName,dataInputFileType,requestedSeqSize);
496 
497  return;
498 }
const VectorSpace< P_V, P_M > & m_paramSpace
Definition: MonteCarloSG.h:124
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 setPositionValues(unsigned int posId, const V &vec)=0
Set the values in vec at position posId of the sequence. See template specialization.
virtual void resizeSequence(unsigned int newSubSequenceSize)=0
Resize the sequence. See template specialization.
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:98
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:218
virtual void realization(V &nextValues) const =0
Performs a realization (sample) from a probability density function. 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 91 of file MonteCarloSG.C.

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

94 {
95  UQ_FATAL_TEST_MACRO(m_qoiFunction.domainSet().vectorSpace().dimLocal() != workingPSeq.vectorSizeLocal(),
96  m_env.worldRank(),
97  "MonteCarloSG<P_V,P_M,Q_V,Q_M>::generateSequence()",
98  "'m_qoiFunction.domainSet' and 'workingPSeq' are related to vector spaces of different dimensions");
99 
100  UQ_FATAL_TEST_MACRO(m_qoiFunction.imageSet().vectorSpace().dimLocal() != workingQSeq.vectorSizeLocal(),
101  m_env.worldRank(),
102  "MonteCarloSG<P_V,P_M,Q_V,Q_M>::generateSequence()",
103  "'m_qoiFunction.imageSet' and 'workingQSeq' are related to vector spaces of different dimensions");
104 
105  MiscCheckTheParallelEnvironment<P_V,Q_V>(m_paramRv.imageSet().vectorSpace().zeroVector(),
106  m_qoiFunction.imageSet().vectorSpace().zeroVector());
107  internGenerateSequence(m_paramRv,workingPSeq,workingQSeq);
108 
109  return;
110 }
const BaseEnvironment & m_env
Definition: MonteCarloSG.h:121
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
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:121
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > & m_qoiFunction
Definition: MonteCarloSG.h:123
unsigned int vectorSizeLocal() const
Local dimension (size) of the vector space.
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:218
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
const BaseVectorRV< P_V, P_M > & m_paramRv
Definition: MonteCarloSG.h:122
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 121 of file MonteCarloSG.C.

References QUESO::BaseVectorSequence< V, M >::name(), QUESO::FilePtrSetStruct::ofsVar, 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_FATAL_TEST_MACRO, UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT, and UQ_MOC_SG_FILENAME_FOR_NO_FILE.

125 {
126  workingPSeq.setName(m_optionsObj->m_prefix+"ParamSeq");
127  workingQSeq.setName(m_optionsObj->m_prefix+"QoiSeq");
128 
129  //****************************************************
130  // Generate sequence of QoI values
131  //****************************************************
132  unsigned int subActualSizeBeforeGeneration = std::min(m_optionsObj->m_ov.m_qseqSize,paramRv.realizer().subPeriod());
133  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
134  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
135  << ": m_optionsObj->m_ov.m_qseqSize = " << m_optionsObj->m_ov.m_qseqSize
136  << ", paramRv.realizer().subPeriod() = " << paramRv.realizer().subPeriod()
137  << ", about to call actualGenerateSequence() with subActualSize = " << subActualSizeBeforeGeneration
138  << std::endl;
139  }
141  actualGenerateSequence(paramRv,
142  workingPSeq,
143  workingQSeq,
144  subActualSizeBeforeGeneration);
145  }
146  else {
147  actualReadSequence(paramRv,
150  workingPSeq,
151  workingQSeq,
152  subActualSizeBeforeGeneration);
153  }
154  unsigned int subActualSizeAfterGeneration = workingPSeq.subSequenceSize();
155  UQ_FATAL_TEST_MACRO(subActualSizeAfterGeneration != workingQSeq.subSequenceSize(),
156  m_env.worldRank(),
157  "MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()",
158  "P and Q sequences should have the same size!");
159 
160  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
161  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
162  << ": returned from call to actualGenerateSequence() with subActualSize = " << subActualSizeAfterGeneration
163  << std::endl;
164  }
165 
166  //****************************************************
167  // Open generic output file
168  //****************************************************
169  if (m_env.subDisplayFile()) {
170  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
171  << ", prefix = " << m_optionsObj->m_prefix
172  << ": checking necessity of opening generic output file (qseq name is " << workingQSeq.name()
173  << ") ..."
174  << std::endl;
175  }
176  FilePtrSetStruct genericFilePtrSet;
178  UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT, // Yes, always ".m"
180  false,
181  genericFilePtrSet);
182 
183  //****************************************************
184  // Eventually:
185  // --> write parameter sequence
186  // --> compute statistics on it
187  //****************************************************
188  if (m_env.subDisplayFile()) {
189  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
190  << ", prefix = " << m_optionsObj->m_prefix
191  << ": checking necessity of opening output files for pseq " << workingPSeq.name()
192  << "..."
193  << std::endl;
194  }
195 
196  // Take "sub" care of pseq
197  if ((m_numPsNotSubWritten > 0 ) &&
199  workingPSeq.subWriteContents(subActualSizeBeforeGeneration - m_numPsNotSubWritten,
204  if (m_env.subDisplayFile()) {
205  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::internGenerateSequence()"
206  << ": just wrote remaining pseq positions (per period request)"
207  << std::endl;
208  }
210  //if (m_env.subDisplayFile()) {
211  // *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
212  // << ", prefix = " << m_optionsObj->m_prefix
213  // << ": closed data output file '" << m_optionsObj->m_ov.m_pseqDataOutputFileName
214  // << "' for pseq " << workingPSeq.name()
215  // << std::endl;
216  //}
217  }
218 
219  // Take "unified" care of pseq
222  if (m_env.subDisplayFile()) {
223  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
224  << ", prefix = " << m_optionsObj->m_prefix
225  << ": closed unified data output file '" << m_optionsObj->m_ov.m_pseqDataOutputFileName
226  << "' for pseq " << workingPSeq.name()
227  << std::endl;
228  }
229  }
230 
231  // Take case of other aspects of pseq
232 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
233  if (m_optionsObj->m_ov.m_pseqComputeStats) {
234  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
235  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
236  << ": about to call 'workingPSeq.computeStatistics()'"
237  << std::endl;
238  }
239  workingPSeq.computeStatistics(*m_optionsObj->m_pseqStatisticalOptionsObj,
240  genericFilePtrSet.ofsVar);
241  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
242  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
243  << ": returned from call to 'workingPSeq.computeStatistics()'"
244  << std::endl;
245  }
246  }
247 #endif
248  //****************************************************
249  // Eventually:
250  // --> write QoI sequence
251  // --> compute statistics on it
252  //****************************************************
253  if (m_env.subDisplayFile()) {
254  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
255  << ", prefix = " << m_optionsObj->m_prefix
256  << ": checking necessity of opening output files for qseq " << workingQSeq.name()
257  << "..."
258  << std::endl;
259  }
260 
261  // Take "sub" care of qseq
262  if ((m_numQsNotSubWritten > 0 ) &&
264  workingQSeq.subWriteContents(subActualSizeBeforeGeneration - m_numQsNotSubWritten,
269  if (m_env.subDisplayFile()) {
270  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::internGenerateSequence()"
271  << ": just wrote remaining qseq positions (per period request)"
272  << std::endl;
273  }
275  //if (m_env.subDisplayFile()) {
276  // *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
277  // << ", prefix = " << m_optionsObj->m_prefix
278  // << ": closed data output file '" << m_optionsObj->m_ov.m_qseqDataOutputFileName
279  // << "' for qseq " << workingQSeq.name()
280  // << std::endl;
281  //}
282  }
283 
284  // Take "unified" care of qseq
287  if (m_env.subDisplayFile()) {
288  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
289  << ", prefix = " << m_optionsObj->m_prefix
290  << ": closed unified data output file '" << m_optionsObj->m_ov.m_qseqDataOutputFileName
291  << "' for qseq " << workingQSeq.name()
292  << std::endl;
293  }
294  }
295 
296  // Take case of other aspects of qseq
297 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
298  if (m_optionsObj->m_ov.m_qseqComputeStats) {
299  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
300  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
301  << ": about to call 'workingQSeq.computeStatistics()'"
302  << std::endl;
303  }
304  workingQSeq.computeStatistics(*m_optionsObj->m_qseqStatisticalOptionsObj,
305  genericFilePtrSet.ofsVar);
306  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
307  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
308  << ": returned from call to 'workingQSeq.computeStatistics()'"
309  << std::endl;
310  }
311  }
312 #endif
313  //****************************************************
314  // Close generic output file
315  //****************************************************
316  if (genericFilePtrSet.ofsVar) {
317  //std::cout << "TODAY 000" << std::endl;
318  delete genericFilePtrSet.ofsVar;
319  //genericFilePtrSet.ofsVar->close();
320  //std::cout << "TODAY 001" << std::endl;
321  if (m_env.subDisplayFile()) {
322  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
323  << ", prefix = " << m_optionsObj->m_prefix
324  << ": closed generic data output file '" << m_optionsObj->m_ov.m_dataOutputFileName
325  << "' for QoI sequence " << workingQSeq.name()
326  << std::endl;
327  }
328  }
329  if (m_env.subDisplayFile()) {
330  *m_env.subDisplayFile() << std::endl;
331  }
332 
333  return;
334 }
std::set< unsigned int > m_pseqDataOutputAllowedSet
std::set< unsigned int > m_qseqDataOutputAllowedSet
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:338
const BaseEnvironment & m_env
Definition: MonteCarloSG.h:121
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
Definition: Defines.h:89
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
unsigned int m_numQsNotSubWritten
Definition: MonteCarloSG.h:128
std::string m_pseqDataOutputFileType
const std::string & name() const
Access to protected attribute m_name: name of the sequence of vectors.
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.
MonteCarloSGOptions * m_optionsObj
Definition: MonteCarloSG.h:131
std::set< unsigned int > m_dataOutputAllowedSet
virtual unsigned int subSequenceSize() const =0
Size of the sub-sequence of vectors. See template specialization.
unsigned int subPeriod() const
Sub-period of the realization. Access to protected attribute m_subPeriod.
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:98
unsigned int displayVerbosity() const
Definition: Environment.C:436
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.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
std::string m_pseqDataOutputFileName
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:516
unsigned int m_numPsNotSubWritten
Definition: MonteCarloSG.h:127
void setName(const std::string &newName)
Changes the name of the sequence of vectors.
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:480
#define UQ_MOC_SG_FILENAME_FOR_NO_FILE
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 114 of file MonteCarloSG.C.

115 {
116  return;
117 }

Friends And Related Function Documentation

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

Definition at line 83 of file MonteCarloSG.h.

84  {
85  obj.print(os);
86  return os;
87  }

Member Data Documentation

template<class P_V, class P_M, class Q_V, class Q_M>
McOptionsValues QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_alternativeOptionsValues
private

Definition at line 130 of file MonteCarloSG.h.

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

Definition at line 121 of file MonteCarloSG.h.

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

Definition at line 127 of file MonteCarloSG.h.

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

Definition at line 128 of file MonteCarloSG.h.

template<class P_V, class P_M, class Q_V, class Q_M>
MonteCarloSGOptions* QUESO::MonteCarloSG< P_V, P_M, Q_V, Q_M >::m_optionsObj
private

Definition at line 131 of file MonteCarloSG.h.

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

Definition at line 122 of file MonteCarloSG.h.

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

Definition at line 124 of file MonteCarloSG.h.

template<class P_V, class P_M, class Q_V, class Q_M>
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 123 of file MonteCarloSG.h.

template<class P_V, class P_M, class Q_V, class Q_M>
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 126 of file MonteCarloSG.h.

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

Definition at line 125 of file MonteCarloSG.h.


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

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