State.hpp 6.07 KB
Newer Older
1 2
// 2009 © Václav Šmilauer <eudoxos@arcig.cz>
#pragma once
3 4 5
#include<lib/serialization/Serializable.hpp>
#include<lib/multimethods/Indexable.hpp>
#include<core/Dispatcher.hpp>
6

7 8
namespace yade { // Cannot have #include directive inside.

9
class State: public Serializable, public Indexable{
10
	public:
11
		/// linear motion (references to inside se3)
12
		Vector3r& pos;
13
		/// rotational motion (reference to inside se3)
14
		Quaternionr& ori;
15 16 17 18

		//! mutex for updating the parameters from within the interaction loop (only used rarely)
		boost::mutex updateMutex;
		
19
		// bits for blockedDOFs
20 21 22 23 24 25 26 27 28 29 30
		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)
31
		void setDOFfromVector3r(Vector3r disp,Vector3r rot=Vector3r::Zero());
32 33 34
		//! Getter of blockedDOFs for list of strings (e.g. DOF_X | DOR_RX | DOF_RZ → 'xXZ')
		std::string blockedDOFs_vec_get() const;
		//! Setter of blockedDOFs from string ('xXZ' → DOF_X | DOR_RX | DOF_RZ)
Anton Gladky's avatar
Anton Gladky committed
35
		void blockedDOFs_vec_set(const std::string& dofs);
36

37
		//! Return displacement (current-reference position)
38
		const Vector3r displ() const {return pos-refPos;}
39
		//! Return rotation (current-reference orientation, as Vector3r)
40
		const Vector3r rot() const { Quaternionr relRot=refOri.conjugate()*ori; AngleAxisr aa(relRot); return aa.axis()*aa.angle(); }
41 42

		// python access functions: pos and ori are references to inside Se3r and cannot be pointed to directly
43
		const Vector3r pos_get() const {return pos;}
44
		void pos_set(const Vector3r p) {pos=p;}
45
		const Quaternionr ori_get() const {return ori; }
46
		void ori_set(const Quaternionr o){ori=o;}
47

48
	YADE_CLASS_BASE_DOC_ATTRS_INIT_CTOR_PY(State,Serializable,"State of a body (spatial configuration, internal variables).",
49 50 51 52 53 54 55 56
		((Se3r,se3,Se3r(Vector3r::Zero(),Quaternionr::Identity()),,"Position and orientation as one object."))
		((Vector3r,vel,Vector3r::Zero(),,"Current linear velocity."))
		((Real,mass,0,,"Mass of this body"))
		((Vector3r,angVel,Vector3r::Zero(),,"Current angular velocity"))
		((Vector3r,angMom,Vector3r::Zero(),,"Current angular momentum"))
		((Vector3r,inertia,Vector3r::Zero(),,"Inertia of associated body, in local coordinate system."))
		((Vector3r,refPos,Vector3r::Zero(),,"Reference position"))
		((Quaternionr,refOri,Quaternionr::Identity(),,"Reference orientation"))
57
		((unsigned,blockedDOFs,,,"[Will be overridden]"))
Jérôme Duriez's avatar
Jérôme Duriez committed
58
		((bool,isDamped,true,,"Damping in :yref:`NewtonIntegrator` can be deactivated for individual particles by setting this variable to FALSE. E.g. damping is inappropriate for particles in free flight under gravity but it might still be applicable to other particles in the same simulation."))
59
		((Real,densityScaling,-1,,"|yupdate| see :yref:`GlobalStiffnessTimeStepper::targetDt`."))
60 61 62 63
#ifdef YADE_SPH
		((Real,rho, -1.0,, "Current density (only for SPH-model)"))      // [Mueller2003], (12)
		((Real,rho0,-1.0,, "Rest density (only for SPH-model)"))         // [Mueller2003], (12)
		((Real,press,0.0,, "Pressure (only for SPH-model)"))             // [Mueller2003], (12)
64 65 66 67
#endif
#ifdef YADE_LIQMIGRATION
		((Real,Vf, 0.0,,   "Individual amount of liquid"))
		((Real,Vmin, 0.0,, "Minimal amount of liquid"))
68 69 70
#endif
#ifdef YADE_DEFORM
		((Real,dR, 0.0,,   "Sphere deformation"))
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#endif
#ifdef THERMAL
		((Real,temp,0,,"temperature of the body"))
		((bool,oldTempSet,false,,"flag to determine which integration method to use"))
		((Real,tempHold,0,,"holds temperature for 2nd order difference"))
		((Real,oldTemp,0,,"change of temp (for thermal expansion)"))
		((Real,stepFlux,0,,"flux during current step"))
		((Real,capVol,0,,"total overlapping volume"))
		((Real,U,0,,"internal energy of the body"))
		((Real,Cp,0,,"internal energy of the body"))
		((Real,k,0,,"thermal conductivity of the body"))
		((Real,alpha,0,,"coefficient of thermal expansion"))
		((bool,Tcondition,false,,"indicates if particle is assigned dirichlet (constant temp) condition"))
		((int,boundaryId,-1,,"identifies if a particle is associated with constant temperature thrermal boundary condition"))
        	((Real,stabilityCoefficient,0,,"sum of solid and fluid thermal resistivities for use in automatic timestep estimation"))
        	((Real,delRadius,0,,"radius change due to thermal expansion"))
87
		((bool,isCavity,true,,"flag used for unbounding cavity bodies"))
88 89
#endif
		,
90 91 92 93 94
		/* additional initializers */
			((pos,se3.position))
			((ori,se3.orientation)),
		/* ctor */,
		/*py*/
95
		YADE_PY_TOPINDEXABLE(State)
96
		.add_property("blockedDOFs",&State::blockedDOFs_vec_get,&State::blockedDOFs_vec_set,"Degress of freedom where linear/angular velocity will be always constant (equal to zero, or to an user-defined value), regardless of applied force/torque. String that may contain 'xyzXYZ' (translations and rotations).")
97
		// references must be set using wrapper funcs
98
		.add_property("pos",&State::pos_get,&State::pos_set,"Current position.")
99
		.add_property("ori",&State::ori_get,&State::ori_set,"Current orientation.")
100
		.def("displ",&State::displ,"Displacement from :yref:`reference position<State.refPos>` (:yref:`pos<State.pos>` - :yref:`refPos<State.refPos>`)")
101
		.def("rot",&State::rot,"Rotation from :yref:`reference orientation<State.refOri>` (as rotation vector)")
102 103 104 105 106
#ifdef YADE_SPH
		.add_property("rho",  &State::rho, "Returns the current density (only for SPH-model).")
		.add_property("rho0", &State::rho0,"Returns the rest density (only for SPH-model).")
		.add_property("press",&State::press,"Returns the pressure (only for SPH-model).")
#endif
107
	);
108
	REGISTER_INDEX_COUNTER(State);
109
	DECLARE_LOGGER;
110 111
};
REGISTER_SERIALIZABLE(State);
112 113 114

} // namespace yade