yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #00924
[svn] r1654 - trunk/pkg/dem/Engine/StandAloneEngine
Author: richefeu
Date: 2009-02-02 17:25:12 +0100 (Mon, 02 Feb 2009)
New Revision: 1654
Added:
trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.cpp
trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.hpp
Log:
Add a DataRecoder that generate MGP files (only for Spheres for the moment).
The MGP files can then be read with mgpost.
Added: trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.cpp 2009-02-02 14:25:50 UTC (rev 1653)
+++ trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.cpp 2009-02-02 16:25:12 UTC (rev 1654)
@@ -0,0 +1,96 @@
+/*************************************************************************
+* 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 "MGPRecorder.hpp"
+
+#include <yade/core/Omega.hpp>
+#include <yade/core/MetaBody.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include <yade/pkg-common/Sphere.hpp>
+
+MGPRecorder::MGPRecorder(): DataRecorder()
+{
+ outputBase = "mgp.out.";
+ interval = 50;
+ stateId = 0;
+}
+
+
+MGPRecorder::~MGPRecorder ()
+{
+
+}
+
+
+void MGPRecorder::postProcessAttributes(bool deserializing)
+{
+ if(deserializing)
+ {
+ //
+ }
+}
+
+
+void MGPRecorder::registerAttributes()
+{
+ DataRecorder::registerAttributes();
+ REGISTER_ATTRIBUTE(outputBase);
+ REGISTER_ATTRIBUTE(interval);
+ REGISTER_ATTRIBUTE(stateId);
+}
+
+bool MGPRecorder::isActivated()
+{
+ return ((Omega::instance().getCurrentIteration() % interval == 0));
+}
+
+void MGPRecorder::action(MetaBody * ncb)
+{
+ shared_ptr<BodyContainer>& bodies = ncb->bodies;
+
+ std::string outputFile = outputBase+lexical_cast<string>(stateId);
+ std::ofstream ofs(outputFile.c_str());
+
+ ofs << "<?xml version=\"1.0\"?>" << endl
+ << " <mgpost mode=\"3D\">" << endl
+ << " <state id=\"" << stateId++
+ << "\" time=\"" << lexical_cast<string>(Omega::instance().getSimulationTime()) << "\">" << endl;
+
+ BodyContainer::iterator bi = bodies->begin();
+ BodyContainer::iterator biEnd = bodies->end();
+ for(; bi != biEnd ; ++bi)
+ {
+ const shared_ptr<Body>& b = *bi;
+ const RigidBodyParameters* p = YADE_CAST<RigidBodyParameters*>(b->physicalParameters.get());
+ const GeometricalModel* gm = YADE_CAST<GeometricalModel*>(b->geometricalModel.get());
+
+ if ( typeid(*gm) == typeid(Sphere) )
+ {
+ ofs << " <body>" << endl;
+ ofs << " <SPHER id=\"" << b->getId() << "\" r=\"" << YADE_CAST<Sphere*>(b->geometricalModel.get())->radius << "\">" << endl;
+ ofs << " <position x=\"" << p->se3.position[0] << "\" y=\""
+ << p->se3.position[1] << "\" z=\"" << p->se3.position[2] << "\"/>" << endl;
+ ofs << " <velocity x=\"" << p->velocity[0] << "\" y=\""
+ << p->velocity[1] << "\" z=\"" << p->velocity[2] << "\"/>" << endl;
+ ofs << " </SPHER>" << endl;
+ ofs << " </body>" << endl << flush;
+ }
+
+
+
+ }
+
+
+ ofs << " </state>" << endl
+ << " </mgpost>" << endl << flush;
+
+
+}
+
+YADE_PLUGIN();
Added: trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.hpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.hpp 2009-02-02 14:25:50 UTC (rev 1653)
+++ trunk/pkg/dem/Engine/StandAloneEngine/MGPRecorder.hpp 2009-02-02 16:25:12 UTC (rev 1654)
@@ -0,0 +1,44 @@
+/*************************************************************************
+* 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 <yade/pkg-common/RigidBodyParameters.hpp>
+#include<yade/core/GeometricalModel.hpp>
+//#include <set>
+
+
+class MGPRecorder : public DataRecorder
+{
+private:
+ //shared_ptr<RigidBodyParameters> rigidBodyParameters;
+ //set<int> body_ids;
+
+
+public :
+ string outputBase;
+ int interval;
+ int stateId;
+
+ MGPRecorder ();
+ ~MGPRecorder ();
+
+ virtual void action(MetaBody*);
+ bool isActivated();
+
+protected :
+ virtual void postProcessAttributes(bool deserializing);
+ void registerAttributes();
+ REGISTER_CLASS_NAME(MGPRecorder);
+ REGISTER_BASE_CLASS_NAME(DataRecorder);
+};
+
+REGISTER_SERIALIZABLE(MGPRecorder);
+
+