← Back to team overview

yade-dev team mailing list archive

[svn] r1936 - in trunk: . gui/qt3 pkg/dem/DataClass py

 

Author: eudoxos
Date: 2009-08-11 12:47:18 +0200 (Tue, 11 Aug 2009)
New Revision: 1936

Modified:
   trunk/SConstruct
   trunk/gui/qt3/GLViewer.cpp
   trunk/gui/qt3/GLViewer.hpp
   trunk/gui/qt3/SimulationController.cpp
   trunk/pkg/dem/DataClass/SpherePack.cpp
   trunk/pkg/dem/DataClass/SpherePack.hpp
   trunk/py/_packSpheres.cpp
Log:
1. Try to fix locking with boost-1.35, possibly fixes https://bugs.launchpad.net/yade/+bug/411572 (please confirm)
2. Add periodic repetition function to SpherePack


Modified: trunk/SConstruct
===================================================================
--- trunk/SConstruct	2009-08-10 17:59:33 UTC (rev 1935)
+++ trunk/SConstruct	2009-08-11 10:47:18 UTC (rev 1936)
@@ -295,8 +295,9 @@
 
 	# gentoo has threaded flavour named differently and it must have precedence over the non-threaded one
 	def CheckLib_maybeMT(conf,lib,header,lang,func): return conf.CheckLibWithHeader(lib+'-mt',['limits.h',header],'c++',func,autoadd=1) or conf.CheckLibWithHeader(lib,['limits.h',header],lang,func,autoadd=1)
+	ok&=CheckLib_maybeMT(conf,'boost_system','boost/system/error_code.hpp','c++','boost::system::error_code();')
+	ok&=CheckLib_maybeMT(conf,'boost_thread','boost/thread/thread.hpp','c++','boost::thread::thread();')
 	ok&=CheckLib_maybeMT(conf,'boost_date_time','boost/date_time/posix_time/posix_time.hpp','c++','boost::posix_time::time_duration::time_duration();')
-	ok&=CheckLib_maybeMT(conf,'boost_thread','boost/thread/thread.hpp','c++','boost::thread::thread();')
 	ok&=CheckLib_maybeMT(conf,'boost_filesystem','boost/filesystem/path.hpp','c++','boost::filesystem::path();')
 	ok&=CheckLib_maybeMT(conf,'boost_iostreams','boost/iostreams/device/file.hpp','c++','boost::iostreams::file_sink("");')
 	ok&=CheckLib_maybeMT(conf,'boost_regex','boost/regex.hpp','c++','boost::regex("");')

Modified: trunk/gui/qt3/GLViewer.cpp
===================================================================
--- trunk/gui/qt3/GLViewer.cpp	2009-08-10 17:59:33 UTC (rev 1935)
+++ trunk/gui/qt3/GLViewer.cpp	2009-08-11 10:47:18 UTC (rev 1936)
@@ -25,37 +25,29 @@
 #endif
 
 CREATE_LOGGER(GLViewer);
-GLLock::GLLock(GLViewer* _glv):
-/* 
- * try: doneCurrent; glFlush; glSwapBuffers after paintGL
- */
-#if BOOST_VERSION<103500
-	boost::try_mutex::scoped_try_lock(Omega::instance().renderMutex,true), glv(_glv){
-		glv->makeCurrent();
-	}
-#else
-	boost::try_mutex::scoped_try_lock(Omega::instance().renderMutex), glv(_glv){
-		glv->makeCurrent();
-	}
-#endif
 
-GLLock::~GLLock(){ glv->doneCurrent();}
+GLLock::GLLock(GLViewer* _glv): boost::try_mutex::scoped_lock(Omega::instance().renderMutex), glv(_glv){
+	glv->makeCurrent();
+}
+GLLock::~GLLock(){ glv->doneCurrent(); }
 
+
 void GLViewer::updateGL(void){/*GLLock lock(this); */QGLViewer::updateGL();}
 
+/* additionally try: doneCurrent; glFlush; glSwapBuffers after paintGL */
 void GLViewer::paintGL(void){
 	/* paintGL encapsulated preDraw, draw and postDraw within QGLViewer. If the mutex cannot be locked,
 	 * we just return without repainting */
+	boost::try_mutex::scoped_try_lock lock(Omega::instance().renderMutex);
 	#if BOOST_VERSION<103500
-		boost::try_mutex::scoped_try_lock lock(Omega::instance().renderMutex);
-		if(lock.locked()){
+		if(lock.locked())
 	#else
-		boost::try_mutex::scoped_try_lock lock(Omega::instance().renderMutex,boost::defer_lock);
-		if(lock.owns_lock()){
+		if(lock.owns_lock())
 	#endif
+		{
 			this->makeCurrent();
 			QGLViewer::paintGL();
-	}
+		}
 	this->doneCurrent();
 }
 
@@ -344,15 +336,16 @@
  * "central" (where most bodies is) part very small or even invisible.
  */
 void GLViewer::centerMedianQuartile(){
-	if(Omega::instance().getRootBody()->isPeriodic){ centerPeriodic(); return; }
-	long nBodies=Omega::instance().getRootBody()->bodies->size();
+	MetaBody* rb=Omega::instance().getRootBody().get();
+	if(rb->isPeriodic){ centerPeriodic(); return; }
+	long nBodies=rb->bodies->size();
 	if(nBodies<4) {
 		LOG_INFO("Less than 4 bodies, median makes no sense; calling centerScene() instead.");
 		return centerScene();
 	}
 	std::vector<Real> coords[3];
 	for(int i=0;i<3;i++)coords[i].reserve(nBodies);
-	FOREACH(const shared_ptr<Body>& b, *Omega::instance().getRootBody()->bodies){
+	FOREACH(const shared_ptr<Body>& b, *rb->bodies){
 		for(int i=0; i<3; i++) coords[i].push_back(b->physicalParameters->se3.position[i]);
 	}
 	Vector3r median,interQuart;
@@ -394,7 +387,7 @@
 	LOG_DEBUG("Got scene box min="<<min<<" and max="<<max);
 	Vector3r center = (max+min)*0.5;
 	Vector3r halfSize = (max-min)*0.5;
-	float radius=std::max(halfSize[0],std::max(halfSize[1],halfSize[2])); if(radius==0) radius=1;
+	float radius=std::max(halfSize[0],std::max(halfSize[1],halfSize[2])); if(radius<=0) radius=1;
 	LOG_DEBUG("Scene center="<<center<<", halfSize="<<halfSize<<", radius="<<radius);
 	setSceneCenter(qglviewer::Vec(center[0],center[1],center[2]));
 	setSceneRadius(radius*1.5);

Modified: trunk/gui/qt3/GLViewer.hpp
===================================================================
--- trunk/gui/qt3/GLViewer.hpp	2009-08-10 17:59:33 UTC (rev 1935)
+++ trunk/gui/qt3/GLViewer.hpp	2009-08-11 10:47:18 UTC (rev 1936)
@@ -112,7 +112,13 @@
 		virtual void mousePressEvent(QMouseEvent *e);
 };
 
-class GLLock: public boost::try_mutex::scoped_try_lock{
+/*! Get unconditional lock on a GL view.
+
+Use if you need to manipulate GL context in some way.
+The ctor doesn't return until the lock has been acquired
+and the lock is released when the GLLock object is desctructed;
+*/
+class GLLock: public boost::try_mutex::scoped_lock{
 	GLViewer* glv;
 	public:
 		GLLock(GLViewer* _glv);

Modified: trunk/gui/qt3/SimulationController.cpp
===================================================================
--- trunk/gui/qt3/SimulationController.cpp	2009-08-10 17:59:33 UTC (rev 1935)
+++ trunk/gui/qt3/SimulationController.cpp	2009-08-11 10:47:18 UTC (rev 1936)
@@ -414,7 +414,7 @@
 		boost::try_mutex::scoped_try_lock lock(Omega::instance().renderMutex);
 		if(!lock.locked()){
 	#else
-		boost::try_mutex::scoped_try_lock lock(Omega::instance().renderMutex,boost::defer_lock);
+		boost::try_mutex::scoped_try_lock lock(Omega::instance().renderMutex,boost::try_to_lock);
 		if(!lock.owns_lock()){
 	#endif
 		deactivateControlsWhenLoading();

Modified: trunk/pkg/dem/DataClass/SpherePack.cpp
===================================================================
--- trunk/pkg/dem/DataClass/SpherePack.cpp	2009-08-10 17:59:33 UTC (rev 1935)
+++ trunk/pkg/dem/DataClass/SpherePack.cpp	2009-08-11 10:47:18 UTC (rev 1936)
@@ -111,3 +111,28 @@
 	return pack.size();
 }
 
+void SpherePack::cellFillVolume(Vector3r vol){
+	Vector3<int> count;
+	for(int i=0; i<3; i++) count[i]=(int)(ceil(vol[i]/cellSize[i]));
+	cellRepeat(count);
+}
+
+void SpherePack::cellRepeat(Vector3<int> count){
+	if(cellSize==Vector3r::ZERO){ throw std::runtime_error("cellRepeat cannot be used on non-periodic packing."); }
+	if(count[0]<=0 || count[1]<=0 || count[2]<=0){ throw std::invalid_argument("Repeat count components must be positive."); }
+	size_t origSize=pack.size();
+	pack.reserve(origSize*count[0]*count[1]*count[2]);
+	for(int i=0; i<count[0]; i++){
+		for(int j=0; j<count[1]; j++){
+			for(int k=0; k<count[2]; j++){
+				if((i==0) && (j==0) && (k==0)) continue; // original cell
+				Vector3r off(cellSize[0]*i,cellSize[1]*j,cellSize[2]*k);
+				for(size_t l=0; l<origSize; l++){
+					const Sph& s=pack[l]; pack.push_back(Sph(s.c+off,s.r));
+				}
+			}
+		}
+	}
+	cellSize=Vector3r(cellSize[0]*count[0],cellSize[1]*count[1],cellSize[2]*count[2]);
+}
+

Modified: trunk/pkg/dem/DataClass/SpherePack.hpp
===================================================================
--- trunk/pkg/dem/DataClass/SpherePack.hpp	2009-08-10 17:59:33 UTC (rev 1935)
+++ trunk/pkg/dem/DataClass/SpherePack.hpp	2009-08-11 10:47:18 UTC (rev 1936)
@@ -58,6 +58,10 @@
 	// random generation
 	long makeCloud(Vector3r min, Vector3r max, Real rMean, Real rFuzz, size_t num, bool periodic=false);
 
+	// periodic repetition
+	void cellRepeat(Vector3<int> count);
+	void cellFillVolume(Vector3r volume);
+
 	// spatial characteristics
 	Vector3r dim() const {Vector3r mn,mx; aabb(mn,mx); return mx-mn;}
 	#ifdef YADE_PYTHON

Modified: trunk/py/_packSpheres.cpp
===================================================================
--- trunk/py/_packSpheres.cpp	2009-08-10 17:59:33 UTC (rev 1935)
+++ trunk/py/_packSpheres.cpp	2009-08-11 10:47:18 UTC (rev 1936)
@@ -16,6 +16,8 @@
 		.def("dim",&SpherePack::dim,"Return dimensions of the packing in terms of aabb(), as a 3-tuple.")
 		.def("center",&SpherePack::midPt,"Return coordinates of the bounding box center.")
 		.def_readonly("cellSize",&SpherePack::cellSize,"Size of periodic cell; is Vector3(0,0,0) if not periodic.")
+		.def("cellFillVolume",&SpherePack::cellFillVolume,"Repeat the packing (if periodic) so that the results has dim() >= given size. The packing retains periodicity, but changes cellSize. Raises exception for non-periodic packing.")
+		.def("cellRepeat",&SpherePack::cellRepeat,"Repeat the packing given number of times in each dimension. Periodicity is retained, cellSize changes. Raises exception for non-periodic packing.")
 		.def("relDensity",&SpherePack::relDensity,"Relative packing density, measured as sum of spheres' volumes / aabb volume.\n(Sphere overlaps are ignored.)")
 		.def("translate",&SpherePack::translate,"Translate all spheres by given vector.")
 		.def("rotate",&SpherePack::rotate,"Rotate all spheres around packing center (in terms of aabb()), given axis and angle of the rotation.")




Follow ups