tssa_code.mac - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tssa_code.mac (2246B)
---
1 /* This macro prints coefficients, taking care to replace powers and products
2 with shortcuts. This is necessary because Maxima prints x raised to the power n
3 as x^n, which does not match C syntax. */
4 print_coeffs(var) := block(
5 for r: 1 step -1 thru -1 do (
6 for c:-1 thru 1 do (
7 printf(file, " ~a, ",
8 subst([dx^2 = dx2,
9 dy^2 = dy2,
10 4*dx*dy = d4,
11 2*dx*dy = d2,
12 aPP^2 = aPP,
13 aMM^2 = aMM,
14 bPP^2 = bPP,
15 bMM^2 = bMM],
16 var[c,r]))
17 ),
18 printf(file, "~%")
19 )
20 )$
21
22 print_code(file_name, interior) := block(
23 load("ssa_coeffs.mac"),
24
25 file : openw(file_name),
26
27 /* Define shortcuts */
28 printf(file, "const double dx2 = dx*dx, dy2 = dy*dy, d4 = 4*dx*dy, d2 = 2*dx*dy;~%~%"),
29
30 printf(file,"/* Coefficients of the discretization of the first equation; u first, then v. */~%"),
31 printf(file, "double eq1[] = {~%"),
32 print_coeffs(c1u),
33 print_coeffs(c1v),
34 printf(file, "};~%~%"),
35
36 printf(file, "/* Coefficients of the discretization of the second equation; u first, then v. */~%"),
37 printf(file, "double eq2[] = {~%"),
38 print_coeffs(c2u),
39 print_coeffs(c2v),
40 printf(file, "};~%~%"),
41
42 printf(file, "/* i indices */~%"),
43 printf(file, "const int I[] = {~%"),
44 for v: 1 thru 2 do ( /* we have 2 variables */
45 for r: 1 step -1 thru -1 do (
46 for c: -1 thru 1 do (
47 printf(file, " ~a, ", i+c)
48 ),
49 printf(file, "~%")
50 )
51 ),
52 printf(file, "};~%~%"),
53
54 printf(file, "/* j indices */~%"),
55 printf(file, "const int J[] = {~%"),
56 for v: 1 thru 2 do ( /* we have 2 variables */
57 for r: 1 step -1 thru -1 do (
58 for c: -1 thru 1 do (
59 printf(file, " ~a, ", j+r)
60 ),
61 printf(file, "~%")
62 )
63 ),
64 printf(file, "};~%~%"),
65
66 printf(file, "/* component indices */~%"),
67 printf(file, "const int C[] = {~%"),
68 for v: 0 thru 1 do ( /* we have 2 variables */
69 for r: 1 step -1 thru -1 do (
70 for c: -1 thru 1 do (
71 printf(file, " ~d, ", v)
72 ),
73 printf(file, "~%")
74 )
75 ),
76 printf(file, "};~%~%"),
77
78 close(file)
79 )$
80
81 print_code("ssafd_code.cc", true)$
82