Beispiel #1
0
class movie(object):
    '''
    
    '''
    def __init__(self, hdf5_file, nPlot=1, ntMax=0, write=False):
        '''
        Constructor
        '''

        self.diagnostics = Diagnostics(hdf5_file)

        if ntMax > 0 and ntMax < self.diagnostics.nt:
            self.nt = ntMax
        else:
            self.nt = self.diagnostics.nt

        self.nPlot = nPlot
        self.plot = PlotMHD2D(self.diagnostics, self.diagnostics.nt, self.nt,
                              nPlot, write)

        self.init()

    def init(self):
        self.update(0)

    def update(self, itime, final=False):
        self.diagnostics.read_from_hdf5(itime)
        self.diagnostics.update_invariants(itime)

        return self.plot.update(itime, final=final)

    def run(self, write=False):
        for itime in range(1, self.nt + 1):
            print("it = %4i" % (itime))
            self.update(itime, final=(itime == self.nt))
Beispiel #2
0
class Plot(object):
    '''
    
    '''
    def __init__(self, hdf5_file, nPlot=1, ntMax=0):
        '''
        Constructor
        '''

        self.diagnostics = Diagnostics(hdf5_file)

        if ntMax > 0 and ntMax < self.diagnostics.nt:
            self.nt = ntMax
        else:
            self.nt = self.diagnostics.nt

        self.plot = PlotMHD2D(self.diagnostics,
                              args.hdf5_file.replace(".hdf5", ""), self.nt,
                              nPlot)

    def update(self, itime):
        self.diagnostics.read_from_hdf5(itime)
        self.diagnostics.update_invariants(itime)

        if itime > 0:
            self.plot.add_timepoint()

        self.plot.update()

    def run(self):
        for itime in range(1, self.nt + 1):
            print("it = %4i" % (itime))
            self.update(itime)
Beispiel #3
0
class replay(object):
    '''
    
    '''

    def __init__(self, hdf5_file, nPlot=1):
        '''
        Constructor
        '''
        
        self.diagnostics = Diagnostics(hdf5_file)
        
        self.nPlot = nPlot
        self.plot  = PlotMHD2D(self.diagnostics, self.diagnostics.nt, nPlot)
#        self.plot.configure_traits()
        
        self.init()
    
    def init(self):
        self.update(0)
    
    
    def update(self, itime, final=False):
        self.diagnostics.read_from_hdf5(itime)
        self.diagnostics.update_invariants(itime)
        
        if itime > 0:
            self.plot.add_timepoint()
        
        if (itime == 0 or itime == 1 or (itime-1) % self.nPlot == 0 or itime-1 == self.plot.nTime):
            self.diagnostics.calculate_divergence()
#            print("   min(Bx)    = %20.12E,     max(Bx)    = %20.12E" % (self.diagnostics.Bx.min(), self.diagnostics.Bx.max()))
#            print("   min(By)    = %20.12E,     max(By)    = %20.12E" % (self.diagnostics.By.min(), self.diagnostics.By.max()))
#            print("   min(Vx)    = %20.12E,     max(Vx)    = %20.12E" % (self.diagnostics.Vx.min(), self.diagnostics.Vx.max()))
#            print("   min(Vy)    = %20.12E,     max(Vy)    = %20.12E" % (self.diagnostics.Vy.min(), self.diagnostics.Vy.max()))
#            print("   min(div B) = %20.12E,     max(div B) = %20.12E" % (self.diagnostics.divB.min(), self.diagnostics.divB.max()))
#            print("   min(div V) = %20.12E,     max(div V) = %20.12E" % (self.diagnostics.divV.min(), self.diagnostics.divV.max()))
            print("   energy     = %20.12E" % self.diagnostics.energy)
            print("   helicity   = %20.12E" % self.diagnostics.helicity)
            print("   max(div B) = %20.12E" % max(-self.diagnostics.divB.min(), self.diagnostics.divB.max()))
            print("   max(div V) = %20.12E" % max(-self.diagnostics.divV.min(), self.diagnostics.divV.max()))
            print
        
        return self.plot.update(final=final)
    
    
    def run(self):
        for itime in range(1, self.diagnostics.nt+1):
            print("it = %4i" % (itime))
            self.update(itime, final=(itime == self.diagnostics.nt))
        
    
    def movie(self, outfile, fps=1):
        self.plot.nPlot = 1
        
        ani = animation.FuncAnimation(self.plot.figure, self.update, np.arange(1, self.diagnostics.nt+1), 
                                      init_func=self.init, repeat=False, blit=True)
        ani.save(outfile, fps=fps)