Diffusion¶
\[\dtempdif{1}\]
209static int diffusion_x (
210 const domain_t * domain,
211 const double diffusivity,
212 const double * restrict t,
213 double * restrict src
214) {
215 const int isize = domain->mysizes[0];
216 const int jsize = domain->mysizes[1];
217#if NDIMS == 3
218 const int ksize = domain->mysizes[2];
219#endif
220 const laplacian_t * lapx = laplacians.lapx;
221 BEGIN
222 src[cnt] += diffusivity * (
223#if NDIMS == 2
224 + LAPX(i).l * T(i-1, j )
225 + LAPX(i).c * T(i , j )
226 + LAPX(i).u * T(i+1, j )
227#else
228 + LAPX(i).l * T(i-1, j , k )
229 + LAPX(i).c * T(i , j , k )
230 + LAPX(i).u * T(i+1, j , k )
231#endif
232 );
233 END
234 return 0;
235}
33const int isize = domain->glsizes[0];
34const double * hxxf = domain->hxxf;
35const double * jdxf = domain->jdxf;
36const double * jdxc = domain->jdxc;
37laplacians.lapx = memory_calloc(isize, sizeof(laplacian_t));
38for (int i = 1; i <= isize; i++) {
39 const double l = 1. / JDXC(i ) * JDXF(i ) / HXXF(i ) / HXXF(i );
40 const double u = 1. / JDXC(i ) * JDXF(i+1) / HXXF(i+1) / HXXF(i+1);
41 const double c = - l - u;
42 laplacians.LAPX(i).l = l;
43 laplacians.LAPX(i).c = c;
44 laplacians.LAPX(i).u = u;
45}
\[\dtempdif{2}\]
238static int diffusion_y (
239 const domain_t * domain,
240 const double diffusivity,
241 const double * restrict t,
242 double * restrict src
243) {
244 const int isize = domain->mysizes[0];
245 const int jsize = domain->mysizes[1];
246#if NDIMS == 3
247 const int ksize = domain->mysizes[2];
248#endif
249 const laplacian_t * lapy = &laplacians.lapy;
250 BEGIN
251 src[cnt] += diffusivity * (
252#if NDIMS == 2
253 + (*lapy).l * T(i , j-1)
254 + (*lapy).c * T(i , j )
255 + (*lapy).u * T(i , j+1)
256#else
257 + (*lapy).l * T(i , j-1, k )
258 + (*lapy).c * T(i , j , k )
259 + (*lapy).u * T(i , j+1, k )
260#endif
261 );
262 END
263 return 0;
264}
49const double hy = domain->hy;
50const double l = 1. / hy / hy;
51const double u = 1. / hy / hy;
52const double c = - l - u;
53laplacians.lapy.l = l;
54laplacians.lapy.c = c;
55laplacians.lapy.u = u;
\[\dtempdif{3}\]
268static int diffusion_z (
269 const domain_t * domain,
270 const double diffusivity,
271 const double * restrict t,
272 double * restrict src
273) {
274 const int isize = domain->mysizes[0];
275 const int jsize = domain->mysizes[1];
276 const int ksize = domain->mysizes[2];
277 const laplacian_t * lapz = &laplacians.lapz;
278 BEGIN
279 src[cnt] += diffusivity * (
280 + (*lapz).l * T(i , j , k-1)
281 + (*lapz).c * T(i , j , k )
282 + (*lapz).u * T(i , j , k+1)
283 );
284 END
285 return 0;
286}
60const double hz = domain->hz;
61const double l = 1. / hz / hz;
62const double u = 1. / hz / hz;
63const double c = - l - u;
64laplacians.lapz.l = l;
65laplacians.lapz.c = c;
66laplacians.lapz.u = u;