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);
37  semiangle_ = 20 * constants::pi / 180.;
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_ = axis_ / axis_.getLength();
61 }
62 
64 {
65  return new ArcWall(*this);
66 }
67 
69  Mdouble& distance, Vec3D& normal_return) const
70 {
71  // distance between x0 and the *surface* (not the axis)
72  distance = radius_ - sqrt(
73  pow((p.getPosition() - pos_).getLength(), 2)
74  - pow(Vec3D::dot(p.getPosition() - pos_, axis_), 2)
75  );
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 = pos_ + Vec3D::dot(p.getPosition() - pos_, axis_) * axis_;
82  // outward-pointing normal, for an inward-pointing force
83  normal_return = p.getPosition() - axisContactPoint;
84  normal_return /= normal_return.getLength();
85 
86  /* There is an interaction iff the interaction normal is within
87  * semiangle of the centreline. */
88  double angle_between = acos(Vec3D::dot(normal_return, centreline_));
89  if (angle_between < semiangle_ || semiangle_ >= constants::pi)
90  return true;
91  else
92  return false;
93  }
94 }
95 
97  unsigned timeStamp, InteractionHandler* interactionHandler)
98 {
99  Mdouble distance;
100  Vec3D normal;
101  if (getDistanceAndNormal(*p, distance, normal))
102  {
103  BaseInteraction* c = interactionHandler->getInteraction(p, this, timeStamp);
104  c->setNormal(-normal);
105  c->setDistance(distance);
106  c->setOverlap(p->getRadius() - distance);
107  c->setContactPoint(p->getPosition() - (p->getRadius() - 0.5 * c->getOverlap()) * c->getNormal());
109  return c;
110  }
111  else
112  return nullptr;
113 }
114 
115 void ArcWall::read(std::istream& is)
116 {
117  BaseWall::read(is);
118  std::string dummy;
119  is >> dummy >> axis_
120  >> dummy >> pos_
121  >> dummy >> radius_
122  >> dummy >> centreline_
123  >> dummy >> semiangle_;
124 }
125 
126 void ArcWall::write(std::ostream& os) const
127 {
128  BaseWall::write(os);
129  os << " axis " << axis_
130  << " pos " << pos_
131  << " radius " << radius_
132  << " centreline " << centreline_
133  << " semiangle " << semiangle_;
134 }
135 
136 std::string ArcWall::getName() const
137 {
138  return "ArcWall";
139 }
Vec3D centreline_
Definition: ArcWall.h:89
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
A wall that is the inside of an arc of a cylinder.
Definition: ArcWall.h:47
void set(Vec3D axis, Vec3D pos, Mdouble radius, Vec3D centreline, Mdouble semiangle)
Set.
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:90
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 ...
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.
void write(std::ostream &os) const override
Write a BaseInteractable to an output stream.
Definition: ArcWall.cc:126
Mdouble getWallInteractionRadius(const BaseWall *wall) const
returns the radius plus the interactionDistance
Definition: BaseParticle.h:383
const Mdouble pi
Definition: ExtendedMath.h:45
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
Container to store Interaction objects.
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: ArcWall.cc:68
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
void read(std::istream &is) override
Reads a BaseInteractable from an input stream.
Definition: ArcWall.cc:115
BaseInteraction * getInteractionWith(BaseParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler) override
Returns the interaction between this object and a given BaseParticle.
Definition: ArcWall.cc:96
Definition: Vector.h:49
Vec3D axis_
Definition: ArcWall.h:86
Mdouble radius_
Definition: ArcWall.h:88
ArcWall()
Default constructor.
Definition: ArcWall.cc:31
std::string getName() const override
A purely virtual function.
Definition: ArcWall.cc:136
Vec3D pos_
Definition: ArcWall.h:87