ESyS-Particle  2.3.4
WallForceReader.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 
14 #ifndef ESYS_LSMWALLFORCEREADER_H
15 #define ESYS_LSMWALLFORCEREADER_H
16 
17 #include "Foundation/vec3.h"
18 #include "Foundation/StringUtil.h"
19 
20 #include <vector>
21 #include <iostream>
22 #include <stdexcept>
23 
24 namespace esys
25 {
26  namespace lsm
27  {
29  {
30  public:
31  typedef int WallId;
32  class WallForce
33  {
34  public:
35  WallForce() : m_id(-1), m_force()
36  {
37  }
38 
39  WallForce(WallId id, const Vec3 &force) : m_id(id), m_force(force)
40  {
41  }
42 
44  StringUtil::StringVector::const_iterator begin,
45  StringUtil::StringVector::const_iterator end
46  )
47  : m_id(-1), m_force()
48  {
49  if (end-begin >= 4) {
50  m_id = StringUtil::to<int>(*begin);
51  for (int i = 0; i < 3; i++) {
52  m_force[i] = StringUtil::to<double>(*(begin + i + 1));
53  }
54  }
55  }
56 
57  const WallId &getId() const
58  {
59  return m_id;
60  }
61 
62  const Vec3 getForce() const
63  {
64  return m_force;
65  }
66  private:
69  };
70 
71  WallForcesRecord(const std::string &line)
72  {
73  parseLine(line);
74  }
75 
76  void parseLine(const std::string &line)
77  {
79  const int elemsPerWallForce = 4;
80  m_wallForceVector.clear();
81  m_wallForceVector.reserve(elemVector.size()/elemsPerWallForce);
82  if ((elemVector.size() % elemsPerWallForce) == 0)
83  {
84  for (
85  StringUtil::StringVector::const_iterator it = elemVector.begin();
86  it != elemVector.end();
87  it += elemsPerWallForce
88  )
89  {
90  const WallForce wallForce(it, it + elemsPerWallForce);
91  if (wallForce.getId() >= static_cast<int>(m_wallForceVector.size()))
92  {
93  m_wallForceVector.insert(m_wallForceVector.end(), wallForce.getId()-m_wallForceVector.size()+1, WallForce());
94  }
95  m_wallForceVector[wallForce.getId()] = wallForce;
96  }
97  }
98  else
99  {
100  std::stringstream msg;
101  msg
102  << "Record '"
103  << line
104  << "' does not contain a number of elements divisible by "
105  << elemsPerWallForce;
106  throw std::runtime_error(msg.str());
107  }
108  }
109 
110  const WallForce &get(WallId id) const
111  {
112  return m_wallForceVector[id];
113  }
114 
115  private:
116  typedef std::vector<WallForce> WallForceVector;
118  };
119 
121  {
122  public:
123  typedef std::pair<Vec3,Vec3> WallForcePair;
125 
126 
127  WallForceReader(WallId wallId1, WallId wallId2, std::istream &iStream)
128  : m_pIStream(&iStream),
129  m_lineBuffer(),
130  m_wallId1(wallId1),
131  m_wallId2(wallId2)
132  {
133  }
134 
135  WallForceReader(WallId wallId1, WallId wallId2)
136  : m_pIStream(NULL),
137  m_lineBuffer(),
138  m_wallId1(wallId1),
139  m_wallId2(wallId2)
140  {
141  }
142 
143  void setStream(std::istream &iStream)
144  {
145  m_pIStream = &iStream;
146  }
147 
148  bool hasNext() const
149  {
150  return ((m_pIStream != NULL) && ((m_pIStream->peek()) != std::istream::traits_type::eof()));
151  }
152 
154  {
157  return WallForcePair(record.get(m_wallId1).getForce(), record.get(m_wallId2).getForce());
158  }
159 
160  private:
161  static const int MAX_LINE_SIZE = 4096;
162 
163  std::istream *m_pIStream;
167  };
168  }
169 }
170 
171 #endif
esys::lsm::WallForcesRecord::WallForce::getId
const WallId & getId() const
Definition: WallForceReader.h:57
esys::lsm::InteractionToStressConverter::addRaw2Interactions
void addRaw2Interactions(std::istream &iStream)
Definition: InteractionToStressConverter.cpp:231
esys::lsm::StringUtil::splitStrings
StringVector splitStrings(const std::string &str, const std::string &delim)
Definition: StringUtil.h:169
esys::lsm::WallForcesRecord::WallForceVector
std::vector< WallForce > WallForceVector
Definition: WallForceReader.h:116
esys::lsm::InteractionToStressConverter::writeVtkUnstructuredXmlGridInformation
void writeVtkUnstructuredXmlGridInformation(std::ostream &oStream)
Definition: InteractionToStressConverter.cpp:267
esys::lsm::WallForcesRecord::WallId
int WallId
Definition: WallForceReader.h:31
esys::lsm::WallForceReader
Definition: WallForceReader.h:121
esys::lsm::WallForcesRecord::WallForce
Definition: WallForceReader.h:33
esys::lsm::WallForcesRecord
Definition: WallForceReader.h:29
esys::lsm::WallForceReader::WallForcePair
std::pair< Vec3, Vec3 > WallForcePair
Definition: WallForceReader.h:123
esys::lsm::WallForceReader::WallForceReader
WallForceReader(WallId wallId1, WallId wallId2, std::istream &iStream)
Definition: WallForceReader.h:127
esys::lsm::WallForceReader::WallId
WallForcesRecord::WallId WallId
Definition: WallForceReader.h:124
esys::lsm::WallForceReader::MAX_LINE_SIZE
static const int MAX_LINE_SIZE
Definition: WallForceReader.h:161
StringUtil.h
esys::lsm::WallForceReader::next
WallForcePair next()
Definition: WallForceReader.h:153
esys::lsm::WallForceReader::hasNext
bool hasNext() const
Definition: WallForceReader.h:148
esys::lsm::InteractionToStressConverter::writeFlatUnstructured
void writeFlatUnstructured(std::ostream &oStream)
Definition: InteractionToStressConverter.cpp:319
esys::lsm::ParticleData::is3d
static bool is3d()
Definition: Contact.h:51
WallForcesToFrictionConverter.h
esys::lsm::BoundingBox
3D bounding box
Definition: BoundingBox.h:28
esys
Definition: CheckPointable.cpp:17
esys::lsm::WallForcesRecord::WallForce::m_id
WallId m_id
Definition: WallForceReader.h:67
Vec3::Z
VEC3_INLINE double & Z()
Definition: vec3.h:121
NULL
#define NULL
Definition: t_list.h:17
esys::lsm::WallForceReader::WallForceReader
WallForceReader(WallId wallId1, WallId wallId2)
Definition: WallForceReader.h:135
esys::lsm::WallForceReader::m_lineBuffer
char m_lineBuffer[MAX_LINE_SIZE]
Definition: WallForceReader.h:164
esys::lsm::WallForcesRecord::WallForce::WallForce
WallForce()
Definition: WallForceReader.h:35
esys::lsm::StringUtil::trim
std::string trim(const std::string &str)
Definition: StringUtil.h:175
esys::lsm::WallForcesRecord::WallForce::WallForce
WallForce(StringUtil::StringVector::const_iterator begin, StringUtil::StringVector::const_iterator end)
Definition: WallForceReader.h:43
esys::lsm::WallForcesRecord::parseLine
void parseLine(const std::string &line)
Definition: WallForceReader.h:76
esys::lsm::WallForcesRecord::get
const WallForce & get(WallId id) const
Definition: WallForceReader.h:110
esys::lsm::WallForcesRecord::WallForce::getForce
const Vec3 getForce() const
Definition: WallForceReader.h:62
esys::lsm::StringUtil::StringVector
esys::lsm::StringVector StringVector
Definition: StringUtil.h:31
esys::lsm::WallForceReader::m_wallId2
WallId m_wallId2
Definition: WallForceReader.h:166
esys::lsm::WallForcesToFrictionConverter::convert
void convert()
Definition: WallForcesToFrictionConverter.cpp:116
esys::lsm::InteractionToStressConverter::writeFlatStructured
void writeFlatStructured(std::ostream &oStream)
Definition: InteractionToStressConverter.cpp:526
esys::lsm::WallForcesRecord::WallForce::WallForce
WallForce(WallId id, const Vec3 &force)
Definition: WallForceReader.h:39
Vec3
Definition: vec3.h:47
esys::lsm::WallForceReader::m_wallId1
WallId m_wallId1
Definition: WallForceReader.h:165
InteractionToStressConverter.h
esys::lsm::WallForcesToFrictionConverter
Definition: WallForcesToFrictionConverter.h:25
esys::lsm::WallForceReader::m_pIStream
std::istream * m_pIStream
Definition: WallForceReader.h:163
vec3.h
esys::lsm::InteractionToStressConverter::writeVtkUnstructuredXml
void writeVtkUnstructuredXml(std::ostream &oStream)
Definition: InteractionToStressConverter.cpp:240
WallForceReader.h
esys::lsm::InteractionToStressConverter
Definition: InteractionToStressConverter.h:49
esys::lsm::WallForcesRecord::WallForce::m_force
Vec3 m_force
Definition: WallForceReader.h:68
main
int main(int argc, char *argv[])
Definition: Main.cpp:23
esys::lsm::WallForceReader::setStream
void setStream(std::istream &iStream)
Definition: WallForceReader.h:143
esys::lsm::BoundingBox::getSizes
Vec3 getSizes() const
Definition: BoundingBox.hpp:78
esys::lsm::WallForcesRecord::m_wallForceVector
WallForceVector m_wallForceVector
Definition: WallForceReader.h:117
getBBox
BoundingBox getBBox(const std::string &arg)
Definition: Main.cpp:24
esys::lsm::WallForcesRecord::WallForcesRecord
WallForcesRecord(const std::string &line)
Definition: WallForceReader.h:71
BoundingBox.h
esys::lsm
Lattice Solid Model namespace.
Definition: CheckPointable.cpp:19