FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
CBall.h
1
2#ifndef CBALL_H
3#define CBALL_H
4
96// Includes
97#include "sfh/timers/Timer.h"
98
99#include <Eigen/Core>
100#include <Eigen/Geometry>
101
102#include <fhsim/simobject/SimObject.h>
103#include <ostream>
104#include <string>
105#include <vector>
106
107class CBall : public SimObject
108{
109 public:
121 CBall(std::string simObjectName, ISimObjectCreator* creator);
122
123 ~CBall();
124
125#ifdef FH_VISUALIZATION
126
128 virtual void RenderInit(Ogre::Root* const OgreRoot, ISimObjectCreator* const creator);
129
131 virtual void RenderUpdate(const double T, const double* const X);
132#endif
133
145 void OdeFcn(const double T, const double* const X, double* const XDot) const;
146
147 bool HasJacobians() const override;
148 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
149 int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) override;
150
160 const double* ForceOut(const double T, const double* const X);
161
162 protected:
172 void CalcForces(const double T, const double* const X) const;
173
182 void ForceInterBall(const double T, const double* const X) const;
183
192 void AddWallStiffness(const double T, const double* const X, Eigen::MatrixXd& forceJacobian) const;
193
201 void AddInterBallStiffness(const double* const X, Eigen::MatrixXd& forceJacobian) const;
202
210 void BoxPlanes(const double T, const double* const X, Eigen::Vector3d norms[6],
211 Eigen::Vector3d planePositions[6]) const;
212
214 void LatchPlaneSide(int pl, double s) const;
215
221 bool IsWallContact(int pl, double s, double dL, double radius) const;
222
230 virtual const double* Position(const double T, const double* const X);
231
239 virtual const double* Velocity(const double T, const double* const X);
240
241 // Member variables
242 int m_count;
243 double m_gravity;
244 double* m_mass;
245 double* m_radius;
246 double* m_stiffness;
247 double m_boxDim[3];
248 Eigen::Vector3d m_norms[6];
249 mutable int m_planeSide[6];
250 mutable Eigen::VectorXd m_forces;
251 mutable Eigen::VectorXd m_interForces;
252
253 ISignalPort* m_inBoxPos;
254 ISignalPort* m_inBoxRot;
257
265 int LocalIndex(int globalStateIndex) const { return globalStateIndex - m_iStatePos; }
266
267 mutable double m_outForce[3];
268
269
270#ifdef FH_VISUALIZATION
271 std::string m_material;
272 std::string m_meshName;
273 double m_scale;
274 Ogre::SceneManager* m_sceneMgr;
275 std::vector<Ogre::SceneNode*> m_renderNodes;
276 std::vector<Ogre::Entity*> m_renderEntities;
277#endif
278};
279
280#endif
Definition CBall.h:108
void LatchPlaneSide(int pl, double s) const
Fixes m_planeSide[pl] from the signed distance s to the wall at the first evaluation.
Eigen::VectorXd m_interForces
3-DOF force acting on each ball i (col(F_i)) from the box. [N]
Definition CBall.h:251
void CalcForces(const double T, const double *const X) const
Calculates contact forces between balls and box.
void OdeFcn(const double T, const double *const X, double *const XDot) const
Cleans up dynamically allocated memory.
virtual const double * Velocity(const double T, const double *const X)
Returns the position of the balls.
void ForceInterBall(const double T, const double *const X) const
Calculates contact forces between the balls.
const double * ForceOut(const double T, const double *const X)
Returns the force acting from the balls on the box.
CBall(std::string simObjectName, ISimObjectCreator *creator)
Reads parameters, registers states, input/output ports and shared resources.
void BoxPlanes(const double T, const double *const X, Eigen::Vector3d norms[6], Eigen::Vector3d planePositions[6]) const
int m_iStatePos
Orientation of the box, Euler angles, x,y,z [rad].
Definition CBall.h:255
Eigen::VectorXd m_forces
Side of the plane, relative normal std::vector (-1: inside, 1: outside, else: undef)
Definition CBall.h:250
void AddWallStiffness(const double T, const double *const X, Eigen::MatrixXd &forceJacobian) const
ISignalPort * m_inBoxPos
3-DOF force acting between each ball i (col(F_i)). [N]
Definition CBall.h:253
double * m_radius
The masses of the balls. [kg].
Definition CBall.h:245
double m_gravity
Number of balls [#].
Definition CBall.h:243
bool IsWallContact(int pl, double s, double dL, double radius) const
Eigen::Vector3d m_norms[6]
The dimensions of the box Lx, Ly, Lz [m].
Definition CBall.h:248
int LocalIndex(int globalStateIndex) const
The index of the velocity state.
Definition CBall.h:265
double * m_mass
The gravity (assumed along z-axis) [kgms^-2].
Definition CBall.h:244
double m_boxDim[3]
The linear stiffnesses of the ball. [N/m].
Definition CBall.h:247
int m_planeSide[6]
Array of box unit normal vectors [-].
Definition CBall.h:249
double * m_stiffness
The radii of the balls. [m].
Definition CBall.h:246
void AddInterBallStiffness(const double *const X, Eigen::MatrixXd &forceJacobian) const
int m_iStateVel
The index of the position state.
Definition CBall.h:256
ISignalPort * m_inBoxRot
Centroid of the box [m].
Definition CBall.h:254
virtual const double * Position(const double T, const double *const X)
Returns the velocity of the balls.