MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CDeltaMax.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 CDeltaMax_H
27 #define CDeltaMax_H
28 
29 #include "Vector.h"
30 #include <algorithm>
31 #include <vector>
32 #include <iostream>
33 #include <iomanip>
34 
35 class CWall;
36 class Particle;
37 
40 class CDeltaMax {
41 public:
43  CDeltaMax() {delta=0; pParticle=-1; pWall=-1; time=-1;}
44 
45  CDeltaMax(Mdouble delta_, int pParticle_, int pWall_, Mdouble time_) {
46  delta = delta_;
47  pParticle = pParticle_;
48  pWall = pWall_;
49  time = time_;
50  }
51 
53  CDeltaMax (const CDeltaMax &ts) {
54  delta = ts.delta;
55  pParticle = ts.pParticle;
56  pWall = ts.pWall;
57  time = ts.time;
58  }
59 
61  void print(std::ostream& os) {
62  os << "delta:" << delta
63  << ", particle:" << pParticle
64  << ", wall:" << pWall
65  << ", time:" << time;
66  }
67 
69  friend inline std::ostream& operator<<(std::ostream& os, const CDeltaMax &p)
70  {
71  os << p.delta << " " << p.pParticle << " " << p.pWall << " " << p.time;
72  return os;
73  }
74 
76  friend inline std::istream& operator>>(std::istream& is, CDeltaMax &p)
77  {
78  is >> p.delta >> p.pParticle >> p.pWall >> p.time;
79  return is;
80  }
81 
82 //member variables
83 
87  int pParticle;
89  int pWall;
92 };
93 
102 class CDeltaMaxs : public std::vector<CDeltaMax> {
103 public:
105  struct check_spring_time : public std::binary_function<CDeltaMax,Mdouble,bool>
106  {
107  bool operator() (const CDeltaMax a, const Mdouble b) const {return(a.time<b);}
108  };
109 
111  Mdouble* select_particle(int P, Mdouble time_, Mdouble dt) {
112  //Remove_if reconstructs the vector with only elements passing the check_spring_time function
113  //Erase removes the end of the vector
114  erase(remove_if(begin(),end(),bind2nd(check_spring_time(),time_)),end());
115 
116  //Loops over all Springs ant returns the correct one (if it exists)
117  for (CDeltaMaxs::iterator it=begin(); it!=end();it++){
118  if (it->pParticle==P)
119  {
120  it->time=time_+dt;
121  return &it->delta;
122  }
123  }
124 
125  //if not, create it
126  push_back(CDeltaMax(0,P,-1,time_+dt));
127  return &back().delta;
128  }
129 
131  Mdouble* select_wall(int W, Mdouble time_, Mdouble dt) {
132  //Remove_if reconstructs the vector with only elements passing the check_spring_time function
133  //Erase removes the end of the vector
134  erase(remove_if(begin(),end(),bind2nd(check_spring_time(),time_)),end());
135 
136  //Loops over all Springs ant returns the correct one (if it exists)
137  for (CDeltaMaxs::iterator it=begin(); it!=end(); it++)
138  {
139  if (it->pWall==W)
140  {
141  it->time=time_+dt;
142  return &it->delta;
143  }
144  }
145 
146  //if not, create it
147  push_back(CDeltaMax(0,-1,W,time_+dt));
148  return &back().delta;
149  }
150 
152  void reset() {
153  clear();
154  reserve(13);
155  }
156 
158  void print(std::ostream& os, Mdouble time_) {
159  os << "Delta max's: N=" << size() << std::endl;
160  for (CDeltaMaxs::iterator it=begin(); it!=end(); it++)
161  if (it->time>=time_) {
162  it->print(os); os << std::endl;
163  }
164  }
165 
166 public:
168  friend inline std::ostream& operator<<(std::ostream& os, const CDeltaMaxs &p)
169  {
170  os << p.size();
171  for (unsigned int i=0; i<p.size(); i++) os <<" "<< p[i];
172  return os;
173  }
174 
176  friend inline std::istream& operator>>(std::istream& is, CDeltaMaxs &p)
177  {
178  int n; is >> n; p.resize(n);
179  for (unsigned int i=0; i<p.size(); i++) is >> p[i];
180  return is;
181  }
182 
183 };
184 
185 #endif
Construction required for the erase/remove_if stuff.
Definition: CDeltaMax.h:105
friend std::istream & operator>>(std::istream &is, CDeltaMaxs &p)
reads all springs
Definition: CDeltaMax.h:176
void reset()
Resets the tangential springs.
Definition: CDeltaMax.h:152
friend std::istream & operator>>(std::istream &is, CDeltaMax &p)
reads spring
Definition: CDeltaMax.h:76
friend std::ostream & operator<<(std::ostream &os, const CDeltaMax &p)
writes spring
Definition: CDeltaMax.h:69
Mdouble * select_particle(int P, Mdouble time_, Mdouble dt)
Function selects the tangential spring vector for particle-particle interations (also removed not use...
Definition: CDeltaMax.h:111
bool operator()(const CDeltaMax a, const Mdouble b) const
Definition: CDeltaMax.h:107
CDeltaMax(Mdouble delta_, int pParticle_, int pWall_, Mdouble time_)
Definition: CDeltaMax.h:45
Mdouble * select_wall(int W, Mdouble time_, Mdouble dt)
Function selects the tangential spring vector for particle-wall interations.
Definition: CDeltaMax.h:131
double Mdouble
Definition: ExtendedMath.h:33
friend std::ostream & operator<<(std::ostream &os, const CDeltaMaxs &p)
writes all springs
Definition: CDeltaMax.h:168
CDeltaMax()
constructors
Definition: CDeltaMax.h:43
void print(std::ostream &os, Mdouble time_)
outputs all current active tangential springs
Definition: CDeltaMax.h:158
void print(std::ostream &os)
outputs tangential spring
Definition: CDeltaMax.h:61
int pParticle
A pointer to the particle in contact; NULL if the contact is with a wall (The other particle is the p...
Definition: CDeltaMax.h:87
int pWall
A pointer to the wall in contact; NULL if the contact is with a particle (The other particle is the p...
Definition: CDeltaMax.h:89
CDeltaMax(const CDeltaMax &ts)
copy constructor
Definition: CDeltaMax.h:53
Mdouble time
stores the last time the history parameter was read (if it was not read during the last timestep...
Definition: CDeltaMax.h:91
Stores the history parameter needed for a plastic force.
Definition: CDeltaMax.h:40
Member variable of #Particle storing all history parameters of a particle.
Definition: CDeltaMax.h:102
Mdouble delta
The maximum overlap on which the repellant spring strength is based.
Definition: CDeltaMax.h:85