← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2642: 1. Better integration of NewtonIntegrator into Clump, avoiding linking cycle with chunkSize=1

 

------------------------------------------------------------
revno: 2642
committer: Václav Šmilauer <eu@xxxxxxxx>
branch nick: yade
timestamp: Mon 2011-01-10 09:35:00 +0100
message:
  1. Better integration of NewtonIntegrator into Clump, avoiding linking cycle with chunkSize=1
modified:
  pkg/dem/Clump.cpp
  pkg/dem/Clump.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 'pkg/dem/Clump.cpp'
--- pkg/dem/Clump.cpp	2011-01-09 16:34:50 +0000
+++ pkg/dem/Clump.cpp	2011-01-10 08:35:00 +0000
@@ -6,9 +6,6 @@
 #include<yade/core/BodyContainer.hpp>
 #include<yade/core/State.hpp>
 
-// to save maxima velocity, when moving clump members
-#include<yade/pkg/dem/NewtonIntegrator.hpp>
-
 
 YADE_PLUGIN((Clump));
 CREATE_LOGGER(Clump);
@@ -42,22 +39,6 @@
 	LOG_DEBUG("Removed body #"<<subBody->id<<" from clump #"<<clumpBody->id);
 }
 
-void Clump::moveMembers(const shared_ptr<Body>& clumpBody, Scene* scene, NewtonIntegrator* newton){
-	const shared_ptr<Clump>& clump=YADE_PTR_CAST<Clump>(clumpBody->shape);
-	const shared_ptr<State>& clumpState=clumpBody->state;
-	FOREACH(MemberMap::value_type& B, clump->members){
-		// B.first is Body::id_t, B.second is local Se3r of that body in the clump
-		const shared_ptr<State>& subState=Body::byId(B.first,scene)->state; const Vector3r& subPos(B.second.position); const Quaternionr& subOri(B.second.orientation);
-		// position update
-		subState->pos=clumpState->pos+clumpState->ori*subPos;
-		subState->ori=clumpState->ori*subOri;
-		// velocity update
-		subState->vel=clumpState->vel+clumpState->angVel.cross(subState->pos-clumpState->pos);
-		subState->angVel=clumpState->angVel;
-		if(likely(newton)) newton->saveMaximaVelocity(B.first,subState.get());
-	}
-}
-
 void Clump::addForceTorqueFromMembers(const State* clumpState, Scene* scene, Vector3r& F, Vector3r& T){
 	FOREACH(const MemberMap::value_type& mm, members){
 		const Body::id_t& memberId=mm.first; const shared_ptr<Body>& member=Body::byId(memberId,scene); assert(member->isClumpMember()); State* memberState=member->state.get();

=== modified file 'pkg/dem/Clump.hpp'
--- pkg/dem/Clump.hpp	2011-01-09 16:34:50 +0000
+++ pkg/dem/Clump.hpp	2011-01-10 08:35:00 +0000
@@ -63,7 +63,25 @@
 		//! Recalculate physical properties of Clump.
 		static void updateProperties(const shared_ptr<Body>& clump, bool intersecting);
 		//! Calculate positions and orientations of members based on relative Se3; newton pointer (if non-NULL) calls NewtonIntegrator::saveMaximaVelocity
-		static void moveMembers(const shared_ptr<Body>& clump, Scene* scene, NewtonIntegrator* newton=NULL);
+		// done as template to avoid cross-dependency between clump and newton (not necessary if all plugins are linked together)
+		template<class IntegratorT>
+		static void moveMembers(const shared_ptr<Body>& clumpBody, Scene* scene, IntegratorT* integrator=NULL){
+			const shared_ptr<Clump>& clump=YADE_PTR_CAST<Clump>(clumpBody->shape);
+			const shared_ptr<State>& clumpState=clumpBody->state;
+			FOREACH(MemberMap::value_type& B, clump->members){
+				// B.first is Body::id_t, B.second is local Se3r of that body in the clump
+				const shared_ptr<State>& subState=Body::byId(B.first,scene)->state; const Vector3r& subPos(B.second.position); const Quaternionr& subOri(B.second.orientation);
+				// position update
+				subState->pos=clumpState->pos+clumpState->ori*subPos;
+				subState->ori=clumpState->ori*subOri;
+				// velocity update
+				subState->vel=clumpState->vel+clumpState->angVel.cross(subState->pos-clumpState->pos);
+				subState->angVel=clumpState->angVel;
+				if(likely(integrator)) integrator->saveMaximaVelocity(B.first,subState.get());
+			}
+		}
+
+
 		//! update member positions after clump being moved by mouse (in case simulation is paused and engines will not do that).
 		void userForcedDisplacementRedrawHook(){ throw runtime_error("Clump::userForcedDisplacementRedrawHook not yet implemented (with Clump as subclass of Shape).");}