yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #02236
[Branch ~yade-dev/yade/trunk] Rev 1791: 1. For each interaction, save when it was last seen by the collider. Adapt SpatialQuickSortCollid...
------------------------------------------------------------
revno: 1791
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Wed 2009-11-18 11:24:57 +0100
message:
1. For each interaction, save when it was last seen by the collider. Adapt SpatialQuickSortCollider for that (remove Interaction::cycle), it saves 2 loops over interactions. The deletion is triggered in InteractionDispatcher/InteractionGeometryDispatcher afterwards. This infrastructure is neede for the grid collider.
modified:
core/Interaction.hpp
core/InteractionContainer.hpp
pkg/common/Engine/MetaEngine/InteractionDispatchers.cpp
pkg/common/Engine/MetaEngine/InteractionGeometryMetaEngine.cpp
pkg/common/Engine/StandAloneEngine/SpatialQuickSortCollider.cpp
pkg/common/Engine/StandAloneEngine/SpatialQuickSortCollider.hpp
--
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/Interaction.hpp'
--- core/Interaction.hpp 2009-08-09 16:17:53 +0000
+++ core/Interaction.hpp 2009-11-18 10:24:57 +0000
@@ -33,8 +33,8 @@
//! If this interaction was just created in this step (for the constitutive law, to know that it is the first time there)
bool isFresh(MetaBody* rb);
- //! phase flag to mark (for example, SpatialQuickSortCollider mark by it the stale interactions)
- bool cycle;
+ //! At which step this interaction was last detected by the collider. InteractionDispatcher will remove it if InteractionContainer::iterColliderLastRun==currentStep and iterLastSeen<currentStep
+ long iterLastSeen;
//! NOTE : TriangulationCollider needs this (nothing else)
bool isNeighbor;
=== modified file 'core/InteractionContainer.hpp'
--- core/InteractionContainer.hpp 2009-11-14 12:32:32 +0000
+++ core/InteractionContainer.hpp 2009-11-18 10:24:57 +0000
@@ -86,8 +86,9 @@
{
public :
boost::mutex drawloopmutex;
+ long iterColliderLastRun;
- InteractionContainer(): serializeSorted(false) {
+ InteractionContainer(): iterColliderLastRun(-1), serializeSorted(false) {
#ifdef YADE_OPENMP
threadsPendingErase.resize(omp_get_max_threads());
#endif
=== modified file 'pkg/common/Engine/MetaEngine/InteractionDispatchers.cpp'
--- pkg/common/Engine/MetaEngine/InteractionDispatchers.cpp 2009-11-14 12:32:32 +0000
+++ pkg/common/Engine/MetaEngine/InteractionDispatchers.cpp 2009-11-18 10:24:57 +0000
@@ -35,6 +35,7 @@
alreadyWarnedNoCollider=true;
}
Vector3r cellSize; if(rootBody->isPeriodic) cellSize=rootBody->cellMax-rootBody->cellMin;
+ bool removeUnseenIntrs=(rootBody->interactions->iterColliderLastRun>=0 && rootBody->interactions->iterColliderLastRun==rootBody->currentIteration);
#ifdef YADE_OPENMP
const long size=rootBody->interactions->size();
#pragma omp parallel for schedule(guided)
@@ -44,13 +45,19 @@
FOREACH(shared_ptr<Interaction> I, *rootBody->interactions){
#endif
#ifdef DISPATCH_CACHE
+ if(removeUnseenIntrs && !I->isReal() && I->iterLastSeen<rootBody->currentIteration) {
+ rootBody->interactions->requestErase(I->getId1(),I->getId2());
+ continue;
+ }
const shared_ptr<Body>& b1_=Body::byId(I->getId1(),rootBody);
const shared_ptr<Body>& b2_=Body::byId(I->getId2(),rootBody);
+ // FIXME: maybe this could be run even in production code without harm. It would make removing bodies much faster, since we wouldn't have to search its interactions and removing them.
#ifndef NDEBUG
- if(!b1_ || !b2_){ LOG_ERROR("Body #"<<(b1_?I->getId2():I->getId1())<<" vanished, erasing intr #"<<I->getId1()<<"+#"<<I->getId2()<<"!"); rootBody->interactions->requestErase(I->getId1(),I->getId2()); continue; }
+ if(!b1_ || !b2_){ LOG_ERROR("Body #"<<(b1_?I->getId2():I->getId1())<<" vanished, erasing intr #"<<I->getId1()<<"+#"<<I->getId2()<<"!"); rootBody->interactions->requestErase(I->getId1(),I->getId2(),/*force*/true); continue; }
#endif
+
// go fast if this pair of bodies cannot interact at all
if((b1_->getGroupMask() & b2_->getGroupMask())==0) continue;
=== modified file 'pkg/common/Engine/MetaEngine/InteractionGeometryMetaEngine.cpp'
--- pkg/common/Engine/MetaEngine/InteractionGeometryMetaEngine.cpp 2009-08-07 09:27:49 +0000
+++ pkg/common/Engine/MetaEngine/InteractionGeometryMetaEngine.cpp 2009-11-18 10:24:57 +0000
@@ -52,6 +52,7 @@
shared_ptr<BodyContainer>& bodies = ncb->bodies;
Vector3r cellSize; if(ncb->isPeriodic) cellSize=ncb->cellMax-ncb->cellMin;
+ bool removeUnseenIntrs=(ncb->interactions->iterColliderLastRun>=0 && ncb->interactions->iterColliderLastRun==ncb->currentIteration);
#ifdef YADE_OPENMP
const long size=ncb->transientInteractions->size();
#pragma omp parallel for
@@ -60,6 +61,10 @@
#else
FOREACH(const shared_ptr<Interaction>& I, *ncb->interactions){
#endif
+ if(removeUnseenIntrs && !I->isReal() && I->iterLastSeen<ncb->currentIteration) {
+ ncb->interactions->requestErase(I->getId1(),I->getId2());
+ continue;
+ }
const shared_ptr<Body>& b1=(*bodies)[I->getId1()];
const shared_ptr<Body>& b2=(*bodies)[I->getId2()];
bool wasReal=I->isReal();
=== modified file 'pkg/common/Engine/StandAloneEngine/SpatialQuickSortCollider.cpp'
--- pkg/common/Engine/StandAloneEngine/SpatialQuickSortCollider.cpp 2009-08-22 18:21:25 +0000
+++ pkg/common/Engine/StandAloneEngine/SpatialQuickSortCollider.cpp 2009-11-18 10:24:57 +0000
@@ -15,7 +15,6 @@
SpatialQuickSortCollider::SpatialQuickSortCollider() : Collider()
{
- haveDistantTransient=false;
}
SpatialQuickSortCollider::~SpatialQuickSortCollider()
@@ -27,8 +26,9 @@
{
const shared_ptr<BodyContainer>& bodies = ncb->bodies;
- // This collider traverses all interactions at every step, therefore interactions that were reset() will be deleted automatically as needed
- ncb->interactions->clearPendingErase();
+ // This collider traverses all interactions at every step, therefore all interactions
+ // that were requested for erase might be erased here and will be recreated if necessary.
+ ncb->interactions->unconditionalErasePending();
size_t nbElements=bodies->size();
if (nbElements!=rank.size())
@@ -59,12 +59,9 @@
rank[i]->min = min;
rank[i]->max = max;
}
-
- shared_ptr< InteractionContainer > transientInteractions = ncb->transientInteractions;
- InteractionContainer::iterator ii = transientInteractions->begin();
- InteractionContainer::iterator iiEnd = transientInteractions->end();
- for( ; ii!=iiEnd ; ++ii)
- (*ii)->cycle=false;
+
+ const shared_ptr<InteractionContainer>& interactions=ncb->interactions;
+ ncb->interactions->iterColliderLastRun=ncb->currentIteration;
sort(rank.begin(), rank.end(), xBoundComparator()); // sotring along X
@@ -85,34 +82,14 @@
&& rank[j]->max[2] > min[2])
{
id2=rank[j]->id;
- if ( (interaction = transientInteractions->find(body_id_t(id),body_id_t(id2))) == 0)
+ if ( (interaction = interactions->find(body_id_t(id),body_id_t(id2))) == 0)
{
interaction = shared_ptr<Interaction>(new Interaction(id,id2) );
- transientInteractions->insert(interaction);
+ interactions->insert(interaction);
}
- interaction->cycle=true;
- // if interaction !isReal it falls back to the potential state
- // FIXME: eudoxos: do nothing here... is that correct?
- // if (!haveDistantTransient && !interaction->isReal()) interaction->isNew=true;
+ interaction->iterLastSeen=ncb->currentIteration;
}
}
}
-
- ii = transientInteractions->begin();
- iiEnd = transientInteractions->end();
- for( ; ii!=iiEnd ; ++ii)
- {
- interaction = *ii;
- if(
- // if haveDistantTransient remove interactions deleted by the constitutive law
- (haveDistantTransient && !interaction->isReal())
- // if !haveDistantTransient remove interactions without AABB overlapping
- || (!haveDistantTransient && !interaction->cycle)
- ) {
- transientInteractions->erase( interaction->getId1(), interaction->getId2() );
- continue;
- }
- }
-
}
=== modified file 'pkg/common/Engine/StandAloneEngine/SpatialQuickSortCollider.hpp'
--- pkg/common/Engine/StandAloneEngine/SpatialQuickSortCollider.hpp 2009-07-17 20:50:55 +0000
+++ pkg/common/Engine/StandAloneEngine/SpatialQuickSortCollider.hpp 2009-11-18 10:24:57 +0000
@@ -38,11 +38,7 @@
virtual void action(MetaBody*);
-
- //! Don't break transient interaction once bodies don't overlap anymore; material law will be responsible for breaking it.
- bool haveDistantTransient;
-
- REGISTER_ATTRIBUTES(Collider,(haveDistantTransient));
+ REGISTER_ATTRIBUTES(Collider,);
DECLARE_LOGGER;
REGISTER_CLASS_NAME(SpatialQuickSortCollider);
REGISTER_BASE_CLASS_NAME(Collider);