PLaSK library
Loading...
Searching...
No Matches
tnt_fortran_array3d_utils.h
Go to the documentation of this file.
1
/*
2
*
3
* Template Numerical Toolkit (TNT)
4
*
5
* Mathematical and Computational Sciences Division
6
* National Institute of Technology,
7
* Gaithersburg, MD USA
8
*
9
*
10
* This software was developed at the National Institute of Standards and
11
* Technology (NIST) by employees of the Federal Government in the course
12
* of their official duties. Pursuant to title 17 Section 105 of the
13
* United States Code, this software is not subject to copyright protection
14
* and is in the public domain. NIST assumes no responsibility whatsoever for
15
* its use by other parties, and makes no guarantees, expressed or implied,
16
* about its quality, reliability, or any other characteristic.
17
*
18
*/
19
20
21
#ifndef TNT_FORTRAN_ARRAY3D_UTILS_H
22
#define TNT_FORTRAN_ARRAY3D_UTILS_H
23
24
#include <cstdlib>
25
#include <cassert>
26
27
namespace
TNT
28
{
29
30
31
template
<
class
T>
32
std::ostream&
operator<<
(std::ostream &s,
const
Fortran_Array3D<T>
&A)
33
{
34
int
M=A.dim1();
35
int
N
=A.dim2();
36
int
K
=A.dim3();
37
38
s << M <<
" "
<<
N
<<
" "
<<
K
<<
"\n"
;
39
40
for
(
int
i=1; i<=M; i++)
41
{
42
for
(
int
j=1; j<=
N
; j++)
43
{
44
for
(
int
k=1; k<=
K
; k++)
45
s << A(i,j,k) <<
" "
;
46
s <<
"\n"
;
47
}
48
s <<
"\n"
;
49
}
50
51
52
return
s;
53
}
54
55
template
<
class
T>
56
std::istream&
operator>>
(std::istream &s,
Fortran_Array3D<T>
&A)
57
{
58
59
int
M,
N
,
K
;
60
61
s >> M >>
N
>>
K
;
62
63
Fortran_Array3D<T>
B(M,
N
,
K
);
64
65
for
(
int
i=1; i<=M; i++)
66
for
(
int
j=1; j<=
N
; j++)
67
for
(
int
k=1; k<=
K
; k++)
68
s >> B(i,j,k);
69
70
A = B;
71
return
s;
72
}
73
74
75
template
<
class
T>
76
Fortran_Array3D<T>
operator+
(
const
Fortran_Array3D<T>
&A,
const
Fortran_Array3D<T>
&B)
77
{
78
int
m = A.dim1();
79
int
n
= A.dim2();
80
int
p = A.dim3();
81
82
if
(B.dim1() != m || B.dim2() !=
n
|| B.dim3() != p )
83
return
Fortran_Array3D<T>
();
84
85
else
86
{
87
Fortran_Array3D<T>
C(m,
n
,p);
88
89
for
(
int
i=1; i<=m; i++)
90
for
(
int
j=1; j<=
n
; j++)
91
for
(
int
k=1; k<=p; k++)
92
C(i,j,k) = A(i,j,k)+ B(i,j,k);
93
94
return
C;
95
}
96
}
97
98
99
template
<
class
T>
100
Fortran_Array3D<T>
operator-
(
const
Fortran_Array3D<T>
&A,
const
Fortran_Array3D<T>
&B)
101
{
102
int
m = A.dim1();
103
int
n
= A.dim2();
104
int
p = A.dim3();
105
106
if
(B.dim1() != m || B.dim2() !=
n
|| B.dim3() != p )
107
return
Fortran_Array3D<T>
();
108
109
else
110
{
111
Fortran_Array3D<T>
C(m,
n
,p);
112
113
for
(
int
i=1; i<=m; i++)
114
for
(
int
j=1; j<=
n
; j++)
115
for
(
int
k=1; k<=p; k++)
116
C(i,j,k) = A(i,j,k)- B(i,j,k);
117
118
return
C;
119
}
120
}
121
122
123
template
<
class
T>
124
Fortran_Array3D<T>
operator*
(
const
Fortran_Array3D<T>
&A,
const
Fortran_Array3D<T>
&B)
125
{
126
int
m = A.dim1();
127
int
n
= A.dim2();
128
int
p = A.dim3();
129
130
if
(B.dim1() != m || B.dim2() !=
n
|| B.dim3() != p )
131
return
Fortran_Array3D<T>
();
132
133
else
134
{
135
Fortran_Array3D<T>
C(m,
n
,p);
136
137
for
(
int
i=1; i<=m; i++)
138
for
(
int
j=1; j<=
n
; j++)
139
for
(
int
k=1; k<=p; k++)
140
C(i,j,k) = A(i,j,k)* B(i,j,k);
141
142
return
C;
143
}
144
}
145
146
147
template
<
class
T>
148
Fortran_Array3D<T>
operator/
(
const
Fortran_Array3D<T>
&A,
const
Fortran_Array3D<T>
&B)
149
{
150
int
m = A.dim1();
151
int
n
= A.dim2();
152
int
p = A.dim3();
153
154
if
(B.dim1() != m || B.dim2() !=
n
|| B.dim3() != p )
155
return
Fortran_Array3D<T>
();
156
157
else
158
{
159
Fortran_Array3D<T>
C(m,
n
,p);
160
161
for
(
int
i=1; i<=m; i++)
162
for
(
int
j=1; j<=
n
; j++)
163
for
(
int
k=1; k<=p; k++)
164
C(i,j,k) = A(i,j,k)/ B(i,j,k);
165
166
return
C;
167
}
168
}
169
170
171
template
<
class
T>
172
Fortran_Array3D<T>
&
operator+=
(
Fortran_Array3D<T>
&A,
const
Fortran_Array3D<T>
&B)
173
{
174
int
m = A.dim1();
175
int
n
= A.dim2();
176
int
p = A.dim3();
177
178
if
(B.dim1() == m && B.dim2() ==
n
&& B.dim3() == p )
179
{
180
for
(
int
i=1; i<=m; i++)
181
for
(
int
j=1; j<=
n
; j++)
182
for
(
int
k=1; k<=p; k++)
183
A(i,j,k) += B(i,j,k);
184
}
185
186
return
A;
187
}
188
189
190
template
<
class
T>
191
Fortran_Array3D<T>
&
operator-=
(
Fortran_Array3D<T>
&A,
const
Fortran_Array3D<T>
&B)
192
{
193
int
m = A.dim1();
194
int
n
= A.dim2();
195
int
p = A.dim3();
196
197
if
(B.dim1() == m && B.dim2() ==
n
&& B.dim3() == p )
198
{
199
for
(
int
i=1; i<=m; i++)
200
for
(
int
j=1; j<=
n
; j++)
201
for
(
int
k=1; k<=p; k++)
202
A(i,j,k) -= B(i,j,k);
203
}
204
205
return
A;
206
}
207
208
209
template
<
class
T>
210
Fortran_Array3D<T>
&
operator*=
(
Fortran_Array3D<T>
&A,
const
Fortran_Array3D<T>
&B)
211
{
212
int
m = A.dim1();
213
int
n
= A.dim2();
214
int
p = A.dim3();
215
216
if
(B.dim1() == m && B.dim2() ==
n
&& B.dim3() == p )
217
{
218
for
(
int
i=1; i<=m; i++)
219
for
(
int
j=1; j<=
n
; j++)
220
for
(
int
k=1; k<=p; k++)
221
A(i,j,k) *= B(i,j,k);
222
}
223
224
return
A;
225
}
226
227
228
template
<
class
T>
229
Fortran_Array3D<T>
&
operator/=
(
Fortran_Array3D<T>
&A,
const
Fortran_Array3D<T>
&B)
230
{
231
int
m = A.dim1();
232
int
n
= A.dim2();
233
int
p = A.dim3();
234
235
if
(B.dim1() == m && B.dim2() ==
n
&& B.dim3() == p )
236
{
237
for
(
int
i=1; i<=m; i++)
238
for
(
int
j=1; j<=
n
; j++)
239
for
(
int
k=1; k<=p; k++)
240
A(i,j,k) /= B(i,j,k);
241
}
242
243
return
A;
244
}
245
246
247
}
// namespace TNT
248
249
#endif
solvers
gain
wasiak
wzmocnienie
tnt
tnt_fortran_array3d_utils.h
Generated by
1.9.8