← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2562: 1. HarmonicRotationEngine is added including example in regular-sphere-pack.py

 

------------------------------------------------------------
revno: 2562
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-11-19 13:06:23 +0100
message:
  1. HarmonicRotationEngine is added including example in regular-sphere-pack.py
  2. TranslationEngine is parallelized with OpenMP.
  3. Translation and Rotation engines are working with Dynamic-bodies properly (temporal solution).
modified:
  examples/regular-sphere-pack/regular-sphere-pack.py
  pkg/common/RotationEngine.cpp
  pkg/common/RotationEngine.hpp
  pkg/common/TranslationEngine.cpp
  pkg/common/TranslationEngine.hpp


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

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription
=== modified file 'examples/regular-sphere-pack/regular-sphere-pack.py'
--- examples/regular-sphere-pack/regular-sphere-pack.py	2010-11-19 09:10:54 +0000
+++ examples/regular-sphere-pack/regular-sphere-pack.py	2010-11-19 12:06:23 +0000
@@ -75,10 +75,16 @@
 O.bodies.append(ymport.text('regular-sphere-pack-FromFile',shift=Vector3(6.0,6.0,-2.9),scale=0.7,color=(1,1,1),**kw))
 
 #Demonstration of HarmonicMotionEngine
-O.bodies.append(pack.regularHexa(pack.inSphere((-10,5,-5),1.5),radius=rad*2.0,gap=gap,color=(0.2,0.5,0.9),material=0))
+O.bodies.append(pack.regularHexa(pack.inSphere((-10,5,-5),1.5),radius=rad*2.0,gap=rad/3.0,color=(0.2,0.5,0.9),material=0))
 O.bodies.append(utils.facetBox((-10,5,-5),(2,2,2),wallMask=15,**kwMeshes))
 vibrationPlate = O.bodies.append(utils.facetBox((-10,5,-5),(2,2,2),wallMask=16,**kwBoxes))
 
+#Demonstration of HarmonicRotationEngine
+O.bodies.append(pack.regularHexa(pack.inSphere((-15,5,-5),1.5),radius=rad*2.0,gap=rad/3.0,color=(0.5,0.5,0.1),material=0))
+O.bodies.append(utils.facetBox((-15,5,-5),(2,2,2),wallMask=15,**kwMeshes))
+vibrationRotationPlate = O.bodies.append(utils.facetBox((-15,5,-5),(2,2,2),wallMask=16,**kwBoxes))
+
+
 
 try:
 	from yade import qt
@@ -102,7 +108,8 @@
 		rotationAxis=[0,0,1],
 		rotateAroundZero=1,
 		zeroPoint=[6.0,6.0,0.0]),
-	HarmonicMotionEngine(A=[0,0,0.5], f=[0,0,50.0], fi = [0.0,0.0,pi], ids = vibrationPlate)
+	HarmonicMotionEngine(A=[0,0,0.5], f=[0,0,20.0], fi = [0.0,0.0,pi], ids = vibrationPlate),
+	HarmonicRotationEngine(A=0.2, f=20.0, fi = pi, rotationAxis=[1.0,0.0,0.0], rotateAroundZero = True, zeroPoint = [-15.0,3.0,-7.0], ids = vibrationRotationPlate) 
 ]
 # we don't care about physical accuracy here, (over)critical step is fine as long as the simulation doesn't explode
 O.dt=utils.PWaveTimeStep()

=== modified file 'pkg/common/RotationEngine.cpp'
--- pkg/common/RotationEngine.cpp	2010-11-07 11:46:20 +0000
+++ pkg/common/RotationEngine.cpp	2010-11-19 12:06:23 +0000
@@ -9,7 +9,7 @@
 
 #include<yade/pkg/common/LinearInterpolate.hpp>
 
-YADE_PLUGIN((RotationEngine)(HelixEngine)(InterpolatingHelixEngine));
+YADE_PLUGIN((RotationEngine)(HelixEngine)(InterpolatingHelixEngine)(HarmonicRotationEngine));
 
 void InterpolatingHelixEngine::action(){
 	Real virtTime=wrap ? Shop::periodicWrap(scene->time,*times.begin(),*times.rbegin()) : scene->time;
@@ -54,15 +54,26 @@
 	#else
 	FOREACH(Body::id_t id,ids){
 	#endif
-		State* state=Body::byId(id,scene)->state.get();
-		state->angVel=rotationAxis*angularVelocity;
+		assert(id<(Body::id_t)scene->bodies->size());
+		Body* b=Body::byId(id,scene).get();
+		if(!b) continue;
+		
+		b->state->angVel=rotationAxis*angularVelocity;
 		if(rotateAroundZero){
-			const Vector3r l=state->pos-zeroPoint;
-			state->pos=q*l+zeroPoint; 
-			state->vel=state->angVel.cross(l);
-		}
-	state->ori=q*state->ori;
-	state->ori.normalize();
+			const Vector3r l=b->state->pos-zeroPoint;
+			if (!b->isDynamic())	b->state->pos=q*l+zeroPoint; 
+			b->state->vel=b->state->angVel.cross(l);
+		}
+		if (!b->isDynamic())	{
+			b->state->ori=q*b->state->ori;
+			b->state->ori.normalize();
+		}
 	}
 }
 
+void HarmonicRotationEngine::action(){
+	const Real& time=scene->time;
+	Real w = f*2.0*Mathr::PI; 			//Angular frequency
+	angularVelocity = -1.0*A*w*sin(w*time + fi);
+	RotationEngine::action();
+}

=== modified file 'pkg/common/RotationEngine.hpp'
--- pkg/common/RotationEngine.hpp	2010-11-07 11:46:20 +0000
+++ pkg/common/RotationEngine.hpp	2010-11-19 12:06:23 +0000
@@ -60,6 +60,13 @@
 };
 REGISTER_SERIALIZABLE(InterpolatingHelixEngine);
 
-
-
-
+class HarmonicRotationEngine:public RotationEngine{
+	public:
+	virtual void action();
+	YADE_CLASS_BASE_DOC_ATTRS(HarmonicRotationEngine,RotationEngine,"This engine implements the harmonic-rotation oscillation of bodies. http://en.wikipedia.org/wiki/Simple_harmonic_motion#Dynamics_of_simple_harmonic_motion ; please, set dynamic=False for bodies, droven by this engine, otherwise amplitude will be 2x more, than awaited.",
+		((Real,A,0,,"Amplitude [rad]"))
+		((Real,f,0,,"Frequency [hertz]"))
+		((Real,fi,Mathr::PI/2.0,,"Initial phase [radians]. By default, the body oscillates around initial position."))
+	);
+};
+REGISTER_SERIALIZABLE(HarmonicRotationEngine);

=== modified file 'pkg/common/TranslationEngine.cpp'
--- pkg/common/TranslationEngine.cpp	2010-11-19 09:10:54 +0000
+++ pkg/common/TranslationEngine.cpp	2010-11-19 12:06:23 +0000
@@ -11,11 +11,18 @@
 
 void TranslationEngine::action(){
 	const Real& dt=scene->dt;
+	#ifdef YADE_OPENMP
+	const long size=ids.size();
+	#pragma omp parallel for schedule(static)
+	for(long i=0; i<size; i++){
+		const Body::id_t& id=ids[i];
+	#else
 	FOREACH(Body::id_t id,ids){
+	#endif
 		assert(id<(Body::id_t)scene->bodies->size());
 		Body* b=Body::byId(id,scene).get();
 		if(!b) continue;
-		b->state->pos+=dt*velocity*translationAxis;
+		if (!b->isDynamic())	b->state->pos+=dt*velocity*translationAxis;
 		b->state->vel=velocity*translationAxis;
 	}
 }
@@ -23,16 +30,15 @@
 void HarmonicMotionEngine::action(){
 	const Real& dt=scene->dt;
 	const Real& time=scene->time;
-	Vector3r w = f*2.0*Mathr::PI; 			//Angular frequency
-	Vector3r velocity = ((((w*time + fi).cwise().sin())*(-1.0)).cwise()*A).cwise()*w; //Linear velocity at current time
+	Vector3r w = f*2.0*Mathr::PI; 																										//Angular frequency
+	Vector3r velocity = ((((w*time + fi).cwise().sin())*(-1.0)).cwise()*A).cwise()*w;	//Linear velocity at current time
 	
 	FOREACH(Body::id_t id,ids){
 		assert(id<(Body::id_t)scene->bodies->size());
 		Body* b=Body::byId(id,scene).get();
 		if(!b) continue;
-		
 		b->state->vel=velocity;
-		b->state->pos+=dt*velocity;
+		if (!b->isDynamic())	b->state->pos+=dt*velocity;
 	}
 }
 

=== modified file 'pkg/common/TranslationEngine.hpp'
--- pkg/common/TranslationEngine.hpp	2010-11-19 09:10:54 +0000
+++ pkg/common/TranslationEngine.hpp	2010-11-19 12:06:23 +0000
@@ -21,18 +21,17 @@
 		((Vector3r,translationAxis,,,"Direction [Vector3]"))
 	);
 };
+REGISTER_SERIALIZABLE(TranslationEngine);
 
-class HarmonicMotionEngine : public TranslationEngine {
+class HarmonicMotionEngine : public PartialEngine {
 	public:
 		virtual void action();
-	YADE_CLASS_BASE_DOC_ATTRS(HarmonicMotionEngine,TranslationEngine,"This engine implements the harmonic oscillation of bodies. http://en.wikipedia.org/wiki/Simple_harmonic_motion#Dynamics_of_simple_harmonic_motion ; please, set dynamic=False for bodies, droven by this engine, otherwise amplitude will be 2x more, than awaited.",
+	YADE_CLASS_BASE_DOC_ATTRS(HarmonicMotionEngine,PartialEngine,"This engine implements the harmonic oscillation of bodies. http://en.wikipedia.org/wiki/Simple_harmonic_motion#Dynamics_of_simple_harmonic_motion";,
 		((Vector3r,A,Vector3r::Zero(),,"Amplitude [m]"))
 		((Vector3r,f,Vector3r::Zero(),,"Frequency [hertz]"))
 		((Vector3r,fi,Vector3r(Mathr::PI/2.0, Mathr::PI/2.0, Mathr::PI/2.0),,"Initial phase [radians]. By default, the body oscillates around initial position."))
 	);
 };
-
-REGISTER_SERIALIZABLE(TranslationEngine);
 REGISTER_SERIALIZABLE(HarmonicMotionEngine);