← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2169: 1. Fix cached values for cell and facet when modified from python

 

------------------------------------------------------------
revno: 2169
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-04-20 18:21:29 +0200
message:
  1. Fix cached values for cell and facet when modified from python
  2. Fix table parsing for lines with 1 character onlyDynamic
modified:
  core/Cell.hpp
  pkg/common/DataClass/Shape/Facet.hpp
  py/pack/_packSpheres.cpp
  py/pack/pack.py
  py/utils.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/Cell.hpp'
--- core/Cell.hpp	2010-02-09 20:22:04 +0000
+++ core/Cell.hpp	2010-04-20 16:21:29 +0000
@@ -84,18 +84,26 @@
 	static Real wrapNum(const Real& x, const Real& sz, int& period){
 		Real norm=x/sz; period=(int)floor(norm); return (norm-period)*sz;
 	}
+
+	Vector3r getRefSize(){ return refSize; }
+	void setRefSize(const Vector3r& s){ refSize=s; integrateAndUpdate(0); }
+	Matrix3r getTrsf(){ return trsf; }
+	void setTrsf(const Matrix3r& m){ trsf=m; integrateAndUpdate(0); }
+
 	void postProcessAttributes(bool deserializing){ if(deserializing) integrateAndUpdate(0); }
 	YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY
 		(Cell,Serializable,"Parameters of periodic boundary conditions. Only applies if O.isPeriodic==True.",
-
-		((Vector3r,refSize,Vector3r(1,1,1),"Reference size of the cell"))
-		((Matrix3r,trsf,Matrix3r::IDENTITY,"Current transformation matrix of the cell"))
+		((Vector3r,refSize,Vector3r(1,1,1),"[will be overridden below]"))
+		((Matrix3r,trsf,Matrix3r::IDENTITY,"[will be overridden below]"))
 		((Matrix3r,velGrad,Matrix3r::ZERO,"Velocity gradient of the transformation; used in NewtonIntegrator.")),
 
 		/*ctor*/ integrateAndUpdate(0),
 
 		/*py*/
 		.def_readonly("size",&Cell::getSize_copy,"Current size of the cell, i.e. lengths of 3 cell lateral vectors after applying current trsf. Update automatically at every step.")
+		/* accessors that ensure cache coherence */
+		.add_property("refSize",&Cell::getRefSize,&Cell::setRefSize,"Reference size of the cell.")
+		.add_property("trsf",&Cell::getTrsf,&Cell::setTrsf,"Transformation matrix of the cell.")
 	);
 };
 REGISTER_SERIALIZABLE(Cell);

=== modified file 'pkg/common/DataClass/Shape/Facet.hpp'
--- pkg/common/DataClass/Shape/Facet.hpp	2010-04-19 10:18:42 +0000
+++ pkg/common/DataClass/Shape/Facet.hpp	2010-04-20 16:21:29 +0000
@@ -35,14 +35,24 @@
 
 	void postProcessAttributes(bool deserializing);
 
-	YADE_CLASS_BASE_DOC_ATTRS_CTOR(Facet,Shape,"Facet (triangular particle) geometry.",
-		((vector<Vector3r>,vertices,vector<Vector3r>(3),"Vertex positions in local coordinates."))
+	void setVertices(const vector<Vector3r>& v){
+		if(v.size()!=3) throw runtime_error("Facet must have exactly 3 vertices.");
+		assert(vertices.size()==3);
+		for(int i=0; i<3; i++) vertices[i]=v[i];
+		Facet::postProcessAttributes(true);
+	}
+	vector<Vector3r> getVertices(){ vector<Vector3r> ret(3); for(int i=0; i<3; i++) ret[i]=vertices[i]; return ret;}
+
+	YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY(Facet,Shape,"Facet (triangular particle) geometry.",
+		((vector<Vector3r>,vertices,vector<Vector3r>(3),"[overridden below]"))
 		#ifdef FACET_TOPO
 		((vector<body_id_t>,edgeAdjIds,vector<body_id_t>(3,Body::ID_NONE),"Facet id's that are adjacent to respective edges [experimental]"))
 		((vector<Real>,edgeAdjHalfAngle,vector<Real>(3,0),"half angle between normals of this facet and the adjacent facet [experimental]"))
 		#endif
 		,
-		/* ctor */ createIndex();
+		/* ctor */ createIndex();,
+		/* must be separate to call postProcessAttributes(0) when changed, to keep internal data consistent */
+		.add_property("vertices",&Facet::getVertices,&Facet::setVertices,"Vertex positions in local coordinates.")
 	);
 	DECLARE_LOGGER;
 	REGISTER_CLASS_INDEX(Facet,Shape);

=== modified file 'py/pack/_packSpheres.cpp'
--- py/pack/_packSpheres.cpp	2010-03-25 13:24:10 +0000
+++ py/pack/_packSpheres.cpp	2010-04-20 16:21:29 +0000
@@ -23,7 +23,7 @@
 		.def("cellRepeat",&SpherePack::cellRepeat,"Repeat the packing given number of times in each dimension. Periodicity is retained, cellSize changes. Raises exception for non-periodic packing.")
 		.def("relDensity",&SpherePack::relDensity,"Relative packing density, measured as sum of spheres' volumes / aabb volume.\n(Sphere overlaps are ignored.)")
 		.def("translate",&SpherePack::translate,"Translate all spheres by given vector.")
-		.def("rotate",&SpherePack::rotate,"Rotate all spheres around packing center (in terms of aabb()), given axis and angle of the rotation.")
+		.def("rotate",&SpherePack::rotate,(python::arg("axis"),python::arg("angle")),"Rotate all spheres around packing center (in terms of aabb()), given axis and angle of the rotation.")
 		.def("scale",&SpherePack::scale,"Scale the packing around its center (in terms of aabb()) by given factor (may be negative).")
 		.def("__len__",&SpherePack::len,"Get number of spheres in the packing")
 		.def("__getitem__",&SpherePack::getitem,"Get entry at given index, as tuple of center and radius.")

=== modified file 'py/pack/pack.py'
--- py/pack/pack.py	2010-03-29 12:28:06 +0000
+++ py/pack/pack.py	2010-04-20 16:21:29 +0000
@@ -383,7 +383,7 @@
 	sp=SpherePack()
 	O.periodic=True
 	O.cell.refSize=Vector3(initSize)
-	sp.makeCloud(Vector3().ZERO,O.cell.refSize,radius,rRelFuzz,int(initSize[0]*initSize[1]*initSize[2]/((4/3.)*pi*radius**3)),True)
+	sp.makeCloud(Vector3().ZERO,O.cell.refSize,radius,rRelFuzz,-1,True)
 	O.engines=[ForceResetter(),BoundDispatcher([Bo1_Sphere_Aabb()]),InsertionSortCollider(nBins=2,sweepLength=.05*radius),InteractionDispatchers([Ig2_Sphere_Sphere_Dem3DofGeom()],[Ip2_FrictMat_FrictMat_FrictPhys()],[Law2_Dem3DofGeom_FrictPhys_Basic()]),PeriIsoCompressor(charLen=2*radius,stresses=[-100e9,-1e8],maxUnbalanced=1e-2,doneHook='O.pause();',globalUpdateInt=20,keepProportions=True),NewtonIntegrator(damping=.8)]
 	O.materials.append(FrictMat(young=30e9,frictionAngle=.1,poisson=.3,density=1e3))
 	for s in sp: O.bodies.append(utils.sphere(s[0],s[1]))

=== modified file 'py/utils.py'
--- py/utils.py	2010-04-18 20:46:54 +0000
+++ py/utils.py	2010-04-20 16:21:29 +0000
@@ -645,7 +645,7 @@
 		# read file in memory, remove newlines and comments; the [''] makes lines 1-indexed
 		ll=[re.sub('\s*#.*','',l[:-1]) for l in ['']+open(file,'r').readlines()]
 		# usable lines are those that contain something else than just spaces
-		usableLines=[i for i in range(len(ll)) if not re.match(r'^\s*(#.*)?$',ll[i][:-1])]
+		usableLines=[i for i in range(len(ll)) if not re.match(r'^\s*(#.*)?$',ll[i])]
 		headings=ll[usableLines[0]].split()
 		# use all values of which heading has ! after its name to build up the description string
 		# if there are none, use all columns


Follow ups