Commit e0729b4a authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

initial Polyhedron class

parent af1f65c2
......@@ -78,6 +78,7 @@ class Material;
class MPISystem;
class Node;
class Plane;
class Polyhedron;
class Process;
class RigidBody;
class Section;
......@@ -120,6 +121,10 @@ typedef Plane PlaneType; //!< Type of the plane geomet
typedef Plane* PlaneID; //!< Handle for a plane primitive.
typedef const Plane* ConstPlaneID; //!< Handle for a constant plane primitive.
typedef Polyhedron PolyhedronType; //!< Type of the polyhedron geometric primitive.
typedef Polyhedron* PolyhedronID; //!< Handle for a polyhedron primitive.
typedef const Polyhedron* ConstPolyhedronID; //!< Handle for a constant polyhedron primitive.
typedef Sphere SphereType; //!< Type of the sphere geometric primitive.
typedef Sphere* SphereID; //!< Handle for a sphere primitive.
typedef const Sphere* ConstSphereID; //!< Handle for a constant sphere primitive.
......
//======================================================================================================================
//
// This file is part of waLBerla. waLBerla is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// waLBerla is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file Polyhedron.cpp
//! \author Sebastian Eibl <sebastian.eibl@fau.de>
//! \brief Marshalling of objects for data transmission or storage.
//
//======================================================================================================================
#include "Polyhedron.h"
namespace walberla {
namespace pe {
namespace communication {
//*************************************************************************************************
/*!\brief Marshalling a polyhedron primitive.
*
* \param buffer The buffer to be filled.
* \param obj The object to be marshalled.
* \return void
*/
void marshal( mpi::SendBuffer& buffer, const Polyhedron& obj ) {
marshal( buffer, static_cast<const GeomPrimitive&>( obj ) );
//buffer << obj.getRadius();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Unmarshalling a polyhedron primitive.
*
* \param buffer The buffer from where to read.
* \param objparam The object to be reconstructed.
* \param hasSuperBody False if body is not part of a union. Passed on to rigid body unmarshalling.
* \return void
*/
void unmarshal( mpi::RecvBuffer& buffer, PolyhedronParameters& objparam ) {
unmarshal( buffer, static_cast<GeomPrimitiveParameters&>( objparam ) );
//buffer >> objparam.radius_;
}
//*************************************************************************************************
} // namespace communication
} // namespace pe
} // namespace walberla
//======================================================================================================================
//
// This file is part of waLBerla. waLBerla is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// waLBerla is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file Polyhedron.h
//! \author Sebastian Eibl <sebastian.eibl@fau.de>
//! \brief Marshalling of objects for data transmission or storage.
//
//======================================================================================================================
#pragma once
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include "pe/communication/Instantiate.h"
#include "pe/communication/Marshalling.h"
#include "pe/rigidbody/Polyhedron.h"
namespace walberla {
namespace pe {
namespace communication {
struct PolyhedronParameters : public GeomPrimitiveParameters {
};
//*************************************************************************************************
/*!\brief Marshalling a polyhedron primitive.
*
* \param buffer The buffer to be filled.
* \param obj The object to be marshalled.
* \return void
*/
void marshal( mpi::SendBuffer& buffer, const Polyhedron& obj );
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Unmarshalling a polyhedron primitive.
*
* \param buffer The buffer from where to read.
* \param objparam The object to be reconstructed.
* \param hasSuperBody False if body is not part of a union. Passed on to rigid body unmarshalling.
* \return void
*/
void unmarshal( mpi::RecvBuffer& buffer, PolyhedronParameters& objparam );
//*************************************************************************************************
inline PolyhedronID instantiate( mpi::RecvBuffer& buffer, const math::AABB& domain, const math::AABB& block, PolyhedronID& newBody )
{
PolyhedronParameters subobjparam;
unmarshal( buffer, subobjparam );
correctBodyPosition(domain, block.center(), subobjparam.gpos_);
newBody = new Polyhedron( subobjparam.sid_, subobjparam.uid_, subobjparam.gpos_, subobjparam.rpos_, subobjparam.q_, real_c(5), subobjparam.material_, false, subobjparam.communicating_, subobjparam.infiniteMass_ );
newBody->setLinearVel( subobjparam.v_ );
newBody->setAngularVel( subobjparam.w_ );
newBody->MPITrait.setOwner( subobjparam.mpiTrait_.owner_ );
return newBody;
}
} // namespace communication
} // namespace pe
} // namespace walberla
//======================================================================================================================
//
// This file is part of waLBerla. waLBerla is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// waLBerla is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file Polyhedron.cpp
//! \author Sebastian Eibl <sebastian.eibl@fau.de>
//
//======================================================================================================================
#include "Polyhedron.h"
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <iomanip>
#include <iostream>
#include <stdexcept>
#include <cmath>
#include <pe/Materials.h>
#include <core/math/Matrix3.h>
#include <core/debug/Debug.h>
namespace walberla {
namespace pe {
//=================================================================================================
//
// CONSTRUCTOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Constructor for the Polyhedron class.
*
* \param sid Unique system-specific ID for the Polyhedron.
* \param uid User-specific ID for the Polyhedron.
* \param gpos Global geometric center of the Polyhedron.
* \param rpos The relative position within the body frame of a superordinate body.
* \param q The orientation of the Polyhedron's body frame in the global world frame.
* \param radius The radius of the Polyhedron \f$ (0..\infty) \f$.
* \param material The material of the Polyhedron.
* \param global specifies if the Polyhedron should be created in the global storage
* \param communicating specifies if the Polyhedron should take part in synchronization (syncNextNeighbour, syncShadowOwner)
* \param infiniteMass specifies if the Polyhedron has infinite mass and will be treated as an obstacle
*/
Polyhedron::Polyhedron( id_t sid, id_t uid, const Vec3& gpos, const Vec3& rpos, const Quat& q,
real_t radius, MaterialID material,
const bool global, const bool communicating, const bool infiniteMass )
: GeomPrimitive( getStaticTypeID(), sid, uid, material ) // Initialization of the parent class
{
// Checking the radius
// Since the Polyhedron constructor is never directly called but only used in a small number
// of functions that already check the Polyhedron arguments, only asserts are used here to
// double check the arguments.
WALBERLA_ASSERT( radius > real_c(0), "Invalid Polyhedron radius" );
// Setting the center of the Polyhedron
gpos_ = gpos;
// Initializing the instantiated Polyhedron
rpos_ = rpos; // Setting the relative position
q_ = q; // Setting the orientation
R_ = q_.toRotationMatrix(); // Setting the rotation matrix
// Calculating the Polyhedron mass
mass_ = calcMass( radius, Material::getDensity( material ) );
invMass_ = real_c(1) / mass_;
// Calculating the moment of inertia
calcInertia();
setGlobal( global );
setMass( infiniteMass );
setCommunicating( communicating );
setFinite( true );
// Setting the axis-aligned bounding box
Polyhedron::calcBoundingBox();
}
//*************************************************************************************************
//=================================================================================================
//
// DESTRUCTOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Destructor for the Polyhedron class.
*/
Polyhedron::~Polyhedron()
{
// Logging the destruction of the Polyhedron
WALBERLA_LOG_DETAIL( "Destroyed Polyhedron " << sid_ );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Calculation of the bounding box of the Polyhedron.
*
* \return void
*
* This function updates the axis-aligned bounding box of the Polyhedron primitive according to the
* current position and orientation of the Polyhedron. Note that the bounding box is increased in
* all dimensions by pe::contactThreshold to guarantee that rigid bodies in close proximity of
* the Polyhedron are also considered during the collision detection process.
*/
void Polyhedron::calcBoundingBox()
{
WALBERLA_ABORT("calcBoundingBox not implemented!");
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Calculation of the moment of inertia in reference to the body frame of the Polyhedron.
*
* \return void
*/
void Polyhedron::calcInertia()
{
WALBERLA_ABORT("calcInertia not implemented!");
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Estimates the point which is farthest in direction \a d.
*
* \param d The normalized search direction in world-frame coordinates.
* \return The support point in world-frame coordinates in direction a\ d.
*/
Vec3 Polyhedron::support( const Vec3& d ) const
{
WALBERLA_ABORT("support not implemented!");
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Estimates the point which is farthest in direction \a d.
*
* \param d The normalized search direction in world-frame coordinates
* \return The support point in world-frame coordinates in direction a\ d extended by a vector in
* direction \a d of length \a pe::contactThreshold.
*/
Vec3 Polyhedron::supportContactThreshold( const Vec3& d ) const
{
WALBERLA_ABORT("supportContactThreshold not implemented!");
}
//*************************************************************************************************
//=================================================================================================
//
// UTILITY FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Checks, whether a point in body relative coordinates lies inside the Polyhedron.
*
* \param px The x-component of the relative coordinate.
* \param py The y-component of the relative coordinate.
* \param pz The z-component of the relative coordinate.
* \return \a true if the point lies inside the Polyhedron, \a false if not.
*/
bool Polyhedron::containsRelPointImpl( real_t px, real_t py, real_t pz ) const
{
WALBERLA_ABORT("containsRelPointImpl not implemented!");
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Checks, whether a point in body relative coordinates lies on the surface of the Polyhedron.
*
* \param px The x-component of the relative coordinate.
* \param py The y-component of the relative coordinate.
* \param pz The z-component of the relative coordinate.
* \return \a true if the point lies on the surface of the Polyhedron, \a false if not.
*
* The tolerance level of the check is pe::surfaceThreshold.
*/
bool Polyhedron::isSurfaceRelPointImpl( real_t px, real_t py, real_t pz ) const
{
WALBERLA_ABORT("isSurfaceRelPointImpl not implemented!");
}
//*************************************************************************************************
//=================================================================================================
//
// OUTPUT FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Output of the current state of a Polyhedron.
*
* \param os Reference to the output stream.
* \param tab Indentation in front of every line of the Polyhedron output.
* \return void
*/
void Polyhedron::print( std::ostream& os, const char* tab ) const
{
using std::setw;
os << tab << " Polyhedron " << uid_ << " with radius " << radius_ << "\n";
os << tab << " Fixed: " << isFixed() << " , sleeping: " << !isAwake() << "\n";
os << tab << " System ID = " << getSystemID() << "\n"
<< tab << " Total mass = " << getMass() << "\n"
<< tab << " Material = " << Material::getName( material_ ) << "\n"
<< tab << " Owner = " << MPITrait.getOwner() << "\n"
<< tab << " Global position = " << getPosition() << "\n"
<< tab << " Relative position = " << getRelPosition() << "\n"
<< tab << " Linear velocity = " << getLinearVel() << "\n"
<< tab << " Angular velocity = " << getAngularVel() << "\n";
// if( verboseMode )
// {
os << tab << " Bounding box = " << getAABB() << "\n"
<< tab << " Quaternion = " << getQuaternion() << "\n"
<< tab << " Rotation matrix = ( " << setw(9) << R_[0] << " , " << setw(9) << R_[1] << " , " << setw(9) << R_[2] << " )\n"
<< tab << " ( " << setw(9) << R_[3] << " , " << setw(9) << R_[4] << " , " << setw(9) << R_[5] << " )\n"
<< tab << " ( " << setw(9) << R_[6] << " , " << setw(9) << R_[7] << " , " << setw(9) << R_[8] << " )\n";
os << std::setiosflags(std::ios::right)
<< tab << " Moment of inertia = ( " << setw(9) << I_[0] << " , " << setw(9) << I_[1] << " , " << setw(9) << I_[2] << " )\n"
<< tab << " ( " << setw(9) << I_[3] << " , " << setw(9) << I_[4] << " , " << setw(9) << I_[5] << " )\n"
<< tab << " ( " << setw(9) << I_[6] << " , " << setw(9) << I_[7] << " , " << setw(9) << I_[8] << " )\n"
<< std::resetiosflags(std::ios::right);
// }
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Global output operator for Polyhedrons.
*
* \param os Reference to the output stream.
* \param s Reference to a constant Polyhedron object.
* \return Reference to the output stream.
*/
std::ostream& operator<<( std::ostream& os, const Polyhedron& s )
{
os << "--" << "Polyhedron PARAMETERS"
<< "-------------------------------------------------------------\n";
s.print( os, "" );
os << "--------------------------------------------------------------------------------\n"
<< std::endl;
return os;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Global output operator for Polyhedron handles.
*
* \param os Reference to the output stream.
* \param s Constant Polyhedron handle.
* \return Reference to the output stream.
*/
std::ostream& operator<<( std::ostream& os, ConstPolyhedronID s )
{
os << "--" << "Polyhedron PARAMETERS"
<< "-------------------------------------------------------------\n";
s->print( os, "" );
os << "--------------------------------------------------------------------------------\n"
<< std::endl;
return os;
}
//*************************************************************************************************
id_t Polyhedron::staticTypeID_ = std::numeric_limits<id_t>::max();
} // namespace pe
} // namespace walberla
//======================================================================================================================
//
// This file is part of waLBerla. waLBerla is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// waLBerla is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file Polyhedron.h
//! \author Sebastian Eibl <sebastian.eibl@fau.de>
//
//======================================================================================================================
#pragma once
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <pe/rigidbody/GeomPrimitive.h>
#include <pe/Types.h>
#include <core/math/Constants.h>
#include <core/math/Matrix3.h>
#include <core/math/Vector3.h>
#include <core/DataTypes.h>
#include <core/logging/Logging.h>
#include <core/math/Constants.h>
#include <core/math/Limits.h>
#include <core/math/Utility.h>
namespace walberla {
namespace pe {
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/**
* \ingroup pe
* \brief pe body representing a polyhedron.
*/
class Polyhedron : public GeomPrimitive
{
public:
//**Constructors********************************************************************************
/*!\name Constructors */
//@{
explicit Polyhedron( id_t sid, id_t uid, const Vec3& gpos, const Vec3& rpos, const Quat& q,
real_t radius, MaterialID material,
const bool global, const bool communicating, const bool infiniteMass );
//@}
//**********************************************************************************************
//**Destructor**********************************************************************************
/*!\name Destructor */
//@{
virtual ~Polyhedron();
//@}
//**********************************************************************************************
//**********************************************************************************************
public:
//**Get functions*******************************************************************************
/*!\name Get functions */
//@{
virtual inline real_t getVolume() const;
//@}
//**********************************************************************************************
//**Utility functions***************************************************************************
/*!\name Utility functions */
//@{
static inline id_t getStaticTypeID();
//@}
//**********************************************************************************************
//**Output functions****************************************************************************
/*!\name Output functions */
//@{
virtual void print( std::ostream& os, const char* tab ) const;
//@}
//**********************************************************************************************
//**Utility functions***************************************************************************
/*!\name Utility functions */
//@{
inline virtual Vec3 support( const Vec3& d ) const;
inline virtual Vec3 supportContactThreshold( const Vec3& d ) const;
//@}
//**********************************************************************************************
protected:
//**Utility functions***************************************************************************
/*!\name Utility functions */
//@{
virtual bool containsRelPointImpl ( real_t px, real_t py, real_t pz ) const;
virtual bool isSurfaceRelPointImpl( real_t px, real_t py, real_t pz ) const;
//@}
//**********************************************************************************************
//**Utility functions***************************************************************************
/*!\name Utility functions */
//@{
inline virtual void calcBoundingBox(); // Calculation of the axis-aligned bounding box
inline void calcInertia(); // Calculation of the moment of inertia
//@}
//**********************************************************************************************
private:
static id_t staticTypeID_; //< type id of polyhedron, will be set by SetBodyTypeIDs
static void setStaticTypeID(id_t typeID) {staticTypeID_ = typeID;}
//** friend declaration
/// needed to be able to set static type ids with setStaticTypeID
template <class T>
friend struct SetBodyTypeIDs;
};
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns unique type id of this type
*
* \return geometry specific type id
*/
inline id_t Polyhedron::getStaticTypeID()
{
return staticTypeID_;
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\name Polyhedron operators */
//@{
std::ostream& operator<<( std::ostream& os, const Polyhedron& s );
std::ostream& operator<<( std::ostream& os, ConstPolyhedronID s );
//@}
//*************************************************************************************************
} // namespace pe