MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseInteractable.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 BASEINTERACTABLE_H
27 #define BASEINTERACTABLE_H
28 
29 #include <list>
30 #include <functional>
31 
32 #include "BaseObject.h"
33 #include "Math/Vector.h"
34 #include <vector>
35 
36 class BaseParticle;
37 class ParticleSpecies;
38 class BaseInteraction;
39 class InteractionHandler;
52 {
53 public:
59 
65 
70  virtual ~BaseInteractable();
71 
75  virtual void read(std::istream& is) = 0;
76 
81  virtual void write(std::ostream& os) const = 0;
82 
86  unsigned int getIndSpecies() const;
87 
91  virtual void setIndSpecies(unsigned int indSpecies);
92 
96  const ParticleSpecies* getSpecies() const;
97 
101  void setSpecies(const ParticleSpecies* species);
102 
106  const Vec3D& getForce() const;
107 
111  const Vec3D& getTorque() const;
112 
116  void setForce(const Vec3D& force);
117 
121  void setTorque(const Vec3D& torque);
122 
126  void addForce(const Vec3D& addForce);
127 
131  void addTorque(const Vec3D& addTorque);
132 
136  const Vec3D& getPosition() const;
137 
141  const Vec3D& getOrientation() const;
142 
146  void setPosition(const Vec3D& position);
147 
151  void setOrientation(const Vec3D& orientation);
152 
156  virtual void move(const Vec3D& move);
157 
161  void rotate(const Vec3D& rotate);
162 
166  const std::list<BaseInteraction*>& getInteractions() const;
167 
172 
177 
183 
187  void setVelocity(const Vec3D& velocity);
188 
192  void setAngularVelocity(const Vec3D& angularVelocity);
193 
197  void addVelocity(const Vec3D& velocity);
198 
202  void addAngularVelocity(const Vec3D& angularVelocity);
203 
207  virtual const Vec3D& getVelocity() const;
208 
212  virtual const Vec3D& getAngularVelocity() const;
213 
218  void setPrescribedPosition(const std::function<Vec3D (double)>& prescribedPosition);
219 
224  void applyPrescribedPosition(double time);
225 
230  void setPrescribedVelocity(const std::function<Vec3D (double)>& prescribedVelocity);
231 
236  void applyPrescribedVelocity(double time);
237 
242  void setPrescribedOrientation(const std::function<Vec3D (double)>& prescribedOrientation);
243 
248  void applyPrescribedOrientation(double time);
249 
254  void setPrescribedAngularVelocity(const std::function<Vec3D (double)>& prescribedAngularVelocity);
255 
260  void applyPrescribedAngularVelocity(double time);
261 
268  virtual std::vector<BaseInteraction*> getInteractionWith(BaseParticle *P, Mdouble timeStamp, InteractionHandler* interactionHandler)=0;
269 
273  virtual const Vec3D getVelocityAtContact(const Vec3D& contact) const;
274 
278  void integrateBeforeForceComputation(double time, double timeStep);
279 
284  void integrateAfterForceComputation(double time, double timeStep);
285 
286 private:
291  std::function<Vec3D (double)> prescribedPosition_;
292 
297  std::function<Vec3D (double)> prescribedVelocity_;
298 
303  std::function<Vec3D (double)> prescribedOrientation_;
304 
309  std::function<Vec3D (double)> prescribedAngularVelocity_;
310 
316 
322 
327 
332 
337 
343 
347  unsigned int indSpecies_;
348 
353 
357  std::list<BaseInteraction*> interactions_;
358 };
359 
360 #include <SpeciesHandler.h>
361 #endif
362 
void setPrescribedVelocity(const std::function< Vec3D(double)> &prescribedVelocity)
Allows the velocity of an infinite mass interactable to be prescribed.
void rotate(const Vec3D &rotate)
Rotates this BaseInteractable.
std::function< Vec3D(double)> prescribedPosition_
void addVelocity(const Vec3D &velocity)
adds an increment to the velocity.
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
unsigned int indSpecies_
void applyPrescribedPosition(double time)
Computes the position from the user defined prescribed position function.
const Vec3D & getForce() const
Returns the force on this BaseInteractable.
void addForce(const Vec3D &addForce)
Adds an amount to the force on this BaseInteractable.
std::function< Vec3D(double)> prescribedVelocity_
void setOrientation(const Vec3D &orientation)
Sets the orientation of this BaseInteractable.
bool removeInteraction(BaseInteraction *I)
Removes an interaction from this BaseInteractable.
void addInteraction(BaseInteraction *I)
Adds an interaction to this BaseInteractable.
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void applyPrescribedAngularVelocity(double time)
Computes the angular velocity from the user defined prescribed angular velocity.
It is an abstract base class due to the purely virtual functions declared below. Even if the function...
Definition: BaseObject.h:49
void setPrescribedAngularVelocity(const std::function< Vec3D(double)> &prescribedAngularVelocity)
Allows the angular velocity of the infinite mass interactable to be prescribed.
virtual const Vec3D getVelocityAtContact(const Vec3D &contact) const
Returns the velocity at the contact point, use by many force laws.
double Mdouble
void applyPrescribedOrientation(double time)
Computes the orientation from the user defined prescribed orientation function.
void integrateBeforeForceComputation(double time, double timeStep)
This is part of integrate routine for objects with infinite mass.
virtual const Vec3D & getAngularVelocity() const
Returns the angular velocity of this interactable.
virtual ~BaseInteractable()
Destructor, it simply destructs the BaseInteractable and all the objects it contains.
virtual std::vector< BaseInteraction * > getInteractionWith(BaseParticle *P, Mdouble timeStamp, InteractionHandler *interactionHandler)=0
Returns the interaction between this object and a given BaseParticle.
void setPrescribedPosition(const std::function< Vec3D(double)> &prescribedPosition)
Allows the position of an infinite mass interactable to be prescribed.
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
const Vec3D & getOrientation() const
Returns the orientation of this BaseInteractable.
Stores information about interactions between two interactable objects; often particles but could be ...
void addAngularVelocity(const Vec3D &angularVelocity)
add an increment to the angular velocity.
void setSpecies(const ParticleSpecies *species)
Sets the species of this BaseInteractable.
virtual void read(std::istream &is)=0
Reads a BaseInteractable from an input stream.
const ParticleSpecies * species_
Container to store Interaction objects.
const Vec3D & getTorque() const
Returns the torque on this BaseInteractable.
std::list< BaseInteraction * > interactions_
std::function< Vec3D(double)> prescribedOrientation_
void copyInteractionsForPeriodicParticles(const BaseInteractable &p)
Copies interactions to this BaseInteractable whenever a periodic copy made.
virtual void setIndSpecies(unsigned int indSpecies)
Sets the index of the Species of this BaseInteractable.
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
void applyPrescribedVelocity(double time)
Computes the velocity from the user defined prescribed velocity function.
void setForce(const Vec3D &force)
Sets the force on this BaseInteractable.
void setTorque(const Vec3D &torque)
Sets the torque on this BaseInteractable.
Defines the basic properties that a interactable object can have.
void addTorque(const Vec3D &addTorque)
Adds an amount to the torque on this BaseInteractable.
std::function< Vec3D(double)> prescribedAngularVelocity_
const std::list< BaseInteraction * > & getInteractions() const
Returns a reference to the list of interactions in this BaseInteractable.
unsigned int getIndSpecies() const
Returns the index of the Species of this BaseInteractable.
virtual void write(std::ostream &os) const =0
Write a BaseInteractable to an output stream.
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
virtual void move(const Vec3D &move)
Moves this BaseInteractable by adding an amount to the position.
void setPrescribedOrientation(const std::function< Vec3D(double)> &prescribedOrientation)
Allows the orientation of the infinite mass interactbale to be prescribed.
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
BaseInteractable()
Default BaseInteractable constructor, it simply creates an empty BaseInteractable.
void integrateAfterForceComputation(double time, double timeStep)
This is part of the integration routine for objects with infinite mass.