Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

sparkapi.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////////////////
00002 /// \file  sparkapi.h  
00003 /// \brief Header file defining the functions required to manage the %SPARK problems 
00004 ///        in a driver function. 
00005 ///
00006 /// This file should be included in the C++ source file where the main driver function 
00007 /// is implemented.
00008 ///
00009 /// It defines functions to start, end and exit the simulation session :
00010 /// \li SPARK::Start()
00011 /// \li SPARK::End()
00012 /// \li SPARK::ExitWithError()
00013 ///
00014 /// Utility functions :
00015 /// \li SPARK::Log()
00016 /// \li SPARK::GetFileName()
00017 ///
00018 /// Access functions :
00019 /// \li SPARK::GetProgramName()
00020 /// \li SPARK::GetBaseName()
00021 /// \li SPARK::GetVersion() 
00022 ///
00023 /// \li SPARK::GetRunLog()
00024 /// \li SPARK::GetRunLogFilename()
00025 ///
00026 /// \li SPARK::GetErrorLog()
00027 /// \li SPARK::GetErrorLogFilename()
00028 ///
00029 /// %SPARK problem API functions used to manage SPARK::TProblem objects :
00030 /// \li SPARK::Problem::StaticBuild::ParseCommandLine()
00031 /// \li SPARK::Problem::StaticBuild::ShowCommandLineUsage()
00032 /// \li SPARK::Problem::StaticBuild::Load()
00033 ///
00034 /// \li SPARK::Problem::DynamicBuild::ParseCommandLine()
00035 /// \li SPARK::Problem::DynamicBuild::ShowCommandLineUsage()
00036 /// \li SPARK::Problem::DynamicBuild::Load()
00037 ///
00038 /// \li SPARK::Problem::Get() 
00039 /// \li SPARK::Problem::Unload() 
00040 /// \li SPARK::Problem::Initialize()
00041 /// \li SPARK::Problem::LoadPreferenceSettings()
00042 /// \li SPARK::Problem::Terminate()
00043 /// \li SPARK::Problem::Save()
00044 /// \li SPARK::Problem::Restore()
00045 /// \li SPARK::Problem::Simulate()
00046 /// \li SPARK::Problem::Step()
00047 /// \li SPARK::Problem::StaticStep()
00048 ///
00049 /////////////////////////////////////////////////////////////////////////////////////////
00050 ///
00051 /// \author  Dimitri Curtil (LBNL/SRG)
00052 /// \date    May 21, 2002
00053 ///          Extended API in Sept, 2003
00054 ///
00055 /////////////////////////////////////////////////////////////////////////////////////////
00056 /// \attention
00057 /// PORTIONS COPYRIGHT (C) 2003 AYRES SOWELL ASSOCIATES, INC. \n
00058 /// PORTIONS COPYRIGHT (C) 2003 THE REGENTS OF THE UNIVERSITY OF CALIFORNIA .
00059 ///   PENDING APPROVAL BY THE US DEPARTMENT OF ENERGY. ALL RIGHTS RESERVED.
00060 ///
00061 /////////////////////////////////////////////////////////////////////////////////////////
00062 
00063 
00064 #if !defined(__SPARKAPI_H__)
00065 #define __SPARKAPI_H__
00066 
00067 
00068 #include <iosfwd>
00069 #include <string>
00070 #include <fstream>
00071 
00072 #include "problem.h"    // for SPARK::TProblem, SPARK::TProblem::SimulationFlags, SPARK::TProblem::TState
00073 #include "exceptions.h" // for SPARK::XInitialization
00074 #include "compat.h"     // for API_DECLSPEC
00075 
00076 
00077 /////////////////////////////////////////////////////////////////////////////////////////
00078 /// \namespace SPARK
00079 /// \brief Definition of global functions and classes used in the %SPARK simulation environment.
00080 ///
00081 /////////////////////////////////////////////////////////////////////////////////////////
00082 
00083 namespace SPARK {
00084 
00085         /////////////////////////////////////////////////////////////////////////////////////
00086         // Forward declaration
00087         /////////////////////////////////////////////////////////////////////////////////////
00088         class TInverse;
00089         class TObject;
00090     class TRuntimeControls;
00091     class TPreferenceSettings;
00092 
00093 
00094         /////////////////////////////////////////////////////////////////////////////////////
00095         /// \name Functions to manage the SPARK solving environment
00096         //@{
00097         
00098         /// \brief Starts the SPARK solving environment.
00099         ///
00100         /// \param  sessionName       Name of the simulation session (used in various output files to identify run)
00101         /// \param  runLogFilename    Name of the run log file where diagnostics for each problem is sent to
00102         /// \param  errorLogFilename  Name of the log file where runtime errors will be notified
00103         /// \param  debugLogFilename  Name of the log file where debug informatiion is written in \c SPARK_DEBUG mode
00104         /// \param  verbose           If true then generates session diagnostic to run log files; if false session remains silent
00105         API_DECLSPEC(void) Start(
00106                 const char* sessionName, 
00107                 const char* runLogFilename,
00108                 const char* errorLogFilename, 
00109                 const char* debugLogFilename,
00110                 bool verbose = true
00111                 ) SPARK_THROWING( (SPARK::XInitialization) );
00112         
00113 
00114         /// \brief Terminates the SPARK solving environment.
00115         ///
00116         /// Closes all log files. Performs garbage collection for all problems loaded at runtime.
00117         ///
00118         /// \post  The SPARK::TProblem objects that have been constructed at runtime using the SPARK::Problem::DynamicLoad()
00119         ///        function will be automatically destructed following the call to SPARK::End().
00120         ///
00121         /// \warning Never explicitly destroy a TProblem object in your code!
00122         API_DECLSPEC(void) End();
00123 
00124 
00125         /// \brief Terminates program execution with exit code
00126         ///
00127         /// Writes out to the run log output stream the error message contained in \c ossErrMsg if not NULL.
00128         ///
00129         /// \param ec is the exit code of type SPARK::ExitCodes
00130         /// \param callingSub contains the name of the caller / owner (e.g., problem, atomic class)
00131         /// \param msg contains the description of the error message. 
00132         /// \param problem  points to the problem object that is requesting to terminate the simulation (usually the 
00133         ///        currently active problem).
00134         ///
00135         /// \post  The simulation is terminated properly with a call to the function SPARK::End(), therefore
00136         ///        cleaning up log files and performing garbage collection. 
00137         ///
00138         /// \note  If <code> ec == SPARK::ExitCode_OK </code>, then the function returns without doing anything.
00139         API_DECLSPEC(void) ExitWithError(
00140                 SPARK::ExitCodes ec,                // Error code (should be different than SPARK::ExitCode_OK)
00141         const std::string& callingSub,      // Name of calling function
00142                 const std::string& msg,             // Description of the error 
00143                 const SPARK::TProblem* problem = 0  // Pointer to currently active problem if available
00144         );
00145 
00146         //@}
00147         /////////////////////////////////////////////////////////////////////////////////////
00148 
00149 
00150 
00151         /////////////////////////////////////////////////////////////////////////////////////
00152         /// \name Utility functions
00153         //@{
00154 
00155         /// \brief Returns the pointer to the first string in the argv[] that has the specified extension. 
00156         ///        If cannot find file with desired extension, returns 0
00157         ///
00158         /// This function is more versatile than the SPARK::StaticBuild::ParseCommandLine() and SPARK::DynamicBuild::ParseCommandLine() 
00159         /// functions as it lets you retrieve one file at a time for the specified extension.
00160         ///
00161         /// \note  The string comparison againt the specified extension is case insensitive.
00162         /// \exception If the desired extension is invalid, throws the SPARK::XInitialization exception.
00163         API_DECLSPEC(char*) GetFileName(unsigned argc, char* argv[], const char* extension) SPARK_THROWING( (SPARK::XInitialization) );
00164 
00165 
00166         /// \brief Writes a message to the specified log file 
00167         ///
00168     /// \param os             reference to the std::iostream object where the log entry is displayed
00169         /// \param strFileName    name of the atomic class file. Use preprocessor macro \c __FILE__ to pass file name automatically.
00170         /// \param strSenderName  name of the sender object. E.g., pass C-string with inverse function name.
00171         /// \param strMsg         C-string message terminated by '\\0' character to be displayed in error log file.
00172         /// \param problem        pointer to the target problem (if available)
00173         API_DECLSPEC(void) Log(
00174         std::ostream& os,
00175                 const char* strFileName,
00176                 const char* strSenderName,
00177                 const char* strMsg,
00178                 const SPARK::TProblem* problem=0
00179         );
00180 
00181 
00182         /// \brief Writes a message to the specified log file from a static callback file in a %SPARK atomic class.
00183         ///
00184     /// \param os        reference to the std::iostream object where the log entry is displayed
00185         /// \param sender    pointer to the Inverse instance that sends the message
00186         /// \param line      indicates the line number in file where the message is sent from
00187         /// \param strMsg    C-string message terminated by '\\n' character to be displayed in error log file.
00188         API_DECLSPEC(void) Log(
00189         std::ostream& os,
00190                 const SPARK::TInverse* sender,
00191                 unsigned line, 
00192                 const char* strMsg
00193         );
00194 
00195 
00196         /// \brief Writes a message to the specified log file from a non-static callback file in a %SPARK atomic class.
00197         ///
00198     /// \param os        reference to the std::iostream object where the log entry is displayed
00199         /// \param sender    pointer to the TObject instance that sends the message
00200         /// \param line      indicates the line number in file where the message is sent from
00201         /// \param strMsg    C-string message terminated by '\\n' character to be displayed in error log file.
00202         API_DECLSPEC(void) Log(
00203         std::ostream& os,
00204                 const SPARK::TObject* sender,
00205                 unsigned line, 
00206                 const char* strMsg
00207         );
00208 
00209         //@}
00210         /////////////////////////////////////////////////////////////////////////////////////
00211 
00212 
00213 
00214         /////////////////////////////////////////////////////////////////////////////////////
00215         /// \name Access methods
00216         // @{
00217 
00218         /// \brief  Returns the name of the program as specified during the call to SPARK::Start()
00219         ///
00220         /// \return program name as <code>const char*</code>
00221         API_DECLSPEC(const char*) GetProgramName() ;
00222 
00223         /// \brief  Returns the base name of the program name (i.e., the program name witout path and 
00224         ///         without any extension)
00225         ///
00226         /// \return base name as <code>const char*</code>
00227         API_DECLSPEC(const char*) GetBaseName() ;
00228 
00229         /// \brief  Returns the version of the solver library being used
00230         ///
00231         /// \return full solver version as <code>const char*</code>
00232         API_DECLSPEC(const char*) GetVersion() ;
00233 
00234         /// \brief  Returns the output stream for the run log
00235         ///
00236         /// \return output stream as <code>std::ostream&</code>
00237         API_DECLSPEC(std::ostream&) GetRunLog() ;
00238         
00239         /// \brief  Returns the output stream for the error log
00240         ///
00241         /// \return output stream as <code>std::ostream&</code>
00242         API_DECLSPEC(std::ostream&) GetErrorLog() ;
00243 
00244         /// \brief  Returns the name of the run log file as specified during the call to SPARK::Start()
00245         ///
00246         /// \return run log file name as <code>const char*</code>
00247         API_DECLSPEC(const char*) GetRunLogFilename() ;
00248 
00249         /// \brief  Returns the name of the error log file as specified during the call to SPARK::Start()
00250         ///
00251         /// \return error log file name as <code>const char*</code>
00252         API_DECLSPEC(const char*) GetErrorLogFilename() ;
00253 
00254         /// \brief  Returns the name of the debug log file as specified during the call to SPARK::Start()
00255         ///
00256         /// \return debug log file name as <code>const char*</code>
00257         API_DECLSPEC(const char*) GetDebugLogFilename() ;
00258 
00259         //@}
00260         /////////////////////////////////////////////////////////////////////////////////////
00261 
00262 }; // namespace SPARK
00263 
00264 
00265 
00266 /////////////////////////////////////////////////////////////////////////////////////////
00267 /// \namespace SPARK::Problem::StaticBuild
00268 /// \brief Definition of the functions used to load a statically-built %SPARK problem.
00269 ///
00270 /// These API functions are used to implement the driver function of the stand-alone
00271 /// %SPARK engine.
00272 /////////////////////////////////////////////////////////////////////////////////////////
00273 
00274 namespace SPARK { namespace Problem { namespace StaticBuild {
00275 
00276         /// \brief Parses up to argc command-line arguments in argv[] to produce the names of the
00277         ///        files with extensions "*.run" and "*.prf" as needed to run a statically-built problem.
00278         ///
00279         /// This function is used to extract the names of the *.run and *.prf files at the command line
00280         /// as required by a statically-built simulator, i.e. a simulator that does not need the *.xml
00281         /// file to load the problem description as it is compiled and linked along the driver function.
00282         ///
00283         /// \note No memory is allocated for the 2 strings passed in the argument list. Upon returning 
00284         ///       from this function, the char*& are pointing to the entries in argv[] that contain the
00285         ///       corresponding file names with the correct extensions.
00286         ///
00287         /// \param  argc        first argument of the main() function declared in the "main.cpp" file
00288         /// \param  argv        second argument of the main() function declared in the "main.cpp" file
00289         /// \param  runFileName points to argv[] with name of the file with extension "*.run" 
00290         /// \param  prfFileName points to argv[] with name of the file with extension "*.prf"
00291         ///
00292         /// \exception SPARK::XInitialization  Thrown if more than one *.run or *.prf file is detected at the command-line.
00293         API_DECLSPEC(void) ParseCommandLine(
00294                 unsigned argc, 
00295                 char** argv, 
00296                 char*& runFileName, 
00297                 char*& prfFileName
00298         ) SPARK_THROWING( (SPARK::XInitialization) );
00299 
00300         
00301         /// \brief Writes command-line usage of stand-alone SPARK engine for a statically-built problem to output stream \c os
00302         ///
00303         /// \param os     output stream where to write the command-line usage
00304         API_DECLSPEC(void) ShowCommandLineUsage(std::ostream& os);
00305 
00306 
00307         /// \brief Loads the statically-built problem named "pbName".
00308         ///
00309         /// By statically-built problem, we refer to a problem whose definition is compiled from the corresponding 
00310         /// "problem.cpp" file and linked along with the solver library and driver function.
00311         ///
00312         /// \return True if operation was successful, false otherwise.
00313         ///
00314         /// \param pbName  the unique name for this instance of the problem 
00315         ///
00316         /// \post If the problem was loaded successfully, then the SPARK::TProblem instance is stored in the 
00317         ///       global problem repository with its name for later retrieval through a call to 
00318         ///       SPARK::Problem::Get().
00319         ///
00320         API_DECLSPEC(bool) Load(const char* pbName);
00321 
00322 
00323 }; }; }; // namespace SPARK::Problem::StaticBuild
00324 
00325 
00326 
00327 /////////////////////////////////////////////////////////////////////////////////////////
00328 /// \namespace SPARK::Problem::DynamicBuild
00329 /// \brief Definition of the functions used to load a %SPARK problem at runtime.
00330 ///
00331 /// These API functions are used to implement the driver function of the stand-alone
00332 /// %SPARK engine.
00333 /////////////////////////////////////////////////////////////////////////////////////////
00334 
00335 namespace SPARK { namespace Problem { namespace DynamicBuild {
00336 
00337         /// \brief Parses up to argc command-line arguments in argv[] to produce the name of the
00338         ///        files with extensions "*.run", "*.prf" and "*.xml" as needed to run a problem
00339         ///        loaded at runtime.
00340         ///
00341         /// \note No memory is allocated for the 3 strings passed in the argument list. Upon returning 
00342         ///       from this function, the char*& are pointing to the entries in argv[] that contain the
00343         ///       corresponding file names with the correct extensions.
00344         ///
00345         /// \param  argc        first argument of the main() function declared in the "main.cpp" file
00346         /// \param  argv        second argument of the main() function declared in the "main.cpp" file
00347         /// \param  runFileName points to argv[] with name of the file with extension "*.run" 
00348         /// \param  prfFileName points to argv[] with name of the file with extension "*.prf"
00349         /// \param  xmlFileName points to argv[] with name of the file with extension "*.xml"
00350         ///
00351         /// \exception SPARK::XInitialization  Thrown if more than one *.run or *.prf or *.xml file is detected at the command-line.
00352         API_DECLSPEC(void) ParseCommandLine(
00353                 unsigned argc, 
00354                 char** argv, 
00355                 char*& runFileName, 
00356                 char*& prfFileName,
00357                 char*& xmlFileName
00358         ) SPARK_THROWING( (SPARK::XInitialization) );
00359 
00360 
00361         /// \brief Writes command-line usage of stand-alone SPARK engine for a problem loaded at runtime to output stream \c os
00362         ///
00363         /// \param os     output stream where to write the command-line usage
00364         API_DECLSPEC(void) ShowCommandLineUsage(std::ostream& os);
00365 
00366 
00367         /// \brief Loads the problem named "pbName" at runtime and sets name of problem instance after unique 
00368         ///        identifier "pbName" 
00369         ///
00370         /// \return True if operation was successful, false otherwise.
00371         ///
00372         /// \param pbName       the unique name for this instance of the problem 
00373         /// \param xmlFileName  name of the xml file with the problem description
00374         ///
00375         /// \post If the problem was loaded successfully, then the SPARK::TProblem instance is stored in the 
00376         ///       global problem repository with its name for later retrieval through a call to 
00377         ///       SPARK::Problem::Get().
00378         ///
00379         /// \post Furthermore, if the problem was loaded successfully using the runtime loading mechanism, 
00380         ///       then the problem factory used to construct the problem is stored in the factory
00381         ///       repository to support garbage collection upon the call to the function SPARK::End().
00382         API_DECLSPEC(bool) Load(
00383                 const char* pbName, 
00384                 const char* xmlFileName
00385         );
00386 
00387         
00388 }; }; }; // namespace SPARK::Problem::DynamicBuild
00389 
00390 
00391 
00392 /////////////////////////////////////////////////////////////////////////////////////////
00393 /// \namespace SPARK::Problem
00394 /// \brief Definition of the %SPARK problem driver API library used to manage the  
00395 ///        SPARK::TProblem objects in the driver function.
00396 /////////////////////////////////////////////////////////////////////////////////////////
00397 
00398 namespace SPARK { namespace Problem {
00399 
00400         /////////////////////////////////////////////////////////////////////////////////////
00401         /// \name Methods used to setup a problem for simulation
00402         // @{
00403 
00404         /// \brief Registers statically-built problem by address with static repository 
00405         ///
00406         /// \param  pbName    unique problem name 
00407         /// \param  instance  address of the SPARK::TProblem instance
00408         /// \return Returns true if operation was successful, false otherwise
00409         ///
00410         /// \note    Used in "problem.cpp" file for precompiled problem file.
00411         /// \note    The name of the problem instance must be unique for this simulation session, otherwise
00412         ///          the %SPARK solver will not be able to load this problem at runtime. This will result
00413         ///          in the %SPARK problem loader throwing a SPARK::XInitialization exception with the exit code 
00414         ///          SPARK::ExitCode_ERROR_INVALID_PROBLEM when calling the function SPARK::Start(). 
00415         ///
00416         /// \warning Since this function is typically invoked in the "problem.cpp" file, it is called at startup 
00417         ///          before entering the main function. Therefore, no error message can be reported to a log file.  
00418         ///          SPARK::Start() will throw a SPARK::XInitialization exception if any such error occurred at startup.
00419         ///
00420         API_DECLSPEC(bool) RegisterStaticInstance(
00421                 const char* pbName, 
00422                 SPARK::TProblem* instance
00423         );
00424 
00425 
00426         /// \brief Unloads the problem instance named "pbName" from repository and frees memory.
00427         ///
00428         /// \return Returns true if instance successfully unloaded; false otherwise
00429         /// \param  pbName   name of the problem to unload
00430         ///
00431         /// \note   If there is no problem instance named after "pbName", the function will return
00432         ///         false.
00433         /// \note   This function unloads both statically-built problems and problems loaded at runtime
00434         ///         , i.e. problem instances loaded:
00435         ///         - either with a call to SPARK::Problem::StaticBuild::Load() or 
00436         ///         - with a call to SPARK::Problem::DynamicBuild::Load().
00437         ///
00438         /// \warning An unloaded problem can no longer be:
00439         ///          - used in the driver function or 
00440         ///          - retrieved with a call to the function SPARK::Problem::Get().
00441         API_DECLSPEC(bool) Unload(const char* pbName);
00442 
00443 
00444         /// \brief Writes out the list of loaded problem instances to the output stream \c os with 
00445         ///        leading string \c before
00446     ///
00447     /// \param os      Output stream for write operation
00448     /// \param before  Prefix string written before the names of the instances
00449         API_DECLSPEC(void) WriteInstances(std::ostream& os, const std::string& before);
00450 
00451 
00452     /// \brief Access method to retrieve a previously loaded problem through its unique name 
00453     ///        from the problem repository.
00454         ///
00455         /// \return Address of the SPARK::TProblem instance describing the problem named "pbName"
00456         /// \param  pbName   name of the problem whose address is to be returned
00457         ///
00458         /// \note   Returns NULL if problem name was not previouly loaded or if no problem with this name
00459         ///         exists in global repository.
00460         API_DECLSPEC(SPARK::TProblem*) Get(const char* pbName);
00461 
00462 
00463     /// \brief  Initializes the problem with the specified runtime controls
00464     ///
00465     /// Calls the SPARK::TProblem::Initialize() method.
00466     ///
00467     /// \param  instance   Address of the SPARK::TProblem object
00468     /// \param  controls   Runtime controls as specified in a *.run file
00469     API_DECLSPEC(void) Initialize(SPARK::TProblem* instance, const SPARK::TRuntimeControls& controls);
00470 
00471 
00472     /// \brief Loads the preference settings into the problem
00473     ///
00474     /// Calls the SPARKK::TProblem::LoadPreferenceSettings() method.
00475     ///
00476     /// \param  instance    Address of the SPARK::TProblem object
00477     /// \param  preferences Preference settings as specified in a *.prf file
00478     API_DECLSPEC(void) LoadPreferenceSettings(SPARK::TProblem* instance, const SPARK::TPreferenceSettings& preferences);
00479 
00480 
00481     /// \brief Terminates the problem.
00482     ///
00483     /// Calls the SPARK::TProblem::Terminate() method.
00484     ///
00485     /// \post The problem must be re-initialized with a call to SPARK::TProblem::Initialize() to allow for
00486     ///       a new simulation.
00487     /// 
00488     /// \param  instance   Address of the SPARK::TProblem object
00489     API_DECLSPEC(void) Terminate(SPARK::TProblem* instance);
00490 
00491 
00492         //@}
00493         /////////////////////////////////////////////////////////////////////////////////////
00494 
00495     
00496         /////////////////////////////////////////////////////////////////////////////////////
00497         /// \name State management methods
00498         // @{
00499 
00500     /// \brief Saves the state of the problem at the current time
00501     ///
00502     /// Calls the SPARK::TProblem::Save() method.
00503     ///
00504     /// \post The state object will contain the new state. If it contained another state, it will
00505     ///       be overriden. The problem object remains unchanged.
00506     ///
00507     /// \param  instance   Address of the SPARK::TProblem object
00508     /// \param  state      SPARK::TProblem::TState object containing the stored state
00509     API_DECLSPEC(void) Save(const SPARK::TProblem* instance, SPARK::TProblem::TState& state);
00510 
00511     /// \brief Restores the problem to the specified state
00512     ///
00513     /// Calls the SPARK::TProblem::Restore() method.
00514     ///
00515     /// \pre  The state to restore must have been saved with a call to SPARK::Problem::Save().
00516     /// \post The problem is restored to the state, in particular the global time, the current
00517     ///       values of all variables as well as their history.
00518     ///
00519     /// \param  instance   Address of the SPARK::TProblem object
00520     /// \param  state      SPARK::TProblem::TState object containing the state to restore
00521     API_DECLSPEC(void) Restore(SPARK::TProblem* instance, const SPARK::TProblem::TState& state); 
00522 
00523         //@}
00524         /////////////////////////////////////////////////////////////////////////////////////
00525 
00526 
00527         /////////////////////////////////////////////////////////////////////////////////////
00528         /// \name Simulation methods 
00529         // @{
00530 
00531     /// \class simulation_parameter
00532     /// \brief Class used to specify a simulation parameter.
00533     ///
00534     /// Wrapper class around a POD object of type T that keeps track of whether the parameter 
00535     /// was initialized in the constructor.
00536     /// Used in the various simulation methods that accept parameters as arguments.
00537     ///
00538     template<typename T>
00539     class CLASS_DECLSPEC simulation_parameter  {
00540     public:
00541         /////////////////////////////////////////////////////////////////////////////////
00542         // Type definition
00543         typedef T  value_type;  ///< template type for the parameter 
00544 
00545 
00546         /////////////////////////////////////////////////////////////////////////////////
00547         // Structors 
00548         
00549         /// Default constructor: empty parameter
00550         simulation_parameter() 
00551             : EmptyFlag(true) 
00552         {} 
00553         /// Explicit constructor: stores value as parameter
00554         explicit simulation_parameter(T value) 
00555             : EmptyFlag(false), Value(value) 
00556         {} 
00557         /// Copy constructor: deep copy of parameter value
00558         simulation_parameter(const simulation_parameter& p) 
00559             : EmptyFlag(p.EmptyFlag), Value(p.Value) 
00560         {} 
00561         ~simulation_parameter() 
00562         {}
00563 
00564         
00565         /////////////////////////////////////////////////////////////////////////////////
00566         // Access methods
00567         
00568         /// Returns true if parameter is empty, false otherwise.
00569         bool empty() const { return EmptyFlag; } 
00570         /// Returns a copy of the parameter value
00571         value_type get() const { return Value; } 
00572         /// Automatic conversion to parameter type
00573         operator value_type() const { return get(); } 
00574 
00575     private:
00576         simulation_parameter& operator=(const simulation_parameter& p);
00577 
00578         const bool EmptyFlag;
00579         value_type Value;
00580     };
00581 
00582 
00583     // Helper function that returns an empty simulation_parameter object for the template type.
00584     template<typename T>
00585     inline simulation_parameter<T> make_empty_parameter() { return simulation_parameter<T>(); }
00586     
00587     // Helper function that returns a simulation_parameter object for the template type specified in argument list.
00588     template<typename T>
00589     inline simulation_parameter<T> make_parameter(T value) { return simulation_parameter<T>( value ); }
00590 
00591     
00592     // Type definition for the supported parameters so far
00593     typedef simulation_parameter<bool>     TRestartFlag;  ///< Parameter type describing the restart flag
00594     typedef simulation_parameter<double>   TStopTime;     ///< Parameter type describing the stop time
00595     typedef simulation_parameter<double>   TTimeStep;     ///< Parameter type describing the time step
00596 
00597 
00598     /// \brief Simulates the <code>instance</code> problem until the final time or the stopping time is
00599     ///        reached, whichever occurs first. 
00600     ///
00601     /// This function calls the TProblem:Simulate() method after having sent the appropriate requests
00602     /// for the specified simulation parameters.
00603     /// Uses the initial time step if specified. By default there is no initial time step parameter.
00604     /// Starts with a static step if the restart flag is set to true.
00605     ///
00606     /// \pre The problem must have been initialized.
00607     ///
00608     /// \return Simulation flag
00609     /// \param  instance        Address of the SPARK::TProblem object
00610     /// \param  restartFlag     Boolean flag. If true, forces the simulation to (re-)start with a static step to 
00611     ///                         ensure consistent initialization.
00612     /// \param  stopTime        Value of the desired stopping time as a double parameter.
00613     ///                         If not specified, the simulation ends when the final time specified in the runtime 
00614     ///                         controls is reached.
00615     /// \param  initialTimeStep Value of the candidate initial time step as a double parameter.
00616     API_DECLSPEC(SPARK::TProblem::SimulationFlags) Simulate(
00617         SPARK::TProblem* instance, 
00618         const SPARK::Problem::TRestartFlag& restartFlag,
00619         const SPARK::Problem::TStopTime& stopTime,
00620         const SPARK::Problem::TTimeStep& initialTimeStep = SPARK::Problem::TTimeStep()
00621     );
00622 
00623 
00624     /// \brief  Computes the next step of the <code>instance</code> problem and returns the simulation flag.
00625     ///
00626     /// This function essentially sends a stop() request to the instance problem and calls the 
00627     /// TProblem::Simulate() method. This forces the finite-state machine to stop after the first step.
00628     ///
00629     /// If the finite-state machine is set to perform a static step following a prior restart request, then
00630     /// the next step is a static step. Otherwise, it will perform the next dynamic step with the candidate
00631     /// time step if specified.
00632     ///
00633     /// \note When calling this function make sure that the runtime controls do not request a final snapshot
00634     ///       file as this would be generated each time the problem steps forward, therefore being very 
00635     ///       resource intensive. When stepping the problem as opposed to simulating it, prefer requesting
00636     ///       a snapshot file using the snapshot request when needed.
00637     ///
00638     /// \pre The problem must have been initialized.
00639     ///
00640     /// \param  instance   Address of the SPARK::TProblem object
00641     /// \param  timeStep   Candidate time step
00642     API_DECLSPEC(SPARK::TProblem::SimulationFlags) Step(
00643         SPARK::TProblem* instance, 
00644         const SPARK::Problem::TTimeStep& timeStep = SPARK::Problem::TTimeStep()
00645     );
00646 
00647 
00648     /// \brief  Computes one static step for the <code>instance</code> problem and returns the simulation flag.
00649     ///
00650     /// This function essentially sends a stop() request to the instance problem and calls the 
00651     /// TProblem::Simulate() method. This forces the finite-state machine to stop after the first step.
00652     ///
00653     /// \pre The problem must have been initialized.
00654     ///
00655     /// \param  instance   Address of the SPARK::TProblem object
00656     API_DECLSPEC(SPARK::TProblem::SimulationFlags) StaticStep(SPARK::TProblem* instance);
00657 
00658 
00659         //@}
00660         /////////////////////////////////////////////////////////////////////////////////////
00661 
00662 
00663 };  }; // namespace SPARK::Problem
00664 /////////////////////////////////////////////////////////////////////////////////////////
00665 
00666 
00667 #endif  //__SPARKAPI_H__
00668 
00669 


Generated on 5 Nov 2003 for VisualSPARK 2.01