Author: eudoxos
Date: 2009-05-24 12:34:22 +0200 (Sun, 24 May 2009)
New Revision: 1776

Modified:
   trunk/gui/py/PythonUI_rc.py
   trunk/pkg/common/Engine/StandAloneEngine/InsertionSortCollider.cpp
   trunk/pkg/common/Engine/StandAloneEngine/InsertionSortCollider.hpp
   trunk/scripts/test/insertion-sort-collider.py
Log:
1. Use bitfield instead of bools in InsertsionSortCollider
2. Revert accidental changes in insertion-sort-collider.py
3. Add function for using renamed classes from python with warning


Modified: trunk/gui/py/PythonUI_rc.py
===================================================================
--- trunk/gui/py/PythonUI_rc.py 2009-05-24 09:19:26 UTC (rev 1775)
+++ trunk/gui/py/PythonUI_rc.py 2009-05-24 10:34:22 UTC (rev 1776)
@@ -39,8 +39,19 @@
                else:                  _dd[p]=lambda __r_=root2,__p_=p,**kw : 
yade.wrapper.__dict__[__r_](__p_,kw) # eval(root2)(p,kw)
 ### end wrappers
 
+#### HANDLE RENAMED CLASSES ####
+renamed={'ef2_Spheres_Brefcom_BrefcomLaw':'ef2_Dem3Dof_Cpm_Cpm'}
+for oldName in renamed:
+       class warnWrap:
+               def __init__(self,_old,_new): self.old,self.new=_old,_new
+               def __call__(self,*args):
+                       import warnings; warnings.warn("Class `%s' was renamed 
to `%s', update your 
code!"%(self.old,self.new),DeprecationWarning,stacklevel=2);
+                       return _dd[self.new](*args)
+       _dd[oldName]=warnWrap(oldName,renamed[oldName])
 
 
+
+
 # python2.4 workaround (so that quit() works as it does in 2.5)
 if not callable(__builtins__.quit):
        def _quit(): import sys; sys.exit(0)

Modified: trunk/pkg/common/Engine/StandAloneEngine/InsertionSortCollider.cpp
===================================================================
--- trunk/pkg/common/Engine/StandAloneEngine/InsertionSortCollider.cpp  
2009-05-24 09:19:26 UTC (rev 1775)
+++ trunk/pkg/common/Engine/StandAloneEngine/InsertionSortCollider.cpp  
2009-05-24 10:34:22 UTC (rev 1776)
@@ -48,11 +48,11 @@
 void InsertionSortCollider::insertionSort(vector<Bound>& v, 
InteractionContainer* interactions, MetaBody* rb, bool doCollide){
        long size=v.size();
        for(long i=0; i<size; i++){
-               Bound viInit=v[i]; long j=i-1; /* cache hasBB(); otherwise 1% 
overall performance hit */ bool viInitBB=viInit.hasBB();
+               const Bound viInit=v[i]; long j=i-1; /* cache hasBB; otherwise 
1% overall performance hit */ const bool viInitBB=viInit.flags.hasBB;
                while(j>=0 && v[j]>viInit){
                        v[j+1]=v[j];
                        // no collisions without bounding boxes
-                       if(doCollide && viInitBB && v[j].hasBB()) 
handleBoundInversion(viInit.id,v[j].id,interactions,rb);
+                       if(doCollide && viInitBB && v[j].flags.hasBB) 
handleBoundInversion(viInit.id,v[j].id,interactions,rb);
                        j--;
                }
                v[j+1]=viInit;
@@ -63,8 +63,6 @@
        //timingDeltas->start();
 
        size_t nBodies=rb->bodies->size();
-       // int axis1=(sortAxis+1)%3, axis2=(sortAxis+2)%3, axis0=sortAxis;
-       long iter=rb->currentIteration;
        InteractionContainer* interactions=rb->interactions.get();
 
 
@@ -83,9 +81,9 @@
                        assert((XX.size()%2)==0);
                        for(size_t id=XX.size()/2; id<nBodies; id++){
                                // add lower and upper bounds; coord is not 
important, will be updated from bb shortly
-                               XX.push_back(Bound(0,id,0|Bound::FLAG_MIN)); 
XX.push_back(Bound(0,id,0|0 /* no Bound::FLAG_MIN */));
-                               YY.push_back(Bound(0,id,0|Bound::FLAG_MIN)); 
YY.push_back(Bound(0,id,0|0 /* no Bound::FLAG_MIN */));
-                               ZZ.push_back(Bound(0,id,0|Bound::FLAG_MIN)); 
ZZ.push_back(Bound(0,id,0|0 /* no Bound::FLAG_MIN */));
+                               XX.push_back(Bound(0,id,/*isMin=*/true)); 
XX.push_back(Bound(0,id,/*isMin=*/false));
+                               YY.push_back(Bound(0,id,          true)); 
YY.push_back(Bound(0,id,          false));
+                               ZZ.push_back(Bound(0,id,          true)); 
ZZ.push_back(Bound(0,id,          false));
                        }
                }
                if(minima.size()!=3*nBodies){ minima.resize(3*nBodies); 
maxima.resize(3*nBodies); }
@@ -97,12 +95,12 @@
                for(size_t i=0; i<2*nBodies; i++){
                        const body_id_t& idXX=XX[i].id; const body_id_t& 
idYY=YY[i].id; const body_id_t& idZZ=ZZ[i].id;
                        const shared_ptr<BoundingVolume>& 
bvXX=Body::byId(idXX,rb)->boundingVolume; const shared_ptr<BoundingVolume>& 
bvYY=Body::byId(idYY,rb)->boundingVolume; const shared_ptr<BoundingVolume>& 
bvZZ=Body::byId(idZZ,rb)->boundingVolume;
-                       // copy bounds from boundingVolume if there is one (and 
call setBB() to mark that), otherwise use position (setNoBB() marks absence of 
bb)
-                       XX[i].coord=bvXX ? (XX[i].setBB(), XX[i].isMin() ? 
bvXX->min[0] : bvXX->max[0]) : (XX[i].setNoBB(), 
Body::byId(idXX,rb)->physicalParameters->se3.position[0]);
-                       YY[i].coord=bvYY ? (YY[i].setBB(), YY[i].isMin() ? 
bvYY->min[1] : bvYY->max[1]) : (YY[i].setNoBB(), 
Body::byId(idYY,rb)->physicalParameters->se3.position[1]);
-                       ZZ[i].coord=bvZZ ? (ZZ[i].setBB(), ZZ[i].isMin() ? 
bvZZ->min[2] : bvZZ->max[2]) : (ZZ[i].setNoBB(), 
Body::byId(idZZ,rb)->physicalParameters->se3.position[2]);
+                       // copy bounds from boundingVolume if there is one, 
otherwise use position; store what was used in the flags.hasBB bit
+                       XX[i].coord=(XX[i].flags.hasBB=(bool)bvXX) ? 
(XX[i].flags.isMin ? bvXX->min[0] : bvXX->max[0]) : 
(Body::byId(idXX,rb)->physicalParameters->se3.position[0]);
+                       YY[i].coord=(YY[i].flags.hasBB=(bool)bvYY) ? 
(YY[i].flags.isMin ? bvYY->min[1] : bvYY->max[1]) : 
(Body::byId(idYY,rb)->physicalParameters->se3.position[1]);
+                       ZZ[i].coord=(ZZ[i].flags.hasBB=(bool)bvZZ) ? 
(ZZ[i].flags.isMin ? bvZZ->min[2] : bvZZ->max[2]) : 
(Body::byId(idZZ,rb)->physicalParameters->se3.position[2]);
                        // and for each body, copy its minima and maxima arrays 
as well
-                       if(XX[i].isMin()){
+                       if(XX[i].flags.isMin){
                                
BOOST_STATIC_ASSERT(sizeof(Vector3r)==3*sizeof(Real));
                                if(bvXX) { 
memcpy(&minima[3*idXX],&bvXX->min,3*sizeof(Real)); 
memcpy(&maxima[3*idXX],&bvXX->max,3*sizeof(Real)); } // ⇐ faster than 6 
assignments 
                                else{ const Vector3r& 
pos=Body::byId(idXX,rb)->physicalParameters->se3.position; 
memcpy(&minima[3*idXX],pos,3*sizeof(Real)); 
memcpy(&maxima[3*idXX],pos,3*sizeof(Real)); }
@@ -143,7 +141,7 @@
                        for(size_t i=0; i<2*nBodies; i++){
                                // start from the lower bound
                                // skip bodies without bbox since we would 
possibly never meet the upper bound again (std::sort may not be stable) and we 
don't want to collide those anyway
-                               if(!(V[i].isMin() && V[i].hasBB())) continue;
+                               if(!(V[i].flags.isMin && V[i].flags.hasBB)) 
continue;
                                const body_id_t& iid=V[i].id;
                                // TRVAR3(i,iid,V[i].coord);
                                // go up until we meet the upper bound
@@ -151,7 +149,7 @@
                                        const body_id_t& jid=V[j].id;
                                        /// FIXME: not sure why this doesn't 
work. If this condition is commented out, we have exact same interactions as 
from SpatialQuickSort. Otherwise some interactions are missing!
                                        // skip bodies with smaller (arbitrary, 
could be greater as well) id, since they will detect us when their turn comes
-                                       // if(jid<iid) { /* LOG_TRACE("Skip 
#"<<V[j].id<<(V[j].isMin()?"(min)":"(max)")<<" with "<<iid<<" (smaller id)"); 
*/ continue; }
+                                       // if(jid<iid) { /* LOG_TRACE("Skip 
#"<<V[j].id<<(V[j].flags.isMin?"(min)":"(max)")<<" with "<<iid<<" (smaller 
id)"); */ continue; }
                                        /* abuse the same function here; since 
it does spatial overlap check first, it is OK to use it */
                                        
handleBoundInversion(iid,jid,interactions,rb);
                                }

Modified: trunk/pkg/common/Engine/StandAloneEngine/InsertionSortCollider.hpp
===================================================================
--- trunk/pkg/common/Engine/StandAloneEngine/InsertionSortCollider.hpp  
2009-05-24 09:19:26 UTC (rev 1775)
+++ trunk/pkg/common/Engine/StandAloneEngine/InsertionSortCollider.hpp  
2009-05-24 10:34:22 UTC (rev 1776)
@@ -24,15 +24,10 @@
                //! id of the body this bound belongs to
                body_id_t id;
                //! is it the minimum (true) or maximum (false) bound?
-               char type;
-               Bound(Real coord_, body_id_t id_, char type_): coord(coord_), 
id(id_), type(type_){}
+               struct{ unsigned hasBB:1; unsigned isMin:1; } flags;
+               Bound(Real coord_, body_id_t id_, bool isMin): coord(coord_), 
id(id_){ flags.isMin=isMin; }
                bool operator<(const Bound& b) const {return coord<b.coord;}
                bool operator>(const Bound& b) const {return coord>b.coord;}
-               enum { FLAG_MIN=1, FLAG_BB=2 };
-               inline bool hasBB() const {return type&FLAG_BB;}
-               inline bool isMin() const {return type&FLAG_MIN;}
-               inline void setBB(){type|=FLAG_BB;}
-               inline void setNoBB(){type&=type^FLAG_BB;}
        };
        //! storage for bounds
        std::vector<Bound> XX,YY,ZZ;

Modified: trunk/scripts/test/insertion-sort-collider.py
===================================================================
--- trunk/scripts/test/insertion-sort-collider.py       2009-05-24 09:19:26 UTC 
(rev 1775)
+++ trunk/scripts/test/insertion-sort-collider.py       2009-05-24 10:34:22 UTC 
(rev 1776)
@@ -4,28 +4,27 @@
        BexResetter(),
        
BoundingVolumeMetaEngine([InteractingSphere2AABB(),InteractingBox2AABB(),InteractingFacet2AABB(),MetaInteractingGeometry2AABB()]),
        InsertionSortCollider(),
-       
#InteractionDispatchers([ef2_Facet_Sphere_Dem3DofGeom()],[SimpleElasticRelationships()],[ef2_Dem3Dof_Elastic_ElasticLaw()],),
-       
InteractionDispatchers([ef2_Facet_Sphere_Dem3DofGeom()],[BrefcomMakeContact(cohesiveThresholdIter=0)],[ef2_Spheres_Brefcom_BrefcomLaw()],),
+       
InteractionDispatchers([ef2_Facet_Sphere_Dem3DofGeom()],[SimpleElasticRelationships()],[ef2_Dem3Dof_Elastic_ElasticLaw()],),
        GravityEngine(gravity=[0,0,-10]),
        NewtonsDampedLaw(damping=0.01),
 ]
 
 O.bodies.append([
-       
utils.facet([[-1,-1,0],[1,-1,0],[0,1,0]],dynamic=False,color=[1,0,0],young=1e3,physParamsClass='BrefcomPhysParams'),
-       
utils.facet([[1,-1,0],[0,1,0,],[1,.5,.5]],dynamic=False,young=1e3,physParamsClass='BrefcomPhysParams')
+       
utils.facet([[-1,-1,0],[1,-1,0],[0,1,0]],dynamic=False,color=[1,0,0],young=1e3),
+       utils.facet([[1,-1,0],[0,1,0,],[1,.5,.5]],dynamic=False,young=1e3)
 ])
 import random
 if 1:
        for i in range(0,100):
-               
O.bodies.append(utils.sphere([random.gauss(0,1),random.gauss(0,1),random.uniform(1,2)],random.uniform(.02,.05),velocity=[random.gauss(0,.1),random.gauss(0,.1),random.gauss(0,.1)],,physParamsClass='BrefcomPhysParams'))
+               
O.bodies.append(utils.sphere([random.gauss(0,1),random.gauss(0,1),random.uniform(1,2)],random.uniform(.02,.05),velocity=[random.gauss(0,.1),random.gauss(0,.1),random.gauss(0,.1)]))
 else:
-       
O.bodies.append(utils.sphere([0,0,.6],.5,,physParamsClass='BrefcomPhysParams'))
+       O.bodies.append(utils.sphere([0,0,.6],.5))
 O.dt=1e-4
 O.saveTmp('init')
 import yade.log
 #yade.log.setLevel("InsertionSortCollider",yade.log.TRACE);
 # compare 2 colliders:
-if 1:
+if 0:
        O.timingEnabled=True
        from yade import timing
        for collider in 
InsertionSortCollider(),PersistentSAPCollider(haveDistantTransient=True):


_______________________________________________
Mailing list: https://launchpad.net/~yade-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~yade-dev
More help   : https://help.launchpad.net/ListHelp
_______________________________________________
yade-dev mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/yade-dev

Reply via email to