GeoModel - GeoModelCore
Pi.cpp
1 //==========================================================================//
2 // Imported from the QAT library (qat.pitt.edu) by the copyright holder //
3 // Joe Boudreau. Software licensed under the terms and conditions of the //
4 // GNU Lesser Public License v3. //
5 //==========================================================================//
6 #include "GeoGenericFunctions/Pi.h"
7 #include "GeoGenericFunctions/Sigma.h"
8 #include "GeoGenericFunctions/FixedConstant.h"
9 #include <stdexcept>
10 
11 namespace GeoGenfun {
12 FUNCTION_OBJECT_IMP(Pi)
13 
14 void Pi::accumulate( const AbsFunction & fcn) {
15  _fcn.push_back(fcn.clone());
16 }
17 
18 Pi::Pi()
19 {
20 }
21 
22 Pi::Pi(const Pi & right) : AbsFunction(right)
23 {
24  for (size_t i=0; i<right._fcn.size();i++) {
25  _fcn.push_back(right._fcn[i]->clone());
26  }
27 }
28 
29 unsigned int Pi::dimensionality() const {
30  if (_fcn.size()==0) throw std::runtime_error("Cannot determine dimensionality from empty product");
31  return _fcn[0]->dimensionality();
32 }
33 
34 Pi::~Pi()
35 {
36  for (size_t i=0; i<_fcn.size();i++) {
37  delete _fcn[i];
38  }
39 }
40 
41 double Pi::operator ()(double x) const
42 {
43  double retVal=1.0;
44  for (size_t i=0;i<_fcn.size();i++) retVal *= (*_fcn[i])(x);
45  return retVal;
46 }
47 
48 
49 double Pi::operator ()(const Argument & x) const
50 {
51  double retVal=1.0;
52  for (size_t i=0;i<_fcn.size();i++) retVal *= (*_fcn[i])(x);
53  return retVal;
54 }
55 
56 
57 
58 Derivative Pi::partial(unsigned int index) const {
59 
60  Sigma fPrime;
61  fPrime.accumulate(FixedConstant(0.0));
62  for (size_t i=0;i<_fcn.size();i++) {
63  Pi subproductI;
64  subproductI.accumulate(FixedConstant(1.0));
65  for (size_t j=0;j<_fcn.size();j++) {
66  if (j!=i) subproductI.accumulate(*_fcn[i]);
67  }
68  fPrime.accumulate(_fcn[i]->partial(index)*subproductI);
69  }
70  return Derivative(&fPrime);
71 }
72 
73 
74 
75 } // namespace GeoGenfun
Definition: Abs.h:15