yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #03029
[Branch ~yade-dev/yade/trunk] Rev 1962: 1. Document PeriodicEngine (doxygen comment in the header)
------------------------------------------------------------
revno: 1962
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-01-11 23:39:05 +0100
message:
1. Document PeriodicEngine (doxygen comment in the header)
2. Fix runtimePREFIX vs. PREFIX in yade-multi (only affects packages, not regular builds)
modified:
core/main/yade-multi.in
pkg/common/Engine/GlobalEngine/PeriodicEngines.hpp
scripts/debian-prep
--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== modified file 'core/main/yade-multi.in'
--- core/main/yade-multi.in 2009-12-08 12:08:48 +0000
+++ core/main/yade-multi.in 2010-01-11 22:39:05 +0000
@@ -6,7 +6,7 @@
import os, sys, thread, time, logging, pipes
## replaced by scons automatically
-prefix,suffix='${PREFIX}' if not os.environ.has_key('YADE_PREFIX') else os.environ('YADE_PREFIX'),'${SUFFIX}'
+prefix,suffix='${runtimePREFIX}' if not os.environ.has_key('YADE_PREFIX') else os.environ('YADE_PREFIX'),'${SUFFIX}'
sys.path.append(os.path.join(prefix,'lib','yade'+suffix,'py'))
executable=os.path.join(prefix,'bin','yade'+suffix)
## we just need this ...
=== modified file 'pkg/common/Engine/GlobalEngine/PeriodicEngines.hpp'
--- pkg/common/Engine/GlobalEngine/PeriodicEngines.hpp 2009-12-09 17:11:51 +0000
+++ pkg/common/Engine/GlobalEngine/PeriodicEngines.hpp 2010-01-11 22:39:05 +0000
@@ -1,22 +1,52 @@
-// 2008 © Václav Šmilauer <eudoxos@xxxxxxxx>
+// 2008, 2009 © Václav Šmilauer <eudoxos@xxxxxxxx>
#pragma once
#include<time.h>
#include<yade/core/GlobalEngine.hpp>
#include<yade/core/Omega.hpp>
-/* run an action with given fixed periodicity (real time, virtual time, iteration number), by setting any of
- * those criteria to a number > 0.
- *
- * The number of times this engine is activated can be limited by setting nDo>0. In the contrary case, or if
- * the number of activations was already reached, no action will be called even if any of active period has elapsed.
- *
- * If initRun is set, the engine will run when called for the first time; otherwise it will only set *Last and will be
- * called after desired period elapses for the first time.
+/*!
+ Run Engine::action with given fixed periodicity real time (=wall clock time, computation time),
+ virtual time (simulation time), iteration number), by setting any of those criteria
+ (virtPeriod, realPeriod, iterPeriod) to a positive value. They are all negative (inactive)
+ by default.
+
+ The number of times this engine is activated can be limited by setting nDo>0. If the number of activations
+ will have been already reached, no action will be called even if an active period has elapsed.
+
+ If initRun is set (false by default), the engine will run when called for the first time; otherwise it will only
+ start counting period (realLast etc interal variables) from that point, but without actually running, and will run
+ only once a period has elapsed since the initial run.
+
+ This class should be used directly; rather, derive your own engine which you want to be run periodically.
+
+ Derived engines should override Engine::action(Scene*), which will be called periodically. If the derived engine
+ overrides also Engine::isActivated, it should also take in account return value from PeriodicEngine::isActivated,
+ since otherwise the periodicity will not be functional.
+
+
+ Example with PeriodicPythonRunner, which derives from PeriodicEngine; likely to be encountered in python scripts):
+
+ PeriodicPythonRunner(realPeriod=5,iterPeriod=10000,command="print O.iter")
+
+ will print iteration number every 10000 iterations or every 5 seconds of wall clock time, whiever comes first since it was
+ last run.
*/
class PeriodicEngine: public GlobalEngine {
public:
static Real getClock(){ timeval tp; gettimeofday(&tp,NULL); return tp.tv_sec+tp.tv_usec/1e6; }
- Real virtPeriod, virtLast, realPeriod, realLast; long iterPeriod,iterLast,nDo,nDone;
+ //! Periodicity criterion using virtual (simulation) time (deactivated if <= 0, which is the default)
+ Real virtPeriod;
+ Real virtLast; // track virtual time we were executed last
+ //! Periodicity criterion using real (wall clock, computation, human) time (deactivated by default)
+ Real realPeriod;
+ Real realLast; // track real time we were executed last
+ //! Periodicity criterion using step number (deactivated by default)
+ long iterPeriod;
+ long iterLast; // track step number of last execution
+ //! Limit number of executions by this number (deactivated if negative, which is the default)
+ long nDo;
+ long nDone; // track number of executions (cummulative)
+ //! Run the first time we are called as well (false by default)
bool initRun;
PeriodicEngine(): virtPeriod(0),virtLast(0),realPeriod(0),realLast(0),iterPeriod(0),iterLast(0),nDo(-1),nDone(0),initRun(false) { realLast=getClock(); }
virtual bool isActivated(Scene*){
@@ -51,24 +81,21 @@
};
REGISTER_SERIALIZABLE(PeriodicEngine);
-#if 0
-class StridePeriodicEngine: public PeriodicEngine{
- public:
- StridePeriodicEngine(): stride, maxStride
-}
-#endif
-
-/* PeriodicEngine but with constraint that may be stretched by a given stretchFactor (default 2).
- * Limits for each periodicity criterion may be set and the mayStretch bool says whether the period
- * can be stretched (default: doubled) without active criteria getting off limits.
- *
- * stretchFactor must be positive; if >1, period is stretched, for <1, it is shrunk.
- *
- * Limit consistency (whether actual period is not over/below the limit) is checked: period is set to the
- * limit value if we are off. If the limit is zero, however, and the period is non-zero, the limit is set
- * to the period value (therefore, if you initialize only iterPeriod, you will get what you expect: engine
- * running at iterPeriod).
- */
+/*!
+ PeriodicEngine but with constraint that may be stretched by a given stretchFactor (default 2).
+ Limits for each periodicity criterion may be set and the mayStretch bool says whether the period
+ can be stretched (default: doubled) without active criteria getting off limits.
+
+ stretchFactor must be positive; if >1, period is stretched, for <1, it is shrunk.
+
+ Limit consistency (whether actual period is not over/below the limit) is checked: period is set to the
+ limit value if we are off. If the limit is zero, however, and the period is non-zero, the limit is set
+ to the period value (therefore, if you initialize only iterPeriod, you will get what you expect: engine
+ running at iterPeriod).
+
+ Note: the logic here is probably too complicated to be practical, although it works. Chances are that
+ if unused, it will be removed from the codebase.
+*/
class StretchPeriodicEngine: public PeriodicEngine{
public:
StretchPeriodicEngine(): PeriodicEngine(), realLim(0.), virtLim(0.), iterLim(0), stretchFactor(2.), mayStretch(false){}
@@ -93,66 +120,3 @@
};
REGISTER_SERIALIZABLE(StretchPeriodicEngine);
-// obsolete, too complicated etc
-#if 0
-
-/* Run an action with adjustable and constrained periodicity (real time, virtual time, iteration)
- *
- * 3 criteria can be used: iteration period, realTime (wallclock) period, virtTime (simulation time) period.
- * Each of them is composed of a Vector3r with the meaning [lower limit, actual period value, upper limit].
- * The criterion is disabled if the lower limit is < 0, which is the default.
- * If _any_ criterion from the enabled ones is satisfied (elapsed iteration period etc.), the engine becomes active.
- *
- * At the first run after construction, the engine will ensure period consistency,
- * i.e. that on enabled periods, limits are properly ordered (swapped otherwise)
- * and that the actual value is not over the upper limit (will be made equal to it otherwise) ot under the lower limit.
- *
- * If it is useful to make the actual periods smaller/larger, mayDouble and mayHalve signify whether actual periods
- * (considering only enabled criteria) may be halved/doubled without getting off limits.
- *
- * This engine may be used only by deriving an engine with something useful in action(Scene*);
- * if used as-is, it will throw when activated.
- */
-class __attribute__((deprecated)) RangePeriodicEngine: public GlobalEngine {
- private:
- Vector3r virtTimeLim,realTimeLim,iterLim;
- Real lastRealTime,lastVirtTime; long lastIter;
- bool mayDouble,mayHalve;
- bool perhapsInconsistent;
- void ensureConsistency(Vector3r& v){
- if(v[0]<0) return; // not active
- if(v[2]<v[0]){Real lo=v[2]; v[2]=v[0]; v[0]=lo;} // swap limits if necessary
- if(v[1]<v[0]) v[1]=v[0]; // put actual value below the lower limit to the lower limit
- if(v[1]>v[2]) v[2]=v[1]; // put actual value above the upper limit to the upper limit
- }
- public :
- RangePeriodicEngine(): virtTimeLim(-1,0,0),realTimeLim(-1,0,0),iterLim(-1,0,0), lastRealTime(0.),lastVirtTime(0.),lastIter(0),mayDouble(false),mayHalve(false),perhapsInconsistent(true){};
- virtual void action(Scene* b) { throw; }
- virtual bool isActivated(Scene* rootBody){
- if(perhapsInconsistent){ ensureConsistency(virtTimeLim); ensureConsistency(realTimeLim); ensureConsistency(iterLim); perhapsInconsistent=false; }
-
- mayDouble=((virtTimeLim[0]<0 || 2*virtTimeLim[1]<=virtTimeLim[2]) && (realTimeLim[0]<0 || 2*realTimeLim[1]<=realTimeLim[2]) && (iterLim[0]<0 || 2*iterLim[1]<=iterLim[2]));
- mayHalve=((virtTimeLim[0]<0 || .5*virtTimeLim[1]>=virtTimeLim[0]) && (realTimeLim[0]<0 && .5*realTimeLim[1]>=realTimeLim[0]) && (iterLim[0]<0 || .5*iterLim[1]>=iterLim[0]));
-
- long nowIter=Omega::instance().getCurrentIteration();
- Real nowVirtTime=Omega::instance().getSimulationTime();
- //Real nowRealTime=boost::posix_time::microsec_clock::universal_time()/1e6;
- timeval tp; gettimeofday(&tp,NULL); Real nowRealTime=tp.tv_sec+tp.tv_usec/1e6;
- //cerr<<"--------------------"<<endl; cerr<<"virt:"<<virtTimeLim<<";"<<lastVirtTime<<";"<<nowVirtTime<<endl; cerr<<"real:"<<realTimeLim<<";"<<lastRealTime<<";"<<nowRealTime<<endl; cerr<<"iter:"<<iterLim<<";"<<lastIter<<";"<<nowIter<<endl;
- if ( (virtTimeLim[0]>=0 && nowVirtTime-lastVirtTime>virtTimeLim[1])
- || (realTimeLim[0]>=0 && nowRealTime-lastRealTime>realTimeLim[1])
- || (iterLim[0]>=0 && nowIter -lastIter >iterLim[1])){
- lastVirtTime=nowVirtTime; lastRealTime=nowRealTime; lastIter=nowIter;
- return true;
- } else return false;
- }
- REGISTER_ATTRIBUTES(GlobalEngine,(virtTimeLim)(realTimeLim)(iterLim)(lastRealTime)(lastVirtTime)(lastIter)(mayDouble)(mayHalve));
- protected :
- virtual void postProcessAttributes(bool deserializing){}
- DECLARE_LOGGER;
- REGISTER_CLASS_NAME(RangePeriodicEngine);
- REGISTER_BASE_CLASS_NAME(GlobalEngine);
-};
-REGISTER_SERIALIZABLE(RangePeriodicEngine);
-
-#endif
=== modified file 'scripts/debian-prep'
--- scripts/debian-prep 2010-01-10 09:09:32 +0000
+++ scripts/debian-prep 2010-01-11 22:39:05 +0000
@@ -9,8 +9,7 @@
##Â DISTRIBUTION (first argument, otherwise the default "unstable")
DISTRIBUTION=$1; [ -n "$DISTRIBUTION" ] || DISTRIBUTION="unstable"
-
-## VERSION (from RELEASE or svn or bzr)
+## create VERSION file (from RELEASE or svn or bzr)
if [ -f RELEASE ]; then VERSION=`cat RELEASE`; SNAPSHOT=""
elif [ -d .svn ]; then VERSION="svn$( svn info | egrep '^Revision:' | cut -f2 -d' ')"; SNAPSHOT="-snapshot"
elif [ -d .bzr ]; then VERSION="bzr$( bzr revno )"; SNAPSHOT="-snapshot"
@@ -26,13 +25,13 @@
fi
_VERSION="-$VERSION"; echo $VERSION > VERSION
echo PRIORITY $PRIORITY
+# process templates
cp debian/yade.postinst-template debian/yade$_VERSION.postinst
cp debian/yade-dbg.postinst-template debian/yade$_VERSION-dbg.postinst
cp debian/yade.prerm-template debian/yade$_VERSION.prerm
cp debian/yade-dbg.prerm-template debian/yade$_VERSION-dbg.prerm
cp debian/control-template debian/control; perl -pi -e"s/\@VERSION\@/$VERSION/g; s/\@_VERSION\@/$_VERSION/g; s/\@SNAPSHOT\@/$SNAPSHOT/g; s/\@PRIORITY\@/$PRIORITY/g;" debian/control debian/yade$_VERSION.postinst debian/yade$_VERSION-dbg.postinst debian/yade$_VERSION.prerm debian/yade$_VERSION-dbg.prerm;
-
-## debian/changelog
+# write debian/changelog
DEBDATE=`date -R`
cat <<EOF > debian/changelog
yade$_VERSION (1~$DISTRIBUTION) $DISTRIBUTION; urgency=low
@@ -41,4 +40,5 @@
-- Václav Šmilauer <eudoxos@xxxxxxxx> $DEBDATE
EOF
-
+# remove generated files that shouldn't be in the orig.tar.gz
+rm -rf tags doc/doxygen doc/html doc/epydoc