Jpp  15.0.3
the software that should make you happy
 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 <fstream>
7 #include <iomanip>
8 #include <string>
9 #include <map>
10 #include <cmath>
11 
12 #include "JSystem/JStat.hh"
13 
14 #include "JLang/JStringStream.hh"
15 #include "JLang/JManip.hh"
16 
17 #include "Jeep/JeepToolkit.hh"
18 #include "Jeep/JComment.hh"
19 
20 
21 /**
22  * \file
23  *
24  * Mechanical modelling of string.
25  * \author mdejong
26  */
27 namespace JACOUSTICS {}
28 namespace JPP { using namespace JACOUSTICS; }
29 
30 namespace JACOUSTICS {
31 
32  using JEEP::JComment;
33 
34 
35  /**
36  * Auxiliary data structure for parameters of mechanical model.\n
37  * This data structure provides for the implementation of the effective height conform the mechanical model of string.
38  */
39  struct JMechanics {
40  /**
41  * Default constructor.
42  */
44  a(0.0),
45  b(0.0)
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param a logarithmic term
53  * \param b linear term
54  */
55  JMechanics(const double a,
56  const double b) :
57  a(a),
58  b(b)
59  {}
60 
61 
62  /**
63  * Get effective height for given actual height.
64  *
65  * \param height height
66  * \return height
67  */
68  double getHeight(const double height) const
69  {
70  return height + this->b * log(1.0 - this->a * height);
71  }
72 
73 
74  /**
75  * Read parameters from input stream.
76  *
77  * \param in input stream
78  * \param parameters parameters
79  * \return input stream
80  */
81  friend inline std::istream& operator>>(std::istream& in, JMechanics& parameters)
82  {
83  return in >> parameters.a >> parameters.b;
84  }
85 
86 
87  /**
88  * Write parameters to output stream.
89  *
90  * \param out output stream
91  * \param parameters parameters
92  * \return output stream
93  */
94  friend inline std::ostream& operator<<(std::ostream& out, const JMechanics& parameters)
95  {
96  return out << FIXED(7,5) << parameters.a << ' '
97  << FIXED(7,3) << parameters.b;
98  }
99 
100  double a; //!< <tt>0 <= a < (maximal height)⁻1;</tt> [m^-1]
101  double b; //!< <tt>0 <= b;</tt> [m]
102  };
103 
104 
105  /**
106  * Auxiliary data structure for mechanical model parameters of strings in a given detector.
107  *
108  * Note that the JDetectorMechanics::WILD_CARD acts as default value for the string number.
109  */
111  public std::map<int, JMechanics>
112  {
113  enum {
114  WILD_CARD = -1 //!< wild card for string number.
115  };
116 
117 
118  /**
119  * Get file name with mechanical model parameters for given detector identifier.
120  *
121  * Note that the environment variable LD_LIBRARY_PATH is used to obtain the path of the targeted file.
122  *
123  * \param id detector identifier
124  * \return file name
125  */
126  static std::string getFilename(const int id)
127  {
128  using namespace std;
129  using namespace JPP;
130 
131  const string file_name = MAKE_STRING("mechanics_" << FILL(8,'0') << id << ".txt");
132 
133  return getFullFilename(LD_LIBRARY_PATH, file_name);
134  }
135 
136 
137  /**
138  * Load mechanical model parameters from file.
139  *
140  * \param file_name file name
141  */
142  void load(const std::string& file_name)
143  {
144  std::ifstream in(file_name.c_str());
145 
146  in >> *this;
147 
148  in.close();
149  }
150 
151 
152  /**
153  * Load mechanical model parameters for given detector identifier.
154  *
155  * \param id detector identifier
156  */
157  void load(const int id)
158  {
159  load(getFilename(id));
160  }
161 
162 
163  /**
164  * Get mechanical parameters for given string.
165  *
166  * \param string string number
167  * \return mechanical parameters
168  */
169  const JMechanics& operator()(const int string) const
170  {
171  static const JMechanics mechanics;
172 
173  const_iterator p;
174 
175  if ((p = this->find(string)) != this->end())
176  return p->second;
177  else if ((p = this->find(WILD_CARD)) != this->end())
178  return p->second;
179  else
180  return mechanics;
181  }
182 
183 
184  /**
185  * Read detector mechanics from input.
186  *
187  * \param in input stream
188  * \param object detector mechanics
189  * \return input stream
190  */
191  friend inline std::istream& operator>>(std::istream& in, JDetectorMechanics& object)
192  {
193  using namespace JPP;
194 
195  JStringStream is(in);
196 
197  if (getFileStatus(is.str().c_str())) {
198  is.load();
199  }
200 
201  object.clear();
202 
203  is >> object.comment;
204 
205  int string;
206  JMechanics mechanics;
207 
208  while (is >> string >> mechanics) {
209  object[string] = mechanics;
210  }
211 
212  return in;
213  }
214 
215 
216  /**
217  * Write detector mechanics to output.
218  *
219  * \param out output stream
220  * \param object detector mechanics
221  * \return output stream
222  */
223  friend inline std::ostream& operator<<(std::ostream& out, const JDetectorMechanics& object)
224  {
225  using namespace std;
226 
227  out << object.comment;
228 
229  for (JDetectorMechanics::const_iterator i = object.begin(); i != object.end(); ++i) {
230  out << setw(4) << i->first << ' ' << i->second << endl;
231  }
232 
233  return out;
234  }
235 
237  };
238 
239 
240  /**
241  * Function object to get string mechanics.
242  */
244 }
245 
246 #endif
Auxiliary data structure for mechanical model parameters of strings in a given detector.
Definition: JMechanics.hh:110
static JDetectorMechanics getMechanics
Function object to get string mechanics.
Definition: JMechanics.hh:243
static const char *const LD_LIBRARY_PATH
Nick names of environment variables.
Definition: JeepToolkit.hh:31
const JMechanics & operator()(const int string) const
Get mechanical parameters for given string.
Definition: JMechanics.hh:169
*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:446
is
Definition: JDAQCHSM.chsm:167
JMechanics(const double a, const double b)
Constructor.
Definition: JMechanics.hh:55
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
friend std::istream & operator>>(std::istream &in, JDetectorMechanics &object)
Read detector mechanics from input.
Definition: JMechanics.hh:191
friend std::istream & operator>>(std::istream &in, JMechanics &parameters)
Read parameters from input stream.
Definition: JMechanics.hh:81
wild card for string number.
Definition: JMechanics.hh:114
Auxiliary methods for handling file names, type names and environment.
double a
0 &lt;= a &lt; (maximal height)⁻1; [m^-1]
Definition: JMechanics.hh:100
double getHeight(const double height) const
Get effective height for given actual height.
Definition: JMechanics.hh:68
JMechanics()
Default constructor.
Definition: JMechanics.hh:43
void load(const std::string &file_name)
Load mechanical model parameters from file.
Definition: JMechanics.hh:142
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
I/O manipulators.
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
Auxiliary class for comment.
Definition: JComment.hh:41
void load(const int id)
Load mechanical model parameters for given detector identifier.
Definition: JMechanics.hh:157
double b
0 &lt;= b; [m]
Definition: JMechanics.hh:101
static std::string getFilename(const int id)
Get file name with mechanical model parameters for given detector identifier.
Definition: JMechanics.hh:126
friend std::ostream & operator<<(std::ostream &out, const JMechanics &parameters)
Write parameters to output stream.
Definition: JMechanics.hh:94
friend std::ostream & operator<<(std::ostream &out, const JDetectorMechanics &object)
Write detector mechanics to output.
Definition: JMechanics.hh:223
std::string getFullFilename(const std::string &variable, const std::string &file_name)
Get full file name (see JEEP::getPath).
Definition: JeepToolkit.hh:213
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 CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:42
File status.
Auxiliary data structure for parameters of mechanical model.
Definition: JMechanics.hh:39