← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 3811: remove deprecated code linked to queuing requestErase'd interactions in an older version of the c...

 

------------------------------------------------------------
revno: 3811
committer: Bruno Chareyre <bruno.chareyre@xxxxxxxxxxxxxxx>
timestamp: Mon 2014-02-03 12:21:42 +0100
message:
  remove deprecated code linked to queuing requestErase'd interactions in an older version of the collider
modified:
  core/InteractionContainer.cpp
  core/InteractionContainer.hpp
  pkg/common/Cylinder.cpp
  pkg/common/Dispatching.cpp
  pkg/common/InteractionLoop.cpp
  pkg/common/SpatialQuickSortCollider.cpp
  pkg/dem/FlatGridCollider.cpp
  pkg/dem/NormalInelasticityLaw.cpp


--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file 'core/InteractionContainer.cpp'
--- core/InteractionContainer.cpp	2013-03-06 17:30:45 +0000
+++ core/InteractionContainer.cpp	2014-02-03 11:21:42 +0000
@@ -46,7 +46,6 @@
 		if (b) b->intrs.clear(); // delete interactions from bodies
 	}
 	linIntrs.clear(); // clear the linear container
-	pendingErase.clear();
 	currSize=0;
 	dirty=true;
 }
@@ -116,14 +115,9 @@
 }
 
 
-void InteractionContainer::requestErase(Body::id_t id1, Body::id_t id2, bool force){
+void InteractionContainer::requestErase(Body::id_t id1, Body::id_t id2){
 	const shared_ptr<Interaction> I=find(id1,id2); if(!I) return;
-	I->reset(); IdsForce v={id1,id2,force};
-	#ifdef YADE_OPENMP
-		threadsPendingErase[omp_get_thread_num()].push_back(v);
-	#else
-		pendingErase.push_back(v);
-	#endif
+	I->reset();
 }
 
 void InteractionContainer::requestErase(const shared_ptr<Interaction>& I){
@@ -134,41 +128,8 @@
 	I->reset();
 }
 
-void InteractionContainer::clearPendingErase(){
-	#ifdef YADE_OPENMP
-		FOREACH(list<IdsForce>& pendingErase, threadsPendingErase){
-			pendingErase.clear();
-		}
-	#else
-		pendingErase.clear();
-	#endif
-}
-
-int InteractionContainer::unconditionalErasePending(){
-	int ret=0;
-	#ifdef YADE_OPENMP
-		// shadow this->pendingErase by the local variable, to share code
-		FOREACH(list<IdsForce>& pendingErase, threadsPendingErase){
-	#endif
-			if(!pendingErase.empty()){
-				FOREACH(const IdsForce& p, pendingErase){ ret++; erase(p.id1,p.id2); }
-				pendingErase.clear();
-			}
-	#ifdef YADE_OPENMP
-		}
-	#endif
-	return ret;
-}
-
 void InteractionContainer::eraseNonReal(){
-	typedef pair<int,int> Ids;
-	std::list<Ids> ids;
-	FOREACH(const shared_ptr<Interaction>& i, *this){
-		if(!i->isReal()) ids.push_back(Ids(i->getId1(),i->getId2()));
-	}
-	FOREACH(const Ids& id, ids){
-		this->erase(id.first,id.second);
-	}
+	FOREACH(const shared_ptr<Interaction>& i, *this) if(!i->isReal()) this->erase(i->getId1(),i->getId2());
 }
 
 // compare interaction based on their first id

=== modified file 'core/InteractionContainer.hpp'
--- core/InteractionContainer.hpp	2012-01-23 14:43:54 +0000
+++ core/InteractionContainer.hpp	2014-02-03 11:21:42 +0000
@@ -65,9 +65,9 @@
 		// required by the class factory... :-|
 		InteractionContainer(): currSize(0),dirty(false),serializeSorted(false),iterColliderLastRun(-1){
 			bodies=NULL;
-			#ifdef YADE_OPENMP
-				threadsPendingErase.resize(omp_get_max_threads());
-			#endif
+// 			#ifdef YADE_OPENMP
+// 				threadsPendingErase.resize(omp_get_max_threads());
+// 			#endif
 		}
 		void clear();
 		// iterators
@@ -101,74 +101,23 @@
 		bool serializeSorted;
 		// iteration number when the collider was last run; set by the collider, if it wants interactions that were not encoutered in that step to be deleted by InteractionLoop (such as SpatialQuickSortCollider). Other colliders (such as InsertionSortCollider) set it it -1, which is the default
 		long iterColliderLastRun;
-		//! Ask for erasing the interaction given (from the constitutive law); this resets the interaction (to the initial=potential state) and collider should traverse pendingErase to decide whether to delete the interaction completely or keep it potential
-		void requestErase(Body::id_t id1, Body::id_t id2, bool force=false);
+		//! Ask for erasing the interaction given (from the constitutive law); this resets the interaction (to the initial=potential state) and collider should traverse potential interactions to decide whether to delete them completely or keep them potential
+		void requestErase(Body::id_t id1, Body::id_t id2);
 		void requestErase(const shared_ptr<Interaction>& I);
 		void requestErase(Interaction* I);
-		/*! List of pairs of interactions that will be (maybe) erased by the collider; if force==true, they will be deleted unconditionally.
-			
-			If accessed from within a parallel section, pendingEraseMutex must be locked (this is done inside requestErase for you).
-
-			If there is, at one point, a multi-threaded collider, pendingEraseMutex should be moved to the public part and used from there as well.
-		*/
-		struct IdsForce{ Body::id_t id1; Body::id_t id2; bool force; };
-		#ifdef YADE_OPENMP
-			vector<list<IdsForce> > threadsPendingErase;
-		#endif
-		list<IdsForce> pendingErase;
-		/*! Erase all pending interactions unconditionally.
-
-			This should be called only in rare cases that collider is not used but still interactions should be erased.
-			Otherwise collider should decide on a case-by-case basis, which interaction to erase for good and which to keep in the potential state
-			(without geom and phys).
-
-			This function doesn't lock pendingEraseMutex, as it is (supposedly) called from no-parallel sections only once per iteration
-		*/
-		int unconditionalErasePending();
-
-		/*! Clear the list of interaction pending erase: all interactions queued for considering erasing them
-		will be dropped; useful for colliders that handle that by themselves, without needing the hint;
-		with openMP, it would not be enough to call pendingErase->clear(), this helper function 
-		does it for all threads. Use this only if you understand this explanation. */
-		void clearPendingErase();
-
-		/*! Traverse all pending interactions and erase them if the (T*)->shouldBeErased(id1,id2) return true
-			and keep it if it return false; finally, pendingErase will be clear()'ed.
-
-			Class using this interface (which is presumably a collider) must define the 
-					
-				bool shouldBeErased(Body::id_t, Body::id_t) const
-
-			method which will be called for every interaction.
-
-			Returns number of interactions, have they been erased or not (this is useful to check if there were some erased, after traversing those)
-		*/
-		template<class T> int erasePending(const T& t, Scene* rb){
-			int ret=0;
-			#ifdef YADE_OPENMP
-				// shadow the this->pendingErase by the local variable, to share the code
-				FOREACH(list<IdsForce>& pendingErase, threadsPendingErase){
-			#endif
-					FOREACH(const IdsForce& p, pendingErase){
-						ret++;
-						if(p.force || t.shouldBeErased(p.id1,p.id2,rb)) erase(p.id1,p.id2);
-					}
-					pendingErase.clear();
-			#ifdef YADE_OPENMP
-				}
-			#endif
-			return ret;
-		}
+
 		/*! Traverse all interactions and erase them if they are not real and the (T*)->shouldBeErased(id1,id2) return true, or if body(id1) has been deleted
 			Class using this interface (which is presumably a collider) must define the
 				bool shouldBeErased(Body::id_t, Body::id_t) const
 		*/
-		template<class T> void conditionalyEraseNonReal(const T& t, Scene* rb){
+		template<class T> size_t conditionalyEraseNonReal(const T& t, Scene* rb){
 			// beware iterators here, since erase is invalidating them. We need to iterate carefully, and keep in mind that erasing one interaction is moving the last one to the current position.
+			size_t initSize=currSize;
 		 	for (size_t linPos=0; linPos<currSize;){
 				const shared_ptr<Interaction>& i=linIntrs[linPos];
 				if(!i->isReal() && t.shouldBeErased(i->getId1(),i->getId2(),rb)) erase(i->getId1(),i->getId2(),linPos);
 				else linPos++;}
+			return initSize-currSize;
 		}
 
 	// we must call Scene's ctor (and from Scene::postLoad), since we depend on the existing BodyContainer at that point.

=== modified file 'pkg/common/Cylinder.cpp'
--- pkg/common/Cylinder.cpp	2013-08-23 15:21:20 +0000
+++ pkg/common/Cylinder.cpp	2014-02-03 11:21:42 +0000
@@ -741,13 +741,13 @@
 
     if (currentContactPhysics->fragile && (-Fn)> currentContactPhysics->normalAdhesion) {
         // BREAK due to tension
-        scene->interactions->requestErase(contact->getId1(),contact->getId2());
+        scene->interactions->requestErase(contact);
     } else {
         if ((-Fn)> currentContactPhysics->normalAdhesion) {//normal plasticity
             Fn=-currentContactPhysics->normalAdhesion;
             currentContactPhysics->unp = un+currentContactPhysics->normalAdhesion/currentContactPhysics->kn;
             if (currentContactPhysics->unpMax && currentContactPhysics->unp<currentContactPhysics->unpMax)
-                scene->interactions->requestErase(contact->getId1(),contact->getId2());
+                scene->interactions->requestErase(contact);
         }
         currentContactPhysics->normalForce = Fn*geom->normal;
         Vector3r& shearForce = geom->rotate(currentContactPhysics->shearForce);
@@ -823,13 +823,13 @@
     
     if (currentContactPhysics->fragile && (-Fn)> currentContactPhysics->normalAdhesion) {
         // BREAK due to tension
-        scene->interactions->requestErase(contact->getId1(),contact->getId2());
+        scene->interactions->requestErase(contact);
     } else {
         if ((-Fn)> currentContactPhysics->normalAdhesion) {//normal plasticity
             Fn=-currentContactPhysics->normalAdhesion;
             currentContactPhysics->unp = un+currentContactPhysics->normalAdhesion/currentContactPhysics->kn;
             if (currentContactPhysics->unpMax && currentContactPhysics->unp<currentContactPhysics->unpMax)
-                scene->interactions->requestErase(contact->getId1(),contact->getId2());
+                scene->interactions->requestErase(contact);
         }
     
         

=== modified file 'pkg/common/Dispatching.cpp'
--- pkg/common/Dispatching.cpp	2012-01-30 20:53:49 +0000
+++ pkg/common/Dispatching.cpp	2014-02-03 11:21:42 +0000
@@ -93,11 +93,6 @@
 }
 
 void IGeomDispatcher::action(){
-	// Erase interaction that were requested for erase, but not processed by the collider, if any (and warn once about that, as it is suspicious)
-	if(scene->interactions->unconditionalErasePending()>0 && !alreadyWarnedNoCollider){
-		LOG_WARN("Interactions pending erase found, no collider being used?");
-		alreadyWarnedNoCollider=true;
-	}
 	updateScenePtr();
 
 	shared_ptr<BodyContainer>& bodies = scene->bodies;

=== modified file 'pkg/common/InteractionLoop.cpp'
--- pkg/common/InteractionLoop.cpp	2013-04-23 14:07:34 +0000
+++ pkg/common/InteractionLoop.cpp	2014-02-03 11:21:42 +0000
@@ -21,10 +21,10 @@
 
 
 void InteractionLoop::action(){
-	if(eraseIntsInLoop && scene->interactions->unconditionalErasePending()>0 && !alreadyWarnedNoCollider){
-		LOG_WARN("Interactions pending erase found (erased), no collider being used?");
-		alreadyWarnedNoCollider=true;
-	}
+// 	if(eraseIntsInLoop && scene->interactions->conditionalyEraseNonReal(scene)>0 && !alreadyWarnedNoCollider){
+// 		LOG_WARN("Interactions pending erase found (erased), no collider being used?");
+// 		alreadyWarnedNoCollider=true;
+// 	}
 	/*
 	if(scene->interactions->dirty){
 		throw std::logic_error("InteractionContainer::dirty is true; the collider should re-initialize in such case and clear the dirty flag.");

=== modified file 'pkg/common/SpatialQuickSortCollider.cpp'
--- pkg/common/SpatialQuickSortCollider.cpp	2012-02-29 19:07:56 +0000
+++ pkg/common/SpatialQuickSortCollider.cpp	2014-02-03 11:21:42 +0000
@@ -26,7 +26,7 @@
 
 	// 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.
-	scene->interactions->unconditionalErasePending();
+	scene->interactions->eraseNonReal();
 
 	size_t nbElements=bodies->size();
 	if (nbElements!=rank.size())

=== modified file 'pkg/dem/FlatGridCollider.cpp'
--- pkg/dem/FlatGridCollider.cpp	2010-11-07 11:46:20 +0000
+++ pkg/dem/FlatGridCollider.cpp	2014-02-03 11:21:42 +0000
@@ -11,7 +11,7 @@
 
 bool FlatGridCollider::isActivated(){
 	// keep interactions trequested for deletion as potential (forget removal requests)
-	scene->interactions->clearPendingErase();
+// 	scene->interactions->clearPendingErase();
 	if(!newton) return true;
 	// handle verlet distance
 	fastestBodyMaxDist+=sqrt(newton->maxVelocitySq)*scene->dt;

=== modified file 'pkg/dem/NormalInelasticityLaw.cpp'
--- pkg/dem/NormalInelasticityLaw.cpp	2012-01-23 14:43:54 +0000
+++ pkg/dem/NormalInelasticityLaw.cpp	2014-02-03 11:21:42 +0000
@@ -41,7 +41,7 @@
 // Check if there is a real overlap or not. The Ig2... seems to let exist interactions with negative un (= no overlap). Such interactions seem then to have to be deleted here.
         if (   un < 0      )
         {
-		 scene->interactions->requestErase(contact->getId1(),contact->getId2());// this, among other things, resets the interaction : geometry and physics variables (as forces, ...) are reset to defaut values
+		 scene->interactions->requestErase(contact);// this, among other things, resets the interaction : geometry and physics variables (as forces, ...) are reset to defaut values
 		 return;
         }