← Back to team overview

yade-dev team mailing list archive

[svn] r1926 - in trunk: core lib/import pkg/dem/DataClass pkg/dem/PreProcessor

 

Author: eudoxos
Date: 2009-08-05 20:00:48 +0200 (Wed, 05 Aug 2009)
New Revision: 1926

Added:
   trunk/pkg/dem/PreProcessor/ClumpTestGen.cpp
   trunk/pkg/dem/PreProcessor/ClumpTestGen.hpp
Modified:
   trunk/core/yade.cpp
   trunk/lib/import/STLReader.hpp
   trunk/pkg/dem/DataClass/Clump.cpp
   trunk/pkg/dem/DataClass/Clump.hpp
Log:
1. Fix (?) https://bugs.launchpad.net/yade/+bug/409254 by moving ClumpTestGen out of Clump.hpp
2. Avoid warnings in STL import code (return values _should_ be checked, though!)
3. Avoid warning in yade.cpp in optimized build


Modified: trunk/core/yade.cpp
===================================================================
--- trunk/core/yade.cpp	2009-08-05 17:18:28 UTC (rev 1925)
+++ trunk/core/yade.cpp	2009-08-05 18:00:48 UTC (rev 1926)
@@ -62,7 +62,9 @@
 
 void
 sigHandler(int sig){
-	int res;
+	#ifdef YADE_DEBUG
+		int res;
+	#endif
 	switch(sig){
 	#ifdef YADE_PYTHON
 		case SIGINT:

Modified: trunk/lib/import/STLReader.hpp
===================================================================
--- trunk/lib/import/STLReader.hpp	2009-08-05 17:18:28 UTC (rev 1925)
+++ trunk/lib/import/STLReader.hpp	2009-08-05 18:00:48 UTC (rev 1926)
@@ -74,13 +74,14 @@
     fseek(fp, 0, SEEK_END);
     int file_size = ftell(fp);
     int facenum;
+	 int res;
     /* Check for binary or ASCII file */
     fseek(fp, STL_LABEL_SIZE, SEEK_SET);
-    fread(&facenum, sizeof(int), 1, fp);
+    res=fread(&facenum, sizeof(int), 1, fp);
     int expected_file_size=STL_LABEL_SIZE + 4 + (sizeof(short)+4*sizeof(float) )*facenum ;
     if(file_size ==  expected_file_size) binary = true;
     unsigned char tmpbuf[128];
-    fread(tmpbuf,sizeof(tmpbuf),1,fp);
+    res=fread(tmpbuf,sizeof(tmpbuf),1,fp);
     for(size_t i = 0; i < sizeof(tmpbuf); i++)
       {
 	if(tmpbuf[i] > 127)
@@ -173,8 +174,9 @@
     }
 
     int facenum;
+	 int res;
     fseek(fp, STL_LABEL_SIZE, SEEK_SET);
-    fread(&facenum, sizeof(int), 1, fp);
+    res=fread(&facenum, sizeof(int), 1, fp);
     
     vector<Vrtx> vcs;
     set<pair<int,int> > egs;
@@ -185,9 +187,9 @@
       short attr;
       float n[3];
       Vrtx v[3];
-      fread(&n,3*sizeof(float),1,fp);
-      fread(&v,sizeof(Vrtx),3,fp);
-      fread(&attr,sizeof(short),1,fp);
+      res=fread(&n,3*sizeof(float),1,fp);
+      res=fread(&v,sizeof(Vrtx),3,fp);
+      res=fread(&attr,sizeof(short),1,fp);
 
       //FIXME: Убрать дублирование кода с open_ascii
       int vid[3];

Modified: trunk/pkg/dem/DataClass/Clump.cpp
===================================================================
--- trunk/pkg/dem/DataClass/Clump.cpp	2009-08-05 17:18:28 UTC (rev 1925)
+++ trunk/pkg/dem/DataClass/Clump.cpp	2009-08-05 18:00:48 UTC (rev 1926)
@@ -2,11 +2,13 @@
 
 #include"Clump.hpp"
 #include<algorithm>
+#include<yade/core/MetaBody.hpp>
+#include<yade/core/BodyContainer.hpp>
+#include<yade/pkg-common/RigidBodyParameters.hpp>
 
-YADE_PLUGIN((Clump)(ClumpMemberMover)(ClumpTestGen));
+YADE_PLUGIN((Clump)(ClumpMemberMover));
 CREATE_LOGGER(Clump);
 CREATE_LOGGER(ClumpMemberMover);
-CREATE_LOGGER(ClumpTestGen);
 
 /**************************************************************************************
  ************************************* ClumpMemberMover ******************************
@@ -326,101 +328,3 @@
 
 
 
-/**************************************************************************************
- ********************* ClumpTestGen ***************************************************
- **************************************************************************************/
-
-#include<yade/core/MetaBody.hpp>
-#include<yade/pkg-dem/Shop.hpp>
-
-bool ClumpTestGen::generate()
-{
-	//Shop::setDefault("param_pythonRunExpr",string("if S.i%50==0 and S.i<1000 and S.i>500:\n\tprint S.i,len(S.sel),B[1].x, B[1].E"));
-
-	rootBody=Shop::rootBody();
-	Shop::rootBodyActors(rootBody);
-	// clumps do not need to subscribe currently (that will most likely change, though)
-	rootBody->engines.push_back(shared_ptr<ClumpMemberMover>(new ClumpMemberMover));
-	
-
-	shared_ptr<MetaBody> oldRootBody=Omega::instance().getRootBody();
-	Omega::instance().setRootBody(rootBody);
-
-	shared_ptr<Body> ground=Shop::box(Vector3r(0,0,-1),Vector3r(3,3,.2));
-	ground->isDynamic=false;
-	// revert random colors for this single case...
-	ground->geometricalModel->diffuseColor=Vector3r(.6,.6,.6);
-	ground->interactingGeometry->diffuseColor=Vector3r(.3,.3,.3);
-	rootBody->bodies->insert(ground);
-
-	vector<Vector3r> relPos; vector<Real> radii; Vector3r clumpPos;
-
-	// standalone (non-clump!) sphere as well
-	shared_ptr<Body> sphere=Shop::sphere(Vector3r(0,0,0),.5);
-	rootBody->bodies->insert(sphere);
-	// one-sphere clump
-	clumpPos=Vector3r(-2,0,0);
-	relPos.push_back(Vector3r(0,0,0)); radii.push_back(.5);
-	createOneClump(rootBody,clumpPos,relPos,radii);
-	relPos.clear(); radii.clear();
-	// two-sphere clump
-	clumpPos=Vector3r(2,0,0);
-	relPos.push_back(Vector3r(0,-.5,.5)); radii.push_back(.5);
-	relPos.push_back(Vector3r(0,.5,0)); radii.push_back(.5);
-	createOneClump(rootBody,clumpPos,relPos,radii);
-	relPos.clear(); radii.clear();
-	// three-sphere slump
-	clumpPos=Vector3r(0,2,0);
-	relPos.push_back(Vector3r(0,-.5,.5)); radii.push_back(.5);
-	relPos.push_back(Vector3r(0,.5,0)); radii.push_back(.5);
-	relPos.push_back(Vector3r(.5,0,0)); radii.push_back(.5);
-	createOneClump(rootBody,clumpPos,relPos,radii);
-	relPos.clear(); radii.clear();
-	// four-sphere slump
-	clumpPos=Vector3r(0,-2,0);
-	relPos.push_back(Vector3r(0,0,0)); radii.push_back(.5);
-	relPos.push_back(Vector3r(.5,0,0)); radii.push_back(.5);
-	relPos.push_back(Vector3r(0,.5,0)); radii.push_back(.5);
-	relPos.push_back(Vector3r(0,0,.5)); radii.push_back(.5);
-	createOneClump(rootBody,clumpPos,relPos,radii);
-	relPos.clear(); radii.clear();
-
-	// restore Omega
-	Omega::instance().setRootBody(oldRootBody);
-	
-	message="OK";
-	return true;
-}
-
-/*! \brief Generate clump of spheres, the result will be inserted into rootBody.
- *
- * Attention here: clump's id must be greater than id of any of its constituents; therefore
- *   1. create bodies that will be clumped, add them to bodies (at that moment they get their id) and save their ids in clumpMembers
- *   2. create (empty) clump and add it to bodies
- *	  3. add bodies to be clumped to the clump
- *	  4. call Clump::updateProperties to get physical properties physically right (inertia, position, orientation, mass, ...).
- *
- * @param clumpPos Center of the clump (not necessarily centroid); serves merely as reference for sphere positions.
- * @param relPos Relative positions of individual spheres' centers.
- * @param radii Radii of composing spheres. Must have the same length as relPos.
- */
-void ClumpTestGen::createOneClump(shared_ptr<MetaBody>& rootBody, Vector3r clumpPos, vector<Vector3r> relPos, vector<Real> radii)
-{
-	assert(relPos.size()==radii.size());
-	list<body_id_t> clumpMembers;	
-	for(size_t i=0; i<relPos.size(); i++){
-		shared_ptr<Body> sphere=Shop::sphere(clumpPos+relPos[i],radii[i]);
-		body_id_t lastId=(body_id_t)rootBody->bodies->insert(sphere);
-		clumpMembers.push_back(lastId);
-		LOG_TRACE("Generated (not yet) clumped sphere #"<<lastId);
-	}
-	shared_ptr<Clump> clump=shared_ptr<Clump>(new Clump());
-	shared_ptr<Body> clumpAsBody=static_pointer_cast<Body>(clump);
-	clump->isDynamic=true;
-	rootBody->bodies->insert(clumpAsBody);
-	FOREACH(body_id_t id, clumpMembers){
-		clump->add(id);
-	}
-	clump->updateProperties(false);
-}
-

Modified: trunk/pkg/dem/DataClass/Clump.hpp
===================================================================
--- trunk/pkg/dem/DataClass/Clump.hpp	2009-08-05 17:18:28 UTC (rev 1925)
+++ trunk/pkg/dem/DataClass/Clump.hpp	2009-08-05 18:00:48 UTC (rev 1926)
@@ -5,15 +5,9 @@
 #include<vector>
 #include<map>
 #include<yade/core/Body.hpp>
-#include<yade/core/MetaBody.hpp>
-#include<yade/core/FileGenerator.hpp>
-#include<yade/core/DeusExMachina.hpp>
-#include<yade/lib-factory/Factorable.hpp>
-#include<yade/pkg-common/PhysicalParametersEngineUnit.hpp>
-#include<yade/pkg-common/RigidBodyParameters.hpp>
-#include<yade/pkg-common/AABB.hpp>
 #include<yade/lib-base/Logging.hpp>
 #include<yade/lib-base/yadeWm3Extra.hpp>
+#include<yade/core/DeusExMachina.hpp>
 
 
 /*! Body representing clump (rigid aggregate) composed by other existing bodies.
@@ -88,6 +82,7 @@
 };
 REGISTER_SERIALIZABLE(Clump);
 
+
 /*! Update ::Clump::members positions so that the Clump behaves as a rigid body. */
 class ClumpMemberMover: public DeusExMachina {
 	public:
@@ -101,15 +96,3 @@
 };
 REGISTER_SERIALIZABLE(ClumpMemberMover);
 
-/*! \brief Test some basic clump functionality; show how to use clumps as well. */
-class ClumpTestGen : public FileGenerator {
-		void createOneClump(shared_ptr<MetaBody>& rootBody, Vector3r clumpPos, vector<Vector3r> relPos, vector<Real> radii);
-		shared_ptr<ClumpMemberMover> clumpMover;
-	public :
-		bool generate();
-	DECLARE_LOGGER;
-	REGISTER_CLASS_AND_BASE(ClumpTestGen,FileGenerator);
-	REGISTER_ATTRIBUTES(FileGenerator,/*nothing here*/);
-};
-REGISTER_SERIALIZABLE(ClumpTestGen);
-

Added: trunk/pkg/dem/PreProcessor/ClumpTestGen.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/ClumpTestGen.cpp	2009-08-05 17:18:28 UTC (rev 1925)
+++ trunk/pkg/dem/PreProcessor/ClumpTestGen.cpp	2009-08-05 18:00:48 UTC (rev 1926)
@@ -0,0 +1,107 @@
+// © 2007 Vaclav Smilauer <eudoxos@xxxxxxxx>
+
+#include"ClumpTestGen.hpp"
+#include<yade/pkg-dem/Clump.hpp>
+#include<yade/core/MetaBody.hpp>
+#include<yade/pkg-dem/Shop.hpp>
+#include<yade/core/FileGenerator.hpp>
+#include<yade/core/DeusExMachina.hpp>
+#include<yade/pkg-common/PhysicalParametersEngineUnit.hpp>
+#include<yade/pkg-common/RigidBodyParameters.hpp>
+#include<yade/pkg-common/AABB.hpp>
+
+YADE_PLUGIN((ClumpTestGen));
+CREATE_LOGGER(ClumpTestGen);
+
+bool ClumpTestGen::generate()
+{
+	//Shop::setDefault("param_pythonRunExpr",string("if S.i%50==0 and S.i<1000 and S.i>500:\n\tprint S.i,len(S.sel),B[1].x, B[1].E"));
+
+	rootBody=Shop::rootBody();
+	Shop::rootBodyActors(rootBody);
+	// clumps do not need to subscribe currently (that will most likely change, though)
+	rootBody->engines.push_back(shared_ptr<ClumpMemberMover>(new ClumpMemberMover));
+	
+
+	shared_ptr<MetaBody> oldRootBody=Omega::instance().getRootBody();
+	Omega::instance().setRootBody(rootBody);
+
+	shared_ptr<Body> ground=Shop::box(Vector3r(0,0,-1),Vector3r(3,3,.2));
+	ground->isDynamic=false;
+	// revert random colors for this single case...
+	ground->geometricalModel->diffuseColor=Vector3r(.6,.6,.6);
+	ground->interactingGeometry->diffuseColor=Vector3r(.3,.3,.3);
+	rootBody->bodies->insert(ground);
+
+	vector<Vector3r> relPos; vector<Real> radii; Vector3r clumpPos;
+
+	// standalone (non-clump!) sphere as well
+	shared_ptr<Body> sphere=Shop::sphere(Vector3r(0,0,0),.5);
+	rootBody->bodies->insert(sphere);
+	// one-sphere clump
+	clumpPos=Vector3r(-2,0,0);
+	relPos.push_back(Vector3r(0,0,0)); radii.push_back(.5);
+	createOneClump(rootBody,clumpPos,relPos,radii);
+	relPos.clear(); radii.clear();
+	// two-sphere clump
+	clumpPos=Vector3r(2,0,0);
+	relPos.push_back(Vector3r(0,-.5,.5)); radii.push_back(.5);
+	relPos.push_back(Vector3r(0,.5,0)); radii.push_back(.5);
+	createOneClump(rootBody,clumpPos,relPos,radii);
+	relPos.clear(); radii.clear();
+	// three-sphere slump
+	clumpPos=Vector3r(0,2,0);
+	relPos.push_back(Vector3r(0,-.5,.5)); radii.push_back(.5);
+	relPos.push_back(Vector3r(0,.5,0)); radii.push_back(.5);
+	relPos.push_back(Vector3r(.5,0,0)); radii.push_back(.5);
+	createOneClump(rootBody,clumpPos,relPos,radii);
+	relPos.clear(); radii.clear();
+	// four-sphere slump
+	clumpPos=Vector3r(0,-2,0);
+	relPos.push_back(Vector3r(0,0,0)); radii.push_back(.5);
+	relPos.push_back(Vector3r(.5,0,0)); radii.push_back(.5);
+	relPos.push_back(Vector3r(0,.5,0)); radii.push_back(.5);
+	relPos.push_back(Vector3r(0,0,.5)); radii.push_back(.5);
+	createOneClump(rootBody,clumpPos,relPos,radii);
+	relPos.clear(); radii.clear();
+
+	// restore Omega
+	Omega::instance().setRootBody(oldRootBody);
+	
+	message="OK";
+	return true;
+}
+
+/*! \brief Generate clump of spheres, the result will be inserted into rootBody.
+ *
+ * Attention here: clump's id must be greater than id of any of its constituents; therefore
+ *   1. create bodies that will be clumped, add them to bodies (at that moment they get their id) and save their ids in clumpMembers
+ *   2. create (empty) clump and add it to bodies
+ *	  3. add bodies to be clumped to the clump
+ *	  4. call Clump::updateProperties to get physical properties physically right (inertia, position, orientation, mass, ...).
+ *
+ * @param clumpPos Center of the clump (not necessarily centroid); serves merely as reference for sphere positions.
+ * @param relPos Relative positions of individual spheres' centers.
+ * @param radii Radii of composing spheres. Must have the same length as relPos.
+ */
+void ClumpTestGen::createOneClump(shared_ptr<MetaBody>& rootBody, Vector3r clumpPos, vector<Vector3r> relPos, vector<Real> radii)
+{
+	assert(relPos.size()==radii.size());
+	list<body_id_t> clumpMembers;	
+	for(size_t i=0; i<relPos.size(); i++){
+		shared_ptr<Body> sphere=Shop::sphere(clumpPos+relPos[i],radii[i]);
+		body_id_t lastId=(body_id_t)rootBody->bodies->insert(sphere);
+		clumpMembers.push_back(lastId);
+		LOG_TRACE("Generated (not yet) clumped sphere #"<<lastId);
+	}
+	shared_ptr<Clump> clump=shared_ptr<Clump>(new Clump());
+	shared_ptr<Body> clumpAsBody=static_pointer_cast<Body>(clump);
+	clump->isDynamic=true;
+	rootBody->bodies->insert(clumpAsBody);
+	FOREACH(body_id_t id, clumpMembers){
+		clump->add(id);
+	}
+	clump->updateProperties(false);
+}
+
+

Added: trunk/pkg/dem/PreProcessor/ClumpTestGen.hpp
===================================================================
--- trunk/pkg/dem/PreProcessor/ClumpTestGen.hpp	2009-08-05 17:18:28 UTC (rev 1925)
+++ trunk/pkg/dem/PreProcessor/ClumpTestGen.hpp	2009-08-05 18:00:48 UTC (rev 1926)
@@ -0,0 +1,23 @@
+// © 2007 Vaclav Smilauer <eudoxos@xxxxxxxx>
+
+#pragma once
+
+#include<yade/core/MetaBody.hpp>
+#include<yade/core/FileGenerator.hpp>
+#include<yade/core/DeusExMachina.hpp>
+#include<yade/pkg-dem/Clump.hpp>
+
+
+/*! \brief Test some basic clump functionality; show how to use clumps as well. */
+class ClumpTestGen : public FileGenerator {
+		void createOneClump(shared_ptr<MetaBody>& rootBody, Vector3r clumpPos, vector<Vector3r> relPos, vector<Real> radii);
+		shared_ptr<ClumpMemberMover> clumpMover;
+	public :
+		bool generate();
+	DECLARE_LOGGER;
+	REGISTER_CLASS_AND_BASE(ClumpTestGen,FileGenerator);
+	REGISTER_ATTRIBUTES(FileGenerator,/*nothing here*/);
+};
+REGISTER_SERIALIZABLE(ClumpTestGen);
+
+