yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #00689
[svn] r1533 - in trunk: core pkg/common pkg/common/Container pkg/dem/DataClass/InteractionGeometry pkg/dem/Engine/EngineUnit
Author: sega
Date: 2008-09-30 12:49:22 +0200 (Tue, 30 Sep 2008)
New Revision: 1533
Added:
trunk/pkg/common/Container/InteractionVecMap.cpp
trunk/pkg/common/Container/InteractionVecMap.hpp
Modified:
trunk/core/InteractionContainer.hpp
trunk/pkg/common/SConscript
trunk/pkg/dem/DataClass/InteractionGeometry/SpheresContactGeometry.hpp
trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.cpp
trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.hpp
Log:
1. New random-access interaction container InteractionVecMap (rewrited from InteractionVecSet)
2. Fixes: default initialization some attributes in SCG and IS2IS4SCG
Modified: trunk/core/InteractionContainer.hpp
===================================================================
--- trunk/core/InteractionContainer.hpp 2008-09-30 10:29:52 UTC (rev 1532)
+++ trunk/core/InteractionContainer.hpp 2008-09-30 10:49:22 UTC (rev 1533)
@@ -97,6 +97,9 @@
virtual InteractionContainer::iterator end() {throw;};
virtual unsigned int size() {throw;};
+ virtual shared_ptr<Interaction>& operator[] (unsigned int) {throw;};
+ virtual const shared_ptr<Interaction>& operator[] (unsigned int) const {throw;};
+
private :
vector<shared_ptr<Interaction> > interaction;
Added: trunk/pkg/common/Container/InteractionVecMap.cpp
===================================================================
--- trunk/pkg/common/Container/InteractionVecMap.cpp 2008-09-30 10:29:52 UTC (rev 1532)
+++ trunk/pkg/common/Container/InteractionVecMap.cpp 2008-09-30 10:49:22 UTC (rev 1533)
@@ -0,0 +1,198 @@
+// 2008 © Sergei Dorofeenko <sega@xxxxxxxxxxxxxxxx>
+
+#include "InteractionVecMap.hpp"
+#include <iostream>
+
+
+InteractionVecMapIterator::InteractionVecMapIterator() : InteractionContainerIterator()
+{
+
+}
+
+
+InteractionVecMapIterator::~InteractionVecMapIterator()
+{
+
+}
+
+shared_ptr<Interaction>& InteractionVecMap::operator[](unsigned int id)
+{
+ return interactions[id];
+}
+
+const shared_ptr<Interaction>& InteractionVecMap::operator[](unsigned int id) const
+{
+ return interactions[id];
+}
+
+bool InteractionVecMapIterator::isDifferent(const InteractionContainerIterator& i)
+{
+ const InteractionVecMapIterator& it = static_cast<const InteractionVecMapIterator&>(i);
+ return ( vii != it.vii );
+}
+
+
+void InteractionVecMapIterator::increment()
+{
+ ++vii;
+}
+
+
+void InteractionVecMapIterator::affect(const InteractionContainerIterator& i)
+{
+ const InteractionVecMapIterator& tmpi = static_cast<const InteractionVecMapIterator&>(i);
+ vii = tmpi.vii;
+}
+
+
+shared_ptr<Interaction> InteractionVecMapIterator::getValue()
+{
+ return *vii;
+}
+
+
+shared_ptr<InteractionContainerIterator> InteractionVecMapIterator::createPtr()
+{
+ return shared_ptr<InteractionContainerIterator>(new InteractionVecMapIterator());
+}
+
+
+/*********************************************************************/
+
+InteractionVecMap::InteractionVecMap()
+{
+ currentSize = 0;
+ clear();
+}
+
+
+InteractionVecMap::~InteractionVecMap()
+{
+}
+
+
+bool InteractionVecMap::insert(shared_ptr<Interaction>& i)
+{
+ boost::mutex::scoped_lock lock(drawloopmutex);
+
+ body_id_t id1 = i->getId1();
+ body_id_t id2 = i->getId2();
+
+ if (id1>id2)
+ swap(id1,id2);
+
+ if ( static_cast<unsigned int>(id1) >=vecmap.size())
+ vecmap.resize(id1+1);
+
+ if (vecmap[id1].insert(pair<body_id_t,unsigned int >(id2,currentSize)).second)
+ {
+ if (interactions.size() == currentSize)
+ interactions.resize(currentSize+1);
+
+ interactions[currentSize]=i;
+ currentSize++;
+
+ return true;
+ }
+ else
+ return false;
+}
+
+
+bool InteractionVecMap::insert(body_id_t id1,body_id_t id2)
+{
+ shared_ptr<Interaction> i(new Interaction(id1,id2) );
+ return insert(i);
+}
+
+
+void InteractionVecMap::clear()
+{
+ boost::mutex::scoped_lock lock(drawloopmutex);
+
+ vecmap.clear();
+ interactions.clear();
+ currentSize=0;
+}
+
+
+bool InteractionVecMap::erase(body_id_t id1,body_id_t id2)
+{
+ boost::mutex::scoped_lock lock(drawloopmutex);
+
+ if (id1>id2)
+ swap(id1,id2);
+
+ if ( static_cast<unsigned int>(id1) < vecmap.size())
+ {
+ map<body_id_t,unsigned int >::iterator mii;
+ mii = vecmap[id1].find(id2);
+ if ( mii != vecmap[id1].end() )
+ {
+ unsigned int iid = (*mii).second;
+ vecmap[id1].erase(mii);
+ currentSize--;
+ if (iid<currentSize) {
+ interactions[iid]=interactions[currentSize];
+ id1 = interactions[iid]->getId1();
+ id2 = interactions[iid]->getId2();
+ if (id1>id2) swap(id1,id2);
+ vecmap[id1][id2]=iid;
+ }
+ return true;
+ }
+ else
+ return false;
+ }
+
+ return false;
+
+}
+
+
+const shared_ptr<Interaction>& InteractionVecMap::find(body_id_t id1,body_id_t id2)
+{
+ if (id1>id2)
+ swap(id1,id2);
+
+ if (static_cast<unsigned int>(id1)<vecmap.size())
+ {
+ map<body_id_t,unsigned int >::iterator mii;
+ mii = vecmap[id1].find(id2);
+ if (mii!=vecmap[id1].end())
+ return interactions[(*mii).second];
+ else
+ {
+ empty = shared_ptr<Interaction>();
+ return empty;
+ }
+ }
+ else
+ {
+ empty = shared_ptr<Interaction>();
+ return empty;
+ }
+}
+
+
+InteractionContainer::iterator InteractionVecMap::begin()
+{
+ shared_ptr<InteractionVecMapIterator> it(new InteractionVecMapIterator());
+ it->vii = interactions.begin();
+ return InteractionContainer::iterator(it);
+}
+
+
+InteractionContainer::iterator InteractionVecMap::end()
+{
+ shared_ptr<InteractionVecMapIterator> it(new InteractionVecMapIterator());
+ it->vii = interactions.begin()+currentSize;
+ return InteractionContainer::iterator(it);
+}
+
+unsigned int InteractionVecMap::size()
+{
+ return currentSize;
+}
+
+// YADE_PLUGIN();
Added: trunk/pkg/common/Container/InteractionVecMap.hpp
===================================================================
--- trunk/pkg/common/Container/InteractionVecMap.hpp 2008-09-30 10:29:52 UTC (rev 1532)
+++ trunk/pkg/common/Container/InteractionVecMap.hpp 2008-09-30 10:49:22 UTC (rev 1533)
@@ -0,0 +1,62 @@
+// 2008 © Sergei Dorofeenko <sega@xxxxxxxxxxxxxxxx>
+
+#include<yade/core/InteractionContainer.hpp>
+#include<yade/core/Interaction.hpp>
+#include<map>
+#include<vector>
+
+using namespace std;
+
+class InteractionVecMapIterator : public InteractionContainerIterator
+{
+ public :
+
+ vector<shared_ptr<Interaction> >::iterator vii;
+ InteractionVecMapIterator();
+ ~InteractionVecMapIterator();
+
+ virtual bool isDifferent(const InteractionContainerIterator& i);
+ virtual void affect(const InteractionContainerIterator& i);
+ virtual void increment();
+ virtual shared_ptr<Interaction> getValue();
+ virtual shared_ptr<InteractionContainerIterator> createPtr();
+
+
+};
+
+
+using namespace __gnu_cxx;
+
+class InteractionVecMap : public InteractionContainer
+{
+ private :
+ vector<shared_ptr<Interaction> > interactions;
+ vector<map<body_id_t, unsigned int > > vecmap;
+ unsigned int currentSize;
+ shared_ptr<Interaction> empty;
+
+ public :
+ InteractionVecMap();
+ virtual ~InteractionVecMap();
+
+ virtual bool insert(body_id_t id1,body_id_t id2);
+ virtual bool insert(shared_ptr<Interaction>& i);
+ virtual void clear();
+ virtual bool erase(body_id_t id1,body_id_t id2);
+ virtual const shared_ptr<Interaction>& find(body_id_t id1,body_id_t id2);
+
+ virtual InteractionContainer::iterator begin();
+ virtual InteractionContainer::iterator end();
+
+ virtual shared_ptr<Interaction>& operator[](unsigned int);
+ virtual const shared_ptr<Interaction>& operator[](unsigned int) const;
+
+ virtual unsigned int size();
+
+ REGISTER_CLASS_NAME(InteractionVecMap);
+ REGISTER_BASE_CLASS_NAME(InteractionContainer);
+
+};
+
+REGISTER_SERIALIZABLE(InteractionVecMap,false);
+
Modified: trunk/pkg/common/SConscript
===================================================================
--- trunk/pkg/common/SConscript 2008-09-30 10:29:52 UTC (rev 1532)
+++ trunk/pkg/common/SConscript 2008-09-30 10:49:22 UTC (rev 1533)
@@ -13,6 +13,10 @@
['Container/InteractionHashMap.cpp'],
LIBS=env['LIBS']+['yade-base']),
+ env.SharedLibrary('InteractionVecMap',
+ ['Container/InteractionVecMap.cpp'],
+ LIBS=env['LIBS']+['yade-base']),
+
## moved to core/DefaultContainerImplementations
# env.SharedLibrary('BodyRedirectionVector',['Container/BodyRedirectionVector.cpp']),
# env.SharedLibrary('InteractionVecSet',['Container/InteractionVecSet.cpp']),
Modified: trunk/pkg/dem/DataClass/InteractionGeometry/SpheresContactGeometry.hpp
===================================================================
--- trunk/pkg/dem/DataClass/InteractionGeometry/SpheresContactGeometry.hpp 2008-09-30 10:29:52 UTC (rev 1532)
+++ trunk/pkg/dem/DataClass/InteractionGeometry/SpheresContactGeometry.hpp 2008-09-30 10:49:22 UTC (rev 1533)
@@ -67,7 +67,7 @@
void relocateContactPoints();
- SpheresContactGeometry():contactPoint(Vector3r::ZERO),radius1(0),radius2(0),hasShear(false){createIndex();}
+ SpheresContactGeometry():contactPoint(Vector3r::ZERO),radius1(0),radius2(0),hasShear(false),pos1(Vector3r::ZERO),pos2(Vector3r::ZERO){createIndex();}
virtual ~SpheresContactGeometry();
protected :
virtual void registerAttributes(){
Modified: trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.cpp
===================================================================
--- trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.cpp 2008-09-30 10:29:52 UTC (rev 1532)
+++ trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.cpp 2008-09-30 10:49:22 UTC (rev 1533)
@@ -14,6 +14,7 @@
InteractingSphere2InteractingSphere4SpheresContactGeometry::InteractingSphere2InteractingSphere4SpheresContactGeometry()
{
interactionDetectionFactor = 1;
+ hasShear=false;
}
void InteractingSphere2InteractingSphere4SpheresContactGeometry::registerAttributes()
Modified: trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.hpp
===================================================================
--- trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.hpp 2008-09-30 10:29:52 UTC (rev 1532)
+++ trunk/pkg/dem/Engine/EngineUnit/InteractingSphere2InteractingSphere4SpheresContactGeometry.hpp 2008-09-30 10:49:22 UTC (rev 1533)
@@ -25,7 +25,7 @@
* @note This parameter is functionally coupled with InteractinSphere2AABB::aabbEnlargeFactor,
* which will create larger bounding boxes and should be of the same value. */
double interactionDetectionFactor;
- /*! Whether we create SpheresContactGeometry with data necessary for (exact) shear computation */
+ /*! Whether we create SpheresContactGeometry with data necessary for (exact) shear computation. By default false */
bool hasShear;
REGISTER_CLASS_NAME(InteractingSphere2InteractingSphere4SpheresContactGeometry);