Commit 3254c554 authored by Václav Šmilauer's avatar Václav Šmilauer

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.
parent 5a16cd77
......@@ -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;
}
}
......
......@@ -53,8 +53,10 @@ class ThreadRunner
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 @@ class ThreadRunner
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;
};
......@@ -25,8 +25,8 @@ void Bo1_Sphere_Aabb::go(const shared_ptr<Shape>& cm, shared_ptr<Bound>& bv, con
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;
......
......@@ -429,8 +429,9 @@ bool InsertionSortCollider::spatialOverlapPeri(body_id_t id1, body_id_t id2,Scen
/* 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);
......
......@@ -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 @@ class pyOmega{
}
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);
......
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=yade.qt.Renderer()
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment