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