← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 1931: 1. Re-enable error check in InsertionSortCollider, make the explanation clearer

 

------------------------------------------------------------
revno: 1931
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Wed 2009-12-30 21:10:59 +0100
message:
  1. Re-enable error check in InsertionSortCollider, make the explanation clearer
  2. Fix sphere's Aabb (hopefully) (Bruno, could you check that?)
  3. Worker thread now catches exception from simulation and O.wait() (or O.run()) will rethrow it; avoids crashes from exceptions.
modified:
  core/ThreadRunner.cpp
  core/ThreadRunner.hpp
  pkg/common/Engine/Functor/Bo1_Sphere_Aabb.cpp
  pkg/common/Engine/GlobalEngine/InsertionSortCollider.cpp
  py/yadeWrapper/yadeWrapper.cpp
  scripts/test/periodic-shear.py


--
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/ThreadRunner.cpp'
--- core/ThreadRunner.cpp	2008-07-21 12:12:23 +0000
+++ core/ThreadRunner.cpp	2009-12-30 20:10:59 +0000
@@ -15,13 +15,22 @@
 
 #include<iostream>
 
+CREATE_LOGGER(ThreadRunner);
+
 void ThreadRunner::run()
 {
 	// this is the body of execution of separate thread
 	boost::mutex::scoped_lock lock(m_runmutex);
-	while(looping()) {
-		call();
-		if(m_thread_worker->shouldTerminate()){ stop(); return; }
+	try{
+		workerThrew=false;
+		while(looping()) {
+			call();
+			if(m_thread_worker->shouldTerminate()){ stop(); return; }
+		}
+	} catch (std::exception& e){
+		LOG_FATAL("Exception occured: "<<endl<<e.what());
+		workerException=std::exception(e); workerThrew=true;
+		stop(); return;
 	}
 }
 

=== modified file 'core/ThreadRunner.hpp'
--- core/ThreadRunner.hpp	2009-01-27 02:19:40 +0000
+++ core/ThreadRunner.hpp	2009-12-30 20:10:59 +0000
@@ -53,8 +53,10 @@
 		void		run();
 		void		call();
 
+		DECLARE_LOGGER;
+
 	public :
-		ThreadRunner(ThreadWorker* c) : m_thread_worker(c), m_looping(false) {};
+		ThreadRunner(ThreadWorker* c) : m_thread_worker(c), m_looping(false), workerThrew(false) {};
 		~ThreadRunner();
 
 		/// perform ThreadWorker::singleAction() in separate thread
@@ -67,6 +69,10 @@
 		void pleaseTerminate();
 		/// precondition for the loop started with start().
 		bool looping();
+		//! if true, workerException is copy of the exception thrown by the worker
+		bool workerThrew;
+		//! last exception thrown by the worker, if any
+		std::exception workerException;
 };
 
 

=== modified file 'pkg/common/Engine/Functor/Bo1_Sphere_Aabb.cpp'
--- pkg/common/Engine/Functor/Bo1_Sphere_Aabb.cpp	2009-12-30 17:38:37 +0000
+++ pkg/common/Engine/Functor/Bo1_Sphere_Aabb.cpp	2009-12-30 20:10:59 +0000
@@ -25,8 +25,8 @@
 		for(int i=0; i<3; i++){
 			//cerr<<"cos["<<i<<"]"<<cos[i]<<" ";
 			int i1=(i+1)%3,i2=(i+2)%3;
-			halfSize[i1]+=refHalfSize[i1]*(1/cos[i]-1);
-			halfSize[i2]+=refHalfSize[i2]*(1/cos[i]-1);
+			halfSize[i1]+=.5*refHalfSize[i1]*(1/cos[i]-1);
+			halfSize[i2]+=.5*refHalfSize[i2]*(1/cos[i]-1);
 		}
 	}
 	//cerr<<" || "<<halfSize<<endl;

=== modified file 'pkg/common/Engine/GlobalEngine/InsertionSortCollider.cpp'
--- pkg/common/Engine/GlobalEngine/InsertionSortCollider.cpp	2009-12-30 17:38:37 +0000
+++ pkg/common/Engine/GlobalEngine/InsertionSortCollider.cpp	2009-12-30 20:10:59 +0000
@@ -429,8 +429,9 @@
 		/* FIXME: condition temporary disabled
 			if wMn==m1 and minima[id2]<m1, then it might give spurious error; why should it be error, though?
 		*/
-		if(false && ((pmn1!=pmx1) || (pmn2!=pmx2))){
-			LOG_FATAL("Body #"<<(pmn1!=pmx1?id1:id2)<<" spans over half of the cell size "<<dim<<" (axis="<<axis<<", min="<<(pmn1!=pmx1?mn1:mn2)<<", max="<<(pmn1!=mn1?mx1:mx2)<<")");
+		if(((pmn1!=pmx1) || (pmn2!=pmx2))){
+			Real span=(pmn1!=pmx1?mx1-mn1:mx2-mn2); if(span<0) span=dim-span;
+			LOG_FATAL("Body #"<<(pmn1!=pmx1?id1:id2)<<" spans over half of the cell size "<<dim<<" (axis="<<axis<<", min="<<(pmn1!=pmx1?mn1:mn2)<<", max="<<(pmn1!=pmx1?mx1:mx2)<<", span="<<span<<")");
 			throw runtime_error(__FILE__ ": Body larger than half of the cell size encountered.");
 		}
 		periods[axis]=(int)(pmn1-pmn2);

=== modified file 'py/yadeWrapper/yadeWrapper.cpp'
--- py/yadeWrapper/yadeWrapper.cpp	2009-12-30 15:45:32 +0000
+++ py/yadeWrapper/yadeWrapper.cpp	2009-12-30 20:10:59 +0000
@@ -26,6 +26,7 @@
 #include<yade/lib-base/Logging.hpp>
 #include<yade/lib-serialization-xml/XMLFormatManager.hpp>
 #include<yade/core/Omega.hpp>
+#include<yade/core/ThreadRunner.hpp>
 #include<yade/core/FileGenerator.hpp>
 
 #include<yade/pkg-dem/STLImporter.hpp>
@@ -35,7 +36,6 @@
 #include<yade/core/PartialEngine.hpp>
 #include<yade/core/Functor.hpp>
 #include<yade/pkg-common/ParallelEngine.hpp>
-#include<yade/core/Functor.hpp>
 
 #include<yade/pkg-common/BoundDispatcher.hpp>
 #include<yade/pkg-common/InteractionGeometryDispatcher.hpp>
@@ -376,8 +376,12 @@
 	}
 	void pause(){Py_BEGIN_ALLOW_THREADS; OMEGA.stopSimulationLoop(); Py_END_ALLOW_THREADS; LOG_DEBUG("PAUSE!");}
 	void step() { if(OMEGA.isRunning()) throw runtime_error("Called O.step() while simulation is running."); OMEGA.getScene()->moveToNextTimeStep(); /* LOG_DEBUG("STEP!"); run(1); wait(); */ }
-	void wait(){ if(OMEGA.isRunning()){LOG_DEBUG("WAIT!");} else return; timespec t1,t2; t1.tv_sec=0; t1.tv_nsec=40000000; /* 40 ms */ Py_BEGIN_ALLOW_THREADS; while(OMEGA.isRunning()) nanosleep(&t1,&t2); Py_END_ALLOW_THREADS; }
-
+	void wait(){
+		if(OMEGA.isRunning()){LOG_DEBUG("WAIT!");} else return;
+		timespec t1,t2; t1.tv_sec=0; t1.tv_nsec=40000000; /* 40 ms */ Py_BEGIN_ALLOW_THREADS; while(OMEGA.isRunning()) nanosleep(&t1,&t2); Py_END_ALLOW_THREADS;
+		if(!OMEGA.simulationLoop->workerThrew) return;
+		LOG_ERROR("Simulation error encountered."); OMEGA.simulationLoop->workerThrew=false; throw OMEGA.simulationLoop->workerException;
+	}
 	void load(std::string fileName) {
 		Py_BEGIN_ALLOW_THREADS; OMEGA.joinSimulationLoop(); Py_END_ALLOW_THREADS; 
 		OMEGA.setSimulationFileName(fileName);

=== modified file 'scripts/test/periodic-shear.py'
--- scripts/test/periodic-shear.py	2009-12-30 17:38:37 +0000
+++ scripts/test/periodic-shear.py	2009-12-30 20:10:59 +0000
@@ -1,5 +1,5 @@
 O.periodic=True
-O.cell.refSize=Vector3(.5,.5,.5)
+O.cell.refSize=Vector3(.55,.55,.55)
 O.bodies.append(utils.facet([[.4,.0001,.3],[.2,.0001,.3],[.3,.2,.2]]))
 O.bodies.append(utils.sphere([.3,.1,.4],.05,dynamic=True))
 O.bodies.append(utils.sphere([.200001,.2000001,.4],.05,dynamic=False))
@@ -36,9 +36,9 @@
 rdr['intrAllWire']=True
 #from yade import log
 #import yade.qt,time
-v=yade.qt.View()
-v.axes=True
-v.grid=(True,True,True)
+#v=yade.qt.View()
+#v.axes=True
+#v.grid=(True,True,True)
 
 from yade import log
 #log.setLevel('Shop',log.TRACE)