Layers
Diffusion in heterogeneous environments
Main Page
Related Pages
Data Structures
Files
File List
Globals
fit-layer
convo.c
Go to the documentation of this file.
1
73
#include <stdio.h>
74
#include <stdlib.h>
75
80
#define A(i,j) a[((i)*N+(j))]
81
86
#define OUT(i,j) out[((i)*N+(j))]
87
88
133
void
convolve3
(
int
M,
int
N,
double
*a,
double
scale1,
double
scale2,
double
*invr,
double
*out)
134
{
135
int
i, j;
136
137
// Calculate the inner part of the array first,
138
// then the edges and corners later
139
for
(i=1; i<M-1; i++)
140
for
(j=2; j<N-1; j++)
141
OUT
(i,j) = scale1 * (
142
A
(i-1,j)
143
+
A
(i,j-1) - 4. *
A
(i, j) +
A
(i,j+1)
144
+
A
(i+1,j) )
145
+ scale2 * ( (-
A
(i,j-1) +
A
(i,j+1))*invr[j]);
146
147
/* j=1: This is the r=0 row, so use L0 rather than L */
148
for
(i=1; i<M-1; i++)
149
OUT
(i,1) = scale1 * (
150
A
(i-1,1)
151
+ 2. *
A
(i,0) - 6. *
A
(i, 1) + 2. *
A
(i,2)
152
+
A
(i+1,1) );
153
154
// j=1, i=0
155
OUT
(0,1) = scale1 * (
156
2. *
A
(0,0) - 6. *
A
(0,1) + 2. *
A
(0,2)
157
+
A
(1,1) );
158
159
// j=1, i=M-1
160
OUT
(M-1,1) = scale1 * (
161
A
(M-2,1)
162
+ 2. *
A
(M-1,0) - 6. *
A
(M-1, 1) + 2. *
A
(M-1,2)
163
);
164
/* End of j=1 section */
165
166
167
// i=0
168
for
(j=1; j<N-1; j++)
169
OUT
(0,j) = scale1 * (
170
A
(0,j-1) - 4. *
A
(0,j) +
A
(0,j+1)
171
+
A
(1,j) )
172
+ scale2 * ( (-
A
(0,j-1) +
A
(0,j+1))*invr[j] );
173
174
// i=M-1
175
for
(j=1; j<N-1; j++)
176
OUT
(M-1,j) = scale1 * (
177
A
(M-2,j)
178
+
A
(M-1,j-1) - 4. *
A
(M-1,j) +
A
(M-1,j+1) )
179
+ scale2 * ( (-
A
(M-1,j-1) +
A
(M-1,j+1))*invr[j] );
180
181
// j=0
182
for
(i=1; i<M-1; i++)
183
OUT
(i,0) = scale1 * (
184
A
(i-1,0)
185
- 4. *
A
(i, 0) +
A
(i,1)
186
+
A
(i+1,0) )
187
+ scale2 * (
A
(i,1)*invr[0] );
188
189
// j=N-1
190
for
(i=1; i<M-1; i++)
191
OUT
(i,N-1) = scale1 * (
192
A
(i-1,N-1)
193
+
A
(i,N-2) - 4. *
A
(i, N-1)
194
+
A
(i+1,N-1) )
195
+ scale2 * ( -
A
(i,N-2)*invr[N-1] );
196
197
// i=0, j=0
198
OUT
(0,0) = scale1 * (
199
- 4. *
A
(0,0) +
A
(0,1)
200
+
A
(1,0) )
201
+ scale2 * (
A
(0,1)*invr[0] );
202
203
// i=0, j=N-1
204
OUT
(0,N-1) = scale1 * (
205
A
(0,N-2) - 4. *
A
(0,N-1)
206
+
A
(1,N-1) )
207
+ scale2 * ( -
A
(0,N-2)*invr[N-1] );
208
209
// i=M-1, j=0
210
OUT
(M-1,0) = scale1 * (
211
A
(M-2,0)
212
- 4. *
A
(M-1,0) +
A
(M-1,1) )
213
+ scale2 * (
A
(M-1,1)*invr[0] );
214
215
// i=M-1, j=N-1
216
OUT
(M-1,N-1) = scale1 * (
217
A
(M-2,N-1)
218
+
A
(M-1,N-2) - 4. *
A
(M-1,N-1) )
219
+ scale2 * ( -
A
(M-1,N-2)*invr[N-1] );
220
}
A
#define A(i, j)
Retrieves the appropriate element from the 1D 'a' array given pseudo-2D indices i (z index) and j (r ...
Definition:
convo.c:80
OUT
#define OUT(i, j)
Retrieves the appropriate element from the 1D 'out' array given pseudo-2D indices i (z index) and j (...
Definition:
convo.c:86
convolve3
void convolve3(int M, int N, double *a, double scale1, double scale2, double *invr, double *out)
Calculates updates to the concentration in a layer by applying the Laplacian in cylindrical coordinat...
Definition:
convo.c:133
Generated on Sun Aug 6 2017 18:21:12 for Layers by
1.8.11