GeoModel - GeoModelCore
FunctionProduct.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/FunctionProduct.h"
8 #include <stdexcept>
9 
10 namespace GeoGenfun {
11 FUNCTION_OBJECT_IMP(FunctionProduct)
12 
13 FunctionProduct::FunctionProduct(const AbsFunction *arg1, const AbsFunction *arg2):
14 _arg1(arg1->clone()),
15 _arg2(arg2->clone())
16 {
17  if (arg1->dimensionality()!=arg2->dimensionality()) {
18  throw std::runtime_error ("FunctionProduct: dimension mismatch");
19  }
20 }
21 
22 FunctionProduct::FunctionProduct(const FunctionProduct & right) :
23  AbsFunction(right),
24  _arg1(right._arg1->clone()),
25  _arg2(right._arg2->clone())
26 {
27 }
28 
29 FunctionProduct::~FunctionProduct()
30 {
31  delete _arg1;
32  delete _arg2;
33 }
34 
35 
36 unsigned int FunctionProduct::dimensionality() const {
37  return _arg1->dimensionality();
38 }
39 
40 double FunctionProduct::operator ()(double x) const
41 {
42  return (*_arg1)(x)*(*_arg2)(x);
43 }
44 
45 double FunctionProduct::operator ()(const Argument & x) const
46 {
47  return (*_arg1)(x)*(*_arg2)(x);
48 }
49 
50 Derivative FunctionProduct::partial(unsigned int index) const {
51  const Derivative & d1=_arg1->partial(index);
52  const Derivative & d2=_arg2->partial(index);
53  const AbsFunction & fPrime = (*_arg1)*d2 + d1*(*_arg2);
54  return Derivative(&fPrime);
55 }
56 
57 } // namespace GeoGenfun
Definition: Abs.h:15