GeoModel - GeoModelCore
Variable.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/Variable.h"
8 #include "GeoGenericFunctions/KVector.h"
9 #include <stdexcept>
10 namespace GeoGenfun {
11 FUNCTION_OBJECT_IMP(Variable)
12 
13 Variable::Variable(unsigned int selectionIndex, unsigned int dmsnlty):
14  _selectionIndex(selectionIndex),
15  _dimensionality(dmsnlty)
16 {}
17 
18 Variable::Variable(const Variable & right):
19  AbsFunction(right),
20  _selectionIndex(right._selectionIndex),
21  _dimensionality(right._dimensionality)
22 {
23 }
24 
25 Variable::~Variable() {
26 }
27 
28 double Variable::operator() (double x) const {
29  if (_selectionIndex!=0) throw std::runtime_error("GeoGenfun::Variable: selection index !=0") ;
30  return x;
31 }
32 
33 double Variable::operator () (const Argument & a) const {
34  if (!(_selectionIndex<a.dimension())) throw std::runtime_error("GeoGenfun::Varaible selection index out of bounds");
35  return a[_selectionIndex];
36 }
37 
38 unsigned int Variable::index() const {
39  return _selectionIndex;
40 }
41 
42 
43 Derivative Variable::partial(unsigned int mindex) const {
44  double kroneckerDelta = mindex==_selectionIndex ? 1.0 : 0.0;
45  KVector vec(_dimensionality,kroneckerDelta);
46  return Derivative(&vec);
47 }
48 
49 unsigned int Variable::dimensionality() const {
50  return _dimensionality;
51 }
52 
53 } // namespace GeoGenfun
Definition: Abs.h:15