pencil.math.laplace_solver ========================== .. py:module:: pencil.math.laplace_solver .. autoapi-nested-parse:: This code contains various functions to solve the vector form of the Laplace equation in various coordinate systems (Cartesian, cylindrical and spherical) using finite differences. Additionally, one can find functions to solve the scalar Laplace equation in Cartesian, cylidrindical and spherical coordinate systems, since these are used (at least in the case of Cartesian and cylindrical) in the vector solvers. Functions --------- .. autoapisummary:: pencil.math.laplace_solver.laplace_scalar_cartesian pencil.math.laplace_solver.laplace_vector_cartesian pencil.math.laplace_solver.laplace_scalar_cylindrical pencil.math.laplace_solver.laplace_vector_cylindrical pencil.math.laplace_solver.laplace_scalar_spherical pencil.math.laplace_solver.laplace_vector_spherical Module Contents --------------- .. py:function:: laplace_scalar_cartesian(bc, dx, dy, dz, niter=200) laplace_scalar_cartesian(bc, dx, dy, dz, niter=100) Solve the scalar Laplace equation in Cartesian coordinates in 3 dimensions using finite differences. :param bc: Boundary conditions on exterior points. Keep the inner points 0. :type bc: ndarray of shape [nz, ny, nx] dx, dy, dz : floats Grid spacing in eaach direction. niter : int Number of iterations. :rtype: ndarray with the same shape as bc, representing solution to the Laplace equation. .. py:function:: laplace_vector_cartesian(bx, by, bz, dx, dy, dz, niter=200) laplace_vector_cartesian(bx, by, bz, dx, dy, dz, niter=1000) Solve the vector Laplace equation in Cartesian coordinates in 3 dimensions using finite differences. This function simply applies the scalar function to the three components. :param bx: Boundary conditions on exterior points. Keep the inner points 0. :type bx: ndarrays of shape [nz, ny, nx] :param by: Boundary conditions on exterior points. Keep the inner points 0. :type by: ndarrays of shape [nz, ny, nx] :param bz: Boundary conditions on exterior points. Keep the inner points 0. :type bz: ndarrays of shape [nz, ny, nx] dx, dy, dz : float Grid spacing in eaach direction. niter : int Number of iterations. :rtype: ndarray with the shape [3, nz, ny, nx], representing solution to the Laplace equation. .. py:function:: laplace_scalar_cylindrical(bc, r, theta, z, niter=200) laplace_scalar_cylindrical(bc, r, theta, z, niter=1000) Solve the scalar Laplace equation in cylindical coordinates in 3 dimensions using finite differences. :param bc: Boundary conditions on exterior points. Keep the inner points 0. :type bc: ndarray of shape [nz, ny, nx] r, theta, z : ndarrays of shape [nx], [ny] and [nz] 1D coordinate arrays of r, theta and z. niter : int Number of iterations. :rtype: ndarray with the same shape as bc, representing solution to the Laplace equation. .. py:function:: laplace_vector_cylindrical(br, btheta, bz, r, theta, z, niter=200) laplace_vector_cylindrical(br, btheta, bz, r, theta, z, niter=200) Solve the vector Laplace equation in cylindrical coordinates in 3 dimensions using finite differences. :param br: Boundary conditions on exterior points. Keep the inner points 0. :type br: ndarrays of shape [nz, ny, nx] :param btheta: Boundary conditions on exterior points. Keep the inner points 0. :type btheta: ndarrays of shape [nz, ny, nx] :param bz: Boundary conditions on exterior points. Keep the inner points 0. :type bz: ndarrays of shape [nz, ny, nx] r, theta, z : ndarrays of shape [nx], [ny] and [nz] 1D coordinate arrays of r, theta and z. niter : int Number of iterations. :rtype: ndarray with the shape [3, nz, ny, nx], representing solution to the Laplace equation. .. py:function:: laplace_scalar_spherical(bc, r, theta, phi, niter=200) laplace_scalar_spherical(bc, r, theta, phi, niter=200) Solve the scalar Laplace equation in spherical coordinates in 3 dimensions using finite differences. :param bc: Boundary conditions on exterior points. Keep the inner points 0. :type bc: ndarray of shape [nz, ny, nx] r, theta, phi : ndarrays of shape [nx], [ny] and [nz] 1D coordinate arrays of r, theta and phi. The convention is taken that theta ranges from 0 to pi and phi ranges from 0 to 2pi. Note that singularities arise in the equation when theta = 0 and r = 0. This may produce unintended results. niter : int Number of iterations. :rtype: ndarray with the same shape as bc, representing solution to the Laplace equation. .. py:function:: laplace_vector_spherical(br, btheta, bphi, r, theta, phi, niter=200) laplace_vector_spherical(br, btheta, bphi, r, theta, phi, niter=200) Solve the scalar Laplace equation in spherical coordinates in 3 dimensions using finite differences. :param bc: Boundary conditions on exterior points. Keep the inner points 0. :type bc: ndarray of shape [nz, ny, nx] :param btheta: Boundary conditions on exterior points. Keep the inner points 0. :type btheta: ndarray of shape [nz, ny, nx] :param bphi: Boundary conditions on exterior points. Keep the inner points 0. :type bphi: ndarray of shape [nz, ny, nx] r, theta, phi : ndarrays of shape [nx], [ny] and [nz] 1D coordinate arrays of r, theta and phi. The convention is taken that theta ranges from 0 to pi and phi ranges from 0 to 2pi. Note that singularities arise in the equation when theta = 0 and r = 0. This may produce unintended results. niter : int Number of iterations. :rtype: ndarray with the shape [3, nz, ny, nx], representing solution to the Laplace equation.