MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Screw Class Reference

This function defines an Archimedes' screw in the z-direction from a (constant) starting point, a (constant) length L, a (constant) radius r, a (constant) number or revelations N and a (constant) rotation speed (rev/s) More...

#include <Screw.h>

+ Inheritance diagram for Screw:

Public Member Functions

 Screw ()
 Default constructor: make a screw with default parameters. More...
 
 Screw (const Screw &other)
 Copy constructor, copies another Screw. More...
 
 Screw (Vec3D start, Mdouble l, Mdouble r, Mdouble n, Mdouble omega, Mdouble thickness)
 Constructor in which all parameters of the screw are set. More...
 
 ~Screw ()
 Default destructor. More...
 
Screwcopy () const final
 Copy this screw and return a pointer to the copy. More...
 
bool getDistanceAndNormal (const BaseParticle &P, Mdouble &distance, Vec3D &normal_return) const final
 Compute the distance from the Screw for a given BaseParticle and return if there is a collision. If there is a collision, also return the normal vector of the interaction point. More...
 
void move_time (Mdouble dt)
 Rotate the Screw for a period dt, so that the offset_ changes with omega_*dt. More...
 
void read (std::istream &is) override
 Reads a Screw from an input stream, for example a restart file. More...
 
void oldRead (std::istream &is)
 Reads a Screw in the old style from an input stream, for example a restart file old style. More...
 
void write (std::ostream &os) const override
 Writes this Screw to an output stream, for example a restart file. More...
 
std::string getName () const final
 Returns the name of the object, here the string "Screw". More...
 
void writeVTK (std::string filename) const
 
void getTriangulation (std::vector< Vec3D > &vertex, std::vector< std::array< unsigned, 3 >> &face, unsigned nr=5, unsigned nz=15) const
 
- Public Member Functions inherited from BaseWall
 BaseWall ()
 Default constructor. It makes an empty BaseWall. More...
 
 BaseWall (const BaseWall &w)
 Copy constructor. More...
 
virtual ~BaseWall ()
 Default destructor. More...
 
virtual MERCURY_DEPRECATED void clear ()
 A function that removes all data from this BaseWall, so sets handler_ to nullptr. More...
 
virtual void setHandler (WallHandler *handler)
 A function which sets the WallHandler for this BaseWall. More...
 
WallHandlergetHandler () const
 A function which returns the WallHandler that handles this BaseWall. More...
 
void setIndSpecies (unsigned int indSpecies)
 Define the species of this wall using the index of the species in the SpeciesHandler in this DPMBase. More...
 
void setSpecies (const ParticleSpecies *species)
 Define the species of this wall. More...
 
bool getLinePlaneIntersect (Vec3D &intersect, const Vec3D &p0, const Vec3D &p1, const Vec3D &n, const Vec3D &p)
 
bool isInsideWallVTK (const Vec3D &point, const Vec3D &normal, const Vec3D &position) const
 
void projectOntoWallVTK (Vec3D &point0, const Vec3D &point1, const Vec3D &normal, const Vec3D &position) const
 
void intersectVTK (std::vector< Vec3D > &points, const Vec3D normal, const Vec3D position) const
 
virtual void writeVTK (VTKContainer &vtk) const
 
virtual std::vector
< BaseInteraction * > 
getInteractionWith (BaseParticle *p, Mdouble timeStamp, InteractionHandler *interactionHandler)
 
- Public Member Functions inherited from BaseInteractable
 BaseInteractable ()
 Default BaseInteractable constructor, it simply creates an empty BaseInteractable. More...
 
 BaseInteractable (const BaseInteractable &p)
 Copy constructor. It copies the BaseInteractable and all objects it contains. More...
 
virtual ~BaseInteractable ()
 Destructor, it simply destructs the BaseInteractable and all the objects it contains. More...
 
unsigned int getIndSpecies () const
 Returns the index of the Species of this BaseInteractable. More...
 
const ParticleSpeciesgetSpecies () const
 Returns a pointer to the species of this BaseInteractable. More...
 
void setSpecies (const ParticleSpecies *species)
 Sets the species of this BaseInteractable. More...
 
const Vec3DgetForce () const
 Returns the force on this BaseInteractable. More...
 
const Vec3DgetTorque () const
 Returns the torque on this BaseInteractable. More...
 
void setForce (const Vec3D &force)
 Sets the force on this BaseInteractable. More...
 
void setTorque (const Vec3D &torque)
 Sets the torque on this BaseInteractable. More...
 
void addForce (const Vec3D &addForce)
 Adds an amount to the force on this BaseInteractable. More...
 
void addTorque (const Vec3D &addTorque)
 Adds an amount to the torque on this BaseInteractable. More...
 
const Vec3DgetPosition () const
 Returns the position of this BaseInteractable. More...
 
const Vec3DgetOrientation () const
 Returns the orientation of this BaseInteractable. More...
 
void setPosition (const Vec3D &position)
 Sets the position of this BaseInteractable. More...
 
void setOrientation (const Vec3D &orientation)
 Sets the orientation of this BaseInteractable. More...
 
virtual void move (const Vec3D &move)
 Moves this BaseInteractable by adding an amount to the position. More...
 
void rotate (const Vec3D &rotate)
 Rotates this BaseInteractable. More...
 
const std::list
< BaseInteraction * > & 
getInteractions () const
 Returns a reference to the list of interactions in this BaseInteractable. More...
 
void addInteraction (BaseInteraction *I)
 Adds an interaction to this BaseInteractable. More...
 
bool removeInteraction (BaseInteraction *I)
 Removes an interaction from this BaseInteractable. More...
 
void copyInteractionsForPeriodicParticles (const BaseInteractable &p)
 Copies interactions to this BaseInteractable whenever a periodic copy made. More...
 
void setVelocity (const Vec3D &velocity)
 set the velocity of the BaseInteractable. More...
 
void setAngularVelocity (const Vec3D &angularVelocity)
 set the angular velocity of the BaseInteractble. More...
 
void addVelocity (const Vec3D &velocity)
 adds an increment to the velocity. More...
 
void addAngularVelocity (const Vec3D &angularVelocity)
 add an increment to the angular velocity. More...
 
virtual const Vec3DgetVelocity () const
 Returns the velocity of this interactable. More...
 
virtual const Vec3DgetAngularVelocity () const
 Returns the angular velocity of this interactable. More...
 
void setPrescribedPosition (const std::function< Vec3D(double)> &prescribedPosition)
 Allows the position of an infinite mass interactable to be prescribed. More...
 
void applyPrescribedPosition (double time)
 Computes the position from the user defined prescribed position function. More...
 
void setPrescribedVelocity (const std::function< Vec3D(double)> &prescribedVelocity)
 Allows the velocity of an infinite mass interactable to be prescribed. More...
 
void applyPrescribedVelocity (double time)
 Computes the velocity from the user defined prescribed velocity function. More...
 
void setPrescribedOrientation (const std::function< Vec3D(double)> &prescribedOrientation)
 Allows the orientation of the infinite mass interactbale to be prescribed. More...
 
void applyPrescribedOrientation (double time)
 Computes the orientation from the user defined prescribed orientation function. More...
 
void setPrescribedAngularVelocity (const std::function< Vec3D(double)> &prescribedAngularVelocity)
 Allows the angular velocity of the infinite mass interactable to be prescribed. More...
 
void applyPrescribedAngularVelocity (double time)
 Computes the angular velocity from the user defined prescribed angular velocity. More...
 
virtual const Vec3D getVelocityAtContact (const Vec3D &contact) const
 Returns the velocity at the contact point, use by many force laws. More...
 
void integrateBeforeForceComputation (double time, double timeStep)
 This is part of integrate routine for objects with infinite mass. More...
 
void integrateAfterForceComputation (double time, double timeStep)
 This is part of the integration routine for objects with infinite mass. More...
 
- Public Member Functions inherited from BaseObject
 BaseObject ()
 Default constructor. More...
 
 BaseObject (const BaseObject &p)
 Copy constructor, copies all the objects BaseObject contains. More...
 
virtual ~BaseObject ()
 virtual destructor More...
 
virtual void moveInHandler (const unsigned int index)
 Except that it is virtual, it does the same thing as setIndex() does. More...
 
void setIndex (const unsigned int index)
 Allows one to assign an index to an object in the handler/container. More...
 
void setId (const unsigned int id)
 Assigns a unique identifier to each object in the handler (container) which remains constant even after the object is deleted from the container/handler. More...
 
unsigned int getIndex () const
 Returns the index of the object in the handler. More...
 
unsigned int getId () const
 Returns the unique identifier of any particular object. More...
 

Private Attributes

Vec3D start_
 The centre of the lower end of the screw. More...
 
Mdouble l_
 The length of the Screw. More...
 
Mdouble maxR_
 The outer radius of the Screw. More...
 
Mdouble n_
 The number of revelations. More...
 
Mdouble omega_
 Rotation speed in rev/s. More...
 
Mdouble offset_
 The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation. More...
 
Mdouble thickness_
 The thickness of the Screw. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseWall
static void addToVTK (const std::vector< Vec3D > &points, VTKContainer &vtk)
 
- Public Attributes inherited from BaseWall
WallHandlerhandler_
 

Detailed Description

This function defines an Archimedes' screw in the z-direction from a (constant) starting point, a (constant) length L, a (constant) radius r, a (constant) number or revelations N and a (constant) rotation speed (rev/s)

q is a new coordinate going from 0 to 1 and t is the time, x=xs+r*cos(2*pi*(offset+N*q)), y=ys+r*sin(2*pi*(offset+N*q)), z=zs+q*L

Todo:
IFCD: Can these details about class Screw be made more clear? I don't understand them.

Definition at line 38 of file Screw.h.

Constructor & Destructor Documentation

Screw::Screw ( )

Default constructor: make a screw with default parameters.

Make a Screw which is centered in the origin, has a length of 1, one revelation, a radius of 1, turns with 1 revelation per second, is infinitely thin and starts at its normal initial point.

Definition at line 37 of file Screw.cc.

References DEBUG, l_, logger, maxR_, n_, offset_, omega_, Vec3D::setZero(), start_, and thickness_.

Referenced by copy().

38 {
39  start_.setZero();
40  l_ = 1.0;
41  maxR_ = 1.0;
42  n_ = 1.0;
43  omega_ = 1.0;
44  offset_ = 0.0;
45  thickness_ = 0.0;
46  logger(DEBUG, "Screw() constructor finished.");
47 }
Mdouble maxR_
The outer radius of the Screw.
Definition: Screw.h:113
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setZero()
Sets all elements to zero.
Definition: Vector.cc:52
Vec3D start_
The centre of the lower end of the screw.
Definition: Screw.h:105
Mdouble offset_
The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation.
Definition: Screw.h:125
Mdouble l_
The length of the Screw.
Definition: Screw.h:109
Mdouble n_
The number of revelations.
Definition: Screw.h:117
Mdouble thickness_
The thickness of the Screw.
Definition: Screw.h:129
Mdouble omega_
Rotation speed in rev/s.
Definition: Screw.h:121
Screw::Screw ( const Screw other)

Copy constructor, copies another Screw.

Parameters
[in]otherThe Screw that has to be copied.

Definition at line 52 of file Screw.cc.

References DEBUG, l_, logger, maxR_, n_, offset_, omega_, start_, and thickness_.

53  : BaseWall(other)
54 {
55  start_ = other.start_;
56  l_ = other.l_;
57  maxR_ = other.maxR_;
58  n_ = other.n_;
59  omega_ = other.omega_;
60  thickness_ = other.thickness_;
61  offset_ = other.offset_;
62  logger(DEBUG, "Screw(const Screw&) copy constructor finished.");
63 }
Mdouble maxR_
The outer radius of the Screw.
Definition: Screw.h:113
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Vec3D start_
The centre of the lower end of the screw.
Definition: Screw.h:105
Mdouble offset_
The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation.
Definition: Screw.h:125
Mdouble l_
The length of the Screw.
Definition: Screw.h:109
BaseWall()
Default constructor. It makes an empty BaseWall.
Definition: BaseWall.cc:31
Mdouble n_
The number of revelations.
Definition: Screw.h:117
Mdouble thickness_
The thickness of the Screw.
Definition: Screw.h:129
Mdouble omega_
Rotation speed in rev/s.
Definition: Screw.h:121
Screw::Screw ( Vec3D  start,
Mdouble  l,
Mdouble  r,
Mdouble  n,
Mdouble  omega,
Mdouble  thickness 
)

Constructor in which all parameters of the screw are set.

Parameters
[in]startA Vec3D which denotes the centre of the lower end of the Screw.
[in]lThe length of the Screw, must be positive.
[in]rThe radius of the Screw, must be positive.
[in]nThe number of revelations of the Screw, must be positive.
[in]omegaThe rotation speed of the Screw in rev/s.
[in]thicknessThe thickness of the Screw, must be non-negative.

Make a Screw by assigning all input parameters to the data-members of this class, and setting the offset_ to 0.

Definition at line 75 of file Screw.cc.

References DEBUG, l_, logger, maxR_, n_, offset_, omega_, start_, and thickness_.

76 {
77  start_ = start;
78  l_ = l;
79  maxR_ = r;
80  n_ = n;
81  omega_ = omega;
82  thickness_ = thickness;
83  offset_ = 0.0;
84  logger(DEBUG, "Screw(Vec3D, Mdouble, Mdouble, Mdouble, Mdouble, Mdouble) constructor finished.");
85 }
Mdouble maxR_
The outer radius of the Screw.
Definition: Screw.h:113
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Vec3D start_
The centre of the lower end of the screw.
Definition: Screw.h:105
Mdouble offset_
The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation.
Definition: Screw.h:125
Mdouble l_
The length of the Screw.
Definition: Screw.h:109
Mdouble n_
The number of revelations.
Definition: Screw.h:117
Mdouble thickness_
The thickness of the Screw.
Definition: Screw.h:129
Mdouble omega_
Rotation speed in rev/s.
Definition: Screw.h:121
Screw::~Screw ( )

Default destructor.

Definition at line 87 of file Screw.cc.

References DEBUG, and logger.

88 {
89  logger(DEBUG, "~Screw() finished, destroyed the Screw.");
90 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")

Member Function Documentation

Screw * Screw::copy ( ) const
finalvirtual

Copy this screw and return a pointer to the copy.

Returns
A pointer to a copy of this Screw.

Implements BaseWall.

Definition at line 95 of file Screw.cc.

References Screw().

96 {
97  return new Screw(*this);
98 }
Screw()
Default constructor: make a screw with default parameters.
Definition: Screw.cc:37
bool Screw::getDistanceAndNormal ( const BaseParticle p,
Mdouble distance,
Vec3D normal_return 
) const
finalvirtual

Compute the distance from the Screw for a given BaseParticle and return if there is a collision. If there is a collision, also return the normal vector of the interaction point.

Parameters
[in]pBaseParticle we want to calculate the distance and whether it collided of.
[out]distanceThe distance of the BaseParticle to this wall.
[out]normal_returnIf there was a collision, the normal vector to this wall will be placed here.
Returns
A boolean which says whether or not there was a collision.

This function computes whether or not there is a collision between a given BaseParticle and this Screw. If there is a collision, this function also computes the distance between the BaseParticle and Screw and the normal of the IntersectionOfWalls at the intersection point.

Todo:
Make this function readable and explain the steps in the details.

Implements BaseWall.

Definition at line 111 of file Screw.cc.

References A, mathsFunc::cos(), BaseInteractable::getPosition(), BaseParticle::getWallInteractionRadius(), l_, maxR_, n_, Vec3D::normalize(), offset_, constants::pi, R, mathsFunc::sign(), mathsFunc::sin(), constants::sqr_pi, mathsFunc::square(), start_, thickness_, Vec3D::X, Vec3D::Y, Z, and Vec3D::Z.

112 {
113  Mdouble RSquared = square(p.getPosition().X - start_.X) + square(p.getPosition().Y - start_.Y);
114  Mdouble Z = p.getPosition().Z - start_.Z;
115  //first do a simple check if particle is within the cylindrical hull of the screw
116  if (RSquared > square(maxR_ + p.getWallInteractionRadius() + thickness_)
117  || Z > l_ + p.getWallInteractionRadius() + thickness_
118  || Z < - p.getWallInteractionRadius() - thickness_)
119  {
120  //std::cout << "failed " << p.getPosition() << std::endl;
121  return false;
122  }
123 
124  //else:
125  Mdouble R = sqrt(RSquared);
126  Mdouble A = atan2(p.getPosition().Y - start_.Y, p.getPosition().X - start_.X);
127 
128  //after subtracting the start position and transforming the particle position from (XYZ) into (RAZ)
129  //coordinates, we compute the distance to the wall at, located at (r,a,z)=(r,2*pi*(offset+N*q+k/2),q*L), 0<q<1.
130 
131  //To find the contact point we have to minimize (with respect to r and q)
132  //distance^2=(x-x0-r*cos(2*pi*(offset+N*q)))^2+(y-y0-r*sin(2*pi*(offset+N*q)))^2+(z-z0-q*L)^2
133  //Using polar coordinates (i.e. x-x0=R*cos(A), y-y0=R*sin(A) and Z=z-z0)
134  //distance^2=R^2+r^2-2*R*r*cos(A-2*pi*(offset+N*q))+(Z-q*L)^2
135 
136  //Assumption: d(distance)/dr=0 at minDistance (should there be also a q-derivative?)
137  //Differentiate with respect to r and solve for zero:
138  //0=2*r-2*R*cos(A-2*pi*(offset+N*q)
139  //r=R*cos(A-2*pi*(offset+N*q))
140 
141  //Substitue back
142  //distance^2=R^2+R^2*cos^2(A-2*pi*(offset+N*q))-2*R^2*cos^2(A-2*pi*(offset+N*q))+(Z-q*L)^2
143  //distance^2=R^2*sin^2(A-2*pi*(offset+N*q))+(Z-q*L)^2
144 
145  //So we have to minimize:
146  //distance^2=R^2*sin^2(A-2*pi*(offset+N*q))^2 + (Z-q*L)^2 = f(q)
147  //f'(q)=(-2*pi*N)*R^2*sin(2*A-4*pi*(offset+N*q)) + 2*L*(Z-q*L) (D[Sin[x]^2,x]=Sin[2x])
148  //f''(q)=(4*pi^2*N^2)*R^2*cos(2*A-4*pi*(offset+N*q)) - 2*L*L
149  //For this we use the Euler algoritm
150 
151  Mdouble q; //Current guess
152  Mdouble dd; //Derivative at current guess
153  Mdouble ddd; //Second derivative at current guess
154  Mdouble q0 = Z / l_; //assume closest point q0 is at same z-location as the particle
155 
156  //Set initial q to the closest position on the screw with the same angle as A
157  //The initial guess will be in the minimum of the sin closest to q0
158  //Minima of the sin are at
159  //A-2*pi*(offset+N*q)=k*pi (k=integer)
160  //q=A/(2*pi*N)-k/(2*N)-offset/N (k=integer)
161 
162  Mdouble k = round(A / constants::pi - 2.0 * (offset_ + n_ * q0)); // k: |A-a(q0)-k*pi|=min
163  q = A / (2.0 * constants::pi * n_) - k / (2.0 * n_) - offset_ / n_; // q: a(q)=A
164 
165  //Now apply Newton's method
166  do
167  {
168  Mdouble arg = 2.0 * A - 4.0 * constants::pi * (n_ * q + offset_);
169  dd = -2.0 * constants::pi * n_ * RSquared * sin(arg) - 2.0 * l_ * (Z - q * l_);
170  ddd = 8.0 * constants::sqr_pi * n_ * n_ * RSquared * cos(arg) + 2.0 * l_ * l_;
171  q -= dd / ddd;
172  } while (fabs(dd / ddd) > 1e-14);
173 
174  //Calculate r
175  Mdouble r = R * cos(2.0 * constants::pi * (offset_ + n_ * q) - A);
176 
177  //Check if the location is actually on the screw:
178  //First posibility is that the radius is too large:
179  if (fabs(r) > maxR_) //Left boundary of the coil
180  {
181  r = mathsFunc::sign(r) * maxR_;
182  unsigned int steps = 0;
183  //This case reduces to the coil problem
184  do
185  {
186  dd = -4.0 * R * r * constants::pi * n_ * sin(A - 2.0 * constants::pi * (n_ * q + offset_)) - 2.0 * l_ * (Z - q * l_);
187  ddd = 8.0 * R * r * constants::sqr_pi * n_ * n_ * cos(A - 2.0 * constants::pi * (n_ * q + offset_)) + 2.0 * l_ * l_;
188  q -= dd / ddd;
189  steps++;
190  } while (fabs(dd / ddd) > 1e-14);
191  }
192  //Second possibility is that it occured before the start of after the end
193  if (q < 0)
194  {
195  q = 0;
196  r = R * cos(A - 2.0 * constants::pi * (offset_ + q * n_));
197  if (fabs(r) > maxR_)
198  {
199  r = mathsFunc::sign(r) * maxR_;
200  }
201  }
202  else if (q > 1)
203  {
204  q = 1;
205  r = R * cos(A - 2.0 * constants::pi * (offset_ + q * n_));
206  if (fabs(r) > maxR_)
207  {
208  r = mathsFunc::sign(r) * maxR_;
209  }
210  }
211 
212  Mdouble distanceSquared = R * R * pow(sin(A - 2 * constants::pi * (offset_ + n_ * q)), 2) + pow(Z - q * l_, 2);
213  //If distance is too large there is no contact
214  if (distanceSquared >= square(p.getWallInteractionRadius() + thickness_))
215  {
216  return false;
217  }
218 
219  Vec3D ContactPoint;
220  distance = sqrt(distanceSquared) - thickness_;
221  ContactPoint.X = start_.X + r * cos(2.0 * constants::pi * (offset_ + n_ * q));
222  ContactPoint.Y = start_.Y + r * sin(2.0 * constants::pi * (offset_ + n_ * q));
223  ContactPoint.Z = start_.Z + q * l_;
224  normal_return = (ContactPoint - p.getPosition());
225  normal_return.normalize();
226  return true;
227 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble maxR_
The outer radius of the Screw.
Definition: Screw.h:113
void normalize()
Makes this Vec3D unit length.
Definition: Vector.cc:214
double Mdouble
int sign(T val)
This is a sign function, it returns -1 for negative numbers, 1 for positive numbers and 0 for 0...
Definition: ExtendedMath.h:83
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Mdouble getWallInteractionRadius() const
Returns the interaction radius for interaction with walls. See also BaseParticle::getInteractionRadiu...
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:60
Vec3D start_
The centre of the lower end of the screw.
Definition: Screw.h:105
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:42
Mdouble offset_
The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation.
Definition: Screw.h:125
const Mdouble pi
Definition: ExtendedMath.h:42
Mdouble l_
The length of the Screw.
Definition: Screw.h:109
Mdouble Y
Definition: Vector.h:52
Mdouble n_
The number of revelations.
Definition: Screw.h:117
Mdouble thickness_
The thickness of the Screw.
Definition: Screw.h:129
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
Mdouble Z
Definition: Vector.h:52
const Mdouble sqr_pi
Definition: ExtendedMath.h:44
std::string Screw::getName ( ) const
finalvirtual

Returns the name of the object, here the string "Screw".

Returns
The string "Screw".

Implements BaseObject.

Definition at line 288 of file Screw.cc.

Referenced by writeVTK().

289 {
290  return "Screw";
291 }
void Screw::getTriangulation ( std::vector< Vec3D > &  vertex,
std::vector< std::array< unsigned, 3 >> &  face,
unsigned  nr = 5,
unsigned  nz = 15 
) const

Definition at line 316 of file Screw.cc.

References mathsFunc::cos(), l_, maxR_, n_, offset_, constants::pi, mathsFunc::sin(), start_, Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by writeVTK().

317 {
318  //add vertices
319  vertices.reserve(nr*nz);
320  Vec3D vertex;
321  for (Mdouble iz=0; iz<nz; iz++) {
322  for (Mdouble ir=0; ir<nr; ir++) {
323  Mdouble q = iz/(nz-1); //angular direction
324  Mdouble r = ir/(nr-1)*maxR_;
325  vertex.X = start_.X - r * cos(2.0 * constants::pi * (offset_ + n_ * q));
326  vertex.Y = start_.Y - r * sin(2.0 * constants::pi * (offset_ + n_ * q));
327  vertex.Z = start_.Z + q * l_;
328  vertices.push_back(vertex);
329  }
330  }
331  //reserve space for faces
332  faces.reserve(2*(nr-1)*(nz-1));
333  std::array<unsigned,3> face;
334  for (unsigned iz=0; iz<nz-1; iz++) {
335  for (unsigned ir=0; ir<nr-1; ir++) {
336  //first face 0 1 nr
337  faces.push_back({iz*nr+ir,iz*nr+(ir+1),(iz+1)*nr+ir});
338  //second face 1 nr+1 nr
339  faces.push_back({iz*nr+(ir+1),(iz+1)*nr+(ir+1),(iz+1)*nr+ir});
340  }
341  }
342 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble maxR_
The outer radius of the Screw.
Definition: Screw.h:113
double Mdouble
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:60
Vec3D start_
The centre of the lower end of the screw.
Definition: Screw.h:105
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:42
Mdouble offset_
The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation.
Definition: Screw.h:125
const Mdouble pi
Definition: ExtendedMath.h:42
Mdouble l_
The length of the Screw.
Definition: Screw.h:109
Mdouble Y
Definition: Vector.h:52
Mdouble n_
The number of revelations.
Definition: Screw.h:117
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
Mdouble Z
Definition: Vector.h:52
void Screw::move_time ( Mdouble  dt)

Rotate the Screw for a period dt, so that the offset_ changes with omega_*dt.

Parameters
[in]dtThe time for which the Screw has to be turned.

Definition at line 232 of file Screw.cc.

References offset_, and omega_.

233 {
234  offset_ += omega_ * dt;
235 }
Mdouble offset_
The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation.
Definition: Screw.h:125
Mdouble omega_
Rotation speed in rev/s.
Definition: Screw.h:121
void Screw::oldRead ( std::istream &  is)

Reads a Screw in the old style from an input stream, for example a restart file old style.

Parameters
[in,out]isInput stream from which the Screw must be read.

Read the Screw in old style, please note that the thickness is not read in this function, so it has either to be set manually or it is 0.0 from the default constructor.

Definition at line 259 of file Screw.cc.

References l_, maxR_, n_, offset_, omega_, and start_.

260 {
261  std::string dummy;
262  is >> dummy >> start_
263  >> dummy >> l_
264  >> dummy >> maxR_
265  >> dummy >> n_
266  >> dummy >> omega_
267  >> dummy >> offset_;
268 }
Mdouble maxR_
The outer radius of the Screw.
Definition: Screw.h:113
Vec3D start_
The centre of the lower end of the screw.
Definition: Screw.h:105
Mdouble offset_
The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation.
Definition: Screw.h:125
Mdouble l_
The length of the Screw.
Definition: Screw.h:109
Mdouble n_
The number of revelations.
Definition: Screw.h:117
Mdouble omega_
Rotation speed in rev/s.
Definition: Screw.h:121
void Screw::read ( std::istream &  is)
overridevirtual

Reads a Screw from an input stream, for example a restart file.

Parameters
[in,out]isInput stream from which the Screw must be read.

Reimplemented from BaseWall.

Definition at line 240 of file Screw.cc.

References l_, maxR_, n_, offset_, omega_, BaseWall::read(), start_, and thickness_.

241 {
242  BaseWall::read(is);
243  std::string dummy;
244  is >> dummy >> start_
245  >> dummy >> l_
246  >> dummy >> maxR_
247  >> dummy >> n_
248  >> dummy >> omega_
249  >> dummy >> thickness_
250  >> dummy >> offset_;
251 }
Mdouble maxR_
The outer radius of the Screw.
Definition: Screw.h:113
Vec3D start_
The centre of the lower end of the screw.
Definition: Screw.h:105
Mdouble offset_
The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation.
Definition: Screw.h:125
Mdouble l_
The length of the Screw.
Definition: Screw.h:109
Mdouble n_
The number of revelations.
Definition: Screw.h:117
Mdouble thickness_
The thickness of the Screw.
Definition: Screw.h:129
Mdouble omega_
Rotation speed in rev/s.
Definition: Screw.h:121
void read(std::istream &is)
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:60
void Screw::write ( std::ostream &  os) const
overridevirtual

Writes this Screw to an output stream, for example a restart file.

Parameters
[in,out]osOutput stream to which the Screw must be written.

Reimplemented from BaseWall.

Definition at line 273 of file Screw.cc.

References l_, maxR_, n_, offset_, omega_, start_, thickness_, and BaseWall::write().

274 {
275  BaseWall::write(os);
276  os << " start " << start_
277  << " Length " << l_
278  << " Radius " << maxR_
279  << " Revolutions " << n_
280  << " Omega " << omega_
281  << " Thickness " << thickness_
282  << " Offset " << offset_;
283 }
Mdouble maxR_
The outer radius of the Screw.
Definition: Screw.h:113
Vec3D start_
The centre of the lower end of the screw.
Definition: Screw.h:105
Mdouble offset_
The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation.
Definition: Screw.h:125
Mdouble l_
The length of the Screw.
Definition: Screw.h:109
Mdouble n_
The number of revelations.
Definition: Screw.h:117
Mdouble thickness_
The thickness of the Screw.
Definition: Screw.h:129
Mdouble omega_
Rotation speed in rev/s.
Definition: Screw.h:121
void write(std::ostream &os) const
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: BaseWall.cc:68
void Screw::writeVTK ( std::string  filename) const

Definition at line 293 of file Screw.cc.

References getName(), getTriangulation(), and helpers::writeToFile().

294 {
295  std::vector<Vec3D> vertices;
296  std::vector<std::array<unsigned,3>> faces;
297  getTriangulation (vertices, faces);
298 
299  std::stringstream file;
300  file << "# vtk DataFile Version 2.0\n"
301  << getName() << "\n"
302  "ASCII\n"
303  "DATASET UNSTRUCTURED_GRID\n"
304  "POINTS " << vertices.size() << " double\n";
305  for (const auto& vertex : vertices)
306  file << vertex << '\n';
307  file << "\nCELLS " << faces.size() << ' ' << 4*faces.size() << "\n";
308  for (const auto& face : faces)
309  file << "3 " << face[0] << ' ' << face[1] << ' ' << face[2] << '\n';
310  file << "\nCELL_TYPES " << faces.size() << "\n";
311  for (const auto& face : faces)
312  file << "5\n";
313  helpers::writeToFile(filename,file.str());
314 }
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Definition: Helpers.cc:418
void getTriangulation(std::vector< Vec3D > &vertex, std::vector< std::array< unsigned, 3 >> &face, unsigned nr=5, unsigned nz=15) const
Definition: Screw.cc:316
std::string getName() const final
Returns the name of the object, here the string "Screw".
Definition: Screw.cc:288

Member Data Documentation

Mdouble Screw::l_
private

The length of the Screw.

Definition at line 109 of file Screw.h.

Referenced by getDistanceAndNormal(), getTriangulation(), oldRead(), read(), Screw(), and write().

Mdouble Screw::maxR_
private

The outer radius of the Screw.

Definition at line 113 of file Screw.h.

Referenced by getDistanceAndNormal(), getTriangulation(), oldRead(), read(), Screw(), and write().

Mdouble Screw::n_
private

The number of revelations.

Definition at line 117 of file Screw.h.

Referenced by getDistanceAndNormal(), getTriangulation(), oldRead(), read(), Screw(), and write().

Mdouble Screw::offset_
private

The angle that describes how much the Screw has turned, going from 0 to 1 for a rotation.

Definition at line 125 of file Screw.h.

Referenced by getDistanceAndNormal(), getTriangulation(), move_time(), oldRead(), read(), Screw(), and write().

Mdouble Screw::omega_
private

Rotation speed in rev/s.

Definition at line 121 of file Screw.h.

Referenced by move_time(), oldRead(), read(), Screw(), and write().

Vec3D Screw::start_
private

The centre of the lower end of the screw.

Definition at line 105 of file Screw.h.

Referenced by getDistanceAndNormal(), getTriangulation(), oldRead(), read(), Screw(), and write().

Mdouble Screw::thickness_
private

The thickness of the Screw.

Definition at line 129 of file Screw.h.

Referenced by getDistanceAndNormal(), read(), Screw(), and write().


The documentation for this class was generated from the following files: