tssa_prettyprint.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_prettyprint.mac (3463B)
---
1 /* Tell Maxima how to pretty-print the following: */
2 texput(dx, "\\Delta x")$
3 texput(dy, "\\Delta y")$
4 texput(D_x, "\\Delta_x")$
5 texput(D_y, "\\Delta_y")$
6 texput(d_px, "\\delta_{+x}")$
7 texput(d_mx, "\\delta_{-x}")$
8 texput(d_py, "\\delta_{+y}")$
9 texput(d_my, "\\delta_{-y}")$
10 texput(c_w, "c_{w}")$
11 texput(c_e, "c_{e}")$
12 texput(c_n, "c_{n}")$
13 texput(c_s, "c_{s}")$
14
15 /* Expression simplification library */
16 load(scifac)$
17
18 /* Load the definition of the SSA discretization from ssa.mac */
19 load("ssa.mac")$
20
21 /* Print discretizations */
22
23 file : openw("formulas.tex")$
24
25 set_tex_environment_default("&\\displaystyle ", " & \\\\")$
26
27 /* The left hand side of the first equation */
28 printf(file, "\\newcommand{\\lhsI}{~%")$
29 for n: 1 thru 4 do tex(part(lhs1, n), file)$
30 printf(file, "}~%")$
31
32 /* The left hand side of the second equation */
33 printf(file, "\\newcommand{\\lhsII}{~%")$
34 for n: 1 thru 4 do tex(part(lhs2, n), file)$
35 printf(file, "}~%")$
36
37 /* Define weights and differences for pretty-printing (we don't need to use
38 actual definitions yet) */
39 a_p(var) := w[part(var,1) + 1/2, part(var,2)]$
40 a_m(var) := w[part(var,1) - 1/2, part(var,2)]$
41 b_p(var) := w[part(var,1), part(var,2) + 1/2]$
42 b_m(var) := w[part(var,1), part(var,2) - 1/2]$
43
44 d_px(foo) := a_p(foo) * delta[\+x](foo)$
45 d_mx(foo) := a_m(foo) * delta[\-x](foo)$
46
47 d_py(foo) := b_p(foo) * delta[\+y](foo)$
48 d_my(foo) := b_m(foo) * delta[\-y](foo)$
49
50 /* centered differences defined as sums of one-sided differences with weights */
51 D_x(foo) := d_px(foo) + d_mx(foo)$
52 D_y(foo) := d_py(foo) + d_my(foo)$
53
54 /* The left hand side of the first equation, expanded half way */
55 printf(file, "\\newcommand{\\lhsIII}{~%")$
56 for n: 1 thru 4 do tex(part(''lhs1, n), file)$
57 printf(file, "}~%")$
58
59 /* Compute coefficients: */
60
61 /* This macro defines a LaTeX command "name" and prints coefficients of a
62 variable "var" simplified using the function "func".
63
64 This is designed to go inside a "tabular" environment.
65 */
66 coeffs_grid(name, var, func) := block(
67 set_tex_environment_default("&$\\displaystyle ", "$"),
68 printf(file, "\\newcommand{\\~a}{~%", name),
69 printf(file, "&-1 & 0 & 1 \\\\\\hline~%"), /* i indices */
70 for n: 1 step -1 thru -1 do (
71 printf(file, "\\hline~%$~d$~%", n),
72
73 for m:-1 thru 1 do tex(func(var[m,n]), file),
74
75 printf(file, "\\\\~%")
76 ),
77 printf(file, "}~%")
78 )$
79
80 /* This macro defines a LaTeX command "name" and prints coefficient of a
81 variable "var" using "sup" as the superscript.
82
83 This is designed to go inside a "eqnarray" environment.
84 */
85 coeffs_list(name, sup, var) := block(
86 printf(file, "\\newcommand{\\~a}{~%", name),
87 for m: -1 thru 1 do (
88 for n: -1 thru 1 do (
89 printf(file, "C^{~a}_{~d,~d} &=& \\displaystyle ~a \\\\~%",
90 sup, m, n, tex1(gcfac(part(var[m,n],1)))),
91 printf(file, "&+& \\displaystyle ~a \\\\~%",
92 tex1(gcfac(part(var[m,n],2))))
93 )
94 ),
95 printf(file, "}~%")
96 )$
97
98 /* First in the interior */
99 interior : true;
100 load("ssa_coeffs.mac")$
101
102 /* u */
103 coeffs_grid("CUfirstInterior", c1u, gcfac)$
104 coeffs_grid("CUsecondInterior", c2u, ratsimp)$
105
106 /* v */
107 coeffs_grid("CVfirstInterior", c1v, ratsimp)$
108 coeffs_grid("CVsecondInterior", c2v, gcfac)$
109
110 /* Now at the boundary */
111 interior : false;
112 load("ssa_coeffs.mac")$
113
114 /* u */
115 coeffs_grid("CUfirstMargin", c1u, gcfac)$
116 coeffs_list("CUsecondMargin", "u,2", c2u)$
117
118 /* v */
119 coeffs_list("CVfirstMargin", "v,1", c1v)$
120 coeffs_grid("CVsecondMargin", c2v, gcfac)$
121
122 /* Close the file */
123