ESyS-Particle  2.3.4
Contact.h
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-2017 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.apache.org/licenses/LICENSE-2.0 //
10 // //
12 
13 #ifndef ESYS_LSMCONTACT_H
14 #define ESYS_LSMCONTACT_H
15 
16 #include "Foundation/vec3.h"
17 
18 #include <math.h>
19 #include <iostream>
20 
21 namespace esys
22 {
23  namespace lsm
24  {
26  {
27  public:
29  {
30  }
31 
32  ParticleData(const Vec3 &pos, double rad) : m_pos(pos), m_rad(rad)
33  {
34  }
35 
36  bool operator==(const ParticleData &pd) const
37  {
38  return ((getPos() == pd.getPos()) && (getRad() == pd.getRad()));
39  }
40 
41  const Vec3 &getPos() const
42  {
43  return m_pos;
44  }
45 
46  const double &getRad() const
47  {
48  return m_rad;
49  }
50 
51  static bool is3d()
52  {
53  return s_is3d;
54  }
55 
56  static bool is2d()
57  {
58  return !s_is3d;
59  }
60 
61  static bool is3d(bool is3d)
62  {
63  s_is3d = is3d;
64  return s_is3d;
65  }
66 
67  static const double FOUR_THIRDS_PI;
68  double getVolume() const
69  {
70  return
71  (
72  is3d()
73  ?
75  :
76  M_PI*getRad()*getRad()
77  );
78  }
79 
80  void read(std::istream &iStream)
81  {
82  iStream >> m_pos >> m_rad;
83  }
84 
85  void write(std::ostream &oStream) const
86  {
87  oStream
88  << m_pos << " "
89  << m_rad;
90  }
91 
92  private:
94  double m_rad;
95 
96  static bool s_is3d;
97  };
98  }
99 }
100 
101 namespace std {
102 inline std::istream &operator>>(std::istream &iStream, esys::lsm::ParticleData &pd)
103 {
104  pd.read(iStream);
105  return iStream;
106 }
107 
108 inline std::ostream &operator<<(std::ostream &oStream, const esys::lsm::ParticleData &pd)
109 {
110  pd.write(oStream);
111  return oStream;
112 }
113 }
114 
115 namespace esys
116 {
117  namespace lsm
118  {
119  class Contact
120  {
121  public:
123  {
124  }
125 
127  const ParticleData &pd1,
128  const ParticleData &pd2,
129  const Vec3 &forcePos,
130  const Vec3 &force
131  )
132  : m_pd1(pd1),
133  m_pd2(pd2),
134  m_forcePos(forcePos),
135  m_force(force)
136  {
137  }
138 
139  Contact(const Contact &data)
140  : m_pd1(data.getParticle1()),
141  m_pd2(data.getParticle2()),
142  m_forcePos(data.getForcePos()),
143  m_force(data.getForce())
144  {
145  }
146 
147  const ParticleData &getParticle1() const
148  {
149  return m_pd1;
150  }
151 
152  const ParticleData &getParticle2() const
153  {
154  return m_pd2;
155  }
156 
157  const Vec3 &getCentrePos1() const
158  {
159  return getParticle1().getPos();
160  }
161 
162  double getVolume1() const
163  {
164  return getParticle1().getVolume();
165  }
166 
167  const Vec3 &getCentrePos2() const
168  {
169  return getParticle2().getPos();
170  }
171 
172  double getVolume2() const
173  {
174  return getParticle2().getVolume();
175  }
176 
177  const Vec3 &getForcePos() const
178  {
179  return m_forcePos;
180  }
181 
182  const Vec3 &getForce() const
183  {
184  return m_force;
185  }
186 
187  bool operator==(const Contact &data) const
188  {
189  return
190  (
191  (m_pd1 == data.m_pd1)
192  &&
193  (m_pd2 == data.m_pd2)
194  &&
195  (m_forcePos == data.m_forcePos)
196  &&
197  (m_force == data.m_force)
198  );
199  }
200 
201  void write(std::ostream &oStream) const
202  {
203  oStream
204  << m_pd1 << " "
205  << m_pd2 << " "
206  << m_forcePos << " "
207  << m_force;
208  }
209 
210  void read(std::istream &iStream)
211  {
212  iStream
213  >> m_pd1
214  >> m_pd2
215  >> m_forcePos
216  >> m_force;
217  }
218 
219  private:
224  };
225  }
226 }
227 
228 inline std::istream &operator>>(std::istream &iStream, esys::lsm::Contact &contact)
229 {
230  contact.read(iStream);
231  return iStream;
232 }
233 
234 inline std::ostream &operator<<(std::ostream &oStream, const esys::lsm::Contact &contact)
235 {
236  contact.write(oStream);
237  return oStream;
238 }
239 
240 #endif
esys::lsm::Contact::getForce
const Vec3 & getForce() const
Definition: Contact.h:182
operator>>
std::istream & operator>>(std::istream &iStream, esys::lsm::Contact &contact)
Definition: Contact.h:228
esys::lsm::ParticleData::s_is3d
static bool s_is3d
Definition: Contact.h:96
esys::lsm::Contact::getForcePos
const Vec3 & getForcePos() const
Definition: Contact.h:177
esys::lsm::ParticleData::getRad
const double & getRad() const
Definition: Contact.h:46
esys::lsm::Contact::m_force
Vec3 m_force
Definition: Contact.h:223
esys::lsm::ParticleData::ParticleData
ParticleData()
Definition: Contact.h:28
esys::lsm::Contact::write
void write(std::ostream &oStream) const
Definition: Contact.h:201
esys::lsm::Contact::getCentrePos2
const Vec3 & getCentrePos2() const
Definition: Contact.h:167
esys::lsm::Contact::m_pd2
ParticleData m_pd2
Definition: Contact.h:221
esys::lsm::Contact::Contact
Contact(const Contact &data)
Definition: Contact.h:139
esys::lsm::Contact::getVolume1
double getVolume1() const
Definition: Contact.h:162
esys::lsm::ParticleData::write
void write(std::ostream &oStream) const
Definition: Contact.h:85
esys::lsm::ParticleData
Definition: Contact.h:26
esys::lsm::ParticleData::m_rad
double m_rad
Definition: Contact.h:94
esys::lsm::Contact::m_forcePos
Vec3 m_forcePos
Definition: Contact.h:222
esys::lsm::Contact::getCentrePos1
const Vec3 & getCentrePos1() const
Definition: Contact.h:157
esys::lsm::ParticleData::m_pos
Vec3 m_pos
Definition: Contact.h:93
esys::lsm::Contact::read
void read(std::istream &iStream)
Definition: Contact.h:210
esys::lsm::ParticleData::getPos
const Vec3 & getPos() const
Definition: Contact.h:41
esys::lsm::ParticleData::is3d
static bool is3d(bool is3d)
Definition: Contact.h:61
esys::lsm::Contact::Contact
Contact(const ParticleData &pd1, const ParticleData &pd2, const Vec3 &forcePos, const Vec3 &force)
Definition: Contact.h:126
esys::lsm::ParticleData::is3d
static bool is3d()
Definition: Contact.h:51
esys
Definition: CheckPointable.cpp:17
esys::lsm::ParticleData::ParticleData
ParticleData(const Vec3 &pos, double rad)
Definition: Contact.h:32
esys::lsm::Contact::getParticle1
const ParticleData & getParticle1() const
Definition: Contact.h:147
esys::lsm::Contact
Definition: Contact.h:120
esys::lsm::Contact::operator==
bool operator==(const Contact &data) const
Definition: Contact.h:187
esys::lsm::ParticleData::is2d
static bool is2d()
Definition: Contact.h:56
esys::lsm::Contact::m_pd1
ParticleData m_pd1
Definition: Contact.h:220
esys::lsm::ParticleData::getVolume
double getVolume() const
Definition: Contact.h:68
esys::lsm::Contact::getVolume2
double getVolume2() const
Definition: Contact.h:172
Vec3
Definition: vec3.h:47
esys::lsm::Contact::Contact
Contact()
Definition: Contact.h:122
esys::lsm::ParticleData::operator==
bool operator==(const ParticleData &pd) const
Definition: Contact.h:36
std::operator>>
std::istream & operator>>(std::istream &iStream, esys::lsm::ParticleData &pd)
Definition: Contact.h:102
vec3.h
std
Definition: Contact.h:101
std::operator<<
std::ostream & operator<<(std::ostream &oStream, const esys::lsm::ParticleData &pd)
Definition: Contact.h:108
operator<<
std::ostream & operator<<(std::ostream &oStream, const esys::lsm::Contact &contact)
Definition: Contact.h:234
esys::lsm::ParticleData::read
void read(std::istream &iStream)
Definition: Contact.h:80
esys::lsm::ParticleData::FOUR_THIRDS_PI
static const double FOUR_THIRDS_PI
Definition: Contact.h:67
Contact.h
esys::lsm::Contact::getParticle2
const ParticleData & getParticle2() const
Definition: Contact.h:152