← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 1818: 1. Add Material::newAssocState creating State instance that is supposed to go along with given ma...

 

------------------------------------------------------------
revno: 1818
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Tue 2009-11-24 18:03:29 +0100
message:
  1. Add Material::newAssocState creating State instance that is supposed to go along with given material; wrapped in python. It is used by utils.{sphere,facet,box,wall} functions now (hence by most or all body-construction things in python)
  2. Fix py/post2d.py and examples/concrete/uniax-post.py 
  3. Fix crash for material-less bodies in scripts/test/regular-sphere-pack.py
modified:
  core/Material.hpp
  core/MetaBody.cpp
  debian/control-template
  examples/concrete/uniax-post.py
  examples/concrete/uniax.py
  pkg/common/Engine/DeusExMachina/TranslationEngine.cpp
  pkg/dem/Engine/StandAloneEngine/VTKRecorder.cpp
  pkg/dem/meta/ConcretePM.cpp
  pkg/dem/meta/ConcretePM.hpp
  py/post2d.py
  py/utils.py
  py/yadeWrapper/yadeWrapper.cpp
  scripts/test/regular-sphere-pack.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 'core/Material.hpp'
--- core/Material.hpp	2009-11-23 14:56:10 +0000
+++ core/Material.hpp	2009-11-24 17:03:29 +0000
@@ -3,6 +3,8 @@
 #include<string>
 #include<yade/lib-serialization/Serializable.hpp>
 #include<yade/lib-multimethods/Indexable.hpp>
+#include<yade/core/State.hpp>
+
 
 class MetaBody;
 /*! Material properties associated with a body.
@@ -22,6 +24,11 @@
 		//! material density; used to compute mass from geometry of the body
 		Real density;
 
+		//! Function to return empty default-initialized instance of State that 
+		// is supposed to go along with this Material. Don't override unless you need
+		// something else than basic State.
+		virtual shared_ptr<State> newAssocState(){ return shared_ptr<State>(new State); }
+
 		static const shared_ptr<Material> byId(int id, MetaBody* world=NULL);
 		static const shared_ptr<Material> byId(int id, shared_ptr<MetaBody> world) {return byId(id,world.get());}
 		static const shared_ptr<Material> byLabel(const std::string& label, MetaBody* world=NULL);

=== modified file 'core/MetaBody.cpp'
--- core/MetaBody.cpp	2009-11-23 16:09:25 +0000
+++ core/MetaBody.cpp	2009-11-24 17:03:29 +0000
@@ -71,8 +71,8 @@
 void MetaBody::postProcessAttributes(bool deserializing){
 	/* since yade::serialization doesn't properly handle shared pointers, iterate over all bodies and make materials shared again, if id>=0 */
 	FOREACH(const shared_ptr<Body>& b, *bodies){
-		if(b->material->id<0) continue; // not a shared material
-		assert(b->material->id < materials.size());
+		if(!b->material || b->material->id<0) continue; // not a shared material
+		assert(b->material->id < (int)materials.size());
 		b->material=materials[b->material->id];
 	}
 }

=== modified file 'debian/control-template'
--- debian/control-template	2009-07-27 17:14:30 +0000
+++ debian/control-template	2009-11-24 17:03:29 +0000
@@ -2,7 +2,7 @@
 Section: x11
 Priority: optional
 Maintainer: Vaclav Smilauer <eudoxos@xxxxxxxx>
-Build-Depends: debhelper (>= 5), scons, libqt3-mt-dev, qt3-dev-tools, freeglut3-dev, libboost-dev (>=1.34), libboost-date-time-dev (>=1.34), libboost-filesystem-dev (>=1.34), libboost-thread-dev (>=1.34), libboost-regex-dev (>=1.34), libboost-python-dev (>=1.34), libboost-iostreams-dev (>=1.34), libboost-program-options-dev, libboost-serialization-dev, liblog4cxx9-dev | liblog4cxx10-dev, docbook-to-man, ipython, libsqlite3-dev, libgts-dev, python-numpy, g++(>4.0)
+Build-Depends: debhelper (>= 5), scons, libqt3-mt-dev, qt3-dev-tools, freeglut3-dev, libboost-dev (>=1.34), libboost-date-time-dev (>=1.34), libboost-filesystem-dev (>=1.34), libboost-thread-dev (>=1.34), libboost-regex-dev (>=1.34), libboost-python-dev (>=1.34), libboost-iostreams-dev (>=1.34), libboost-program-options-dev, libboost-serialization-dev, liblog4cxx9-dev | liblog4cxx10-dev, docbook-to-man, ipython, libsqlite3-dev, libgts-dev, python-numpy, g++(>4.0), libvtk5-dev
 Standards-Version: 3.7.2
 
 Package: yade@_VERSION@

=== modified file 'examples/concrete/uniax-post.py'
--- examples/concrete/uniax-post.py	2009-11-13 11:27:22 +0000
+++ examples/concrete/uniax-post.py	2009-11-24 17:03:29 +0000
@@ -10,10 +10,10 @@
 # flattener that project to the xz plane
 flattener=post2d.AxisFlatten(useRef=False,axis=1)
 # return scalar given a Body instance
-extractDmg=lambda b: b.phys['normDmg']
+extractDmg=lambda b: b.state['normDmg']
 # will call flattener.planar implicitly
-# the same as: extractVelocity=lambda b: flattener.planar(b,b.phys['velocity'])
-extractVelocity=lambda b: b.phys['velocity']
+# the same as: extractVelocity=lambda b: flattener.planar(b,b.state['vel'])
+extractVelocity=lambda b: b.state['vel']
 
 # create new figure
 pylab.figure()

=== modified file 'examples/concrete/uniax.py'
--- examples/concrete/uniax.py	2009-11-23 16:09:25 +0000
+++ examples/concrete/uniax.py	2009-11-24 17:03:29 +0000
@@ -64,7 +64,7 @@
 # make geom; the dimensions are hard-coded here; could be in param table if desired
 # z-oriented hyperboloid, length 20cm, diameter 10cm, skirt 8cm
 # using spheres 7mm of diameter
-concreteId=O.materials.append(CpmMat(young=young,frictionAngle=frictionAngle,poisson=poisson,density=1))
+concreteId=O.materials.append(CpmMat(young=young,frictionAngle=frictionAngle,poisson=poisson,density=4800))
 spheres=pack.randomDensePack(pack.inHyperboloid((0,0,-.5*specimenLength),(0,0,.5*specimenLength),.25*specimenLength,.2*specimenLength),spheresInCell=2000,radius=sphereRadius,memoizeDb='/tmp/triaxPackCache.sqlite',material=concreteId)
 O.bodies.append(spheres)
 bb=utils.uniaxialTestFeatures()

=== modified file 'pkg/common/Engine/DeusExMachina/TranslationEngine.cpp'
--- pkg/common/Engine/DeusExMachina/TranslationEngine.cpp	2009-11-24 14:08:28 +0000
+++ pkg/common/Engine/DeusExMachina/TranslationEngine.cpp	2009-11-24 17:03:29 +0000
@@ -12,7 +12,7 @@
 void TranslationEngine::applyCondition(MetaBody * ncb){
 	Real dt=Omega::instance().getTimeStep();
 	FOREACH(body_id_t id,subscribedBodies){
-		assert(id<(body_id_t)bodies->size());
+		assert(id<(body_id_t)ncb->bodies->size());
 		Body* b=Body::byId(id,ncb).get();
 		if(!b) continue;
 		b->state->pos+=dt*velocity*translationAxis;

=== modified file 'pkg/dem/Engine/StandAloneEngine/VTKRecorder.cpp'
--- pkg/dem/Engine/StandAloneEngine/VTKRecorder.cpp	2009-11-24 14:47:35 +0000
+++ pkg/dem/Engine/StandAloneEngine/VTKRecorder.cpp	2009-11-24 17:03:29 +0000
@@ -149,18 +149,16 @@
 				if(recActive[REC_VELOCITY]){
 					spheresVelocity->InsertNextTupleValue((float*)(&b->state->vel));
 				}
-				/*
-				*Vaclav, please, fix it. 
-				* if (recActive[REC_CPM]) {
-					cpmDamage->InsertNextValue(YADE_PTR_CAST<CpmState>(b->material)->normDmg);
-					const Vector3r& ss=YADE_PTR_CAST<CpmState>(b->material)->sigma;
-					const Vector3r& tt=YADE_PTR_CAST<CpmState>(b->material)->tau;
+				if (recActive[REC_CPM]) {
+					cpmDamage->InsertNextValue(YADE_PTR_CAST<CpmState>(b->state)->normDmg);
+					const Vector3r& ss=YADE_PTR_CAST<CpmState>(b->state)->sigma;
+					const Vector3r& tt=YADE_PTR_CAST<CpmState>(b->state)->tau;
 					float s[3]={ss[0],ss[1],ss[2]};
 					float t[3]={tt[0],tt[1],tt[2]};
 					cpmSigma->InsertNextTupleValue(s);
 					cpmSigmaM->InsertNextValue((ss[0]+ss[1]+ss[2])/3.);
 					cpmTau->InsertNextTupleValue(t);
-				}*/
+				}
 				continue;
 			}
 		}

=== modified file 'pkg/dem/meta/ConcretePM.cpp'
--- pkg/dem/meta/ConcretePM.cpp	2009-11-23 14:56:10 +0000
+++ pkg/dem/meta/ConcretePM.cpp	2009-11-24 17:03:29 +0000
@@ -376,7 +376,7 @@
 	FOREACH(shared_ptr<Body> B, *rootBody->bodies){
 		const body_id_t& id=B->getId();
 		// add damaged contacts that have already been deleted
-		CpmState* state=dynamic_cast<CpmState*>(B->material.get());
+		CpmState* state=dynamic_cast<CpmState*>(B->state.get());
 		if(!state) continue;
 		state->sigma=bodyStats[id].sigma;
 		state->tau=bodyStats[id].tau;

=== modified file 'pkg/dem/meta/ConcretePM.hpp'
--- pkg/dem/meta/ConcretePM.hpp	2009-11-23 14:56:10 +0000
+++ pkg/dem/meta/ConcretePM.hpp	2009-11-24 17:03:29 +0000
@@ -85,6 +85,7 @@
 class CpmMat: public GranularMat {
 	public:
 		CpmMat() { createIndex(); density=4800; };
+		virtual shared_ptr<State> newAssocState(){ return shared_ptr<State>(new CpmState); }
 		REGISTER_ATTRIBUTES(GranularMat,);
 		REGISTER_CLASS_AND_BASE(CpmMat,GranularMat);
 		REGISTER_CLASS_INDEX(CpmMat,GranularMat);

=== modified file 'py/post2d.py'
--- py/post2d.py	2009-11-17 12:26:35 +0000
+++ py/post2d.py	2009-11-24 17:03:29 +0000
@@ -27,10 +27,10 @@
  # flattener that project to the xz plane
  flattener=post2d.AxisFlatten(useRef=False,axis=1)
  # return scalar given a Body instance
- extractDmg=lambda b: b.phys['normDmg']
+ extractDmg=lambda b: b.state['normDmg']
  # will call flattener.planar implicitly
- # the same as: extractVelocity=lambda b: flattener.planar(b,b.phys['velocity'])
- extractVelocity=lambda b: b.phys['velocity']
+ # the same as: extractVelocity=lambda b: flattener.planar(b,b.state['vel'])
+ extractVelocity=lambda b: b.state['vel']
 
  # create new figure
  pylab.figure()
@@ -79,7 +79,7 @@
 		self.useRef,self.thetaRange,self.dH_dTheta,self.axis,self.periodStart=useRef,thetaRange,dH_dTheta,axis,periodStart
 		self.ax1,self.ax2=(axis+1)%3,(axis+2)%3
 	def _getPos(self,b):
-		return b.phys.refPos if self.useRef else b.phys.pos
+		return b.state.refPos if self.useRef else b.state.pos
 	def __call__(self,b):
 		import yade.utils
 		xy,theta=yade.utils.spiralProject(_getPos(b),self.dH_dTheta,self.axis,self.periodStart)
@@ -107,7 +107,7 @@
 		if axis not in (0,1,2): raise IndexError("axis must be one of 0,1,2 (not %d)"%axis)
 		self.useRef,self.axis=useRef,axis
 	def _getPos(self,b):
-		return b.phys.refPos if self.useRef else b.phys.pos
+		return b.state.refPos if self.useRef else b.state.pos
 	def __call__(self,b):
 		p=_getPos(b)
 		pp=(p[(self.axis+1)%3],p[(self.axis+2)%3])
@@ -133,7 +133,7 @@
 		self.useRef,self.axis=useRef,axis
 		self.ax1,self.ax2=(self.axis+1)%3,(self.axis+2)%3
 	def __call__(self,b):
-		p=b.phys.refPos if self.useRef else b.phys.pos
+		p=b.state.refPos if self.useRef else b.state.pos
 		return (p[self.ax1],p[self.ax2])
 	def planar(self,pos,vec):
 		return vec[self.ax1],vec[self.ax2]

=== modified file 'py/utils.py'
--- py/utils.py	2009-11-23 12:32:14 +0000
+++ py/utils.py	2009-11-24 17:03:29 +0000
@@ -83,9 +83,8 @@
 	elif isinstance(material,string): b.mat=O.materials[material]
 	elif isinstance(material,Material): b.mat=material
 	else: raise TypeError("The 'material' argument must be None (for defaultMaterial), string (for shared material label), int (for shared material id) or Material instance.");
-	#matKw2=bodiesMatDefaults.copy(); matKw2.update(matKw)
-	#b.mat=Material(materialClass)
-	#b.mat.updateExistingAttrs(matKw2)
+	## resets state (!!)
+	b.state=b.mat.newAssocState()
 	mass=volume*b.mat['density']
 	b.state['mass'],b.state['inertia']=mass,geomInertia*b.mat['density']
 	if not noBound: b.bound=BoundingVolume('AABB',diffuseColor=[0,1,0])
@@ -105,11 +104,11 @@
 	"""
 	b=Body()
 	b.mold=InteractingSphere(radius=radius,diffuseColor=color if color else randomColor(),wire=wire,highlight=highlight)
-	b.state.pos=b.state.refPos=center
 	V=(4./3)*math.pi*radius**3
 	geomInert=(2./5.)*V*radius**2
 	_commonBodySetup(b,V,Vector3(geomInert,geomInert,geomInert),material)
-	b['isDynamic']=dynamic
+	b.state.pos=b.state.refPos=center
+	b.dynamic=dynamic
 	return b
 
 def box(center,extents,orientation=[1,0,0,0],dynamic=True,wire=False,color=None,highlight=False,material=0):
@@ -122,11 +121,11 @@
 	See utils.sphere's documentation for meaning of other parameters."""
 	b=Body()
 	b.mold=InteractingGeometry('InteractingBox',extents=extents,diffuseColor=color if color else randomColor(),wire=wire,highlight=highlight)
-	b.state.pos=b.state.refPos=center
 	V=8*extents[0]*extents[1]*extents[2]
 	geomInert=Vector3(4*(extents[1]**2+extents[2]**2),4*(extents[0]**2+extents[2]**2),4*(extents[0]**2+extents[1]**2))
 	_commonBodySetup(b,V,geomInert,material)
-	b['isDynamic']=dynamic
+	b.state.pos=b.state.refPos=center
+	b.dynamic=dynamic
 	return b
 
 def wall(position,axis,sense=0,color=None,material=0):
@@ -143,11 +142,11 @@
 	See utils.sphere's documentation for meaning of other parameters."""
 	b=Body()
 	b.mold=Wall(sense=sense,axis=axis,diffuseColor=color if color else randomColor())
+	_commonBodySetup(b,0,Vector3(0,0,0),material)
 	if isinstance(position,(int,long,float)):
 		pos2=Vector3(0,0,0); pos2[axis]=position
 	else: pos2=position
 	b.pos=b.refPos=pos2
-	_commonBodySetup(b,0,Vector3(0,0,0),material)
 	b.dynamic=False
 	return b
 
@@ -164,12 +163,12 @@
 	if not color: color=randomColor()
 	center=inscribedCircleCenter(vertices[0],vertices[1],vertices[2])
 	vertices=Vector3(vertices[0])-center,Vector3(vertices[1])-center,Vector3(vertices[2])-center
-	b.state.pos=b.state.refPos=center
 	b.mold=InteractingGeometry('InteractingFacet',diffuseColor=color if color else randomColor(),wire=wire,highlight=highlight)
 	b.mold['vertices']=vertices
 	b.mold.postProcessAttributes(True)
 	_commonBodySetup(b,0,Vector3(0,0,0),material,noBound=noBoundingVolume)
-	b['isDynamic']=dynamic
+	b.state.pos=b.state.refPos=center
+	b.dynamic=dynamic
 	return b
 
 def facetBox(center,extents,orientation=[1,0,0,0],wallMask=63,**kw):

=== modified file 'py/yadeWrapper/yadeWrapper.cpp'
--- py/yadeWrapper/yadeWrapper.cpp	2009-11-23 16:09:25 +0000
+++ py/yadeWrapper/yadeWrapper.cpp	2009-11-24 17:03:29 +0000
@@ -873,7 +873,9 @@
 		.def_readonly("min",&BoundingVolume::min)
 		.def_readonly("max",&BoundingVolume::max);
 	EXPOSE_CXX_CLASS_IX(Material)
-		.def_readwrite("label",&Material::label);
+		.def_readwrite("label",&Material::label)
+		.def("newAssocState",&Material::newAssocState)
+		;
 	EXPOSE_CXX_CLASS(State)
 		.add_property("blockedDOFs",&State::blockedDOFs_vec_get,&State::blockedDOFs_vec_set)
 		.add_property("pos",&State_pos_get,&State_pos_set)

=== modified file 'scripts/test/regular-sphere-pack.py'
--- scripts/test/regular-sphere-pack.py	2009-11-24 14:08:28 +0000
+++ scripts/test/regular-sphere-pack.py	2009-11-24 17:03:29 +0000
@@ -84,4 +84,4 @@
 ]
 # we don't care about physical accuracy here, over-critical step is fine as long as the simulation doesn't explode
 O.dt=3*utils.PWaveTimeStep()
-#O.saveTmp()
+O.saveTmp()