@@ -36,7 +36,7 @@ def __init__(self, nx, ng=0, xmin=0.0, xmax=1.0, voff=0.0):
3636 self .ng = ng
3737 self .xmin = xmin
3838 self .xmax = xmax
39-
39+
4040 self .ilo = ng
4141 self .ihi = ng + nx - 1
4242
@@ -62,36 +62,36 @@ def draw_grid(self, draw_ghost=0, emphasize_end=0, edge_ticks=1, color="k"):
6262
6363 if not draw_ghost :
6464 if emphasize_end :
65- plt .plot ([self .xmin , self .xmax ],
65+ plt .plot ([self .xmin , self .xmax ],
6666 [self .voff , self .voff ], color = color , lw = 2 )
6767 else :
68- plt .plot ([self .xmin - 0.5 * self .dx , self .xmax + 0.5 * self .dx ],
68+ plt .plot ([self .xmin - 0.5 * self .dx , self .xmax + 0.5 * self .dx ],
6969 [self .voff ,self .voff ], color = color , lw = 2 )
7070 else :
7171 plt .plot ([self .xmin - self .ng * self .dx , self .xmin ],
7272 [self .voff ,self .voff ], color = color , lw = 2 , ls = ":" )
73- plt .plot ([self .xmax , self .xmax + self .ng * self .dx ],
73+ plt .plot ([self .xmax , self .xmax + self .ng * self .dx ],
7474 [self .voff ,self .voff ], color = color , lw = 2 , ls = ":" )
75- plt .plot ([self .xmin , self .xmax ],
75+ plt .plot ([self .xmin , self .xmax ],
7676 [self .voff ,self .voff ], color = color , lw = 2 )
7777
7878 for n in range (nstart , nstop + 1 ):
7979
8080 # draw center (node) indicator line
8181 if n < self .ilo or n > self .ihi :
82- plt .plot ([self .xc [n ], self .xc [n ]],
83- [- 0.05 + self .voff , grid_top + self .voff ],
82+ plt .plot ([self .xc [n ], self .xc [n ]],
83+ [- 0.05 + self .voff , grid_top + self .voff ],
8484 color = color , ls = ":" , lw = 2 )
8585 else :
86- plt .plot ([self .xc [n ], self .xc [n ]],
86+ plt .plot ([self .xc [n ], self .xc [n ]],
8787 [- 0.05 + self .voff , grid_top + self .voff ], color = color , lw = 2 )
88-
88+
8989
9090 if emphasize_end :
91- plt .plot ([self .xc [self .ilo ], self .xc [self .ilo ]],
91+ plt .plot ([self .xc [self .ilo ], self .xc [self .ilo ]],
9292 [- 0.05 + self .voff , grid_top + self .voff ], color = color , lw = 4 )
9393
94- plt .plot ([self .xc [self .ihi ], self .xc [self .ihi ]],
94+ plt .plot ([self .xc [self .ihi ], self .xc [self .ihi ]],
9595 [- 0.05 + self .voff , grid_top + self .voff ], color = color , lw = 4 )
9696
9797 def label_node (self , idx , string , fontsize = "small" ):
@@ -113,7 +113,7 @@ def label_value(self, idx, value, string, color="k", fontsize="large"):
113113 fontsize = fontsize , color = color )
114114
115115 def draw_data (self , idx , value , color = "0.5" , marker = "o" ):
116- plt .scatter ([self .xc [idx ]], [self .voff + value ],
116+ plt .scatter ([self .xc [idx ]], [self .voff + value ],
117117 color = color , marker = marker , zorder = 100 )
118118
119119
@@ -125,7 +125,7 @@ def label_dx(self, idx):
125125 plt .text (0.5 * (self .xc [idx - 1 ] + self .xc [idx ]), - 0.45 , r"$\Delta x$" ,
126126 horizontalalignment = "center" )
127127
128-
128+
129129 def clean_axes (self , show_ghost = False , padding = True , ylim = None , pad_fac = 1.0 ):
130130 xmin = self .xmin
131131 xmax = self .xmax
@@ -172,13 +172,12 @@ def scratch_array(self):
172172
173173 def draw_grid (self , center_only = 0 , draw_ghost = 0 ,
174174 emphasize_end = 0 , draw_end = True ,
175- edge_ticks = True , color = "k" ):
175+ edge_ticks = True , center_ticks = True ,
176+ grid_top = 1.0 , color = "k" ):
176177
177178 if center_only and emphasize_end :
178179 sys .exit ("center_only and emphasize_end are incompatible" )
179180
180- grid_top = 1.0
181-
182181 if not draw_ghost :
183182 if center_only == 1 :
184183 nstart = self .ng + self .nx // 2 - 1
@@ -216,35 +215,36 @@ def draw_grid(self, center_only=0, draw_ghost=0,
216215
217216 # draw right edge
218217 if emphasize_end and n == self .ihi :
219- plt .plot ([self .xr [n ], self .xr [n ]],
218+ plt .plot ([self .xr [n ], self .xr [n ]],
220219 [self .voff , grid_top + self .voff ],
221220 color = color , lw = 4 )
222221
223222 elif n < nstop or (n == nstop and draw_end ):
224- plt .plot ([self .xr [n ], self .xr [n ]],
223+ plt .plot ([self .xr [n ], self .xr [n ]],
225224 [self .voff , grid_top + self .voff ],
226225 color = color , lw = 2 )
227226
228227 # draw center marker
229- plt .plot ([self .xc [n ], self .xc [n ]],
230- [- 0.05 + self .voff , self .voff ], color = color )
228+ if center_ticks :
229+ plt .plot ([self .xc [n ], self .xc [n ]],
230+ [- 0.05 + self .voff , self .voff ], color = color )
231231
232232 # draw edge marker
233-
233+
234234 if edge_ticks :
235235 if n == nstart :
236236 if emphasize_end :
237237 lw = 4
238238 else :
239239 lw = 2
240- plt .plot ([self .xl [nstart ], self .xl [nstart ]],
240+ plt .plot ([self .xl [nstart ], self .xl [nstart ]],
241241 [- 0.05 + self .voff , self .voff ], color = color , lw = lw )
242242
243243 if n == nstop and emphasize_end :
244244 lw = 4
245245 else :
246246 lw = 2
247- plt .plot ([self .xr [n ], self .xr [n ]],
247+ plt .plot ([self .xr [n ], self .xr [n ]],
248248 [- 0.05 + self .voff , self .voff ], color = color , lw = lw )
249249
250250
@@ -254,14 +254,15 @@ def label_center(self, idx, string, fontsize="small"):
254254 horizontalalignment = 'center' , verticalalignment = 'top' ,
255255 fontsize = fontsize )
256256
257- def label_edge (self , idx , string , fontsize = "small" , right_edge = False ):
257+ def label_edge (self , idx , string , fontsize = "small" ,
258+ right_edge = False , offset = - 0.075 ):
258259
259260 if not right_edge :
260- plt .text (self .xl [idx ], self .voff - 0.075 , string ,
261+ plt .text (self .xl [idx ], self .voff - offset , string ,
261262 horizontalalignment = 'center' , verticalalignment = 'top' ,
262263 fontsize = fontsize )
263264 else :
264- plt .text (self .xr [idx ], self .voff - 0.075 , string ,
265+ plt .text (self .xr [idx ], self .voff - offset , string ,
265266 horizontalalignment = 'center' , verticalalignment = 'top' ,
266267 fontsize = fontsize )
267268
@@ -283,11 +284,11 @@ def mark_cell_left_state(self, idx, string, color="k", value=0.5,
283284 def mark_cell_edge (self , idx , string , color = "k" , value = 0.5 ,
284285 vertical = "center" , fontsize = "medium" ):
285286
286- plt .scatter (self .xl [idx ], self .voff + value ,
287+ plt .scatter (self .xl [idx ], self .voff + value ,
287288 marker = "x" , color = color , zorder = 100 )
288289
289290 plt .text (self .xl [idx ]+ 0.05 * self .dx , self .voff + value , string ,
290- horizontalalignment = 'left' , verticalalignment = vertical ,
291+ horizontalalignment = 'left' , verticalalignment = vertical ,
291292 color = color , fontsize = fontsize )
292293
293294 def mark_cell_right_state (self , idx , string , color = "k" , value = 0.5 ,
@@ -382,11 +383,11 @@ def label_cell_avg(self, idx, string, color="k"):
382383
383384 def draw_cell_avg (self , idx , color = "0.5" , ls = "-" , filled = False ):
384385 plt .plot ([self .gr .xl [idx ], self .gr .xr [idx ]],
385- [self .gr .voff + self .a [idx ]/ self .scale ,
386+ [self .gr .voff + self .a [idx ]/ self .scale ,
386387 self .gr .voff + self .a [idx ]/ self .scale ], color = color , ls = ls )
387388 if filled :
388389 plt .fill ([self .gr .xl [idx ], self .gr .xl [idx ], self .gr .xr [idx ], self .gr .xr [idx ], self .gr .xl [idx ]],
389- [self .gr .voff , self .gr .voff + self .a [idx ]/ self .scale ,
390+ [self .gr .voff , self .gr .voff + self .a [idx ]/ self .scale ,
390391 self .gr .voff + self .a [idx ]/ self .scale , self .gr .voff , self .gr .voff ], color = color , alpha = 0.25 , ls = ls , zorder = - 100 )
391392
392393class PiecewiseLinear (PiecewiseConstant ):
@@ -401,7 +402,7 @@ def __init__(self, gr, a, nolimit=0, scale=1.0):
401402 self .nolimit = nolimit
402403
403404 self .calculate_slopes ()
404-
405+
405406 def calculate_slopes (self ):
406407 # calculate the slopes
407408 for n in range (1 , len (self .a )- 1 ):
@@ -600,7 +601,7 @@ def ppm_trace_left(self, idx, sigma, color="0.5"):
600601class Grid2d (object ):
601602 """ the base 2-d grid """
602603
603- def __init__ (self , nx , ny , ng = 0 ,
604+ def __init__ (self , nx , ny , ng = 0 ,
604605 xmin = 0.0 , xmax = 1.0 , ymin = 0.0 , ymax = 1.0 ):
605606
606607 # finite-volume or cell-centered finite-difference
@@ -633,22 +634,22 @@ def __init__(self, nx, ny, ng = 0,
633634 def draw_grid (self , color = "k" ):
634635 # x lines
635636 for n in range (self .ny ):
636- plt .plot ([self .xmin - 0.25 * self .dx , self .xmax + 0.25 * self .dx ],
637- [self .yl [self .ng + n ], self .yl [self .ng + n ]],
637+ plt .plot ([self .xmin - 0.25 * self .dx , self .xmax + 0.25 * self .dx ],
638+ [self .yl [self .ng + n ], self .yl [self .ng + n ]],
638639 color = color , lw = 2 )
639-
640- plt .plot ([self .xmin - 0.25 * self .dx , self .xmax + 0.25 * self .dx ],
641- [self .yr [self .ng + self .ny - 1 ], self .yr [self .ng + self .ny - 1 ]],
640+
641+ plt .plot ([self .xmin - 0.25 * self .dx , self .xmax + 0.25 * self .dx ],
642+ [self .yr [self .ng + self .ny - 1 ], self .yr [self .ng + self .ny - 1 ]],
642643 color = color , lw = 2 )
643644
644645 # y lines
645646 for n in range (self .nx ):
646- plt .plot ([self .xl [self .ng + n ], self .xl [self .ng + n ]],
647- [self .ymin - 0.25 * self .dy , self .ymax + 0.25 * self .dy ],
647+ plt .plot ([self .xl [self .ng + n ], self .xl [self .ng + n ]],
648+ [self .ymin - 0.25 * self .dy , self .ymax + 0.25 * self .dy ],
648649 color = color , lw = 2 )
649-
650- plt .plot ([self .xr [self .ng + self .nx - 1 ], self .xr [self .ng + self .nx - 1 ]],
651- [self .ymin - 0.25 * self .dy , self .ymax + 0.25 * self .dy ],
650+
651+ plt .plot ([self .xr [self .ng + self .nx - 1 ], self .xr [self .ng + self .nx - 1 ]],
652+ [self .ymin - 0.25 * self .dy , self .ymax + 0.25 * self .dy ],
652653 color = color , lw = 2 )
653654
654655
@@ -670,7 +671,7 @@ class FVGrid2d(Grid2d):
670671 """ a 2-d finite-volume grid """
671672
672673 def label_cell_center (self , idx , jdx , string , fontsize = "medium" , color = "k" ):
673- plt .text (self .xc [idx ], self .yc [jdx ],
674+ plt .text (self .xc [idx ], self .yc [jdx ],
674675 string , fontsize = fontsize , color = color ,
675676 horizontalalignment = 'center' , verticalalignment = 'center' )
676677
@@ -681,48 +682,48 @@ def shade_cell(self, idx, jdx):
681682 yr = self .yr [jdx ]
682683 plt .fill ([xl , xl , xr , xr , xl ], [yl , yr , yr , yl , yl ], "0.75" )
683684
684- def mark_cell_left_state_x (self , idx , jdx , string , color = "k" ,
685+ def mark_cell_left_state_x (self , idx , jdx , string , color = "k" ,
685686 fontsize = "medium" ):
686- plt .scatter (self .xr [idx ]- 0.05 * self .dx , self .yc [jdx ],
687+ plt .scatter (self .xr [idx ]- 0.05 * self .dx , self .yc [jdx ],
687688 marker = "x" , s = 50 , color = color )
688- plt .text (self .xr [idx ]- 0.075 * self .dx , self .yc [jdx ], string ,
689+ plt .text (self .xr [idx ]- 0.075 * self .dx , self .yc [jdx ], string ,
689690 fontsize = fontsize , rotation = "270" , color = color ,
690691 horizontalalignment = 'right' , verticalalignment = 'center' )
691692
692- def mark_cell_right_state_x (self , idx , jdx , string , color = "k" ,
693+ def mark_cell_right_state_x (self , idx , jdx , string , color = "k" ,
693694 fontsize = "medium" ):
694- plt .scatter (self .xl [idx ]+ 0.05 * self .dx , self .yc [jdx ],
695+ plt .scatter (self .xl [idx ]+ 0.05 * self .dx , self .yc [jdx ],
695696 marker = "x" , s = 50 , color = color )
696- plt .text (self .xl [idx ]+ 0.075 * self .dx , self .yc [jdx ], string ,
697+ plt .text (self .xl [idx ]+ 0.075 * self .dx , self .yc [jdx ], string ,
697698 fontsize = fontsize , rotation = "270" , color = color ,
698699 horizontalalignment = 'left' , verticalalignment = 'center' )
699700
700- def mark_cell_state_y (self , idx , jdx , string , color = "k" ,
701+ def mark_cell_state_y (self , idx , jdx , string , color = "k" ,
701702 fontsize = "medium" , off_sign = 1.0 ):
702- plt .scatter (self .xc [idx ], self .yr [jdx ],
703+ plt .scatter (self .xc [idx ], self .yr [jdx ],
703704 marker = "x" , s = 50 , color = color )
704705 if off_sign > 0 :
705706 align = "bottom"
706707 else :
707708 align = "top"
708709
709- plt .text (self .xc [idx ], self .yr [jdx ]+ off_sign * 0.05 * self .dy , string ,
710+ plt .text (self .xc [idx ], self .yr [jdx ]+ off_sign * 0.05 * self .dy , string ,
710711 fontsize = fontsize , rotation = "0" , color = color ,
711712 horizontalalignment = 'center' , verticalalignment = align )
712713
713- def mark_cell_left_state_y (self , idx , jdx , string , color = "k" ,
714+ def mark_cell_left_state_y (self , idx , jdx , string , color = "k" ,
714715 fontsize = "medium" ):
715- plt .scatter (self .xc [idx ], self .yr [jdx ]- 0.05 * self .dy ,
716+ plt .scatter (self .xc [idx ], self .yr [jdx ]- 0.05 * self .dy ,
716717 marker = "x" , s = 50 , color = color )
717- plt .text (self .xc [idx ], self .yr [jdx ]- 0.075 * self .dy , string ,
718+ plt .text (self .xc [idx ], self .yr [jdx ]- 0.075 * self .dy , string ,
718719 fontsize = fontsize , rotation = "0" , color = color ,
719720 horizontalalignment = 'center' , verticalalignment = 'top' )
720721
721- def mark_cell_right_state_y (self , idx , jdx , string , color = "k" ,
722+ def mark_cell_right_state_y (self , idx , jdx , string , color = "k" ,
722723 fontsize = "medium" ):
723- plt .scatter (self .xc [idx ], self .yl [jdx ]+ 0.05 * self .dy ,
724+ plt .scatter (self .xc [idx ], self .yl [jdx ]+ 0.05 * self .dy ,
724725 marker = "x" , s = 50 , color = color )
725- plt .text (self .xc [idx ], self .yl [jdx ]+ 0.075 * self .dy , string ,
726+ plt .text (self .xc [idx ], self .yl [jdx ]+ 0.075 * self .dy , string ,
726727 fontsize = fontsize , rotation = "0" , color = color ,
727728 horizontalalignment = 'center' , verticalalignment = 'bottom' )
728729
@@ -733,7 +734,6 @@ class FDGrid2d(Grid2d):
733734
734735 def label_cell_center (self , idx , jdx , string , fontsize = "medium" , color = "k" ):
735736 plt .scatter ([self .xc [idx ]], [self .yc [jdx ]], marker = "x" , color = color )
736- plt .text (self .xc [idx ]+ 0.075 * self .dx , self .yc [jdx ]+ 0.075 * self .dy ,
737+ plt .text (self .xc [idx ]+ 0.075 * self .dx , self .yc [jdx ]+ 0.075 * self .dy ,
737738 string , fontsize = fontsize , color = color ,
738739 horizontalalignment = 'left' , verticalalignment = 'center' )
739-
0 commit comments