| 1 |
/* |
| 2 |
* Advanced Simulation Library <http://asl.org.il> |
| 3 |
* |
| 4 |
* Copyright 2015 Avtech Scientific <http://avtechscientific.com> |
| 5 |
* |
| 6 |
* |
| 7 |
* This file is part of Advanced Simulation Library (ASL). |
| 8 |
* |
| 9 |
* ASL is free software: you can redistribute it and/or modify it |
| 10 |
* under the terms of the GNU Affero General Public License as |
| 11 |
* published by the Free Software Foundation, version 3 of the License. |
| 12 |
* |
| 13 |
* ASL is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Affero General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Affero General Public License |
| 19 |
* along with ASL. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
#include "aclComplexNumOfElements.h" |
| 25 |
#include "aclUtilities.h" |
| 26 |
#include "acl.h" |
| 27 |
#include "../aslUtilities.h" |
| 28 |
#include <algorithm> |
| 29 |
|
| 30 |
using namespace std; |
| 31 |
using asl::errorMessage; |
| 32 |
|
| 33 |
namespace acl |
| 34 |
{ |
| 35 |
ComplexNumOfElements::ComplexNumOfElements(): |
| 36 |
ve(2) |
| 37 |
{ |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
void ComplexNumOfElements::setRe(Element a) |
| 42 |
{ |
| 43 |
ve[0]=a; |
| 44 |
} |
| 45 |
|
| 46 |
void ComplexNumOfElements::setIm(Element a) |
| 47 |
{ |
| 48 |
ve[1]=a; |
| 49 |
} |
| 50 |
|
| 51 |
const Element ComplexNumOfElements::getRe() const |
| 52 |
{ |
| 53 |
return ve[0]; |
| 54 |
} |
| 55 |
|
| 56 |
const Element ComplexNumOfElements::getIm() const |
| 57 |
{ |
| 58 |
return ve[1]; |
| 59 |
} |
| 60 |
|
| 61 |
VectorOfElements & ComplexNumOfElements::getInternalVector() |
| 62 |
{ |
| 63 |
return ve; |
| 64 |
} |
| 65 |
|
| 66 |
const VectorOfElements & ComplexNumOfElements::getInternalVector() const |
| 67 |
{ |
| 68 |
return ve; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
void copy(const ComplexNumOfElements & source,ComplexNumOfElements destination) |
| 73 |
{ |
| 74 |
copy(source.getInternalVector(),destination.getInternalVector()); |
| 75 |
} |
| 76 |
|
| 77 |
ComplexNumOfElements operator+(ComplexNumOfElements & a,ComplexNumOfElements & b) |
| 78 |
{ |
| 79 |
ComplexNumOfElements m; |
| 80 |
copy(a.getInternalVector()+b.getInternalVector(),m.getInternalVector()); |
| 81 |
return m; |
| 82 |
} |
| 83 |
|
| 84 |
ComplexNumOfElements operator-(ComplexNumOfElements & a,ComplexNumOfElements & b) |
| 85 |
{ |
| 86 |
ComplexNumOfElements m; |
| 87 |
copy(a.getInternalVector()-b.getInternalVector(),m.getInternalVector()); |
| 88 |
return m; |
| 89 |
} |
| 90 |
|
| 91 |
ComplexNumOfElements operator*(const ComplexNumOfElements & a, const ComplexNumOfElements & b) |
| 92 |
{ |
| 93 |
ComplexNumOfElements m; |
| 94 |
using namespace elementOperators; |
| 95 |
m.setRe(a.getRe()*b.getRe()-a.getIm()*b.getIm()); |
| 96 |
m.setIm(a.getRe()*b.getIm()+a.getIm()*b.getRe()); |
| 97 |
return m; |
| 98 |
} |
| 99 |
|
| 100 |
} // namespace acl |