← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 3952: update of O.bodies.erase(): it can erase clump members too when erasing a clump

 

------------------------------------------------------------
revno: 3952
committer: Christian Jakob <jakob@xxxxxxxxxxxxxxxxxxx>
timestamp: Thu 2014-05-15 19:50:26 +0200
message:
  update of O.bodies.erase(): it can erase clump members too when erasing a clump
modified:
  core/BodyContainer.cpp
  core/BodyContainer.hpp
  pkg/dem/DomainLimiter.cpp
  py/wrapper/yadeWrapper.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/BodyContainer.cpp'
--- core/BodyContainer.cpp	2013-02-19 06:53:16 +0000
+++ core/BodyContainer.cpp	2014-05-15 17:50:26 +0000
@@ -49,27 +49,36 @@
 	return id;
 }
 
-bool BodyContainer::erase(Body::id_t id){
+bool BodyContainer::erase(Body::id_t id, bool eraseClumpMembers){//default is false (as before)
 	if(!exists(id)) return false;
 	lowestFree=min(lowestFree,id);
 	
-	const shared_ptr<Body>& b=Body::byId(id);   //If the body is the last member of clump, the clump should be removed as well
+	const shared_ptr<Body>& b=Body::byId(id);
+	
 	if ((b) and (b->isClumpMember())) {
 		const shared_ptr<Body>& clumpBody=Body::byId(b->clumpId);
 		const shared_ptr<Clump> clump=YADE_PTR_CAST<Clump>(clumpBody->shape);
 		Clump::del(clumpBody, b);
 		
-		if (clump->members.size()==0) {            //Clump has no members any more. Remove it
-			this->erase(b->clumpId);
+		if (clump->members.size()==0) this->erase(b->clumpId,false);	//Clump has no members any more. Remove it
+	}
+	
+	if ((b) and (b->isClump())){
+		//erase all members if eraseClumpMembers is true:
+		const shared_ptr<Clump>& clump=YADE_PTR_CAST<Clump>(b->shape);
+		std::map<Body::id_t,Se3r>& members = clump->members;
+		FOREACH(MemberMap::value_type& mm, members){
+			const Body::id_t& memberId=mm.first;
+			if (eraseClumpMembers) this->erase(memberId,false);	// erase members
+			//when the last members is erased, the clump will be erased automatically, see above
+			else Body::byId(memberId)->clumpId=Body::id_t(-1);	// make members standalones
 		}
 	}
-	
 	const shared_ptr<Scene>& scene=Omega::instance().getScene();
-	for(Body::MapId2IntrT::iterator it=b->intrs.begin(),end=b->intrs.end(); it!=end; ++it) {  //Iterate over all bodie's interactions
+	for(Body::MapId2IntrT::iterator it=b->intrs.begin(),end=b->intrs.end(); it!=end; ++it) {  //Iterate over all body's interactions
 		scene->interactions->requestErase((*it).second);
 	}
 	body[id]=shared_ptr<Body>();
 	
 	return true;
 }
-

=== modified file 'core/BodyContainer.hpp'
--- core/BodyContainer.hpp	2013-03-06 17:30:45 +0000
+++ core/BodyContainer.hpp	2014-05-15 17:50:26 +0000
@@ -34,6 +34,7 @@
 class BodyContainer: public Serializable{
 	private:
 		typedef std::vector<shared_ptr<Body> > ContainerT;
+		typedef std::map<Body::id_t,Se3r> MemberMap;
 		ContainerT body;
 		Body::id_t lowestFree;
 		Body::id_t findFreeId();
@@ -86,7 +87,7 @@
 		const shared_ptr<Body>& operator[](unsigned int id) const { return body[id]; }
 
 		bool exists(Body::id_t id) const { return (id>=0) && ((size_t)id<body.size()) && ((bool)body[id]); }
-		bool erase(Body::id_t id);
+		bool erase(Body::id_t id, bool eraseClumpMembers);
 		
 		REGISTER_CLASS_AND_BASE(BodyContainer,Serializable);
 		REGISTER_ATTRIBUTES(Serializable,(body));

=== modified file 'pkg/dem/DomainLimiter.cpp'
--- pkg/dem/DomainLimiter.cpp	2013-10-15 05:01:48 +0000
+++ pkg/dem/DomainLimiter.cpp	2014-05-15 17:50:26 +0000
@@ -23,7 +23,7 @@
 		}
 	}
 	FOREACH(Body::id_t id, out){
-		scene->bodies->erase(id);
+		scene->bodies->erase(id,false);
 	}
 }
 

=== modified file 'py/wrapper/yadeWrapper.cpp'
--- py/wrapper/yadeWrapper.cpp	2014-05-15 12:57:17 +0000
+++ py/wrapper/yadeWrapper.cpp	2014-05-15 17:50:26 +0000
@@ -190,7 +190,7 @@
 			else Clump::add(clp,bp);// bp must be a standalone!
 		}
 		Clump::updateProperties(clp, discretization);
-		FOREACH(Body::id_t bid, eraseList) proxee->erase(bid);//erase old clumps
+		FOREACH(Body::id_t bid, eraseList) proxee->erase(bid,false);//erase old clumps
 	}
 	void releaseFromClump(Body::id_t bid, Body::id_t cid, unsigned int discretization){
 		Scene* scene(Omega::instance().getScene().get());	// get scene
@@ -385,7 +385,7 @@
         #endif
 				Body::id_t newClumpId = clump(idsTmp, discretization);
 				ret.append(python::make_tuple(newClumpId,idsTmp));
-				erase(b->id);
+				erase(b->id,false);
 			}
 		}
 		return ret;
@@ -430,7 +430,7 @@
 	vector<Body::id_t> replace(vector<shared_ptr<Body> > bb){proxee->clear(); return appendList(bb);}
 	long length(){return proxee->size();}
 	void clear(){proxee->clear();}
-	bool erase(Body::id_t id){ return proxee->erase(id); }
+	bool erase(Body::id_t id, bool eraseClumpMembers){ return proxee->erase(id,eraseClumpMembers); }
 };
 
 
@@ -917,7 +917,7 @@
 		.def("replaceByClumps",&pyBodyContainer::replaceByClumps,(python::arg("discretization")=0),"Replace spheres by clumps using a list of clump templates and a list of amounts; returns a list of tuples: ``[(clumpId1,[memberId1,memberId2,...]),(clumpId2,[memberId1,memberId2,...]),...]``. A new clump will have the same volume as the sphere, that was replaced. Clump masses and inertia are adapted automatically (for details see :yref:`clump()<BodyContainer.clump>`). \n\n\t *O.bodies.replaceByClumps( [utils.clumpTemplate([1,1],[.5,.5])] , [.9] ) #will replace 90 % of all standalone spheres by 'dyads'*\n\nSee :ysrc:`examples/clumps/replaceByClumps-example.py` for an example script.")
 		.def("getRoundness",&pyBodyContainer::getRoundness,(python::arg("excludeList")=python::list()),"Returns roundness coefficient RC = R2/R1. R1 is the theoretical radius of a sphere, with same volume as clump. R2 is the minimum radius of a sphere, that imbeds clump. If just spheres are present RC = 1. If clumps are present 0 < RC < 1. Bodies can be excluded from the calculation by giving a list of ids: *O.bodies.getRoundness([ids])*.\n\nSee :ysrc:`examples/clumps/replaceByClumps-example.py` for an example script.")
 		.def("clear", &pyBodyContainer::clear,"Remove all bodies (interactions not checked)")
-		.def("erase", &pyBodyContainer::erase,"Erase body with the given id; all interaction will be deleted by InteractionLoop in the next step.")
+		.def("erase", &pyBodyContainer::erase,(python::arg("eraseClumpMembers")=0),"Erase body with the given id; all interaction will be deleted by InteractionLoop in the next step. If a clump is erased use *O.bodies.erase(clumpId,True)* to erase the clump AND its members.")
 		.def("replace",&pyBodyContainer::replace);
 	python::class_<pyBodyIterator>("BodyIterator",python::init<pyBodyIterator&>())
 		.def("__iter__",&pyBodyIterator::pyIter)