This repository has been archived by the owner on Jul 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VectorGridFunction.tpp
255 lines (216 loc) · 7.36 KB
/
VectorGridFunction.tpp
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#include "VectorGridFunction.h"
//Constructor that initializes to a specific value. If inner vector size and
//array size are fixed, outer vector size may be zero and additional
//GridFunctions may be appended later.
template <class T>
VectorGridFunction<T>::VectorGridFunction(int outerVecSize,
int innerVecSize, int arraySize,
T initvalue):
VGFvectorDim(outerVecSize), GFvectorDim(innerVecSize), GFarrayDim(arraySize)
{
if(outerVecSize<0) {
cout << "Negative Vector dimensions at VectorGridFunction constructor." << endl;
}
for(int i=0; i<outerVecSize; i++) {
GridFunction<T> temp(innerVecSize,arraySize,initvalue);
data.push_back(temp);
}
}
//Uninitialized constructor. Same property for outerVecSize=0 as above.
template <class T>
VectorGridFunction<T>::VectorGridFunction(int outerVecSize,
int innerVecSize, int arraySize):
VGFvectorDim(outerVecSize), GFvectorDim(innerVecSize), GFarrayDim(arraySize)
{
if(outerVecSize<0){
cout << "Negative Vector dimensions at VectorGridFunction constructor." << endl;
}
for(int i = 0; i < outerVecSize; i++){
GridFunction<T> temp(innerVecSize,arraySize);
data.push_back(temp);
}
}
//Set the value of a specific point.
template <class T>
void VectorGridFunction<T>::set(int VGFvcoord, int GFvcoord, int GFacoord,
T value)
{
if((0 > VGFvcoord) || (VGFvcoord >= VGFvectorDim)){
cout << "Vector index out of range in set" << endl;
}
data.at(VGFvcoord).set(GFvcoord,GFacoord,value);
}
//Set an outer vector coordinate to a grid function.
template <class T>
void VectorGridFunction<T>::set(int VGFcoord, GridFunction<T> gf)
{
if((0 > VGFcoord) || (VGFcoord >= VGFvectorDim)){
cout << "Vector index out of range in set" << endl;
}
data.at(VGFcoord)=gf;
}
//Set an outer and inner vector coordinate to an vector.
template <class T>
void VectorGridFunction<T>::set(int VGFcoord, int GFcoord, std::vector<T> arr)
{
if((0 > VGFcoord)||(VGFcoord >= VGFvectorDim)){
cout << "Vector index out of range in set" << endl;
}
data.at(VGFcoord).set(GFcoord,arr);
}
//Set an inner vector coordinate and an array coordinate to a vector of values.
template <class T>
void VectorGridFunction<T>::setVector(int GFcoord, int GFacoord, vector<T> vec)
{
if((GFcoord < 0) || (GFacoord < 0) || (GFacoord > GFarrayDim)){
cout << "Coordinates in setVector out of range." << endl;
}
for(int i = 0; i < VGFvectorDim; i++){
data.at(i).set(GFcoord,GFacoord,vec[i]);
}
}
//Get the value of a specific point.
template <class T>
T VectorGridFunction<T>::get(int VGFvcoord, int GFvcoord, int GFacoord)
{
if((0 > VGFvcoord) || (VGFvcoord >= VGFvectorDim)){
cout << "Vector index out of range in get" << endl;
}
return data.at(VGFvcoord).get(GFvcoord,GFacoord);
}
//Get an array from an inner and outer vector coordinate.
template <class T>
vector<T> VectorGridFunction<T>::get(int VGFvcoord,int GFvcoord)
{
if((0 > VGFvcoord) || (VGFvcoord >= VGFvectorDim)){
cout << "Vector index out of range in get" << endl;
}
return data.at(VGFvcoord).get(GFvcoord);
}
//Get a GridFunction from an outer vector coordinate.
template <class T>
GridFunction<T> VectorGridFunction<T>::get(int VGFvcoord)
{
if((0 > VGFvcoord) || (VGFvcoord >= VGFvectorDim)){
cout << "Vector index out of range in get" << endl;
}
return data.at(VGFvcoord);
}
//Append a GridFunction to the end of the VectorGridFunction.
template <class T>
void VectorGridFunction<T>::append(GridFunction<T> gf)
{
VGFvectorDim++;
data.push_back(gf);
}
//May be obsolete.
template <class T>
void VectorGridFunction<T>::save(string filename)
{
ofstream fs;
fs.open(filename);
for(int j=0; j<GFvectorDim; j++){
for(int k = 0; k<GFarrayDim; k++){
for(int i=0; i<VGFvectorDim; i++){
fs << data.at(i).get(j,k) << " ";
}
fs << endl;
}
}
fs.close();
}
//Get a vector from an inner vector coordinate and an array coordinate.
template <class T>
vector<T> VectorGridFunction<T>::getVector(int GFvcoord, int GFacoord)
{
if((GFvcoord < 0) || (GFvcoord >= GFvectorDim) || (GFacoord < 0)
|| (GFacoord > GFarrayDim)) {
cout << "Get indices out of range." << endl;
}
vector<T> outputvec;
for(int i = 0; i < VGFvectorDim; i++) {
outputvec.push_back(get(i, GFvcoord, GFacoord));
}
return outputvec;
}
//Get an vector from an inner vector coordinate and an array coordinate,
//ranging from outer vector index vmin to vmax.
template <class T>
vector<T> VectorGridFunction<T>::getVectorRegion(int GFvcoord,
int GFacoord, int vmin,
int vmax)
{
if((GFvcoord < 0) || (GFvcoord >= GFvectorDim) || (GFacoord < 0)
|| (GFacoord > GFarrayDim)) {
cout << "Get indices out of range." << endl;
}
if((vmax > VGFvectorDim) || (vmin < 0)) {
cout << "Get max or min vector indices out of range" << endl;
}
vector<T> outputvec(vmax - vmin + 1);
for(int i = vmin; i <= vmax; i++){
outputvec[i - vmin] =get(i, GFvcoord, GFacoord);
}
return outputvec;
}
/*//Get an Array2D containing the values of the VGF at an inner vector
//coordinate, with the outer vector values running along the rows
//and the array values running along the columns. Begins selecting
//outer vector values at startvec and ends at stopvec.
template <class T>
Array2D<T> VectorGridFunction<T>::getVectorNodeArray2D(int GFcoord,
int startvec,
int stopvec)
{
if((GFcoord < 0) || (GFcoord > GFvectorDim)) {
cout << "Get indices out of range" << endl;
}
if((startvec < 0) || (stopvec >= VGFvectorDim)) {
cout << "Endpoints of vector requested are out of range" << endl;
}
Array2D<T> output(GFarrayDim, stopvec - startvec + 1);
for(int i = startvec; i <= stopvec; i++){
for(int j = 0; j < GFarrayDim; j++){
output[j][i - startvec]=get(i, GFcoord, j);
}
}
return output;
}*/
//-----------------------------
//not in class
//Addition operator for VectorGridFunctions.
template <typename T>
VectorGridFunction<T> operator+(VectorGridFunction<T> vgf1,
VectorGridFunction<T> vgf2)
{
if(vgf1.VGFdim() != vgf2.VGFdim()){
cout << "Vector dimension mismatch in + operation" << endl;
}
VectorGridFunction<T> vgfsum(0, vgf1.GFvecDim(), vgf1.GFarrDim());
for(int i = 0; i < vgf1.VGFdim(); i++){
vgfsum.append(vgf1.get(i) + vgf2.get(i));
}
return vgfsum;
}
//Scalar multiplication operator for VectorGridFunctions.
template <typename T>
VectorGridFunction<T> operator*(T A, VectorGridFunction<T> vgf)
//for easy multiplication in rk4 routine
{
VectorGridFunction<T> vgfprod(0, vgf.GFvecDim(), vgf.GFarrDim());
for(int i = 0; i < vgf.VGFdim(); i++){
vgfprod.append(A * vgf.get(i));
}
return vgfprod;
}
//Scalar multiplication operator for complex VectorGridFunctions.
template <typename T>
VectorGridFunction<complex<T>> operator*(T A, VectorGridFunction<complex<T>> vgf)
//for easy multiplication in rk4 routine
{
VectorGridFunction<complex<T>> vgfprod(0, vgf.GFvecDim(), vgf.GFarrDim());
for(int i = 0; i < vgf.VGFdim(); i++){
vgfprod.append(A * vgf.get(i));
}
return vgfprod;
}