OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
LinearFun.h
Go to the documentation of this file.
1#ifndef CLASSIC_LinearFun_HH
2#define CLASSIC_LinearFun_HH
3
4// ------------------------------------------------------------------------
5// $RCSfile: LinearFun.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.1.1.1 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Template class: LinearFun<T,N>
13//
14// ------------------------------------------------------------------------
15// Class category: FixedAlgebra
16// ------------------------------------------------------------------------
17//
18// $Date: 2000/03/27 09:32:36 $
19// $Author: fci $
20//
21// ------------------------------------------------------------------------
22
23#include <iosfwd>
24
25template <class T, int N> class FVector;
26template <class T, int N> class LinearMap;
27template <class T, int M, int N> class FMatrix;
28
29
30// Template class LinearFun<T,N>.
31// ------------------------------------------------------------------------
33// All divide operations throw DivideError,
34// if the constant part of the divisor is zero.
35// The copy constructor, destructor, and assignment operator generated
36// by the compiler do the correct thing, and are not defined for speed.
37
38template <class T, int N>
39class LinearFun {
40
41public:
42
44 // Construct zero value.
45 LinearFun();
46
48 LinearFun(const T &);
49
51 LinearFun(int);
52
54 LinearFun &operator=(const T &y);
55
57 // Return value of the coefficient denoted by the index.
58 // The index zero stands for the constant term,
59 // any other value selects the derivative by the variable index+1.
60 // Return zero, if index is out of range.
61 const T getCoefficient(int index) const;
62
64 // Assign value of the coefficient denoted by the index.
65 // The index zero stands for the constant term,
66 // any other value selects the derivative by the variable index+1.
67 // Ignore, if index is out of range.
68 void setCoefficient(int index, const T &value);
69
71 // Return value of the coefficient denoted by the index.
72 // The index zero stands for the constant term,
73 // any other value selects the derivative by the variable index+1.
74 // Result is undefined, if index is out of range.
75 inline const T operator[](int index) const;
76
78 // Return a reference to the coefficient denoted by the index.
79 // Result is undefined, if index is out of range.
80 // The index zero stands for the constant term,
81 // any other value selects the derivative by the variable index+1.
82 // Use as a lvalue is only allowed when the LinearFun is unique().
83 inline T &operator[](int index);
84
86 // Construct the variable identified by the index [b]var[/b],
87 // with total of [b]nVar[/b] variables.
88 static LinearFun makeVariable(int var);
89
91 LinearFun operator+() const;
92
94 LinearFun operator-() const;
95
98
100 LinearFun &operator-=(const LinearFun &y);
101
103 LinearFun &operator*=(const LinearFun &y);
104
106 LinearFun &operator/=(const LinearFun &y);
107
109 LinearFun &operator+=(const T &y);
110
112 LinearFun &operator-=(const T &y);
113
115 LinearFun &operator*=(const T &y);
116
118 LinearFun &operator/=(const T &y);
119
121 bool operator==(const LinearFun &y) const;
122
124 bool operator==(const T &y) const;
125
127 bool operator!=(const LinearFun &y) const;
128
130 bool operator!=(const T &y) const;
131
133 LinearFun inverse() const;
134
136 LinearFun multiply(const LinearFun &y) const;
137
139 T evaluate(const FVector<T, N> &) const;
140
142 // Substitute map [b]m[/b] in LinearFun, giving new LinearFun.
144
146 // Substitute matrix [b]M[/b] in LinearFun, giving new LinearFun.
148
150 // Expand Taylor series with coefficiens [b]series[/b] and order one.
151 LinearFun taylor(const T series[2]) const;
152
154 std::istream &get(std::istream &is);
155
157 std::ostream &put(std::ostream &os) const;
158
159private:
160
162 // data[0] is the constant term,
163 // data[v+1] is the coefficient of variable [b]v[/b].
164 T data[N+1];
165};
166
167
168// Global functions.
169// ------------------------------------------------------------------------
170
172template <class T, int N>
174
176template <class T, int N>
178
180template <class T, int N>
182
184template <class T, int N>
186
188template <class T, int N>
190
192template <class T, int N>
194
196template <class T, int N>
198
200template <class T, int N>
202
204template <class T, int N>
206
208template <class T, int N>
210
212template <class T, int N>
214
216template <class T, int N>
218
220template <class T, int N>
221bool operator==(const T &, const LinearFun<T, N> &);
222
224template <class T, int N>
225bool operator!=(const T &, const LinearFun<T, N> &);
226
228template <class T, int N>
229std::istream &operator>>(std::istream &is, LinearFun<T, N> &);
230
232template <class T, int N>
233std::ostream &operator<<(std::ostream &os, const LinearFun<T, N> &);
234
235
236// Implementation.
239
240#endif // CLASSIC_LinearFun_HH
std::ostream & operator<<(std::ostream &os, const LinearFun< T, N > &)
Insert LinearFun to stream [b]os[/b].
Definition: LinearFun.hpp:475
LinearFun< T, N > operator/(const LinearFun< T, N > &, const LinearFun< T, N > &)
Divide.
Definition: LinearFun.hpp:424
bool operator!=(const T &, const LinearFun< T, N > &)
Inequality.
Definition: LinearFun.hpp:463
std::istream & operator>>(std::istream &is, LinearFun< T, N > &)
Extract LinearFun from stream [b]is[/b].
Definition: LinearFun.hpp:469
LinearFun< T, N > operator*(const LinearFun< T, N > &, const LinearFun< T, N > &)
Multiply.
Definition: LinearFun.hpp:418
LinearFun< T, N > operator-(const LinearFun< T, N > &, const LinearFun< T, N > &)
Subtract.
Definition: LinearFun.hpp:383
LinearFun< T, N > operator+(const LinearFun< T, N > &, const LinearFun< T, N > &)
Add.
Definition: LinearFun.hpp:376
bool operator==(const T &, const LinearFun< T, N > &)
Equality.
Definition: LinearFun.hpp:457
A templated representation for matrices.
Definition: FMatrix.h:39
A templated representation for vectors.
Definition: FVector.h:38
Linear map with values of type [b]T[/b] in [b]N[/b] variables.
Definition: LinearMap.h:38
Linear function in N variables of type T.
Definition: LinearFun.h:39
LinearFun & operator=(const T &y)
Convert and assign.
Definition: LinearFun.hpp:59
const T operator[](int index) const
Get coefficient.
Definition: LinearFun.hpp:79
LinearFun & operator-=(const LinearFun &y)
Subtract and assign.
Definition: LinearFun.hpp:121
const T getCoefficient(int index) const
Get coefficient.
Definition: LinearFun.hpp:67
std::istream & get(std::istream &is)
Read LinearFun on the stream [b]is[/b].
Definition: LinearFun.hpp:290
void setCoefficient(int index, const T &value)
Set coefficient.
Definition: LinearFun.hpp:73
LinearFun< T, N > substitute(const LinearMap< T, N > &m) const
Substitute.
Definition: LinearFun.hpp:262
LinearFun multiply(const LinearFun &y) const
Multiplication truncated to order one.
Definition: LinearFun.hpp:226
T evaluate(const FVector< T, N > &) const
Evaluate LinearFun at point.
Definition: LinearFun.hpp:239
T data[N+1]
Representation.
Definition: LinearFun.h:164
LinearFun & operator+=(const LinearFun &y)
Add and assign.
Definition: LinearFun.hpp:114
LinearFun taylor(const T series[2]) const
Taylor series.
Definition: LinearFun.hpp:277
bool operator!=(const LinearFun &y) const
Inequality operator.
Definition: LinearFun.hpp:199
LinearFun operator-() const
Unary minus.
Definition: LinearFun.hpp:106
LinearFun operator+() const
Unary plus.
Definition: LinearFun.hpp:100
LinearFun & operator/=(const LinearFun &y)
Approximate division and assignation.
Definition: LinearFun.hpp:134
bool operator==(const LinearFun &y) const
Equality operator.
Definition: LinearFun.hpp:177
LinearFun & operator*=(const LinearFun &y)
Multiply and assign.
Definition: LinearFun.hpp:128
static LinearFun makeVariable(int var)
Make variable.
Definition: LinearFun.hpp:91
LinearFun()
Default constructor.
Definition: LinearFun.hpp:39
LinearFun inverse() const
Approximate reciprocal value 1/(*this).
Definition: LinearFun.hpp:211
std::ostream & put(std::ostream &os) const
Write LinearFun on the stream [b]os[/b].
Definition: LinearFun.hpp:343