herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
Interpolator.h
1 // -*- C++ -*-
2 //
3 // Interpolator.h is a part of Herwig - A multi-purpose Monte Carlo event generator
4 // Copyright (C) 2002-2019 The Herwig Collaboration
5 //
6 // Herwig is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef HERWIG_Interpolator_H
10 #define HERWIG_Interpolator_H
11 //
12 // This is the declaration of the Interpolator class.
13 //
14 
15 #include "ThePEG/Interface/Interfaced.h"
16 #include <cassert>
17 
18 namespace Herwig {
19 
20 using namespace ThePEG;
21 
30 template <typename ValT, typename ArgT>
31 class Interpolator: public Interfaced {
32 
33 public:
34 
38  typedef typename Ptr<Interpolator<ValT,ArgT> >::pointer Ptr;
39 
45  Interpolator() : _order(3), _copyx(5),_copyfun(5) {}
46 
50  Interpolator(const vector<ValT> & f,
51  const vector<ArgT> & x,
52  unsigned int order)
53  : _fun(f.size(),0.0),_xval(x.size(),0.0),_order(order),
54  _funit(TypeTraits<ValT>::baseunit()),
55  _xunit(TypeTraits<ArgT>::baseunit()),
56  _copyx(order+2),_copyfun(order+2) {
57  assert(_order>0);
58  assert(x.size() == f.size());
59  for (size_t i = 0; i < f.size(); ++i) {
60  _fun [i] = f[i] / _funit;
61  _xval[i] = x[i] / _xunit;
62  }
63  }
64 
68  template <size_t N>
69  Interpolator(const array<ValT,N> & f,
70  const array<ArgT,N> & x,
71  unsigned int order)
72  : _fun(N,0.0),_xval(N,0.0),_order(order),
73  _funit(TypeTraits<ValT>::baseunit()),
74  _xunit(TypeTraits<ArgT>::baseunit()),
75  _copyx(order+2),_copyfun(order+2) {
76  assert(_order>0);
77  for (size_t i = 0; i < N; ++i) {
78  _fun [i] = f[i] / _funit;
79  _xval[i] = x[i] / _xunit;
80  }
81  }
83 
87  Interpolator(size_t size,
88  const double f[], ValT funit,
89  const double x[], ArgT xunit,
90  unsigned int order)
91  : _fun(size,0.0),_xval(size,0.0),_order(order),
92  _funit(funit),_xunit(xunit), _copyx(order+2),_copyfun(order+2) {
93  assert(_order>0);
94  for (size_t i = 0; i < size; ++i) {
95  _fun [i] = f[i];
96  _xval[i] = x[i];
97  }
98  }
100 
104  ValT operator () (ArgT) const;
106  typedef ValT ValType;
108  typedef ArgT ArgType;
109 
110 public:
111 
118  void persistentOutput(PersistentOStream & os) const;
119 
125  void persistentInput(PersistentIStream & is, int version);
127 
134  static void Init();
135 
136 protected:
137 
144  virtual IBPtr clone() const { return new_ptr(*this); }
145 
150  virtual IBPtr fullclone() const { return new_ptr(*this); }
152 
153 private:
154 
159  Interpolator & operator=(const Interpolator &) = delete;
160 
161 private:
162 
166  vector<double> _fun;
167 
171  vector<double> _xval;
172 
176  unsigned int _order;
177 
181  ValT _funit;
182 
186  ArgT _xunit;
187 
191  mutable vector<double> _copyx;
192 
196  mutable vector<double> _copyfun;
197 
198 };
199 
204 template <typename ValT, typename ArgT>
205 inline typename Interpolator<ValT,ArgT>::Ptr
206 make_InterpolatorPtr(size_t size,
207  const double f[], ValT funit,
208  const double x[], ArgT xunit,
209  unsigned int order)
210 {
211  return new_ptr(Interpolator<ValT,ArgT>(size,
212  f,funit,
213  x,xunit,
214  order));
215 }
216 
221 template <typename ValT, typename ArgT>
222 inline typename Interpolator<ValT,ArgT>::Ptr
223 make_InterpolatorPtr(const typename std::vector<ValT> & f,
224  const typename std::vector<ArgT> & x,
225  unsigned int order)
226 {
227  return new_ptr(Interpolator<ValT,ArgT>(f,x,order));
228 }
229 
234 template <typename ValT, typename ArgT, size_t N>
235 inline typename Interpolator<ValT,ArgT>::Ptr
236 make_InterpolatorPtr(const typename std::array<ValT,N> & f,
237  const typename std::array<ArgT,N> & x,
238  unsigned int order)
239 {
240  return new_ptr(Interpolator<ValT,ArgT>(f,x,order));
241 }
242 
243 }
244 
245 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
246 #include "Interpolator.tcc"
247 #endif
248 
249 #endif /* HERWIG_Interpolator_H */
vector< double > _fun
the function values.
Definition: Interpolator.h:166
vector< double > _copyx
Temporary storage vector.
Definition: Interpolator.h:191
ArgT ArgType
Argument type for GaussianIntegrator.
Definition: Interpolator.h:108
virtual IBPtr fullclone() const
Make a clone of this object, possibly modifying the cloned object to make it sane.
Definition: Interpolator.h:150
Interpolator(const vector< ValT > &f, const vector< ArgT > &x, unsigned int order)
Constructor with data as vectors.
Definition: Interpolator.h:50
ThePEG::Ptr< InterfacedBase >::pointer IBPtr
ValT ValType
Return type for GaussianIntegrator.
Definition: Interpolator.h:106
ArgT _xunit
The Unit of the argument values.
Definition: Interpolator.h:186
Interpolator()
The default constructor.
Definition: Interpolator.h:45
unsigned int _order
the order of interpolation.
Definition: Interpolator.h:176
Interpolator< ValT, ArgT >::Ptr make_InterpolatorPtr(size_t size, const double f[], ValT funit, const double x[], ArgT xunit, unsigned int order)
helper function to create InterpolatorPtr easily from bare arrays (analogous to make_pair() ) ...
Definition: Interpolator.h:206
virtual IBPtr clone() const
Make a simple clone of this object.
Definition: Interpolator.h:144
Ptr< Interpolator< double, Energy2 > >::pointer Ptr
Pointer to an Interpolator.
Definition: Interpolator.h:38
Interpolator(size_t size, const double f[], ValT funit, const double x[], ArgT xunit, unsigned int order)
Constructor from bare arrays.
Definition: Interpolator.h:87
vector< double > _copyfun
Temporary storage vector.
Definition: Interpolator.h:196
Interpolator(const array< ValT, N > &f, const array< ArgT, N > &x, unsigned int order)
Constructor with data as arrays.
Definition: Interpolator.h:69
ValT _funit
The Unit of the function values.
Definition: Interpolator.h:181
vector< double > _xval
The x values.
Definition: Interpolator.h:171
-*- C++ -*-