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