← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 1753: SpheresFactory now can create a spheres by python function. See scripts/test/SpheresFactory/model...

 

------------------------------------------------------------
revno: 1753
committer: Sergei D. <sega@laptop>
branch nick: trunk
timestamp: Tue 2009-09-01 16:34:25 +0400
message:
  SpheresFactory now can create a spheres by python function. See scripts/test/SpheresFactory/model.py for example.
modified:
  pkg/common/Engine/StandAloneEngine/SpheresFactory.cpp
  pkg/common/Engine/StandAloneEngine/SpheresFactory.hpp
  py/utils.py
  scripts/test/SpheresFactory/model.py


--
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/Engine/StandAloneEngine/SpheresFactory.cpp'
--- pkg/common/Engine/StandAloneEngine/SpheresFactory.cpp	2009-08-26 10:34:11 +0000
+++ pkg/common/Engine/StandAloneEngine/SpheresFactory.cpp	2009-09-01 12:34:25 +0000
@@ -14,9 +14,10 @@
 #include<yade/pkg-common/Sphere.hpp>
 #include<yade/pkg-dem/BodyMacroParameters.hpp>
 #include"SpheresFactory.hpp"
+#include<sstream>
 
 YADE_PLUGIN((SpheresFactory));
-
+YADE_REQUIRE_FEATURE(PYTHON)
 CREATE_LOGGER(SpheresFactory);
 
 namespace {
@@ -43,6 +44,7 @@
 	density 	= 2400;
 	first_run = true;
 	color=Vector3r(0.8,0.8,0.8);
+	pySpheresCreator="";
 }
 
 SpheresFactory::~SpheresFactory()
@@ -102,8 +104,20 @@
 			}
 			if (is_overlap) continue;
 		}
-		ncb->bodies->insert(sphere);
-		bI->action(ncb);
+		if (pySpheresCreator!="")
+		{
+			ostringstream command;
+			command << pySpheresCreator << "((" << position[0] << ',' << position[1] << ',' << position[2] << ")," << r << ')';
+			PyGILState_STATE gstate;
+				gstate = PyGILState_Ensure();
+				PyRun_SimpleString(command.str().c_str()); 
+			PyGILState_Release(gstate);
+		}
+		else
+		{
+			ncb->bodies->insert(sphere);
+		}
+		//bI->action(ncb);
 		return;
 	}
 	LOG_WARN("Can't placing sphere during " << maxAttempts << " attemps.");

=== modified file 'pkg/common/Engine/StandAloneEngine/SpheresFactory.hpp'
--- pkg/common/Engine/StandAloneEngine/SpheresFactory.hpp	2009-08-26 10:34:11 +0000
+++ pkg/common/Engine/StandAloneEngine/SpheresFactory.hpp	2009-09-01 12:34:25 +0000
@@ -69,6 +69,9 @@
 	/// @brief Color.
 	Vector3r color;
 
+	/// @brief python's function for a spheres creation
+	string pySpheresCreator;
+
 private:
 	/// @brief Pointer to Collider.
 	/// It is necessary in order to probe the bounding volume for new sphere.
@@ -104,6 +107,7 @@
 			(poisson)
 			(density)
 			(frictionAngle)
+			(pySpheresCreator)
 			(color))
 	REGISTER_CLASS_AND_BASE(SpheresFactory, StandAloneEngine);
 };

=== modified file 'py/utils.py'
--- py/utils.py	2009-09-01 09:01:20 +0000
+++ py/utils.py	2009-09-01 12:34:25 +0000
@@ -99,22 +99,24 @@
 	b['isDynamic']=dynamic
 	return b
 
-def facet(vertices,dynamic=False,wire=True,color=None,density=1,highlight=False,physParamsClass='BodyMacroParameters',**physParamsAttr):
+def facet(vertices,dynamic=False,wire=True,color=None,density=1,highlight=False,noInteractingGeometry=False,physParamsClass='BodyMacroParameters',**physParamsAttr):
 	"""Create default facet with given parameters. Vertices are given as sequence of 3 3-tuple and they, all in global coordinates."""
 	b=Body()
 	if not color: color=randomColor()
 	pp=bodiesPhysDefaults.copy(); pp.update(physParamsAttr);
 	b.shape=GeometricalModel('Facet',diffuseColor=color,wire=wire,highlight=highlight)
-	b.mold=InteractingGeometry('InteractingFacet',diffuseColor=color)
 	center=inscribedCircleCenter(vertices[0],vertices[1],vertices[2])
 	vertices=Vector3(vertices[0])-center,Vector3(vertices[1])-center,Vector3(vertices[2])-center
-	b.shape['vertices']=vertices;	b.mold['vertices']=vertices
+	b.shape['vertices']=vertices;	
 	pp.update({'se3':[center[0],center[1],center[2],1,0,0,0],'refSe3':[center[0],center[1],center[2],1,0,0,0],'inertia':[0,0,0]})
 	b.phys=PhysicalParameters(physParamsClass)
 	b.phys.updateExistingAttrs(pp)
 	b.bound=BoundingVolume('AABB',diffuseColor=[0,1,0])
 	b['isDynamic']=dynamic
-	b.mold.postProcessAttributes(True)
+	if not noInteractingGeometry: 
+		b.mold=InteractingGeometry('InteractingFacet',diffuseColor=color)
+		b.mold['vertices']=vertices
+		b.mold.postProcessAttributes(True)
 	return b
 
 def facetBox(center,extents,orientation=[1,0,0,0],wallMask=63,**kw):

=== modified file 'scripts/test/SpheresFactory/model.py'
--- scripts/test/SpheresFactory/model.py	2009-08-26 10:34:11 +0000
+++ scripts/test/SpheresFactory/model.py	2009-09-01 12:34:25 +0000
@@ -5,6 +5,7 @@
 ## PhysicalParameters 
 Young = 0.15e9
 Poisson = 0.3
+density=2700
 
 ## Import box geometry
 box = utils.import_stl_geometry('plane.stl',young=Young,poisson=Poisson,color=[0.7,0.7,0.7],wire=False)
@@ -26,17 +27,24 @@
 	BexResetter(),
 	BoundingVolumeMetaEngine([InteractingSphere2AABB(),InteractingFacet2AABB(),MetaInteractingGeometry2AABB()]),
 	InsertionSortCollider(),
-	## Spheres factory engine
-	SpheresFactory(factoryFacets=factory1,virtPeriod=0.005,radius=0.07,radiusRange=0.03,young=Young,color=(1,0,0)),
-	SpheresFactory(factoryFacets=factory2,virtPeriod= 0.01,radius=0.08,young=Young,color=(0,1,0)),
-	SpheresFactory(factoryFacets=factory3,virtPeriod= 0.01,radius=0.05,young=Young,color=(0,0,1)),
-
 	InteractionGeometryMetaEngine([ef2_Facet_Sphere_Dem3DofGeom(),ef2_Sphere_Sphere_Dem3DofGeom()]),
 	InteractionPhysicsMetaEngine([SimpleElasticRelationships()]),
 	ConstitutiveLawDispatcher([Law2_Dem3Dof_Elastic_Elastic()]),
-
 	GravityEngine(gravity=(0,0,-9.81)),
-	NewtonsDampedLaw(damping=0.3)
+	NewtonsDampedLaw(damping=0.3),
+	## Spheres factory engines
+	SpheresFactory(factoryFacets=factory1,virtPeriod=0.005,radius=0.07,radiusRange=0.03,young=Young,pySpheresCreator='spheresCreator',color=(1,0,0)),
+	SpheresFactory(factoryFacets=factory2,virtPeriod= 0.01,radius=0.08,young=Young,color=(0,1,0)),
+	SpheresFactory(factoryFacets=factory3,virtPeriod= 0.01,radius=0.05,young=Young,color=(0,0,1))
 ]
 O.saveTmp()
 
+def spheresCreator( center, radius ):
+	s = utils.sphere(center=center, radius=radius, poisson=Poisson, young=Young, density=density )
+	O.bodies.append(s)
+
+from yade import qt
+qt.View()
+O.run()
+
+