queso-0.56.0
Environment.h
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 #ifndef UQ_ENVIRONMENT_H
26 #define UQ_ENVIRONMENT_H
27 
28 #include <queso/Defines.h>
29 #undef UQ_USES_COMMAND_LINE_OPTIONS
30 
31 #include <queso/MpiComm.h>
32 #ifdef QUESO_HAS_HDF5
33 #include <hdf5.h>
34 #endif
35 #include <iostream>
36 #include <fstream>
37 
38 #include <queso/ScopedPtr.h>
39 #include <queso/RngBase.h>
40 #include <queso/BasicPdfsBase.h>
41 
42 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
43 // Forward declarations
44 namespace boost {
45  namespace program_options {
46  class options_description;
47  class variables_map;
48  }
49 }
50 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
51 
52 namespace QUESO {
53 
54 // Forward declarations
55 class GetPot;
56 class EnvironmentOptions;
57 class EnvOptionsValues;
58 
59 
67 
75 struct FilePtrSetStruct {
77 
80 
83 
85  std::ofstream* ofsVar;
86 
88  std::ifstream* ifsVar;
89 #ifdef QUESO_HAS_HDF5
90  hid_t h5Var;
91 #endif
92 };
93 
94 //------------------------------------------------------------------------
95 // Library versioning routines: we include them in a QUESO namespace
96 // here so that multiple classes can use them as required (and so we
97 // can have a standalone versioning binary which does not require a full
98 // QUESO MPI environment.
99 //------------------------------------------------------------------------
100 
101  void QUESO_version_print (std::ostream &os);
103 
104 //*****************************************************
105 // Base class
106 //*****************************************************
198 public:
200 
201  BaseEnvironment(const char* passedOptionsInputFileName, EnvOptionsValues* alternativeOptionsValues);
203 
204  BaseEnvironment(const std::string & passedOptionsInputFileName,
205  EnvOptionsValues* alternativeOptionsValues);
206 
208 
211  virtual ~BaseEnvironment();
213 
215 
216  bool fullEnvIsReady() const;
218 
220  int worldRank () const;
221 
223  int fullRank () const;
224 
226  const MpiComm& fullComm () const;
227 
229  RawType_MPI_Group subGroup () const;
230 
232  int subRank () const;
233 
235  const MpiComm& subComm () const;
236 
238  const MpiComm& selfComm () const;
239 
241  int inter0Rank () const;
242 
244  const MpiComm& inter0Comm () const;
245 
247  std::ofstream* subDisplayFile() const;
248 
250  std::string subDisplayFileName () const;
251 
253  unsigned int numSubEnvironments () const;
254 
256  unsigned int subId () const;
257 
259  const std::string& subIdString () const;
260 
261  //TODO Not implemented?
262  void checkTheParallelEnvironment () const;
263 
265  std::string optionsInputFileName () const;
266 
267  void setOptionsInputFileAccessState(bool newState) const; // Yes, 'const'
268 
269 
270 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
271 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
272  const boost::program_options::options_description& allOptionsDesc () const;
273 #endif
274 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
275 
276 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
277  boost::program_options::variables_map& allOptionsMap () const;
280 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
281 
282 
283 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
284 
287  void scanInputFileForMyOptions(const boost::program_options::options_description& optionsDesc) const;
288 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
289 
292  unsigned int displayVerbosity () const;
293 
295  unsigned int syncVerbosity () const;
296 
298  unsigned int checkingLevel () const;
299 
301  const RngBase* rngObject () const;
302 
304  void resetSeed (int newSeedOption);
305 
307  int seed () const;
308 
310  const BasicPdfsBase* basicPdfs() const;
311 
313  std::string platformName () const;
314 
316  std::string identifyingString () const;
317 
319  void resetIdentifyingString(const std::string& newString);
320 
322  bool isThereInputFile () const;
323 
325  struct timeval timevalBegin () const;
327 
329 
330 
332  bool openOutputFile(const std::string& fileName, const std::string& fileType,
333  const std::set<unsigned int>& allowedSubEnvIds, bool writeOver,
334  FilePtrSetStruct& filePtrSet) const;
335 
337  bool openUnifiedOutputFile (const std::string& fileName, const std::string& fileType,
338  bool writeOver, FilePtrSetStruct& filePtrSet) const;
339 
341  bool openInputFile (const std::string& fileName, const std::string& fileType,
342  const std::set<unsigned int>& allowedSubEnvIds,
343  FilePtrSetStruct& filePtrSet) const;
344 
346  bool openUnifiedInputFile (const std::string& fileName, const std::string& fileType,
347  FilePtrSetStruct& filePtrSet) const;
348 
350  void closeFile (FilePtrSetStruct& filePtrSet, const std::string& fileType) const;
351 
353  void setExceptionalCircumstance (bool value) const;
354 
356  bool exceptionalCircumstance () const;
357 
359  const GetPot & input() const;
360 
361 
362  virtual void print (std::ostream& os) const = 0;
363 
365 protected:
368 
373 
375  mutable bool m_optionsInputFileAccessState; // Yes, 'mutable'
376 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
377  boost::program_options::options_description* m_allOptionsDesc;
378  boost::program_options::variables_map* m_allOptionsMap;
379 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
380  ScopedPtr<GetPot>::Type m_input;
381 
382  unsigned int m_subId;
383  std::string m_subIdString;
388 
390 
395 
396  mutable std::ofstream* m_subDisplayFile;
399  struct timeval m_timevalBegin;
401 
403 };
404 
405 //*****************************************************
406 // Empty Environment
407 //*****************************************************
412 public:
414 
415 
418 
422 
423 void print(std::ostream& os) const;
424 };
425 
426 //*****************************************************
427 // Full Environment
428 //*****************************************************
436 public:
438 
439 
445 #ifdef QUESO_HAS_MPI
446  FullEnvironment(RawType_MPI_Comm inputComm, const char* passedOptionsInputFileName, const char* prefix, EnvOptionsValues* alternativeOptionsValues);
447 
449  const std::string& passedOptionsInputFileName,
450  const std::string& prefix,
451  EnvOptionsValues* alternativeOptionsValues);
452 #endif
453 
455 
459  FullEnvironment(const char* passedOptionsInputFileName, const char* prefix, EnvOptionsValues* alternativeOptionsValues);
460 
461  FullEnvironment(const std::string& passedOptionsInputFileName,
462  const std::string& prefix,
463  EnvOptionsValues* alternativeOptionsValues);
464 
468 
470 
471  void print (std::ostream& os) const;
474 
475 private:
476 #ifdef QUESO_HAS_MPI
477  void construct(RawType_MPI_Comm inputComm,
479  const char *prefix);
480 #endif
481 
483  void construct(const char *prefix);
484 
486  void readOptionsInputFile();
487  //void queso_terminate_handler();
488 
489 };
490 
491 std::ostream& operator<<(std::ostream& os, const BaseEnvironment& obj);
492 
493 } // End namespace QUESO
494 
495 #endif // UQ_ENVIRONMENT_H
virtual ~BaseEnvironment()
Destructor.
Definition: Environment.C:205
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:470
std::string m_optionsInputFileName
Definition: Environment.h:374
EnvOptionsValues * m_optionsObj
Definition: Environment.h:402
struct timeval m_timevalBegin
Definition: Environment.h:399
int worldRank() const
Returns the process world rank.
Definition: Environment.C:262
const GetPot & input() const
The GetPot input file parser.
Definition: Environment.C:1148
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
int subRank() const
Access function for sub-rank.
Definition: Environment.C:287
std::ifstream * ifsVar
Provides a stream interface to read data from files.
Definition: Environment.h:88
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:353
boost::program_options::variables_map * m_allOptionsMap
Definition: Environment.h:378
This class provides a suite options one can pass to a QUESO environment.
int RawType_MPI_Comm
Definition: MpiComm.h:57
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:197
void resetIdentifyingString(const std::string &newString)
Reset private attribute m_identifyingString with the value newString.
Definition: Environment.C:507
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
std::string subDisplayFileName() const
Access function for m_subDisplayFileName (displays filename on stream).
Definition: Environment.C:326
RawType_MPI_Group m_subGroup
Definition: Environment.h:384
std::ofstream * m_subDisplayFile
Definition: Environment.h:396
std::string platformName() const
Access to the platform name.
Definition: Environment.C:495
EmptyEnvironment()
Default constructor. Does nothing.
Definition: Environment.C:1157
bool fullEnvIsReady() const
Returns whether the full environment class is ready (constructor has successfully been called)...
Definition: Environment.C:256
void print(std::ostream &os) const
Sends the environment options to the stream.
Definition: Environment.C:1716
bool openInputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, FilePtrSetStruct &filePtrSet) const
Opens an input file.
Definition: Environment.C:895
boost::program_options::variables_map & allOptionsMap() const
Definition: Environment.C:385
std::string m_subIdString
Definition: Environment.h:383
Struct for handling data input and output from files.
Definition: Environment.h:76
boost::program_options::options_description * m_allOptionsDesc
Definition: Environment.h:377
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:341
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
Definition: Environment.C:456
void print(std::ostream &os) const
Definition: Environment.C:1168
std::string identifyingString() const
Access function to private attribute m_identifyingString: identifying string.
Definition: Environment.C:501
unsigned int m_subId
Definition: Environment.h:382
void scanInputFileForMyOptions(const boost::program_options::options_description &optionsDesc) const
This method scans the input file provided by the user to QUESO.
Definition: Environment.C:396
Class for random number generation (base class for either GSL or Boost RNG).
Definition: RngBase.h:45
const std::string & subIdString() const
Access to the attribute m_subIdString; which stores the string for the sub-environment, and it will be used, for instance, to create the output files for each sub-environment.
Definition: Environment.C:347
Definition: getpot.h:152
void setExceptionalCircumstance(bool value) const
Set an exceptional circumstance.
Definition: Environment.C:1135
void checkTheParallelEnvironment() const
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1083
int fullRank() const
Returns the process full rank.
Definition: Environment.C:268
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1749
int QUESO_get_numeric_version()
Definition: Environment.C:84
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:334
~FilePtrSetStruct()
Destructor.
Definition: Environment.C:127
std::ofstream * ofsVar
Provides a stream interface to write data to files.
Definition: Environment.h:85
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:141
RawType_MPI_Group subGroup() const
Access function for sub-group.
Definition: Environment.C:281
bool exceptionalCircumstance() const
Decides whether there is an exceptional circumstance.
Definition: Environment.C:1142
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:520
void resetSeed(int newSeedOption)
Reset RNG seed.
Definition: Environment.C:482
TODO: Base class for basic PDFs (via either GSL or Boost).
Definition: BasicPdfsBase.h:44
unsigned int checkingLevel() const
Access function to private attribute m_checkingLevel.
Definition: Environment.C:463
int seed() const
Access to the RNG seed.
Definition: Environment.C:476
ScopedPtr< GetPot >::Type m_input
Definition: Environment.h:380
unsigned int displayVerbosity() const
Definition: Environment.C:449
RawType_MPI_Group m_fullGroup
Definition: Environment.h:372
const MpiComm & subComm() const
Access function for MpiComm sub communicator.
Definition: Environment.C:293
virtual void print(std::ostream &os) const =0
const BasicPdfsBase * basicPdfs() const
Access to Basic PDFs.
Definition: Environment.C:489
The QUESO MPI Communicator Class.
Definition: MpiComm.h:203
~FullEnvironment()
Destructor.
Definition: Environment.C:1711
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:274
~EmptyEnvironment()
Destructor.
Definition: Environment.C:1163
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1722
This class sets up the environment underlying the use of the QUESO library by an executable.
Definition: Environment.h:411
This class sets up the full environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:435
bool openUnifiedInputFile(const std::string &fileName, const std::string &fileType, FilePtrSetStruct &filePtrSet) const
Opens the unified input file.
Definition: Environment.C:990
void setOptionsInputFileAccessState(bool newState) const
Definition: Environment.C:364
RawType_MPI_Group m_inter0Group
Definition: Environment.h:391
bool isThereInputFile() const
//TODO Not implemented? it is called in examples/validationCycle/tests_old/results_5_25/uqTgaEx4.h.
FullEnvironment(const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
Parallel constructor.
Definition: Environment.C:1462
FilePtrSetStruct()
Struct constructor.
Definition: Environment.C:116
bool openUnifiedOutputFile(const std::string &fileName, const std::string &fileType, bool writeOver, FilePtrSetStruct &filePtrSet) const
Opens a unified output file, that will contain data from all sub-environments.
Definition: Environment.C:725
int RawType_MPI_Group
Definition: MpiComm.h:58
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:54
BasicPdfsBase * m_basicPdfs
Definition: Environment.h:398
const MpiComm & inter0Comm() const
Access function for MpiComm inter0-communicator.
Definition: Environment.C:313
void construct(const char *prefix)
Named constructor backend for multiple constructor overloads.
Definition: Environment.C:1483
const MpiComm & selfComm() const
Access function for MpiComm self-communicator.
Definition: Environment.C:300

Generated on Tue Nov 29 2016 10:53:10 for queso-0.56.0 by  doxygen 1.8.5