Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMechanics.hh
Go to the documentation of this file.
1 #ifndef __JACOUSTICS__JMECHANICS__
2 #define __JACOUSTICS__JMECHANICS__
3 
4 #include <istream>
5 #include <ostream>
6 #include <iomanip>
7 #include <cmath>
8 
9 #include "JLang/JManip.hh"
10 #include "JTools/JHashMap.hh"
11 
12 /**
13  * \file
14  *
15  * Mechanical modelling of string.
16  * \author mdejong
17  */
18 namespace JACOUSTICS {}
19 namespace JPP { using namespace JACOUSTICS; }
20 
21 namespace JACOUSTICS {
22 
23  using JTOOLS::JHashMap;
24 
25 
26  /**
27  * Auxiliary data structure for parameters of mechanical model.\n
28  * This data structure provides for the implementation of the effective height conform the mechanical model of string.
29  */
30  struct JMechanics {
31  /**
32  * Default constructor.
33  */
35  a(0.0),
36  b(0.0)
37  {}
38 
39 
40  /**
41  * Constructor.
42  *
43  * \param a logarithmic term
44  * \param b linear term
45  */
46  JMechanics(const double a,
47  const double b) :
48  a(a),
49  b(b)
50  {}
51 
52 
53  /**
54  * Get effective height.
55  *
56  * \param height height
57  * \return height
58  */
59  double getHeight(const double height) const
60  {
61  return height + this->b * log(1.0 - this->a * height);
62  }
63 
64 
65  /**
66  * Read parameters from input stream.
67  *
68  * \param in input stream
69  * \param parameters parameters
70  * \return input stream
71  */
72  friend inline std::istream& operator>>(std::istream& in, JMechanics& parameters)
73  {
74  return in >> parameters.a >> parameters.b;
75  }
76 
77 
78  /**
79  * Write parameters to output stream.
80  *
81  * \param out output stream
82  * \param parameters parameters
83  * \return output stream
84  */
85  friend inline std::ostream& operator<<(std::ostream& out, const JMechanics& parameters)
86  {
87  return out << FIXED(7,5) << parameters.a << ' '
88  << FIXED(7,3) << parameters.b;
89  }
90 
91  double a; //!< <tt>0 <= a < (maximal height)⁻1;</tt> [m^-1]
92  double b; //!< <tt>0 <= b;</tt> [m]
93  };
94 
95 
96  /**
97  * Auxiliary data structure for mechanical model parameters of strings in a given detector.
98  *
99  * The template parameter corresponds to the detector identifier.\n
100  * This scheme allows for extensions of an existing detector by derivation.
101  */
102  template<int detector = 0>
104  public JHashMap<int, JMechanics>
105  {
106  /**
107  * Default constructor.
108  */
110  {}
111 
112 
113  /**
114  * Constructor.
115  *
116  * \param mechanics default mechanical parameters
117  */
119  mechanics(mechanics)
120  {}
121 
122 
123  /**
124  * Get mechanical parameters for given string.
125  *
126  * \param string string number
127  * \return mechanical parameters
128  */
129  virtual const JMechanics& get(const int string) const override
130  {
131  if (this->has(string))
132  return static_cast<const JHashMap<int, JMechanics>&>(*this).get(string);
133  else
134  return mechanics;
135  }
136 
137  JMechanics mechanics; //!< default parameters
138  };
139 
140 
141  /**
142  * Mechanical model parameters for specific detector.
143  */
144  template<>
145  struct JDetectorMechanics<42> :
146  public JDetectorMechanics<>
147  {
149  JDetectorMechanics<>(JMechanics(0.00094, 294.291))
150  {}
151  };
152 
153 
154  /**
155  * Mechanical model parameters for specific detector.
156  */
157  template<>
158  struct JDetectorMechanics<49> :
159  public JDetectorMechanics<>
160  {
162  JDetectorMechanics<>(JMechanics(0.00311, 85.967))
163  {
164  (*this)[9] = JMechanics();
165  }
166  };
167 
168 
169  /**
170  * Auxiliary data structure for mechanical model parameters of strings in any detector.
171  */
172  struct JGetMechanics :
173  public JHashMap<int, JDetectorMechanics<> >
174  {
175  /**
176  * Default constructor.
177  */
179  {
180  (*this)[42] = JDetectorMechanics<42>();
181  (*this)[49] = JDetectorMechanics<49>();
182  }
183  } getMechanics;
184 }
185 
186 #endif
Auxiliary data structure for mechanical model parameters of strings in a given detector.
Definition: JMechanics.hh:103
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:71
Mechanical model parameters for specific detector.
Definition: JMechanics.hh:145
Mechanical model parameters for specific detector.
Definition: JMechanics.hh:158
General purpose class for hash map of unique elements.
*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: JManip.hh:445
JMechanics(const double a, const double b)
Constructor.
Definition: JMechanics.hh:46
JACOUSTICS::JGetMechanics getMechanics
virtual mapped_type & get(typename JClass< key_type >::argument_type key) override
Get mapped value.
Definition: JHashMap.hh:118
friend std::istream & operator>>(std::istream &in, JMechanics &parameters)
Read parameters from input stream.
Definition: JMechanics.hh:72
double a
0 &lt;= a &lt; (maximal height)⁻1; [m^-1]
Definition: JMechanics.hh:91
double getHeight(const double height) const
Get effective height.
Definition: JMechanics.hh:59
JMechanics()
Default constructor.
Definition: JMechanics.hh:34
I/O manipulators.
double b
0 &lt;= b; [m]
Definition: JMechanics.hh:92
JGetMechanics()
Default constructor.
Definition: JMechanics.hh:178
Auxiliary data structure for mechanical model parameters of strings in any detector.
Definition: JMechanics.hh:172
JDetectorMechanics()
Default constructor.
Definition: JMechanics.hh:109
JMechanics mechanics
default parameters
Definition: JMechanics.hh:137
friend std::ostream & operator<<(std::ostream &out, const JMechanics &parameters)
Write parameters to output stream.
Definition: JMechanics.hh:85
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
bool has(const T &value) const
Test whether given value is present.
Auxiliary data structure for parameters of mechanical model.
Definition: JMechanics.hh:30
JDetectorMechanics(const JMechanics &mechanics)
Constructor.
Definition: JMechanics.hh:118