← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2824: 1. Move Dragengine from SphereFactory to ForceEngine.

 

------------------------------------------------------------
revno: 2824
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
branch nick: yade
timestamp: Wed 2011-04-20 15:10:23 +0200
message:
  1. Move Dragengine from SphereFactory to ForceEngine.
  2. Fixes in ForceEngine (crashed, when force applied to non existing body)
modified:
  pkg/common/ForceEngine.cpp
  pkg/common/ForceEngine.hpp
  pkg/dem/SpheresFactory.cpp
  pkg/dem/SpheresFactory.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 'pkg/common/ForceEngine.cpp'
--- pkg/common/ForceEngine.cpp	2011-02-27 13:54:43 +0000
+++ pkg/common/ForceEngine.cpp	2011-04-20 13:10:23 +0000
@@ -4,17 +4,18 @@
 
 #include"ForceEngine.hpp"
 #include<yade/core/Scene.hpp>
+#include<yade/pkg/common/Sphere.hpp>
 #include<yade/lib/smoothing/LinearInterpolate.hpp>
 #include<yade/pkg/dem/Shop.hpp>
 
 #include<yade/core/IGeom.hpp>
 #include<yade/core/IPhys.hpp>
 
-YADE_PLUGIN((ForceEngine)(InterpolatingDirectedForceEngine)(RadialForceEngine));
+YADE_PLUGIN((ForceEngine)(InterpolatingDirectedForceEngine)(RadialForceEngine)(DragEngine));
 
 void ForceEngine::action(){
 	FOREACH(Body::id_t id, ids){
-		assert(scene->bodies->exists(id));
+		if (!(scene->bodies->exists(id))) continue;
 		scene->forces.addForce(id,force);
 	}
 }
@@ -30,10 +31,29 @@
 
 void RadialForceEngine::action(){
 	FOREACH(Body::id_t id, ids){
-		assert(scene->bodies->exists(id));
+		if (!(scene->bodies->exists(id))) continue;
 		const Vector3r& pos=Body::byId(id,scene)->state->pos;
 		Vector3r radial=(pos - (axisPt+axisDir * /* t */ ((pos-axisPt).dot(axisDir)))).normalized();
 		if(radial.squaredNorm()==0) continue;
 		scene->forces.addForce(id,fNorm*radial);
 	}
 }
+
+void DragEngine::action(){
+	FOREACH(Body::id_t id, ids){
+		Body* b=Body::byId(id,scene).get();
+		if (!b) continue;
+		if (!(scene->bodies->exists(id))) continue;
+		const Sphere* sphere = dynamic_cast<Sphere*>(b->shape.get());
+		if (sphere){
+			Real A = sphere->radius*sphere->radius*Mathr::PI;	//Crossection of the sphere
+			Vector3r velSphTemp = b->state->vel;
+			Vector3r dragForce = Vector3r::Zero();
+			
+			if (velSphTemp != Vector3r::Zero()) {
+				dragForce = -0.5*Rho*A*Cd*velSphTemp.squaredNorm()*velSphTemp.normalized();
+			}
+			scene->forces.addForce(id,dragForce);
+		}
+	}
+}

=== modified file 'pkg/common/ForceEngine.hpp'
--- pkg/common/ForceEngine.hpp	2011-02-27 13:54:43 +0000
+++ pkg/common/ForceEngine.hpp	2011-04-20 13:10:23 +0000
@@ -48,3 +48,13 @@
 	);
 };
 REGISTER_SERIALIZABLE(RadialForceEngine);
+
+class DragEngine: public PartialEngine{
+	public:
+		virtual void action();
+	YADE_CLASS_BASE_DOC_ATTRS(DragEngine,PartialEngine,"Apply `drag force <http://en.wikipedia.org/wiki/Drag_equation>`__ on some particles at each step, decelerating them proportionally to their linear velocities. The applied force reads\n\n.. math:: F_{d}=-\\frac{\\vec{v}}{|\\vec{v}|}\\frac{1}{2}\\rho|\\vec{v}|^2 C_d A\n\nwhere $\\rho$ is the medium density (:yref:`density<DragEngine.Rho>`), $v$ is particle's velocity,  $A$ is particle projected area (disc), $C_d$ is the drag coefficient (0.47 for :yref:`Sphere`), \n\n.. note:: Drag force is only applied to spherical particles, listed in ids.",
+		((Real,Rho,1.225,,"Density of the medium (fluid or air), by default - the density of the air."))
+		((Real,Cd,0.47,,"Drag coefficient <http://en.wikipedia.org/wiki/Drag_coefficient>`_."))
+	);
+};
+REGISTER_SERIALIZABLE(DragEngine);

=== modified file 'pkg/dem/SpheresFactory.cpp'
--- pkg/dem/SpheresFactory.cpp	2011-02-14 08:05:09 +0000
+++ pkg/dem/SpheresFactory.cpp	2011-04-20 13:10:23 +0000
@@ -6,22 +6,12 @@
 #include <boost/random/variate_generator.hpp>
 
 
-//YADE_PLUGIN((SpheresFactory)(DragForceApplier));
-YADE_PLUGIN((SpheresFactory)(CircularFactory)(BoxFactory)(DragForceApplier));
+
+YADE_PLUGIN((SpheresFactory)(CircularFactory)(BoxFactory));
 CREATE_LOGGER(SpheresFactory);
 CREATE_LOGGER(CircularFactory);
 CREATE_LOGGER(BoxFactory);
 
-void DragForceApplier::action(){
-	FOREACH(const shared_ptr<Body>& b, *scene->bodies){
-		if(!b) continue;
-		Sphere* sphere=dynamic_cast<Sphere*>(b->shape.get());
-		if(!sphere) continue;
-		Vector3r dragForce=-b->state->vel.normalized()*(1/2.)*density*b->state->vel.squaredNorm()*.47*Mathr::PI*pow(sphere->radius,2);
-		scene->forces.addForce(b->id,dragForce);
-	}
-}
-
 // initialize random number generator with time seed
 static boost::minstd_rand randGen(TimingInfo::getNow(/* get the number even if timing is disabled globally */ true));
 static boost::variate_generator<boost::minstd_rand&, boost::uniform_real<Real> > randomUnit(randGen, boost::uniform_real<Real>(0,1));

=== modified file 'pkg/dem/SpheresFactory.hpp'
--- pkg/dem/SpheresFactory.hpp	2011-02-21 14:45:36 +0000
+++ pkg/dem/SpheresFactory.hpp	2011-04-20 13:10:23 +0000
@@ -58,11 +58,3 @@
 	);
 };
 REGISTER_SERIALIZABLE(BoxFactory);
-
-class DragForceApplier: public GlobalEngine{
-	public: virtual void action();
-	YADE_CLASS_BASE_DOC_ATTRS(DragForceApplier,GlobalEngine,"Apply `drag force <http://en.wikipedia.org/wiki/Drag_equation>`__ on particles, decelerating them proportionally to their linear velocities. The applied force reads\n\n.. math:: F_{d}=-\\frac{\\vec{v}}{|\\vec{v}|}\\frac{1}{2}\\rho|\\vec{v}|^2 C_d A\n\nwhere $\\rho$ is the medium density (:yref:`density<DragForceApplier.density>`), $v$ is particle's velocity,  $A$ is particle projected area (disc), $C_d$ is the drag coefficient (0.47 for :yref:`Sphere`), \n\n.. note:: Drag force is only applied to spherical particles.\n\n.. warning:: Not tested.",
-		((Real,density,0,,"Density of the medium."))
-	);
-};
-REGISTER_SERIALIZABLE(DragForceApplier);