Skip to content

Commit 096ca48

Browse files
authored
Merge pull request #51 from ambrad/ambrad/islet2-methods-update
Islet2 methods update
2 parents 17053af + 4fbc91d commit 096ca48

15 files changed

+1044
-176
lines changed

methods/islet/figures/figs-adv-diag.hy

+327-78
Large diffs are not rendered by default.

methods/islet/figures/figs-methods.hy

+13-9
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@
440440
(defn norm->str [n]
441441
(get {:l1 "$l_1$" :l2 "$l_2$" :li "$l_{\infty}$"} n))
442442

443-
(defn plot1-slmmir-vs-heuristic [c d nps prop-preserve ic norm pum-thr lebesgue]
443+
(defn plot1-slmmir-vs-heuristic [c d nps prop-preserve ic norm pum-thr lebesgue
444+
&optional [jcp False]]
444445
(sv npa npy.array fs 11
445446
plot (if lebesgue pl.semilogy pl.loglog))
446447
(for [np nps]
@@ -466,7 +467,10 @@
466467
:fontsize fs)))
467468
(my-grid)
468469
(pl.title (.format (+ "Test problem vs.~heuristic:\n"
469-
"nondivergent flow, 1.5$^\circ$, {}, long steps\n"
470+
"nondivergent flow, "
471+
(if jcp "$n_e = 20$, " "1.5$^\circ$, ")
472+
"{}, "
473+
(if jcp "120 steps\n" "long steps\n")
470474
"$p$-refinement, {}")
471475
(futils.ic-short2long ic)
472476
(+ (if prop-preserve "" "no ") "property preservation"))
@@ -498,7 +502,7 @@
498502
(sv t (nth norm-pp-ic-tuples i))
499503
(pl.subplot 1 2 (inc i))
500504
(plot1-slmmir-vs-heuristic c d nps (nth t 1) (nth t 2) (nth t 0) pum-thr
501-
lebesgue)
505+
lebesgue :jcp True)
502506
(sv f (pl.gcf))
503507
(f.text (nth (, 0.02 0.52) i) 0.05 (nth (, "(a)" "(b)") i)
504508
:fontsize fs))))
@@ -644,7 +648,7 @@
644648
;;; drivers
645649

646650
(when-inp ["dev-parse"]
647-
(sv fname "data/search-0.txt"
651+
(sv fname "data/mar21/search-0.txt"
648652
blns (parse-search-list fname))
649653
(print (len blns))
650654
(for [b blns]
@@ -664,7 +668,7 @@
664668
"search-findnodal_given_bestosn-7.txt")
665669
blns [])
666670
(for [fname data-fnames]
667-
(.extend blns (parse-search-list (+ "data/" fname))))
671+
(.extend blns (parse-search-list (+ "data/mar21/" fname))))
668672
(sv blns (uniquify-search-list blns))
669673
(write-slmmir-script blns script-fname))
670674

@@ -674,7 +678,7 @@
674678
lebesgue False
675679
d {})
676680
(for [fname fnames]
677-
(sv d (parse-slmmir-output (+ "data/" fname) :d d :lebesgue lebesgue)))
681+
(sv d (parse-slmmir-output (+ "data/mar21/" fname) :d d :lebesgue lebesgue)))
678682
(for [(, norm pp ic) (, (, :l2 False "gau") (, :l2 True "cos"))]
679683
(plot-slmmir-vs-heuristic
680684
c d (.format (+ "{}slmmir-vs-heuristic-{}-{}-{}" (if lebesgue "-leb" ""))
@@ -688,7 +692,7 @@
688692
lebesgue False
689693
d {})
690694
(for [fname fnames]
691-
(sv d (parse-slmmir-output (+ "data/" fname) :d d :lebesgue lebesgue)))
695+
(sv d (parse-slmmir-output (+ "data/mar21/" fname) :d d :lebesgue lebesgue)))
692696
(plot-slmmir-vs-heuristic-ab
693697
c d (+ c.fig-dir "slmmir-vs-heuristic-ab")
694698
(, (, :l2 False "gau") (, :l2 True "cos"))
@@ -702,13 +706,13 @@
702706

703707
(when-inp ["pum-vs-perturb"]
704708
(sv fname "pum_perturb_plot-041021.txt"
705-
d (parse-pum-vs-perturb (+ "data/" fname))
709+
d (parse-pum-vs-perturb (+ "data/mar21/" fname))
706710
c (futils.get-context))
707711
(plot-pum-vs-perturb c d (+ c.fig-dir "pum-vs-perturb")))
708712

709713
(when-inp ["meam1-and-pum-vs-dx"]
710714
(sv c (futils.get-context)
711-
data-dir "data/"
715+
data-dir "data/mar21/"
712716
meam1-fname (+ data-dir "run_meam1_sweep-np8.txt")
713717
method-fnames (zip (, "gll_best" "gll_natural" "uniform_offset_nodal_subset")
714718
(lfor fname (, "pum_sweep-np8-gll_best.txt"

methods/islet/figures/figs-vortex.hy

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
(require [amb3 [*]])
2+
(import [amb3 [*]]
3+
[figsutils [*]]
4+
math colorsys)
5+
6+
(assoc matplotlib.rcParams "savefig.dpi" 300)
7+
(do (pl-require-type1-fonts))
8+
9+
(defn get-errs [d ne np cycle]
10+
(get d "exact" "movingvortices" 1 "pcsl" "none" "none" 0 np "vor" cycle ne :C))
11+
12+
(defn make-vortex-cmap []
13+
(sv lsc (fn [colors lo hi n]
14+
((matplotlib.colors.LinearSegmentedColormap.from-list
15+
"filament" colors 11)
16+
(npy.linspace lo hi n)))
17+
h2r colorsys.hsv-to-rgb
18+
s 0.2
19+
red (lsc [(h2r 0 1 1) (h2r 0 s 1)] 0 1 11)
20+
b (/ 2 3)
21+
blue (lsc [(h2r b 1 1) (h2r b s 1)] 1 0 11)
22+
cmap (matplotlib.colors.ListedColormap
23+
(npy.concatenate (, blue red) :axis 0)))
24+
cmap)
25+
26+
(defn fig-vortex [c d configs]
27+
(print "TODO config labels")
28+
(defn draw-circle []
29+
(sv th (npy.linspace 0 (* 2 math.pi) 512)
30+
r 0.995
31+
x (* r (npy.cos th)) y (* r (npy.sin th))
32+
g 0.8)
33+
(pl.plot x y "-" :lw 0.75 :color [g g g]))
34+
(sv ncol (len configs)
35+
fs 11
36+
cmap (make-vortex-cmap)
37+
ecmap (matplotlib.colors.LinearSegmentedColormap.from-list
38+
"filament" [[1 1 1] [0 0 0]]))
39+
(with [(pl-plot (, (* 2 ncol) 4) (+ c.fig-dir "vortex")
40+
:format "png"
41+
:tight False)]
42+
(for [(, icon config) (enumerate configs)]
43+
(sv (, ne np nstep cycle recon) config
44+
e (get-errs d ne np cycle)
45+
arrs (read-slmmir-io-arrays
46+
(+ c.data-dir f"vortex-imgs/ne{ne}np{np}nstep{nstep}{recon}.bin")))
47+
(sv img (get arrs (+ 1 (* 3 cycle)))
48+
diff (/ (npy.abs (- img (get arrs (+ 2 (* 3 cycle)))))
49+
(npy.max (npy.abs (get arrs (+ 2 (* 3 cycle))))))
50+
imgs [img diff])
51+
(for [i (range 2)]
52+
(sv img (get imgs i)
53+
mask (!= img 0)
54+
ext (, (npy.min (get img mask)) (npy.max img)))
55+
(when (zero? i)
56+
(sv nmask (npy.logical-not mask)))
57+
(sv (get img nmask) npy.nan)
58+
(print "corner" (get img (, 0 0)))
59+
(print "ext" ext)
60+
(if (zero? i)
61+
(sv vmin 0.45 vmax 1.55)
62+
(sv vmax (get e :li)
63+
vmin 0))
64+
(sv rect [(/ icon ncol) (- 1 (* i 0.5))
65+
(/ 0.97 ncol) (* 0.97 0.5)]
66+
ax (pl.axes rect))
67+
(pl.imshow img :cmap (if (zero? i) cmap ecmap)
68+
:vmin vmin :vmax vmax
69+
:origin "upper"
70+
:extent [-1 1 -1 1])
71+
(pl.axis "off")
72+
(pl.text -1 -1
73+
(.format "({})" (if (zero? i)
74+
(get "abcd" icon)
75+
(get "efgh" icon)))
76+
:ha "left" :va "bottom" :fontsize fs)
77+
(draw-circle)
78+
(unless (zero? i)
79+
(pl.text 0 0.5
80+
(.format "$n_e \, {}$, $n_p \, {}$, cycle {}, $n_{{step}} \, {}$\n"
81+
ne np cycle (* cycle nstep))
82+
:ha "center" :fontsize fs)
83+
(unless (= recon "constant")
84+
(for [k (range 3)]
85+
(pl.text -0.4 (+ 0.0 (* 0.2 (- 2 k)))
86+
(.format (+ (get ["$l_1$" "$l_2$" "$l_{{\infty}}$"] k)
87+
" {:1.2e}")
88+
(get e (get (, :l1 :l2 :li) k)))
89+
:ha "right" :fontsize fs)))
90+
(when (= recon "constant")
91+
(pl.text 0 0.9 "constant in subcell" :ha "center" :fontsize fs)))
92+
(cond [(and (zero? i) (= icon 0))
93+
(sv f (pl.gcf)
94+
cax (f.add-axes [(- (get rect 0) 0.04)
95+
(+ (get rect 1) (* 0.1 (get rect 3)))
96+
(* 0.1 (get rect 2))
97+
(* 0.8 (get rect 3))]))
98+
(pl.colorbar :cax cax :ticks [0.5 0.75 1 1.25 1.5]
99+
:aspect 10)
100+
(cax.yaxis.set-ticks-position "left")]
101+
[(= i 1)
102+
(sv f (pl.gcf)
103+
cax (f.add-axes [(+ (get rect 0) (* 0.1 (get rect 2)))
104+
(+ (get rect 1) 0.1)
105+
(* 0.8 (get rect 2))
106+
(* 0.05 (get rect 3))])
107+
cb (pl.colorbar :cax cax :orientation "horizontal"
108+
:ticks [0 vmax]
109+
:shrink 0.6 :aspect 10))
110+
(cb.ax.set-xticklabels ["0" (.format "{:1.2e}" vmax)])])))))
111+
112+
(when-inp ["fig-vortex"]
113+
(sv c (jcp-context (get-context))
114+
d (acc-parse (+ c.data-dir "vortex-imgs.txt")
115+
:map-nstepfac jcp-nenp2nstepfac)
116+
configs [(, 3 13 72 1 "constant")
117+
(, 3 13 72 1 "bilin")
118+
(, 6 13 144 1 "bilin")
119+
(, 12 13 288 2 "bilin")])
120+
(fig-vortex c d configs))

methods/islet/figures/figsutils.hy

+96-9
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
(defn get-context []
55
(sv c (Box)
6-
c.data-dir "data/"
7-
c.fig-dir "figs/"
6+
c.data-dir "data/mar21/"
7+
c.fig-dir "figs/drafts/"
88
c.odes (, "rotate" "divergent" "nondivergent")
99
c.cdrs (, (, "none" "none") (, "caas-node" "caas") (, "caas" "caas"))
1010
c.nstepfacs (, 1 5)
@@ -14,32 +14,88 @@
1414
c.nes (, 5 10 20 40 80)
1515
c.nps (, 4 6 8 9 12) ;(, 4 5 6 7 8 9 10 11 12 13 16)
1616
c.ics (, "gau" "cos" "slo")
17-
c.npclrs {4 "g" 5 "m" 6 "r" 7 "c" 8 "k" 9 "b" 10 "g" 11 "c" 12 "m" 13 "m" 16 "g"}
17+
c.npclrs {4 "g" 5 "m" 6 "r" 7 "c" 8 "k" 9 "b" 10 "g" 11 "c" 12 "r" 13 "m" 16 "g"}
1818
c.npmarks {4 "o" 5 "x" 6 "s" 7 "x" 8 "p" 9 "+" 10 "." 11 "^" 12 "." 13 "*" 16 "."})
1919
c)
2020

2121
(defn flow-short2long [flow]
2222
(get {"divergent" "divergent flow"
2323
"nondivergent" "nondivergent flow"
24-
"rotate" "solid-body rotation"} flow))
24+
"rotate" "solid-body rotation"
25+
"movingvortices" "moving vortices"} flow))
2526

2627
(defn ic-short2long [ic]
2728
(get {"gau" "Gaussian hills"
2829
"cos" "cosine bells"
2930
"slo" "slotted cylinders"} ic))
3031

31-
(defn nes->degstrs [nes]
32+
(defn nes->degstrs [nes &optional [convert-all False]]
3233
(sv x [] xstr [])
3334
(for [ne nes]
34-
(sv deg (geton {5 6 10 3 20 "1.5" 40 "0.75" 80 "0.375" 160 "0.1875"} ne))
35-
(when (none? deg) (continue))
35+
(sv deg (geton {2 15 5 6 10 3 20 "1.5" 40 "0.75" 80 "0.375" 160 "0.1875"} ne))
3636
(.append x ne)
37-
(.append xstr (.format "${}^{{\circ}}$" deg)))
37+
(if (none? deg)
38+
(do (sv deg (/ 30 ne))
39+
(.append xstr (.format "${:1.4f}^{{\circ}}$" deg)))
40+
(.append xstr (.format "${}^{{\circ}}$" deg))))
3841
{:ne x :deg xstr})
3942

4043
(defn cdr-name [short]
4144
(get {"caas" "CAAS-CAAS" "caas-node" "CAAS-point"} short))
4245

46+
;;; parse cmd, L, M, C slmmir output
47+
48+
(defn acc-parse [fname &optional map-nstepfac]
49+
(sv txt (.split (readall fname) "\n")
50+
bo None d {})
51+
(for [ln txt]
52+
(sv ln2 (cut ln 0 2))
53+
(cond [(and (= "cm" ln2) (in "cmd>" ln))
54+
(sv cmd ln c (parse-cmd ln :map-nstepfac map-nstepfac))]
55+
[(= ln2 "M ")
56+
(sv mp (parse-midpoint-check ln))
57+
(unless (none? (geton d #*(+ (cmd->key-base c)
58+
(, (:ic mp) cyc (:ne c) :M))))
59+
;; handle repeated ic used for src-term OOA testing.
60+
(assoc mp :ic (+ (:ic mp) "-src")))
61+
(assoc-nested d (+ (cmd->key-base c) (, (:ic mp) cyc (:ne c) :M))
62+
{:l1 (:l1 mp) :l2 (:l2 mp)})]
63+
[(= ln2 "C ")
64+
(cond [(in "cycle" ln) (sv (, - - cyc) (sscanf ln "s,s,i"))]
65+
[(or (in "PASS" ln) (in "FAIL" ln))
66+
(sv (, - pf) (sscanf ln "s,s"))
67+
(when (and (= pf "FAIL") (!= (:mono c) "none") (<= cyc 10))
68+
(prf "FAIL {}" cmd))]
69+
[:else
70+
(sv cl (parse-C ln))
71+
(unless (none? (geton d #*(+ (cmd->key-base c)
72+
(, (:ic cl) cyc (:ne c) :C))))
73+
;; handle repeated ic used for src-term OOA testing.
74+
(assoc cl :ic (+ (:ic cl) "-src")))
75+
#_(print "found:" (+ (cmd->key-base c) (, (:ic cl) cyc (:ne c) :C)))
76+
(assoc-nested d (+ (cmd->key-base c) (, (:ic cl) cyc (:ne c) :C))
77+
cl)])]
78+
[(= ln2 "L ")
79+
(cond [(in "L file" ln)
80+
(assoc-nested d (+ (cmd->key-base c)
81+
(, "cos" cyc (:ne c) :L :mixing-file))
82+
(last (.split ln)))
83+
;; If nothing else has marked bo as done, do it now.
84+
(unless (none? bo)
85+
(assoc bo :done True))]
86+
[(in "phimin" ln)
87+
(sv (, - ic - l1 - l2 - li - phimin - phimax)
88+
(sscanf ln "s,s,s,f,s,f,s,f,s,f,s,f"))
89+
(assoc-nested d (+ (cmd->key-base c) (, ic cyc (:ne c) :Lerr))
90+
{:l1 l1 :l2 l2 :li li :phimin phimin :phimax phimax})]
91+
[:else
92+
(sv bo (parse-bakeoff-diag bo ln (:timeint c)))])
93+
(when (and (not (none? bo)) (:done bo))
94+
(for [(, k v) (.items bo)]
95+
(assoc-nested d (+ (cmd->key-base c) (, "cos" cyc (:ne c) :L k)) v))
96+
(sv bo None))]))
97+
d)
98+
4399
;;; slmmir I/O
44100

45101
(defn read-slmmir-io-arrays [fname &optional beg end stride]
@@ -91,6 +147,7 @@
91147

92148
;;; parse slmmir text output
93149

150+
;; (map-nstepfac nstepfac-initial ne np)
94151
(defn parse-cmd [cmd &optional map-nstepfac]
95152
(sv toks (.split cmd))
96153
(defn int-or-none [x]
@@ -105,7 +162,8 @@
105162
(for [e (.items keys)]
106163
(assoc d (keyword (first e)) ((second e) (get-key-val (first e)))))
107164
(sv nstepfac (/ (:nsteps d) (:ne d) 6))
108-
(unless (none? map-nstepfac) (sv nstepfac (map-nstepfac nstepfac)))
165+
(unless (none? map-nstepfac)
166+
(sv nstepfac (map-nstepfac nstepfac (:ne d) (:np d))))
109167
(assoc d :nstepfac (int nstepfac))
110168
(when (= (:timeint d) "exact") (assoc d :prefine 0))
111169
d)
@@ -224,3 +282,32 @@
224282
(if (in " offst " ln)
225283
(parse-search-offset-nodal-subset-line ln)
226284
(parse-search-nodal-subset-line ln)))
285+
286+
;;; JCP manuscript revision utilities
287+
288+
(defn jcp-context [c]
289+
(sv c.data-dir "data/feb24/"
290+
c.nps (, 4 6 8 11 13))
291+
c)
292+
293+
;; Compute ne for np given tne for np=4 such that (ne,np) has the maximal #DOF
294+
;; <= $DOF for (tne,4).
295+
(defn jcp-tne2ne [tne np]
296+
(// (* tne 3) (dec np)))
297+
298+
;; The floating point actual value of resolution converted to np=4.
299+
(defn jcp-effective-tne [tne np]
300+
(/ (* (jcp-tne2ne tne np) (dec np)) 3))
301+
302+
(defn jcp-np4-ne [ne np]
303+
(/ (* ne (dec np)) 3))
304+
305+
;; Deduce nstepfac 1 or 5 from parse-cmd's internal values.
306+
(defn jcp-nenp2nstepfac [nstepfac ne np]
307+
(sv nsteps (* nstepfac ne 6)
308+
tne (/ (* ne (dec np)) 3)
309+
tnstepfac (/ nsteps tne 6))
310+
(cond [(< tnstepfac 3) 1]
311+
[(< tnstepfac 8) 5]
312+
[:else (raisefmt "jcp-nenp2nstepfac failed: {} {} {} => {}"
313+
nstepfac ne np tnstepfac)]))
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cat $0
2+
3+
exe=slmmir
4+
5+
ctr=0
6+
function run {
7+
ctr=$(expr $ctr + 1)
8+
cmd="OMP_NUM_THREADS=64 KMP_AFFINITY=balanced ../$exe -method pcsl -ic gaussianhills -ic cosinebells -ic correlatedcosinebells -ic slottedcylinders -we 0 -rit -T 12 -d2c -ode $ode -ne $ne -np $np -nsteps $nstep -prefine 0 -mono none -lim none -timeint exact -rotate-grid"
9+
grepcmd='grep "^C \|^L \|^M "'
10+
echo "cmd> $ctr $cmd"
11+
eval "$cmd | $grepcmd"
12+
}
13+
14+
for tne in 5 10 20 40 80 160; do
15+
for nstepfac in 1 5; do
16+
for ode in nondivergent; do
17+
tgtres=$(($tne * 3))
18+
for np in $(seq 4 13) 16; do
19+
ne=$(($tgtres / ($np - 1)))
20+
nstep=$(($nstepfac * 2 * ($np - 1) * $ne))
21+
if [[ $ne == 1 ]]; then
22+
continue
23+
fi
24+
run
25+
done
26+
done
27+
done
28+
done

0 commit comments

Comments
 (0)