yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #00880
[svn] r1632 - in trunk: core pkg/common pkg/common/Engine/StandAloneEngine scripts
Author: sega
Date: 2009-01-23 10:05:03 +0100 (Fri, 23 Jan 2009)
New Revision: 1632
Added:
trunk/pkg/common/Engine/StandAloneEngine/SpheresFactory.cpp
trunk/pkg/common/Engine/StandAloneEngine/SpheresFactory.hpp
Modified:
trunk/core/BroadInteractor.hpp
trunk/core/MetaBody.cpp
trunk/core/MetaBody.hpp
trunk/pkg/common/SConscript
trunk/scripts/test-sphere-facet.py
Log:
Intermediate commit for SpheresFactory. Don't work yet.
1. New engine SpheresFactory
2. Add function engineByLabel to MetaBody
3. Add members to BroadInteractor.
Modified: trunk/core/BroadInteractor.hpp
===================================================================
--- trunk/core/BroadInteractor.hpp 2009-01-21 10:33:46 UTC (rev 1631)
+++ trunk/core/BroadInteractor.hpp 2009-01-23 09:05:03 UTC (rev 1632)
@@ -9,6 +9,7 @@
#ifndef BROADINTERACTOR_HPP
#define BROADINTERACTOR_HPP
+#include <yade/core/BoundingVolume.hpp>
#include "StandAloneEngine.hpp"
class BroadInteractor : public StandAloneEngine
@@ -16,7 +17,11 @@
public :
BroadInteractor() {};
virtual ~BroadInteractor() {};
+ virtual bool probeBoundingVolume(const shared_ptr<BoundingVolume>& bv, const Vector3r& center){throw;}
+ vector<body_id_t> probedBodies;
+ protected:
+
REGISTER_CLASS_NAME(BroadInteractor);
REGISTER_BASE_CLASS_NAME(StandAloneEngine);
};
Modified: trunk/core/MetaBody.cpp
===================================================================
--- trunk/core/MetaBody.cpp 2009-01-21 10:33:46 UTC (rev 1631)
+++ trunk/core/MetaBody.cpp 2009-01-23 09:05:03 UTC (rev 1632)
@@ -85,6 +85,12 @@
return shared_ptr<Engine>();
}
+shared_ptr<Engine> MetaBody::engineByLabel(string s){
+ FOREACH(shared_ptr<Engine> e, engines){
+ if(e->label==s) return e;
+ }
+ return shared_ptr<Engine>();
+}
void MetaBody::setTimeSteppersActive(bool a)
{
Modified: trunk/core/MetaBody.hpp
===================================================================
--- trunk/core/MetaBody.hpp 2009-01-21 10:33:46 UTC (rev 1631)
+++ trunk/core/MetaBody.hpp 2009-01-23 09:05:03 UTC (rev 1632)
@@ -40,6 +40,7 @@
void setTimeSteppersActive(bool a);
shared_ptr<Engine> engineByName(string s);
+ shared_ptr<Engine> engineByLabel(string s);
Real dt;
long currentIteration;
Added: trunk/pkg/common/Engine/StandAloneEngine/SpheresFactory.cpp
===================================================================
--- trunk/pkg/common/Engine/StandAloneEngine/SpheresFactory.cpp 2009-01-21 10:33:46 UTC (rev 1631)
+++ trunk/pkg/common/Engine/StandAloneEngine/SpheresFactory.cpp 2009-01-23 09:05:03 UTC (rev 1632)
@@ -0,0 +1,106 @@
+/*************************************************************************
+* Copyright (C) 2009 by Sergei Dorofeenko *
+* sega@xxxxxxxxxxxxxxxx *
+* *
+* 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<boost/random.hpp>
+#include<yade/core/Body.hpp>
+#include<yade/pkg-common/PersistentSAPCollider.hpp>
+#include<yade/pkg-common/AABB.hpp>
+#include<yade/pkg-common/InteractingSphere.hpp>
+#include<yade/pkg-common/InteractingFacet.hpp>
+#include<yade/pkg-common/Sphere.hpp>
+#include<yade/pkg-dem/BodyMacroParameters.hpp>
+#include"SpheresFactory.hpp"
+
+SpheresFactory::SpheresFactory() : first_run(true)
+{
+
+}
+
+SpheresFactory::~SpheresFactory()
+{
+
+}
+
+
+
+void SpheresFactory::action(MetaBody* ncb)
+{
+ if (first_run)
+ {
+ //FIXME: Why dynamic_cast failed here???
+ Engine* eng = ncb->engineByLabel(labelBroadInteractor).get();
+ bI=dynamic_cast<BroadInteractor*>(eng);
+ if (!bI)
+ {
+ LOG_FATAL("For engine with label '" << labelBroadInteractor << "' dynamic_cast from class '" << eng->getClassName() << "' to class 'BroadInteractor' failed!" );
+ return;
+ }
+ first_run=false;
+ }
+
+ static boost::variate_generator<boost::minstd_rand,boost::uniform_int<> > randomFacet(boost::minstd_rand(),boost::uniform_int<>(0,factoryFacets.size()-1));
+
+ static boost::variate_generator<boost::mt19937,boost::uniform_real<> > random(boost::mt19937(),boost::uniform_real<>(0,1));
+
+ body_id_t facetId = factoryFacets[randomFacet()];
+ Real t1 = random();
+ Real t2 = random()*(1-t1);
+
+ shared_ptr<Body> facet = Body::byId(factoryFacets[facetId]);
+ InteractingFacet* ifacet = static_cast<InteractingFacet*>(facet->interactingGeometry.get());
+
+ Vector3r position = t1*(ifacet->vertices[1]-ifacet->vertices[0])+t2*(ifacet->vertices[2]-ifacet->vertices[0])+ifacet->vertices[0]+facet->physicalParameters->se3.position;
+
+ Real radius=0.1;
+
+ shared_ptr<Body> sphere;
+ createSphere(sphere,position,radius);
+ ncb->bodies->insert(sphere);
+
+ bI->action(ncb);
+}
+
+void SpheresFactory::createSphere(shared_ptr<Body>& body, const Vector3r& position, Real radius)
+{
+ body = shared_ptr<Body>(new Body(body_id_t(0),1));
+ shared_ptr<BodyMacroParameters> physics(new BodyMacroParameters);
+ shared_ptr<AABB> aabb(new AABB);
+ shared_ptr<Sphere> gSphere(new Sphere);
+ shared_ptr<InteractingSphere> iSphere(new InteractingSphere);
+
+ Quaternionr q;
+ q.FromAxisAngle( Vector3r(0,0,1),0);
+
+ body->isDynamic = false;
+
+ physics->angularVelocity = Vector3r(0,0,0);
+ physics->velocity = Vector3r(0,0,0);
+ physics->mass = 4.0/3.0*Mathr::PI*radius*radius*radius*2400;
+ physics->inertia = Vector3r(2.0/5.0*physics->mass*radius*radius,2.0/5.0*physics->mass*radius*radius,2.0/5.0*physics->mass*radius*radius); //
+ physics->se3 = Se3r(position,q);
+ physics->young = 0.15e9;
+ physics->poisson = 0.3;
+ //physics->frictionAngle = sphereFrictionDeg * Mathr::PI/180.0;
+
+ aabb->diffuseColor = Vector3r(0,1,0);
+
+ gSphere->radius = radius;
+ gSphere->diffuseColor = Vector3r(Mathr::UnitRandom(),Mathr::UnitRandom(),Mathr::UnitRandom());
+ gSphere->wire = false;
+ gSphere->visible = true;
+ gSphere->shadowCaster = true;
+
+ iSphere->radius = radius;
+ iSphere->diffuseColor = Vector3r(0.8,0.3,0.3);
+
+ body->interactingGeometry = iSphere;
+ body->geometricalModel = gSphere;
+ body->boundingVolume = aabb;
+ body->physicalParameters = physics;
+}
+
Added: trunk/pkg/common/Engine/StandAloneEngine/SpheresFactory.hpp
===================================================================
--- trunk/pkg/common/Engine/StandAloneEngine/SpheresFactory.hpp 2009-01-21 10:33:46 UTC (rev 1631)
+++ trunk/pkg/common/Engine/StandAloneEngine/SpheresFactory.hpp 2009-01-23 09:05:03 UTC (rev 1632)
@@ -0,0 +1,43 @@
+/*************************************************************************
+* Copyright (C) 2009 by Sergei Dorofeenko *
+* sega@xxxxxxxxxxxxxxxx *
+* *
+* 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. *
+*************************************************************************/
+#ifndef ___SPHERESFACTORYENGINE___
+#define ___SPHERESFACTORYENGINE___
+
+#include <yade/core/StandAloneEngine.hpp>
+#include <yade/core/BroadInteractor.hpp>
+#include <yade/core/MetaBody.hpp>
+#include <vector>
+#include <string>
+
+using namespace std;
+
+class SpheresFactory : public StandAloneEngine {
+public:
+
+ SpheresFactory();
+ virtual ~SpheresFactory();
+
+ virtual void action(MetaBody*);
+
+ vector<body_id_t> factoryFacets;
+ string labelBroadInteractor;
+
+protected:
+ BroadInteractor* bI;
+ bool first_run;
+
+ void createSphere(shared_ptr<Body>& body, const Vector3r& position, Real radius);
+
+ REGISTER_ATTRIBUTES(StandAloneEngine,(factoryFacets)(labelBroadInteractor))
+ REGISTER_CLASS_AND_BASE(SpheresFactory, StandAloneEngine);
+
+};
+REGISTER_SERIALIZABLE(SpheresFactory);
+
+#endif //___SPHERESFACTORYENGINE___
+
Modified: trunk/pkg/common/SConscript
===================================================================
--- trunk/pkg/common/SConscript 2009-01-21 10:33:46 UTC (rev 1631)
+++ trunk/pkg/common/SConscript 2009-01-23 09:05:03 UTC (rev 1632)
@@ -152,6 +152,8 @@
# LIBS=env['LIBS']+['yade-base', 'TesselationWrapper', 'CGAL', 'InteractingSphere', 'RigidBodyParameters'],
# CPPPATH=env['CPPPATH']+['Engine/StandAloneEngine', '$PREFIX/include', '/home/bruno/micromacro/KdevMicroMacro/src']),
+ env.SharedLibrary('SpheresFactory',['Engine/StandAloneEngine/SpheresFactory.cpp'],
+ LIBS=env['LIBS']+['AABB','InteractingSphere','InteractingFacet','Sphere','BodyMacroParameters','PersistentSAPCollider']),
env.SharedLibrary('SpatialQuickSortCollider',['Engine/StandAloneEngine/SpatialQuickSortCollider.cpp']),
env.SharedLibrary('PersistentSAPCollider',['Engine/StandAloneEngine/PersistentSAPCollider.cpp']),
env.SharedLibrary('DistantPersistentSAPCollider',['Engine/StandAloneEngine/DistantPersistentSAPCollider.cpp']),
Modified: trunk/scripts/test-sphere-facet.py
===================================================================
--- trunk/scripts/test-sphere-facet.py 2009-01-21 10:33:46 UTC (rev 1631)
+++ trunk/scripts/test-sphere-facet.py 2009-01-23 09:05:03 UTC (rev 1632)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
# © Václav Šmilauer <eudoxos@xxxxxxxx>
#
# Test case for sphere-facet interaction preserving the original contact orientation.