-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathconv_rates_immersed.lua
740 lines (592 loc) · 23 KB
/
conv_rates_immersed.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
util = util or {}
util.rates = util.rates or {}
util.rates.static = util.rates.static or {}
ug_load_script("util/persistence.lua")
--------------------------------------------------------------------------------
-- Std Functions (used as defaults)
--------------------------------------------------------------------------------
function util.rates.static.StdPrepareInitialGuess(u, lev, minLev, maxLev,
domainDisc, solver)
if lev > minLev then
Prolongate(u[lev], u[lev-1]);
write(">> Solution interpolated as start value from coarser level.\n")
else
u[lev]:set(0.0)
write(">> Solution set to zero on coarsest level.\n")
end
end
function util.rates.static.StdComputeLinearSolution(u, domainDisc, solver)
-- create operator from discretization
local A = AssembledLinearOperator(domainDisc)
local b = u:clone()
write(">> Algebra created.\n")
-- 1. init operator
domainDisc:assemble_linear(A, b)
write(">> Matrix and Rhs assembled.\n")
-- 2. set dirichlet values in start iterate
domainDisc:adjust_solution(u)
write(">> Inital guess for solution prepared.\n")
-- 3. init solver for linear Operator
solver:init(A, u)
write(">> Linear Solver initialized.\n")
-- 4. apply solver
if solver:apply_return_defect(u, b) ~= true then
write(">> Linear solver failed. Aborting."); exit();
end
end
function util.rates.static.StdComputeNonLinearSolution(u, domainDisc, solver)
solver:init(AssembledOperator(domainDisc, u:grid_level()))
if solver:apply(u) == false then
print (">> Newton solver apply failed."); exit();
end
write(">> Newton Solver done.\n")
end
function util.rates.static.StdMaxLevelPadding(p)
return math.floor(p/2)
end
function util.rates.static.StdMinLevelPadding(p)
return 0
end
function util.rates.static.NoMaxLevelPadding(p)
return 0
end
function util.rates.static.NoMinLevelPadding(p)
return 0
end
--------------------------------------------------------------------------------
-- Label names
--------------------------------------------------------------------------------
util.rates.static.StdLabel = util.rates.static.StdLabel or {}
function util.rates.static.StdLabel.MeasLatexP(disc, p)
return disc.." $\\mathbb{P}_{"..p.."}$"
end
function util.rates.static.StdLabel.MeasLatexQ(disc, p)
return disc.." $\\mathbb{Q}_{"..p.."}$"
end
function util.rates.static.StdLabel.XLatex(x)
local gpXLabel ={ DoFs = "Anzahl Unbekannte", h = "h (Gitterweite)"}
return gpXLabel[x]
end
function util.rates.static.StdLabel.YLatex(f, t, n)
local gpType = { ["l-exact"] = "{}",
["l-lmax"] = "h_{\\text{min}}",
["l-prev"] = "{h/2}",
}
local gpNorm = { l2 = "L_2", h1 = "H^1"}
if t == "interpol" then
return "$\\norm{\\mathcal{I}_h("..f..") - "..f.."}_{"..gpNorm[n].."}$"
else
return "$\\norm{"..f.."_h - "..f.."_{"..gpType[t].."} }_{ "..gpNorm[n].."}$"
end
end
function util.rates.static.StdLabel.MeasPdfP(disc, p)
return disc.." $P_"..p.."$"
end
function util.rates.static.StdLabel.MeasPdfQ(disc, p)
return disc.." $Q_"..p.."$"
end
function util.rates.static.StdLabel.XPdf(x)
local gpXLabel ={ DoFs = "Anzahl Unbekannte", h = "h (Gitterweite)"}
return gpXLabel[x]
end
function util.rates.static.StdLabel.YPdf(f, t, n)
local gpType = { ["l-exact"] = "{}",
["l-lmax"] = "h_{\\text{min}}",
["l-prev"] = "{h/2}",
}
local gpNorm = { l2 = "L_2", h1 = "H^1"}
if t == "interpol" then
return "$|| I_h("..f..") - "..f.." ||_{"..gpNorm[n].."}$"
else
return "$|| "..f.."_h - "..f.."_{"..gpType[t].."} ||_{"..gpNorm[n].."}$"
end
end
--------------------------------------------------------------------------------
-- util.rates.static.compute (main-function)
--------------------------------------------------------------------------------
--[[!
Computes convergence rates for a static problem
In the convergence rate setup the following parameters can be passed:
- (required) CreateDomain()
function used to create Domain
- (required) CreateApproxSpace(dom, discType, p)
function used to create ApproximationSpace
- (required) CreateDomainDisc(approxSpace, discType, p)
function used to create Domain Discretization
- (required) CreateSolver(approxSpace, discType, p)
function used to create Solver
- (required) DiscTypes
Array containing types, orders and level to be looped
- (optional) ComputeSolution(u, domainDisc, solver)
function used to compute solution
- (optional) PrepareInitialGuess
function used to prepare Initial Guess
- (optional) ExactSol
Array containing exact solution as a function
- (optional) ExactGrad
Array containing exact gradients as a function
@param ConvRate Setup setup used
]]--
function util.rates.static.compute(ConvRateSetup)
-- check passed param
local CRS
if ConvRateSetup == nil then print("No setup passed."); exit()
else CRS = ConvRateSetup end
-- create directories
local plotPath = CRS.plotPath or "plots/"
local solPath = CRS.solPath or "sol/"
local dataPath = CRS.dataPath or "data/"
local gpOptions = CRS.gpOptions or
{
grid = true,
logscale = true,
mtics = true
}
-- check for methods
local PrepareInitialGuess = CRS.PrepareInitialGuess or util.rates.static.StdPrepareInitialGuess
local ComputeSolution = CRS.ComputeSolution or util.rates.static.StdComputeNonLinearSolution
local CreateApproxSpace = CRS.CreateApproxSpace
local CreateDomainDisc = CRS.CreateDomainDisc
local CreateSolver = CRS.CreateSolver
local CreateDomain = CRS.CreateDomain
local MaxLevelPadding = CRS.MaxLevelPadding or util.rates.static.StdMaxLevelPadding
local MinLevelPadding = CRS.MinLevelPadding or util.rates.static.StdMinLevelPadding
if CreateApproxSpace == nil or CreateDomainDisc == nil or
CreateSolver == nil or CreateDomain == nil then
print("You must pass: CreateApproxSpace, CreateDomainDisc, CreateSolver, CreateDomain")
exit()
end
local DiscTypes = CRS.DiscTypes
local maxlevel = CRS.maxlevel; if maxlevel == nil then maxlevel = true end
local prevlevel = CRS.prevlevel; if prevlevel == nil then prevlevel = true end
local exact = CRS.exact; if exact == nil then exact = true end
local interpol = CRS.interpol; if interpol == nil then interpol = true end
local plotSol = CRS.plotSol; if plotSol == nil then plotSol = false end
local ExactSol = CRS.ExactSol
local ExactGrad = CRS.ExactGrad
local PlotCmps = CRS.PlotCmps
local MeasLabel = CRS.MeasLabel or util.rates.static.StdLabel.MeasLatexP
local XLabel = CRS.XLabel or util.rates.static.StdLabel.XLatex
local YLabel = CRS.YLabel or util.rates.static.StdLabel.YLatex
--------------------------------------------------------------------
-- Loop Discs
--------------------------------------------------------------------
local function ensureDir(name)
if not(DirectoryExists(name)) then CreateDirectory(name) end
end
if plotSol then ensureDir(solPath) end
-- compute element size
local dom = CreateDomain()
local numRefs = dom:grid():num_levels() - 1;
-- to store measurement
local gpData = {};
local errors = {};
for _, DiscType in ipairs(DiscTypes) do
local disc = DiscType.type
if disc == nil then print("type required."); exit(); end
local pmin = DiscType.pmin or 1
local pmax = DiscType.pmax or 1
local lmin = DiscType.lmin or 0
local lmax = DiscType.lmax or numRefs
if lmin > lmax then print("lmin: "..lmin.." must be less or equal lmax: "..lmax); exit(); end
if lmax > numRefs then print("lmax: "..lmax.." must be less or equal numRefs: "..numRefs); exit(); end
errors[disc] = errors[disc] or {}
for p = pmin, pmax do
errors[disc][p] = errors[disc][p] or {}
local maxLev = lmax - MaxLevelPadding(p)
local minLev = lmin + MinLevelPadding(p)
--------------------------------------------------------------------
-- Print Setup
--------------------------------------------------------------------
print("\n")
print(">> -------------------------------------------------------------------")
print(">> Computing solutions and error norms of the following problem")
print(">> -------------------------------------------------------------------")
print(">> dim = " .. dim)
print(">> grid = " .. gridName)
print(">> minLev = " .. minLev)
print(">> maxLev = " .. maxLev)
print(">> type = " .. disc)
print(">> order = " .. p)
print("\n")
--------------------------------------------------------------------
-- Create ApproxSpace, Disc and Solver
--------------------------------------------------------------------
print(">> Create ApproximationSpace: "..disc..", "..p)
local approxSpace = CreateApproxSpace(dom, disc, p)
print(">> Create Domain Disc: "..disc..", "..p)
local domainDisc = CreateDomainDisc(approxSpace, disc, p)
--local solver = CreateSolver(approxSpace, disc, p)
-- get names in approx space
local SpaceCmp = approxSpace:names()
-- per default compute each Space-cmp
if PlotCmps == nil then
PlotCmps = {}
for f = 1,#SpaceCmp do
PlotCmps[SpaceCmp[f]] = {SpaceCmp[f]}
end
end
-- check functions to measure
for _,Cmps in pairs(PlotCmps) do
for _, cmp in pairs(Cmps) do
if not table.contains(SpaceCmp, cmp) then
print("Cmp: '"..cmp.."' not contained in ApproxSpace.");
exit()
end
end
end
--------------------------------------------------------------------
-- Create Solutions on each level
--------------------------------------------------------------------
write(">> Allocating storage for solution vectors.\n")
local u = {}
for lev = minLev, maxLev do
u[lev] = GridFunction(approxSpace, lev)
end
--------------------------------------------------------------------
-- Compute Solution on each level
--------------------------------------------------------------------
if exact or maxlevel or prevlevel then
for lev = minLev, maxLev do
print(">> Create Solver on lev "..lev)
local solver = CreateSolver(approxSpace, disc, p, lev)
write("\n>> Computing Level "..lev..", "..disc..", "..p..".\n")
write(">> Preparing inital guess on level "..lev..".\n")
--solver = CreateSolver(approxSpace, disc, p)
PrepareInitialGuess(u, lev, minLev, maxLev, domainDisc, solver, approxSpace, disc, p)
write(">> Start: Computing solution on level "..lev..".\n")
--solver = CreateSolver(approxSpace, disc, p)
ComputeSolution(u[lev], domainDisc, solver)
write(">> End: Solver done.\n")
if plotSol then
WriteGridFunctionToVTK(u[lev], solPath.."sol_"..disc..p.."_l"..lev)
write(">> Solution written to: "..solPath.."sol_"..disc..p.."_l"..lev.."\n");
end
solver = nil
end
end
approxSpace, domainDisc = nil, nil
collectgarbage()
--------------------------------------------------------------------
-- Compute Error Norms on each level
--------------------------------------------------------------------
-- prepare error measurement
local err = errors[disc][p]
err.h, err.DoFs, err.level = {}, {}, {}
for lev = minLev, maxLev do
err.h[lev] = MaxElementDiameter(dom, lev)
err.level[lev] = lev
err.DoFs[lev] = u[lev]:num_dofs()
end
-- loop levels and compute error
for lev = maxLev, minLev, -1 do
write("\n>> Error Norm values on Level "..lev..".\n")
local quadOrder = p*p+3
write(">> #DoF on Level "..lev.." is "..err.DoFs[lev] .."\n");
-- compute for each component
for f, Cmps in pairs(PlotCmps) do
-- create component
err[f] = err[f] or {}
-- help fct to create an measurement
local function createMeas(f, t, n)
err[f][t] = err[f][t] or {}
err[f][t][n] = err[f][t][n] or {}
err[f][t][n].value = err[f][t][n].value or {}
return err[f][t][n].value
end
-- check for exact solution and grad
local solAvail, gradAvail = true, true
for _,cmp in pairs(Cmps) do
if ExactSol == nil or ExactSol[cmp] == nil then solAvail = false end
if ExactGrad == nil or ExactGrad[cmp] == nil then gradAvail = false end
end
-- w.r.t exact solution
if exact and solAvail then
local value = createMeas(f, "l-exact", "l2")
value[lev] = 0.0
for _,cmp in pairs(Cmps) do
value[lev] = value[lev] + math.pow(L2Error(ExactSol[cmp], u[lev], cmp, 0.0, quadOrder), 2)
end
value[lev] = math.sqrt(value[lev])
write(">> L2 l-exact for "..f.." on Level "..lev.." is "..string.format("%.3e", value[lev]) .."\n");
if gradAvail then
local value = createMeas(f, "l-exact", "h1")
value[lev] = 0.0
for _,cmp in pairs(Cmps) do
value[lev] = value[lev] + math.pow(H1Error(ExactSol[cmp], ExactGrad[cmp], u[lev], cmp, 0.0, quadOrder), 2)
end
value[lev] = math.sqrt(value[lev])
write(">> H1 l-exact for "..f.." on Level "..lev.." is "..string.format("%.3e", value[lev]) .."\n");
end
end
if interpol and solAvail then
local uExact = u[lev]:clone()
for _,cmp in pairs(Cmps) do
Interpolate(ExactSol[cmp], uExact, cmp)
end
local value = createMeas(f, "interpol", "l2")
value[lev] = 0.0
for _,cmp in pairs(Cmps) do
value[lev] = value[lev] + math.pow(L2Error(ExactSol[cmp], uExact, cmp, 0.0, quadOrder), 2)
end
value[lev] = math.sqrt(value[lev])
write(">> L2 interpol for "..f.." on Level "..lev.." is "..string.format("%.3e", value[lev]) .."\n");
if gradAvail then
local value = createMeas(f, "interpol", "h1")
value[lev] = 0.0
for _,cmp in pairs(Cmps) do
value[lev] = value[lev] + math.pow(H1Error(ExactSol[cmp], ExactGrad[cmp], uExact, cmp, 0.0, quadOrder), 2)
end
value[lev] = math.sqrt(value[lev])
write(">> H1 interpol for "..f.." on Level "..lev.." is "..string.format("%.3e", value[lev]) .."\n");
end
uExact = nil
end
-- w.r.t max level solution
if maxlevel and lev < maxLev then
local value = createMeas(f, "l-lmax", "l2")
value[lev] = 0.0
for _,cmp in pairs(Cmps) do
value[lev] = value[lev] + math.pow(L2ErrorInside(u[maxLev], cmp, u[lev], cmp, quadOrder), 2)
-- value[lev] = value[lev] + math.pow(L2Error(u[maxLev], cmp, u[lev], cmp, quadOrder), 2)
end
value[lev] = math.sqrt(value[lev])
write(">> L2 l-lmax for "..f.." on Level "..lev.." is "..string.format("%.3e", value[lev]) .."\n");
local value = createMeas(f, "l-lmax", "h1")
value[lev] = 0.0
for _,cmp in pairs(Cmps) do
value[lev] = value[lev] + math.pow(H1Error(u[maxLev], cmp, u[lev], cmp, quadOrder), 2)
end
value[lev] = math.sqrt(value[lev])
write(">> H1 l-lmax for "..f.." on Level "..lev.." is "..string.format("%.3e", value[lev]) .."\n");
end
-- w.r.t previous level solution
if prevlevel and lev < maxLev then
local value = createMeas(f, "l-prev", "l2")
value[lev] = 0.0
for _,cmp in pairs(Cmps) do
value[lev] = value[lev] + math.pow(L2ErrorInside(u[lev+1], cmp, u[lev], cmp, quadOrder), 2)
-- value[lev] = value[lev] + math.pow(L2Error(u[lev+1], cmp, u[lev], cmp, quadOrder), 2)
end
value[lev] = math.sqrt(value[lev])
write(">> L2 l-(l-1) for "..f.." on Level "..lev.." is "..string.format("%.3e", value[lev]) .."\n");
local value = createMeas(f, "l-prev", "h1")
value[lev] = 0.0
for _,cmp in pairs(Cmps) do
value[lev] = value[lev] + math.pow(H1Error(u[lev+1], cmp, u[lev], cmp, quadOrder), 2)
end
value[lev] = math.sqrt(value[lev])
write(">> H1 l-(l-1) for "..f.." on Level "..lev.." is "..string.format("%.3e", value[lev]) .."\n");
end
end -- end fct
end -- end level
for lev = minLev, maxLev do u[lev] = nil end
u = nil
collectgarbage()
--------------------------------------------------------------------
-- Compute Factors and Rates
--------------------------------------------------------------------
for f, _ in pairs(PlotCmps) do
for t, _ in pairs(err[f]) do
for n, _ in pairs(err[f][t]) do
local meas = err[f][t][n]
meas.fac = meas.fac or {}
meas.rate = meas.rate or {}
local value = meas.value
local fac = meas.fac
local rate = meas.rate
for lev, _ in pairs(value) do
if value[lev] ~= nil and value[lev-1] ~= nil then
fac[lev] = value[lev-1]/value[lev]
rate[lev] = math.log(fac[lev]) / math.log(2)
end
end
end
end
end
--------------------------------------------------------------------
-- Write Data to Screen
--------------------------------------------------------------------
for f, Cmps in pairs(PlotCmps) do
write("\n>> Statistic for type: "..disc..", order: "..p..", comp: "..f.." [ ")
for _, cmp in pairs(Cmps) do write(cmp.." ") end
print("]\n")
local values = {err.level, err.h, err.DoFs}
local heading = {"L", "h", "#DoFs"}
local format = {"%d", "%.2e", "%d"}
for t, _ in pairs(err[f]) do
for n, _ in pairs(err[f][t]) do
local meas = err[f][t][n]
table.append(values, {meas.value, meas.rate})
table.append(heading,{n.." "..t, "rate"})
table.append(format, {"%.2e", "%.3f"})
end
end
table.print(values, {heading = heading, format = format,
hline = true, vline = true, forNil = "--"})
end
end -- end loop over p
end -- end loop over type
--------------------------------------------------------------------
-- Write gnuplot data
--------------------------------------------------------------------
-- the following is serial and one proc doing it is sufficient
if ProcRank() ~= 0 then return end
ensureDir(dataPath)
ensureDir(plotPath)
-- help fct to create a plot
local plots = {}
local function accessPlot(...)
local keys = arg
local plot = plots
for _, key in ipairs(keys) do
plot[key] = plot[key] or {}
plot = plot[key]
end
return plot
end
local function getPlot(...)
local plot = accessPlot(...)
local pl = table.ideepcopy( plot )
pl.label = plot.label
return pl
end
for disc, _ in pairs(errors) do
for p, _ in pairs(errors[disc]) do
for f, _ in pairs(PlotCmps) do
for t, _ in pairs(errors[disc][p][f]) do
for n, _ in pairs(errors[disc][p][f][t]) do
-- write l2 and h1 to data file
local file = dataPath..table.concat({"error",disc,p,f,t,n},"_")..".dat"
local cols = {errors[disc][p].DoFs, errors[disc][p].h, errors[disc][p][f][t][n].value}
gnuplot.write_data(file, cols)
-- store dataset
for xCol, x in ipairs({"DoFs", "h"}) do
local dataset = {label=MeasLabel(disc, p), file=file, style="linespoints", xCol, 3}
local label = { x = XLabel(x), y = YLabel(f,t,n)}
local function addSet(plot, dataset, label)
table.insert( plot, dataset)
plot.label = label
end
addSet( accessPlot(disc, p, f, t, n, x), dataset, label)
addSet( accessPlot(disc, f, t, n, x), dataset, label)
addSet( accessPlot("all", f, t, n, x), dataset, label)
end
end
end
end
end
end
--------------------------------------------------------------------
-- Execute Plot of gnuplot
--------------------------------------------------------------------
-- one plot
local validP
ensureDir(plotPath.."dataset/")
ensureDir(plotPath.."disc/")
ensureDir(plotPath.."multi/")
for disc, _ in pairs(errors) do
for p, _ in pairs(errors[disc]) do
for f, _ in pairs(PlotCmps) do
for t, _ in pairs(errors[disc][p][f]) do
for n, _ in pairs(errors[disc][p][f][t]) do
for _, x in ipairs({"DoFs", "h"}) do
-- single dataset
local file = plotPath.."dataset/"..table.concat({disc,p,f,t,n,x},"_")
gpData[file] = getPlot(disc, p, f, t, n, x)
-- grouping by (disc+p)
local file = plotPath.."disc/"..table.concat({f,disc,t,n,x}, "_")
gpData[file] = getPlot(disc, f, t, n, x)
-- grouping (all discs+p)
local file = plotPath.."disc/"..table.concat({f,"all",t,n,x}, "_")
gpData[file] = getPlot("all", f, t, n, x)
validP = p
end
end
end
end
end
end
for disc, _ in pairs(errors) do
local p = validP
for f, _ in pairs(PlotCmps) do
for t, _ in pairs(errors[disc][p][f]) do
for n, _ in pairs(errors[disc][p][f][t]) do
for _, x in ipairs({"DoFs", "h"}) do
-- multi-plot: all discs for one norm
local file = plotPath.."multi/"..table.concat({f,t,n,x}, "_")
gpData[file] = gpData[file] or {}
gpData[file].multiplot = {rows = 1}
table.insert( gpData[file], getPlot(disc, f, t, n, x) )
-- multi-plot: all norms for one disc
local file = plotPath.."multi/"..table.concat({f,disc,t,x}, "_")
gpData[file] = gpData[file] or {}
gpData[file].multiplot = {cols = 1}
table.insert( gpData[file], getPlot(disc, f, t, n, x) )
-- multi-plot: all types for one disc and one norm
local file = plotPath.."multi/"..table.concat({f,disc,n,x}, "_")
gpData[file] = gpData[file] or {}
gpData[file].multiplot = {cols = 1}
table.insert( gpData[file], getPlot(disc, f, t, n, x) )
-- multi-plot: all comps for one disc and one norm
local file = plotPath.."multi/"..table.concat({"all",disc,t,n,x}, "_")
gpData[file] = gpData[file] or {}
gpData[file].multiplot = {cols = 1}
table.insert( gpData[file], getPlot(disc, f, t, n, x) )
end
end
end
end
end
-- multi-plot: all discs for all norm
for _, n in pairs({"h1", "l2"}) do
for disc, _ in pairs(errors) do
local p = validP
for f, _ in pairs(PlotCmps) do
for t, _ in pairs(errors[disc][p][f]) do
if errors[disc][p][f][t][n] then
for _, x in ipairs({"DoFs", "h"}) do
local file = plotPath.."multi/"..table.concat({f,t,x}, "_")
gpData[file] = gpData[file] or {}
gpData[file].multiplot = {cols = 2}
table.insert( gpData[file], getPlot(disc, f, t, n, x) )
end
end
end
end
end
end
-- save for reuse
persistence.store(dataPath.."gp-data-files.lua", gpData);
-- create scheduled plots
if CRS.noplot == nil or CRS.noplot == false then
for plotFile, data in pairs(gpData) do
local opt = table.deepcopy(gpOptions)
if data.multiplot then opt.multiplot = data.multiplot end
gnuplot.plot(plotFile..".tex", data, opt)
gnuplot.plot(plotFile..".pdf", data, opt)
end
end
end
function util.rates.static.replot(gpOptions, file)
if ProcRank() ~= 0 then return end
local dataPath = "data/"
local plotPath = "plots/"
local function ensureDir(name)
if not(DirectoryExists(name)) then CreateDirectory(name) end
end
ensureDir(dataPath)
ensureDir(plotPath)
ensureDir(plotPath.."dataset/")
ensureDir(plotPath.."disc/")
ensureDir(plotPath.."multi/")
local file = file or dataPath.."gp-data-files.lua"
local gpData = persistence.load(file);
-- create scheduled plots
for plotFile, data in pairs(gpData) do
local opt = table.deepcopy(gpOptions)
if data.multiplot then opt.multiplot = data.multiplot end
gnuplot.plot(plotFile..".tex", data, opt)
gnuplot.plot(plotFile..".pdf", data, opt)
end
end