MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MixedSpecies.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 MIXEDSPECIES_H
27 #define MIXEDSPECIES_H
31 class BaseInteraction;
32 
39 template<class NormalForceSpecies, class FrictionForceSpecies = EmptyFrictionSpecies, class AdhesiveForceSpecies = EmptyAdhesiveSpecies>
41 {
42 public:
43 
45  MixedSpecies();
46 
48  MixedSpecies(const MixedSpecies &s);
49 
52 
54  virtual ~MixedSpecies();
55 
60 
62  void read(std::istream& is);
63 
65  void write(std::ostream& os) const;
66 
68  std::string getName() const;
69 
75 
79  bool getUseAngularDOFs() const;
80 
85  void mixAll(BaseSpecies * const S, BaseSpecies * const T);
86 
89 };
90 
91 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
94 {
95 #ifdef DEBUG_CONSTRUCTOR
96  std::cout << "MixedSpecies::MixedSpecies() finished" << std::endl;
97 #endif
98 }
99 
100 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
103 {
104 #ifdef DEBUG_CONSTRUCTOR
105  std::cout << "MixedSpecies::MixedSpecies(const MixedSpecies &p) finished" << std::endl;
106 #endif
107 }
108 
109 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
112 {
113 #ifdef DEBUG_CONSTRUCTOR
114  std::cout << "MixedSpecies::MixedSpecies(const MixedSpecies &p) finished" << std::endl;
115 #endif
116 }
117 
118 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
120 {
121 #ifdef DEBUG_DESTRUCTOR
122  std::cout << "MixedSpecies::~MixedSpecies() finished" << std::endl;
123 #endif
124 }
125 
127 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
129 ::copy() const
130 {
131  return new MixedSpecies(*this);
132 }
133 
141 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
143 ::write(std::ostream& os) const
144 {
145  os << getName();
146  os << " idA " << BaseObject::getId();
147  os << " idB " << BaseObject::getIndex();
148  NormalForceSpecies::write(os);
149  FrictionForceSpecies::write(os);
150  AdhesiveForceSpecies::write(os);
151 }
152 
157 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
159 ::read(std::istream& is)
160 {
161  //note: name is already read by SpeciesHandler::readObject
162  std::string dummy;
163  unsigned int id, index;
164  is >> dummy >> id;
165  is >> dummy >> index;
166  BaseObject::setId(id);
167  BaseObject::setIndex(index);
168  NormalForceSpecies::read(is);
169  FrictionForceSpecies::read(is);
170  AdhesiveForceSpecies::read(is);
171 }
172 
187 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
189 {
190  return NormalForceSpecies::getBaseName()
191  + FrictionForceSpecies::getBaseName()
192  + AdhesiveForceSpecies::getBaseName() + "MixedSpecies";
193 }
194 
203 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
205 {
207 }
208 
215 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
217 {
218  return FrictionForceSpecies::getUseAngularDOFs();
219 }
220 
227 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
229 {
230  if (dynamic_cast<NormalForceSpecies*> (T) ==NULL||
231  dynamic_cast<FrictionForceSpecies*> (T) ==NULL||
232  dynamic_cast<AdhesiveForceSpecies*> (T) ==NULL) {
233  std::cerr << "Warning: cannot mix two species of different type; the mixed species is an empty species of the same type as the second species instead" << std::endl;
234  return;
235  }
236  NormalForceSpecies::mix(dynamic_cast<NormalForceSpecies*> (S), dynamic_cast<NormalForceSpecies*> (T));
237  FrictionForceSpecies::mix(dynamic_cast<FrictionForceSpecies*> (S), dynamic_cast<FrictionForceSpecies*> (T));
238  AdhesiveForceSpecies::mix(dynamic_cast<AdhesiveForceSpecies*> (S), dynamic_cast<AdhesiveForceSpecies*> (T));
239 }
240 
242 
243 template<class NormalForceSpecies, class FrictionForceSpecies, class AdhesiveForceSpecies>
245 {
246  return AdhesiveForceSpecies::getInteractionDistance();
247 }
248 #endif
void setIndex(const unsigned int index)
Allows one to assign an index to an object in the handler/container.
Definition: BaseObject.cc:91
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.cc:116
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:108
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:44
Defines a contact force orthogonal to the contact normal.
Defines a contact force parallel to the contact normal.
double Mdouble
void mixAll(BaseSpecies *const S, BaseSpecies *const T)
sets the MixedSpecies properties by mixing the properties of two particle species ...
Definition: MixedSpecies.h:228
Stores information about interactions between two interactable objects; often particles but could be ...
Defines a short-range (non-contact) force parallel to the contact normal, usually adhesive...
MixedSpecies()
The default constructor.
Definition: MixedSpecies.h:92
void setId(const unsigned int id)
Assigns a unique identifier to each object in the handler (container) which remains constant even aft...
Definition: BaseObject.cc:99
Mdouble getInteractionDistance() const
Returns the particle distance below which adhesive forces can occur (needed for contact detection) ...
Definition: MixedSpecies.h:244
MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies > * copy() const
Creates a deep copy of the MixedSpecies from which it is called.
Definition: MixedSpecies.h:129
void read(std::istream &is)
Reads the species properties from an input stream.
Definition: MixedSpecies.h:159
Contains contact force properties for contacts between particles with two different species...
Definition: MixedSpecies.h:40
Defines the basic properties that a interactable object can have.
std::string getName() const
Returns the name of the MixedSpecies as it is used in the restart file.
Definition: MixedSpecies.h:188
Contains material and contact force properties.
Definition: Interaction.h:35
BaseInteraction * getNewInteraction(BaseInteractable *P, BaseInteractable *I, Mdouble timeStamp) const
When a contact between two particles is determined, an Interaction object is created, as the type of Interaction depends on the MixedSpecies type.
Definition: MixedSpecies.h:204
virtual ~MixedSpecies()
The default destructor.
Definition: MixedSpecies.h:119
void write(std::ostream &os) const
Writes the MixedSpecies properties to an output stream.
Definition: MixedSpecies.h:143
Contains information about the contact between two interactables, BaseInteraction::P_ and BaseInterac...
Definition: Interaction.h:107
bool getUseAngularDOFs() const
Returns true if torques have to be calculated.
Definition: MixedSpecies.h:216