← Back to team overview

yade-dev team mailing list archive

[svn] r1658 - in trunk: core gui/py gui/qt3 pkg/common/Engine/DeusExMachina pkg/dem/Engine/EngineUnit

 

Author: eudoxos
Date: 2009-02-06 21:46:33 +0100 (Fri, 06 Feb 2009)
New Revision: 1658

Modified:
   trunk/core/yade.cpp
   trunk/gui/py/_eudoxos.cpp
   trunk/gui/py/_utils.cpp
   trunk/gui/py/utils.py
   trunk/gui/qt3/GLViewer.cpp
   trunk/gui/qt3/QtGUI-python.cpp
   trunk/gui/qt3/QtSimulationPlayer.cpp
   trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp
   trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp
   trunk/pkg/dem/Engine/EngineUnit/InteractingFacet2InteractingSphere4SpheresContactGeometry.cpp
Log:
1. Beautify no-debug code in main
2. SpiralEngine now saves angle it has turned so far
3. Remove failing assertion from IFacet2ISphere4SCG?\194?\160(why it fails? it was a (I->isReal&&I->interactionGeometry)||(!I->isReal&&!I->interactionGeometry)...)
4. Improve the utils.spiralproject function to specify period (moderately tested, but seems to work)
5. Adjust locks in GLViewer. Fixes my crashes on nvidia for both player and 3d view (didn't dare to try 2nd view). Next step will be to move this lock to Omega and lock it when loading/resetting simulation etc.
6. Change theora video quality to 63 (maximum) instead of medium 32 in utils.encodeVideoFromFrames. Makes the video about 3x bigger.



Modified: trunk/core/yade.cpp
===================================================================
--- trunk/core/yade.cpp	2009-02-04 21:45:01 UTC (rev 1657)
+++ trunk/core/yade.cpp	2009-02-06 20:46:33 UTC (rev 1658)
@@ -31,8 +31,6 @@
 
 using namespace std;
 
-bool dontUseGdb(false);
-
 #ifdef LOG4CXX
 	// provides parent logger for everybody
 	log4cxx::LoggerPtr logger=log4cxx::Logger::getLogger("yade");
@@ -61,8 +59,7 @@
 		case SIGSEGV:
 			signal(SIGSEGV,SIG_DFL); signal(SIGABRT,SIG_DFL); // prevent loops - default handlers
 			cerr<<"SIGSEGV/SIGABRT handler called; gdb batch file is `"<<Omega::instance().gdbCrashBatch<<"'"<<endl;
-			if(!dontUseGdb)
-				std::system((string("gdb -x ")+Omega::instance().gdbCrashBatch).c_str());
+			std::system((string("gdb -x ")+Omega::instance().gdbCrashBatch).c_str());
 			unlink(Omega::instance().gdbCrashBatch.c_str()); // delete the crash batch file
 			raise(sig); // reemit signal after exiting gdb
 			break;
@@ -152,6 +149,8 @@
 	filesystem::path::default_name_check(filesystem::native);
 
 	string configPath=string(getenv("HOME")) + "/.yade" SUFFIX; // this is the default, may be overridden by -c / -C
+
+	bool useGdb=true;
 	
 	int ch; string gui=""; string simulationFileName=""; bool setup=false; int verbose=0; bool coreOptions=true; bool explicitUI=false;
 	while(coreOptions && (ch=getopt(argc,argv,"hnN:wC:cxvS:"))!=-1)
@@ -162,7 +161,7 @@
 			case 'w': setup=true; break;
 			case 'C': configPath=optarg; break;
 			case 'c': configPath="."; break;
-			case 'x': dontUseGdb=true; break;
+			case 'x': useGdb=false; break;
 			case 'v': verbose+=1; break;
 			case 'S': simulationFileName=optarg; break;
 			case '-': coreOptions=false; break;
@@ -221,13 +220,15 @@
 	}
 
 	#ifdef YADE_DEBUG
-		// postponed until the config dir has been created
-		ofstream gdbBatch;
-		Omega::instance().gdbCrashBatch=(yadeConfigPath/"gdb_crash_batch-pid").string()+lexical_cast<string>(getpid());
-		gdbBatch.open(Omega::instance().gdbCrashBatch.c_str()); gdbBatch<<"attach "<<lexical_cast<string>(getpid())<<"\nset pagination off\nthread info\nthread apply all backtrace\ndetach\nquit\n"; gdbBatch.close();
-		signal(SIGABRT,sigHandler);
-		signal(SIGSEGV,sigHandler);
-		LOG_DEBUG("ABRT/SEGV signal handlers set, crash batch created as "<<Omega::instance().gdbCrashBatch);
+		if(useGdb){
+			// postponed until the config dir has been created
+			ofstream gdbBatch;
+			Omega::instance().gdbCrashBatch=(yadeConfigPath/"gdb_crash_batch-pid").string()+lexical_cast<string>(getpid());
+			gdbBatch.open(Omega::instance().gdbCrashBatch.c_str()); gdbBatch<<"attach "<<lexical_cast<string>(getpid())<<"\nset pagination off\nthread info\nthread apply all backtrace\ndetach\nquit\n"; gdbBatch.close();
+			signal(SIGABRT,sigHandler);
+			signal(SIGSEGV,sigHandler);
+			LOG_DEBUG("ABRT/SEGV signal handlers set, crash batch created as "<<Omega::instance().gdbCrashBatch);
+		}
 	#endif
 	
 	LOG_INFO("Loading "<<yadeConfigFile.string()); IOFormatManager::loadFromFile("XMLFormatManager",yadeConfigFile.string(),"preferences",Omega::instance().preferences);
@@ -270,9 +271,11 @@
 		// Py_Finalize();
 	#endif
 	#ifdef YADE_DEBUG
-		signal(SIGABRT,SIG_DFL); signal(SIGHUP,SIG_DFL); // default handlers
-		signal(SIGSEGV,warnOnceHandler); // FIXME: this is to cover up crash that occurs in log4cxx on i386 sometimes 
-		unlink(Omega::instance().gdbCrashBatch.c_str());
+		if(useGdb){
+			signal(SIGABRT,SIG_DFL); signal(SIGHUP,SIG_DFL); // default handlers
+			signal(SIGSEGV,warnOnceHandler); // FIXME: this is to cover up crash that occurs in log4cxx on i386 sometimes 
+			unlink(Omega::instance().gdbCrashBatch.c_str());
+		}
 	#endif
 
 	LOG_INFO("Yade: normal exit.");

Modified: trunk/gui/py/_eudoxos.cpp
===================================================================
--- trunk/gui/py/_eudoxos.cpp	2009-02-04 21:45:01 UTC (rev 1657)
+++ trunk/gui/py/_eudoxos.cpp	2009-02-06 20:46:33 UTC (rev 1658)
@@ -36,7 +36,7 @@
  *
  * The code is analogous to AxialGravityEngine and is intended to give initial motion
  * to particles subject to axial compaction to speed up the process. */
-void velocityTowardsAxis(python::tuple _axisPoint, python::tuple _axisDirection, Real timeToAxis, Real subtractDist=0.){
+void velocityTowardsAxis(python::tuple _axisPoint, python::tuple _axisDirection, Real timeToAxis, Real subtractDist=0., Real perturbation=0.1){
 	Vector3r axisPoint=tuple2vec(_axisPoint), axisDirection=tuple2vec(_axisDirection);
 	FOREACH(const shared_ptr<Body>&b, *(Omega::instance().getRootBody()->bodies)){
 		if(!b->isDynamic) continue;
@@ -48,13 +48,15 @@
 		Vector3r toAxis=closestAxisPoint-x0;
 		if(subtractDist>0) toAxis*=(toAxis.Length()-subtractDist)/toAxis.Length();
 		pp->velocity=toAxis/timeToAxis;
+		Vector3r ppDiff=perturbation*(1./sqrt(3.))*Vector3r(Mathr::UnitRandom(),Mathr::UnitRandom(),Mathr::UnitRandom())*pp->velocity.Length();
+		pp->velocity+=ppDiff;
 	}
 }
-BOOST_PYTHON_FUNCTION_OVERLOADS(velocityTowardsAxis_overloads,velocityTowardsAxis,3,4);
+BOOST_PYTHON_FUNCTION_OVERLOADS(velocityTowardsAxis_overloads,velocityTowardsAxis,3,5);
 
 
 
 BOOST_PYTHON_MODULE(_eudoxos){
-	def("velocityTowardsAxis",velocityTowardsAxis,velocityTowardsAxis_overloads(args("axisPoint","axisDirection","timeToAxis","subtractDist")));
+	def("velocityTowardsAxis",velocityTowardsAxis,velocityTowardsAxis_overloads(args("axisPoint","axisDirection","timeToAxis","subtractDist","perturbation")));
 }
 

Modified: trunk/gui/py/_utils.cpp
===================================================================
--- trunk/gui/py/_utils.cpp	2009-02-04 21:45:01 UTC (rev 1657)
+++ trunk/gui/py/_utils.cpp	2009-02-06 20:46:33 UTC (rev 1658)
@@ -245,20 +245,34 @@
  * dH_dTheta is the inclination of the spiral (height increase per radian),
  * theta0 is the angle for zero height (by given axis).
  */
-python::tuple spiralProject(python::tuple _pt, Real dH_dTheta, int axis=2, Real theta0=0){
+python::tuple spiralProject(python::tuple _pt, Real dH_dTheta, int axis=2, Real periodStart=std::numeric_limits<Real>::quiet_NaN(), Real theta0=0){
 	int ax1=(axis+1)%3,ax2=(axis+2)%3;
 	Vector3r pt=tuple2vec(_pt);
 	Real r=sqrt(pow(pt[ax1],2)+pow(pt[ax2],2));
 	Real theta;
-	if(r>Mathr::ZERO_TOLERANCE) theta=acos(pt[ax1]/r);
-	if(pt[ax2]<0) theta=Mathr::TWO_PI-theta;
+	if(r>Mathr::ZERO_TOLERANCE){
+		theta=acos(pt[ax1]/r);
+		if(pt[ax2]<0) theta=Mathr::TWO_PI-theta;
+	}
 	else theta=0;
 	Real hRef=dH_dTheta*(theta-theta0);
 	long period;
-	Real h=Shop::periodicWrap(pt[axis],hRef-.5*Mathr::PI*dH_dTheta,hRef+.5*Mathr::PI*dH_dTheta,&period);
-	return python::make_tuple(python::make_tuple(r,h-hRef),theta);
+	if(isnan(periodStart)){
+		Real h=Shop::periodicWrap(pt[axis]-hRef,hRef-Mathr::PI*dH_dTheta,hRef+Mathr::PI*dH_dTheta,&period);
+		return python::make_tuple(python::make_tuple(r,h),theta);
+	}
+	else{
+		Real hPeriodStart=(periodStart-theta0)*dH_dTheta;
+		//TRVAR4(hPeriodStart,periodStart,theta0,theta);
+		//Real h=Shop::periodicWrap(pt[axis]-hRef,hPeriodStart,hPeriodStart+2*Mathr::PI*dH_dTheta,&period);
+		theta=Shop::periodicWrap(theta,periodStart,periodStart+2*Mathr::PI,&period);
+		Real h=pt[axis]-hRef+period*2*Mathr::PI*dH_dTheta;
+		//TRVAR3(pt[axis],pt[axis]-hRef,period);
+		//TRVAR2(h,theta);
+		return python::make_tuple(python::make_tuple(r,h),theta);
+	}
 }
-BOOST_PYTHON_FUNCTION_OVERLOADS(spiralProject_overloads,spiralProject,2,4);
+BOOST_PYTHON_FUNCTION_OVERLOADS(spiralProject_overloads,spiralProject,2,5);
 
 // for now, don't return anything, since we would have to include the whole yadeControl.cpp because of pyInteraction
 void Shop__createExplicitInteraction(body_id_t id1, body_id_t id2){ (void) Shop::createExplicitInteraction(id1,id2);}
@@ -286,7 +300,7 @@
 	def("sumBexForces",sumBexForces);
 	def("sumBexTorques",sumBexTorques);
 	def("createInteraction",Shop__createExplicitInteraction);
-	def("spiralProject",spiralProject,spiralProject_overloads(args("axis","theta0")));
+	def("spiralProject",spiralProject,spiralProject_overloads(args("axis","periodStart","theta0")));
 	def("pointInsidePolygon",pointInsidePolygon);
 	def("scalarOnColorScale",Shop__scalarOnColorScale);
 }

Modified: trunk/gui/py/utils.py
===================================================================
--- trunk/gui/py/utils.py	2009-02-04 21:45:01 UTC (rev 1657)
+++ trunk/gui/py/utils.py	2009-02-06 20:46:33 UTC (rev 1658)
@@ -276,7 +276,7 @@
 		while(os.path.exists(out+"~%d"%i)): i+=1
 		os.rename(out,out+"~%d"%i); print "Output file `%s' already existed, old file renamed to `%s'"%(out,out+"~%d"%i)
 	print "Encoding video from %s to %s"%(wildcard,out)
-	pipeline=gst.parse_launch('multifilesrc location="%s" index=0 caps="image/png,framerate=\(fraction\)%d/1" ! pngdec ! ffmpegcolorspace ! theoraenc sharpness=2 quality=32 ! oggmux ! filesink location="%s"'%(wildcard,fps,out))
+	pipeline=gst.parse_launch('multifilesrc location="%s" index=0 caps="image/png,framerate=\(fraction\)%d/1" ! pngdec ! ffmpegcolorspace ! theoraenc sharpness=2 quality=63 ! oggmux ! filesink location="%s"'%(wildcard,fps,out))
 	bus=pipeline.get_bus()
 	bus.add_signal_watch()
 	mainloop=gobject.MainLoop();

Modified: trunk/gui/qt3/GLViewer.cpp
===================================================================
--- trunk/gui/qt3/GLViewer.cpp	2009-02-04 21:45:01 UTC (rev 1657)
+++ trunk/gui/qt3/GLViewer.cpp	2009-02-06 20:46:33 UTC (rev 1658)
@@ -22,18 +22,20 @@
 
 CREATE_LOGGER(GLViewer);
 GLLock::GLLock(GLViewer* _glv):
-
+/* 
+ * try: doneCurrent; glFlush; glSwapBuffers after paintGL
+ */
 #if BOOST_VERSION<103500
 	boost::try_mutex::scoped_try_lock(YadeQtMainWindow::self->glMutex,true), glv(_glv){
-		if(locked()) glv->makeCurrent();
+		glv->makeCurrent();
 	}
 #else
 	boost::try_mutex::scoped_try_lock(YadeQtMainWindow::self->glMutex), glv(_glv){
-		if(owns_lock()) glv->makeCurrent();
+		glv->makeCurrent();
 	}
 #endif
 
-GLLock::~GLLock(){ /*glv->doneCurrent();*/}
+GLLock::~GLLock(){ glv->doneCurrent();}
 
 void GLViewer::updateGL(void){/*GLLock lock(this); */QGLViewer::updateGL();}
 
@@ -50,7 +52,7 @@
 			this->makeCurrent(); // not sure if this is needed
 			QGLViewer::paintGL();
 	}
-	//this->doneCurrent();
+	this->doneCurrent();
 }
 
 GLViewer::~GLViewer(){ /* get the GL mutex when closing */ GLLock lock(this); }

Modified: trunk/gui/qt3/QtGUI-python.cpp
===================================================================
--- trunk/gui/qt3/QtGUI-python.cpp	2009-02-04 21:45:01 UTC (rev 1657)
+++ trunk/gui/qt3/QtGUI-python.cpp	2009-02-06 20:46:33 UTC (rev 1658)
@@ -82,7 +82,9 @@
 	string snapBase2(snapBase);
 	if(snapBase2.empty()){ char tmpnam_str [L_tmpnam]; tmpnam(tmpnam_str); snapBase2=tmpnam_str; LOG_INFO("Using "<<snapBase2<<" as temporary basename for snapshots."); }
 	glv->stride=stride;
-	glv->load(savedSim);
+	{ GLLock lock(glv);
+		glv->load(savedSim);
+	}
 	glv->saveSnapShots=true;
 	glv->snapshotsBase=snapBase2;
 	{

Modified: trunk/gui/qt3/QtSimulationPlayer.cpp
===================================================================
--- trunk/gui/qt3/QtSimulationPlayer.cpp	2009-02-04 21:45:01 UTC (rev 1657)
+++ trunk/gui/qt3/QtSimulationPlayer.cpp	2009-02-06 20:46:33 UTC (rev 1658)
@@ -29,6 +29,7 @@
 QtSimulationPlayer::QtSimulationPlayer() : QtGeneratedSimulationPlayer(){
 	YadeQtMainWindow::self->ensureRenderer();
 	glSimulationPlayerViewer=new GLSimulationPlayerViewer(NULL,YadeQtMainWindow::self->renderer);
+	YadeQtMainWindow::self->renderer->initgl();
 	glSimulationPlayerViewer->simPlayer=this;
 	leInputConfigFile->setText(Omega::instance().getSimulationFileName());
 	enableControls(false);

Modified: trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp	2009-02-04 21:45:01 UTC (rev 1657)
+++ trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp	2009-02-06 20:46:33 UTC (rev 1658)
@@ -32,6 +32,7 @@
 	axis.Normalize();
 	Quaternionr q;
 	q.FromAxisAngle(axis,angularVelocity*dt);
+	angleTurned+=angularVelocity*dt;
 	shared_ptr<BodyContainer> bodies = rb->bodies;
 	FOREACH(body_id_t id,subscribedBodies){
 		assert(id<bodies->size());

Modified: trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp	2009-02-04 21:45:01 UTC (rev 1657)
+++ trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp	2009-02-06 20:46:33 UTC (rev 1658)
@@ -33,16 +33,18 @@
  */
 class SpiralEngine:public DeusExMachina{
 	public:
-		SpiralEngine():angularVelocity(0.),linearVelocity(0.),axis(Vector3r::UNIT_X),axisPt(0,0,0){}
+		SpiralEngine():angularVelocity(0.),linearVelocity(0.),axis(Vector3r::UNIT_X),axisPt(0,0,0),angleTurned(0.){}
 		Real angularVelocity;
 		Real linearVelocity;
 		//! axis of translation and rotation (direction); will be normalized by the engine
 		Vector3r axis;
 		//! a point on the axis, to position it in space properly
 		Vector3r axisPt;
+		//! how much have we turned so far
+		Real angleTurned;
 	virtual void applyCondition(MetaBody*);
 	REGISTER_CLASS_AND_BASE(SpiralEngine,DeusExMachina);
-	REGISTER_ATTRIBUTES(DeusExMachina,(angularVelocity)(linearVelocity)(axis)(axisPt));
+	REGISTER_ATTRIBUTES(DeusExMachina,(angularVelocity)(linearVelocity)(axis)(axisPt)(angleTurned));
 };
 REGISTER_SERIALIZABLE(SpiralEngine);
 

Modified: trunk/pkg/dem/Engine/EngineUnit/InteractingFacet2InteractingSphere4SpheresContactGeometry.cpp
===================================================================
--- trunk/pkg/dem/Engine/EngineUnit/InteractingFacet2InteractingSphere4SpheresContactGeometry.cpp	2009-02-04 21:45:01 UTC (rev 1657)
+++ trunk/pkg/dem/Engine/EngineUnit/InteractingFacet2InteractingSphere4SpheresContactGeometry.cpp	2009-02-06 20:46:33 UTC (rev 1658)
@@ -51,7 +51,7 @@
 	Real L = normal.Dot(cl);
 
 	int contactFace=0; // temp to save what will be maybe needed for new contact
-	assert((c->interactionGeometry&&c->isReal)||(!c->interactionGeometry&&!c->isReal));
+	//assert((c->interactionGeometry&&c->isReal)||(!c->interactionGeometry&&!c->isReal));
 	if(c->interactionGeometry){ // contact already exists, use old data here
 		contactFace=YADE_CAST<SpheresContactGeometry*>(c->interactionGeometry.get())->facetContactFace;
 		// determinate contact on negative side: reverse quantities