Commit fdab27a6 by Sebastian Eibl

`static calcMass and calcInertia functions are now available for all geometries`
parent 7d572372
 ... ... @@ -1693,6 +1693,25 @@ inline const Matrix3 fabs( const Matrix3& m ) //********************************************************************************************************************** //********************************************************************************************************************** /*!\fn bool math::isinf( const Matrix3& m ) // \brief Checks the given matrix for infinite elements. // // \param m The matrix to be checked for infinite elements. // \return \a true if at least one element of the matrix is infinite, \a false otherwise. */ template< typename Type > inline bool isinf( const Matrix3& m ) { if( math::isinf( m[0] ) || math::isinf( m[1] ) || math::isinf( m[2] ) || math::isinf( m[3] ) || math::isinf( m[4] ) || math::isinf( m[5] ) || math::isinf( m[6] ) || math::isinf( m[7] ) || math::isinf( m[8] ) ) return true; else return false; } //********************************************************************************************************************** //********************************************************************************************************************** // \brief Calculates the tensor product of two vectors. //********************************************************************************************************************** ... ...
 ... ... @@ -90,14 +90,15 @@ void ConvexPolyhedron::init( const Vec3& gpos, const Vec3& rpos, const Quat& q, q_ = q; // Setting the orientation R_ = q_.toRotationMatrix(); // Setting the rotation matrix // Calculating the ConvexPolyhedron mass mass_ = getVolume() * Material::getDensity( getMaterial() ); // Calculating the moment of inertia calcInertia(); setGlobal( global ); setMass( infiniteMass ); // sets inverse mass and interatio tensor if (infiniteMass) { setMassAndInertiaToInfinity(); } else { // sets inverse mass and interatio tensor setMassAndInertia( getVolume() * Material::getDensity( getMaterial() ), mesh::computeIntertiaTensor( mesh_ ) ); } setCommunicating( communicating ); setFinite( true ); ... ... @@ -159,17 +160,6 @@ void ConvexPolyhedron::calcBoundingBox() } //************************************************************************************************* //************************************************************************************************* /*!\brief Calculation of the moment of inertia in reference to the body frame of the ConvexPolyhedron. * * \return void */ void ConvexPolyhedron::calcInertia() { I_ = mesh::computeIntertiaTensor( mesh_ ); } //************************************************************************************************* //************************************************************************************************* /*!\brief Calculation of the volume of the ConvexPolyhedron. ... ...
 ... ... @@ -127,7 +127,6 @@ protected: /*!\name Utility functions */ //@{ virtual void calcBoundingBox(); // Calculation of the axis-aligned bounding box void calcInertia(); // Calculation of the moment of inertia virtual TriangleMesh::VertexHandle supportVertex( const TriangleMesh::Normal & d, const TriangleMesh::VertexHandle startVertex ) const; //@} //********************************************************************************************** ... ...
 ... ... @@ -288,7 +288,7 @@ inline void HardContactSemiImplicitTimesteppingSolvers::timestep( const real_t d for( auto body = globalBodyStorage_->begin(); body != globalBodyStorage_->end(); ++body, ++j ) { body->wake(); // BUGFIX: Force awaking of all bodies! body->index_ = j; WALBERLA_ASSERT( body->hasInfiniteMass(), "fatal" ); WALBERLA_CHECK( body->hasInfiniteMass(), "Global bodies need to have infinite mass as they are not communicated!" ); initializeVelocityCorrections( *body, bodyCache.dv_[j], bodyCache.dw_[j], dt ); // use applied external forces to calculate starting velocity ... ... @@ -347,7 +347,7 @@ inline void HardContactSemiImplicitTimesteppingSolvers::timestep( const real_t d for( auto body = globalBodyStorage_->begin(); body != globalBodyStorage_->end(); ++body, ++j ) { body->wake(); // BUGFIX: Force awaking of all bodies! body->index_ = j; WALBERLA_ASSERT( body->hasInfiniteMass(), "fatal" ); WALBERLA_CHECK( body->hasInfiniteMass(), "Global bodies need to have infinite mass as they are not communicated!" ); initializeVelocityCorrections( *body, bodyCache.dv_[j], bodyCache.dw_[j], dt ); // use applied external forces to calculate starting velocity ... ...
 ... ... @@ -75,15 +75,15 @@ Box::Box( id_t sid, id_t uid, const Vec3& gpos, const Vec3& rpos, const Quat& q, q_ = q; // Setting the orientation R_ = q_.toRotationMatrix(); // Setting the rotation matrix // Calculating the sphere mass mass_ = calcMass( lengths, Material::getDensity( material ) ); invMass_ = real_c(1) / mass_; // Calculating the moment of inertia calcInertia(); setGlobal( global ); setMass( infiniteMass ); if (infiniteMass) { setMassAndInertiaToInfinity(); } else { auto mass = calcMass( lengths, Material::getDensity( material ) ); setMassAndInertia( mass, calcInertia( lengths, mass ) ); } setCommunicating( communicating ); setFinite( true ); ... ... @@ -130,8 +130,8 @@ Box::~Box() bool Box::containsRelPointImpl( real_t px, real_t py, real_t pz ) const { return std::fabs(px) <= real_t(0.5)*lengths_[0] && std::fabs(py) <= real_t(0.5)*lengths_[1] && std::fabs(pz) <= real_t(0.5)*lengths_[2]; std::fabs(py) <= real_t(0.5)*lengths_[1] && std::fabs(pz) <= real_t(0.5)*lengths_[2]; } //************************************************************************************************* ... ... @@ -307,7 +307,7 @@ void Box::calcBoundingBox() const real_t ylength( real_t(0.5) * ( fabs(R_[3]*lengths_[0]) + fabs(R_[4]*lengths_[1]) + fabs(R_[5]*lengths_[2]) ) + contactThreshold ); const real_t zlength( real_t(0.5) * ( fabs(R_[6]*lengths_[0]) + fabs(R_[7]*lengths_[1]) + fabs(R_[8]*lengths_[2]) ) + contactThreshold ); aabb_ = math::AABB( gpos_[0] - xlength, gpos_[0] - xlength, gpos_[1] - ylength, gpos_[2] - zlength, gpos_[0] + xlength, ... ... @@ -326,12 +326,12 @@ void Box::calcBoundingBox() * * \return void */ void Box::calcInertia() Mat3 Box::calcInertia(const Vec3& length, const real_t mass) { I_[0] = mass_/static_cast( 12 ) * ( lengths_[1]*lengths_[1] + lengths_[2]*lengths_[2] ); I_[4] = mass_/static_cast( 12 ) * ( lengths_[0]*lengths_[0] + lengths_[2]*lengths_[2] ); I_[8] = mass_/static_cast( 12 ) * ( lengths_[0]*lengths_[0] + lengths_[1]*lengths_[1] ); Iinv_ = I_.getInverse(); return Mat3::makeDiagonalMatrix( mass/static_cast( 12 ) * ( length[1]*length[1] + length[2]*length[2] ), mass/static_cast( 12 ) * ( length[0]*length[0] + length[2]*length[2] ), mass/static_cast( 12 ) * ( length[0]*length[0] + length[1]*length[1] )); } //************************************************************************************************* ... ...
 ... ... @@ -96,6 +96,7 @@ public: static inline real_t calcMass( const Vec3& l, real_t density ); static inline real_t calcDensity( real_t x, real_t y, real_t z, real_t mass ); static inline real_t calcDensity( const Vec3& l, real_t mass ); static inline Mat3 calcInertia( const Vec3& length, const real_t mass); // Calculation of the moment of inertia //@} //********************************************************************************************** ... ... @@ -143,7 +144,6 @@ protected: /*!\name Utility functions */ //@{ virtual void calcBoundingBox(); // Calculation of the axis-aligned bounding box void calcInertia(); // Calculation of the moment of inertia //@} //********************************************************************************************** ... ...