[docs]classRKIntegrator:"""the integration class for CellCenterData2d, supporting RK integration"""def__init__(self,t,dt,method="RK4"):"""t is the starting time, dt is the total timestep to advance, method = {2,4} is the temporal method"""self.method=methodself.t=tself.dt=dt# storage for the intermediate stagesself.k=[None]*len(b[self.method])self.start=None
[docs]defnstages(self):"""return the number of stages"""returnlen(b[self.method])
[docs]defset_start(self,start):"""store the starting conditions (should be a CellCenterData2d object)"""self.start=start
[docs]defstore_increment(self,istage,k_stage):"""store the increment for stage istage -- this should not have a dt weighting"""self.k[istage]=k_stage
[docs]defget_stage_start(self,istage):"""get the starting conditions (a CellCenterData2d object) for stage istage"""ifistage==0:ytmp=self.startelse:ytmp=patch.cell_center_data_clone(self.start)forninrange(ytmp.nvar):var=ytmp.get_var_by_index(n)forsinrange(istage):var.v()[:,:]+=self.dt*a[self.method][istage,s]*self.k[s].v(n=n)[:,:]ytmp.t=self.t+c[self.method][istage]*self.dtreturnytmp
[docs]defcompute_final_update(self):"""this constructs the final t + dt update, overwriting the initial data"""ytmp=self.startforninrange(ytmp.nvar):var=ytmp.get_var_by_index(n)forsinrange(self.nstages()):var.v()[:,:]+=self.dt*b[self.method][s]*self.k[s].v(n=n)[:,:]returnytmp
def__str__(self):returnf"integration method: {self.method}; number of stages: {self.nstages()}"