Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JGeometry.hh
Go to the documentation of this file.
1 #ifndef __JACOUSTICS__JGEOMETRY__
2 #define __JACOUSTICS__JGEOMETRY__
3 
4 #include <ostream>
5 #include <iomanip>
6 
7 #include "JLang/JException.hh"
9 #include "JTools/JHashMap.hh"
10 #include "Jeep/JPrint.hh"
11 
13 #include "JAcoustics/JModel.hh"
14 
15 
16 /**
17  * \file
18  *
19  * Acoustic geometries.
20  * \author mdejong
21  */
22 namespace JACOUSTICS {}
23 namespace JPP { using namespace JACOUSTICS; }
24 
25 namespace JACOUSTICS {
26 
30  using JTOOLS::JHashMap;
31 
32 
33  /**
34  * Auxiliary data structure to encapsulate different geometries.\n
35  * This data structure provides for the implementation of the model dependent geometry of a detector string.
36  */
37  struct JGeometry {
38 
39  /**
40  * Floor geometry.
41  */
42  struct JFloor {
43  /**
44  * Default constructor.
45  */
46  JFloor() :
47  height(0.0)
48  {}
49 
50 
51  /**
52  * Constructor.\n
53  * The height refers to the maximal distance from
54  * the fixed reference point of the parent string.
55  *
56  * \param height height
57  */
58  JFloor(const double height) :
59  height(height)
60  {}
61 
62 
63  /**
64  * Get height of this floor.\n
65  * The height refers to the maximal distance from
66  * the fixed reference point of the parent string.
67  *
68  * \return height
69  */
70  double getHeight() const
71  {
72  return height;
73  }
74 
75 
76  /**
77  * Write floor parameters to output stream.
78  *
79  * \param out output stream
80  * \param floor floor
81  * \return output stream
82  */
83  friend inline std::ostream& operator<<(std::ostream& out, const JFloor& floor)
84  {
85  return out << FIXED(7,2) << floor.getHeight();
86  }
87 
88 
89  protected:
90  double height;
91  };
92 
93 
94  /**
95  * String geometry.
96  *
97  * A piezo sensor is mounted in each optical module.\n
98  * The position of the piezo is determined from the actual string parameters and the floor number of the optical module.\n
99  * A hydrophone is mounted on the anchor which corresponds to floor zero.\n
100  * It has a fixed position which is relative to the reference position of the string.
101  */
102  struct JString :
103  public JPosition3D,
104  public JHashMap<int, JFloor>
105  {
108 
109  /**
110  * Default constructor.
111  */
113  {}
114 
115 
116  /**
117  * Constructor.
118  *
119  * The given position corresponds to the reference point of the string from
120  * which the positions of the piezo sensors and hydrophone are calculated.
121  *
122  * \param position position
123  */
124  JString(const JVector3D& position) :
125  JPosition3D(position)
126  {}
127 
128 
129  /**
130  * Constructor.
131  *
132  * The template parameter should correspond to a data type which implements the following policy methods.
133  * <pre>
134  * int getFloor();
135  * JPosition3D getPosition();
136  * </pre>
137  *
138  * The given position corresponds to the reference point of the string from
139  * which the positions of the piezo sensors and hydrophone are calculated.
140  *
141  * Note that the position of the piezo is offset by JACOUSTICS::getPiezoPosition and
142  * that the position of the hydrophone should manually be set.
143  *
144  * \param position position
145  * \param __begin begin of optical modules
146  * \param __end end of optical modules
147  */
148  template<class T>
149  JString(const JVector3D& position,
150  T __begin,
151  T __end) :
152  JPosition3D(position)
153  {
154  for (T i = __begin; i != __end; ++i) {
155  (*this)[i->getFloor()] = this->getDistance(i->getPosition() + getPiezoPosition());
156  }
157  }
158 
159 
160  /**
161  * Get position at given height according to actual string parameters.
162  *
163  * \param parameters parameters
164  * \param height height
165  * \return position
166  */
168  const double height) const
169  {
170  const double tx = parameters.tx;
171  const double ty = parameters.ty;
172  const double tz = sqrt(1.0 - tx*tx - ty*ty);
173 
174  return JPosition3D(this->getX() + tx * height,
175  this->getY() + ty * height,
176  this->getZ() + tz * height);
177  }
178 
179 
180  /**
181  * Get position of given floor according to actual string parameters.
182  *
183  * \param parameters parameters
184  * \param floor floor
185  * \return position
186  */
188  const int floor) const
189  {
190  if (floor == 0)
191  return getPosition() + hydrophone.getPosition();
192  else if (this->has(floor))
193  return getPosition(parameters, this->get(floor).getHeight());
194  else
195  THROW(JValueOutOfRange, "Invalid floor " << floor);
196  }
197 
198 
199  /**
200  * Get position at given height according to default string parameters.
201  *
202  * \param height height
203  * \return position
204  */
205  JPosition3D getPosition(const double height) const
206  {
207  return getPosition(JModel::JString(), height);
208  }
209 
210 
211  /**
212  * Get position of given floor according to default string parameters.
213  *
214  * \param floor floor
215  * \return position
216  */
217  JPosition3D getPosition(const int floor) const
218  {
219  return getPosition(JModel::JString(), floor);
220  }
221 
222 
223  /**
224  * Get distance between given position and floor according to actual string parameters.
225  *
226  * \param parameters parameters
227  * \param position position
228  * \param floor floor
229  * \return distance
230  */
232  const JVector3D& position,
233  const int floor) const
234  {
235  return this->getPosition(parameters, floor).getDistance(position);
236  }
237 
238 
239  /**
240  * Get model gradient of distance between given position and floor according to actual string parameters.
241  *
242  * \param parameters parameters
243  * \param position position
244  * \param floor floor
245  * \return gradient
246  */
248  const JVector3D& position,
249  const int floor) const
250  {
251  if (floor == 0) {
252 
253  return JModel::JString();
254 
255  } else if (this->has(floor)) {
256 
257  const double height = this->get(floor).getHeight();
258  const JPosition3D pos = this->getPosition(parameters, height);
259 
260  const double tx = parameters.tx;
261  const double ty = parameters.ty;
262  const double tz = sqrt(1.0 - tx*tx - ty*ty);
263 
264  const double dx = pos.getX() - position.getX();
265  const double dy = pos.getY() - position.getY();
266  const double dz = pos.getZ() - position.getZ();
267 
268  const double D = sqrt(dx*dx + dy*dy + dz*dz);
269 
270  return JModel::JString(height * dx / D - (tx / tz) * dz / D,
271  height * dy / D - (ty / tz) * dz / D);
272 
273  } else {
274 
275  THROW(JValueOutOfRange, "Invalid floor " << floor);
276  }
277  }
278 
279 
280  /**
281  * Write string parameters to output stream.
282  *
283  * \param out output stream
284  * \param string string
285  * \return output stream
286  */
287  friend inline std::ostream& operator<<(std::ostream& out, const JString& string)
288  {
289  using namespace std;
290 
291  for (JString::const_iterator i = string.begin(); i != string.end(); ++i) {
292  out << setw(2) << i->first << ' ' << i->second << " | " << string.getPosition(i->first) << endl;
293  }
294 
295  return out;
296  }
297 
298 
299  /**
300  * Hydrophone.
301  *
302  * The position of the hydrophone is relative to the reference position of the string.
303  */
305  };
306 
307 
308  /**
309  * Detector geometry.
310  */
311  struct JDetector :
312  public JHashMap<int, JString>
313  {
314  /**
315  * Default constructor.
316  */
318  {}
319 
320 
321  /**
322  * Write detector parameters to output stream.
323  *
324  * \param out output stream
325  * \param detector detector
326  * \return output stream
327  */
328  friend inline std::ostream& operator<<(std::ostream& out, const JDetector& detector)
329  {
330  using namespace std;
331 
332  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
333  out << setw(4) << i->first << endl << i->second;
334  }
335 
336  return out;
337  }
338  };
339  };
340 }
341 
342 #endif
Exceptions.
do echo Generating $dir eval D
Definition: JDrawLED.sh:50
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:71
JFloor()
Default constructor.
Definition: JGeometry.hh:46
General purpose class for hash map of unique elements.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JPosition3D hydrophone
Hydrophone.
Definition: JGeometry.hh:304
JPosition3D getPosition(const JModel::JString &parameters, const int floor) const
Get position of given floor according to actual string parameters.
Definition: JGeometry.hh:187
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
double getDistance(const JVector3D &pos) const
Get distance to point.
Definition: JVector3D.hh:269
double getHeight() const
Get height of this floor.
Definition: JGeometry.hh:70
JDetector()
Default constructor.
Definition: JGeometry.hh:317
JPosition3D getPosition(const JModel::JString &parameters, const double height) const
Get position at given height according to actual string parameters.
Definition: JGeometry.hh:167
JString(const JVector3D &position, T __begin, T __end)
Constructor.
Definition: JGeometry.hh:149
friend std::ostream & operator<<(std::ostream &out, const JDetector &detector)
Write detector parameters to output stream.
Definition: JGeometry.hh:328
JPosition3D getPosition(const double height) const
Get position at given height according to default string parameters.
Definition: JGeometry.hh:205
JString()
Default constructor.
Definition: JGeometry.hh:112
I/O formatting auxiliaries.
Acoustics toolkit.
Data structure for vector in three dimensions.
Definition: JVector3D.hh:33
JString(const JVector3D &position)
Constructor.
Definition: JGeometry.hh:124
Auxiliary data structure to encapsulate different geometries.
Definition: JGeometry.hh:37
JModel::JString getGradient(const JModel::JString &parameters, const JVector3D &position, const int floor) const
Get model gradient of distance between given position and floor according to actual string parameters...
Definition: JGeometry.hh:247
JFloor(const double height)
Constructor.
Definition: JGeometry.hh:58
do set_variable OUTPUT_DIRECTORY $WORKDIR T
friend std::ostream & operator<<(std::ostream &out, const JFloor &floor)
Write floor parameters to output stream.
Definition: JGeometry.hh:83
double getY() const
Get y position.
Definition: JVector3D.hh:103
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
JPosition3D()
Default constructor.
Definition: JPosition3D.hh:47
double getX() const
Get x position.
Definition: JVector3D.hh:93
double getDistance(const JModel::JString &parameters, const JVector3D &position, const int floor) const
Get distance between given position and floor according to actual string parameters.
Definition: JGeometry.hh:231
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
container_type::const_iterator const_iterator
Definition: JHashMap.hh:85
friend std::ostream & operator<<(std::ostream &out, const JString &string)
Write string parameters to output stream.
Definition: JGeometry.hh:287
JPosition3D getPosition(const int floor) const
Get position of given floor according to default string parameters.
Definition: JGeometry.hh:217
Model for fit to acoutsics data.
JPosition3D getPiezoPosition()
Get relative position of piezo in optical module.
bool has(const T &value) const
Test whether given value is present.
double getZ() const
Get z position.
Definition: JVector3D.hh:114