I have an algorithm (second derivative) to solve poisson equaition. Why the commented…
- User
I have an algorithm (second derivative) to solve poisson equaition. Why the commented algorithm don't work? I have tried very fine grid and small dt and still not work, so there must be something wrong with it
codefor (int i = 2; i < (num_grids_x - 2); i++) { for (int j = 2; j < (num_grids_y - 2); j++) { // p[i][j] = ( // (dy * dy) * (-temp_p[i + 2][j] + 16.0 * temp_p[i + 1][j] + 16.0 * temp_p[i - 1][j] - temp_p[i - 2][j]) // + (dx * dx) * (-temp_p[i][j + 2] + 16.0 * temp_p[i][j + 1] + 16.0 * temp_p[i][j - 1] - temp_p[i][j - 2]) // - 12.0 * b[i][j] * (dx * dx * dy * dy) // ) / (30.0 * (dx * dx + dy * dy)); p[i][j] = ( (dy * dy) * (temp_p[i + 1][j] + temp_p[i - 1][j]) + (dx * dx) * (temp_p[i][j + 1] + temp_p[i][j - 1]) - b[i][j] * (dx * dx * dy * dy) ) / (2.0 * (dx * dx + dy * dy)); } } Assistant
A Poisson equation solver!
The commented algorithm is an attempt to discretize the Poisson equation using a finite difference method with a higher-order accuracy scheme. Specifically, it appears to be a fourth-order accurate discretization of the Laplacian operator.
There are a few reasons why this algorithm might not work as expected:
- Incorrect stencil: The stencil used in the commented algorithm is not a standard fourth-order accurate stencil for the Laplacian operator. The coefficients and the arrangement of the neighboring points seem to be incorrect.
- Lack of boundary handling: The algorithm does not handle boundary conditions correctly. In a Poisson equation solver, you need to apply boundary conditions to the solution on the boundaries of the domain. The commented algorithm does not account for this.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.