GeoModel - GeoModelCore
FunctionDirectProduct.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 
7 #include "GeoGenericFunctions/FunctionDirectProduct.h"
8 #include <stdexcept>
9 
10 namespace GeoGenfun {
11 FUNCTION_OBJECT_IMP(FunctionDirectProduct)
12 
13 FunctionDirectProduct::FunctionDirectProduct(const AbsFunction *arg1, const AbsFunction *arg2):
14 _arg1(arg1->clone()),
15 _arg2(arg2->clone()),
16 _m(arg1->dimensionality()),
17 _n(arg2->dimensionality())
18 {
19 }
20 
21 FunctionDirectProduct::FunctionDirectProduct(const FunctionDirectProduct & right):
22 AbsFunction(right),
23 _arg1(right._arg1->clone()),
24 _arg2(right._arg2->clone()),
25 _m(right._m),
26 _n(right._n)
27 {
28 }
29 
30 
31 FunctionDirectProduct::~FunctionDirectProduct()
32 {
33  delete _arg1;
34  delete _arg2;
35 }
36 
37 
38 double FunctionDirectProduct::operator() (const Argument & a) const {
39  unsigned int P = a.dimension();
40  Argument x1(_m);
41  Argument x2(_n);
42  if (_m+_n != P) {
43  throw std::runtime_error("FunctionDirectProduct: dimension mismatch");
44  return 0;
45  }
46  for (unsigned int i = 0; i<_m;i++) {
47  x1[i]=a[i];
48  }
49  for (unsigned int j = 0;j<_n;j++) {
50  x2[j]=a[j+_m];
51  }
52  return (*_arg1)(x1) * (*_arg2)(x2);
53 }
54 
55 unsigned int FunctionDirectProduct::dimensionality() const {
56  return _m+_n;
57 }
58 
59 double FunctionDirectProduct::operator ()(double) const
60 {
61  throw std::runtime_error("FunctionDirectProduct: evaluation with scalar argument");
62  return 0;
63 }
64 
65 
66 
67 Derivative FunctionDirectProduct::partial(unsigned int index) const {
68  if (index>=(_m+_n)) throw std::range_error ("FunctionDirectProduct: partial derivative index out of range");
69  if (index<_m) {
70  const Derivative & d1=_arg1->partial(index);
71  const AbsFunction & fPrime = d1%(*_arg2);
72  return Derivative(&fPrime);
73  }
74  else {
75  const Derivative &d2=_arg2->partial(index-_m);
76  const AbsFunction & fPrime = (*_arg1)%d2;
77  return Derivative(&fPrime);
78  }
79 }
80 
81 
82 } // namespace GeoGenfun
Definition: Abs.h:15