MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Coil.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, 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 COIL_H
27 #define COIL_H
28 
29 #include "../BaseWall.h"
30 
31 
33 
38 
39 
40 class Coil : public BaseWall
41 {
42  public:
43 
44  Coil() : BaseWall()
45  {
46  Start.set_zero();
47  L=1;
48  r=1;
49  N=1;
50  omega=1;
51  offset=0;
52  thickness=0;
53  #ifdef CONSTUCTOR_OUTPUT
54  std::cerr << "Coil() finished" << std::endl;
55  #endif
56  }
57 
58  Coil(Vec3D Start, double L, double r, double N, double omega,double thickness) : BaseWall()
59  {
60  this->Start=Start;
61  this->L=L;
62  this->r=r;
63  this->N=N;
64  this->omega=omega;
65  this->thickness=thickness;
66  this->offset=0.0;
67  #ifdef CONSTUCTOR_OUTPUT
68  std::cerr << "Coil() finished" << std::endl;
69  #endif
70  }
71 
72  virtual Coil* copy() const
73  {
74  return new Coil(*this);
75  }
76 
77  bool get_distance_and_normal(BaseParticle &P, Mdouble &distance, Vec3D &normal_return)
78  {
79  double Rsqr=pow(P.get_Position().X-Start.X,2)+pow(P.get_Position().Y-Start.Y,2);
81  {
82  //std::cout<<"Particle is out of first bound checking"<<std::endl;
83  //std::cout<<"Rule 1: "<<pow(r-P.get_Radius()-thickness,2)<<"<"<<Rsqr<<"<"<<pow(r+P.get_Radius()+thickness,2)<<std::endl;
84  //std::cout<<"Rule 2: "<<Start.Z-P.get_Radius()-thickness<<"<"<<P.get_Position().Z<<"<"<<L+Start.Z+P.get_Radius()+thickness<<std::endl;
85  return false;
86  }
87  double R=sqrt(Rsqr);
88  double alpha=atan2(P.get_Position().Y-Start.Y,P.get_Position().X-Start.X);
89  double dz=P.get_Position().Z-Start.Z;
90 
95 
99 
100  double q; //Current guess
101  double dd; //Derivative at current guess
102  double ddd; //Second derivative at current guess
103  double q0=dz/L; //Minimum of the parabolic part
104 
109 
110  double k=round(alpha/2.0/constants::pi-(offset+N*q0));
111  q=alpha/(2*constants::pi*N)-k/N-offset/N;
112 
113  //Now apply Newton's method
114  do
115  {
116  dd =-4.0*R*r*constants::pi *N *sin(alpha-2.0*constants::pi*(N*q+offset))-2.0*L*(dz-q*L);
117  ddd= 8.0*R*r*constants::sqr_pi*N*N*cos(alpha-2.0*constants::pi*(N*q+offset))+2.0*L*L;
118  q-=dd/ddd;
119  } while(fabs(dd/ddd)>1e-14);
120 
121 
122  //Check if the location is actually on the coil, otherwise a point collision with the end of the coil calculated
123  if(q<0) //Left boundary of the coil
124  {
125  q=0;
126  }
127  else if(q>1) //right boundary of the coil
128  {
129  q=1;
130  }
131 
132  distance=R*R+r*r-2*R*r*cos(alpha-2*constants::pi*(offset+N*q))+pow(dz-q*L,2);
133  //If distance is to large there is no contact
135  {
136  //std::cout<<"Particle is out of second bound checking, distance^2="<<distance<<" max="<<(P.get_Radius()+thickness)*(P.get_Radius()+thickness)<<std::endl;
137  return false;
138  }
139 
140  Vec3D ContactPoint;
141  distance=sqrt(distance)-thickness;
142  ContactPoint.X=Start.X+r*cos(2.0*constants::pi*(offset+N*q));
143  ContactPoint.Y=Start.Y+r*sin(2.0*constants::pi*(offset+N*q));
144  ContactPoint.Z=Start.Z+q*L;
145  normal_return=ContactPoint-P.get_Position();
146  normal_return/=normal_return.GetLength();
147  return true;
148  }
149 
152  {
153  offset+=omega*dt;
154  }
155 
157  void read(std::istream& is)
158  {
159  std::string dummy;
160  is >> dummy >> Start >> dummy >> L >> dummy >> r >> dummy >> N >> dummy >> omega >> dummy >> offset;
161  }
162 
164  void print(std::ostream& os) const
165  {
166  os << "Coil Start " << Start << " Length "<<L<<" Radius "<<r<<" Revolutions "<<N<<" Omega "<<omega<<" Thickness "<<thickness<<" Offset "<<offset;
167  }
168 
170  Vec3D get_Velocity() const {return Vec3D(0.0,0.0,0.0);}
171 
172  private:
175 };
176 
177 #endif
Vec3D Start
Definition: Coil.h:173
Mdouble X
Definition: Vector.h:44
double offset
Definition: Coil.h:174
double L
Definition: Coil.h:174
void print(std::ostream &os) const
outputs wall
Definition: Coil.h:164
double r
Definition: Coil.h:174
const Mdouble pi
Definition: ExtendedMath.h:54
void read(std::istream &is)
reads wall
Definition: Coil.h:157
double Mdouble
Definition: ExtendedMath.h:33
Mdouble get_WallInteractionRadius() const
double thickness
Definition: Coil.h:174
bool get_distance_and_normal(BaseParticle &P, Mdouble &distance, Vec3D &normal_return)
Definition: Coil.h:77
const Vec3D & get_Position() const
Mdouble Y
Definition: Vector.h:44
void set_zero()
Definition: Vector.h:55
void move_time(Mdouble dt)
Allows the wall to be moved to a new position (also orthogonal to the normal), and setting the veloci...
Definition: Coil.h:151
Mdouble GetLength() const
Definition: Vector.h:248
Coil()
Definition: Coil.h:44
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
Coil(Vec3D Start, double L, double r, double N, double omega, double thickness)
Definition: Coil.h:58
Mdouble Z
Definition: Vector.h:44
virtual Coil * copy() const
Definition: Coil.h:72
This function defines a coil in the z-direction from a (constant) starting point, a (constant) length...
Definition: Coil.h:40
Vec3D get_Velocity() const
Todo{Implement this function correctly}.
Definition: Coil.h:170
const Mdouble sqr_pi
Definition: ExtendedMath.h:56
double N
Definition: Coil.h:174
double omega
Definition: Coil.h:174