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

prefs.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////////////////
00002 /// \file  prefs.h 
00003 /// \brief Header file for the definition of the classes SPARK::TGlobalSettings, 
00004 ///        SPARK::TComponentSettings and SPARK::TPreferenceSettings.
00005 ///
00006 /// The SPARK::TPreferenceSettings class is a wrapper class that manages the settings for all
00007 /// components, including the default settings and the global settings.
00008 ///
00009 /// The SPARK::TGlobalSettings class is a wrapper class that contains the global solution method
00010 /// settings defined at the problem level in the section \c GlobalSettings of the *.prf file.
00011 ///
00012 /// The SPARK::TComponentSettings class is a wrapper class that contains the solution method
00013 /// settings defined for each component under the section \c ComponentSettings of the *.prf file.
00014 ///
00015 /////////////////////////////////////////////////////////////////////////////////////////
00016 /// \attention
00017 /// PORTIONS COPYRIGHT (C) 2003 AYRES SOWELL ASSOCIATES, INC. \n
00018 /// PORTIONS COPYRIGHT (C) 2003 THE REGENTS OF THE UNIVERSITY OF CALIFORNIA .
00019 ///   PENDING APPROVAL BY THE US DEPARTMENT OF ENERGY. ALL RIGHTS RESERVED.
00020 ///
00021 /////////////////////////////////////////////////////////////////////////////////////////
00022 /// \author  Dimitri Curtil (LBNL/SRG)
00023 /// \date    January 6, 2003
00024 /////////////////////////////////////////////////////////////////////////////////////////
00025 
00026 
00027 // Gets rid of warning messages about dll-interface for private data member
00028 // Message shows typically with std classes, e.g., std::string
00029 #pragma warning(disable:4251)
00030 
00031 
00032 #if !defined(__PREFS_H__)
00033 #define __PREFS_H__
00034 
00035 #include <ctime>
00036 #include <cstdlib>
00037 #include <iosfwd>
00038 #include <string>
00039 #include <map>
00040 
00041 #include "exceptions.h"     // For SPARK::XInitialization and SPARK::XIO
00042 #include "compat.h"         // for CLASS_DECLSPEC
00043 
00044 
00045 namespace SPARK { 
00046         
00047         /////////////////////////////////////////////////////////////////////////////////////
00048         /// \namespace SPARK::DefaultGlobalSettings
00049         /// \brief Defines the default values for the global settings 
00050         /////////////////////////////////////////////////////////////////////////////////////
00051         namespace DefaultGlobalSettings {
00052 
00053                 /////////////////////////////////////////////////////////////////////////////////
00054                 /// \name Tolerance settings
00055                 //@{
00056                 const double Tolerance    = 1.0e-6;  ///< Relative tolerance used throughout the simulation
00057                 const double MaxTolerance = 1.0e-3;  ///< Looser relative tolerance used to recover if convergence cannot be achieved against Tolerance
00058                 //@}
00059                 /////////////////////////////////////////////////////////////////////////////////
00060                 
00061                 /////////////////////////////////////////////////////////////////////////////////
00062                 /// \name Safety factors
00063                 /// Safety factors are used to modify the convergence check depending on the context 
00064                 /// (i.e., check after prediction step or after an iteration) and on the type of the unknwon variable
00065                 /// (i.e., a normal unknwon or a break unknown). 
00066                 /// A safety factor smaller than 1 makes the convergence check tougher to satisfy, with 0 making it impossible.
00067                 /// A safety factory larger than 1 essentially corresponds to a relaxation of the convergence check. E.g, if 
00068                 /// <code>IterationSafetyFactor=10</code> then the convergence check at each iteration after the prediction
00069                 /// will be made 10 times easier to satsify than the specified tolerence, because the convergence error 
00070                 /// must be samller than < SafetyFactor*Tolerance.
00071                 /// The default safety factors are equal to 1. therefore, they treat break and normal unknowns
00072                 /// with the same weight in the convergence check. For certain applications, it might be useful to only
00073                 /// perform a convergence check on the break variables. This is achieved by setting the NormalUnknownSafetyFactor
00074                 /// entry to a number larger than 1.
00075                 //@{
00076                 const double PredictionSafetyFactor = 0.01; ///< Safety factor used to check convergence after prediction [feature added in %SPARK 2.0]
00077                 const double IterationSafetyFactor  = 0.9;  ///< Safety factor used to check convergence after each iteration [feature added in %SPARK 2.0]
00078 
00079                 const double BreakUnknownSafetyFactor  = 1.0; ///< Safety factor used to check convergence for a break unknown [feature added in %SPARK 2.0]
00080                 const double NormalUnknownSafetyFactor = 1.0; ///< Safety factor used to check convergence for a normal unknown (i.e., not a break variable) [feature added in %SPARK 2.0]
00081                 //@}
00082                 /////////////////////////////////////////////////////////////////////////////////
00083 
00084         }; // namespace DefaultGlobalSettings
00085 
00086 
00087         /////////////////////////////////////////////////////////////////////////////////////
00088         /// \namespace SPARK::DefaultComponentSettings
00089         /// \brief Defines the default values for the component settings 
00090         /////////////////////////////////////////////////////////////////////////////////////
00091         namespace DefaultComponentSettings {
00092                 
00093                 /////////////////////////////////////////////////////////////////////////////////
00094                 /// \name Component solution method
00095                 //@{
00096                 const unsigned ComponentSolvingMethod = 0; ///< Newton-Raphson method
00097                 const unsigned MaxIterations = 50; ///< Default maximum number of iterations 
00098                 const unsigned MinIterations = 1;  ///< Default minimum number of iterations 
00099                 const unsigned ScalingMethod = 0;    ///< By default, no scaling is performed
00100         const unsigned CheckBadNumericsFlag = 0; ///< Do not check for bad numerics by default [new feature added in %SPARK 2.01]
00101                 //@}
00102                 /////////////////////////////////////////////////////////////////////////////////
00103                 
00104                 /////////////////////////////////////////////////////////////////////////////////
00105                 /// \name Step control method
00106                 //@{
00107                 const unsigned StepControlMethod = 1; ///< Default step control method is basic halving backtracking strategy [changed in %SPARK 2.01]
00108                 const double   MaxRelaxationCoefficient = 1.0e+0; ///< Default maximum relaxation coefficient
00109                 const double   MinRelaxationCoefficient = 1.0e-6; ///< Default minimum relaxatio coefficient
00110                 //@}
00111                 /////////////////////////////////////////////////////////////////////////////////
00112 
00113                 /////////////////////////////////////////////////////////////////////////////////
00114                 /// \name Jacobian evaluation method
00115                 //@{
00116                 const unsigned TrueJacobianEvalStep = 0;   ///< Refresh Jacobian automatically
00117                 const double   Epsilon              = 0.0; ///< By default, use scaled perturbation
00118                 const double   JacobianRefreshRatio = 0.5; ///< Jacobian refreshed if ResidualsNorm > JacobianRefreshRatio*PrevIterationResidualsNorm by default
00119                 //@}
00120                 /////////////////////////////////////////////////////////////////////////////////
00121                 
00122                 /////////////////////////////////////////////////////////////////////////////////
00123                 /// \name Matrix solution method
00124                 //@{
00125                 const unsigned MatrixSolvingMethod = 0; ///< Gaussian elimination method for dense matrix
00126                 const unsigned PivotingMethod = 1;   ///< Partial pivoting by default 
00127                 const unsigned RefinementMethod = 0; ///< No refinement iterations by default
00128                 //@}
00129                 /////////////////////////////////////////////////////////////////////////////////
00130         
00131         }; // namespace DefaultComponentSettings
00132 
00133 }; // namespace SPARK
00134 /////////////////////////////////////////////////////////////////////////////////////////
00135 
00136 
00137 
00138 /////////////////////////////////////////////////////////////////////////////////////////
00139 namespace SPARK {
00140 
00141         /////////////////////////////////////////////////////////////////////////////////////
00142         // Forward declaration
00143         /////////////////////////////////////////////////////////////////////////////////////
00144         class TPrefList;
00145     class XInitialization;
00146     class XIO;
00147 
00148 
00149         /////////////////////////////////////////////////////////////////////////////////////
00150         /// \class TGlobalSettings
00151         /// \brief Class acts as repository of global control settings defined at the problem level
00152         ///
00153         /// Behavior:
00154         ///   - compile-time default values are initialized with the hard-coded values 
00155         ///   - then at runtime, values are overloaded with the values specified in the *.prf file 
00156         ///     in the section \c GlobalSettings
00157         ///
00158         /// See namespace SPARK::DefaultGlobalSettings for a list of the default hard-coded values.
00159         ///
00160         class CLASS_DECLSPEC TGlobalSettings {
00161         public:
00162                 /////////////////////////////////////////////////////////////////////////////////
00163                 /// \name Structors
00164                 //@{
00165                 /// Initialize all settings to compile-time default values
00166                 TGlobalSettings(); 
00167                 /// Copy constructor
00168                 TGlobalSettings(const TGlobalSettings& ); 
00169                 /// Trivial destructor
00170                 ~TGlobalSettings() SPARK_NOT_THROWING; 
00171                 //@}
00172                 /////////////////////////////////////////////////////////////////////////////////
00173 
00174                 
00175                 /////////////////////////////////////////////////////////////////////////////////
00176                 /// \name Main operations
00177                 //@{
00178                 /// \brief Resets settings to default values
00179                 /// See namespace SPARK::DefaultSettings
00180                 void Reset();  
00181                 /// Performs shallow copy of prefList into member datum PrefList and loads hard-coded settings.
00182                 void Load(SPARK::TPrefList* prefList); 
00183                 //@}
00184                 /////////////////////////////////////////////////////////////////////////////////
00185                 
00186                 
00187                 /////////////////////////////////////////////////////////////////////////////////
00188                 /// \name Access methods for hard-coded global settings
00189                 //@{
00190                 /// Returns the value of the relative tolerance specified with the key Tolerance in the GlobalSettings section of the *.prf file
00191                 double GetTolerance() const { return Tolerance; }
00192                 /// Sets relative tolerance to \c scalar
00193                 void SetTolerance(double scalar) { Tolerance = scalar; }
00194                 
00195                 /// Returns the value of the max relative tolerance specified with the key MaxTolerance in the GlobalSettings section of the *.prf file
00196                 double GetMaxTolerance() const { return MaxTolerance; }
00197                 /// Sets the max relative tolerance to \c scalar
00198                 void SetMaxTolerance(double scalar) { MaxTolerance = scalar; }
00199 
00200                 /// Returns the prediction safety factor (used in convergence test) as \c double
00201                 double GetPredictionSafetyFactor() const { return PredictionSafetyFactor; } 
00202                 /// Sets the prediction safety factor to \c factor
00203                 void SetPredictionSafetyFactor(double factor) { PredictionSafetyFactor = factor; } 
00204 
00205                 /// Returns the iteration safety factor (used in convergence test) as \c double
00206                 double GetIterationSafetyFactor() const { return IterationSafetyFactor; } 
00207                 /// Sets the iteration safety factor to \c factor
00208                 void SetIterationSafetyFactor(double factor) { IterationSafetyFactor = factor; } 
00209 
00210                 /// Returns the safety factor for a break unknown (used in convergence test) as \c double
00211                 double GetBreakUnknownSafetyFactor() const { return BreakUnknownSafetyFactor; } 
00212                 /// Sets the safety factor for a break unknown to \c factor
00213                 void SetBreakUnknownSafetyFactor(double factor) { BreakUnknownSafetyFactor = factor; } 
00214 
00215                 /// Returns the safety factor for a normal unknown (used in convergence test) as \c double
00216                 double GetNormalUnknownSafetyFactor() const { return NormalUnknownSafetyFactor; } 
00217                 /// Sets the safety factor for a normal unknown to \c factor
00218                 void SetNormalUnknownSafetyFactor(double factor) { NormalUnknownSafetyFactor = factor; } 
00219                 //@}
00220                 /////////////////////////////////////////////////////////////////////////////////
00221 
00222 
00223                 /////////////////////////////////////////////////////////////////////////////////
00224                 /// \name Access methods for customized global settings 
00225                 ///
00226                 /// \note The key can be specified either as a simple key with "Key" or a complex key with "Key1:Key2"
00227                 //@{
00228                 /// Returns as const char* the entry for the key in the GlobalSettings section of the *.prf file
00229                 const char* GetString(const std::string& key, const std::string& defaultString) const;
00230                 /// Returns as double the entry for the key in the GlobalSettings section of the *.prf file
00231                 double GetScalar(const std::string& key, double defaultScalar) const;
00232                 /// Returns as unsigned the entry for the key in the GlobalSettings section of the *.prf file
00233                 unsigned GetCount(const std::string& key, unsigned defaultCount) const;
00234                 //@}
00235                 /////////////////////////////////////////////////////////////////////////////////
00236 
00237                 
00238                 /////////////////////////////////////////////////////////////////////////////////
00239                 /// \name I/O Operations
00240                 //@{
00241                 /// Writes the list of global settings to os
00242                 ///
00243                 /// \note Only hard-coded global settings are printed since the other settings are not known a priori.
00244                 void Write(std::ostream& os, const std::string& before) const; 
00245                 //@}
00246                 /////////////////////////////////////////////////////////////////////////////////
00247 
00248 
00249         private:
00250                 /// Assignment operator not implemented.
00251                 TGlobalSettings& operator=(const TGlobalSettings& ); 
00252 
00253                 void SetString(const std::string& key, const std::string& newString);
00254                 void SetScalar(const std::string& key, double newScalar);
00255                 void SetCount(const std::string& key, unsigned newCount);
00256 
00257 
00258                 /////////////////////////////////////////////////////////////////////////////////
00259                 // Member data
00260                 double      Tolerance;
00261                 double      MaxTolerance;   ///< \note MaxTolerance >= Tolerance
00262                 
00263                 double      PredictionSafetyFactor;
00264                 double      IterationSafetyFactor;
00265 
00266                 double      BreakUnknownSafetyFactor;
00267                 double      NormalUnknownSafetyFactor;
00268 
00269                 SPARK::TPrefList*  PrefList;    ///< Not owned by this class (used to query customized global settings)
00270         };
00271         /////////////////////////////////////////////////////////////////////////////////////
00272 
00273 
00274         ////////////////////////////////////////////////////////////////////////////////////
00275         /// \class TComponentSettings
00276         /// \brief Class acts as repository of settings defined for each component 
00277         ///
00278         /// Behavior:
00279         ///   - compile-time default values are initialized with the hard-coded values.
00280         ///   - then at runtime, values are overloaded with the ones specified in the *.prf file
00281         ///     in the section \c ComponentSettings for each component.
00282         ///
00283         /// See namespace SPARK::DefaultComponentSettings for the list of hard-coded default settings.
00284         /// \note By default, no tracer file names are specified.
00285         ///
00286         class CLASS_DECLSPEC TComponentSettings {
00287         public:
00288                 /////////////////////////////////////////////////////////////////////////////////
00289                 /// \name Structors
00290                 //@{
00291                 /// Initialize all settings to compile-time default values
00292                 TComponentSettings(); 
00293                 /// Copy constructor
00294                 TComponentSettings(const TComponentSettings& ); 
00295                 /// Assignement operator
00296                 TComponentSettings& operator=(const TComponentSettings& ); 
00297                 /// Trivial destructor
00298                 ~TComponentSettings() SPARK_NOT_THROWING
00299                 {}
00300                 //@}
00301                 /////////////////////////////////////////////////////////////////////////////////
00302 
00303                 
00304                 /////////////////////////////////////////////////////////////////////////////////
00305                 /// \name Main operations
00306                 //@{
00307                 /// Resets settings to default values
00308                 void Reset();  
00309                 /// Loads all settings from prefList
00310                 void Load(SPARK::TPrefList* prefList); 
00311                 //@}
00312                 /////////////////////////////////////////////////////////////////////////////////
00313                 
00314                 
00315                 /////////////////////////////////////////////////////////////////////////////////
00316                 /// \name Access methods for nonlinear solver
00317                 //@{
00318                 /// \brief Returns the code for the component solving method as \c unsigned
00319                 ///
00320                 /// List of codes:
00321                 ///  \li Newton-Raphson method = 0
00322                 ///  \li Perturbed Newton-Raphson method = 1
00323                 ///  \li Fixed-point iteration (aka forward substitution) = 2
00324                 ///  \li Secant method (Newton method with Broyden's update formula) = 4
00325                 unsigned GetComponentSolvingMethod() const { return ComponentSolvingMethod; } 
00326                 /// Sets the code for the component solving method to \c method
00327                 void SetComponentSolvingMethod(unsigned method) { ComponentSolvingMethod = method; } 
00328 
00329                 /// Returns the maximum number of iterations allowed in the nonlinear solver as \c unsigned
00330                 unsigned GetMaxIterations() const { return MaxIterations; } 
00331                 /// Sets the maximum number of iterations allowed in the nonlinear solver to \c maxIterations
00332                 void SetMaxIterations(unsigned maxIterations) { MaxIterations = maxIterations; } 
00333                 
00334                 /// Returns the minimum number of iterations allowed in the nonlinear solver as \c unsigned
00335                 unsigned GetMinIterations() const { return MinIterations; } 
00336                 /// Sets the minimum number of iterations allowed in the nonlinear solver to \c minIterations
00337                 void SetMinIterations(unsigned minIterations) { MinIterations = minIterations; } 
00338                 
00339         /// Returns the boolean flag (0=false | 1=true) indicating whether or not the solver will check for bad numerics at each iteration as \c unsigned
00340         unsigned GetCheckBadNumericsFlag() const { return CheckBadNumericsFlag; }
00341         /// Sets the flag indicating whether or not the solver will check for bad numerics at each iteration
00342         void SetCheckBadNumericsFlag(unsigned flag) { CheckBadNumericsFlag = flag; }
00343 
00344         //@}
00345                 /////////////////////////////////////////////////////////////////////////////////
00346                 
00347                 /////////////////////////////////////////////////////////////////////////////////
00348                 /// \name Access methods for jacobian evaluation method
00349                 //@{
00350                 /// \brief Returns the number of iterations until the Jacobian should be refreshed as \c unsigned
00351                 ///
00352                 /// \note  If it is equal to 0 then it is automatically refreshed by the solver when the convergence process becomes to slow or diverging.
00353                 unsigned GetTrueJacobianEvalStep() const { return TrueJacobianEvalStep; } 
00354                 /// Sets the number of iterations until the jacobian should be refreshed to \c frequency
00355                 void SetTrueJacobianEvalStep(unsigned frequency) { TrueJacobianEvalStep = frequency; }
00356 
00357                 /// Returns the threshold value of the ratio of the residual norms over successive iterations that triggers a Jacobian refresh as \c double
00358                 double GetJacobianRefreshRatio() const { return JacobianRefreshRatio; }
00359                 /// Sets the threshold value of the ratio of the residual norms over successive iterations that triggers a Jacobian refresh to \c refreshRatio
00360                 void SetJacobianRefreshRatio(double refreshRatio) { JacobianRefreshRatio = refreshRatio; }
00361 
00362                 /// \brief Returns the perturbation value used to estimate the partial derivatives with finite-differences as \c double
00363                 ///
00364                 /// \note If it is equal to 0, then solver automatically computes a scaled perturbation value for each dependent variable
00365                 double GetEpsilon() const { return Epsilon; }
00366                 /// Sets the perturbation value used to estimate the partial derivatives with finite-differences to \c epsilon
00367                 void SetEpsilon(double epsilon) { Epsilon = epsilon; }
00368 
00369                 //@}
00370                 /////////////////////////////////////////////////////////////////////////////////
00371                 
00372                 /////////////////////////////////////////////////////////////////////////////////
00373                 /// \name Access methods for step control method
00374                 //@{
00375                 /// \brief Returns the code for the step control method as \c unsigned
00376                 ///
00377                 /// List of codes:
00378                 ///  \li Fixed relaxation method = 0
00379                 ///  \li Basic backtracking method based on halving strategy = 1
00380                 ///  \li Line search backtracking method = 2
00381                 ///  \li Affine invariant backtracking strategy = 3
00382                 unsigned GetStepControlMethod() const { return StepControlMethod; }
00383                 /// Sets the code for the step control method to \c method
00384                 void SetStepControlMethod(unsigned method) { StepControlMethod = method; }
00385 
00386                 /// Returns the maximum relaxation coefficient used by the step control method as \c double
00387                 double GetMaxRelaxationCoefficient() const { return MaxRelaxationCoefficient; }
00388                 /// Sets the maximum relaxation coefficient used by the step control method to \c maxRelaxation
00389                 void SetMaxRelaxationCoefficient(double maxRelaxation) { MaxRelaxationCoefficient = maxRelaxation; }
00390                 
00391                 /// Returns the minimum relaxation coefficient used by the step control method as \c double
00392                 double GetMinRelaxationCoefficient() const { return MinRelaxationCoefficient; }
00393                 /// Sets the minimum relaxation coefficient used by the step control method to \c minRelaxation
00394                 void SetMinRelaxationCoefficient(double minRelaxation) { MinRelaxationCoefficient = minRelaxation; }
00395 
00396                 //@}
00397                 /////////////////////////////////////////////////////////////////////////////////
00398                 
00399                 /////////////////////////////////////////////////////////////////////////////////
00400                 /// \name Access methods for linear solver
00401                 //@{
00402                 /// \brief Returns the code for the linear solution method as \c unsigned
00403                 ///
00404                 /// List of codes:
00405                 ///  \li Dense Gaussian elimination = 0
00406                 ///  \li Dense singular value decomposition (SVD) = 1
00407                 ///  \li Dense LU decomposition = 2
00408                 ///  \li Dense Gauss-Jordan elimination = 3
00409                 ///  \li Sparse LU decomposition = 4  (implemented with the UMFPACK 4.0 library. See http://www.cise.ufl.edu/research/sparse/umfpack/ )
00410                 unsigned GetMatrixSolvingMethod() const { return MatrixSolvingMethod; }
00411                 /// Sets the code for the linear solution method to \c method
00412                 void SetMatrixSolvingMethod(unsigned method) { MatrixSolvingMethod = method; }
00413 
00414                 /// \brief Returns the code for the scaling method as \c unsigned
00415                 ///
00416                 /// List of codes:
00417                 ///  \li No scaling = 0
00418                 ///  \li Affine invariant scaling (in both variable and residual spaces) = 1
00419                 unsigned GetScalingMethod() const { return ScalingMethod; }
00420                 /// Sets the code for the scaling method to \c method
00421                 void SetScalingMethod(unsigned method) { ScalingMethod = method; }
00422 
00423                 /// \brief Returns the code for the pivoting method used in conjunction with the Gaussian elimination method as \c unsigned
00424                 ///
00425                 /// List of codes:
00426                 ///  \li No pivoting method = 0
00427                 ///  \li Partial pivoting method = 1
00428                 ///  \li Total pivoting method = 2
00429                 ///
00430                 /// \note The total pivoting method is implemented with the Gauss-Jordan method. See TComponentSettings::GetMatrixSolvingMethod().
00431                 unsigned GetPivotingMethod() const { return PivotingMethod; }
00432                 /// Sets the code for the pivoting method used in conjunction with the Gaussian elimination method to \c method
00433                 void SetPivotingMethod(unsigned method) { PivotingMethod = method; }
00434 
00435                 /// \brief Returns the number of desired refinement iterations as \c unsigned
00436                 ///
00437                 /// \note  Typically, 2/3 iterations is sufficient to improve the accuracy of the solution of the linear system.
00438                 unsigned GetRefinementMethod() const { return RefinementMethod; }
00439                 /// Sets the number of desired refinement iterations to \c method
00440                 void SetRefinementMethod(unsigned method) { RefinementMethod = method; }
00441 
00442                 //@}
00443                 /////////////////////////////////////////////////////////////////////////////////
00444 
00445                 /////////////////////////////////////////////////////////////////////////////////
00446                 /// \name Access methods for tracers
00447                 ///
00448                 /// \note The tracer file names must be unique across all active components and problems
00449                 ///       being solved within the same process space.
00450                 //@{
00451 
00452                 /// Returns the name of the variables tracer file as <code> const char* </code>
00453                 const char* GetVariablesTracerFilename() const { return VariablesTracerFilename.c_str(); } 
00454                 /// Sets the name of the variables tracer file to \c filename
00455                 void SetVariablesTracerFilename(const char* filename) { VariablesTracerFilename = filename; } 
00456 
00457                 /// Returns the name of the increments tracer file as <code> const char* </code>
00458                 const char* GetIncrementsTracerFilename() const { return IncrementsTracerFilename.c_str(); } 
00459                 /// Sets the name of the increments tracer file to \c filename
00460                 void SetIncrementsTracerFilename(const char* filename) { IncrementsTracerFilename = filename; } 
00461 
00462                 /// Returns the name of the residuals tracer file as <code> const char* </code>
00463                 const char* GetResidualsTracerFilename() const { return ResidualsTracerFilename.c_str(); } 
00464                 /// Sets the name of the residuals tracer file to \c filename
00465                 void SetResidualsTracerFilename(const char* filename) { ResidualsTracerFilename = filename; } 
00466 
00467                 /// Returns the name of the Jacobian tracer file as <code> const char* </code>
00468                 const char* GetJacobianTracerFilename() const { return JacobianTracerFilename.c_str(); } 
00469                 /// Sets the name of the Jacobian tracer file to \c filename
00470                 void SetJacobianTracerFilename(const char* filename) { JacobianTracerFilename = filename; } 
00471                 
00472                 //@}
00473                 /////////////////////////////////////////////////////////////////////////////////
00474 
00475 
00476                 /////////////////////////////////////////////////////////////////////////////////
00477                 /// \name I/O Operations
00478                 //@{
00479                 /// Writes the list of component settings to \c os
00480                 void Write(std::ostream& os, const std::string& before) const; 
00481                 //@}
00482                 /////////////////////////////////////////////////////////////////////////////////
00483 
00484 
00485         private:
00486                 /////////////////////////////////////////////////////////////////////////////////
00487                 // Member data
00488                 unsigned     ComponentSolvingMethod;
00489                 unsigned     MaxIterations;
00490                 unsigned     MinIterations;  ///< \note MinIterations <= MaxIterations
00491         unsigned     CheckBadNumericsFlag;
00492 
00493                 unsigned     TrueJacobianEvalStep;
00494                 double       JacobianRefreshRatio;
00495                 double       Epsilon;
00496                 
00497                 unsigned     StepControlMethod;
00498                 double       MaxRelaxationCoefficient;
00499                 double       MinRelaxationCoefficient;
00500 
00501                 unsigned     MatrixSolvingMethod;
00502                 unsigned     ScalingMethod;
00503                 unsigned     PivotingMethod;
00504                 unsigned     RefinementMethod;
00505 
00506                 std::string  VariablesTracerFilename;
00507                 std::string  IncrementsTracerFilename;
00508                 std::string  ResidualsTracerFilename;
00509                 std::string  JacobianTracerFilename;
00510         };
00511         /////////////////////////////////////////////////////////////////////////////////////
00512 
00513 
00514         /////////////////////////////////////////////////////////////////////////////////////
00515         /// \class TPreferenceSettings
00516         /// \brief Wrapper class to store and manipulate information required to initialize the
00517         ///        settings for the solution methods for each component.
00518         class CLASS_DECLSPEC TPreferenceSettings
00519         {
00520         public:
00521                 /////////////////////////////////////////////////////////////////////////////////
00522                 // Type definition
00523                 typedef unsigned                                        TComponentHandle; 
00524                 typedef std::map<TComponentHandle, TComponentSettings>  TRepository;
00525 
00526 
00527                 /////////////////////////////////////////////////////////////////////////////////
00528                 /// \name Structors
00529                 //@{
00530                 /// Loads preference settings from *.prf file named "prfFileName"
00531                 TPreferenceSettings(const char* prfFileName);
00532                 /// Trivial destructor
00533                 ~TPreferenceSettings() SPARK_NOT_THROWING;
00534                 //@}
00535                 /////////////////////////////////////////////////////////////////////////////////
00536 
00537 
00538                 /////////////////////////////////////////////////////////////////////////////////
00539                 /// \name Access methods 
00540                 //@{
00541                 /// Returns the name of the *.prf file used to construct this object as <code> const char* </code>
00542                 const char* GetPrfFileName() const { return PrfFileName.c_str(); }
00543                 
00544                 /// Returns a reference to the TGlobalSettings object containing the global setting defined in the *.prf file
00545                 TGlobalSettings& GetGlobalSettings() ;
00546                 /// Returns a const reference to the TGlobalSettings object containing the global setting defined in the *.prf file
00547                 const TGlobalSettings& GetGlobalSettings() const;
00548 
00549                 /// Returns a reference to the TCopmonentSettings object containing the component setting for the component with handle \c comphandle defined in the *.prf file
00550                 TComponentSettings& GetComponentSettings(unsigned compHandle) ;
00551                 /// Returns a const reference to the TCopmonentSettings object containing the component setting for the component with handle \c comphandle defined in the *.prf file
00552                 const TComponentSettings& GetComponentSettings(unsigned compHandle) const;
00553                 //@}
00554                 /////////////////////////////////////////////////////////////////////////////////
00555 
00556 
00557                 /////////////////////////////////////////////////////////////////////////////////
00558                 /// \name I/O Operations
00559                 //@{
00560                 /// Writes the global settings and all component settings to \c os
00561                 void Write(std::ostream& os, const std::string& before) const;
00562                 //@}
00563                 /////////////////////////////////////////////////////////////////////////////////
00564 
00565 
00566         private:
00567                 /////////////////////////////////////////////////////////////////////////////////
00568                 /// \name Operations
00569                 //@{
00570                 TPreferenceSettings();
00571                 TPreferenceSettings(const TPreferenceSettings& );
00572                 TPreferenceSettings& operator=(const TPreferenceSettings& );
00573 
00574                 /// Sets the name of the file where the preference settings are defined.
00575                 ///
00576                 /// \exception SPARK::XInitialization  Thrown if file name is not specified or NULL.
00577                 void SetPrfFileName(const char* name) SPARK_THROWING( (SPARK::XInitialization) );
00578                 
00579                 /// Checks that filename is a valid filename.
00580                 ///
00581                 /// \exception SPARK::XIO  Thrown if filename is nbot a valid filename.
00582                 void CheckFilename(std::string& filename) SPARK_THROWING( (SPARK::XIO) );
00583 
00584                 /// Loads preference settings from *.prf file
00585                 ///
00586                 /// \exception SPARK::XIO  Thrown if file could not be opened.
00587                 void LoadFromFile() SPARK_THROWING( (SPARK::XIO) );
00588                 void LoadGlobal();
00589                 void LoadDefault();
00590                 
00591                 /// Loads component settings for each component in problem.
00592                 ///
00593                 /// \exception SPARK::XInitialization  Thrown if settings for a component are duplicate or invalid.
00594                 void LoadComponents() SPARK_THROWING( (SPARK::XInitialization) );
00595                 //@}
00596                 /////////////////////////////////////////////////////////////////////////////////
00597 
00598 
00599                 /////////////////////////////////////////////////////////////////////////////////
00600                 /// \name Predicate methods
00601                 //@{
00602                 bool ArePreferencesNew() const;
00603                 //@}
00604                 /////////////////////////////////////////////////////////////////////////////////
00605 
00606 
00607         private:
00608                 /////////////////////////////////////////////////////////////////////////////////
00609                 // Data
00610                 std::string         PrfFileName;                ///< "*.prf" file name
00611 
00612                 // Declared as mutable variables because of the update at runtime scheme that
00613                 // updates the next variables at every step, therefore breaking the constness assumption
00614                 // for the methods used by the TProblem object
00615                 mutable time_t      LastTimeModified;   ///< Used to figure out when to read the prf file at run-time
00616                 mutable SPARK::TPrefList*  PrefList; 
00617 
00618                 TGlobalSettings     GlobalSettings;
00619                 TComponentSettings  DefaultSettings;
00620                 TRepository         Repository;
00621         };
00622         /////////////////////////////////////////////////////////////////////////////////////
00623 
00624 
00625 }; // namespace SPARK
00626 /////////////////////////////////////////////////////////////////////////////////////////
00627 
00628 
00629 #endif  // __PREFS_H__
00630 
00631 


Generated on 5 Nov 2003 for VisualSPARK 2.01