GeoModel - GeoModelCore
FunctionDifference.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/FunctionDifference.h"
8 #include <stdexcept>
9 
10 namespace GeoGenfun {
11 FUNCTION_OBJECT_IMP(FunctionDifference)
12 
13 FunctionDifference::FunctionDifference(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("FunctionDifference: dimension mismatch");
19  }
20 }
21 
22 
23 FunctionDifference::FunctionDifference(const FunctionDifference & right):
24  AbsFunction(right),
25  _arg1(right._arg1->clone()),
26  _arg2(right._arg2->clone())
27 {
28 }
29 
30 
31 unsigned int FunctionDifference::dimensionality() const {
32  return _arg1->dimensionality();
33 }
34 
35 FunctionDifference::~FunctionDifference()
36 {
37  delete _arg1;
38  delete _arg2;
39 }
40 
41 
42 
43 double FunctionDifference::operator ()(double x) const
44 {
45  return (*_arg1)(x)-(*_arg2)(x);
46 }
47 
48 double FunctionDifference::operator ()(const Argument & x) const
49 {
50  return (*_arg1)(x)-(*_arg2)(x);
51 }
52 
53 
54 Derivative FunctionDifference::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