Process.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) 1996-2002 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 __PROCESS_HPP
00032 #define __PROCESS_HPP
00033 
00034 #include <boost/mem_fn.hpp>
00035 #include <boost/functional.hpp>
00036 
00037 #include "AssocVector.h"
00038 
00039 #include "libecs.hpp"
00040 #include "Entity.hpp"
00041 #include "VariableReference.hpp"
00042 
00043 namespace libecs
00044 {
00045 
00046   /** @addtogroup entities
00047    *@{
00048    */
00049 
00050   /** @file */
00051 
00052 
00053   DECLARE_ASSOCVECTOR( String, VariableReference, std::less< const String >, 
00054                        VariableReferenceMap  );
00055 
00056   DECLARE_VECTOR( VariableReference, VariableReferenceVector );
00057 
00058   /**
00059      Process class is used to represent chemical and other phenonema which 
00060      may or may not result in change in value of one or more Variables.
00061 
00062   */
00063 
00064   LIBECS_DM_CLASS( Process, Entity )
00065   {
00066 
00067   public:
00068 
00069     LIBECS_DM_BASECLASS( Process );
00070 
00071     LIBECS_DM_OBJECT_ABSTRACT( Process )
00072       {
00073         INHERIT_PROPERTIES( Entity );
00074 
00075         PROPERTYSLOT_LOAD_SAVE( Polymorph, VariableReferenceList,
00076                                 &Process::setVariableReferenceList,
00077                                 &Process::getVariableReferenceList,
00078                                 &Process::setVariableReferenceList,
00079                                 &Process::saveVariableReferenceList );
00080 
00081         PROPERTYSLOT_SET_GET( Integer,       Priority );
00082         PROPERTYSLOT_SET_GET( String,        StepperID );
00083 
00084         PROPERTYSLOT_SET_GET_NO_LOAD_SAVE( Real,    Activity );
00085         PROPERTYSLOT_GET_NO_LOAD_SAVE(     Real,    MolarActivity );
00086 
00087         PROPERTYSLOT_GET_NO_LOAD_SAVE(     Integer, IsContinuous );
00088       }
00089 
00090     /** 
00091         Sort Processes in reversed order of 'Priority' values.
00092         (Largest one first, smallest one last)
00093         
00094 
00095     */
00096     class PriorityCompare
00097     {
00098     public:
00099       bool operator()( ProcessPtr aLhs, ProcessPtr aRhs ) const
00100       {
00101         return compare( aLhs->getPriority(), aRhs->getPriority() );
00102       }
00103 
00104       bool operator()( ProcessPtr aLhs, IntegerParam aRhs ) const
00105       {
00106         return compare( aLhs->getPriority(), aRhs );
00107       }
00108 
00109       bool operator()( IntegerParam aLhs, ProcessPtr aRhs ) const
00110       {
00111         return compare( aLhs, aRhs->getPriority() );
00112       }
00113 
00114     private:
00115 
00116       // if statement can be faster than returning an expression directly
00117       inline static bool compare( IntegerParam aLhs, IntegerParam aRhs )
00118       {
00119         if( aLhs > aRhs )
00120           {
00121             return true;
00122           }
00123         else
00124           {
00125             return false;
00126           }
00127       }
00128 
00129 
00130     };
00131 
00132 
00133   public:
00134 
00135     ECELL_API Process();
00136     ECELL_API virtual ~Process();
00137 
00138     virtual const EntityType getEntityType() const
00139     {
00140       return EntityType( EntityType::PROCESS );
00141     }
00142 
00143     ECELL_API virtual void initialize();
00144     
00145     virtual void fire() = 0;
00146     
00147     virtual GET_METHOD( Real, StepInterval )
00148     {
00149       return INF;
00150     }
00151 
00152 
00153     /**
00154        This method returns true if this Process is compatible with 
00155        continuous Steppers.
00156     */
00157 
00158     virtual const bool isContinuous() const
00159     {
00160       return false;
00161     }
00162     
00163     GET_METHOD( Integer, IsContinuous )
00164     {
00165       return isContinuous();
00166     }
00167 
00168     /**
00169        Set activity value.
00170 
00171        Semantics of this property can be defined in each subclass of
00172        Process.  Usually it is a turnover number if the Process represents a
00173        chemical reaction.
00174 
00175        If the value has time in its dimension, the unit should be [per
00176        second], not [per step].
00177 
00178        @param anActivity An activity value to be set.
00179        @see getActivity()
00180     */
00181 
00182     SET_METHOD( Real, Activity )
00183     { 
00184       theActivity = value; 
00185     }
00186 
00187     /**
00188        Get activity value.
00189 
00190        @see setActivity()
00191        @return the activity value of this Process.
00192     */
00193 
00194     GET_METHOD( Real, Activity )
00195     {
00196       return theActivity;
00197     }
00198 
00199     ECELL_API SET_METHOD( Polymorph, VariableReferenceList );
00200     ECELL_API GET_METHOD( Polymorph, VariableReferenceList );
00201     ECELL_API SAVE_METHOD( Polymorph, VariableReferenceList );
00202 
00203 
00204     GET_METHOD( Real, MolarActivity )
00205     {
00206       return theActivity / ( getSuperSystem()->getSize() * N_A );
00207     }
00208 
00209 
00210     /**
00211        Set a priority value of this Process.
00212 
00213        The priority is an Integer value which is used to determine the
00214        order of call to Process::fire() method in Stepper.
00215 
00216        @param aValue the priority value as an Integer.
00217        @see Stepper
00218     */
00219 
00220     SET_METHOD( Integer, Priority )
00221     {
00222       thePriority = value;
00223     }
00224 
00225     /**
00226        @see setPriority()
00227     */
00228 
00229     GET_METHOD( Integer, Priority )
00230     {
00231       return thePriority;
00232     }
00233 
00234     /**
00235        Register the Stepper of this Process by an ID.
00236 
00237        @param anID Stepper ID.
00238     */
00239 
00240     ECELL_API SET_METHOD( String, StepperID );
00241 
00242     /**
00243        Get an ID of the Stepper of this Process.
00244 
00245        @return StepperID as a String.
00246     */
00247 
00248     ECELL_API GET_METHOD( String, StepperID );
00249 
00250 
00251 
00252     /**
00253        Create a new VariableReference.
00254 
00255        This method gets a Polymorph which contains
00256        ( name, [ fullid, [ [ coefficient ] , accessor_flag ] ] ).
00257 
00258        If only the name is given, the VariableReference with the name
00259        is removed from this Process.
00260 
00261        Default values of coefficient and accessor_flag are 0 and true (1).
00262        
00263        @param aValue a PolymorphVector specifying a VariableReference.
00264     */
00265 
00266     void setVariableReference( PolymorphVectorCref aValue );
00267 
00268     void removeVariableReference( StringCref aName );
00269 
00270 
00271     /**
00272        Register a new VariableReference to theVariableReferenceVector.
00273 
00274        VariableReferences are sorted by coefficients, preserving the relative
00275        order by the names.
00276 
00277        @param aName name of the VariableReference. 
00278        @param aVariable a Pointer to the Variable.
00279        @param aCoefficient an Integer value of the coefficient.
00280     */
00281 
00282     void registerVariableReference( StringCref aName, 
00283                                     VariablePtr aVariable, 
00284                                     IntegerParam aCoefficient, 
00285                                     const bool isAccessor = true );
00286 
00287     /**
00288        Get VariableReference by a tag name.
00289 
00290        @param aVariableReferenceName
00291        @return a VariableReference
00292        @see VariableReference
00293     */
00294 
00295     ECELL_API VariableReferenceCref getVariableReference( StringCref aVariableReferenceName );
00296 
00297     /**
00298        @return a const reference to the VariableReferenceVector
00299     */
00300 
00301     VariableReferenceVectorCref getVariableReferenceVector() const
00302     {
00303       return theVariableReferenceVector;
00304     }
00305 
00306     VariableReferenceVector::size_type getZeroVariableReferenceOffset() const
00307     {
00308       return theZeroVariableReferenceIterator - 
00309         getVariableReferenceVector().begin();
00310     }
00311 
00312     VariableReferenceVector::size_type 
00313     getPositiveVariableReferenceOffset() const
00314     {
00315       return thePositiveVariableReferenceIterator - 
00316         getVariableReferenceVector().begin();
00317     }
00318 
00319 
00320 
00321 
00322     void setStepper( StepperPtr const aStepper );
00323 
00324     /**
00325        Returns a pointer to a Stepper object that this Process belongs.
00326 
00327        @return A pointer to a Stepper object that this Process, or
00328        NULLPTR if it is not set yet.
00329     */
00330 
00331     StepperPtr getStepper() const
00332     {
00333       return theStepper;
00334     }
00335 
00336     ModelPtr getModel() const
00337     {
00338       return getSuperSystem()->getModel();
00339     }
00340 
00341 
00342     /**
00343        Add a value to each of VariableReferences.
00344 
00345        For each VariableReference, the new value is: 
00346        old_value + ( aValue * theCoeffiencnt ).
00347 
00348        VariableReferences with zero coefficients are skipped for optimization.
00349 
00350        This is a convenient method for use in subclasses.
00351 
00352        @param aValue aReal value to be added.
00353     */
00354 
00355     void addValue( RealParam aValue )
00356     {
00357       setActivity( aValue );
00358 
00359       // Increase or decrease variables, skipping zero coefficients.
00360       std::for_each( theVariableReferenceVector.begin(),
00361                      theZeroVariableReferenceIterator,
00362                      boost::bind2nd
00363                      ( boost::mem_fun_ref
00364                        ( &VariableReference::addValue ), aValue ) );
00365 
00366       std::for_each( thePositiveVariableReferenceIterator,
00367                      theVariableReferenceVector.end(),
00368                      boost::bind2nd
00369                      ( boost::mem_fun_ref
00370                        ( &VariableReference::addValue ), aValue ) );
00371     }
00372 
00373 
00374     /**
00375        Set velocity of each VariableReference according to stoichiometry.
00376 
00377        VariableReferences with zero coefficients are skipped for optimization.
00378 
00379        This is a convenient method for use in subclasses.
00380 
00381        @param aVelocity a base velocity to be added.
00382     */
00383 
00384     void setFlux( RealParam aVelocity )
00385     {
00386       setActivity( aVelocity );
00387     }
00388 
00389     /**
00390        Unset all the product species' isAccessor() bit.
00391 
00392        Product species here means VariableReferences those have positive 
00393        non-zero coefficients.
00394 
00395        As a result these becomes write-only VariableReferences.
00396 
00397        This method is typically called in initialize() of subclasses.
00398        This method should be called before getVariableReference().
00399 
00400        This is a convenient method.
00401 
00402     */
00403 
00404     ECELL_API void declareUnidirectional();
00405 
00406 
00407     /**
00408        Check if this Process can affect on a given Process.
00409        
00410 
00411     */
00412 
00413     const bool isDependentOn( const ProcessCptr aProcessPtr ) const;
00414 
00415 
00416   protected:
00417 
00418     ECELL_API VariableReferenceVectorIterator findVariableReference( StringCref aName );
00419 
00420     void updateVariableReferenceVector();
00421 
00422     //    static const Polymorph 
00423     //      convertVariableReferenceToPolymorph( VariableReferenceCref 
00424     //                                     aVariableReference );
00425 
00426     //    static const VariableReference 
00427     //      convertPolymorphToVariableReference( PolymorphCref aPolymorph );
00428 
00429   protected:
00430 
00431     VariableReferenceVector theVariableReferenceVector;
00432 
00433     VariableReferenceVectorIterator theZeroVariableReferenceIterator;
00434     VariableReferenceVectorIterator thePositiveVariableReferenceIterator;
00435 
00436   private:
00437 
00438     StepperPtr  theStepper;
00439 
00440     Real        theActivity;
00441     Integer     thePriority;
00442 
00443   };
00444 
00445 
00446   /*@}*/
00447 
00448 } // namespace libecs
00449 
00450 #endif /* __PROCESS_HPP */
00451 
00452 /*
00453   Do not modify
00454   $Author: sachiboo $
00455   $Revision: 2624 $
00456   $Date: 2006-11-24 13:32:35 +0100 (Fri, 24 Nov 2006) $
00457   $Locker$
00458 */

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