← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 4005: Body::groupMask may be optionally boost::python::long_, subsequently modified code where necessary

 

------------------------------------------------------------
revno: 4005
committer: Jan Stransky <jan.stransky@xxxxxxxxxxx>
timestamp: Thu 2014-06-05 15:19:44 +0200
message:
  Body::groupMask may be optionally boost::python::long_, subsequently modified code where necessary
modified:
  core/Body.hpp
  pkg/common/Collider.cpp
  pkg/common/GravityEngines.cpp
  pkg/dem/CapillaryTriaxialTest.cpp
  pkg/dem/CohesiveTriaxialTest.cpp
  pkg/dem/NewtonIntegrator.cpp
  pkg/dem/SimpleShear.cpp
  pkg/dem/SpheresFactory.cpp
  pkg/dem/TesselationWrapper.cpp
  pkg/dem/TriaxialTest.cpp
  pkg/dem/VTKRecorder.cpp


--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file 'core/Body.hpp'
--- core/Body.hpp	2014-05-23 13:05:19 +0000
+++ core/Body.hpp	2014-06-05 13:19:44 +0000
@@ -20,6 +20,7 @@
 #include<yade/lib/serialization/Serializable.hpp>
 #include<yade/lib/multimethods/Indexable.hpp>
 
+
 class Scene;
 class Interaction;
 
@@ -29,6 +30,13 @@
 		typedef int id_t;
 		// internal structure to hold some interaction of a body; used by InteractionContainer;
 		typedef std::map<Body::id_t, shared_ptr<Interaction> > MapId2IntrT;
+		// groupMask type
+#ifdef BODY_GROUP_MASK_ARBITRARY_PRECISION
+		typedef boost::python::long_ groupMask_t;
+#else
+		typedef int groupMask_t;
+#endif
+
 
 		// bits for Body::flags
 		enum { FLAG_BOUNDED=1, FLAG_ASPHERICAL=2 }; /* add powers of 2 as needed */
@@ -62,13 +70,18 @@
 		 * (otherwise, GLViewer would depend on Clump and therefore Clump would have to go to core...) */
 		virtual void userForcedDisplacementRedrawHook(){return;}
 
-    boost::python::list py_intrs();
+		boost::python::list py_intrs();
 
 		Body::id_t getId() const {return id;};
 		unsigned int coordNumber();  // Number of neighboring particles
 
-		int getGroupMask() {return groupMask; };
-		bool maskOk(int mask){return (mask==0 || (groupMask&mask));}
+		Body::groupMask_t getGroupMask() const {return groupMask; };
+		bool maskOk(int mask) const {return (mask==0 || (bool)(groupMask & mask));}
+		bool maskCompatible(int mask) const { return (bool)(groupMask & mask); }
+#ifdef BODY_GROUP_MASK_ARBITRARY_PRECISION
+		bool maskOk(const boost::python::long_& mask) const {return (mask==0 || (bool)(groupMask & mask));}
+		bool maskCompatible(const boost::python::long_& mask) const { return (bool)(groupMask & mask); }
+#endif
 
 		// only BodyContainer can set the id of a body
 		friend class BodyContainer;
@@ -76,7 +89,7 @@
 	YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY(Body,Serializable,"A particle, basic element of simulation; interacts with other bodies.",
 		((Body::id_t,id,Body::ID_NONE,Attr::readonly,"Unique id of this body."))
 
-		((int,groupMask,1,,"Bitmask for determining interactions."))
+		((Body::groupMask_t,groupMask,1,,"Bitmask for determining interactions."))
 		((int,flags,FLAG_BOUNDED,Attr::readonly,"Bits of various body-related flags. *Do not access directly*. In c++, use isDynamic/setDynamic, isBounded/setBounded, isAspherical/setAspherical. In python, use :yref:`Body.dynamic`, :yref:`Body.bounded`, :yref:`Body.aspherical`."))
 
 		((shared_ptr<Material>,material,,,":yref:`Material` instance associated with this body."))
@@ -122,3 +135,16 @@
 	);
 };
 REGISTER_SERIALIZABLE(Body);
+
+
+#ifdef BODY_GROUP_MASK_ARBITRARY_PRECISION
+namespace boost { namespace serialization {
+template<class Archive>
+void serialize(Archive & ar, boost::python::long_ & l, const unsigned int version){
+	namespace bp = boost::python;
+	std::string value = bp::extract<std::string>(bp::str(l));
+	ar & BOOST_SERIALIZATION_NVP(value);
+	l = bp::long_(value);
+}
+}} // namespace boost::serialization
+#endif

=== modified file 'pkg/common/Collider.cpp'
--- pkg/common/Collider.cpp	2014-05-23 13:05:19 +0000
+++ pkg/common/Collider.cpp	2014-06-05 13:19:44 +0000
@@ -20,9 +20,9 @@
 		 // do not collide clumps, since they are just containers, never interact
 		!b1->isClump() && !b2->isClump() &&
 		// masks must have at least 1 bit in common
-		(b1->groupMask & b2->groupMask)!=0 &&
+		b1->maskCompatible(b2->groupMask) &&
 		// avoid contact between particles having the same mask compatible with the avoidSelfInteractionMask.
- 		!( (b1->groupMask == b2->groupMask) && ( avoidSelfInteractionMask & b1->groupMask ))
+ 		!( (b1->groupMask == b2->groupMask) && b1->maskCompatible(avoidSelfInteractionMask) )
 	;
 }
 

=== modified file 'pkg/common/GravityEngines.cpp'
--- pkg/common/GravityEngines.cpp	2014-05-23 13:05:19 +0000
+++ pkg/common/GravityEngines.cpp	2014-06-05 13:19:44 +0000
@@ -22,7 +22,7 @@
 	YADE_PARALLEL_FOREACH_BODY_BEGIN(const shared_ptr<Body>& b, scene->bodies){
 		// skip clumps, only apply forces on their constituents
 		if(b->isClump()) continue;
-		if(mask!=0 && (b->groupMask & mask)==0) continue;
+		if(mask!=0 && !b->maskCompatible(mask)) continue;
 		scene->forces.addForce(b->getId(),gravity*b->state->mass);
 		// work done by gravity is "negative", since the energy appears in the system from outside
 		if(trackEnergy) scene->energy->add(-gravity.dot(b->state->vel)*b->state->mass*dt,"gravWork",fieldWorkIx,/*non-incremental*/false);
@@ -33,7 +33,7 @@
 	const Vector3r& centralPos=Body::byId(centralBody)->state->pos;
 	FOREACH(const shared_ptr<Body>& b, *scene->bodies){
 		if(b->isClump() || b->getId()==centralBody) continue; // skip clumps and central body
-		if(mask!=0 && (b->groupMask & mask)==0) continue;
+		if(mask!=0 && !b->maskCompatible(mask)) continue;
 		Real F=accel*b->state->mass;
 		Vector3r toCenter=centralPos-b->state->pos; toCenter.normalize();
 		scene->forces.addForce(b->getId(),F*toCenter);
@@ -44,7 +44,7 @@
 void AxialGravityEngine::action(){
 	FOREACH(const shared_ptr<Body>&b, *scene->bodies){
 		if(!b || b->isClump()) continue;
-		if(mask!=0 && (b->groupMask & mask)==0) continue;
+		if(mask!=0 && !b->maskCompatible(mask)) continue;
 		/* http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html */
 		const Vector3r& x0=b->state->pos;
 		const Vector3r& x1=axisPoint;

=== modified file 'pkg/dem/CapillaryTriaxialTest.cpp'
--- pkg/dem/CapillaryTriaxialTest.cpp	2014-05-23 13:20:43 +0000
+++ pkg/dem/CapillaryTriaxialTest.cpp	2014-06-05 13:19:44 +0000
@@ -209,7 +209,7 @@
 
 void CapillaryTriaxialTest::createSphere(shared_ptr<Body>& body, Vector3r position, Real radius, bool big, bool dynamic )
 {
-	body = shared_ptr<Body>(new Body); body->groupMask=2;
+	body = shared_ptr<Body>(new Body); body->groupMask=Body::groupMask_t(2);
 	shared_ptr<FrictMat> physics(new FrictMat);
 	shared_ptr<Aabb> aabb(new Aabb);
 
@@ -254,7 +254,7 @@
 
 void CapillaryTriaxialTest::createBox(shared_ptr<Body>& body, Vector3r position, Vector3r extents, bool wire)
 {
-	body = shared_ptr<Body>(new Body); body->groupMask=2;
+	body = shared_ptr<Body>(new Body); body->groupMask=Body::groupMask_t(2);
 	shared_ptr<FrictMat> physics(new FrictMat);
 	shared_ptr<Aabb> aabb(new Aabb);
 	shared_ptr<Box> iBox(new Box);

=== modified file 'pkg/dem/CohesiveTriaxialTest.cpp'
--- pkg/dem/CohesiveTriaxialTest.cpp	2014-05-23 13:05:19 +0000
+++ pkg/dem/CohesiveTriaxialTest.cpp	2014-06-05 13:19:44 +0000
@@ -200,7 +200,7 @@
 
 void CohesiveTriaxialTest::createSphere(shared_ptr<Body>& body, Vector3r position, Real radius, bool dynamic )
 {
-	body = shared_ptr<Body>(new Body); body->groupMask=2;
+	body = shared_ptr<Body>(new Body); body->groupMask=Body::groupMask_t(2);
 	shared_ptr<CohFrictMat> physics(new CohFrictMat);
 	shared_ptr<Aabb> aabb(new Aabb);
 	shared_ptr<Sphere> iSphere(new Sphere);
@@ -243,7 +243,7 @@
 
 void CohesiveTriaxialTest::createBox(shared_ptr<Body>& body, Vector3r position, Vector3r extents, bool wire)
 {
-	body = shared_ptr<Body>(new Body); body->groupMask=2;
+	body = shared_ptr<Body>(new Body); body->groupMask=Body::groupMask_t(2);
 	shared_ptr<CohFrictMat> physics(new CohFrictMat);
 	shared_ptr<Aabb> aabb(new Aabb);
 

=== modified file 'pkg/dem/NewtonIntegrator.cpp'
--- pkg/dem/NewtonIntegrator.cpp	2014-05-23 13:05:19 +0000
+++ pkg/dem/NewtonIntegrator.cpp	2014-06-05 13:19:44 +0000
@@ -229,7 +229,7 @@
 		//Reflect mean-field (periodic cell) acceleration in the velocity
 	if(scene->isPeriodic && homoDeform) {Vector3r dVel=dVelGrad*state->pos; state->vel+=dVel;}
 	
-	if ( (mask<=0) or ((mask>0) and ((Body::byId(id)->groupMask & mask)!=0)) ) {
+	if ( (mask<=0) or ((mask>0) and (Body::byId(id)->maskCompatible(mask))) ) {
 		state->pos+=state->vel*dt;
 	}
 }
@@ -237,13 +237,13 @@
 void NewtonIntegrator::leapfrogSphericalRotate(State* state, const Body::id_t& id, const Real& dt )
 {
 	Real angle2=state->angVel.squaredNorm();
-	if (angle2!=0 and ( (mask<=0) or ((mask>0) and ((Body::byId(id)->groupMask & mask)!=0)) )) {//If we have an angular velocity, we make a rotation
+	if (angle2!=0 and ( (mask<=0) or ((mask>0) and (Body::byId(id)->maskCompatible(mask))) )) {//If we have an angular velocity, we make a rotation
 		Real angle=sqrt(angle2);
 		Quaternionr q(AngleAxisr(angle*dt,state->angVel/angle));
 		state->ori = q*state->ori;
 	}
 	if(scene->forces.getMoveRotUsed() && scene->forces.getRot(id)!=Vector3r::Zero() 
-		and ( (mask<=0) or ((mask>0) and ((Body::byId(id)->groupMask & mask)!=0)) )) {
+		and ( (mask<=0) or ((mask>0) and (Body::byId(id)->maskCompatible(mask))) )) {
 		Vector3r r(scene->forces.getRot(id));
 		Real norm=r.norm(); r/=norm;
 		Quaternionr q(AngleAxisr(norm,r));

=== modified file 'pkg/dem/SimpleShear.cpp'
--- pkg/dem/SimpleShear.cpp	2014-05-23 13:05:19 +0000
+++ pkg/dem/SimpleShear.cpp	2014-06-05 13:19:44 +0000
@@ -116,7 +116,7 @@
 
 void SimpleShear::createSphere(shared_ptr<Body>& body, Vector3r position, Real radius)
 {
-	body = shared_ptr<Body>(new Body); body->groupMask=1;
+	body = shared_ptr<Body>(new Body); body->groupMask=Body::groupMask_t(1);
 	shared_ptr<NormalInelasticMat> mat(new NormalInelasticMat);
 	shared_ptr<Aabb> aabb(new Aabb);
 	shared_ptr<Sphere> iSphere(new Sphere);
@@ -147,7 +147,7 @@
 
 void SimpleShear::createBox(shared_ptr<Body>& body, Vector3r position, Vector3r extents)
 {
-	body = shared_ptr<Body>(new Body); body->groupMask=1;
+	body = shared_ptr<Body>(new Body); body->groupMask=Body::groupMask_t(1);
 	shared_ptr<NormalInelasticMat> mat(new NormalInelasticMat);
 	shared_ptr<Aabb> aabb(new Aabb);
 // 	shared_ptr<BoxModel> gBox(new BoxModel);

=== modified file 'pkg/dem/SpheresFactory.cpp'
--- pkg/dem/SpheresFactory.cpp	2014-05-23 13:05:19 +0000
+++ pkg/dem/SpheresFactory.cpp	2014-06-05 13:19:44 +0000
@@ -182,7 +182,7 @@
 		b->shape=sphere; 
 		b->state=state; 
 		b->material=material;
-		if (mask>0) {b->groupMask=mask;}
+		if (mask>0) {b->groupMask=Body::groupMask_t(mask);}
 		// insert particle in the simulation
 		scene->bodies->insert(b);
 		ids.push_back(b->getId());

=== modified file 'pkg/dem/TesselationWrapper.cpp'
--- pkg/dem/TesselationWrapper.cpp	2014-05-23 13:05:19 +0000
+++ pkg/dem/TesselationWrapper.cpp	2014-06-05 13:19:44 +0000
@@ -306,7 +306,7 @@
 
 void createSphere(shared_ptr<Body>& body, Vector3r position, Real radius, bool big, bool dynamic )
 {
-	body = shared_ptr<Body>(new Body); body->groupMask=2;
+	body = shared_ptr<Body>(new Body); body->groupMask=Body::groupMask_t(2);
 	shared_ptr<Sphere> iSphere(new Sphere);
 	body->state->blockedDOFs=State::DOF_NONE;
 	body->state->pos=position;

=== modified file 'pkg/dem/TriaxialTest.cpp'
--- pkg/dem/TriaxialTest.cpp	2014-05-23 13:05:19 +0000
+++ pkg/dem/TriaxialTest.cpp	2014-06-05 13:19:44 +0000
@@ -187,7 +187,7 @@
 
 void TriaxialTest::createSphere(shared_ptr<Body>& body, Vector3r position, Real radius, bool big, bool dynamic )
 {
-	body = shared_ptr<Body>(new Body); body->groupMask=2;
+	body = shared_ptr<Body>(new Body); body->groupMask=Body::groupMask_t(2);
 	shared_ptr<Aabb> aabb(new Aabb);
 	shared_ptr<Sphere> iSphere(new Sphere);
 	body->state->blockedDOFs=State::DOF_NONE;
@@ -213,7 +213,7 @@
 
 void TriaxialTest::createBox(shared_ptr<Body>& body, Vector3r position, Vector3r extents, bool wire)
 {
-	body = shared_ptr<Body>(new Body); body->groupMask=2;
+	body = shared_ptr<Body>(new Body); body->groupMask=Body::groupMask_t(2);
 	body->state->blockedDOFs=State::DOF_ALL;
 	shared_ptr<Aabb> aabb(new Aabb);
 	aabb->color		= Vector3r(1,0,0);

=== modified file 'pkg/dem/VTKRecorder.cpp'
--- pkg/dem/VTKRecorder.cpp	2014-05-23 13:05:19 +0000
+++ pkg/dem/VTKRecorder.cpp	2014-06-05 13:19:44 +0000
@@ -37,6 +37,12 @@
 YADE_PLUGIN((VTKRecorder));
 CREATE_LOGGER(VTKRecorder);
 
+#ifdef BODY_GROUP_MASK_ARBITRARY_PRECISION
+#define GET_MASK(b) boost::python::extract<int>(b->groupMask)
+#else
+#define GET_MASK(b) b->groupMask
+#endif
+
 void VTKRecorder::action(){
 	vector<bool> recActive(REC_SENTINEL,false);
 	FOREACH(string& rec, recorders){
@@ -414,7 +420,7 @@
 	
 	FOREACH(const shared_ptr<Body>& b, *scene->bodies){
 		if (!b) continue;
-		if(mask!=0 && (b->groupMask & mask)==0) continue;
+		if(mask!=0 && !b->maskCompatible(mask)) continue;
 		if (recActive[REC_SPHERES]){
 			const Sphere* sphere = dynamic_cast<Sphere*>(b->shape.get()); 
 			if (sphere){
@@ -425,7 +431,7 @@
 				spheresCells->InsertNextCell(1,pid);
 				radii->InsertNextValue(sphere->radius);
 				if (recActive[REC_ID]) spheresId->InsertNextValue(b->getId()); 
-				if (recActive[REC_MASK]) spheresMask->InsertNextValue(b->groupMask);
+				if (recActive[REC_MASK]) spheresMask->InsertNextValue(GET_MASK(b));
 				if (recActive[REC_MASS]) spheresMass->InsertNextValue(b->state->mass);
 				if (recActive[REC_CLUMPID]) clumpId->InsertNextValue(b->clumpId);
 				if (recActive[REC_COLORS]){
@@ -508,7 +514,7 @@
 					facetsForceLen->InsertNextValue(stress.norm());
 				}
 				if (recActive[REC_MATERIALID]) facetsMaterialId->InsertNextValue(b->material->id);
-				if (recActive[REC_MASK]) facetsMask->InsertNextValue(b->groupMask);
+				if (recActive[REC_MASK]) facetsMask->InsertNextValue(GET_MASK(b));
 				continue;
 			}
 		}
@@ -560,7 +566,7 @@
 						boxesForceLen->InsertNextValue(stress.norm());
 					}
 					if (recActive[REC_MATERIALID]) boxesMaterialId->InsertNextValue(b->material->id);
-					if (recActive[REC_MASK]) boxesMask->InsertNextValue(b->groupMask);
+					if (recActive[REC_MASK]) boxesMask->InsertNextValue(GET_MASK(b));
 				}
 				continue;
 			}
@@ -885,3 +891,4 @@
 };
 
 #endif /* YADE_VTK */
+#undef GET_MASK