55import advection .advective_fluxes as flx
66import mesh .patch as patch
77from simulation_null import NullSimulation , grid_setup , bc_setup
8+ import particles .particles as particles
9+ import util .plot_tools as plot_tools
810
911
1012class Simulation (NullSimulation ):
@@ -25,6 +27,11 @@ def initialize(self):
2527
2628 self .cc_data = my_data
2729
30+ if self .rp .get_param ("particles.do_particles" ) == 1 :
31+ n_particles = self .rp .get_param ("particles.n_particles" )
32+ particle_generator = self .rp .get_param ("particles.particle_generator" )
33+ self .particles = particles .Particles (self .cc_data , bc , n_particles , particle_generator )
34+
2835 # now set the initial conditions for the problem
2936 problem = importlib .import_module ("advection.problems.{}" .format (self .problem_name ))
3037 problem .init_data (self .cc_data , self .rp )
@@ -73,6 +80,16 @@ def evolve(self):
7380 dens .v ()[:, :] = dens .v () + dtdx * (flux_x .v () - flux_x .ip (1 )) + \
7481 dtdy * (flux_y .v () - flux_y .jp (1 ))
7582
83+ if self .particles is not None :
84+ myg = self .cc_data .grid
85+ u = self .rp .get_param ("advection.u" )
86+ v = self .rp .get_param ("advection.v" )
87+
88+ u2d = myg .scratch_array () + u
89+ v2d = myg .scratch_array () + v
90+
91+ self .particles .update_particles (self .dt , u2d , v2d )
92+
7693 # increment the time
7794 self .cc_data .t += self .dt
7895 self .n += 1
@@ -87,16 +104,36 @@ def dovis(self):
87104
88105 myg = self .cc_data .grid
89106
90- plt .imshow (np .transpose (dens .v ()),
107+ _ , axes , cbar_title = plot_tools .setup_axes (myg , 1 )
108+
109+ # plot density
110+ ax = axes [0 ]
111+ img = ax .imshow (np .transpose (dens .v ()),
91112 interpolation = "nearest" , origin = "lower" ,
92113 extent = [myg .xmin , myg .xmax , myg .ymin , myg .ymax ],
93114 cmap = self .cm )
94115
95- plt .xlabel ("x" )
96- plt .ylabel ("y" )
116+ ax .set_xlabel ("x" )
117+ ax .set_ylabel ("y" )
118+
119+ # needed for PDF rendering
120+ cb = axes .cbar_axes [0 ].colorbar (img )
121+ cb .solids .set_rasterized (True )
122+ cb .solids .set_edgecolor ("face" )
123+
97124 plt .title ("density" )
98125
99- plt .colorbar ()
126+ if self .particles is not None :
127+ particle_positions = self .particles .get_positions ()
128+
129+ # dye particles
130+ colors = self .particles .get_init_positions ()[:, 0 ]
131+
132+ # plot particles
133+ ax .scatter (particle_positions [:, 0 ],
134+ particle_positions [:, 1 ], c = colors , cmap = "Greys" )
135+ ax .set_xlim ([myg .xmin , myg .xmax ])
136+ ax .set_ylim ([myg .ymin , myg .ymax ])
100137
101138 plt .figtext (0.05 , 0.0125 , "t = {:10.5f}" .format (self .cc_data .t ))
102139
0 commit comments