MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SuperQuadricParticle.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef SuperQuad_H
27 #define SuperQuad_H
28 
29 #include "Math/SmallVector.h"
30 #include "BaseParticle.h"
31 #include "BaseInteractable.h"
33 
36 
55 class SuperQuadricParticle final : public BaseParticle
56 {
57 public:
63 
70 
72 
77  ~SuperQuadricParticle() override;
78 
82  SuperQuadricParticle* copy() const override;
83 
87  void write(std::ostream& os) const override;
88 
93  void read(std::istream& is) override;
94 
98  std::string getName() const override;
99 
106  void setAxesAndExponents(const Mdouble& a1, const Mdouble& a2, const Mdouble& a3, const Mdouble& eps1,
107  const Mdouble& eps2);
108 
115  void setAxesAndExponents(const Vec3D& axes, const Mdouble& eps1, const Mdouble& eps2);
116 
122  void setAxes(const Mdouble& a1, const Mdouble& a2, const Mdouble& a3);
123 
129  void setAxes(const Vec3D& axes) override;
130 
136  void setExponents(const Mdouble& eps1, const Mdouble& eps2) override;
137 
140 
145  Vec3D getAxes() const override;
146 
152  Mdouble getExponentEps1() const override;
153 
159  Mdouble getExponentEps2() const override;
160 
164  Mdouble getVolume() const override;
165 
169  void setInertia() override;
170 
171  void setRadius(const Mdouble radius) override;
172 
177  BaseInteraction* getInteractionWith(BaseParticle* P, unsigned timeStamp,
178  InteractionHandler* interactionHandler) override;
179 
184  Mdouble getCurvature(const LabFixedCoordinates& labFixedCoordinates) const override;
185 
189  bool isInContactWith(const BaseParticle* p) const override;
190 
194  SmallVector<3> computeShapeGradientLabFixed(const LabFixedCoordinates& labFixedCoordinates) const;
195 
196 
202  InteractionHandler* interactionHandler);
203 
207  SmallMatrix<3, 3> computeHessianLabFixed(const LabFixedCoordinates& labFixedCoordinates) const;
208 
212  Mdouble computeShape(const LabFixedCoordinates& labFixedCoordinates) const;
213 
219  const SuperQuadricParticle* p1,
220  const SuperQuadricParticle* p2) const;
221 
227  const SuperQuadricParticle* p1,
228  const SuperQuadricParticle* p2) const;
229 
234 
238  Mdouble overlapFromContactPoint(const LabFixedCoordinates& contactPoint, const LabFixedCoordinates& normal) const;
239 
244 
249  SmallVector<4> getContactPointPlanB(const SuperQuadricParticle* pOther, unsigned numberOfSteps) const;
250 
255  bool computeContactPoint(SmallVector<4>& contactPoint, const SuperQuadricParticle* p1,
256  const SuperQuadricParticle* p2) const;
257 
258 
259  void writeDebugMessageStep1(const SuperQuadricParticle* pQuad, const SmallVector<4>& contactPointPlanB) const;
260 
261  void writeDebugMessageStep2(const SuperQuadricParticle* pQuad, const Vec3D& dAxesThis, const Mdouble& dn11,
262  const Mdouble& dn12, const Vec3D& dAxesOther, const Mdouble& dn21,
263  const Mdouble& dn22) const;
264 
265  void writeDebugMessageStep3(const Vec3D& axesThis, const Mdouble& n11, const Mdouble& n12, const Vec3D& axesOther,
266  const Mdouble& n21, const Mdouble& n22) const;
267 
268  void
270  const unsigned int& counter) const;
271 
275  Mdouble getInteractionRadius(const BaseParticle* particle) const;
276 
278  void computeMass(const ParticleSpecies& s) override;
279 
280 private:
281 
285  void setBoundingRadius();
286 
293 
298 };
299 
300 #endif
BaseInteraction * getInteractionWith(BaseParticle *P, unsigned timeStamp, InteractionHandler *interactionHandler) override
Checks if this superquadric is in interaction with the given particle, and if so, returns vector of p...
Mdouble getCurvature(const LabFixedCoordinates &labFixedCoordinates) const override
Get the mean curvature of this superquadric at the given (lab-fixed) position, see Podlozhyuk et al...
void computeMass(const ParticleSpecies &s) override
Computes the particle's (inverse) mass and inertia.
SuperQuadricParticle * copy() const override
Copy method. It calls to copy constructor of this superquadric, useful for polymorphism.
std::string getName() const override
Returns the name of the class, here "SuperQuadricParticle".
bool computeContactPoint(SmallVector< 4 > &contactPoint, const SuperQuadricParticle *p1, const SuperQuadricParticle *p2) const
Perform the actual Newton-iterations to find the contact point. Note, that it is given back as a para...
Mdouble getInteractionRadius(const BaseParticle *particle) const
returns the radius plus half the interactionDistance of the mixed species
void setBoundingRadius()
Get the radius of the sphere that fits precisely around the particle.
void read(std::istream &is) override
Read function: read in the information for this superquadric from the given input-stream, for example a restart file.
void setRadius(const Mdouble radius) override
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
double Mdouble
Definition: GeneralDefine.h:34
SuperQuadricParticle()
Basic Particle constructor, creates a superquadric with axes (1,1,1) and exponents (2...
Vec3D BodyFixedCoordinates
BaseInteraction * getInteractionWithSuperQuad(SuperQuadricParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler)
Checks if this superquadric is in interaction with the given superquadric, and if so...
bool isInContactWith(const BaseParticle *p) const override
Get whether or not this superquadric is in contact with the given particle.
~SuperQuadricParticle() override
Destructor, needs to be implemented and checked to see if it is the largest or smallest particle curr...
Implementation of a 3D vector (by Vitaliy).
Definition: SmallVector.h:61
Vec3D getAxes() const override
Get the axes-lengths of this superquadric. We use the super-ellipsoid definition stated in Chapter 2 ...
SmallVector< 4 > getContactPoint(const SuperQuadricParticle *p, BaseInteraction *C) const
Compute the contact point between this and the given superquadric particle.
SmallVector< 4 > computeResidualContactDetection(const SmallVector< 4 > &position, const SuperQuadricParticle *p1, const SuperQuadricParticle *p2) const
Objective function for contact detection between the two given superquadrics. See Podlozhyuk et al...
Stores information about interactions between two interactable objects; often particles but could be ...
void setExponents(const Mdouble &eps1, const Mdouble &eps2) override
Set the exponents to eps1 and eps2 for this superquadric. We use the super-ellipsoid definition state...
SmallVector< 4 > getContactPointPlanB(const SuperQuadricParticle *pOther, unsigned numberOfSteps) const
If the "normal" procedure fails to find a contact point, use an alternative approach that involves st...
Mdouble getVolume() const override
Vec3D axes_
Lengths of principal axes (a1, a2, a3).
SmallVector< 4 > getInitialGuessForContact(const SuperQuadricParticle *pQuad, BaseInteraction *C) const
Get an initial guess for the contact-point between this particle and the given particle.
Container to store Interaction objects.
Mdouble eps1_
Blockiness parameters.
Mdouble computeShape(const LabFixedCoordinates &labFixedCoordinates) const
Compute and get the shape-functiion at the given (lab-fixed) position.
void setInertia() override
Compute and set the inertia-tensor for this superquadric. For internal use only.
Vec3D LabFixedCoordinates
Mdouble getExponentEps1() const override
Get the first exponent of this superquadric. We use the super-ellipsoid definition stated in Chapter ...
void writeDebugMessageStep1(const SuperQuadricParticle *pQuad, const SmallVector< 4 > &contactPointPlanB) const
SmallMatrix< 4, 4 > getJacobianOfContactDetectionObjective(const SmallVector< 4 > &contactPoint, const SuperQuadricParticle *p1, const SuperQuadricParticle *p2) const
Compute and return the derivative of functionThatShouldBecomeZeroForContactDetection, both to the position and the Lagrange multiplier, and evaluated at the contact point.
void setAxes(const Mdouble &a1, const Mdouble &a2, const Mdouble &a3)
Set the axes-lengths to a1, a2 and a3 for this superquadric. We use the super-ellipsoid definition st...
void writeDebugMessageStep3(const Vec3D &axesThis, const Mdouble &n11, const Mdouble &n12, const Vec3D &axesOther, const Mdouble &n21, const Mdouble &n22) const
void setAxesAndExponents(const Mdouble &a1, const Mdouble &a2, const Mdouble &a3, const Mdouble &eps1, const Mdouble &eps2)
Set the geometrical properties of the superquadrics, namely the axes-lengths a1, a2 and a3...
Definition: Vector.h:49
Mdouble overlapFromContactPoint(const LabFixedCoordinates &contactPoint, const LabFixedCoordinates &normal) const
Compute the distance between the contact-point and surface of this superquadric particle.
Data type for small dense matrix.
Definition: SmallMatrix.h:67
Mdouble getExponentEps2() const override
Get the second exponent of this superquadric. We use the super-ellipsoid definition stated in Chapter...
SmallVector< 3 > computeShapeGradientLabFixed(const LabFixedCoordinates &labFixedCoordinates) const
Compute and get the gradient of the shape-function at the given (lab-fixed) position.
void writeDebugMessageStep2(const SuperQuadricParticle *pQuad, const Vec3D &dAxesThis, const Mdouble &dn11, const Mdouble &dn12, const Vec3D &dAxesOther, const Mdouble &dn21, const Mdouble &dn22) const
void writeDebugMessageMiddleOfLoop(const SuperQuadricParticle &p1, const SuperQuadricParticle &p2, SmallVector< 4 > &contactPointPlanB, const unsigned int &counter) const
void write(std::ostream &os) const override
Write function: write this superquadric to the given output-stream, for example a restart-file...
SmallMatrix< 3, 3 > computeHessianLabFixed(const LabFixedCoordinates &labFixedCoordinates) const
Compute and get the hessian ("second derivative") of the shape-function at the given (lab-fixed) posi...