yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #00716
[svn] r1543 - in trunk: extra gui/py gui/qt3 pkg/common/Engine/StandAloneEngine pkg/dem/Engine/DeusExMachina
Author: eudoxos
Date: 2008-10-13 09:38:23 +0200 (Mon, 13 Oct 2008)
New Revision: 1543
Modified:
trunk/extra/Brefcom.cpp
trunk/extra/Brefcom.hpp
trunk/gui/py/PeriodicPythonRunner.hpp
trunk/gui/qt3/QtGUI-python.cpp
trunk/pkg/common/Engine/StandAloneEngine/PeriodicEngines.hpp
trunk/pkg/common/Engine/StandAloneEngine/PersistentSAPCollider.cpp
trunk/pkg/dem/Engine/DeusExMachina/TriaxialCompressionEngine.cpp
Log:
1. Fix crasher (under special circumstances) in PersistentSAPCollider (deletion invalidating iterator)
2. PeriodicEngine now takes nDo and nDone attributes, limitng number of activations
3. Fix minor things is BrefcomDamageColorizer, add normalized damage to BrefcomPhysParams
4. Fix some indents in Triaxial
Modified: trunk/extra/Brefcom.cpp
===================================================================
--- trunk/extra/Brefcom.cpp 2008-10-11 14:23:53 UTC (rev 1542)
+++ trunk/extra/Brefcom.cpp 2008-10-13 07:38:23 UTC (rev 1543)
@@ -233,7 +233,7 @@
void BrefcomDamageColorizer::action(MetaBody* rootBody){
vector<pair<short,Real> > bodyDamage; /* number of cohesive interactions per body; cummulative damage of interactions */
bodyDamage.resize(rootBody->bodies->size(),pair<short,Real>(0,0));
- FOREACH(shared_ptr<Interaction> I, *rootBody->transientInteractions){
+ FOREACH(const shared_ptr<Interaction>& I, *rootBody->transientInteractions){
shared_ptr<BrefcomContact> BC=dynamic_pointer_cast<BrefcomContact>(I->interactionPhysics);
if(!BC || !BC->isCohesive) continue;
const body_id_t id1=I->getId1(), id2=I->getId2();
@@ -242,11 +242,14 @@
maxOmega=max(maxOmega,BC->omega);
}
FOREACH(shared_ptr<Body> B, *rootBody->bodies){
+ body_id_t id=B->getId();
// add damaged contacts that have already been deleted
- unsigned numBrokenCohesive=YADE_PTR_CAST<BrefcomPhysParams>(B->physicalParameters)->numBrokenCohesive;
- if(bodyDamage[B->getId()].first==0) {B->geometricalModel->diffuseColor=Vector3r(0.5,0.5,B->isDynamic?0:1); continue; }
- Real normDmg=(bodyDamage[B->getId()].second+numBrokenCohesive)/(bodyDamage[B->getId()].first+numBrokenCohesive);
- B->geometricalModel->diffuseColor=Vector3r(normDmg,1-normDmg,B->isDynamic?0:1);
+ shared_ptr<BrefcomPhysParams> bpp=YADE_PTR_CAST<BrefcomPhysParams>(B->physicalParameters);
+ //if(bodyDamage[B->getId()].first==0) {B->geometricalModel->diffuseColor=Vector3r(0.5,0.5,B->isDynamic?0:1); continue; }
+ int pastOrPresentContacts=bodyDamage[id].first+bpp->numBrokenCohesive;
+ if(pastOrPresentContacts>0) bpp->normDmg=(bodyDamage[id].second+bpp->numBrokenCohesive)/pastOrPresentContacts;
+ else bpp->normDmg=0;
+ B->geometricalModel->diffuseColor=Vector3r(bpp->normDmg,1-bpp->normDmg,B->isDynamic?0:1);
}
}
Modified: trunk/extra/Brefcom.hpp
===================================================================
--- trunk/extra/Brefcom.hpp 2008-10-11 14:23:53 UTC (rev 1542)
+++ trunk/extra/Brefcom.hpp 2008-10-13 07:38:23 UTC (rev 1543)
@@ -137,8 +137,10 @@
int numBrokenCohesive;
//! number of contacts with this body
int numContacts;
- BrefcomPhysParams(): epsVolumetric(0.), numBrokenCohesive(0), numContacts(0) {createIndex();};
- virtual void registerAttributes(){BodyMacroParameters::registerAttributes(); REGISTER_ATTRIBUTE(epsVolumetric); REGISTER_ATTRIBUTE(numBrokenCohesive); REGISTER_ATTRIBUTE(numContacts); }
+ //! average damage including already deleted contacts
+ Real normDmg;
+ BrefcomPhysParams(): epsVolumetric(0.), numBrokenCohesive(0), numContacts(0), normDmg(0.) {createIndex();};
+ virtual void registerAttributes(){BodyMacroParameters::registerAttributes(); REGISTER_ATTRIBUTE(epsVolumetric); REGISTER_ATTRIBUTE(numBrokenCohesive); REGISTER_ATTRIBUTE(numContacts); REGISTER_ATTRIBUTE(normDmg); }
REGISTER_CLASS_NAME(BrefcomPhysParams);
REGISTER_BASE_CLASS_NAME(BodyMacroParameters);
};
Modified: trunk/gui/py/PeriodicPythonRunner.hpp
===================================================================
--- trunk/gui/py/PeriodicPythonRunner.hpp 2008-10-11 14:23:53 UTC (rev 1542)
+++ trunk/gui/py/PeriodicPythonRunner.hpp 2008-10-13 07:38:23 UTC (rev 1543)
@@ -14,7 +14,7 @@
string command;
public :
PeriodicPythonRunner(): command("pass"){};
- /* virtual bool isActivated: not overridden, PeriodicEngine handles that */
+ /* virtual bool isActivated: not overridden, StretchPeriodicEngine handles that */
virtual void action(MetaBody* b){
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
Modified: trunk/gui/qt3/QtGUI-python.cpp
===================================================================
--- trunk/gui/qt3/QtGUI-python.cpp 2008-10-11 14:23:53 UTC (rev 1542)
+++ trunk/gui/qt3/QtGUI-python.cpp 2008-10-13 07:38:23 UTC (rev 1543)
@@ -96,7 +96,9 @@
if(dispParamsNo>=0) { LOG_INFO("Loading view state from state #"<<dispParamsNo); glv->useDisplayParameters(dispParamsNo);}
glv->raise();
glv->startAnimation();
+ Py_BEGIN_ALLOW_THREADS;
while(glv->animationIsStarted()) { usleep(2000000); LOG_DEBUG("Last msg: "<<*player->messages.rbegin()); }
+ Py_END_ALLOW_THREADS;
python::list snaps; FOREACH(string s, glv->snapshots){snaps.append(s);}
return python::make_tuple(snapBase2+"-%.04d.png",snaps);
}
Modified: trunk/pkg/common/Engine/StandAloneEngine/PeriodicEngines.hpp
===================================================================
--- trunk/pkg/common/Engine/StandAloneEngine/PeriodicEngines.hpp 2008-10-11 14:23:53 UTC (rev 1542)
+++ trunk/pkg/common/Engine/StandAloneEngine/PeriodicEngines.hpp 2008-10-13 07:38:23 UTC (rev 1543)
@@ -5,21 +5,26 @@
#include<yade/core/StandAloneEngine.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. */
+ * 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.
+ */
class PeriodicEngine: public StandAloneEngine {
protected:
static Real getClock(){ timeval tp; gettimeofday(&tp,NULL); return tp.tv_sec+tp.tv_usec/1e6; }
public:
- Real virtPeriod, virtLast, realPeriod, realLast; long iterPeriod,iterLast;
- PeriodicEngine(): virtPeriod(0),virtLast(0),realPeriod(0),realLast(0),iterPeriod(0),iterLast(0) { realLast=getClock(); }
+ Real virtPeriod, virtLast, realPeriod, realLast; long iterPeriod,iterLast,nDo,nDone;
+ PeriodicEngine(): virtPeriod(0),virtLast(0),realPeriod(0),realLast(0),iterPeriod(0),iterLast(0),nDo(-1),nDone(0) { realLast=getClock(); }
virtual bool isActivated(){
Real virtNow=Omega::instance().getSimulationTime();
Real realNow=getClock();
long iterNow=Omega::instance().getCurrentIteration();
- if((virtPeriod>0 && virtNow-virtLast>=virtPeriod) ||
- (realPeriod>0 && realNow-realLast>=realPeriod) ||
- (iterPeriod>0 && iterNow-iterLast>=iterPeriod)){
- realLast=realNow; virtLast=virtNow; iterLast=iterNow;
+ if((nDo<0 || nDone<nDo) &&
+ ((virtPeriod>0 && virtNow-virtLast>=virtPeriod) ||
+ (realPeriod>0 && realNow-realLast>=realPeriod) ||
+ (iterPeriod>0 && iterNow-iterLast>=iterPeriod))){
+ realLast=realNow; virtLast=virtNow; iterLast=iterNow; nDone++;
return true;
}
return false;
@@ -33,12 +38,21 @@
REGISTER_ATTRIBUTE(virtLast);
REGISTER_ATTRIBUTE(realLast);
REGISTER_ATTRIBUTE(iterLast);
+ REGISTER_ATTRIBUTE(nDo);
+ REGISTER_ATTRIBUTE(nDone);
}
REGISTER_CLASS_NAME(PeriodicEngine);
REGISTER_BASE_CLASS_NAME(StandAloneEngine);
};
REGISTER_SERIALIZABLE(PeriodicEngine,false);
+#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.
@@ -55,7 +69,7 @@
StretchPeriodicEngine(): PeriodicEngine(), realLim(0.), virtLim(0.), iterLim(0), stretchFactor(2.){}
Real realLim, virtLim; long iterLim;
Real stretchFactor;
- int mayStretch;
+ bool mayStretch;
virtual bool isActivated(){
assert(stretchFactor>0);
if(iterLim==0 && iterPeriod!=0){iterLim=iterPeriod;} else if(iterLim!=0 && iterPeriod==0){iterPeriod=iterLim;}
Modified: trunk/pkg/common/Engine/StandAloneEngine/PersistentSAPCollider.cpp
===================================================================
--- trunk/pkg/common/Engine/StandAloneEngine/PersistentSAPCollider.cpp 2008-10-11 14:23:53 UTC (rev 1542)
+++ trunk/pkg/common/Engine/StandAloneEngine/PersistentSAPCollider.cpp 2008-10-13 07:38:23 UTC (rev 1543)
@@ -71,10 +71,12 @@
maxima[offset+0]=pos[0]; maxima[offset+1]=pos[1]; maxima[offset+2]=pos[2];
}
}
+ typedef pair<body_id_t,body_id_t> bodyIdPair;
+ list<bodyIdPair> toBeDeleted;
FOREACH(const shared_ptr<Interaction>& I,*ncb->transientInteractions){
// remove interactions deleted by the constitutive law: thay are not new, but nor real either
// to make sure, do that only with haveDistantTransient
- if(haveDistantTransient && !I->isNew && !I->isReal) { transientInteractions->erase(I->getId1(),I->getId2()); continue; }
+ if(haveDistantTransient && !I->isNew && !I->isReal) { toBeDeleted.push_back(bodyIdPair(I->getId1(),I->getId2())); continue; }
// Once the interaction has been fully created, it is not "new" anymore
if (I->isReal) I->isNew=false;
// OTOH if is is now real anymore, it falls back to the potential state
@@ -85,6 +87,7 @@
if(!haveDistantTransient) I->isReal=false;
//if(!I->isReal){LOG_DEBUG("Interaction #"<<I->getId1()<<"=#"<<I->getId2()<<" is not real.");}
}
+ FOREACH(const bodyIdPair& p, toBeDeleted){ transientInteractions->erase(p.first,p.second); }
updateIds(bodies->size());
nbObjects=bodies->size();
Modified: trunk/pkg/dem/Engine/DeusExMachina/TriaxialCompressionEngine.cpp
===================================================================
--- trunk/pkg/dem/Engine/DeusExMachina/TriaxialCompressionEngine.cpp 2008-10-11 14:23:53 UTC (rev 1542)
+++ trunk/pkg/dem/Engine/DeusExMachina/TriaxialCompressionEngine.cpp 2008-10-13 07:38:23 UTC (rev 1543)
@@ -269,27 +269,21 @@
}
InteractionContainer::iterator ii = ncb->transientInteractions->begin();
- InteractionContainer::iterator iiEnd = ncb->transientInteractions->end();
-
- for( ; ii!=iiEnd ; ++ii )
- {
- if ((*ii)->isReal)
- {
- const shared_ptr<BodyMacroParameters>& sdec1 = YADE_PTR_CAST<BodyMacroParameters>((*bodies)[(body_id_t) ((*ii)->getId1())]->physicalParameters);
- const shared_ptr<BodyMacroParameters>& sdec2 = YADE_PTR_CAST<BodyMacroParameters>((*bodies)[(body_id_t) ((*ii)->getId2())]->physicalParameters);
-
- //FIXME - why dynamic_cast fails here?
- //const shared_ptr<ElasticContactInteraction>& contactPhysics = YADE_PTR_CAST<ElasticContactInteraction>((*ii)->interactionPhysics);
- const shared_ptr<ElasticContactInteraction>& contactPhysics = static_pointer_cast<ElasticContactInteraction>((*ii)->interactionPhysics);
-
- Real fa = sdec1->frictionAngle;
- Real fb = sdec2->frictionAngle;
+ InteractionContainer::iterator iiEnd = ncb->transientInteractions->end();
+ for( ; ii!=iiEnd ; ++ii ) {
+ if (!(*ii)->isReal) continue;
+ const shared_ptr<BodyMacroParameters>& sdec1 = YADE_PTR_CAST<BodyMacroParameters>((*bodies)[(body_id_t) ((*ii)->getId1())]->physicalParameters);
+ const shared_ptr<BodyMacroParameters>& sdec2 = YADE_PTR_CAST<BodyMacroParameters>((*bodies)[(body_id_t) ((*ii)->getId2())]->physicalParameters);
+ //FIXME - why dynamic_cast fails here?
+ //const shared_ptr<ElasticContactInteraction>& contactPhysics = YADE_PTR_CAST<ElasticContactInteraction>((*ii)->interactionPhysics);
+ const shared_ptr<ElasticContactInteraction>& contactPhysics = static_pointer_cast<ElasticContactInteraction>((*ii)->interactionPhysics);
- contactPhysics->frictionAngle = std::min(fa,fb);
- contactPhysics->tangensOfFrictionAngle = std::tan(contactPhysics->frictionAngle);
- }
- }
+ Real fa = sdec1->frictionAngle;
+ Real fb = sdec2->frictionAngle;
+ contactPhysics->frictionAngle = std::min(fa,fb);
+ contactPhysics->tangensOfFrictionAngle = std::tan(contactPhysics->frictionAngle);
+ }
}