Author: eudoxos
Date: 2008-10-05 15:21:51 +0200 (Sun, 05 Oct 2008)
New Revision: 1536

Modified:
   trunk/core/Interaction.cpp
   trunk/core/Interaction.hpp
   trunk/gui/qt3/GLViewer.cpp
   trunk/gui/qt3/SnapshotEngine.cpp
   trunk/gui/qt3/SnapshotEngine.hpp
   trunk/gui/qt3/qt.py
   trunk/lib/multimethods/DynLibDispatcher.hpp
   
trunk/pkg/dem/Engine/EngineUnit/InteractingFacet2InteractingSphere4SpheresContactGeometry.cpp
   
trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.cpp
   
trunk/pkg/dem/RenderingEngine/GLDrawSpheresContactGeometry/GLDrawSpheresContactGeometry.cpp
   
trunk/pkg/dem/RenderingEngine/GLDrawSpheresContactGeometry/GLDrawSpheresContactGeometry.hpp
Log:
1. Add Interaction::swapOrder(), for use in EngineUnits that want to avoid 
calling goReverse()
2. SnapshotEngine can sleep specified number of msecs after shot, which 
probably can avoid some hw problems (make_current failed in mesa, freezes etc)
3. InteractingFacet2IS4SCG now works "correctly" (not exactly physically, 
though) with shear
4. DynLibDispatcher should report names of classes if dispatch fails.




Modified: trunk/core/Interaction.cpp
===================================================================
--- trunk/core/Interaction.cpp  2008-10-01 09:41:03 UTC (rev 1535)
+++ trunk/core/Interaction.cpp  2008-10-05 13:21:51 UTC (rev 1536)
@@ -43,3 +43,9 @@
        REGISTER_ATTRIBUTE(interactionPhysics);
 }
 
+void Interaction::swapOrder(){
+       if(interactionGeometry || interactionPhysics || !isNew){
+               throw std::logic_error("Bodies in interaction cannot be swapped 
if !isNew, have interactionGeometry or have interactionPhysics.");
+       }
+       std::swap(id1,id2);
+}

Modified: trunk/core/Interaction.hpp
===================================================================
--- trunk/core/Interaction.hpp  2008-10-01 09:41:03 UTC (rev 1535)
+++ trunk/core/Interaction.hpp  2008-10-05 13:21:51 UTC (rev 1536)
@@ -13,6 +13,8 @@
 //BOOST_STRONG_TYPEDEF(int, body_id_t)
 typedef int body_id_t;
 
+class InteractionGeometryEngineUnit;
+
 class Interaction : public Serializable
 {
        private :
@@ -33,6 +35,9 @@
                body_id_t getId1() {return id1;};
                body_id_t getId2() {return id2;};
 
+               //! swaps order of bodies within the interaction
+               void swapOrder();
+
                #if 0
                        //! Whether both bodies involved in interaction 
satisfies given mask; provide rootBody for faster lookup
                        bool maskBothOK(int mask, MetaBody* 
rootBody=NULL){return (mask==0) || (Body::byId(id1,rootBody)->maskOK(mask) && 
Body::byId(id2,rootBody)->maskOK(mask));}

Modified: trunk/gui/qt3/GLViewer.cpp
===================================================================
--- trunk/gui/qt3/GLViewer.cpp  2008-10-01 09:41:03 UTC (rev 1535)
+++ trunk/gui/qt3/GLViewer.cpp  2008-10-05 13:21:51 UTC (rev 1536)
@@ -228,7 +228,7 @@
                }
        }
        else if(e->key()==Qt::Key_S){
-               LOG_DEBUG("Saving QGLViewer state to /tmp/qglviewerState.xml");
+               LOG_INFO("Saving QGLViewer state to /tmp/qglviewerState.xml");
                setStateFileName("/tmp/qglviewerState.xml"); saveStateToFile(); 
setStateFileName(QString::null);
        }
        else if(e->key()==Qt::Key_X || e->key()==Qt::Key_Y || 
e->key()==Qt::Key_Z){

Modified: trunk/gui/qt3/SnapshotEngine.cpp
===================================================================
--- trunk/gui/qt3/SnapshotEngine.cpp    2008-10-01 09:41:03 UTC (rev 1535)
+++ trunk/gui/qt3/SnapshotEngine.cpp    2008-10-05 13:21:51 UTC (rev 1536)
@@ -13,5 +13,6 @@
        glv->setSnapshotFormat("PNG");
        glv->saveSnapshot(QString(fss.str()),/*overwrite*/ true);
        savedSnapshots.push_back(fss.str());
+       usleep((long)(msecSleep*1000));
 }
 

Modified: trunk/gui/qt3/SnapshotEngine.hpp
===================================================================
--- trunk/gui/qt3/SnapshotEngine.hpp    2008-10-01 09:41:03 UTC (rev 1535)
+++ trunk/gui/qt3/SnapshotEngine.hpp    2008-10-05 13:21:51 UTC (rev 1536)
@@ -21,7 +21,9 @@
                bool ignoreErrors;
                //! files that have been created so far
                vector<string> savedSnapshots;
-       SnapshotEngine():counter(0),viewNo(0),ignoreErrors(true){}
+               //! number of msec to sleep after snapshot (to prevent 3d hw 
problems)
+               int msecSleep;
+       SnapshotEngine():counter(0),viewNo(0),ignoreErrors(true),msecSleep(0){}
        virtual void action(MetaBody*);
        void registerAttributes(){      
                PeriodicEngine::registerAttributes();
@@ -30,6 +32,7 @@
                REGISTER_ATTRIBUTE(viewNo);
                REGISTER_ATTRIBUTE(ignoreErrors);
                REGISTER_ATTRIBUTE(savedSnapshots);
+               REGISTER_ATTRIBUTE(msecSleep);
        }
        DECLARE_LOGGER;
        REGISTER_CLASS_NAME(SnapshotEngine);

Modified: trunk/gui/qt3/qt.py
===================================================================
--- trunk/gui/qt3/qt.py 2008-10-01 09:41:03 UTC (rev 1535)
+++ trunk/gui/qt3/qt.py 2008-10-05 13:21:51 UTC (rev 1536)
@@ -6,7 +6,7 @@
 
 
 
-def 
makeSimulationVideo(output,realPeriod=1,virtPeriod=0,iterPeriod=0,viewNo=0,fps=24):
+def 
makeSimulationVideo(output,realPeriod=1,virtPeriod=0,iterPeriod=0,viewNo=0,fps=24,msecSleep=0):
        """Create video by running simulation. SnapshotEngine is added (and 
removed once done), temporary
        files are deleted. The video is theora-encoded in the ogg container. 
Periodicity is controlled
        in the same way as for PeriodicEngine (SnapshotEngine is a 
PeriodicEngine and realPeriod, virtPeriod 
@@ -26,7 +26,7 @@
        # create primary view if none
        if len(views())==0: View()
        # remove existing SnaphotEngines
-       
se=wrapper.StandAloneEngine('SnapshotEngine',{'iterPeriod':iterPeriod,'realPeriod':realPeriod,'virtPeriod':virtPeriod,'fileBase':os.tmpnam(),'ignoreErrors':False,'viewNo':viewNo})
+       
se=wrapper.StandAloneEngine('SnapshotEngine',{'iterPeriod':iterPeriod,'realPeriod':realPeriod,'virtPeriod':virtPeriod,'fileBase':os.tmpnam(),'ignoreErrors':False,'viewNo':viewNo,'msecSleep':msecSleep})
        origEngines=o.engines; o.engines=[e for e in o.engines if 
e.name!='SnapshotEngine']+[se]
        o.run(); o.wait();
        wildcard=se['fileBase']+'%04d.png'

Modified: trunk/lib/multimethods/DynLibDispatcher.hpp
===================================================================
--- trunk/lib/multimethods/DynLibDispatcher.hpp 2008-10-01 09:41:03 UTC (rev 
1535)
+++ trunk/lib/multimethods/DynLibDispatcher.hpp 2008-10-05 13:21:51 UTC (rev 
1536)
@@ -494,7 +494,7 @@
                                }
                        }
                        else if( index1_tmp != -1 && index2_tmp != -1 )
-                               cerr << "DynLibDispatcher: ambigious dispatch, 
could not determine which multivirtual function should be called\n";
+                               throw std::runtime_error("DynLibDispatcher: 
ambiguous or undefined dispatch for 2d multivirtual function, classes: 
"+base1->getClassName()+" "+base2->getClassName());
                        
                        return false;
                  };

Modified: 
trunk/pkg/dem/Engine/EngineUnit/InteractingFacet2InteractingSphere4SpheresContactGeometry.cpp
===================================================================
--- 
trunk/pkg/dem/Engine/EngineUnit/InteractingFacet2InteractingSphere4SpheresContactGeometry.cpp
       2008-10-01 09:41:03 UTC (rev 1535)
+++ 
trunk/pkg/dem/Engine/EngineUnit/InteractingFacet2InteractingSphere4SpheresContactGeometry.cpp
       2008-10-05 13:21:51 UTC (rev 1536)
@@ -35,12 +35,18 @@
                                                        const 
shared_ptr<Interaction>& c)
 {
        InteractingFacet*   facet = static_cast<InteractingFacet*>(cm1.get());
+       /* could be written as (needs to be tested):
+        * Vector3r 
cl=se32.orientation.Conjugate()*(se32.position-se32.position);
+        */
        Matrix3r facetAxisT; se31.orientation.ToRotationMatrix(facetAxisT); 
        Matrix3r facetAxis = facetAxisT.Transpose();
-       
        // local orientation
        Vector3r cl = facetAxis*(se32.position - se31.position); 
 
+       //
+       // BEGIN everything in facet-local coordinates
+       //
+
        Vector3r normal = facet->nf;
        Real L = normal.Dot(cl);
        if (L<0) { normal=-normal; L=-L; }
@@ -67,7 +73,7 @@
 
        if (icr<0)
        {
-               LOG_INFO("WARNING: a radius of a facet's inscribed circle less 
than zero! So, shrinkFactor is too large and would be reduced to zero.");
+               LOG_WARN("a radius of a facet's inscribed circle less than 
zero! So, shrinkFactor is too large and would be reduced to zero.");
                shrinkFactor=0;
                icr = facet->icr;
                sh = 0;
@@ -92,6 +98,10 @@
                penetrationDepth = sphereRadius - normal.Normalize();
        }
 
+       //
+       // END everything in facet-local coordinates
+       //
+
        if (penetrationDepth>0)
        {
                shared_ptr<SpheresContactGeometry> scm;
@@ -100,7 +110,7 @@
                else
                        scm = shared_ptr<SpheresContactGeometry>(new 
SpheresContactGeometry());
          
-           normal = facetAxisT*normal; // global orientation
+               normal = facetAxisT*normal; // in global orientation
                scm->contactPoint = se32.position - 
(sphereRadius-0.5*penetrationDepth)*normal; 
                scm->normal = normal; 
                scm->penetrationDepth = penetrationDepth;
@@ -112,17 +122,18 @@
 
                if(hasShear){
                        scm->hasShear=true;
-                       
scm->pos1=scm->contactPoint-(2*sphereRadius-.5*penetrationDepth)*normal; 
scm->pos2=se32.position;
+                       // fictive center of the sphere representing the facet 
in the sphere-sphere contact
+                       
scm->pos1=scm->contactPoint-(scm->radius1-.5*penetrationDepth)*normal; 
scm->pos2=se32.position;
                        scm->ori1=se31.orientation; scm->ori2=se32.orientation;
                        if(c->isNew){
-                               scm->d0=(scm->pos2-scm->pos1).Length();
-                               scm->d1=2*sphereRadius-penetrationDepth; 
scm->d2=sphereRadius-penetrationDepth;
+                               
scm->d0=scm->radius1+scm->radius2-penetrationDepth;
+                               scm->d1=scm->radius1-.5*penetrationDepth; 
scm->d2=scm->radius2-.5*penetrationDepth;
                                // quasi-constants
                                
scm->cp1rel.Align(Vector3r::UNIT_X,se31.orientation.Conjugate()*normal);
                                
scm->cp2rel.Align(Vector3r::UNIT_X,se32.orientation.Conjugate()*(-normal));
                                scm->cp1rel.Normalize(); 
scm->cp2rel.Normalize();
                        }
-                       cerr<<"[n"<<scm->displacementN()<<" 
t"<<scm->displacementT()<<"]";
+                       TRVAR2(scm->contPtInTgPlane1(),scm->contPtInTgPlane2());
                }
 
                return true;
@@ -137,16 +148,23 @@
                                                                const Se3r& 
se32,
                                                                const 
shared_ptr<Interaction>& c)
 {
+       c->swapOrder();
+       //LOG_WARN("Swapped interaction order for 
"<<c->getId2()<<"&"<<c->getId1());
+       return go(cm2,cm1,se32,se31,c);
+#if 0  
        bool isInteracting = go(cm2,cm1,se32,se31,c);
        if (isInteracting)
        {
            SpheresContactGeometry* scm = 
static_cast<SpheresContactGeometry*>(c->interactionGeometry.get());
-           scm->normal = -scm->normal;
-           Real tmpR = scm->radius1;
-           scm->radius1 = scm->radius2;
-           scm->radius2 = tmpR;
+                scm->normal*=-1;
+                std::swap(scm->radius1,scm->radius2);
+                if(hasShear){
+                        swap(scm->pos1,scm->pos2); swap(scm->ori1,scm->ori2);
+                        if(c->isNew){ swap(scm->cp1rel,scm->cp2rel); 
swap(scm->d1,scm->d2); }
+                }
        }
        return isInteracting;
+#endif
 }
 
 YADE_PLUGIN();

Modified: 
trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.cpp
===================================================================
--- 
trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.cpp
      2008-10-01 09:41:03 UTC (rev 1535)
+++ 
trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.cpp
      2008-10-05 13:21:51 UTC (rev 1536)
@@ -36,7 +36,6 @@
                shared_ptr<SpheresContactGeometry> scm;
                if(c->interactionGeometry) 
scm=YADE_PTR_CAST<SpheresContactGeometry>(c->interactionGeometry);
                else { scm=shared_ptr<SpheresContactGeometry>(new 
SpheresContactGeometry()); c->interactionGeometry=scm; }
-               //cerr<<"Assigned scm 
"<<scm.get()<<"=="<<c->interactionGeometry.get()<<endl;
 
                Real penetrationDepth=s1->radius+s2->radius-normal.Normalize(); 
/* Normalize() works in-place and returns length before normalization; from 
here, normal is unit vector */
                
scm->contactPoint=se31.position+(s1->radius-0.5*penetrationDepth)*normal;//0.5*(pt1+pt2);

Modified: 
trunk/pkg/dem/RenderingEngine/GLDrawSpheresContactGeometry/GLDrawSpheresContactGeometry.cpp
===================================================================
--- 
trunk/pkg/dem/RenderingEngine/GLDrawSpheresContactGeometry/GLDrawSpheresContactGeometry.cpp
 2008-10-01 09:41:03 UTC (rev 1535)
+++ 
trunk/pkg/dem/RenderingEngine/GLDrawSpheresContactGeometry/GLDrawSpheresContactGeometry.cpp
 2008-10-05 13:21:51 UTC (rev 1536)
@@ -15,6 +15,7 @@
 #include<yade/lib-opengl/GLUtils.hpp>
 
 YADE_PLUGIN("GLDrawSpheresContactGeometry");
+CREATE_LOGGER(GLDrawSpheresContactGeometry);
 
 void GLDrawSpheresContactGeometry::go(
                const shared_ptr<InteractionGeometry>& ig,
@@ -77,15 +78,19 @@
        }
 
        if(sc->hasShear){
-               Vector3r 
contPt=se31.position+(sc->d1/sc->d0)*(se32.position-se31.position); // must be 
recalculated to not be unscaled if scaling displacements ...
+               Vector3r pos1=sc->pos1, pos2=sc->pos2, contPt=sc->contPt();
+               //Vector3r 
contPt=se31.position+(sc->d1/sc->d0)*(se32.position-se31.position); // must be 
recalculated to not be unscaled if scaling displacements ...
                GLUtils::GLDrawLine(pos1,pos2,Vector3r(.5,.5,.5));
                // sphere center to point on the sphere
                
//GLUtils::GLDrawLine(pos1,pos1+(sc->ori1*sc->cp1rel*Vector3r::UNIT_X*sc->d1),Vector3r(0,.5,1));
                
//GLUtils::GLDrawLine(pos2,pos2+(sc->ori2*sc->cp2rel*Vector3r::UNIT_X*sc->d2),Vector3r(0,1,.5));
+               //TRVAR4(pos1,sc->ori1,pos2,sc->ori2);
+               
//TRVAR2(sc->cp2rel,pos2+(sc->ori2*sc->cp2rel*Vector3r::UNIT_X*sc->d2));
                // contact point to projected points
                Vector3r ptTg1=sc->contPtInTgPlane1(), 
ptTg2=sc->contPtInTgPlane2();
-               GLUtils::GLDrawLine(contPt,contPt+ptTg1,Vector3r(0,.5,1));
-               GLUtils::GLDrawLine(contPt,contPt+ptTg2,Vector3r(0,1,.5));
+               TRVAR3(ptTg1,ptTg2,sc->normal)
+               //GLUtils::GLDrawLine(contPt,contPt+ptTg1,Vector3r(0,.5,1)); 
GLUtils::GLDrawLine(pos1,contPt+ptTg1,Vector3r(0,.5,1));
+               //GLUtils::GLDrawLine(contPt,contPt+ptTg2,Vector3r(0,1,.5)); 
GLUtils::GLDrawLine(pos2,contPt+ptTg2,Vector3r(0,1,.5));
                // projected shear
                GLUtils::GLDrawLine(contPt+ptTg1,contPt+ptTg2,Vector3r(1,1,1));
                // 

Modified: 
trunk/pkg/dem/RenderingEngine/GLDrawSpheresContactGeometry/GLDrawSpheresContactGeometry.hpp
===================================================================
--- 
trunk/pkg/dem/RenderingEngine/GLDrawSpheresContactGeometry/GLDrawSpheresContactGeometry.hpp
 2008-10-01 09:41:03 UTC (rev 1535)
+++ 
trunk/pkg/dem/RenderingEngine/GLDrawSpheresContactGeometry/GLDrawSpheresContactGeometry.hpp
 2008-10-05 13:21:51 UTC (rev 1536)
@@ -20,6 +20,7 @@
                virtual void go(const shared_ptr<InteractionGeometry>&,const 
shared_ptr<Interaction>&,const shared_ptr<Body>&,const shared_ptr<Body>&,bool 
wireFrame);
                //      virtual void registerAttributes();
 
+       DECLARE_LOGGER;
        RENDERS(SpheresContactGeometry);
        REGISTER_CLASS_NAME(GLDrawSpheresContactGeometry);
        REGISTER_BASE_CLASS_NAME(GLDrawInteractionGeometryFunctor);


_______________________________________________
Mailing list: https://launchpad.net/~yade-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~yade-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to