def initial_stepAB(self): global dudt global dudtm1 global JSdudt global JSdudtm1 global Mdudt global Mdudtm1 global Zdudt global Zdudtm1 if self.flux_choice == "center": rflux = 0.25 * (self.u + np.roll(self.u, -1)) ** 2 dudt = -(rflux - np.roll(rflux, 1)) / 1.0 dudtm1 = dudt self.u += self.dt * dudt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) rflux = 0.25 * (self.u + np.roll(self.u, -1)) ** 2 dudt = -(rflux - np.roll(rflux, 1)) / 1.0 self.u = self.u + (1.5 * dudt - 0.5 * dudtm1) * self.dt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) elif self.flux_choice == "JS": JSdudt = MomentumAdvection(self.u) JSdudt.fill("WENO-JS") JSdudtm1 = JSdudt self.u += self.dt * JSdudt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) JSdudt.fill("WENO-JS") self.u = self.u + (1.5 * JSdudt - 0.5 * JSdudtm1) * self.dt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) elif self.flux_choice == "M": Mdudt = MomentumAdvection(self.u) Mdudt.fill("WENO-M") Mdudtm1 = Mdudt self.u += self.dt * Mdudt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) Mdudt.fill("WENO-M") self.u = self.u + (1.5 * Mdudt - 0.5 * Mdudtm1) * self.dt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) elif self.flux_choice == "Z": Zdudt = MomentumAdvection(self.u) Zdudt.fill("WENO-Z") Zdudtm1 = Zdudt self.u += self.dt * Zdudt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) Zdudt.fill("WENO-Z") self.u = self.u + (1.5 * Zdudt - 0.5 * Zdudtm1) * self.dt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy())
def update(self): global dudt global dudtm1 global dudtm2 global JSdudt global JSdudtm1 global JSdudtm2 global Mdudt global Mdudtm1 global Mdudtm2 global Zdudt global Zdudtm1 global Zdudtm2 if self.timeintegration == "AB": if self.flux_choice == "center": dudtm2 = dudtm1 dudtm1 = dudt rflux = 0.25 * (self.u + np.roll(self.u, -1)) ** 2 dudt = -(rflux - np.roll(rflux, 1)) / 1.0 self.u = self.u + ((23.0 / 12.0) * dudt - (4.0 / 3.0) * dudtm1 + (5.0 / 12.0) * dudtm2) * self.dt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) elif self.flux_choice == "JS": JSdudtm2 = JSdudtm1 JSdudtm1 = JSdudt JSdudt = MomentumAdvection(self.u) JSdudt.fill("WENO-JS") self.u = self.u + ((23.0 / 12.0) * JSdudt - (4.0 / 3.0) * JSdudtm1 + (5.0 / 12.0) * JSdudtm2) * self.dt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) elif self.flux_choice == "M": Mdudtm2 = Mdudtm1 Mdudtm1 = Mdudt Mdudt = MomentumAdvection(self.u) Mdudt.fill("WENO-M") self.u = self.u + ((23.0 / 12.0) * Mdudt - (4.0 / 3.0) * Mdudtm1 + (5.0 / 12.0) * Mdudtm2) * self.dt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) elif self.flux_choice == "Z": Zdudtm2 = Zdudtm1 Zdudtm1 = Zdudt Zdudt = MomentumAdvection(self.u) Zdudt.fill("WENO-Z") self.u = self.u + ((23.0 / 12.0) * Zdudt - (4.0 / 3.0) * Zdudtm1 + (5.0 / 12.0) * Zdudtm2) * self.dt self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) elif self.timeintegration == "RK3": if self.flux_choice == "center": rflux = 0.25 * (self.u + np.roll(self.u, -1)) ** 2 dudtR = -(rflux - np.roll(rflux, 1)) / 1.0 temp1 = self.u + self.dt * dudtR rflux = 0.25 * (temp1 + np.roll(temp1, -1)) ** 2 dudtR = -(rflux - np.roll(rflux, 1)) / 1.0 temp2 = 0.75 * self.u + 0.25 * temp1 + 0.25 * self.dt * dudtR rflux = 0.25 * (temp2 + np.roll(temp2, -1)) ** 2 dudtR = -(rflux - np.roll(rflux, 1)) / 1.0 self.u = (1.0 / 3.0) * self.u + (2.0 / 3.0) * temp2 + (2.0 / 3.0) * self.dt * dudtR self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) elif self.flux_choice == "JS": dudtR = MomentumAdvection(self.u) dudtR.fill("WENO-JS") temp1 = self.u + self.dt * dudtR.tendency dudtR = MomentumAdvection(temp1) dudtR.fill("WENO-JS") temp2 = 0.75 * self.u + 0.25 * temp1 + 0.25 * self.dt * dudtR.tendency dudtR = MomentumAdvection(temp2) dudtR.fill("WENO-JS") self.u = (1.0 / 3.0) * self.u + (2.0 / 3.0) * temp2 + (2.0 / 3.0) * self.dt * dudtR.tendency self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) elif self.flux_choice == "M": dudtR = MomentumAdvection(self.u) dudtR.fill("WENO-M") temp1 = self.u + self.dt * dudtR.tendency dudtR = MomentumAdvection(temp1) dudtR.fill("WENO-M") temp2 = 0.75 * self.u + 0.25 * temp1 + 0.25 * self.dt * dudtR.tendency dudtR = MomentumAdvection(temp2) dudtR.fill("WENO-M") self.u = (1.0 / 3.0) * self.u + (2.0 / 3.0) * temp2 + (2.0 / 3.0) * self.dt * dudtR.tendency self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy()) elif self.flux_choice == "Z": dudtR = MomentumAdvection(self.u) dudtR.fill("WENO-Z") temp1 = self.u + self.dt * dudtR.tendency dudtR = MomentumAdvection(temp1) dudtR.fill("WENO-Z") temp2 = 0.75 * self.u + 0.25 * temp1 + 0.25 * self.dt * dudtR.tendency dudtR = MomentumAdvection(temp2) dudtR.fill("WENO-Z") self.u = (1.0 / 3.0) * self.u + (2.0 / 3.0) * temp2 + (2.0 / 3.0) * self.dt * dudtR.tendency self.time_elapsed += self.dt self.timesteps.append(self.time_elapsed) self.energy.append(self.Energy())