MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParabolaChute.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 "ParabolaChute.h"
27 #include "InteractionHandler.h"
28 #include "Particles/BaseParticle.h"
29 
31 {
32  l_ = 1.0;
33  ws_ = 1.0;
34  logger(DEBUG, "ParabolaChute() constructor finished");
35 }
36 
38 {
39  l_ = other.l_;
40  ws_ = other.ws_;
41  logger(DEBUG, "ParabolaChute copy constructor finished");
42 }
43 
44 
46 {
47  l_ = length;
48  ws_ = widthscale;
49  logger(DEBUG, "ParabolaChute(params) constructor finished");
50 }
51 
53 {
54  logger(DEBUG, "ParabolaChute destructor finished");
55 }
56 
57 void ParabolaChute::set(Mdouble length, Mdouble widthscale)
58 {
59  l_ = length;
60  ws_ = widthscale;
61 }
62 
63 /*
64 ParabolaChute* ParabolaChute::copy() const {
65  return new ParabolaChute(*this);
66 }
67 */
68 
69 bool ParabolaChute::getDistanceAndNormal(const BaseParticle& p, Mdouble& distance, Vec3D& normal_return) const
70 {
71  /* Define some shortcuts */
72  Mdouble y0 = p.getPosition().Y;
73  Mdouble z0 = p.getPosition().Z;
74  Mdouble a = p.getRadius();
75 
76  /* First, check whether the particle is definitely out of contact with the
77  * chute. This will be so if the particle's interaction radius is small and
78  * the particle's z-position is high. */
79  // TODO do this properly
80  if (false)
81  {
82  return false;
83  }
84 
85  /* If not, then use Newton's method to minimise (half of the squared) distance */
86  Mdouble R; //TODO
87  Mdouble alpha; //TODO
88  Mdouble dz = p.getPosition().Z; //TODO
89  Mdouble q; // current guess
90  Mdouble dd; // derivative of half of the squared distance at current guess
91  Mdouble ddd; // second derivative at current guess
92  Mdouble q0 = dz / l_; // minimum of the parabolic part
93 
94  // Iterate according to Newton
95  do
96  {
97  dd = -2 * pow(q, 3) / pow(ws_, 2) + (1 - 2 * z0 / ws_) * q - y0;
98  ddd = 6 * pow(q / ws_, 2) + (1 - 2 * z0 / ws_);
99  q -= dd / ddd;
100  } while (fabs(dd / ddd) > 1e-14);
101 
102  // Check whether this location is actually on the parabolic chute, otherwise
103  // a point collision with the end of the chute calculated
104 
105  Mdouble distanceSquared = pow(q - y0, 2) + pow(pow(q, 2) / ws_ - z0, 2);
106  // TODO
107  if (distanceSquared >= mathsFunc::square(p.getWallInteractionRadius(this)))
108  {
109  return false;
110  }
111  else
112  {
113  Vec3D ContactPoint;
114  distance = sqrt(distanceSquared);
115  // ContactPoint.X = // TODO
116  normal_return = ContactPoint - p.getPosition();
117  normal_return /= normal_return.getLength();
118  return true;
119  }
120 }
121 
122 /* TODO - getInteractionWith, read, write, getName */
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
ParabolaChute()
Default constructor, sets a chute with default parameters.
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:331
Mdouble getWallInteractionRadius(const BaseWall *wall) const
returns the radius plus the interactionDistance
Definition: BaseParticle.h:383
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...
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:345
Basic class for walls.
Definition: BaseWall.h:47
Mdouble Y
Definition: Vector.h:65
void set(Mdouble length, Mdouble widthscale)
~ParabolaChute() override
Definition: Vector.h:49
T square(const T val)
squares a number
Definition: ExtendedMath.h:104
Mdouble Z
Definition: Vector.h:65