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