MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Combtooth.cc
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 #include "Combtooth.h"
27 #include "InteractionHandler.h"
28 #include "Particles/BaseParticle.h"
29 #include "Math/ExtendedMath.h"
30 
32 {
33  axis_ = Vec3D(0, 0, 1);
34  position_ = Vec3D(0, 0, 0);
35  radius_ = 1;
36 }
37 
38 Combtooth::Combtooth(const Combtooth& other) : BaseWall(other)
39 {
40  axis_ = other.axis_;
41  position_ = other.position_;
42  radius_ = other.radius_;
43 
44  /* Normalise axis_ */
45  axis_ /= axis_.getLength();
46 }
47 
48 Combtooth::~Combtooth() = default;
49 
50 void Combtooth::set(Vec3D axis, Vec3D position, Mdouble radius)
51 {
52  axis_ = axis / axis.getLength();
53  position_ = position;
54  radius_ = radius;
55 }
56 
58 {
59  return new Combtooth(*this);
60 }
61 
63  Mdouble& distance, Vec3D& normal_return) const
64 {
65  /* define shortcuts */
66  const Mdouble x0 = p.getPosition().X;
67  const Mdouble y0 = p.getPosition().Y;
68  const Mdouble z0 = p.getPosition().Z;
69  const Mdouble ra = p.getWallInteractionRadius(this); // note, not getRadius()
70 
71  // distance between x0 and the *surface* (not the axis)
72  distance = sqrt(
73  pow((p.getPosition() - position_).getLength(), 2)
74  - pow(Vec3D::dot(p.getPosition() - position_, axis_), 2)
75  ) - radius_;
76  if (distance >= p.getWallInteractionRadius(this))
77  return false;
78  else
79  {
80  Vec3D axisContactPoint; // the point on the axis closest to the particle
81  axisContactPoint = position_ + Vec3D::dot(p.getPosition() - position_, axis_) * axis_;
82  normal_return = (axisContactPoint - p.getPosition()); // inward-pointing normal
83  normal_return /= normal_return.getLength();
84  return true;
85  }
86 }
87 
89  unsigned timeStamp, InteractionHandler* interactionHandler)
90 {
91  Mdouble distance;
92  Vec3D normal;
93  if (getDistanceAndNormal(*p, distance, normal))
94  {
95  BaseInteraction* c = interactionHandler->getInteraction(p, this, timeStamp);
96  c->setNormal(-normal); // outward-pointing normal to cylinder
97  c->setDistance(distance);
98  c->setOverlap(p->getRadius() - distance);
100  c->setContactPoint(p->getPosition() - (p->getRadius() - 0.5 * c->getOverlap()) * c->getNormal());
101  return c;
102  }
103  else
104  return nullptr;
105 }
106 
107 void Combtooth::read(std::istream& is)
108 {
109  BaseWall::read(is);
110  std::string dummy;
111  is >> dummy >> axis_
112  >> dummy >> position_
113  >> dummy >> radius_;
114 }
115 
116 void Combtooth::write(std::ostream& os) const
117 {
118  BaseWall::write(os);
119  os << " axis " << axis_
120  << " position " << position_
121  << " radius " << radius_;
122 }
123 
124 std::string Combtooth::getName() const
125 {
126  return "Combtooth";
127 }
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
void setNormal(Vec3D normal)
Sets the normal vector between the two interacting objects.
Mdouble X
the vector components
Definition: Vector.h:65
Vec3D position_
Definition: Combtooth.h:76
void setOverlap(Mdouble overlap)
Set the overlap between the two interacting object.
double Mdouble
Definition: GeneralDefine.h:34
BaseInteraction * getInteractionWith(BaseParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler) override
Returns the interaction between this wall and a given particle, nullptr if there is no interaction...
Definition: Combtooth.cc:88
Combtooth * copy() const override
Copy.
Definition: Combtooth.cc:57
void setContactPoint(Vec3D contactPoint)
Set the location of the contact point between the two interacting objects.
void write(std::ostream &os) const override
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: BaseWall.cc:102
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
void set(Vec3D axis, Vec3D position, Mdouble radius)
Set.
Definition: Combtooth.cc:50
void setDistance(Mdouble distance)
Sets the interaction distance between the two interacting objects.
Stores information about interactions between two interactable objects; often particles but could be ...
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:331
const Vec3D & getNormal() const
Gets the normal vector between the two interacting objects.
~Combtooth() override
Default destructor.
Combtooth()
Default constructor.
Definition: Combtooth.cc:31
void write(std::ostream &os) const override
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: Combtooth.cc:116
Mdouble getWallInteractionRadius(const BaseWall *wall) const
returns the radius plus the interactionDistance
Definition: BaseParticle.h:383
std::string getName() const override
A purely virtual function.
Definition: Combtooth.cc:124
void read(std::istream &is) override
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: Combtooth.cc:107
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
Vec3D axis_
Definition: Combtooth.h:75
Container to store Interaction objects.
Mdouble radius_
Definition: Combtooth.h:77
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:345
Basic class for walls.
Definition: BaseWall.h:47
Mdouble getOverlap() const
Returns a Mdouble with the current overlap between the two interacting objects.
void read(std::istream &is) override
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:80
Mdouble Y
Definition: Vector.h:65
bool getDistanceAndNormal(const BaseParticle &p, Mdouble &distance, Vec3D &normal_return) const override
Pure virtual function that computes the distance of a BaseParticle to this wall and returns the norma...
Definition: Combtooth.cc:62
Definition: Vector.h:49
Mdouble Z
Definition: Vector.h:65