← Back to team overview

yade-dev team mailing list archive

[svn] r1797 - in trunk/pkg/dem: . Engine/StandAloneEngine

 

Author: richefeu
Date: 2009-06-15 15:43:29 +0200 (Mon, 15 Jun 2009)
New Revision: 1797

Added:
   trunk/pkg/dem/Engine/StandAloneEngine/HistoryRecorder.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/HistoryRecorder.hpp
Modified:
   trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.cpp
   trunk/pkg/dem/SConscript
Log:
- Add 'HistoryRecorder' to save the sample and network state with a given time-step interval.
- Correct a small bug due to the fact that a Clump cannot be casted into a GeometricalModel (and I don't know why!)


Added: trunk/pkg/dem/Engine/StandAloneEngine/HistoryRecorder.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/HistoryRecorder.cpp	2009-06-13 21:47:20 UTC (rev 1796)
+++ trunk/pkg/dem/Engine/StandAloneEngine/HistoryRecorder.cpp	2009-06-15 13:43:29 UTC (rev 1797)
@@ -0,0 +1,149 @@
+/*************************************************************************
+*  Copyright (C) 2009 by Vincent Richefeu                                *
+*  Vincent.Richefeu@xxxxxxxxxxx                                          *
+*                                                                        *
+*  This program is free software; it is licensed under the terms of the  *
+*  GNU General Public License v2 or later. See file LICENSE for details. *
+*************************************************************************/
+
+#include "HistoryRecorder.hpp"
+#include<yade/pkg-common/RigidBodyParameters.hpp>
+#include<yade/core/Omega.hpp>
+#include<yade/core/MetaBody.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include <yade/pkg-common/Sphere.hpp>
+#include <yade/pkg-common/Box.hpp>
+
+#include <yade/pkg-dem/SpheresContactGeometry.hpp>
+#include <yade/pkg-common/NormalShearInteractions.hpp>
+
+HistoryRecorder::HistoryRecorder () : DataRecorder()
+{
+  outputBase = "spl_nwk_";
+  interval   = 50;
+  stateId    = 0;
+}
+
+
+HistoryRecorder::~HistoryRecorder ()
+{
+
+}
+
+
+void HistoryRecorder::postProcessAttributes(bool deserializing)
+{
+	if(deserializing)
+	{
+		
+	}
+}
+
+
+void HistoryRecorder::registerAttributes()
+{
+	DataRecorder::registerAttributes();
+	REGISTER_ATTRIBUTE(outputBase);
+	REGISTER_ATTRIBUTE(interval);
+	REGISTER_ATTRIBUTE(stateId);
+}
+
+bool HistoryRecorder::isActivated()
+{
+	return ((Omega::instance().getCurrentIteration() % interval == 0));
+}
+
+
+
+void HistoryRecorder::action(MetaBody * ncb)
+{
+  shared_ptr<BodyContainer>& bodies = ncb->bodies;
+
+  std::string outputFile = outputBase + lexical_cast<string>(stateId++) + ".his";
+  std::ofstream ofs(outputFile.c_str());
+  cout << "Saving " << outputFile << "..." << endl;
+   ofs << "Sample{" << endl;
+
+   BodyContainer::iterator bi    = bodies->begin();
+   BodyContainer::iterator biEnd = bodies->end();
+   for( ; bi != biEnd ; ++bi)
+   {
+     const shared_ptr<Body>& b = *bi;
+	 if (b->isClump()) continue;
+	 
+     const RigidBodyParameters* p = YADE_CAST<RigidBodyParameters*>(b->physicalParameters.get());
+	 const GeometricalModel* gm   = YADE_CAST<GeometricalModel*>(b->geometricalModel.get());
+
+	if ( typeid(*gm) == typeid(Sphere) )
+     {
+		ofs << "sphere " << b->groupMask << " " << YADE_CAST<Sphere*>(b->geometricalModel.get())->radius
+		<< " " << p->se3.position[0] << " " << p->se3.position[1] << " " << p->se3.position[2]
+		<< " 0 0 0" 
+		<< " " << p->velocity[0] << " " << p->velocity[1] << " " << p->velocity[2]
+		<< " " << p->angularVelocity[0] << " " << p->angularVelocity[1] << " " << p->angularVelocity[2]
+		<< endl << flush;
+	 }
+
+	if ( typeid(*gm) == typeid(Box) )
+	{
+	  ofs << "box " << b->groupMask << " " << YADE_CAST<Box*>(b->geometricalModel.get())->extents
+	  << " " << p->se3.position[0] << " " << p->se3.position[1] << " " << p->se3.position[2]
+	  << " 0 0 0"
+	  << " " << p->velocity[0] << " " << p->velocity[1] << " " << p->velocity[2]
+	  << " " << p->angularVelocity[0] << " " << p->angularVelocity[1] << " " << p->angularVelocity[2]
+	  << endl << flush;
+	}
+
+   } 
+   ofs << "}" << endl << endl;
+   
+   ofs << "Network{" << endl;
+   
+   InteractionContainer::iterator ii    = ncb->transientInteractions->begin();
+   InteractionContainer::iterator iiEnd = ncb->transientInteractions->end();
+   
+   for( ;ii!=iiEnd;++ii)
+   {
+	 if ((*ii)->isReal()) // to be claryfied...
+	 {
+	   const shared_ptr<Interaction>& contact = *ii;
+
+	   const InteractionGeometry* ig = YADE_CAST<InteractionGeometry*>(contact->interactionGeometry.get());
+	   
+	   body_id_t id1 = contact->getId1();
+	   body_id_t id2 = contact->getId2();
+	   
+	   shared_ptr<Body> b1=(*bodies)[id1];
+	   shared_ptr<Body> b2=(*bodies)[id2];
+
+	   if( typeid(*ig) == typeid(SpheresContactGeometry) )
+	   {
+		 
+		 if (typeid(*(b1->geometricalModel.get())) == typeid(Sphere)
+		  && typeid(*(b2->geometricalModel.get())) == typeid(Sphere))
+		 {
+		   const NormalShearInteraction* nsi = YADE_CAST<NormalShearInteraction*>(contact->interactionPhysics.get());
+		   Vector3r n = nsi->normalForce;
+		   Real fn = n.Length();
+
+		   Vector3r t = nsi->shearForce;
+		   Real ft = t.Length();
+		   
+		   // remark: This is not exactly the format used in gdm-tk
+		   ofs << "spsp " << id1 << " " << id2 << " " << n << " " << t << " "
+			   << fn << " " << ft << " 0 0 0 0"
+		       << endl;
+		 }
+
+	   }
+	 }
+   }
+
+  ofs << "}" << endl << endl;
+   
+}
+
+
+
+

Added: trunk/pkg/dem/Engine/StandAloneEngine/HistoryRecorder.hpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/HistoryRecorder.hpp	2009-06-13 21:47:20 UTC (rev 1796)
+++ trunk/pkg/dem/Engine/StandAloneEngine/HistoryRecorder.hpp	2009-06-15 13:43:29 UTC (rev 1797)
@@ -0,0 +1,38 @@
+/*************************************************************************
+*  Copyright (C) 2009 by Vincent Richefeu                                *
+*  Vincent.Richefeu@xxxxxxxxxxx                                          *
+*                                                                        *
+*  This program is free software; it is licensed under the terms of the  *
+*  GNU General Public License v2 or later. See file LICENSE for details. *
+*************************************************************************/
+
+#pragma once
+
+#include<yade/core/DataRecorder.hpp>
+#include <string>
+#include <fstream>
+
+class HistoryRecorder : public DataRecorder
+{
+public :
+	
+	string outputBase; 
+    int interval;
+    int stateId;
+	
+	HistoryRecorder ();
+	~HistoryRecorder ();
+	virtual void action(MetaBody*);
+	virtual bool isActivated();
+
+protected :
+
+	virtual void postProcessAttributes(bool deserializing);
+	virtual void registerAttributes();
+	REGISTER_CLASS_NAME(HistoryRecorder);
+	REGISTER_BASE_CLASS_NAME(DataRecorder);
+};
+
+REGISTER_SERIALIZABLE(HistoryRecorder);
+
+

Modified: trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.cpp	2009-06-13 21:47:20 UTC (rev 1796)
+++ trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.cpp	2009-06-15 13:43:29 UTC (rev 1797)
@@ -67,6 +67,8 @@
    for(; bi != biEnd ; ++bi)
    {
      const shared_ptr<Body>& b = *bi;
+	 if (b->isClump()) continue;
+	 
      const RigidBodyParameters* p = YADE_CAST<RigidBodyParameters*>(b->physicalParameters.get());
      const GeometricalModel* gm   = YADE_CAST<GeometricalModel*>(b->geometricalModel.get());
 

Modified: trunk/pkg/dem/SConscript
===================================================================
--- trunk/pkg/dem/SConscript	2009-06-13 21:47:20 UTC (rev 1796)
+++ trunk/pkg/dem/SConscript	2009-06-15 13:43:29 UTC (rev 1797)
@@ -982,6 +982,14 @@
 	,['Engine/StandAloneEngine/RigidBodyRecorder.cpp']
 	,LIBS=env['LIBS']+['RigidBodyParameters'])
 
+	,env.SharedLibrary('MGPRecorder'
+	,['Engine/StandAloneEngine/MGPRecorder.cpp']
+	,LIBS=env['LIBS']+['RigidBodyParameters','Sphere'])
+
+	,env.SharedLibrary('HistoryRecorder'
+	,['Engine/StandAloneEngine/HistoryRecorder.cpp']
+	,LIBS=env['LIBS']+['RigidBodyParameters','Sphere','Box','SpheresContactGeometry','NormalShearInteractions'])
+
 	,env.SharedLibrary('TestSimpleViscoelastic'
 		,['PreProcessor/TestSimpleViscoelastic.cpp']
 		,LIBS=env['LIBS']+['AABB'




Follow ups