Jpp  16.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JElement.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JELEMENT__
2 #define __JTOOLS__JELEMENT__
3 
4 #include <cmath>
5 
6 #include "JMath/JZero.hh"
7 #include "JMath/JMath.hh"
8 #include "JLang/JClass.hh"
9 #include "JIO/JSerialisable.hh"
10 
11 
12 /**
13  * \file
14  *
15  * The elements in a collection are sorted according to their abscissa values and a given distance operator.
16  * These elements should have the following type definitions and member methods:
17  * <pre>
18  * typedef <abscissa type> abscissa_type;
19  * typedef <ordinate type> ordinate_type;
20  *
21  * constructor();
22  * constructor(abscissa_type, ordinate_type);
23  *
24  * abscissa_type getX() const;
25  * const ordinate_type& getY() const;
26  * ordinate_type& getY();
27  * </pre>
28  * \author mdejong
29  */
30 
31 namespace JTOOLS {}
32 namespace JPP { using namespace JTOOLS; }
33 
34 namespace JTOOLS {
35 
36  using JIO::JReader;
37  using JIO::JWriter;
38  using JMATH::JMath;
39  using JMATH::getZero;
40 
41 
42  /**
43  * 2D Element.
44  */
45  template<class JAbscissa_t, class JOrdinate_t>
46  struct JElement2D {
47 
48  typedef JAbscissa_t abscissa_type;
49  typedef JOrdinate_t ordinate_type;
50 
51 
52  /**
53  * Default constructor.
54  */
58  {}
59 
60 
61  /**
62  * Constructor.
63  *
64  * \param x abscissa value
65  * \param y ordinate value
66  */
69  __x(x),
70  __y(y)
71  {}
72 
73 
74  /**
75  * Get abscissa value.
76  *
77  * \return abscissa value
78  */
80  {
81  return __x;
82  }
83 
84 
85  /**
86  * Get ordinate value.
87  *
88  * \return ordinate value
89  */
90  const ordinate_type& getY() const
91  {
92  return __y;
93  }
94 
95 
96  /**
97  * Get ordinate value.
98  *
99  * \return ordinate value
100  */
102  {
103  return __y;
104  }
105 
106 
107  /**
108  * Read element from input.
109  *
110  * \param in reader
111  * \param element element
112  * \return reader
113  */
114  friend inline JReader& operator>>(JReader& in, JElement2D& element)
115  {
116  in >> element.__x;
117  in >> element.__y;
118 
119  return in;
120  }
121 
122 
123  /**
124  * Write element to output.
125  *
126  * \param out writer
127  * \param element element
128  * \return writer
129  */
130  friend inline JWriter& operator<<(JWriter& out, const JElement2D& element)
131  {
132  out << element.__x;
133  out << element.__y;
134 
135  return out;
136  }
137 
138 
139  protected:
142  };
143 
144 
145  /**
146  * 2D Element for spline interpolations.
147  *
148  * Note that the internal data members needed for the calculation
149  * of the 2nd derivatives are not subject to I/O, i.e.\ the I/O of
150  * this class is identical to that of the JElement2D class.
151  */
152  template<class JAbscissa_t, class JOrdinate_t>
154  public JElement2D<JAbscissa_t, JOrdinate_t>
155  {
156 
160 
161 
162  /**
163  * Default constructor.
164  */
166  element_type(),
168  {}
169 
170 
171  /**
172  * Constructor.
173  *
174  * \param x abscissa value
175  * \param y ordinate value
176  */
179  element_type(x, y),
181  {}
182 
183 
184  /**
185  * Get derivative.
186  *
187  * \return derivative
188  */
190  {
191  return __u;
192  }
193 
194 
195  /**
196  * Set derivative.
197  *
198  * \param u derivative
199  */
201  {
202  __u= u;
203  }
204 
205 
206  protected:
208  };
209 
210 
211  /**
212  * 2D Element for spline interpolations.
213  *
214  * Note that the internal data members needed for the calculation
215  * of the integral values are not subject to I/O, i.e.\ the I/O of
216  * this class is identical to that of the JElement2D class.
217  */
218  template<class JAbscissa_t, class JOrdinate_t>
220  public JSplineElement2D<JAbscissa_t, JOrdinate_t>
221  {
222 
226 
227 
228  /**
229  * Default constructor.
230  */
232  element_type(),
234  {}
235 
236 
237  /**
238  * Constructor.
239  *
240  * \param x abscissa value
241  * \param y ordinate value
242  */
245  element_type(x, y),
247  {}
248 
249 
250  /**
251  * Get integral.
252  *
253  * \return integral
254  */
256  {
257  return __v;
258  }
259 
260 
261  /**
262  * Set integral.
263  *
264  * \param v integral
265  */
267  {
268  __v = v;
269  }
270 
271 
272  protected:
274  };
275 
276 
277  /**
278  * 2D Element for polynomial interpolations.
279  *
280  * Note that the internal data members needed for the calculation
281  * of the integral values are not subject to I/O, i.e.\ the I/O of
282  * this class is identical to that of the JElement2D class.
283  */
284  template<class JAbscissa_t, class JOrdinate_t>
286  public JElement2D<JAbscissa_t, JOrdinate_t>
287  {
288 
292 
293 
294  /**
295  * Default constructor.
296  */
298  element_type(),
300  {}
301 
302 
303  /**
304  * Constructor.
305  *
306  * \param x abscissa value
307  * \param y ordinate value
308  */
311  element_type(x, y),
313  {}
314 
315 
316  /**
317  * Get integral.
318  *
319  * \return integral
320  */
322  {
323  return __v;
324  }
325 
326 
327  /**
328  * Set integral.
329  *
330  * \param v integral
331  */
333  {
334  __v = v;
335  }
336 
337 
338  protected:
340  };
341 
342 
343  /**
344  * 2D Binned element.
345  *
346  * Note that the internal data members needed for the calculation
347  * of the bin center are not subject to I/O, i.e.\ the I/O of
348  * this class is identical to that of the JElement2D class.
349  */
350  template<class JAbscissa_t, class JOrdinate_t>
351  struct JBin2D :
352  public JElement2D<JAbscissa_t, JOrdinate_t>,
353  public JMath< JBin2D<JAbscissa_t, JOrdinate_t> >
354  {
355 
359 
360 
361  /**
362  * Default constructor.
363  */
364  JBin2D() :
365  element_type(),
368  {}
369 
370 
371  /**
372  * Constructor.
373  *
374  * \param x abscissa value
375  * \param y ordinate value
376  */
379  element_type(x,y),
382  {}
383 
384 
385  /**
386  * Add abscissa value.
387  *
388  * \param x abscissa value
389  * \param w weight
390  */
393  {
394  this->__y += w;
395  this->__z += w * x;
396  this->__w2 += w * w;
397  }
398 
399 
400  /**
401  * Get bin center.
402  *
403  * \return center
404  */
406  {
407  if (this->__y != 0)
408  return this->__z / this->__y;
409  else
410  return this->__x;
411  }
412 
413 
414  /**
415  * Get bin content.
416  *
417  * \return content
418  */
420  {
421  return this->__y;
422  }
423 
424 
425  /**
426  * Get bin error.
427  *
428  * \return error
429  */
431  {
432  return sqrt(this->__w2);
433  }
434 
435 
436  /**
437  * Add bin.
438  *
439  * \param bin bin
440  * \return this bin
441  */
442  JBin2D& add(const JBin2D& bin)
443  {
444  this->__y += bin.__y;
445  this->__z += bin.__zl;
446  this->__w2 += bin.__w2;
447 
448  return *this;
449  }
450 
451 
452  /**
453  * Scale contents.
454  *
455  * \param value multiplication factor
456  * \return this bin
457  */
458  JBin2D& mul(const double value)
459  {
460  this->__y *= value;
461  this->__z *= value;
462  this->__w2 *= value*value;
463 
464  return *this;
465  }
466 
467 
468  /**
469  * Scale contents.
470  *
471  * \param value division factor
472  * \return this bin
473  */
474  JBin2D& div(const double value)
475  {
476  this->__y /= value;
477  this->__z /= value;
478  this->__w2 /= value*value;
479 
480  return *this;
481  }
482 
483 
484  protected:
487  };
488 
489 
490  /**
491  * 3D Element.
492  */
493  template<class JAbscissa_t, class JOrdinate_t>
494  struct JElement3D {
495 
496  typedef JAbscissa_t abscissa_type;
497  typedef JOrdinate_t ordinate_type;
498 
499 
500  /**
501  * Default constructor.
502  */
507  {}
508 
509 
510  /**
511  * Constructor.
512  *
513  * \param x abscissa value
514  * \param y abscissa value
515  * \param z ordinate value
516  */
520  __x(x),
521  __y(y),
522  __z(z)
523  {}
524 
525 
526  /**
527  * Get abscissa value.
528  *
529  * \return abscissa value
530  */
532  {
533  return __x;
534  }
535 
536 
537  /**
538  * Get abscissa value.
539  *
540  * \return abscissa value
541  */
543  {
544  return __y;
545  }
546 
547 
548  /**
549  * Get ordinate value.
550  *
551  * \return ordinate value
552  */
553  const ordinate_type& getZ() const
554  {
555  return __y;
556  }
557 
558 
559  /**
560  * Get ordinate value.
561  *
562  * \return ordinate value
563  */
565  {
566  return __y;
567  }
568 
569 
570  /**
571  * Read element from input.
572  *
573  * \param in reader
574  * \param element element
575  * \return reader
576  */
577  friend inline JReader& operator>>(JReader& in, JElement3D& element)
578  {
579  in >> element.__x;
580  in >> element.__y;
581  in >> element.__z;
582 
583  return in;
584  }
585 
586 
587  /**
588  * Write element to output.
589  *
590  * \param out writer
591  * \param element element
592  * \return writer
593  */
594  friend inline JWriter& operator<<(JWriter& out, const JElement3D& element)
595  {
596  out << element.__x;
597  out << element.__y;
598  out << element.__z;
599 
600  return out;
601  }
602 
603 
604  protected:
608  };
609 }
610 
611 #endif
JPolintElement2S()
Default constructor.
Definition: JElement.hh:297
data_type w[N+1][M+1]
Definition: JPolint.hh:757
Interface for binary output.
JSplineElement2D()
Default constructor.
Definition: JElement.hh:165
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:110
element_type::abscissa_type abscissa_type
Definition: JElement.hh:224
ordinate_type __z
Definition: JElement.hh:485
const ordinate_type & getZ() const
Get ordinate value.
Definition: JElement.hh:553
2D Element for spline interpolations.
Definition: JElement.hh:219
ordinate_type getIntegral() const
Get integral.
Definition: JElement.hh:321
2D Binned element.
Definition: JElement.hh:351
JElement2D< JAbscissa_t, JOrdinate_t > element_type
Definition: JElement.hh:356
JAbscissa_t abscissa_type
Definition: JElement.hh:48
JOrdinate_t ordinate_type
Definition: JElement.hh:49
ordinate_type getIntegral() const
Get integral.
Definition: JElement.hh:255
3D Element.
Definition: JElement.hh:494
void setIntegral(typename JLANG::JClass< ordinate_type >::argument_type v)
Set integral.
Definition: JElement.hh:266
JElement2D(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
Constructor.
Definition: JElement.hh:67
abscissa_type getBinCenter() const
Get bin center.
Definition: JElement.hh:405
JElement3D(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< abscissa_type >::argument_type y, typename JLANG::JClass< ordinate_type >::argument_type z)
Constructor.
Definition: JElement.hh:517
Definition of zero value for any class.
JSplineElement2D(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
Constructor.
Definition: JElement.hh:177
JElement3D()
Default constructor.
Definition: JElement.hh:503
element_type::ordinate_type ordinate_type
Definition: JElement.hh:159
ordinate_type __z
Definition: JElement.hh:607
ordinate_type __w2
Definition: JElement.hh:486
JElement2D()
Default constructor.
Definition: JElement.hh:55
const ordinate_type & getY() const
Get ordinate value.
Definition: JElement.hh:90
ordinate_type getU() const
Get derivative.
Definition: JElement.hh:189
JBin2D & add(const JBin2D &bin)
Add bin.
Definition: JElement.hh:442
friend JWriter & operator<<(JWriter &out, const JElement3D &element)
Write element to output.
Definition: JElement.hh:594
T getZero()
Get zero value for a given data type.
Definition: JZero.hh:26
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
void setU(typename JLANG::JClass< ordinate_type >::argument_type u)
Set derivative.
Definition: JElement.hh:200
JBin2D(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
Constructor.
Definition: JElement.hh:377
JElement2D< JAbscissa_t, JOrdinate_t > element_type
Definition: JElement.hh:289
JBin2D & mul(const double value)
Scale contents.
Definition: JElement.hh:458
ordinate_type getBinError() const
Get bin error.
Definition: JElement.hh:430
Interface for binary input.
element_type::ordinate_type ordinate_type
Definition: JElement.hh:225
ordinate_type __y
Definition: JElement.hh:141
JElement2D< JAbscissa_t, JOrdinate_t > element_type
Definition: JElement.hh:157
abscissa_type __x
Definition: JElement.hh:605
JOrdinate_t ordinate_type
Definition: JElement.hh:497
JSplineElement2D< JAbscissa_t, JOrdinate_t > element_type
Definition: JElement.hh:223
ordinate_type & getY()
Get ordinate value.
Definition: JElement.hh:101
abscissa_type __x
Definition: JElement.hh:140
element_type::ordinate_type ordinate_type
Definition: JElement.hh:291
friend JReader & operator>>(JReader &in, JElement3D &element)
Read element from input.
Definition: JElement.hh:577
ordinate_type getBinContent() const
Get bin content.
Definition: JElement.hh:419
element_type::abscissa_type abscissa_type
Definition: JElement.hh:357
JPolintElement2S(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
Constructor.
Definition: JElement.hh:309
friend JReader & operator>>(JReader &in, JElement2D &element)
Read element from input.
Definition: JElement.hh:114
abscissa_type getY() const
Get abscissa value.
Definition: JElement.hh:542
ordinate_type & getZ()
Get ordinate value.
Definition: JElement.hh:564
2D Element for spline interpolations.
Definition: JElement.hh:153
JSplineElement2S(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
Constructor.
Definition: JElement.hh:243
Base class for data structures with artithmetic capabilities.
2D Element.
Definition: JElement.hh:46
element_type::ordinate_type ordinate_type
Definition: JElement.hh:358
element_type::abscissa_type abscissa_type
Definition: JElement.hh:158
abscissa_type __y
Definition: JElement.hh:606
JAbscissa_t abscissa_type
Definition: JElement.hh:496
data_type v[N+1][M+1]
Definition: JPolint.hh:756
double u[N+1]
Definition: JPolint.hh:755
abscissa_type getX() const
Get abscissa value.
Definition: JElement.hh:79
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
abscissa_type getX() const
Get abscissa value.
Definition: JElement.hh:531
void fill(typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type w)
Add abscissa value.
Definition: JElement.hh:391
void setIntegral(typename JLANG::JClass< ordinate_type >::argument_type v)
Set integral.
Definition: JElement.hh:332
element_type::abscissa_type abscissa_type
Definition: JElement.hh:290
JBin2D()
Default constructor.
Definition: JElement.hh:364
2D Element for polynomial interpolations.
Definition: JElement.hh:285
JBin2D & div(const double value)
Scale contents.
Definition: JElement.hh:474
JSplineElement2S()
Default constructor.
Definition: JElement.hh:231
friend JWriter & operator<<(JWriter &out, const JElement2D &element)
Write element to output.
Definition: JElement.hh:130