← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 1914: 1. Fix weird behavior reported by Luc at https://lists.launchpad.net/yade-dev/msg02794.html (nume...

 

------------------------------------------------------------
revno: 1914
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Mon 2009-12-21 23:19:11 +0100
message:
  1. Fix weird behavior reported by Luc at https://lists.launchpad.net/yade-dev/msg02794.html (numerical issue)
  2. Fix crash at body selection (wrong dispatcher arguments)
  3. Add warnings about what Luc observed, should it happen again.
modified:
  core/Collider.cpp
  core/Scene.cpp
  pkg/common/Engine/Dispatcher/InteractionDispatchers.cpp
  pkg/common/Engine/Dispatcher/LawDispatcher.cpp
  pkg/common/Engine/Dispatcher/LawDispatcher.hpp
  pkg/common/RenderingEngine/OpenGLRenderingEngine.cpp
  pkg/dem/DataClass/InteractionGeometry/Dem3DofGeom_FacetSphere.cpp


--
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/Collider.cpp'
--- core/Collider.cpp	2009-12-11 07:27:29 +0000
+++ core/Collider.cpp	2009-12-21 22:19:11 +0000
@@ -39,6 +39,8 @@
 }
 bool Collider::mayCollide(const Body* b1, const Body* b2){
 	return 
+		// might be called with deleted bodies, i.e. NULL pointers
+		(b1!=NULL && b2!=NULL) &&
 		// only collide if at least one particle is standalone or they belong to different clumps
 		(b1->isStandalone() || b2->isStandalone() || b1->clumpId!=b2->clumpId ) &&
 		 // do not collide clumps, since they are just containers, never interact

=== modified file 'core/Scene.cpp'
--- core/Scene.cpp	2009-12-20 22:03:17 +0000
+++ core/Scene.cpp	2009-12-21 22:19:11 +0000
@@ -64,6 +64,7 @@
 void Scene::postProcessAttributes(bool deserializing){
 	/* since yade::serialization doesn't properly handle shared pointers, iterate over all bodies and make materials shared again, if id>=0 */
 	FOREACH(const shared_ptr<Body>& b, *bodies){
+		if(!b) continue; // erased body
 		if(!b->material || b->material->id<0) continue; // not a shared material
 		assert(b->material->id < (int)materials.size());
 		b->material=materials[b->material->id];

=== modified file 'pkg/common/Engine/Dispatcher/InteractionDispatchers.cpp'
--- pkg/common/Engine/Dispatcher/InteractionDispatchers.cpp	2009-12-20 22:03:17 +0000
+++ pkg/common/Engine/Dispatcher/InteractionDispatchers.cpp	2009-12-21 22:19:11 +0000
@@ -146,6 +146,7 @@
 			physDispatcher->operator()(Body::byId(I->getId1(),scene)->material, Body::byId(I->getId2(),scene)->material,I);
 			// LawDispatcher
 			lawDispatcher->operator()(I->interactionGeometry,I->interactionPhysics,I.get(),scene);
+			if(!I->isReal() && I->isFresn(scene)) LOG_WARN("Law functor deleted interaction that was just created. Please report bug: either this message is spurious, or the functor (or something else) is buggy.");
 		#endif
 		}
 }

=== modified file 'pkg/common/Engine/Dispatcher/LawDispatcher.cpp'
--- pkg/common/Engine/Dispatcher/LawDispatcher.cpp	2009-12-09 16:43:25 +0000
+++ pkg/common/Engine/Dispatcher/LawDispatcher.cpp	2009-12-21 22:19:11 +0000
@@ -1,6 +1,7 @@
 // 2009 © Václav Šmilauer <eudoxos@xxxxxxxx>
 #include "LawDispatcher.hpp"
 YADE_PLUGIN((LawDispatcher));
+CREATE_LOGGER(LawDispatcher);
 void LawDispatcher::action(Scene*){
 	updateScenePtr();
 	#ifdef YADE_OPENMP
@@ -14,6 +15,7 @@
 		if(I->isReal()){
 			assert(I->interactionGeometry); assert(I->interactionPhysics);
 			operator()(I->interactionGeometry,I->interactionPhysics,I.get(),scene);
+			if(!I->isReal() && I->isFresh(scene)) LOG_ERROR("Law functor deleted interaction that was just created. Please report bug: either this message is spurious, or the functor (or something else) is buggy.");
 		}
 	}
 }

=== modified file 'pkg/common/Engine/Dispatcher/LawDispatcher.hpp'
--- pkg/common/Engine/Dispatcher/LawDispatcher.hpp	2009-12-04 23:07:34 +0000
+++ pkg/common/Engine/Dispatcher/LawDispatcher.hpp	2009-12-21 22:19:11 +0000
@@ -17,6 +17,7 @@
 		public:
 		virtual void action(Scene*);
 		REGISTER_CLASS_AND_BASE(LawDispatcher,Dispatcher2D);
+		DECLARE_LOGGER;
 };
 REGISTER_SERIALIZABLE(LawDispatcher);
 

=== modified file 'pkg/common/RenderingEngine/OpenGLRenderingEngine.cpp'
--- pkg/common/RenderingEngine/OpenGLRenderingEngine.cpp	2009-12-20 22:03:17 +0000
+++ pkg/common/RenderingEngine/OpenGLRenderingEngine.cpp	2009-12-21 22:19:11 +0000
@@ -95,7 +95,7 @@
 		glRotatef(angle*Mathr::RAD_TO_DEG,axis[0],axis[1],axis[2]);
 		//if(b->shape->getClassName() != "LineSegment"){ // FIXME: a body needs to say: I am selectable ?!?!
 			glPushName(b->getId());
-			shapeDispatcher(b->shape,b->state,Body_wire || b->shape->wire);
+			shapeDispatcher(b->shape,b->state,Body_wire || b->shape->wire,viewInfo);
 			glPopName();
 		//}
 		glPopMatrix();

=== modified file 'pkg/dem/DataClass/InteractionGeometry/Dem3DofGeom_FacetSphere.cpp'
--- pkg/dem/DataClass/InteractionGeometry/Dem3DofGeom_FacetSphere.cpp	2009-12-13 20:30:13 +0000
+++ pkg/dem/DataClass/InteractionGeometry/Dem3DofGeom_FacetSphere.cpp	2009-12-21 22:19:11 +0000
@@ -51,7 +51,7 @@
 			The FACET_TOPO thing is still missing here but can be copied literally once it is tested */
 		// begin facet-local coordinates
 			Vector3r cogLine=state1.ori.Conjugate()*(state2.pos+shift2-state1.pos); // connect centers of gravity
-			//TRVAR4(se31.position,se31.orientation,se32.position,cogLine);
+			//TRVAR4(state1.pos,state1.ori,state2.pos,cogLine);
 			Vector3r normal=facet->nf;
 			Real planeDist=normal.Dot(cogLine);
 			if(planeDist<0){normal*=-1; planeDist*=-1; }
@@ -139,15 +139,24 @@
 
 	if(penetrationDepth<0 && !c->isReal()) return false;
 
+
 	shared_ptr<Dem3DofGeom_FacetSphere> fs;
 	Vector3r normalGlob=state1.ori*normal;
+	bool isNew=false;
 	if(c->interactionGeometry) fs=YADE_PTR_CAST<Dem3DofGeom_FacetSphere>(c->interactionGeometry);
 	else {
+		isNew=true;
 		fs=shared_ptr<Dem3DofGeom_FacetSphere>(new Dem3DofGeom_FacetSphere());
 		c->interactionGeometry=fs;
 		fs->effR2=sphereRadius-penetrationDepth;
 		fs->refR1=-1; fs->refR2=sphereRadius;
-		fs->refLength=fs->effR2;
+		// postponed till below, to avoid numeric issues
+		// see https://lists.launchpad.net/yade-dev/msg02794.html
+		// since displacementN() is computed from fs->contactPoint,
+		// it was returning something like +1e-16 at the very first step
+		// when it was created ⇒ the constitutive law was erasing the
+		// contact as soon as it was created.
+		//fs->refLength=fs->effR2;
 		fs->cp1pt=contactPt; // facet-local intial contact point
 		fs->localFacetNormal=facet->nf;
 		fs->cp2rel.Align(Vector3r::UNIT_X,state2.ori.Conjugate()*(-normalGlob)); // initial sphere-local center-contactPt orientation WRT +x
@@ -155,7 +164,11 @@
 	}
 	fs->se31=state1.se3; fs->se32=state2.se3; fs->se32.position+=shift2;
 	fs->normal=normalGlob;
-	fs->contactPoint=state2.pos+shift2+(-normalGlob)*(sphereRadius-penetrationDepth);
+	fs->contactPoint=state2.pos+shift2+(-normalGlob)*fs->effR2;
+	// this refLength computation mimics what displacementN() does inside
+	// displcementN will therefore return exactly zero at the step the contact
+	// was created, which is what we want
+	if(isNew) fs->refLength=(state2.pos+shift2-fs->contactPoint).Length();
 	return true;
 }