← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2229: 1. Parameter groupMask is added to utils.sphere and utils.facet

 

------------------------------------------------------------
revno: 2229
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-05-14 20:35:45 +0200
message:
  1. Parameter groupMask is added to utils.sphere and utils.facet
  2. VTKRecorder. subscribedBodies mechanism was changed to 
removed:
  pkg/dem/Engine/GlobalEngine/VTKRecorder.inc
modified:
  pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp
  pkg/dem/Engine/GlobalEngine/VTKRecorder.hpp
  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 'pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp'
--- pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp	2010-05-14 14:04:31 +0000
+++ pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp	2010-05-14 18:35:45 +0000
@@ -141,17 +141,74 @@
 		}
 	}
 
-	if (subscribedBodies.empty()) {
-		FOREACH(const shared_ptr<Body>& b, *scene->bodies){
-			#include"VTKRecorder.inc"
+
+	FOREACH(const shared_ptr<Body>& b, *scene->bodies){
+		if (!b) continue;
+		if(mask!=0 && (b->groupMask & mask)==0) continue;
+		if (recActive[REC_SPHERES]){
+			const Sphere* sphere = dynamic_cast<Sphere*>(b->shape.get()); 
+			if (sphere){
+				if(skipNondynamic && !b->isDynamic) continue;
+				vtkIdType pid[1];
+				const Vector3r& pos = b->state->pos;
+				pid[0] = spheresPos->InsertNextPoint(pos[0], pos[1], pos[2]);
+				spheresCells->InsertNextCell(1,pid);
+				radii->InsertNextValue(sphere->radius);
+				if (recActive[REC_ID]) spheresId->InsertNextValue(b->getId()); 
+				if (recActive[REC_CLUMPID]) clumpId->InsertNextValue(b->clumpId);
+				if (recActive[REC_COLORS]){
+					const Vector3r& color = sphere->color;
+					float c[3] = {color[0],color[1],color[2]};
+					spheresColors->InsertNextTupleValue(c);
+				}
+				if(recActive[REC_VELOCITY]){
+					const Vector3r& vel = b->state->vel;
+					float v[3] = { vel[0],vel[1],vel[2] };
+					spheresVelocity->InsertNextTupleValue(v);
+					
+					const Vector3r& angVel = b->state->angVel;
+					float av[3] = { angVel[0],angVel[1],angVel[2] };
+					sphAngVel->InsertNextTupleValue(av);
+				}
+				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);
+				}
+				if (recActive[REC_MATERIALID]) spheresMaterialId->InsertNextValue(b->material->id);
+				continue;
+			}
 		}
-	} else {
-		FOREACH(body_id_t id,subscribedBodies){
-			assert(id<(body_id_t)scene->bodies->size());
-			Body* b=Body::byId(id,scene).get();
-			#include"VTKRecorder.inc"
+		if (recActive[REC_FACETS]){
+			const Facet* facet = dynamic_cast<Facet*>(b->shape.get()); 
+			if (facet){
+				const Se3r& O = b->state->se3;
+				const vector<Vector3r>& localPos = facet->vertices;
+				Matrix3r facetAxisT=O.orientation.toRotationMatrix();
+				vtkSmartPointer<vtkTriangle> tri = vtkSmartPointer<vtkTriangle>::New();
+				vtkIdType nbPoints=facetsPos->GetNumberOfPoints();
+				for (int i=0;i<3;++i){
+					Vector3r globalPos = O.position + facetAxisT * localPos[i];
+					facetsPos->InsertNextPoint(globalPos[0], globalPos[1], globalPos[2]);
+					tri->GetPointIds()->SetId(i,nbPoints+i);
+				}
+				facetsCells->InsertNextCell(tri);
+				if (recActive[REC_COLORS]){
+					const Vector3r& color = facet->color;
+					float c[3] = {color[0],color[1],color[2]};
+					facetsColors->InsertNextTupleValue(c);
+				}
+				if (recActive[REC_MATERIALID]) facetsMaterialId->InsertNextValue(b->material->id);
+				continue;
+			}
 		}
 	}
+
 	
 	vtkSmartPointer<vtkDataCompressor> compressor;
 	if(compress) compressor=vtkSmartPointer<vtkZLibDataCompressor>::New();

=== modified file 'pkg/dem/Engine/GlobalEngine/VTKRecorder.hpp'
--- pkg/dem/Engine/GlobalEngine/VTKRecorder.hpp	2010-05-14 14:04:31 +0000
+++ pkg/dem/Engine/GlobalEngine/VTKRecorder.hpp	2010-05-14 18:35:45 +0000
@@ -12,7 +12,7 @@
 		((bool,skipNondynamic,false,"Skip non-dynamic spheres (but not facets)."))
 		((string,fileName,"","Base file name; it will be appended with {spheres,intrs,facets}-243100.vtu depending on active recorders and step number (243100 in this case). It can contain slashes, but the directory must exist already."))
 		((vector<string>,recorders,,"List of active recorders (as strings). Accepted recorders are:\n\n``all``\n\tSaves all possible parameters, except of specific. Default value.\n``spheres``\n\tSaves positions and radii (``radii``) of :yref:`spherical<Sphere>` particles.\n``id``\n\tSaves id's (field ``id``) of spheres; active only if ``spheres`` is active.\n``clumpId``\n\tSaves id's of clumps to which each sphere belongs (field ``clumpId``); active only if ``spheres`` is active.\n``colors``\n\tSaves colors of :yref:`spheres<Sphere>` and of :yref:`facets<Facet>` (field ``color``); only active if ``spheres`` or ``facets`` is activated.\n``materialId``\n\tSaves materialID of :yref:`spheres<Sphere>` and of :yref:`facets<Facet>`; only active if ``spheres`` or ``facets`` is activated.\n``velocity``\n\tSaves linear and angular velocities of spherical particles (fields ``velocity`` and ``angVel`` respectively``); only effective with ``spheres``.\n``facets``\n\tSave :yref:`facets<Facet>` positions (vertices).\n``cpm``\n\tSaves data pertaining to the :yref:`concrete model<Law2_Dem3DofGeom_CpmPhys_Cpm>`: ``cpmDamage`` (normalized residual strength averaged on particle), ``cpmSigma`` (stress on particle, normal components), ``cpmTau`` (shear components of stress on particle), ``cpmSigmaM`` (mean stress around particle); ``intr`` is activated automatically by ``cpm``.\n``intr``\n\tWhen ``cpm`` is used, it saves magnitude of normal (``forceN``) and shear (``absForceT``) forces.\n\n\tWithout ``cpm``, saves [TODO]\n\n"))
-		((std::vector<int>,subscribedBodies,,"List of bodies, which will be exported. If empty - all bodies will be exported.")),
+		((int,mask,0,"If mask defined, only bodies with corresponding groupMask will be exported. If 0 - all bodies will be exported.")),
 		/*ctor*/
 		initRun=true;
 		if (recorders.empty()) {recorders.push_back("all");}	//Default value

=== removed file 'pkg/dem/Engine/GlobalEngine/VTKRecorder.inc'
--- pkg/dem/Engine/GlobalEngine/VTKRecorder.inc	2010-05-14 14:04:31 +0000
+++ pkg/dem/Engine/GlobalEngine/VTKRecorder.inc	1970-01-01 00:00:00 +0000
@@ -1,65 +0,0 @@
-
-		if (!b) continue;
-		if (recActive[REC_SPHERES]){
-			const Sphere* sphere = dynamic_cast<Sphere*>(b->shape.get()); 
-			if (sphere){
-				if(skipNondynamic && !b->isDynamic) continue;
-				vtkIdType pid[1];
-				const Vector3r& pos = b->state->pos;
-				pid[0] = spheresPos->InsertNextPoint(pos[0], pos[1], pos[2]);
-				spheresCells->InsertNextCell(1,pid);
-				radii->InsertNextValue(sphere->radius);
-				if (recActive[REC_ID]) spheresId->InsertNextValue(b->getId()); 
-				if (recActive[REC_CLUMPID]) clumpId->InsertNextValue(b->clumpId);
-				if (recActive[REC_COLORS]){
-					const Vector3r& color = sphere->color;
-					float c[3] = {color[0],color[1],color[2]};
-					spheresColors->InsertNextTupleValue(c);
-				}
-				if(recActive[REC_VELOCITY]){
-					const Vector3r& vel = b->state->vel;
-					float v[3] = { vel[0],vel[1],vel[2] };
-					spheresVelocity->InsertNextTupleValue(v);
-					
-					const Vector3r& angVel = b->state->angVel;
-					float av[3] = { angVel[0],angVel[1],angVel[2] };
-					sphAngVel->InsertNextTupleValue(av);
-				}
-				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);
-				}
-				if (recActive[REC_MATERIALID]) spheresMaterialId->InsertNextValue(b->material->id);
-				continue;
-			}
-		}
-		if (recActive[REC_FACETS]){
-			const Facet* facet = dynamic_cast<Facet*>(b->shape.get()); 
-			if (facet){
-				const Se3r& O = b->state->se3;
-				const vector<Vector3r>& localPos = facet->vertices;
-				Matrix3r facetAxisT=O.orientation.toRotationMatrix();
-				vtkSmartPointer<vtkTriangle> tri = vtkSmartPointer<vtkTriangle>::New();
-				vtkIdType nbPoints=facetsPos->GetNumberOfPoints();
-				for (int i=0;i<3;++i){
-					Vector3r globalPos = O.position + facetAxisT * localPos[i];
-					facetsPos->InsertNextPoint(globalPos[0], globalPos[1], globalPos[2]);
-					tri->GetPointIds()->SetId(i,nbPoints+i);
-				}
-				facetsCells->InsertNextCell(tri);
-				if (recActive[REC_COLORS]){
-					const Vector3r& color = facet->color;
-					float c[3] = {color[0],color[1],color[2]};
-					facetsColors->InsertNextTupleValue(c);
-				}
-				if (recActive[REC_MATERIALID]) facetsMaterialId->InsertNextValue(b->material->id);
-				continue;
-			}
-		}
-		

=== modified file 'py/utils.py'
--- py/utils.py	2010-05-08 14:53:54 +0000
+++ py/utils.py	2010-05-14 18:35:45 +0000
@@ -113,7 +113,7 @@
 	b.state.mass,b.state.inertia=mass,geomInertia*b.mat.density
 	if not noBound: b.bound=Aabb(diffuseColor=[0,1,0])
 
-def sphere(center,radius,dynamic=True,wire=False,color=None,highlight=False,material=-1):
+def sphere(center,radius,dynamic=True,wire=False,color=None,highlight=False,material=-1,groupMask=0):
 	"""Create sphere with given parameters; mass and inertia computed automatically.
 
 	Last assigned material is used by default (*material*=-1), and utils.defaultMaterial() will be used if no material is defined at all.
@@ -130,6 +130,8 @@
 			* if string, it is label of an existing material that will be used
 			* if Material instance, this instance will be used
 			* if callable, it will be called without arguments; returned Material value will be used (Material factory object, if you like)
+		`groupMask`: integer
+			groupMask for the body
 
 	:return:
 		A Body instance with desired characteristics.
@@ -185,6 +187,7 @@
 	_commonBodySetup(b,V,Vector3(geomInert,geomInert,geomInert),material)
 	b.state.pos=b.state.refPos=center
 	b.dynamic=dynamic
+	b.groupMask=groupMask
 	return b
 
 def box(center,extents,orientation=[1,0,0,0],dynamic=True,wire=False,color=None,highlight=False,material=-1):
@@ -226,14 +229,25 @@
 	b.dynamic=False
 	return b
 
-def facet(vertices,dynamic=False,wire=True,color=None,highlight=False,noBound=False,material=-1):
+def facet(vertices,dynamic=False,wire=True,color=None,highlight=False,noBound=False,material=-1,groupMask=0):
 	"""Create facet with given parameters.
 
 	:Parameters:
 		`vertices`: [Vector3,Vector3,Vector3]
 			coordinates of vertices in the global coordinate system.
+		`wire`: bool
+			if True, facets are shown as skeleton; otherwise facets are filled
 		`noBound`:
 			do not assign Body().bound
+		`color`: Vector3 or None
+			random color will be assigned if None
+		`material`: int | string | Material instance | callable returning Material instance
+			* if int, O.materials[material] will be used; as a special case, if material==-1 and there is no shared materials defined, utils.defaultMaterial() will be assigned to O.materials[0]
+			* if string, it is label of an existing material that will be used
+			* if Material instance, this instance will be used
+			* if callable, it will be called without arguments; returned Material value will be used (Material factory object, if you like)
+		`groupMask`: integer
+			groupMask for the body
 	
 	See :yref:`yade.utils.sphere`'s documentation for meaning of other parameters."""
 	b=Body()
@@ -245,6 +259,7 @@
 	_commonBodySetup(b,0,Vector3(0,0,0),material,noBound=noBound)
 	b.state.pos=b.state.refPos=center
 	b.dynamic=dynamic
+	b.groupMask=groupMask
 	return b
 
 def facetBox(center,extents,orientation=Quaternion().Identity,wallMask=63,**kw):