MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ArcWall.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 "ArcWall.h"
27 #include "InteractionHandler.h"
28 #include "Particles/BaseParticle.h"
29 #include "Math/ExtendedMath.h"
30 
32 {
33  axis_ = Vec3D(0, 0, 1);
34  pos_ = Vec3D(0, 1, 0);
35  radius_ = 1;
36  centreline_ = Vec3D(0, -1, 0);
38 }
39 
40 ArcWall::ArcWall(const ArcWall& other) : BaseWall(other)
41 {
42  axis_ = other.axis_;
43  pos_ = other.pos_;
44  radius_ = other.radius_;
45  centreline_ = other.centreline_;
46  semiangle_ = other.semiangle_;
47 }
48 
49 void ArcWall::set(Vec3D axis, Vec3D pos, Mdouble radius, Vec3D centreline, Mdouble semiangle)
50 {
51  axis_ = axis;
52  pos_ = pos;
53  radius_ = radius;
54  centreline_ = centreline;
55  semiangle_ = semiangle;
56 
57  /* Normalise axis_ and centreline_, and make centreline_ perpendicular to axis_ */
58  axis_.normalise();
61 }
62 
64 {
65  return new ArcWall(*this);
66 }
67 
69  Mdouble& distance,
70  Vec3D& normal) const
71 {
72  Vec3D nearestPointOnAxis = pos_ + Vec3D::dot(p.getPosition() - pos_, axis_) * axis_;
73  Mdouble distanceFromAxis = (p.getPosition() - nearestPointOnAxis).getLength();
74  // distance between x0 and the surface
75  distance = radius_ - distanceFromAxis;
76  if (distance >= p.getWallInteractionRadius(this))
77  return false;
78 
79  // the normal points into the wall, i.e. out from the axis
80  normal = p.getPosition() - nearestPointOnAxis;
81  normal.normalise();
82 
83  // If the arc is actually a full circle then there is definitely an
84  // interaction, regardless of direction.
85  if (semiangle_ >= 180. * constants::degree)
86  return true;
87 
88  // Otherwise it depends on whether the interaction direction is
89  // sufficiently aligned with the centreline.
90  return acos(Vec3D::dot(normal, centreline_)) < semiangle_;
91 }
92 
94  unsigned timeStamp,
95  InteractionHandler* interactionHandler)
96 {
97  Mdouble distance;
98  Vec3D normal;
99  if (getDistanceAndNormal(*p, distance, normal))
100  {
101  BaseInteraction* c = interactionHandler->getInteraction(p, this, timeStamp);
102  c->setNormal(-normal);
103  c->setDistance(distance);
104  c->setOverlap(p->getRadius() - distance);
105  c->setContactPoint(p->getPosition() - (p->getRadius() - 0.5 * c->getOverlap()) * c->getNormal());
107  return c;
108  }
109  else
110  return nullptr;
111 }
112 
113 void ArcWall::read(std::istream& is)
114 {
115  BaseWall::read(is);
116  std::string dummy;
117  is >> dummy >> axis_
118  >> dummy >> pos_
119  >> dummy >> radius_
120  >> dummy >> centreline_
121  >> dummy >> semiangle_;
122 }
123 
124 void ArcWall::write(std::ostream& os) const
125 {
126  BaseWall::write(os);
127  os << " axis " << axis_
128  << " pos " << pos_
129  << " radius " << radius_
130  << " centreline " << centreline_
131  << " semiangle " << semiangle_;
132 }
133 
134 std::string ArcWall::getName() const
135 {
136  return "ArcWall";
137 }
Vec3D centreline_
Definition: ArcWall.h:104
ArcWall * copy() const override
Pure virtual function that can be overwritten in inherited classes in order to copy a BaseWall...
Definition: ArcWall.cc:63
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
void setNormal(Vec3D normal)
Sets the normal vector between the two interacting objects.
void setOverlap(Mdouble overlap)
Set the overlap between the two interacting object.
double Mdouble
Definition: GeneralDefine.h:34
void normalise()
Makes this Vec3D unit length.
Definition: Vector.cc:123
A wall that is the inside (concave side) of an arc of a cylinder, like a pipe or half-pipe.
Definition: ArcWall.h:51
void set(Vec3D axis, Vec3D pos, Mdouble radius, Vec3D centreline, Mdouble semiangle)
Set parameters of the ArcWall.
Definition: ArcWall.cc:49
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
Mdouble semiangle_
Definition: ArcWall.h:105
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
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 ...
const Vec3D & getNormal() const
Gets the normal vector between the two interacting objects.
void write(std::ostream &os) const override
Write a BaseInteractable to an output stream.
Definition: ArcWall.cc:124
Mdouble getWallInteractionRadius(const BaseWall *wall) const
returns the radius plus the interactionDistance
Definition: BaseParticle.h:386
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
Container to store Interaction objects.
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:348
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
bool getDistanceAndNormal(const BaseParticle &p, Mdouble &distance, Vec3D &normal) const override
Pure virtual function that computes the distance of a BaseParticle to this wall and returns the norma...
Definition: ArcWall.cc:68
const Mdouble degree
Definition: ExtendedMath.h:52
void read(std::istream &is) override
Reads a BaseInteractable from an input stream.
Definition: ArcWall.cc:113
BaseInteraction * getInteractionWith(BaseParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler) override
Returns the interaction between this object and a given BaseParticle.
Definition: ArcWall.cc:93
Definition: Vector.h:49
Vec3D axis_
Definition: ArcWall.h:101
Mdouble radius_
Definition: ArcWall.h:103
ArcWall()
Default constructor.
Definition: ArcWall.cc:31
std::string getName() const override
A purely virtual function.
Definition: ArcWall.cc:134
Vec3D pos_
Definition: ArcWall.h:102