|
From: <mor...@us...> - 2008-10-23 18:44:28
|
Revision: 3248
http://ecell.svn.sourceforge.net/ecell/?rev=3248&view=rev
Author: moriyoshi
Date: 2008-10-23 18:44:13 +0000 (Thu, 23 Oct 2008)
Log Message:
-----------
* libecs changes:
* Fix indent / coding style.
* Fix doxygen comments.
* Remove $...$ placeholders as they may contain localized characters
which are troublesome in VC++.
* Remove obsolete FluxProcess.
* Document macros in EcsObject.hpp.
* Make Polymorph accept boost::tuple<> and const char *.
* Remove setAvg() / setMin() / setMax() from DataPoint.
* Add Logger::Policy class and remove methods that accept polymorph tuples
that contain the policy information.
* Make Process::setVariableReference() only accept VariableReference
instead of scatterd arguments for consistency with getVariableReference().
* Make Process::registerVariableReference() have the same signature as
the previous version of Process::setVariableReference().
* Remove LoggerBroker::setModel() in favor of dependency injection in
initialization.
* And more tiny changes.
* libemc changes:
* Fix indent / conding style.
* Remove obsolete FluxProcess.
The same changes were applied to SimulatorImplementation and LocalSimulatorImplementation accordingly.
* Rename Simulator::isEntityExist() to Simulator::entityExists().
* Remove Simulator::getLoggerMinimumInterval() and
Simulator::setLoggerMinimumInterval() in favor of setLoggerPolicy().
Modified Paths:
--------------
ecell3/branches/ecell-3.1/build/msvc/libecs.vcproj
ecell3/branches/ecell-3.1/ecell/libecs/ContinuousProcess.cpp
ecell3/branches/ecell-3.1/ecell/libecs/ContinuousProcess.hpp
ecell3/branches/ecell-3.1/ecell/libecs/DataPoint.cpp
ecell3/branches/ecell-3.1/ecell/libecs/DataPoint.hpp
ecell3/branches/ecell-3.1/ecell/libecs/DataPointVector.cpp
ecell3/branches/ecell-3.1/ecell/libecs/DataPointVector.hpp
ecell3/branches/ecell-3.1/ecell/libecs/DifferentialStepper.cpp
ecell3/branches/ecell-3.1/ecell/libecs/DifferentialStepper.hpp
ecell3/branches/ecell-3.1/ecell/libecs/DiscreteEventStepper.cpp
ecell3/branches/ecell-3.1/ecell/libecs/DiscreteEventStepper.hpp
ecell3/branches/ecell-3.1/ecell/libecs/DiscreteTimeStepper.cpp
ecell3/branches/ecell-3.1/ecell/libecs/DiscreteTimeStepper.hpp
ecell3/branches/ecell-3.1/ecell/libecs/DynamicPriorityQueue.hpp
ecell3/branches/ecell-3.1/ecell/libecs/EcsObject.cpp
ecell3/branches/ecell-3.1/ecell/libecs/EcsObject.hpp
ecell3/branches/ecell-3.1/ecell/libecs/EcsObjectMaker.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Entity.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Entity.hpp
ecell3/branches/ecell-3.1/ecell/libecs/EntityType.cpp
ecell3/branches/ecell-3.1/ecell/libecs/EntityType.hpp
ecell3/branches/ecell-3.1/ecell/libecs/EventScheduler.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Exceptions.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Exceptions.hpp
ecell3/branches/ecell-3.1/ecell/libecs/FullID.cpp
ecell3/branches/ecell-3.1/ecell/libecs/FullID.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Interpolant.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Interpolant.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Logger.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Logger.hpp
ecell3/branches/ecell-3.1/ecell/libecs/LoggerAdapter.cpp
ecell3/branches/ecell-3.1/ecell/libecs/LoggerAdapter.hpp
ecell3/branches/ecell-3.1/ecell/libecs/LoggerBroker.cpp
ecell3/branches/ecell-3.1/ecell/libecs/LoggerBroker.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Makefile.am
ecell3/branches/ecell-3.1/ecell/libecs/MethodProxy.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Model.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Model.hpp
ecell3/branches/ecell-3.1/ecell/libecs/PassiveStepper.cpp
ecell3/branches/ecell-3.1/ecell/libecs/PassiveStepper.hpp
ecell3/branches/ecell-3.1/ecell/libecs/PhysicalLogger.cpp
ecell3/branches/ecell-3.1/ecell/libecs/PhysicalLogger.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Polymorph.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Process.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Process.hpp
ecell3/branches/ecell-3.1/ecell/libecs/ProcessEvent.hpp
ecell3/branches/ecell-3.1/ecell/libecs/PropertyAttributes.hpp
ecell3/branches/ecell-3.1/ecell/libecs/PropertyInterface.cpp
ecell3/branches/ecell-3.1/ecell/libecs/PropertyInterface.hpp
ecell3/branches/ecell-3.1/ecell/libecs/PropertySlot.cpp
ecell3/branches/ecell-3.1/ecell/libecs/PropertySlot.hpp
ecell3/branches/ecell-3.1/ecell/libecs/PropertySlotProxy.cpp
ecell3/branches/ecell-3.1/ecell/libecs/PropertySlotProxy.hpp
ecell3/branches/ecell-3.1/ecell/libecs/PropertySlotProxyLoggerAdapter.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Stepper.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Stepper.hpp
ecell3/branches/ecell-3.1/ecell/libecs/StepperEvent.hpp
ecell3/branches/ecell-3.1/ecell/libecs/System.cpp
ecell3/branches/ecell-3.1/ecell/libecs/System.hpp
ecell3/branches/ecell-3.1/ecell/libecs/SystemStepper.cpp
ecell3/branches/ecell-3.1/ecell/libecs/SystemStepper.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Util.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Util.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Variable.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Variable.hpp
ecell3/branches/ecell-3.1/ecell/libecs/VariableReference.cpp
ecell3/branches/ecell-3.1/ecell/libecs/VariableReference.hpp
ecell3/branches/ecell-3.1/ecell/libecs/convertTo.hpp
ecell3/branches/ecell-3.1/ecell/libecs/libecs.cpp
ecell3/branches/ecell-3.1/ecell/libecs/libecs.hpp
ecell3/branches/ecell-3.1/ecell/libecs/osif.cpp
ecell3/branches/ecell-3.1/ecell/libemc/LocalSimulatorImplementation.cpp
ecell3/branches/ecell-3.1/ecell/libemc/LocalSimulatorImplementation.hpp
ecell3/branches/ecell-3.1/ecell/libemc/Simulator.hpp
ecell3/branches/ecell-3.1/ecell/libemc/SimulatorImplementation.hpp
ecell3/branches/ecell-3.1/ecell/pyecell/ecell/_ecs.cpp
Removed Paths:
-------------
ecell3/branches/ecell-3.1/ecell/libecs/FluxProcess.hpp
Modified: ecell3/branches/ecell-3.1/build/msvc/libecs.vcproj
===================================================================
--- ecell3/branches/ecell-3.1/build/msvc/libecs.vcproj 2008-10-23 18:24:55 UTC (rev 3247)
+++ ecell3/branches/ecell-3.1/build/msvc/libecs.vcproj 2008-10-23 18:44:13 UTC (rev 3248)
@@ -572,10 +572,6 @@
>
</File>
<File
- RelativePath="..\..\ecell\libecs\FluxProcess.hpp"
- >
- </File>
- <File
RelativePath="..\..\ecell\libecs\FullID.hpp"
>
</File>
Modified: ecell3/branches/ecell-3.1/ecell/libecs/ContinuousProcess.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/ContinuousProcess.cpp 2008-10-23 18:24:55 UTC (rev 3247)
+++ ecell3/branches/ecell-3.1/ecell/libecs/ContinuousProcess.cpp 2008-10-23 18:44:13 UTC (rev 3248)
@@ -25,6 +25,7 @@
//
//END_HEADER
//
+
#ifdef HAVE_CONFIG_H
#include "ecell_config.h"
#endif /* HAVE_CONFIG_H */
@@ -34,5 +35,5 @@
namespace libecs
{
- LIBECS_DM_INIT_STATIC( ContinuousProcess, Process );
+LIBECS_DM_INIT_STATIC( ContinuousProcess, Process );
}
Modified: ecell3/branches/ecell-3.1/ecell/libecs/ContinuousProcess.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/ContinuousProcess.hpp 2008-10-23 18:24:55 UTC (rev 3247)
+++ ecell3/branches/ecell-3.1/ecell/libecs/ContinuousProcess.hpp 2008-10-23 18:44:13 UTC (rev 3248)
@@ -28,36 +28,39 @@
#include "libecs/libecs.hpp"
#include "libecs/Process.hpp"
+/**
+ @addtogroup entities
+ @ingroup libecs
+ @{
+ */
namespace libecs
{
- LIBECS_DM_CLASS( ContinuousProcess, Process )
- {
+LIBECS_DM_CLASS( ContinuousProcess, Process )
+{
- public:
+public:
+ LIBECS_DM_OBJECT_ABSTRACT( ContinuousProcess )
+ {
+ INHERIT_PROPERTIES( Process );
+ }
- LIBECS_DM_OBJECT_ABSTRACT( ContinuousProcess )
- {
- INHERIT_PROPERTIES( Process );
- }
-
ContinuousProcess()
- {
- ; // do nothing
- }
-
+ {
+ ; // do nothing
+ }
+
virtual ~ContinuousProcess()
- {
- ;
- }
+ {
+ ;
+ }
virtual const bool isContinuous() const
{
- return true;
+ return true;
}
+};
- protected:
-
- };
+} // namespace libecs
-}
+/** @} */
Modified: ecell3/branches/ecell-3.1/ecell/libecs/DataPoint.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/DataPoint.cpp 2008-10-23 18:24:55 UTC (rev 3247)
+++ ecell3/branches/ecell-3.1/ecell/libecs/DataPoint.cpp 2008-10-23 18:44:13 UTC (rev 3248)
@@ -27,6 +27,7 @@
//
// written by Gabor Bereczki <gab...@ta...>
// 24/03/2002
+
#ifdef HAVE_CONFIG_H
#include "ecell_config.h"
#endif /* HAVE_CONFIG_H */
@@ -35,156 +36,136 @@
namespace libecs
{
-
-
- DataPointRef DataPoint::operator= ( LongDataPointCref aLongDataPoint )
- {
- setTime( aLongDataPoint.getTime() );
- setValue ( aLongDataPoint.getValue() );
- return *this;
- }
-
-
- DataPointAggregator::DataPointAggregator()
- :
- theAccumulator( -1.0, 0.0 ),
- theCollector ( -1.0, 0.0 ),
- thePreviousPoint( 1.0, 0.0 )
- {
+DataPointAggregator::DataPointAggregator()
+ : theAccumulator( -1.0, 0.0 ),
+ theCollector ( -1.0, 0.0 ),
+ thePreviousPoint( 1.0, 0.0 )
+{
; //do nothing
- }
-
+}
- DataPointAggregator::DataPointAggregator( LongDataPointCref aDataPoint )
- {
+
+DataPointAggregator::DataPointAggregator( LongDataPointCref aDataPoint )
+{
store( aDataPoint );
- }
-
+}
- DataPointAggregator::~DataPointAggregator()
- {
+
+DataPointAggregator::~DataPointAggregator()
+{
; // do nothing
- }
-
-
- void DataPointAggregator::store( LongDataPointCref aDataPoint )
- {
+}
+
+
+void DataPointAggregator::store( LongDataPointCref aDataPoint )
+{
theAccumulator = aDataPoint;
thePreviousPoint = aDataPoint;
theCollector.setTime( -1.0 );
- }
-
-
- bool DataPointAggregator::stockpile( LongDataPointRef aTarget,
- LongDataPointCref aNewPoint )
- {
+}
+
+
+bool DataPointAggregator::stockpile( LongDataPointRef aTarget,
+ LongDataPointCref aNewPoint )
+{
//if target empty, simply store
//return true
if( aTarget.getTime() == -1.0 )
- {
- aTarget = aNewPoint;
- return true;
- }
+ {
+ aTarget = aNewPoint;
+ return true;
+ }
// if target not empty and time is the same
// calculate MinMax, store Avg
//return true
if( aTarget.getTime() == aNewPoint.getTime() )
- {
- calculateMinMax( aTarget, aNewPoint );
- aTarget.setAvg( aNewPoint.getAvg() );
- aTarget.setValue( aNewPoint.getValue() );
- return true;
- }
+ {
+ calculateMinMax( aTarget, aNewPoint );
+ aTarget.setAvg( aNewPoint.getAvg() );
+ aTarget.setValue( aNewPoint.getValue() );
+ return true;
+ }
//if target time is below newtime
//return false
return false;
- }
-
-
- void DataPointAggregator::aggregate( LongDataPointCref aNewPoint )
- {
+}
+
+
+void DataPointAggregator::aggregate( LongDataPointCref aNewPoint )
+{
// first try to put it into accumulator
if ( ! stockpile( theAccumulator, aNewPoint ) )
- {
- // then try to put it into collector
- if (! stockpile( theCollector, aNewPoint ) )
- {
- // then calculate
- calculate( aNewPoint );
- theCollector = aNewPoint;
- calculateMinMax( theAccumulator, theCollector );
- }
- else
- {
- calculateMinMax( theAccumulator, theCollector );
- }
- }
- }
-
-
- LongDataPointCref DataPointAggregator::getData()
- {
+ {
+ // then try to put it into collector
+ if (! stockpile( theCollector, aNewPoint ) )
+ {
+ // then calculate
+ calculate( aNewPoint );
+ theCollector = aNewPoint;
+ calculateMinMax( theAccumulator, theCollector );
+ }
+ else
+ {
+ calculateMinMax( theAccumulator, theCollector );
+ }
+ }
+}
+
+
+LongDataPointCref DataPointAggregator::getData()
+{
return theAccumulator;
- }
-
-
- inline void
- DataPointAggregator::calculateMinMax( LongDataPointRef aTarget,
- LongDataPointCref aNewPoint )
- {
+}
+
+
+inline void
+DataPointAggregator::calculateMinMax( LongDataPointRef aTarget,
+ LongDataPointCref aNewPoint )
+{
// accu min
-
if( aTarget.getMin() > aNewPoint.getMin() )
- {
- aTarget.setMin ( aNewPoint.getMin() );
- }
+ {
+ aTarget.setMin ( aNewPoint.getMin() );
+ }
// accu max
if( aTarget.getMax() < aNewPoint.getMax() )
- {
- aTarget.setMax ( aNewPoint.getMax() );
- }
-
- }
-
-
- void DataPointAggregator::calculate( LongDataPointCref aNewPoint )
- {
+ {
+ aTarget.setMax ( aNewPoint.getMax() );
+ }
+}
+
+
+void DataPointAggregator::calculate( LongDataPointCref aNewPoint )
+{
// accu avg
theAccumulator.setAvg
- ( ( theCollector.getAvg() *
- ( aNewPoint.getTime() - theCollector.getTime() ) +
- theAccumulator.getAvg() *
- ( theCollector.getTime() - theAccumulator.getTime() ) )
- / ( aNewPoint.getTime() - theAccumulator.getTime() ) );
- }
-
- void DataPointAggregator::beginNextPoint()
- {
- // theAccumulator = thePreviousPoint;
- // thePreviousPoint = theCollector;
-
+ ( ( theCollector.getAvg() *
+ ( aNewPoint.getTime() - theCollector.getTime() ) +
+ theAccumulator.getAvg() *
+ ( theCollector.getTime() - theAccumulator.getTime() ) )
+ / ( aNewPoint.getTime() - theAccumulator.getTime() ) );
+}
+
+void DataPointAggregator::beginNextPoint()
+{
store( theCollector );
- }
-
-
- LongDataPoint DataPointAggregator::getLastPoint()
- {
+}
+
+
+LongDataPoint DataPointAggregator::getLastPoint()
+{
//if collector empty return Accu
if (theCollector.getTime() == -1.0 )
- {
- return theAccumulator;
- }
+ {
+ return theAccumulator;
+ }
else
- {
- return theCollector;
- }
- }
-
-
-
-} // namespace libecs
+ {
+ return theCollector;
+ }
+}
-
+} // namespace libecs
Modified: ecell3/branches/ecell-3.1/ecell/libecs/DataPoint.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/DataPoint.hpp 2008-10-23 18:24:55 UTC (rev 3247)
+++ ecell3/branches/ecell-3.1/ecell/libecs/DataPoint.hpp 2008-10-23 18:44:13 UTC (rev 3248)
@@ -35,281 +35,269 @@
#include "libecs/libecs.hpp"
#include "libecs/Polymorph.hpp"
+/**
+ @addtogroup logging
+ @{
+ */
namespace libecs
{
- /** @addtogroup logging
- *@{
- */
+class LongDataPoint;
+class DataPoint;
- /** \file */
-
- class LongDataPoint;
- class DataPoint;
-
-
-
- /**
-
- */
-
- class DataPoint
- {
-
- public:
+class DataPoint
+{
+public:
class EarlinessOrdering
{
public:
- bool operator()(const DataPoint& x, const DataPoint& y)
- {
- return x.getTime() < y.getTime();
- }
+ bool operator()(const DataPoint& x, const DataPoint& y)
+ {
+ return x.getTime() < y.getTime();
+ }
};
class LatenessOrdering
{
public:
- bool operator()(const DataPoint& x, const DataPoint& y)
- {
- return x.getTime() > y.getTime();
- }
+ bool operator()(const DataPoint& x, const DataPoint& y)
+ {
+ return x.getTime() > y.getTime();
+ }
};
- public:
-
+public:
DataPoint()
- :
- theTime ( 0.0 ),
- theValue( 0.0 )
+ : theTime ( 0.0 ),
+ theValue( 0.0 )
{
- ; // do nothing
+ ; // do nothing
}
DataPoint( RealParam aTime, RealParam aValue )
- :
- theTime ( aTime ),
- theValue( aValue )
+ : theTime ( aTime ),
+ theValue( aValue )
{
- ; //do nothing
+ ; //do nothing
}
-
-
~DataPoint()
{
- ; // do nothing
+ ; // do nothing
}
+
const Real getTime() const
{
- return theTime;
+ return theTime;
}
+
const Real getValue() const
{
- return theValue;
+ return theValue;
}
+
const Real getAvg() const
{
- return theValue;
+ return theValue;
}
+
const Real getMin() const
{
- return theValue;
+ return theValue;
}
+
const Real getMax() const
{
- return theValue;
+ return theValue;
}
void setTime( RealParam aReal )
{
- theTime = aReal;
+ theTime = aReal;
}
+
void setValue( RealParam aReal )
{
- theValue = aReal;
+ theValue = aReal;
}
- void setAvg( RealParam aReal )
- {
- ;
- }
- void setMin( RealParam aReal )
- {
- ;
- }
-
- void setMax( RealParam aReal )
- {
- ;
- }
-
static const size_t getElementSize()
{
- return sizeof( Real );
+ return sizeof( Real );
}
+
static const int getElementNumber()
{
- return 2;
+ return 2;
}
+
DataPointRef operator= ( LongDataPointCref aLongDataPoint );
+
bool operator==( const DataPoint& that ) const
{
- return theTime == that.theTime &&
- theValue == that.theValue;
+ return theTime == that.theTime && theValue == that.theValue;
}
- protected:
+protected:
Real theTime;
Real theValue;
- };
+};
- class LongDataPoint
- :
- public DataPoint
- {
+class LongDataPoint: public DataPoint
+{
- public:
-
+public:
LongDataPoint() //constructor with no arguments
- :
- theAvg( 0.0 ),
- theMin( 0.0 ),
- theMax( 0.0 )
+ : theAvg( 0.0 ),
+ theMin( 0.0 ),
+ theMax( 0.0 )
{
- ; // do nothing
+ ; // do nothing
}
LongDataPoint( RealParam aTime, RealParam aValue )//constructor with 2 args
- :
- DataPoint( aTime, aValue ),
- theAvg( aValue ),
- theMin( aValue ),
- theMax( aValue )
+ : DataPoint( aTime, aValue ),
+ theAvg( aValue ),
+ theMin( aValue ),
+ theMax( aValue )
{
- ; // do nothing
+ ; // do nothing
}
LongDataPoint( RealParam aTime, RealParam aValue,
- RealParam anAvg,
- RealParam aMax,
- RealParam aMin ) //constructor with 5 args
- :
- DataPoint( aTime, aValue ),
- theAvg( anAvg ),
- theMin( aMin ),
- theMax( aMax )
+ RealParam anAvg, RealParam aMax,
+ RealParam aMin ) //constructor with 5 args
+ : DataPoint( aTime, aValue ),
+ theAvg( anAvg ),
+ theMin( aMin ),
+ theMax( aMax )
{
- ; // do nothing
+ ; // do nothing
}
LongDataPoint( DataPointCref aDataPoint ) // constructor from DP2
- :
- DataPoint( aDataPoint ),
- theAvg( aDataPoint.getAvg() ),
- theMin( aDataPoint.getMin() ),
- theMax( aDataPoint.getMax() )
+ : DataPoint( aDataPoint ),
+ theAvg( aDataPoint.getAvg() ),
+ theMin( aDataPoint.getMin() ),
+ theMax( aDataPoint.getMax() )
{
- ; // do nothing
+ ; // do nothing
}
+
~LongDataPoint()
{
- ; // do nothing
+ ; // do nothing
}
+
const Real getTime() const
{
- return theTime;
+ return theTime;
}
+
const Real getValue() const
{
- return theValue;
+ return theValue;
}
+
const Real getAvg() const
{
- return theAvg;
+ return theAvg;
}
+
const Real getMin() const
{
- return theMin;
+ return theMin;
}
+
const Real getMax() const
{
- return theMax;
+ return theMax;
}
void setTime( RealParam aReal )
{
- theTime = aReal;
+ theTime = aReal;
}
+
void setValue( RealParam aReal )
{
- theValue = aReal;
+ theValue = aReal;
}
+
void setAvg( RealParam aReal )
{
- theAvg = aReal;
+ theAvg = aReal;
}
+
void setMin( RealParam aReal )
{
- theMin = aReal;
+ theMin = aReal;
}
- void setMax( RealParam aReal )
+ void setMax( RealParam aReal )
{
- theMax = aReal;
+ theMax = aReal;
}
+
static const size_t getElementSize()
{
- return sizeof( Real );
+ return sizeof( Real );
}
+
static const int getElementNumber()
{
- return 5;
+ return 5;
}
- protected:
-
+protected:
Real theAvg;
Real theMin;
Real theMax;
+};
- };
+inline DataPoint& DataPoint::operator=( LongDataPoint const& aLongDataPoint )
+{
+ setTime( aLongDataPoint.getTime() );
+ setValue( aLongDataPoint.getValue() );
+ return *this;
+}
- class DataPointAggregator
- {
+
+class DataPointAggregator
+{
+public:
- public:
-
DataPointAggregator();
DataPointAggregator( LongDataPointCref );
@@ -325,7 +313,7 @@
LongDataPoint getLastPoint();
- private:
+private:
void store( LongDataPointCref );
bool stockpile( LongDataPointRef, LongDataPointCref );
@@ -335,13 +323,10 @@
LongDataPoint theAccumulator;
LongDataPoint theCollector;
LongDataPoint thePreviousPoint;
-
- };
-
-
- //@}
-
+};
+
} // namespace libecs
+/** @} */
#endif /* __DATAPOINT_HPP */
Modified: ecell3/branches/ecell-3.1/ecell/libecs/DataPointVector.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/DataPointVector.cpp 2008-10-23 18:24:55 UTC (rev 3247)
+++ ecell3/branches/ecell-3.1/ecell/libecs/DataPointVector.cpp 2008-10-23 18:44:13 UTC (rev 3248)
@@ -27,103 +27,98 @@
//
// written by Gabor Bereczki <gab...@ta...>
// 14/04/2002
+
#ifdef HAVE_CONFIG_H
#include "ecell_config.h"
#endif /* HAVE_CONFIG_H */
#include "DataPointVector.hpp"
-#include <assert.h>
+#include <cassert>
namespace libecs
{
- DataPointVector::~DataPointVector()
- {
+
+DataPointVector::~DataPointVector()
+{
if( thePointSize==2 )
- {
- delete[] theRawArray;
- }
+ {
+ delete[] theRawArray;
+ }
else
- {
- delete[] theRawArrayLong;
- }
- }
+ {
+ delete[] theRawArrayLong;
+ }
+}
-
-
- DataPointVector::DataPointVector( DataPointVectorIterator aLength,
- int aPointSize )
- :
- theSize( aLength ),
- thePointSize( aPointSize )
- {
+DataPointVector::DataPointVector( DataPointVectorIterator aLength,
+ int aPointSize )
+ : theSize( aLength ),
+ thePointSize( aPointSize )
+{
// init the appropriate array
if( thePointSize == 2 )
- {
- theRawArray = new DataPoint[ aLength ];
- }
+ {
+ theRawArray = new DataPoint[ aLength ];
+ }
else
- {
- theRawArrayLong = new LongDataPoint[ aLength ];
- }
- }
+ {
+ theRawArrayLong = new LongDataPoint[ aLength ];
+ }
+}
- size_t DataPointVector::getElementSize() const
- {
+size_t DataPointVector::getElementSize() const
+{
if( thePointSize == 2 )
- {
- return sizeof(DataPoint);
- }
+ {
+ return sizeof(DataPoint);
+ }
return sizeof(LongDataPoint);
- }
+}
-
-
-
- DataPointRef DataPointVector::asShort( DataPointVectorIterator aPosition )
- {
+DataPointRef DataPointVector::asShort( DataPointVectorIterator aPosition )
+{
assert (thePointSize == 2);
return theRawArray[ aPosition ];
- }
+}
- DataPointCref
- DataPointVector::asShort( DataPointVectorIterator aPosition ) const
- {
+DataPointCref
+DataPointVector::asShort( DataPointVectorIterator aPosition ) const
+{
assert (thePointSize == 2);
return theRawArray[ aPosition ];
- }
+}
- LongDataPointRef DataPointVector::asLong( DataPointVectorIterator aPosition )
- {
+LongDataPointRef DataPointVector::asLong( DataPointVectorIterator aPosition )
+{
assert (thePointSize == 5);
return theRawArrayLong[ aPosition ];
- }
+}
- LongDataPointCref
- DataPointVector::asLong( DataPointVectorIterator aPosition ) const
- {
+LongDataPointCref
+DataPointVector::asLong( DataPointVectorIterator aPosition ) const
+{
assert (thePointSize == 5);
return theRawArrayLong[ aPosition ];
- }
+}
- const void* DataPointVector::getRawArray() const
- {
+const void* DataPointVector::getRawArray() const
+{
if (thePointSize == 2)
- {
- return (void*) theRawArray;
- }
+ {
+ return (void*) theRawArray;
+ }
return (void*) theRawArrayLong;
- }
+}
- Integer DataPointVector::getPointSize()
- {
- return DataPointVector::thePointSize;
- }
-} // namespace libecs
+Integer DataPointVector::getPointSize()
+{
+ return DataPointVector::thePointSize;
+}
-
+} // namespace libecs
Modified: ecell3/branches/ecell-3.1/ecell/libecs/DataPointVector.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/DataPointVector.hpp 2008-10-23 18:24:55 UTC (rev 3247)
+++ ecell3/branches/ecell-3.1/ecell/libecs/DataPointVector.hpp 2008-10-23 18:44:13 UTC (rev 3248)
@@ -37,25 +37,21 @@
#include <sys/types.h>
+/**
+ @addtogroup logging
+ @{
+*/
+
namespace libecs
{
- /** @addtogroup logging
- *@{
- */
+DECLARE_TYPE( size_t, DataPointVectorIterator );
- /** @file */
+DECLARE_SHAREDPTR( DataPointVector );
-
- DECLARE_TYPE( size_t, DataPointVectorIterator );
-
- DECLARE_SHAREDPTR( DataPointVector );
-
- class LIBECS_API DataPointVector
- {
-
- public:
-
+class LIBECS_API DataPointVector
+{
+public:
DataPointVector( DataPointVectorIterator, int aPointSize );
~DataPointVector();
@@ -70,27 +66,26 @@
DataPointVectorIterator getSize() const
{
- return theSize;
+ return theSize;
}
size_t getElementSize() const;
-
+
DataPointVectorIterator begin() const
{
- return 0;
+ return 0;
}
-
+
DataPointVectorIterator end() const
{
- return getSize();
+ return getSize();
}
-
+
const void* getRawArray() const;
Integer getPointSize();
- private:
-
+private:
DataPointVectorIterator theSize;
Integer thePointSize;
@@ -98,12 +93,10 @@
DataPoint* theRawArray;
LongDataPoint* theRawArrayLong;
+};
- };
-
- //@}
-
} // namespace libecs
+/** @} */
#endif /* __DATAPOINTVECTOR_HPP */
Modified: ecell3/branches/ecell-3.1/ecell/libecs/DifferentialStepper.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/DifferentialStepper.cpp 2008-10-23 18:24:55 UTC (rev 3247)
+++ ecell3/branches/ecell-3.1/ecell/libecs/DifferentialStepper.cpp 2008-10-23 18:44:13 UTC (rev 3248)
@@ -28,6 +28,7 @@
// written by Koichi Takahashi <sh...@e-...>,
// E-Cell Project.
//
+
#ifdef HAVE_CONFIG_H
#include "ecell_config.h"
#endif /* HAVE_CONFIG_H */
@@ -50,193 +51,190 @@
namespace libecs
{
- LIBECS_DM_INIT_STATIC( DifferentialStepper, Stepper );
- LIBECS_DM_INIT_STATIC( AdaptiveDifferentialStepper, Stepper );
+LIBECS_DM_INIT_STATIC( DifferentialStepper, Stepper );
+LIBECS_DM_INIT_STATIC( AdaptiveDifferentialStepper, Stepper );
- DifferentialStepper::DifferentialStepper()
- :
- theNextStepInterval( 0.001 ),
- theTolerableStepInterval( 0.001 ),
- theStateFlag( true )
- {
+DifferentialStepper::DifferentialStepper()
+ : theNextStepInterval( 0.001 ),
+ theTolerableStepInterval( 0.001 ),
+ theStateFlag( true )
+{
; // do nothing
- }
+}
- DifferentialStepper::~DifferentialStepper()
- {
+
+DifferentialStepper::~DifferentialStepper()
+{
; // do nothing
- }
+}
- void DifferentialStepper::initialize()
- {
+
+void DifferentialStepper::initialize()
+{
Stepper::initialize();
createInterpolants();
theTaylorSeries.resize( boost::extents[ getStage() ][
- static_cast< RealMatrix::index >(
- getReadOnlyVariableOffset() ) ] );
+ static_cast< RealMatrix::index >(
+ getReadOnlyVariableOffset() ) ] );
- // should registerProcess be overrided?
+ // XXX: should go into registerProcess?
+ /*
if ( getDiscreteProcessOffset() < theProcessVector.size() )
- {
- for ( ProcessVectorConstIterator
- i( theProcessVector.begin() + getDiscreteProcessOffset() );
- i < theProcessVector.end(); ++i )
- {
- // XXX: To be addressed later.
- // std::cerr << "WARNING: Process [" << (*i)->getID() << "] is not continuous." << std::endl;
- }
- }
+ {
+ for ( ProcessVectorConstIterator i(
+ theProcessVector.begin() + getDiscreteProcessOffset() );
+ i < theProcessVector.end(); ++i )
+ {
+ std::cerr << "WARNING: Process [" << (*i)->getID() << "] is not continuous." << std::endl;
+ }
+ }
+ */
initializeVariableReferenceList();
+}
- // should create another method for property slot ?
- // setNextStepInterval( getStepInterval() );
- // theStateFlag = false;
- }
+void DifferentialStepper::initializeVariableReferenceList()
+{
+ const ProcessVector::size_type aDiscreteProcessOffset(
+ getDiscreteProcessOffset() );
- void DifferentialStepper::initializeVariableReferenceList()
- {
- const ProcessVector::size_type
- aDiscreteProcessOffset( getDiscreteProcessOffset() );
-
theVariableReferenceListVector.clear();
theVariableReferenceListVector.resize( aDiscreteProcessOffset );
for ( ProcessVector::size_type i( 0 ); i < aDiscreteProcessOffset; ++i )
- {
- ProcessPtr const aProcess( theProcessVector[ i ] );
+ {
+ ProcessPtr const aProcess( theProcessVector[ i ] );
- VariableReferenceVectorCref aVariableReferenceVector(
- aProcess->getVariableReferenceVector() );
+ VariableReferenceVectorCref aVariableReferenceVector(
+ aProcess->getVariableReferenceVector() );
- VariableReferenceVector::size_type const
- aZeroVariableReferenceOffset(
- aProcess->getZeroVariableReferenceOffset() );
- VariableReferenceVector::size_type const
- aPositiveVariableReferenceOffset(
- aProcess->getPositiveVariableReferenceOffset() );
+ VariableReferenceVector::size_type const aZeroVariableReferenceOffset(
+ aProcess->getZeroVariableReferenceOffset() );
+ VariableReferenceVector::size_type const aPositiveVariableReferenceOffset(
+ aProcess->getPositiveVariableReferenceOffset() );
- theVariableReferenceListVector[ i ].reserve(
- ( aVariableReferenceVector.size() -
- aPositiveVariableReferenceOffset +
- aZeroVariableReferenceOffset ) );
+ theVariableReferenceListVector[ i ].reserve(
+ ( aVariableReferenceVector.size() -
+ aPositiveVariableReferenceOffset +
+ aZeroVariableReferenceOffset ) );
- for ( VariableReferenceVectorConstIterator
- anIterator( aVariableReferenceVector.begin() ),
- anEnd ( aVariableReferenceVector.begin() +
- aZeroVariableReferenceOffset );
- anIterator < anEnd; ++anIterator )
- {
- VariableReference const& aVariableReference( *anIterator );
+ for ( VariableReferenceVectorConstIterator
+ anIterator( aVariableReferenceVector.begin() ),
+ anEnd ( aVariableReferenceVector.begin()
+ + aZeroVariableReferenceOffset );
+ anIterator < anEnd; ++anIterator )
+ {
+ VariableReference const& aVariableReference( *anIterator );
- theVariableReferenceListVector[ i ].push_back(
- ExprComponent( getVariableIndex(
- aVariableReference.getVariable() ),
- aVariableReference.getCoefficient() ) );
- }
+ theVariableReferenceListVector[ i ].push_back(
+ ExprComponent( getVariableIndex(
+ aVariableReference.getVariable() ),
+ aVariableReference.getCoefficient() ) );
+ }
- for ( VariableReferenceVectorConstIterator anIterator(
- aVariableReferenceVector.begin() +
- aPositiveVariableReferenceOffset );
- anIterator < aVariableReferenceVector.end();
- ++anIterator )
- {
- VariableReference const& aVariableReference( *anIterator );
+ for ( VariableReferenceVectorConstIterator
+ anIterator( aVariableReferenceVector.begin()
+ + aPositiveVariableReferenceOffset );
+ anIterator < aVariableReferenceVector.end(); ++anIterator )
+ {
+ VariableReference const& aVariableReference( *anIterator );
- theVariableReferenceListVector[ i ].push_back(
- ExprComponent( getVariableIndex(
- aVariableReference.getVariable() ),
- aVariableReference.getCoefficient() ) );
- }
- }
- }
+ theVariableReferenceListVector[ i ].push_back(
+ ExprComponent( getVariableIndex(
+ aVariableReference.getVariable() ),
+ aVariableReference.getCoefficient() ) );
+ }
+ }
+}
- void DifferentialStepper::
- setVariableVelocity( boost::detail::multi_array::sub_array<Real, 1>
- aVelocityBuffer )
- {
+
+void DifferentialStepper::setVariableVelocity(
+ boost::detail::multi_array::sub_array<Real, 1> aVelocityBuffer )
+{
const ProcessVector::size_type
- aDiscreteProcessOffset( getDiscreteProcessOffset() );
+ aDiscreteProcessOffset( getDiscreteProcessOffset() );
for ( RealMatrix::index i( 0 );
- i < static_cast< RealMatrix::index >( aVelocityBuffer.size() );
- ++i )
- {
- aVelocityBuffer[ i ] = 0.0;
- }
+ i < static_cast< RealMatrix::index >( aVelocityBuffer.size() );
+ ++i )
+ {
+ aVelocityBuffer[ i ] = 0.0;
+ }
for ( ProcessVector::size_type i( 0 ); i < aDiscreteProcessOffset; ++i )
- {
- const Real anActivity( theProcessVector[ i ]->getActivity() );
+ {
+ const Real anActivity( theProcessVector[ i ]->getActivity() );
- for ( VariableReferenceList::const_iterator
- anIterator( theVariableReferenceListVector[ i ].begin() );
- anIterator < theVariableReferenceListVector[ i ].end();
- anIterator++ )
- {
- ExprComponent const& aComponent = *anIterator;
- const RealMatrix::index anIndex(
- static_cast< RealMatrix::index >(
- aComponent.first ) );
- aVelocityBuffer[ anIndex ] += aComponent.second * anActivity;
- }
- }
- }
+ for ( VariableReferenceList::const_iterator anIterator(
+ theVariableReferenceListVector[ i ].begin() );
+ anIterator < theVariableReferenceListVector[ i ].end();
+ anIterator++ )
+ {
+ ExprComponent const& aComponent = *anIterator;
+ const RealMatrix::index anIndex(
+ static_cast< RealMatrix::index >( aComponent.first ) );
+ aVelocityBuffer[ anIndex ] += aComponent.second * anActivity;
+ }
+ }
+}
- void DifferentialStepper::reset()
- {
+
+void DifferentialStepper::reset()
+{
// is this needed?
for ( RealMatrix::index i( 0 ); i != getStage(); ++i )
- for ( RealMatrix::index j( 0 );
- j != getReadOnlyVariableOffset(); ++j )
- {
- theTaylorSeries[ i ][ j ] = 0.0;
+ {
+ for ( RealMatrix::index j( 0 );
+ j != getReadOnlyVariableOffset(); ++j )
+ {
+ theTaylorSeries[ i ][ j ] = 0.0;
+ }
+ }
- // RealMatrix::index_gen indices;
- // theTaylorSeries[ indices[ i ][ RealMatrix::index_range( 0, getReadOnlyVariableOffset() ) ] ].assign( 0.0 );
- }
-
Stepper::reset();
- }
+}
- void DifferentialStepper::resetAll()
- {
+
+void DifferentialStepper::resetAll()
+{
const VariableVector::size_type aSize( theVariableVector.size() );
for ( VariableVector::size_type c( 0 ); c < aSize; ++c )
- {
- VariablePtr const aVariable( theVariableVector[ c ] );
- aVariable->loadValue( theValueBuffer[ c ] );
- }
- }
+ {
+ VariablePtr const aVariable( theVariableVector[ c ] );
+ aVariable->loadValue( theValueBuffer[ c ] );
+ }
+}
- void DifferentialStepper::interIntegrate()
- {
+
+void DifferentialStepper::interIntegrate()
+{
Real const aCurrentTime( getCurrentTime() );
VariableVector::size_type c( theReadWriteVariableOffset );
for( ; c != theReadOnlyVariableOffset; ++c )
- {
- VariablePtr const aVariable( theVariableVector[ c ] );
+ {
+ VariablePtr const aVariable( theVariableVector[ c ] );
- aVariable->interIntegrate( aCurrentTime );
- }
+ aVariable->interIntegrate( aCurrentTime );
+ }
// RealOnly Variables must be reset by the values in theValueBuffer
// before interIntegrate().
for( ; c != theVariableVector.size(); ++c )
- {
- VariablePtr const aVariable( theVariableVector[ c ] );
+ {
+ VariablePtr const aVariable( theVariableVector[ c ] );
- aVariable->loadValue( theValueBuffer[ c ] );
- aVariable->interIntegrate( aCurrentTime );
- }
- }
+ aVariable->loadValue( theValueBuffer[ c ] );
+ aVariable->interIntegrate( aCurrentTime );
+ }
+}
- void DifferentialStepper::interrupt( TimeParam aTime )
- {
+
+void DifferentialStepper::interrupt( TimeParam aTime )
+{
const Real aCallerCurrentTime( aTime );
const Real aCallerTimeScale( getModel()->getLastStepper()->getTimeScale() );
@@ -245,116 +243,215 @@
// If the step size of this is less than caller's timescale,
// ignore this interruption.
if( aCallerTimeScale >= aStepInterval )
- {
- return;
- }
+ {
+ return;
+ }
const Real aCurrentTime( getCurrentTime() );
// aCallerTimeScale == 0 implies need for immediate reset
if( aCallerTimeScale != 0.0 )
- {
- // Shrink the next step size to that of caller's
- setNextStepInterval( aCallerTimeScale );
+ {
+ // Shrink the next step size to that of caller's
+ setNextStepInterval( aCallerTimeScale );
- const Real aNextStep( aCurrentTime + aStepInterval );
- const Real aCallerNextStep( aCallerCurrentTime + aCallerTimeScale );
+ const Real aNextStep( aCurrentTime + aStepInterval );
+ const Real aCallerNextStep( aCallerCurrentTime + aCallerTimeScale );
- // If the next step of this occurs *before* the next step
- // of the caller, just shrink step size of this Stepper.
- if( aNextStep <= aCallerNextStep )
- {
- return;
- }
-
-
- // If the next step of this will occur *after* the caller,
- // reschedule this Stepper, as well as shrinking the next step size.
- // setStepInterval( aCallerCurrentTime + ( aCallerTimeScale * 0.5 )
- // - aCurrentTime );
- }
+ // If the next step of this occurs *before* the next step
+ // of the caller, just shrink step size of this Stepper.
+ if( aNextStep <= aCallerNextStep )
+ {
+ return;
+ }
+ }
else
- {
- // reset step interval to the default
- setNextStepInterval( 0.001 );
- }
-
+ {
+ // reset step interval to the default
+ setNextStepInterval( 0.001 );
+ }
+
const Real aNewStepInterval( aCallerCurrentTime - aCurrentTime );
loadStepInterval( aNewStepInterval );
- }
+}
- ////////////////////////// AdaptiveDifferentialStepper
+const Real DifferentialStepper::Interpolant::getDifference(
+ RealParam aTime, RealParam anInterval ) const
+{
+ if ( !theStepper.theStateFlag )
+ {
+ return 0.0;
+ }
- AdaptiveDifferentialStepper::AdaptiveDifferentialStepper()
- :
- theTolerance( 1.0e-6 ),
- theAbsoluteToleranceFactor( 1.0 ),
- theStateToleranceFactor( 1.0 ),
- theDerivativeToleranceFactor( 1.0 ),
- theEpsilonChecked( 0 ),
- theAbsoluteEpsilon( 0.1 ),
- theRelativeEpsilon( 0.1 ),
- safety( 0.9 ),
- theMaxErrorRatio( 1.0 )
- {
+ const Real aTimeInterval1( aTime - theStepper.getCurrentTime() );
+ const Real aTimeInterval2( aTimeInterval1 - anInterval );
+
+ RealMatrixCref aTaylorSeries( theStepper.getTaylorSeries() );
+ RealCptr aTaylorCoefficientPtr( aTaylorSeries.origin() + theIndex );
+
+ // calculate first order.
+ // here it assumes that always aTaylorSeries.size() >= 1
+
+ // *aTaylorCoefficientPtr := aTaylorSeries[ 0 ][ theIndex ]
+ Real aValue1( *aTaylorCoefficientPtr * aTimeInterval1 );
+ Real aValue2( *aTaylorCoefficientPtr * aTimeInterval2 );
+
+
+ // check if second and higher order calculations are necessary.
+ const RealMatrix::size_type aTaylorSize( theStepper.getOrder() );
+ if( aTaylorSize >= 2)
+ {
+ const Real aStepIntervalInv(
+ 1.0 / theStepper.getTolerableStepInterval() );
+
+ const RealMatrix::size_type aStride( aTaylorSeries.strides()[0] );
+
+ Real aFactorialInv1( aTimeInterval1 );
+ Real aFactorialInv2( aTimeInterval2 );
+
+ RealMatrix::size_type s( aTaylorSize - 1 );
+
+ const Real theta1( aTimeInterval1 * aStepIntervalInv );
+ const Real theta2( aTimeInterval2 * aStepIntervalInv );
+
+ do
+ {
+ // main calculation for the 2+ order
+
+ // aTaylorSeries[ s ][ theIndex ]
+ aTaylorCoefficientPtr += aStride;
+ const Real aTaylorCoefficient( *aTaylorCoefficientPtr );
+
+ aFactorialInv1 *= theta1;
+ aFactorialInv2 *= theta2;
+
+ aValue1 += aTaylorCoefficient * aFactorialInv1;
+ aValue2 += aTaylorCoefficient * aFactorialInv2;
+
+ --s;
+ } while( s != 0 );
+ }
+
+ return aValue1 - aValue2;
+}
+
+
+const Real DifferentialStepper::Interpolant::getVelocity( RealParam aTime ) const
+{
+ if ( !theStepper.theStateFlag )
+ {
+ return 0.0;
+ }
+
+ const Real aTimeInterval( aTime - theStepper.getCurrentTime() );
+
+ RealMatrixCref aTaylorSeries( theStepper.getTaylorSeries() );
+ RealCptr aTaylorCoefficientPtr( aTaylorSeries.origin() + theIndex );
+
+ // calculate first order.
+ // here it assumes that always aTaylorSeries.size() >= 1
+
+ // *aTaylorCoefficientPtr := aTaylorSeries[ 0 ][ theIndex ]
+ Real aValue( *aTaylorCoefficientPtr );
+
+ // check if second and higher order calculations are necessary.
+ const RealMatrix::size_type aTaylorSize( theStepper.getStage() );
+ if( aTaylorSize >= 2 && aTimeInterval != 0.0 )
+ {
+ const RealMatrix::size_type aStride( aTaylorSeries.strides()[0] );
+
+ Real aFactorialInv( 1.0 );
+
+ RealMatrix::size_type s( 1 );
+
+ const Real theta( aTimeInterval
+ / theStepper.getTolerableStepInterval() );
+
+ do
+ {
+ // main calculation for the 2+ order
+ ++s;
+
+ aTaylorCoefficientPtr += aStride;
+ const Real aTaylorCoefficient( *aTaylorCoefficientPtr );
+
+ aFactorialInv *= theta * s;
+
+ aValue += aTaylorCoefficient * aFactorialInv;
+
+ // LIBECS_PREFETCH( aTaylorCoefficientPtr + aStride, 0, 1 );
+ } while( s != aTaylorSize );
+ }
+
+ return aValue;
+}
+
+
+////////////////////////// AdaptiveDifferentialStepper
+
+AdaptiveDifferentialStepper::AdaptiveDifferentialStepper()
+ : theTolerance( 1.0e-6 ),
+ theAbsoluteToleranceFactor( 1.0 ),
+ theStateToleranceFactor( 1.0 ),
+ theDerivativeToleranceFactor( 1.0 ),
+ theEpsilonChecked( 0 ),
+ theAbsoluteEpsilon( 0.1 ),
+ theRelativeEpsilon( 0.1 ),
+ safety( 0.9 ),
+ theMaxErrorRatio( 1.0 )
+{
// use more narrow range
setMinStepInterval( 1e-100 );
setMaxStepInterval( 1e+10 );
- }
+}
- AdaptiveDifferentialStepper::~AdaptiveDifferentialStepper()
- {
+AdaptiveDifferentialStepper::~AdaptiveDifferentialStepper()
+{
; // do nothing
- }
+}
- void AdaptiveDifferentialStepper::initialize()
- {
+void AdaptiveDifferentialStepper::initialize()
+{
DifferentialStepper::initialize();
+}
- //FIXME:!!
- // theEpsilonChecked = ( theEpsilonChecked
- // || ( theDependentStepperVector.size() > 1 ) );
- }
-
- void AdaptiveDifferentialStepper::step()
- {
+void AdaptiveDifferentialStepper::step()
+{
theStateFlag = false;
clearVariables();
setStepInterval( getNextStepInterval() );
- // setTolerableInterval( 0.0 );
while ( !calculate() )
- {
- const Real anExpectedStepInterval( safety * getStepInterval()
- * pow( getMaxErrorRatio(),
- -1.0 / getOrder() ) );
- // const Real anExpectedStepInterval( 0.5 * getStepInterval() );
+ {
+ const Real anExpectedStepInterval( safety * getStepInterval()
+ * pow( getMaxErrorRatio(),
+ -1.0 / getOrder() ) );
- if ( anExpectedStepInterval > getMinStepInterval() )
- {
- // shrink it if the error exceeds 110%
- setStepInterval( anExpectedStepInterval );
- }
- else
- {
- setStepInterval( getMinStepInterval() );
+ if ( anExpectedStepInterval > getMinStepInterval() )
+ {
+ // shrink it if the error exceeds 110%
+ setStepInterval( anExpectedStepInterval );
+ }
+ else
+ {
+ setStepInterval( getMinStepInterval() );
- // this must return false,
- // so theTolerableStepInterval does NOT LIMIT the error.
- THROW_EXCEPTION( SimulationError,
- "The error-limit step interval of Stepper [" +
- getID() + "] is too small." );
-
- calculate();
- break;
- }
- }
+ // this must return false,
+ // so theTolerableStepInterval does NOT LIMIT the error.
+ THROW_EXCEPTION( SimulationError,
+ "The error-limit step interval of Stepper ["
+ + getID() + "] is too small." );
+ calculate();
+ break;
+ }
+ }
+
// an extra calculation for resetting the activities of processes
fireProcesses();
@@ -365,51 +462,16 @@
// grow it if error is 50% less than desired
const Real maxError( getMaxErrorRatio() );
if ( maxError < 0.5 )
- {
- const Real aNewStepInterval( getTolerableStepInterval() * safety
- * pow( maxError ,
- -1.0 / ( getOrder() + 1 ) ) );
- // const Real aNewStepInterval( getStepInterval() * 2.0 );
-
- setNextStepInterval( aNewStepInterval );
- }
+ {
+ const Real aNewStepInterval( getTolerableStepInterval() * safety
+ * pow( maxError,
+ -1.0 / ( getOrder() + 1 ) ) );
+ setNextStepInterval( aNewStepInterval );
+ }
else
- {
- setNextStepInterval( getTolerableStepInterval() );
- }
+ {
+ setNextStepInterval( getTolerableStepInterval() );
+ }
+}
- /**
- // check the tolerances for Epsilon
- if ( isEpsilonChecked() )
- {
- const VariableVector::size_type aSize( getReadOnlyVariableOffset() );
-
- for ( VariableVector::size_type c( 0 ); c < aSize; ++c )
- {
- VariablePtr const aVariable( theVariableVector[ c ] );
-
- const Real aTolerance( FMA( fabs( aVariable->getValue() ),
- theRelativeEpsilon,
- theAbsoluteEpsilon ) );
-
- const Real aVelocity( fabs( theVelocityBuffer[ c ] ) );
-
- if ( aTolerance < aVelocity * getStepInterval() )
- {
- setStepInterval( aTolerance / aVelocity );
- }
- }
- }
- */
- }
-
} // namespace libecs
-
-
-/*
- Do not modify
- $Author$
- $Revision$
- $Date$
- $Locker$
-*/
Modified: ecell3/branches/ecell-3.1/ecell/libecs/DifferentialStepper.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/DifferentialStepper.hpp 2008-10-23 18:24:55 UTC (rev 3247)
+++ ecell3/branches/ecell-3.1/ecell/libecs/DifferentialStepper.hpp 2008-10-23 18:44:13 UTC (rev 3248)
@@ -37,243 +37,71 @@
#include <boost/multi_array.hpp>
+/**
+ @addtogroup stepper
+ @{
+*/
namespace libecs
{
- /** @addtogroup stepper
- *@{
- */
+typedef boost::multi_array<Real, 2> RealMatrix_;
+DECLARE_TYPE( RealMatrix_, RealMatrix );
- /** @file */
+DECLARE_CLASS( DifferentialStepper );
- /**
- DIFFERENTIAL EQUATION SOLVER
-
-
- */
-
- // DECLARE_VECTOR( RealVector, RealMatrix );
-
- typedef boost::multi_array<Real, 2> RealMatrix_;
- DECLARE_TYPE( RealMatrix_, RealMatrix );
-
- typedef std::pair< VariableIndex, Integer > ExprComponent;
- typedef std::vector< ExprComponent > VariableReferenceList;
- typedef std::vector< VariableReferenceList > VariableReferenceListVector;
-
- DECLARE_CLASS( DifferentialStepper );
-
- LIBECS_DM_CLASS( DifferentialStepper, Stepper )
- {
- public:
+LIBECS_DM_CLASS( DifferentialStepper, Stepper )
+{
+public:
typedef VariableVector::size_type VariableIndex;
+ typedef std::pair< VariableIndex, Integer > ExprComponent;
+ typedef std::vector< ExprComponent > VariableReferenceList;
+ typedef std::vector< VariableReferenceList > VariableReferenceListVector;
- public:
+public:
LIBECS_DM_OBJECT_ABSTRACT( DifferentialStepper )
- {
- INHERIT_PROPERTIES( Stepper );
+ {
+ INHERIT_PROPERTIES( Stepper );
- // FIXME: load/save ??
- PROPERTYSLOT( Real, StepInterval,
- &DifferentialStepper::initializeStepInterval,
- &DifferentialStepper::getStepInterval );
-
- PROPERTYSLOT_GET_NO_LOAD_SAVE( Real, NextStepInterval );
- PROPERTYSLOT_SET_GET_NO_LOAD_SAVE( Real, TolerableStepInterval );
- PROPERTYSLOT_GET_NO_LOAD_SAVE( Integer, Stage );
- PROPERTYSLOT_GET_NO_LOAD_SAVE( Integer, Order );
- }
+ // FIXME: load/save ??
+ PROPERTYSLOT( Real, StepInterval,
+ &DifferentialStepper::initializeStepInterval,
+ &DifferentialStepper::getStepInterval );
+
+ PROPERTYSLOT_GET_NO_LOAD_SAVE( Real, NextStepInterval );
+ PROPERTYSLOT_SET_GET_NO_LOAD_SAVE( Real, TolerableStepInterval );
+ PROPERTYSLOT_GET_NO_LOAD_SAVE( Integer, Stage );
+ PROPERTYSLOT_GET_NO_LOAD_SAVE( Integer, Order );
+ }
class Interpolant
- :
- public libecs::Interpolant
+ : public libecs::Interpolant
{
public:
+ Interpolant( DifferentialStepperRef aStepper,
+ VariablePtr const aVariablePtr )
+ : libecs::Interpolant( aVariablePtr ),
+ theStepper( aStepper ),
+ theIndex( theStepper.getVariableIndex( aVariablePtr ) )
+ {
+ ; // do nothing
+ }
- Interpolant( DifferentialStepperRef aStepper,
- VariablePtr const aVariablePtr )
- :
- libecs::Interpolant( aVariablePtr ),
- theStepper( aStepper ),
- theIndex( theStepper.getVariableIndex( aVariablePtr ) )
- {
- ; // do nothing
- }
-
- /*
- The getDifference() below is an optimized version of
- the original implementation based on the following two functions.
- (2004/10/19)
+ virtual const Real getDifference( RealParam aTime,
+ RealParam anInterval ) const;
- const Real interpolate( const RealMatrixCref aTaylorSeries,
- const Real anInterval,
- const Real aStepInterval )
- {
- const Real theta( anInterval / aStepInterval );
+ virtual const Real getVelocity( RealParam aTime ) const;
- Real aDifference( 0.0 );
- Real aFactorialInv( 1.0 );
-
- for ( RealMatrix::size_type s( 0 ); s < aTaylorSeries.size(); ++s )
- {
- // aFactorialInv /= s + 1;
- aDifference += aTaylorSeries[ s ][ theIndex ] * aFactorialInv;
- aFactorialInv *= theta;
- }
-
- return aDifference * anInterval;
- }
-
- virtual const Real getDifference( RealParam aTime,
- RealParam anInterval )
- {
-
- if ( !theStepper.theStateFlag )
- {
- return 0.0;
- }
-
- const RealMatrixCref aTaylorSeries( theStepper.getTaylorSeries() );
- const Real aTimeInterval( aTime - theStepper.getCurrentTime() );
- const Real aStepInterval( theStepper.getTolerableStepInterval() );
-
-
- const Real i1( interpolate( aTaylorSeries,
- aTimeInterval,
- aStepInterval ) );
- const Real i2( interpolate( aTaylorSeries,
- aTimeInterval - anInterval,
- aStepInterval ) );
- return ( i1 - i2 );
-
- }
- */
-
- virtual const Real getDifference( RealParam aTime,
- RealParam anInterval ) const
- {
- if ( !theStepper.theStateFlag )
- {
- return 0.0;
- }
-
- const Real aTimeInterval1( aTime - theStepper.getCurrentTime() );
- const Real aTimeInterval2( aTimeInterval1 - anInterval );
-
- RealMatrixCref aTaylorSeries( theStepper.getTaylorSeries() );
- RealCptr aTaylorCoefficientPtr( aTaylorSeries.origin() + theIndex );
-
- // calculate first order.
- // here it assumes that always aTaylorSeries.size() >= 1
-
- // *aTaylorCoefficientPtr := aTaylorSeries[ 0 ][ theIndex ]
- Real aValue1( *aTaylorCoefficientPtr * aTimeInterval1 );
- Real aValue2( *aTaylorCoefficientPtr * aTimeInterval2 );
-
-
- // check if second and higher order calculations are necessary.
- // const RealMatrix::size_type aTaylorSize( aTaylorSeries.size() );
- const RealMatrix::size_type aTaylorSize( theStepper.getOrder() );
- if( aTaylorSize >= 2)
- {
- const Real
- aStepIntervalInv( 1.0 / theStepper.getTolerableStepInterval() );
-
- const RealMatrix::size_type aStride( aTaylorSeries.strides()[0] );
-
- Real aFactorialInv1( aTimeInterval1 );
- Real aFactorialInv2( aTimeInterval2 );
-
- RealMatrix::size_type s( aTaylorSize - 1 );
-
- const Real theta1( aTimeInterval1 * aStepIntervalInv );
- const Real theta2( aTimeInterval2 * aStepIntervalInv );
-
- do
- {
- // main calculation for the 2+ order
-
- // aTaylorSeries[ s ][ theIndex ]
- aTaylorCoefficientPtr += aStride;
- const Real aTaylorCoefficient( *aTaylorCoefficientPtr );
-
- aFactorialInv1 *= theta1;
- aFactorialInv2 *= theta2;
-
- aValue1 += aTaylorCoefficient * aFactorialInv1;
- aValue2 += aTaylorCoefficient * aFactorialInv2;
-
- // LIBECS_PREFETCH( aTaylorCoefficientPtr + aStride, 0, 1 );
- --s;
- } while( s != 0 );
- }
-
- return aValue1 - aValue2;
- }
-
- virtual const Real getVelocity( RealParam aTime ) const
- {
- if ( !theStepper.theStateFlag )
- {
- return 0.0;
- }
-
- const Real aTimeInterval( aTime - theStepper.getCurrentTime() );
-
- RealMatrixCref aTaylorSeries( theStepper.getTaylorSeries() );
- RealCptr aTaylorCoefficientPtr( aTaylorSeries.origin() + theIndex );
-
- // calculate first order.
- // here it assumes that always aTaylorSeries.size() >= 1
-
- // *aTaylorCoefficientPtr := aTaylorSeries[ 0 ][ theIndex ]
- Real aValue( *aTaylorCoefficientPtr );
-
- // check if second and higher order calculations are necessary.
- // const RealMatrix::size_type aTaylorSize( aTaylorSeries.size() );
-
- const RealMatrix::size_type aTaylorSize( theStepper.getStage() );
- if( aTaylorSize >= 2 && aTimeInterval != 0.0 )
- {
- const RealMatrix::size_type aStride( aTaylorSeries.strides()[0] );
-
- Real aFactorialInv( 1.0 );
-
- RealMatrix::size_type s( 1 );
-
- const Real theta( aTimeInterval
- / theStepper.getTolerableStepInterval() );
-
- do
- {
- // main calculation for the 2+ order
- ++s;
-
- aTaylorCoefficientPtr += aStride;
- const Real aTaylorCoefficient( *aTaylorCoefficientPtr );
-
- aFactorialInv *= theta * s;
-
- aValue += aTaylorCoefficient * aFactorialInv;
-
- // LIBECS_PREFETCH( aTaylorCoefficientPtr + aStride, 0, 1 );
- } while( s != aTaylorSize );
- }
-
- return aValue;
- }
-
protected:
- DifferentialStepperRef theStepper;
- VariableVector::size_type theIndex;
+ DifferentialStepperRef theStepper;
+ VariableVector::size_type theIndex;
};
- public:
+public:
DifferentialStepper();
@@ -281,29 +109,29 @@
SET_METHOD( Real, NextStepInterval )
{
- theNextStepInterval = value;
+ theNextStepInterval = value;
}
GET_METHOD( Real, NextStepInterval )
{
- return theNextStepInterval;
+ return theNextStepInterval;
}
SET_METHOD( Real, TolerableStepInterval )
{
- theTolerableStepInterval = value;
+ theTolerableStepInterval = value;
}
GET_METHOD( Real, TolerableStepInterval )
{
- return theTolerableStepInterval;
+ return theTolerableStepInterval;
}
void initializeStepInterval( RealParam aStepInterval )
{
- setStepInterval( aStepInterval );
- setTolerableStepInterval( aStepInterval );
- setNextStepInterval( aStepInterval );
+ setStepInterval( aStepInterval );
+ setTolerableStepInterval( aStepInterval );
+ setNextStepInterval( aStepInterval );
}
void resetAll();
@@ -313,7 +141,7 @@
void initializeVariableReferenceList();
void setVariableVelocity( boost::detail::multi_array::sub_array<Real, 1> aVelocityBuffer );
-
+
virtual void initialize();
virtual void reset();
@@ -322,25 +150,25 @@
virtual InterpolantPtr createInterpolant( VariablePtr aVariable )
{
- return new DifferentialStepper::Interpolant( *this, aVariable );
+ return new DifferentialStepper::Interpolant( *this, aVariable );
}
virtual GET_METHOD( Integer, Stage )
{
- return 1;
+ return 1;
}
virtual GET_METHOD( Integer, Order )
{
- return getStage();
+ return getStage();
}
RealMatrixCref getTaylorSeries() const
{
- return theTaylorSeries;
+ return theTaylorSeries;
}
- protected:
+protected:
const bool isExternalErrorTolerable() const;
@@ -350,45 +178,45 @@
bool theStateFlag;
- private:
+private:
Real theNextStepInterval;
Real theTolerableStepInterval;
- };
+};
- /**
+/**
ADAPTIVE STEPSIZE DIFFERENTIAL EQUATION SOLVER
- */
+*/
- DECLARE_CLASS( AdaptiveDifferentialStepper );
+DECLARE_CLASS( AdaptiveDifferentialStepper );
- LIBECS_DM_CLASS( AdaptiveDifferentialStepper, DifferentialStepper )
- {
+LIBECS_DM_CLASS( AdaptiveDifferentialStepper, DifferentialStepper )
+{
- public:
+public:
LIBECS_DM_OBJECT_ABSTRACT( AdaptiveDifferentialStepper )
- {
- INHERIT_PROPERTIES( DifferentialStepper );
+ {
+ INHERIT_PROPERTIES( DifferentialStepper );
- PROPERTYSLOT_SET_GET( Real, Tolerance );
- PROPERTYSLOT_SET_GET( Real, AbsoluteToleranceFactor );
- PROPERTYSLOT_SET_GET( Real, StateToleranceFactor );
- PROPERTYSLOT_SET_GET( Real, DerivativeToleranceFactor );
+ PROPERTYSLOT_SET_GET( Real, Tolerance );
+ PROPERTYSLOT_SET_GET( Real, AbsoluteToleranceFactor );
+ PROPERTYSLOT_SET_GET( Real, StateToleranceFactor );
+ PROPERTYSLOT_SET_GET( Real, DerivativeToleranceFactor );
- PROPERTYSLOT( Integer, IsEpsilonChecked,
- &AdaptiveDifferentialStepper::setEpsilonChecked,
- &AdaptiveDifferentialStepper::isEpsilonChecked );
- PROPERTYSLOT_SET_GET( Real, AbsoluteEpsilon );
- PROPERTYSLOT_SET_GET( Real, RelativeEpsilon );
+ PROPERTYSLOT( Integer, IsEpsilonChecked,
+ &AdaptiveDifferentialStepper::setEpsilonChecked,
+ &AdaptiveDifferentialStepper::isEpsilonChe...
[truncated message content] |