yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #10212
[Branch ~yade-pkg/yade/git-trunk] Rev 3752: Add BicyclePedalEngine as a new kinematic motion.
------------------------------------------------------------
revno: 3752
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
timestamp: Mon 2013-11-11 17:22:15 +0100
message:
Add BicyclePedalEngine as a new kinematic motion.
See an example in examples/baraban/BicyclePedalEngine.py
added:
examples/baraban/BicyclePedalEngine.py
modified:
pkg/common/KinematicEngines.cpp
pkg/common/KinematicEngines.hpp
--
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
=== added file 'examples/baraban/BicyclePedalEngine.py'
--- examples/baraban/BicyclePedalEngine.py 1970-01-01 00:00:00 +0000
+++ examples/baraban/BicyclePedalEngine.py 2013-11-11 16:22:15 +0000
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+import time
+
+## PhysicalParameters
+Density=2400
+frictionAngle=radians(35)
+tc = 0.001
+en = 0.3
+es = 0.3
+
+## Import wall's geometry
+params=getViscoelasticFromSpheresInteraction(tc,en,es)
+facetMat=O.materials.append(ViscElMat(frictionAngle=frictionAngle,**params)) # **params sets kn, cn, ks, cs
+sphereMat=O.materials.append(ViscElMat(density=Density,frictionAngle=frictionAngle,**params))
+from yade import ymport
+fctIds=O.bodies.append(ymport.stl('baraban.stl',color=(1,0,0),material=facetMat))
+## Spheres
+sphereRadius = 0.2
+nbSpheres = (10,10,10)
+#nbSpheres = (50,50,50)
+for i in xrange(nbSpheres[0]):
+ for j in xrange(nbSpheres[1]):
+ for k in xrange(nbSpheres[2]):
+ x = (i*2 - nbSpheres[0])*sphereRadius*1.1
+ y = (j*2 - nbSpheres[1])*sphereRadius*1.1
+ z = (k*2 - nbSpheres[2])*sphereRadius*1.1
+ s=sphere([x,y,z],sphereRadius,material=sphereMat)
+ O.bodies.append(s)
+
+## Timestep
+O.dt=.2*tc
+
+## Engines
+O.engines=[
+ ## Resets forces and momenta the act on bodies
+ ForceResetter(),
+ ## Using bounding boxes find possible body collisions.
+ InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
+ ## Interactions
+ InteractionLoop(
+ ## Create geometry information about each potential collision.
+ [Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom()],
+ ## Create physical information about the interaction.
+ [Ip2_ViscElMat_ViscElMat_ViscElPhys()],
+ ## Constitutive law
+ [Law2_ScGeom_ViscElPhys_Basic()],
+ ),
+ ## Apply gravity
+ ## Cundall damping must been disabled!
+ NewtonIntegrator(damping=0,gravity=[0,-9.81,0]),
+## Saving results
+ #VTKRecorder(virtPeriod=0.04,fileName='/tmp/stlimp-',recorders=['spheres','facets']),
+ ## Apply kinematics to walls
+ BicyclePedalEngine(ids=fctIds,rotationAxis=[0,0,1],radius = 1.2,angularVelocity=4.0)
+]
+
+from yade import qt
+qt.View()
+#O.saveTmp()
+#O.run()
+
=== modified file 'pkg/common/KinematicEngines.cpp'
--- pkg/common/KinematicEngines.cpp 2013-10-16 13:48:29 +0000
+++ pkg/common/KinematicEngines.cpp 2013-11-11 16:22:15 +0000
@@ -4,7 +4,7 @@
#include<yade/pkg/dem/Shop.hpp>
#include<yade/lib/smoothing/LinearInterpolate.hpp>
-YADE_PLUGIN((KinematicEngine)(CombinedKinematicEngine)(TranslationEngine)(HarmonicMotionEngine)(RotationEngine)(HelixEngine)(InterpolatingHelixEngine)(HarmonicRotationEngine)(ServoPIDController));
+YADE_PLUGIN((KinematicEngine)(CombinedKinematicEngine)(TranslationEngine)(HarmonicMotionEngine)(RotationEngine)(HelixEngine)(InterpolatingHelixEngine)(HarmonicRotationEngine)(ServoPIDController)(BicyclePedalEngine));
CREATE_LOGGER(KinematicEngine);
@@ -109,7 +109,6 @@
}
}
-
void RotationEngine::apply(const vector<Body::id_t>& ids){
if (ids.size()>0) {
#ifdef YADE_OPENMP
@@ -183,3 +182,33 @@
TranslationEngine::apply(ids);
}
+
+void BicyclePedalEngine::apply(const vector<Body::id_t>& ids){
+ if (ids.size()>0) {
+ Quaternionr qRotateZVec(Quaternionr().setFromTwoVectors(Vector3r(0,0,1), rotationAxis));
+
+ Vector3r newPos = Vector3r(cos(fi + angularVelocity*scene->dt)*radius, sin(fi + angularVelocity*scene->dt)*radius, 0.0);
+ Vector3r oldPos = Vector3r(cos(fi)*radius, sin(fi)*radius, 0.0);
+
+ Vector3r newVel = (oldPos - newPos)/scene->dt;
+
+ fi += angularVelocity*scene->dt;
+ newVel = qRotateZVec*newVel;
+
+ #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->vel+=newVel;
+ }
+ } else {
+ LOG_WARN("The list of ids is empty! Can't move any body.");
+ }
+}
=== modified file 'pkg/common/KinematicEngines.hpp'
--- pkg/common/KinematicEngines.hpp 2013-07-04 17:36:34 +0000
+++ pkg/common/KinematicEngines.hpp 2013-11-11 16:22:15 +0000
@@ -115,3 +115,15 @@
DECLARE_LOGGER;
};
REGISTER_SERIALIZABLE(ServoPIDController);
+
+struct BicyclePedalEngine: public KinematicEngine{
+ virtual void apply(const vector<Body::id_t>& ids);
+ void postLoad(BicyclePedalEngine&){ rotationAxis.normalize(); }
+ YADE_CLASS_BASE_DOC_ATTRS(BicyclePedalEngine,KinematicEngine,"Engine applying the linear motion of ``bicycle pedal`` e.g. moving points around the axis without rotation",
+ ((Real,angularVelocity,0,,"Angular velocity. [rad/s]"))
+ ((Vector3r,rotationAxis,Vector3r::UnitX(),Attr::triggerPostLoad,"Axis of rotation (direction); will be normalized automatically."))
+ ((Real,radius,-1.0,,"Rotation radius. [m]"))
+ ((Real,fi,Mathr::PI/2.0,,"Initial phase [radians]"))
+ );
+};
+REGISTER_SERIALIZABLE(BicyclePedalEngine);