CS 294-73 Software Engineering for Scientific Computing http://www.cs.berkeley.edu/~colella/cs294fall2013 Lecture 16: Particle Methods; Homework #4
Discretizing Time-Dependent Problems From here on in, we will have occasion to solve timeevolution equations. Abstractly, these take the form of ordinary differential equations. In particle dynamics, this is how the problem is stated. {x k, v k,w k } N k=1 dx k = v k dt dv k = F (x k ) dt F (x) = X k 0 w k 0(r )(x x k 0) 2!
Discretizing Time-Dependent Problems We can convert discretizations of partial differential equations to systems of ordinary differential equations by discretizing in space first, which then leads to a system of ODEs for the spatially discretized variables. 3!
Particle Discretizations of PDE Particle discretizations fall into the latter category, since they start with a particular spatial discretization of the Lagrangian form of the equations. 4!
Discretizing ODEs To discretize ODEs, we replace derivatives by difference approximations. We will focus here on one-step methods: q is the order of accuracy of the method: Q n = Q(n Δt) + (Δt) p. Closely related to quadrature formulas for approximating integrals. 5!
Discretizing ODEs To discretize ODEs, we replace derivatives by difference approximations. We will focus here on one-step methods: q is the order of accuracy of the method: Q n = Q(n Δt) + (Δt) q. Closely related to quadrature formulas for approximating integrals. Essential question: for what choices of stable? Answer: check for are various methods Stability region is given in terms of. In the general case, s are the eigenvalues of the matrix. 6!
Discretizing ODEs Some simple examples: Forward Euler: stable if Backward Euler: stable if, Trapezoidal rule: 7!
Discretizing ODEs Generally, use implicit methods if there are modes for which, and the time step for an explicit method would be much smaller than the one required to resolve the effective dynamics. For particles, we typically use explicit methods., 8!
Discretizing ODEs Fourth-order Runge-Kutta: Generalizes Simpson s rule for integrals. 9!
Programming ODE Methods Generic programming: only want to do it once.! template <class X, class F, class dx> class RK4! {!!public: void advance(double a_time, double a_dt, X& a_state);!!protected:!!dx m_k;!!dx m_delta;!!f m_f;! };! 10!
Programming ODE Methods Generic programming: only want to do it once.! template <class X, class F, class dx>! void RK4<X,F,dX>::advance(double a_time, double a_dt, X& a_state)! {!!m_delta.init(a_state);! m_k.init(a_state);! m_f(m_k, a_time, a_dt, a_state, m_k); // compute k1!!// F::operator()(dX,Real,X,dX);! m_delta.increment(sixth, m_k); m_k*=half;! m_f(m_k, a_time+half*a_dt, a_dt, a_state, m_k); // compute k2 m_delta.increment(third, m_k); m_k*=half;!!m_f(m_k, a_time+half*a_dt, a_dt, a_state, m_k); // conpute k3 m_delta.increment(third, m_k);!!m_f(m_k, a_time+a_dt, a_dt, a_state, m_k); // compute k4 m_delta.increment(sixth, m_k);! a_state.increment(m_delta);! }! 11!
Discretizing ODEs Fourth-order Runge-Kutta: Generalizes Simpson s rule for integrals. 12!
Programming ODE Methods Generic programming: only want to do it once.! template <class X, class F, class dx>! void RK4<X,F,dX>::advance(double a_time, double a_dt, X& a_state)! {!!m_delta.init(a_state);! m_k.init(a_state);! m_f(m_k, a_time, a_dt, a_state, m_k); // compute k1 m_delta.increment(sixth, m_k); m_k*=half;! m_f(m_k, a_time+half*a_dt, a_dt, a_state, m_k); // compute k2 m_delta.increment(third, m_k); m_k*=half;!!m_f(m_k, a_time+half*a_dt, a_dt, a_state, m_k); // conpute k3 m_delta.increment(third, m_k);!!m_f(m_k, a_time+a_dt, a_dt, a_state, m_k); // compute k4 m_delta.increment(sixth, m_k);! a_state.increment(m_delta);! }! 13!
Programming Assignment 4 An experiment: PIC methods for vorticity, but regularized using the theory. Algorithmic issues Software / implementation. 14!
Regularized particle methods Particle method for vorticity transport in 2D. α < 1 essential for stability. 15!
Regularized particle methods 16!
Test Problem 17!
Particle-in-cell Methods The velocity induced by a single particle on itself is zero. 18!
Particle-in-cell Methods 19!
Particle-in-cell Methods Difficulty with particle-in-cell methods: marginally stable for long-time integration. 20!
Regularized PIC Conjecture: problem with PIC is that the regularization corresponds to alpha = 1. 21!
Division of Labor I will provide an implementation of Hockney s algorithm for computing as well as the templated RK4 class. You will implement the rest of the particle method: Deposition of charge and calculation of velocity field. The template classes X, dx, F appropriate to the PIC method. 22!
Bin Sorting class Particle{...} // Describes a single particle: position, vorticity.! vector<particle> particles;! // This is your persistent data representation of particles.! RectMDArray<vector<int> >;! // Whenever you evaluate the forces, step one will be to binsort. Each! // element of the vector contains the index into element of the! // vector<particle> particles contained in that bin.! 23!