HG-MD
1
|
00001 #ifndef CDeltaMax_H 00002 #define CDeltaMax_H 00003 00004 #include "Vector.h" 00005 #include <algorithm> 00006 #include <vector> 00007 #include <iostream> 00008 #include <iomanip> 00009 00010 using namespace std; 00011 00012 class CWall; 00013 class Particle; 00014 00017 class CDeltaMax { 00018 public: 00020 CDeltaMax() {delta=0; pParticle=-1; pWall=-1; time=-1;} 00021 00022 CDeltaMax(Mdouble delta_, int pParticle_, int pWall_, Mdouble time_) { 00023 delta = delta_; 00024 pParticle = pParticle_; 00025 pWall = pWall_; 00026 time = time_; 00027 } 00028 00030 CDeltaMax (const CDeltaMax &ts) { 00031 delta = ts.delta; 00032 pParticle = ts.pParticle; 00033 pWall = ts.pWall; 00034 time = ts.time; 00035 } 00036 00038 void print(std::ostream& os) { 00039 os << "delta:" << delta 00040 << ", particle:" << pParticle 00041 << ", wall:" << pWall 00042 << ", time:" << time; 00043 } 00044 00046 friend inline std::ostream& operator<<(std::ostream& os, const CDeltaMax &p) 00047 { 00048 os << p.delta << " " << p.pParticle << " " << p.pWall << " " << p.time; 00049 return os; 00050 } 00051 00053 friend inline std::istream& operator>>(std::istream& is, CDeltaMax &p) 00054 { 00055 is >> p.delta >> p.pParticle >> p.pWall >> p.time; 00056 return is; 00057 } 00058 00059 //member variables 00060 00062 Mdouble delta; 00064 int pParticle; 00066 int pWall; 00068 Mdouble time; 00069 }; 00070 00079 class CDeltaMaxs : public vector<CDeltaMax> { 00080 public: 00082 struct check_spring_time : public binary_function<CDeltaMax,Mdouble,bool> 00083 { 00084 bool operator() (const CDeltaMax a, const Mdouble b) const {return(a.time<b);} 00085 }; 00086 00088 Mdouble* select_particle(int P, Mdouble time_, Mdouble dt) { 00089 //Remove_if reconstructs the vector with only elements passing the check_spring_time function 00090 //Erase removes the end of the vector 00091 erase(remove_if(begin(),end(),bind2nd(check_spring_time(),time_)),end()); 00092 00093 //Loops over all Springs ant returns the correct one (if it exists) 00094 for (CDeltaMaxs::iterator it=begin(); it!=end();it++){ 00095 if (it->pParticle==P) 00096 { 00097 it->time=time_+dt; 00098 return &it->delta; 00099 } 00100 } 00101 00102 //if not, create it 00103 push_back(CDeltaMax(0,P,-1,time_+dt)); 00104 return &back().delta; 00105 } 00106 00108 Mdouble* select_wall(int W, Mdouble time_, Mdouble dt) { 00109 //Remove_if reconstructs the vector with only elements passing the check_spring_time function 00110 //Erase removes the end of the vector 00111 erase(remove_if(begin(),end(),bind2nd(check_spring_time(),time_)),end()); 00112 00113 //Loops over all Springs ant returns the correct one (if it exists) 00114 for (CDeltaMaxs::iterator it=begin(); it!=end(); it++) 00115 { 00116 if (it->pWall==W) 00117 { 00118 it->time=time_+dt; 00119 return &it->delta; 00120 } 00121 } 00122 00123 //if not, create it 00124 push_back(CDeltaMax(0,-1,W,time_+dt)); 00125 return &back().delta; 00126 } 00127 00129 void reset() { 00130 clear(); 00131 reserve(13); 00132 } 00133 00135 void print(std::ostream& os, Mdouble time_) { 00136 os << "Delta max's: N=" << size() << endl; 00137 for (CDeltaMaxs::iterator it=begin(); it!=end(); it++) 00138 if (it->time>=time_) { 00139 it->print(os); os << endl; 00140 } 00141 } 00142 00143 public: 00145 friend inline std::ostream& operator<<(std::ostream& os, const CDeltaMaxs &p) 00146 { 00147 os << p.size() << " "; 00148 for (unsigned int i=0; i<p.size(); i++) os << p[i] << " "; 00149 return os; 00150 } 00151 00153 friend inline std::istream& operator>>(std::istream& is, CDeltaMaxs &p) 00154 { 00155 int n; is >> n; p.resize(n); 00156 for (unsigned int i=0; i<p.size(); i++) is >> p[i]; 00157 return is; 00158 } 00159 00160 }; 00161 00162 #endif