smoothed.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2016 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// epsic/src/smoothed.h
10
11#ifndef __epsic_smoothed_h
12#define __epsic_smoothed_h
13
14#include "mode.h"
15
16namespace epsic
17{
18 /***************************************************************************
19 *
20 * a boxcar-smoothed mode of electromagnetic radiation
21 *
22 ***************************************************************************/
23
24 class boxcar_mode : public mode_decorator
25 {
26 std::vector< Spinor<double> > instances;
27 unsigned smooth;
28 unsigned current;
29
30 void setup()
31 {
32 current = 0;
33 instances.resize (smooth);
34 for (unsigned i=1; i<smooth; i++)
35 instances[i] = source->get_field();
36 }
37
38 public:
39
40 boxcar_mode (mode* s, unsigned n) : mode_decorator(s) { smooth = n; }
41
42 Spinor<double> get_field ()
43 {
44 if (instances.size() < smooth)
45 setup ();
46
47 instances[current] = source->get_field();
48 current = (current + 1) % smooth;
49
50 Spinor<double> result;
51 for (unsigned i=0; i<smooth; i++)
52 result += instances[i];
53
54 result /= sqrt(smooth);
55 return result;
56 }
57 };
58
59} // namespace epsic
60
61#endif // ! defined __epsic_smoothed_h

Generated using doxygen 1.14.0