Model.hpp

Go to the documentation of this file.
00001 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00002 //
00003 //        This file is part of E-Cell Simulation Environment package
00004 //
00005 //                Copyright (C) 2000-2004 Keio University
00006 //
00007 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00008 //
00009 //
00010 // E-Cell is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2 of the License, or (at your option) any later version.
00014 // 
00015 // E-Cell is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 // See the GNU General Public License for more details.
00019 // 
00020 // You should have received a copy of the GNU General Public
00021 // License along with E-Cell -- see the file COPYING.
00022 // If not, write to the Free Software Foundation, Inc.,
00023 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 // 
00025 //END_HEADER
00026 //
00027 // written by Koichi Takahashi <shafi@e-cell.org>,
00028 // E-Cell Project.
00029 //
00030 
00031 #ifndef __MODEL_HPP
00032 #define __MODEL_HPP
00033 
00034 #include "AssocVector.h"
00035 
00036 #include "libecs.hpp"
00037 
00038 #include "EventScheduler.hpp"
00039 #include "StepperEvent.hpp"
00040 
00041 namespace libecs
00042 {
00043 
00044   /** @addtogroup model The Model.
00045 
00046       The model.
00047 
00048       @ingroup libecs
00049       @{ 
00050    */ 
00051 
00052   /** @file */
00053 
00054 
00055   DECLARE_ASSOCVECTOR( String, StepperPtr, std::less< const String >,
00056                        StepperMap ); 
00057 
00058   
00059 
00060   /**
00061      Model class represents a simulation model.
00062 
00063      Model has a list of Steppers and a pointer to the root system.
00064 
00065   */
00066 
00067   class Model
00068   {
00069 
00070   protected:
00071 
00072     typedef EventScheduler<StepperEvent> StepperEventScheduler;
00073     typedef StepperEventScheduler::EventIndex EventIndex;
00074 
00075   public:
00076 
00077     ECELL_API Model();
00078     ECELL_API ~Model();
00079 
00080     /**
00081        Initialize the whole model.
00082 
00083        This method must be called before running the model, and when
00084        structure of the model is changed.
00085 
00086        Procedure of the initialization is as follows:
00087 
00088        1. Initialize Systems recursively starting from theRootSystem.
00089           ( System::initialize() )
00090        2. Check if all the Systems have a Stepper each.
00091        3. Initialize Steppers. ( Stepper::initialize() )
00092        4. Construct Stepper interdependency graph 
00093           ( Stepper::updateDependentStepperVector() )
00094 
00095 
00096        @throw InitializationFailed
00097     */
00098 
00099     ECELL_API void initialize();
00100 
00101     /**
00102        Conduct a step of the simulation.
00103 
00104        @see Scheduler
00105     */
00106 
00107     void step()
00108     {
00109       StepperEventCref aNextEvent( theScheduler.getTopEvent() );
00110       theCurrentTime = aNextEvent.getTime();
00111       theLastStepper = aNextEvent.getStepper();
00112 
00113       theScheduler.step();
00114     }
00115 
00116 
00117     /**
00118        Get the next event to occur on the scheduler.
00119 
00120      */
00121 
00122     const StepperEvent& getTopEvent() const
00123     {
00124       return theScheduler.getTopEvent();
00125     }
00126 
00127 
00128     /**
00129        Returns the current time.
00130 
00131        @return time elasped since start of the simulation.
00132     */
00133 
00134     const Real getCurrentTime() const
00135     {
00136       return theCurrentTime;
00137     }
00138 
00139 
00140     const StepperPtr getLastStepper() const
00141     {
00142       return theLastStepper;
00143     }
00144 
00145     /**
00146        Creates a new Entity object and register it in an appropriate System
00147        in  the Model.
00148 
00149        @param aClassname
00150        @param aClassType
00151     */
00152 
00153     ECELL_API PolymorphMap getClassInfo( StringCref aClassType, StringCref aClassname, Integer forceReload );
00154 
00155     /**
00156        Creates a new Entity object and register it in an appropriate System
00157        in  the Model.
00158 
00159        @param aClassname
00160        @param aFullID
00161        @param aName
00162     */
00163 
00164     ECELL_API void createEntity( StringCref aClassname, FullIDCref aFullID );
00165 
00166 
00167     /**
00168        This method finds an Entity object pointed by the FullID.
00169 
00170        @param aFullID a FullID of the requested Entity.
00171        @return A borrowed pointer to an Entity specified by the FullID.
00172     */
00173 
00174     ECELL_API EntityPtr getEntity( FullIDCref aFullID ) const;
00175 
00176     /**
00177        This method finds a System object pointed by the SystemPath.  
00178 
00179 
00180        @param aSystemPath a SystemPath of the requested System.
00181        @return A borrowed pointer to a System.
00182     */
00183 
00184 
00185     ECELL_API SystemPtr getSystem( SystemPathCref aSystemPath ) const;
00186 
00187 
00188     /**
00189        Create a stepper with an ID and a classname. 
00190 
00191        @param aClassname  a classname of the Stepper to create.  
00192 
00193        @param anID        a Stepper ID string of the Stepper to create.  
00194 
00195     */
00196 
00197     ECELL_API void createStepper( StringCref aClassname, StringCref anID );
00198 
00199 
00200     /**
00201        Get a stepper by an ID.
00202 
00203        @param anID a Stepper ID string of the Stepper to get.
00204        @return a borrowed pointer to the Stepper.
00205     */
00206 
00207     ECELL_API StepperPtr getStepper( StringCref anID ) const;
00208 
00209 
00210     /**
00211        Get the StepperMap of this Model.
00212 
00213        @return the const reference of the StepperMap.
00214     */
00215 
00216     StepperMapCref getStepperMap() const
00217     {
00218       return theStepperMap;
00219     }
00220 
00221 
00222 
00223 
00224     /**
00225        Flush the data in all Loggers immediately.
00226 
00227        Usually Loggers record data with logging intervals.  This method
00228        orders every Logger to write the data immediately ignoring the
00229        logging interval.
00230 
00231     */
00232 
00233     ECELL_API void flushLoggers();
00234 
00235 
00236     /**
00237        Get the RootSystem.
00238 
00239        @return a borrowed pointer to the RootSystem.
00240     */
00241 
00242     SystemPtr getRootSystem() const
00243     {
00244       return theRootSystemPtr;
00245     }
00246 
00247 
00248     SystemStepperPtr getSystemStepper() const
00249     {
00250       return theSystemStepperPtr;
00251     }
00252 
00253 
00254 
00255 
00256     /**
00257        Get the LoggerBroker.
00258 
00259        @return a borrowed pointer to the LoggerBroker.
00260     */
00261 
00262     LoggerBrokerRef getLoggerBroker() const
00263     { 
00264       return theLoggerBroker; 
00265     }
00266 
00267     StepperEventScheduler&   getScheduler() { return theScheduler; }
00268 
00269     /// @internal
00270 
00271     StepperMakerRef     getStepperMaker()     { return theStepperMaker; }
00272 
00273     /// @internal
00274 
00275     ProcessMakerRef     getProcessMaker()     { return theProcessMaker; }
00276 
00277     /// @internal
00278 
00279     VariableMakerRef    getVariableMaker()    { return theVariableMaker; }
00280 
00281     /// @internal
00282 
00283     SystemMakerRef      getSystemMaker()      { return theSystemMaker; }
00284 
00285 
00286   private:
00287 
00288     /**
00289        This method checks recursively if all systems have Steppers
00290        connected.
00291 
00292        @param aSystem a root node to start recursive search.
00293        
00294        @throw InitializationFailed if the check is failed.
00295     */
00296 
00297     void checkStepper( SystemCptr const aSystem ) const;
00298 
00299     void checkSizeVariable( SystemCptr const aSystem );
00300 
00301     static void initializeSystems( SystemPtr const aSystem );
00302 
00303   private:
00304 
00305     Time                theCurrentTime;
00306     StepperPtr          theLastStepper;
00307 
00308     StepperEventScheduler theScheduler;
00309 
00310     LoggerBrokerRef     theLoggerBroker;
00311 
00312     SystemPtr           theRootSystemPtr;
00313  
00314     SystemStepperPtr    theSystemStepperPtr;
00315 
00316     StepperMap          theStepperMap;
00317 
00318     StepperMakerRef     theStepperMaker;
00319     SystemMakerRef      theSystemMaker;
00320     VariableMakerRef    theVariableMaker;
00321     ProcessMakerRef     theProcessMaker;
00322 
00323   };
00324 
00325   
00326   /*@}*/
00327 
00328 } // namespace libecs
00329 
00330 
00331 
00332 
00333 #endif /* __STEPPERLEADER_HPP */
00334 
00335 
00336 
00337 
00338 /*
00339   Do not modify
00340   $Author: sachiboo $
00341   $Revision: 2621 $
00342   $Date: 2006-11-24 13:19:59 +0100 (Fri, 24 Nov 2006) $
00343   $Locker$
00344 */
00345 

Generated on Fri Aug 31 18:42:39 2007 for E-CELL C++ libraries (libecs and libemc) 3.1.105 by  doxygen 1.5.3