2 ms·
Nice! I've always been fascinated by tools and techniques that reduce the burden of solving complicated PDEs. After deriving, by hand, the finite difference mat
by brotchie 14y ago
Nice! I've always been fascinated by tools and techniques that reduce the burden of solving complicated PDEs. After deriving, by hand, the finite difference matrix for a two-dimensional 2nd order PDE with varied boundary conditions I thought "there has to be a better way!"
In a similar manner to you I wrote an internal DSL in Python that lets you specify your system, for example that pesky 2D 2nd order PDE
pde = PDE('dx_dt', V)
pde.eqn = mu_e * E * d(V, E) - \
(1-tau)*sigma_E*E*(sigma_gamma*A*rho_gamma_E + sigma_D*D*rho_E_D) * d(V, A*E) + \
(1 - tau) * (E - gamma*A - r_f*D) * d(V, A) + \
0.5 * (1-tau)**2 * ((sigma_gamma * A)**2 + \
(sigma_D*D)**2 - \
2*sigma_gamma*A*sigma_D*D*rho_gamma_D) * d(V, A**2) + \
0.5 * sigma_E**2 * E**2 * d(V, E**2) - \
(r_f + lambda_gamma + lambda_E) * V
and appropriate boundary conditions in Python. My pdegen tool then works on the resultant AST to generate the primary finite difference matrix. Given some initial conditions this matrix can then be used with any linear algebra library to time-step the system.
You've given me motivation to clean up my code and release it :)