← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2236: VTKRecorder. force->stress. But only for Dem3DofGeom now

 

------------------------------------------------------------
revno: 2236
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-05-18 15:57:34 +0200
message:
  VTKRecorder. force->stress. But only for Dem3DofGeom now
modified:
  pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp
  pkg/dem/Engine/GlobalEngine/VTKRecorder.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/dem/Engine/GlobalEngine/VTKRecorder.cpp'
--- pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp	2010-05-18 09:25:24 +0000
+++ pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp	2010-05-18 13:57:34 +0000
@@ -34,7 +34,7 @@
 			recActive[REC_ID]=true;
 			recActive[REC_CLUMPID]=true;
 			recActive[REC_MATERIALID]=true;
-			recActive[REC_FORCE]=true;
+			recActive[REC_STRESS]=true;
 		}
 		else if(rec=="spheres") recActive[REC_SPHERES]=true;
 		else if(rec=="velocity") recActive[REC_VELOCITY]=true;
@@ -45,8 +45,8 @@
 		else if((rec=="ids") || (rec=="id")) recActive[REC_ID]=true;
 		else if((rec=="clumpids") || (rec=="clumpId")) recActive[REC_CLUMPID]=true;
 		else if(rec=="materialId") recActive[REC_MATERIALID]=true;
-		else if(rec=="force") recActive[REC_FORCE]=true;
-		else LOG_ERROR("Unknown recorder named `"<<rec<<"' (supported are: all, spheres, velocity, facets, color, force, cpm, intr, id, clumpId, materialId). Ignored.");
+		else if(rec=="stress") recActive[REC_STRESS]=true;
+		else LOG_ERROR("Unknown recorder named `"<<rec<<"' (supported are: all, spheres, velocity, facets, color, stress, cpm, intr, id, clumpId, materialId). Ignored.");
 	}
 	// cpm needs interactions
 	if(recActive[REC_CPM]) recActive[REC_INTR]=true;
@@ -87,19 +87,18 @@
 	spheresAngVelLen->SetNumberOfComponents(1);
 	spheresAngVelLen->SetName("angVelLen");		//Length (magnitude) of angular velocity
 	
-	vtkSmartPointer<vtkFloatArray> spheresForceVec = vtkSmartPointer<vtkFloatArray>::New();
-	spheresForceVec->SetNumberOfComponents(3);
-	spheresForceVec->SetName("forceVec");
+	vtkSmartPointer<vtkFloatArray> spheresStressVec = vtkSmartPointer<vtkFloatArray>::New();
+	spheresStressVec->SetNumberOfComponents(3);
+	spheresStressVec->SetName("stressVec");
 	
-	vtkSmartPointer<vtkFloatArray> spheresForceLen = vtkSmartPointer<vtkFloatArray>::New();
-	spheresForceLen->SetNumberOfComponents(1);
-	spheresForceLen->SetName("forceLen");
+	vtkSmartPointer<vtkFloatArray> spheresStressLen = vtkSmartPointer<vtkFloatArray>::New();
+	spheresStressLen->SetNumberOfComponents(1);
+	spheresStressLen->SetName("stressLen");
 	
 	vtkSmartPointer<vtkFloatArray> spheresMaterialId = vtkSmartPointer<vtkFloatArray>::New();
 	spheresMaterialId->SetNumberOfComponents(1);
 	spheresMaterialId->SetName("materialId");
 	
-	
 	// facets
 	vtkSmartPointer<vtkPoints> facetsPos = vtkSmartPointer<vtkPoints>::New();
 	vtkSmartPointer<vtkCellArray> facetsCells = vtkSmartPointer<vtkCellArray>::New();
@@ -109,12 +108,11 @@
 	
 	vtkSmartPointer<vtkFloatArray> facetsForceVec = vtkSmartPointer<vtkFloatArray>::New();
 	facetsForceVec->SetNumberOfComponents(3);
-	facetsForceVec->SetName("forceVec");
+	facetsForceVec->SetName("stressVec");
 	
 	vtkSmartPointer<vtkFloatArray> facetsForceLen = vtkSmartPointer<vtkFloatArray>::New();
 	facetsForceLen->SetNumberOfComponents(1);
-	facetsForceLen->SetName("forceLen");
-	
+	facetsForceLen->SetName("stressLen");
 	
 	vtkSmartPointer<vtkFloatArray> facetsMaterialId = vtkSmartPointer<vtkFloatArray>::New();
 	facetsMaterialId->SetNumberOfComponents(1);
@@ -177,20 +175,32 @@
 	}
 
 	//Additional Vector for storing forces
-	vector<bodyForce> bodyForces;
-	if(recActive[REC_FORCE]){
-		bodyForces.resize(scene->bodies->size());
+	vector<bodyState> bodyStates;
+	if(recActive[REC_STRESS]){
+		bodyStates.resize(scene->bodies->size());
 		FOREACH(const shared_ptr<Interaction>& I, *scene->interactions){
 			if(!I->isReal()) continue;
 			const NormShearPhys* phys = YADE_CAST<NormShearPhys*>(I->interactionPhysics.get());
+			Dem3DofGeom* geom=YADE_CAST<Dem3DofGeom*>(I->interactionGeometry.get());	//For the moment only for Dem3DofGeom!!!
 			if(!phys) continue;
 			const body_id_t id1=I->getId1(), id2=I->getId2();
 			
-			bodyForces[id1].norm+=phys->normalForce;
-			bodyForces[id2].norm-=phys->normalForce;
-			
-			bodyForces[id1].shear+=phys->shearForce;
-			bodyForces[id2].shear-=phys->shearForce;
+			Real minRad=(geom->refR1<=0?geom->refR2:(geom->refR2<=0?geom->refR1:min(geom->refR1,geom->refR2)));
+			Real crossSection=Mathr::PI*pow(minRad,2);
+			
+			Vector3r normalStress=((1./crossSection)*geom->normal.dot(phys->normalForce))*geom->normal;
+			Vector3r shearStress;
+			for(int i=0; i<3; i++){
+				int ix1=(i+1)%3,ix2=(i+2)%3;
+				shearStress[i]=geom->normal[ix1]*phys->shearForce[ix1]+geom->normal[ix2]*phys->shearForce[ix2];
+				shearStress[i]/=crossSection;
+			}
+			
+			bodyStates[id1].normStress+=normalStress;
+			bodyStates[id2].normStress+=normalStress;
+			
+			bodyStates[id1].shearStress+=shearStress;
+			bodyStates[id2].shearStress+=shearStress;
 		}
 	}
 	
@@ -224,11 +234,11 @@
 					spheresAngVelVec->InsertNextTupleValue(av);
 					spheresAngVelLen->InsertNextValue(angVel.norm());
 				}
-				if(recActive[REC_FORCE]){
-					const Vector3r& force = bodyForces[b->getId()].norm+bodyForces[b->getId()].shear;
-					float f[3] = { force[0],force[1],force[2] };
-					spheresForceVec->InsertNextTupleValue(f);
-					spheresForceLen->InsertNextValue(force.norm());
+				if(recActive[REC_STRESS]){
+					const Vector3r& stress = bodyStates[b->getId()].normStress+bodyStates[b->getId()].shearStress;
+					float s[3] = { stress[0],stress[1],stress[2] };
+					spheresStressVec->InsertNextTupleValue(s);
+					spheresStressLen->InsertNextValue(stress.norm());
 				}
 				
 				if (recActive[REC_CPM]){
@@ -264,11 +274,11 @@
 					float c[3] = {color[0],color[1],color[2]};
 					facetsColors->InsertNextTupleValue(c);
 				}
-				if(recActive[REC_FORCE]){
-					const Vector3r& force = bodyForces[b->getId()].norm+bodyForces[b->getId()].shear;
-					float f[3] = { force[0],force[1],force[2] };
-					facetsForceVec->InsertNextTupleValue(f);
-					facetsForceLen->InsertNextValue(force.norm());
+				if(recActive[REC_STRESS]){
+					const Vector3r& stress = bodyStates[b->getId()].normStress+bodyStates[b->getId()].shearStress;
+					float s[3] = { stress[0],stress[1],stress[2] };
+					facetsForceVec->InsertNextTupleValue(s);
+					facetsForceLen->InsertNextValue(stress.norm());
 				}
 				if (recActive[REC_MATERIALID]) facetsMaterialId->InsertNextValue(b->material->id);
 				continue;
@@ -294,9 +304,9 @@
 			spheresUg->GetPointData()->AddArray(spheresLinVelLen);
 			spheresUg->GetPointData()->AddArray(spheresAngVelLen);
 		}
-		if (recActive[REC_FORCE]){
-			spheresUg->GetPointData()->AddArray(spheresForceVec);
-			spheresUg->GetPointData()->AddArray(spheresForceLen);
+		if (recActive[REC_STRESS]){
+			spheresUg->GetPointData()->AddArray(spheresStressVec);
+			spheresUg->GetPointData()->AddArray(spheresStressLen);
 		}
 		if (recActive[REC_CPM]){
 			spheresUg->GetPointData()->AddArray(cpmDamage);
@@ -318,7 +328,7 @@
 		facetsUg->SetPoints(facetsPos);
 		facetsUg->SetCells(VTK_TRIANGLE, facetsCells);
 		if (recActive[REC_COLORS]) facetsUg->GetCellData()->AddArray(facetsColors);
-		if (recActive[REC_FORCE]){
+		if (recActive[REC_STRESS]){
 			facetsUg->GetCellData()->AddArray(facetsForceVec);
 			facetsUg->GetCellData()->AddArray(facetsForceLen);
 		}

=== modified file 'pkg/dem/Engine/GlobalEngine/VTKRecorder.hpp'
--- pkg/dem/Engine/GlobalEngine/VTKRecorder.hpp	2010-05-18 09:25:24 +0000
+++ pkg/dem/Engine/GlobalEngine/VTKRecorder.hpp	2010-05-18 13:57:34 +0000
@@ -4,14 +4,14 @@
 
 class VTKRecorder: public PeriodicEngine {
 	public:
-		enum {REC_SPHERES=0,REC_FACETS,REC_COLORS,REC_CPM,REC_INTR,REC_VELOCITY,REC_ID,REC_CLUMPID,REC_SENTINEL,REC_MATERIALID,REC_FORCE};
+		enum {REC_SPHERES=0,REC_FACETS,REC_COLORS,REC_CPM,REC_INTR,REC_VELOCITY,REC_ID,REC_CLUMPID,REC_SENTINEL,REC_MATERIALID,REC_STRESS};
 		virtual void action();
 	YADE_CLASS_BASE_DOC_ATTRS_CTOR(VTKRecorder,PeriodicEngine,"Engine recording snapshots of simulation into series of *.vtu files, readable by VTK-based postprocessing programs such as Paraview. Both bodies (spheres and facets) and interactions can be recorded, with various vector/scalar quantities that are defined on them.\n\n:yref:`PeriodicEngine.initRun` is initialized to ``True`` automatically.",
 		((bool,compress,false,"Compress output XML files [experimental]."))
 		((bool,skipFacetIntr,true,"Skip interactions with facets, when saving interactions"))
 		((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 as Vector3 and length(fields ``linVelVec``, ``linVelLen`` and ``angVelVec``, ``angVelLen`` respectively``); only effective with ``spheres``.\n``facets``\n\tSave :yref:`facets<Facet>` positions (vertices).\n``force``\n\tSaves forces of :yref:`spheres<Sphere>` and of :yref:`facets<Facet>`  as Vector3 and length; only active if ``spheres`` or ``facets`` is activated.\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"))
+		((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 as Vector3 and length(fields ``linVelVec``, ``linVelLen`` and ``angVelVec``, ``angVelLen`` respectively``); only effective with ``spheres``.\n``facets``\n\tSave :yref:`facets<Facet>` positions (vertices).\n``stress``\n\tSaves stresses of :yref:`spheres<Sphere>` and of :yref:`facets<Facet>`  as Vector3 and length; only active if ``spheres`` or ``facets`` is activated.\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"))
 		((int,mask,0,"If mask defined, only bodies with corresponding groupMask will be exported. If 0 - all bodies will be exported.")),
 		/*ctor*/
 		initRun=true;
@@ -21,12 +21,12 @@
 };
 
 //Class for storing forces, affected on bodies, obtained from Interactions
-class bodyForce{
+class bodyState{
 	public:
-		Vector3r norm, shear;
-		bodyForce (){
-			norm = Vector3r(0.0,0.0,0.0);
-			shear = Vector3r(0.0,0.0,0.0);
+		Vector3r normStress, shearStress;
+		bodyState (){
+			normStress = Vector3r(0.0,0.0,0.0);
+			shearStress = Vector3r(0.0,0.0,0.0);
 		}
 };
 REGISTER_SERIALIZABLE(VTKRecorder);