← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 4086: Disable reusing of removed body ids.

 

------------------------------------------------------------
revno: 4086
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
timestamp: Thu 2014-07-17 08:34:00 +0200
message:
  Disable reusing of removed body ids.
  
  Some change in BodyContainer. Previously the ids of removed
  bodies could be reused by newly created particles. It caused
  some problems, for instance, by saving in VTK file and building
  pathlines of them in ParaView.
  
  Also it could lead to some unexpected behaviour during intensive
  removal/adding particles.
modified:
  core/BodyContainer.cpp
  core/BodyContainer.hpp


--
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	2014-07-02 16:11:24 +0000
+++ core/BodyContainer.cpp	2014-07-17 06:34:00 +0000
@@ -10,51 +10,25 @@
 
 
 CREATE_LOGGER(BodyContainer);
- 
-BodyContainer::BodyContainer(): lowestFree(0)
-{}
-
-
-BodyContainer::~BodyContainer(){}
 
 void BodyContainer::clear(){
-	body.clear(); lowestFree=0;
-}
-
-Body::id_t BodyContainer::findFreeId(){
-	Body::id_t max=body.size();
-	for(; lowestFree<max; lowestFree++){
-		if(!(bool)body[lowestFree]) return lowestFree;
-	}
-	return body.size();
+	body.clear();
 }
 
 Body::id_t BodyContainer::insert(shared_ptr<Body>& b){
-	Body::id_t newId=findFreeId();
-	return insert(b,newId);
-}
-
-Body::id_t BodyContainer::insert(shared_ptr<Body>& b, Body::id_t id){
-	assert(id>=0);
-	if((size_t)id>=body.size()) body.resize(id+1);
-	
 	const shared_ptr<Scene>& scene=Omega::instance().getScene(); 
 	b->iterBorn=scene->iter;
 	b->timeBorn=scene->time;
-	b->id=id;
-	
+	b->id=body.size();
 	scene->doSort = true;
-	
-	body[id]=b;
-
+	body.push_back(b);
 	// Notify ForceContainer about new id
-	scene->forces.addMaxId(id);
-	return id;
+	scene->forces.addMaxId(b->id);
+	return b->id;
 }
 
 bool BodyContainer::erase(Body::id_t id, bool eraseClumpMembers){//default is false (as before)
-	if(!exists(id)) return false;
-	lowestFree=min(lowestFree,id);
+	if(!body[id]) return false;
 	
 	const shared_ptr<Body>& b=Body::byId(id);
 	
@@ -81,7 +55,7 @@
 	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>();
+	body[id]=nullptr;
 	
 	return true;
 }

=== modified file 'core/BodyContainer.hpp'
--- core/BodyContainer.hpp	2014-07-03 17:20:40 +0000
+++ core/BodyContainer.hpp	2014-07-17 06:34:00 +0000
@@ -30,8 +30,6 @@
 		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();
 	public:
 		friend class InteractionContainer;  // accesses the body vector directly
 		
@@ -50,25 +48,13 @@
 			smart_iterator(const ContainerT::iterator& source) {(*this)=source;}
 			smart_iterator(const smart_iterator& source) {(*this)=source; end=source.end;}
 		};
-
-// 		typedef ContainerT::iterator iterator;
-// 		typedef ContainerT::const_iterator const_iterator;
 		typedef smart_iterator iterator;
 		typedef const smart_iterator const_iterator;
 
-		BodyContainer();
-		virtual ~BodyContainer();
+		BodyContainer() {};
+		virtual ~BodyContainer() {};
 		Body::id_t insert(shared_ptr<Body>&);
-		Body::id_t insert(shared_ptr<Body>& b, Body::id_t id);
-	
-		// mimick some STL api
 		void clear();
-		// by using simple vector<>::iterator's, we can hit null bodies 
-// 		iterator begin() { return body.begin(); }
-// 		iterator end() { return body.end(); }
-// 		const_iterator begin() const { return body.begin(); }
-// 		const_iterator end() const { return body.end(); }
-// 		//with smart iterators
 		iterator begin() {
 			iterator temp(body.begin()); temp.end=body.end();
 			return (body.begin()==body.end() || *temp)?temp:++temp;}


Follow ups