-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfdvecarray.hpp
105 lines (89 loc) · 3.64 KB
/
fdvecarray.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
fdvecarray.hpp (Multigrid)
Jess Robertson, 2011-01-28
Two-dimensional vector array class
*/
#ifndef FDVECARRAY_HPP_IF30D0T0
#define FDVECARRAY_HPP_IF30D0T0
#include "fdbase.hpp"
#include "fdarray.hpp"
namespace mgrid {
class FDVecArray: public FDBase, public blitz::Array<double, 3> {
public:
FDVecArray(const double aspectRatio, const int nx, const int nz);
FDVecArray() {};
virtual ~FDVecArray() {};
// Override base method for array resizing and boundary conditions
inline virtual
void resize(const double aspectRatio, const int nx, const int nz);
inline virtual
void reference(FDVecArray array);
inline virtual
void reference(blitz::Array<double, 3> array);
// Component arrays
FDArray first, second;
// Derivative methods
void magnitude(ArrayType& result);
void divergence(ArrayType& result);
// Writing method
void write(std::string filestring);
// Explicitly inherit operators from blitz::Array, since
// these are not inherited by default.
using blitz::Array<double, 3>::operator=;
using blitz::Array<double, 3>::operator+=;
using blitz::Array<double, 3>::operator-=;
using blitz::Array<double, 3>::operator*=;
using blitz::Array<double, 3>::operator/=;
// Overload operators to use FDArray input. These employ the same templates
// from blitz, but stop the compiler complaining about FDVecArray types.
inline FDVecArray& operator=(const FDVecArray& x);
inline FDVecArray& operator+=(const FDVecArray& x);
inline FDVecArray& operator-=(const FDVecArray& x);
inline FDVecArray& operator*=(const FDVecArray& x);
inline FDVecArray& operator/=(const FDVecArray& x);
};
// Overloaded methods from blitz
inline void FDVecArray::resize(const double aspect, const int nx, const int nz) {
calculate_geometry(aspect, nx, nz);
blitz::Array<double, 3>::resize(nx, nz, 2);
// Generate component arrays
first.calculate_geometry(aspect, nx, nz);
second.calculate_geometry(aspect, nx, nz);
first.reference((*this)(blitz::Range::all(), blitz::Range::all(), 0));
second.reference((*this)(blitz::Range::all(), blitz::Range::all(), 1));
}
inline void FDVecArray::reference(FDVecArray array) {
calculate_geometry(array.aspectRatio, array.rows(), array.columns());
blitz::Array<double, 3>::reference(array);
}
inline void FDVecArray::reference(blitz::Array<double, 3> array) {
blitz::Array<double, 3>::reference(array);
}
// Overloaded operators for FDVecArray
inline FDVecArray& FDVecArray::operator=(const FDVecArray& x) {
using namespace blitz;
(*this) = _bz_ArrayExpr<FastArrayIterator<double, 3> >(x.beginFast());
return (*this);
}
inline FDVecArray& FDVecArray::operator+=(const FDVecArray& x) {
using namespace blitz;
(*this) += _bz_ArrayExpr<FastArrayIterator<double, 3> >(x.beginFast());
return (*this);
}
inline FDVecArray& FDVecArray::operator-=(const FDVecArray& x) {
using namespace blitz;
(*this) -= _bz_ArrayExpr<FastArrayIterator<double, 3> >(x.beginFast());
return (*this);
}
inline FDVecArray& FDVecArray::operator*=(const FDVecArray& x) {
using namespace blitz;
(*this) *= _bz_ArrayExpr<FastArrayIterator<double, 3> >(x.beginFast());
return (*this);
}
inline FDVecArray& FDVecArray::operator/=(const FDVecArray& x) {
using namespace blitz;
(*this) /= _bz_ArrayExpr<FastArrayIterator<double, 3> >(x.beginFast());
return (*this);
}
} // end namespace mgrid
#endif /* end of include guard: FDVECARRAY_HPP_IF30D0T0 */