yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #02266
[Branch ~yade-dev/yade/trunk] Rev 1799: Initial commit of new Material and State classes that will replace PhysicalParameters in the futu...
------------------------------------------------------------
revno: 1799
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Fri 2009-11-20 10:08:07 +0100
message:
Initial commit of new Material and State classes that will replace PhysicalParameters in the future. No changes in functionality.
added:
core/Material.hpp
core/State.cpp
core/State.hpp
modified:
SConstruct
core/Body.hpp
core/SConscript
--
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 'SConstruct'
--- SConstruct 2009-11-20 08:25:37 +0000
+++ SConstruct 2009-11-20 09:08:07 +0000
@@ -138,7 +138,7 @@
ListVariable('exclude','Yade components that will not be built','none',names=['qt3','gui','extra','common','dem','lattice','snow']),
EnumVariable('PGO','Whether to "gen"erate or "use" Profile-Guided Optimization','',['','gen','use'],{'no':'','0':'','false':''},1),
# OK, dummy prevents bug in scons: if one selects all, it says all in scons.config, but without quotes, which generates error.
- ListVariable('features','Optional features that are turned on','python,log4cxx,opengl,gts,openmp',names=['opengl','python','log4cxx','cgal','openmp','gts','vtk','shape']),
+ ListVariable('features','Optional features that are turned on','python,log4cxx,opengl,gts,openmp',names=['opengl','python','log4cxx','cgal','openmp','gts','vtk','shape','nomaterial']),
('jobs','Number of jobs to run at the same time (same as -j, but saved)',4,None,int),
#('extraModules', 'Extra directories with their own SConscript files (must be in-tree) (whitespace separated)',None,None,Split),
('buildPrefix','Where to create build-[version][variant] directory for intermediary files','..'),
=== modified file 'core/Body.hpp'
--- core/Body.hpp 2009-11-17 08:55:09 +0000
+++ core/Body.hpp 2009-11-20 09:08:07 +0000
@@ -14,6 +14,9 @@
#include"InteractingGeometry.hpp"
#include"BoundingVolume.hpp"
#include"PhysicalParameters.hpp"
+#include"State.hpp"
+#include"Material.hpp"
+
#include"InteractionContainer.hpp"
#include"Interaction.hpp"
@@ -68,8 +71,15 @@
// only BodyContainer can set the id of a body
friend class BodyContainer;
- /// here are stored physical things that describe the Body: mass, stiffness
- shared_ptr<PhysicalParameters> physicalParameters;
+ #ifdef YADE_NOMATERIAL
+ /// here are stored physical things that describe the Body: mass, stiffness
+ shared_ptr<PhysicalParameters> physicalParameters;
+ #else
+ //! material of the body; might be shared among bodies (via shared_ptr)
+ shared_ptr<Material> material;
+ //! state of the body
+ shared_ptr<State> state;
+ #endif
#ifdef YADE_SHAPE
/// the 'perfect' representation of body's geometry: Polyhedron, Box
shared_ptr<GeometricalModel> geometricalModel;
@@ -94,7 +104,12 @@
(id)
(groupMask)
(isDynamic)
- (physicalParameters)
+ #ifdef YADE_NOMATERIAL
+ (physicalParameters)
+ #else
+ (material)
+ (state)
+ #endif
#ifdef YADE_SHAPE
(geometricalModel)
#endif
=== added file 'core/Material.hpp'
--- core/Material.hpp 1970-01-01 00:00:00 +0000
+++ core/Material.hpp 2009-11-20 09:08:07 +0000
@@ -0,0 +1,17 @@
+// 2009 © Václav Šmilauer <eudoxos@xxxxxxxx>
+#pragma once
+
+/*! Material properties associated with a body.
+
+Historical note: this used to be part of the PhysicalParameters class.
+The other data are now in the State class.
+*/
+class Material: public Serializable, public Indexable{
+ public:
+ //! textual name of material; if shared, can be looked up by that name
+ string label;
+ REGISTER_CLASS_AND_BASE(Material,Serializable);
+ REGISTER_ATTRIBUTES(Serializable,(label));
+ REGISTER_INDEX_COUNTER(Material);
+};
+REGISTER_SERIALIZABLE(Material);
=== modified file 'core/SConscript'
--- core/SConscript 2009-11-18 14:06:42 +0000
+++ core/SConscript 2009-11-20 09:08:07 +0000
@@ -20,6 +20,7 @@
'PhysicalParameters.cpp',
'Preferences.cpp',
'SimulationFlow.cpp',
+ 'State.cpp',
'ThreadRunner.cpp',
'ThreadWorker.cpp',
'TimeStepper.cpp',
=== added file 'core/State.cpp'
--- core/State.cpp 1970-01-01 00:00:00 +0000
+++ core/State.cpp 2009-11-20 09:08:07 +0000
@@ -0,0 +1,29 @@
+// 2009 © Václav Šmilauer <eudoxos@xxxxxxxx>
+#include<yade/core/State.hpp>
+#include<boost/foreach.hpp>
+#include<stdexcept>
+#ifndef FOREACH
+ #define FOREACH BOOST_FOREACH
+#endif
+
+void State::setDOFfromVector3r(Vector3r disp,Vector3r rot){
+ blockedDOFs=((disp[0]==1.0)?DOF_X :0)|((disp[1]==1.0)?DOF_Y :0)|((disp[2]==1.0)?DOF_Z :0)|
+ ((rot [0]==1.0)?DOF_RX:0)|((rot [1]==1.0)?DOF_RY:0)|((rot [2]==1.0)?DOF_RZ:0);
+}
+
+std::vector<std::string> State::blockedDOFs_vec_get() const {
+ std::vector<std::string> ret;
+ #define _SET_DOF(DOF_ANY,str) if((blockedDOFs & PhysicalParameters::DOF_ANY)!=0) ret.push_back(str);
+ _SET_DOF(DOF_X,"x"); _SET_DOF(DOF_Y,"y"); _SET_DOF(DOF_Z,"z"); _SET_DOF(DOF_RX,"rx"); _SET_DOF(DOF_RY,"ry"); _SET_DOF(DOF_RZ,"rz");
+ #undef _SET_DOF
+ return ret;
+}
+void State::blockedDOFs_vec_set(const std::vector<std::string>& dofs){
+ FOREACH(const std::string s, dofs){
+ #define _GET_DOF(DOF_ANY,str) if(s==str) { blockedDOFs|=PhysicalParameters::DOF_ANY; continue; }
+ _GET_DOF(DOF_X,"x"); _GET_DOF(DOF_Y,"y"); _GET_DOF(DOF_Z,"z"); _GET_DOF(DOF_RX,"rx"); _GET_DOF(DOF_RY,"ry"); _GET_DOF(DOF_RZ,"rz");
+ #undef _GET_DOF
+ throw std::invalid_argument("Invalid DOF specification `"+s+"', must be â{x,y,z,rx,ry,rz}.");
+ }
+}
+
=== added file 'core/State.hpp'
--- core/State.hpp 1970-01-01 00:00:00 +0000
+++ core/State.hpp 2009-11-20 09:08:07 +0000
@@ -0,0 +1,57 @@
+// 2009 © Václav Šmilauer <eudoxos@xxxxxxxx>
+#pragma once
+/*! State (internal & spatial variables) of a body.
+
+For now, I put position, orientation, velocity and angular velocity here,
+since (AFAIK) we have no bodies that lack them. If in the future
+someone needs bodies without orientation, then orientation and angular
+velocity can be pushed to a derived class (and the rest of code adapted
+to that).
+
+All state variables are initialized to zeros.
+
+Historical note: this used to be part of the PhysicalParameters class.
+The other data are now in the Material class.
+*/
+
+class State: public Serializable{
+ public:
+ //! Spatial position and orientation
+ Se3r se3;
+ //! Reference position and orientation
+ Se3r refSe3;
+ //! linear velocity
+ Vector3r velocity;
+ //! angular velocity
+ Vector3r angularVelocity;
+
+ //! mutex for updating the parameters from within the interaction loop (only used rarely)
+ boost::mutex updateMutex;
+
+
+ //! Bitmask for degrees of freedom where velocity will be always zero, regardless of applied forces
+ unsigned blockedDOFs;
+ // bits
+ enum {DOF_NONE=0,DOF_X=1,DOF_Y=2,DOF_Z=4,DOF_RX=8,DOF_RY=16,DOF_RZ=32};
+ //! shorthand for all DOFs blocked
+ static const unsigned DOF_ALL=DOF_X|DOF_Y|DOF_Z|DOF_RX|DOF_RY|DOF_RZ;
+ //! shorthand for all displacements blocked
+ static const unsigned DOF_XYZ=DOF_X|DOF_Y|DOF_Z;
+ //! shorthand for all rotations blocked
+ static const unsigned DOF_RXRYRZ=DOF_RX|DOF_RY|DOF_RZ;
+
+ //! Return DOF_* constant for given axisâ{0,1,2} and rotationalDOFâ{false(default),true}; e.g. axisDOF(0,true)==DOF_RX
+ static unsigned axisDOF(int axis, bool rotationalDOF=false){return 1<<(axis+(rotationalDOF?3:0));}
+ //! set DOFs according to two Vector3r arguments (blocked is when disp[i]==1.0 or rot[i]==1.0)
+ void setDOFfromVector3r(Vector3r disp,Vector3r rot=Vector3r::ZERO);
+ //! Getter of blockedDOFs for list of strings (e.g. DOF_X | DOR_RX | DOF_RZ â ['x','rx','rz'])
+ std::vector<std::string> blockedDOFs_vec_get() const;
+ //! Setter of blockedDOFs from list of strings (['x','rx','rz'] â DOF_X | DOR_RX | DOF_RZ)
+ void blockedDOFs_vec_set(const std::vector<std::string>& dofs);
+
+ State(): se3(Vector3r::ZERO,Quaternionr::IDENTITY), velocity(Vector3r::ZERO), angularVelocity(Vector3r::ZERO){}
+
+ REGISTER_CLASS_AND_BASE(State,Serializable);
+ REGISTER_ATTRIBUTES(Serializable,(se3)(refSe3)(blockedDOFs)(velocity)(angularVelocity));
+};
+REGISTER_SERIALIZABLE(State);