plot.py

changeset 12
a0d61ac3719e
parent 3
c3a4f4bb87f7
equal deleted inserted replaced
11:c4f923017349 12:a0d61ac3719e
12 import matplotlib.colors as colors 12 import matplotlib.colors as colors
13 import matplotlib.pyplot as plt 13 import matplotlib.pyplot as plt
14 import matplotlib.tri as tri 14 import matplotlib.tri as tri
15 import numpy as np 15 import numpy as np
16 from dolfinx import fem 16 from dolfinx import fem
17
17 from src.convection_diffusion import ConvectionDiffusion 18 from src.convection_diffusion import ConvectionDiffusion
18 19
19 20
20 def find_files(dirname): 21 def find_files(dirname):
21 """ 22 """
47 48
48 pde = ConvectionDiffusion( 49 pde = ConvectionDiffusion(
49 u0=lambda x: 0.0 * x[1], 50 u0=lambda x: 0.0 * x[1],
50 g=lambda x: 0.0 * x[1], # ((x[1] + 2) / 4) ** 2, # nonzero bcs 51 g=lambda x: 0.0 * x[1], # ((x[1] + 2) / 4) ** 2, # nonzero bcs
51 # w0=lambda x: np.cos(5 * x[1]), 52 # w0=lambda x: np.cos(5 * x[1]),
52 domain_size=[0, 0.5, 0, 0.5], 53 domain_dims=[[0, 0.5], [0, 0.5]],
53 # nx=128, 54 nx=32,
54 # ny=128, 55 ny=32,
56 num_steps=50,
55 ) 57 )
56 58
57 # Get coordinates 59 # Get coordinates
58 coords = pde.V.tabulate_dof_coordinates() 60 coords = pde.V.tabulate_dof_coordinates()
59 x_coords, y_coords = coords[:, 0], coords[:, 1] 61 x_coords, y_coords = coords[:, 0], coords[:, 1]
133 μ = list(filter(lambda x: x[2] != 0.0 and not np.isnan(x).any(), mu)) 135 μ = list(filter(lambda x: x[2] != 0.0 and not np.isnan(x).any(), mu))
134 μ_alpha = list(map(lambda x: x[2], μ)) 136 μ_alpha = list(map(lambda x: x[2], μ))
135 true_μ_alpha = list(map(lambda x: x[2], true_μ)) 137 true_μ_alpha = list(map(lambda x: x[2], true_μ))
136 138
137 if len(μ_alpha) == 0: 139 if len(μ_alpha) == 0:
138 alpha_mi, alpha_ma, alpha_me = 0, 0, 0 140 alpha_mi, alpha_ma, alpha_me, alpha_sum = 0, 0, 0, 0
139 else: 141 else:
140 alpha_mi, alpha_ma, alpha_me = min(μ_alpha), max(μ_alpha), median(μ_alpha) 142 alpha_mi, alpha_ma, alpha_me, alpha_sum = (
143 min(μ_alpha),
144 max(μ_alpha),
145 median(μ_alpha),
146 sum(μ_alpha),
147 )
141 148
142 true_alpha_mi, true_alpha_ma = min(true_μ_alpha), max(true_μ_alpha) 149 true_alpha_mi, true_alpha_ma = min(true_μ_alpha), max(true_μ_alpha)
143 alpha_base = min(true_alpha_mi, alpha_mi) 150 alpha_base = min(true_alpha_mi, alpha_mi)
144 alpha_scale = max(true_alpha_ma, alpha_ma) - alpha_base 151 alpha_scale = max(true_alpha_ma, alpha_ma) - alpha_base
145 if alpha_scale == 0: 152 if alpha_scale == 0:
312 ax.set_xticklabels([]) 319 ax.set_xticklabels([])
313 ax.set_yticklabels([]) 320 ax.set_yticklabels([])
314 ax.set_aspect("equal") 321 ax.set_aspect("equal")
315 322
316 plt.suptitle( 323 plt.suptitle(
317 "Convection-Diffusion, iteration %d; len(μ) = %d; μ_min = %f, μ_max = %f, μ_median = %f;" 324 "Convection-Diffusion, iteration %d; len(μ) = %d; μ_min = %f, μ_max = %f, μ_sum = %f;"
318 % ( 325 % (
319 iter, 326 iter,
320 len(μ), 327 len(μ),
321 alpha_mi, 328 alpha_mi,
322 alpha_ma, 329 alpha_ma,
323 alpha_me, 330 alpha_sum,
324 ), 331 ),
325 fontsize=14, 332 fontsize=14,
326 ) 333 )
327 334
328 str = "(k, c, c1) = (%g, %g, %g)" % (data["k"], data["c1"], data["c2"]) 335 str = "(k, c, c1) = (%g, %g, %g)" % (data["k"], data["c1"], data["c2"])
439 # plt.show() 446 # plt.show()
440 447
441 # print("Saved: solution_evolution.png + solution_time.png") 448 # print("Saved: solution_evolution.png + solution_time.png")
442 449
443 450
444 parser = argparse.ArgumentParser( 451 def main():
445 prog="plot.py", 452 parser = argparse.ArgumentParser(
446 description="Plots results of pointsource_pde", 453 prog="plot.py",
447 ) 454 description="Plots results of pointsource_pde",
448 455 )
449 parser.add_argument("filename") 456
450 parser.add_argument("--simple", action="store_true") 457 parser.add_argument("filename")
451 parser.add_argument("--shaded", action="store_true") 458 parser.add_argument("--simple", action="store_true")
452 parser.add_argument("--iter", type=int, action="store") 459 parser.add_argument("--shaded", action="store_true")
453 parser.add_argument("--save-only", action="store_true") 460 parser.add_argument("--iter", type=int, action="store")
454 461 parser.add_argument("--save-only", action="store_true")
455 args = parser.parse_args() 462
456 463 args = parser.parse_args()
457 plot(args.filename, args.simple, args.shaded, args.iter, args.save_only) 464
465 plot(args.filename, args.simple, args.shaded, args.iter, args.save_only)
466
467
468 if __name__ == "__main__":
469 main()

mercurial