1 Introduction

Many physical phenomenon in acoustics, seismology, electromagnetic radiation, nondestructive testing, medical imaging and others can be modeled by the Helmholtz equation. Therefore, many researchers (e.g., see [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55]) are working on the development of accurate numerical techniques for the solution of the Helmholtz equation that has a lot of important civil and military engineering applications. Many of these numerical techniques finally reduce to a discrete system with compact stencils; e.g., different modifications of the finite element method, the isogeometric elements, the spectral element method, the finite difference method and others. The finite element method, the finite volume method, the isogeometric elements, the spectral elements and similar techniques represent very powerful tools for the solution of PDEs for a complex geometry. However, the generation of non-uniform meshes for a complex geometry is not simple and may lead to the decrease in accuracy of these techniques if ’bad’ elements (e.g., elements with small angles) appear in the mesh. Moreover, the conventional derivation of discrete equations for these techniques (e.g., based on the Galerkin approaches) does not lead to the optimal accuracy. For example, it has been shown in many publications on wave propagation that at the same width of stencil equations of a semi-discrete system for regular rectangular domains with uniform meshes, the accuracy of the conventional linear finite elements can be improved from order two to order four (e.g., see [56,57,58,59,60,61,62,63,64,65,66,67] and others), the accuracy of the conventional high-order finite and isogeometric elements can be improved from order 2p to order \(2p+2\) where p is the element order (e.g., see [68,69,70,71,72]). However, the improvement in the order of accuracy for the high-order elements in [68,69,70,71,72] is not optimal. In [73,74,75,76] the order of accuracy of the high-order elements on rectangular domains has been improved to 4p and this order is optimal at a given width of stencil equations.

There is a significant number of publications related to the numerical solution of different PDEs on irregular domains with uniform embedded meshes. For example, we can mention the following fictitious domain numerical methods that use uniform embedded meshes: the embedded finite difference method, the cut finite element method, the finite cell method, the Cartesian grid method, the immersed interface method, the virtual boundary method, the embedded boundary method, etc; e.g., see [77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106] and many others. The main objective of these techniques is to simplify the mesh generation for irregular domains as well as to mitigate the effect of ’bad’ elements. For example, the techniques based of the finite element formulations (such as the cut finite element method, the finite cell method, the virtual boundary method and others) yield the \(p+1\) order of accuracy even with small cut cells generated by the complicated irregular boundary (e.g., see [78,79,80,81, 85, 104, 105] and many others). The main advantage of the embedded boundary method developed in [86,87,88, 100, 101] is the use of a simple Cartesian mesh. The boundary conditions or fluxes in this technique are interpolated using the Cartesian grid points and this leads to the increase in the stencil width for the grid points located close to the boundary (however, the numerical techniques developed in [86,87,88, 100, 101] provide just the second order of accuracy for the global solution). An interesting high-order accurate approach is suggested in [35] for the Helmholtz equation on irregular domains that combines the method of difference potentials with compact high-order finite difference schemes on Cartesian meshes.

Summarizing, the development of robust numerical techniques for the solution of PDEs on irregular domains that provide an optimal and high order of accuracy is still a challenging problem.

A new numerical approach suggested in this paper is the extension of our previous numerical algorithms for wave and heat equations (see [73, 76, 107]) to the Helmholtz equation. In this paper we show that the approach based on the minimization of the local truncation error is very general and can be also applied to the Helmholtz equation on complex irregular domains. We call this approach as the optimal local truncation error method (OLTEM).

The idea of the proposed OLTEM is very simple. We start the development of a new numerical technique by assuming the stencil equations of a discrete system of equations used for the solution of a system of partial differential equations. A stencil equation is a linear combination of the numerical values of the function at a number of grid points where the coefficients of the stencil equations are assumed to be unknown. These unknown coefficients are determined by the minimization of the order of the local truncation error for each stencil equation. This procedure includes a Taylor series expansion of the unknown exact solution at the grid points and its substitution into the stencil equation. As a result, we obtain the local truncation error in the form of a Taylor series. At this point, no information about partial differential equations is used. Then, the corresponding partial differential equations are applied at the grid points in order to exclude some partial derivatives in the expression for the local truncation error. Finally, the unknown coefficients of the stencil equation are calculated from a small local system of algebraic equations obtained by equating to zero the lowest terms in the Taylor series expansion of the local truncation error. The coefficients of the stencil equations are similarly calculated for the regular (uniform) stencils located far from the boundary and for the cut (nonuniform) stencils located close to the boundary. Then, a fully discrete global system can be easily solved. The main advantages of the new approach are a high optimal accuracy and the simplicity of the formation of a discrete system for irregular domains. As a mesh, the grid points of a uniform rectangular (square) Cartesian mesh as well as the points of the intersection of the boundary of a complex irregular domain with the horizontal, vertical and diagonal grid lines of the uniform Cartesian mesh are used; i.e., in contrast to the finite element meshes, a trivial mesh is used with the new approach. Changing the width of the stencil equations, different linear and high-order numerical techniques can be developed.

In this paper we show the application of the new numerical approach to the Helmholtz equation as well as to its simple modification called the screened Poisson equation on an irregular domain \(\Omega \):

$$\begin{aligned} \nabla ^2 u +a k^2 u = f \,, \end{aligned}$$
(1)

where \(a=1\) for the Helmholtz equation, \(a=-1\) for the screened Poisson equation, k is the wave number for the Helmholtz equation, f(xy) is the loading term, u(xy) is the field variable. The Neumann boundary conditions \({\varvec{n}} \cdot \bigtriangledown u = g_1\) on \(\Gamma ^t \) and the Dirichlet boundary conditions \(u=g_2\) on \(\Gamma ^u\) are applied where \(g_i\) (\(i=1,2\)) are the given functions, \({\varvec{n}}\) is the outward unit normal on \(\Gamma ^t\), and \(\Gamma ^t\) and \(\Gamma ^u\) denote the boundaries with the Neumann and Dirichlet boundary conditions, respectively.

According to the new approach we assume that after the space discretization with a rectangular Cartesian mesh, the stencil equation for Eq. (1) can be written as an algebraic equation:

$$\begin{aligned} \sum \limits _{i=1}^{L} ( a k^2 h^2 m_i u^{num}_{i} + {k_i} u^{num}_{i} ) \, = \, {\bar{f}} \,, \end{aligned}$$
(2)

where \(u^{num}_i\) is the numerical solution for function u at the i-th grid point, \(m_i\) and \(k_i\) are the unknown stencil coefficients to be determined, L is the number of the grid points included into a stencil, \({\bar{f}} \) is the discretized loading term (see the next Sections), h is the mesh size along the x- axis. Many numerical techniques for the Helmholtz equation such as the finite difference method, the finite element method, the finite volume method, the isogeometric elements, the spectral elements, different meshless methods and others can be finally reduced to Eq. (2) with some specific coefficients \(m_i\) and \(k_i\). In order to demonstrate the new technique, below we will assume 9-point stencils in the 2-D case that correspond to the width of the stencils for the linear quadrilateral finite elements on Cartesian meshes. However, the stencils with any width can be used with the suggested approach.

Let us introduce the local truncation error used with the new approach. The replacement of the numerical values of the function \(u^{num}_{i}\) at the grid points in Eq. (2) by the exact solution \(u_{i}\) to Eq. (1) leads to the residual of this equation called the local truncation error e of the discrete equation, Eq. (2):

$$\begin{aligned} e \, = \, \sum \limits _{i=1}^{L} ( a k^2 h^2 {m_i} u_{i}+ {k_i} u_{i} ) - \bar{f} \,. \end{aligned}$$
(3)

Calculating the difference between Eqs. (3) and (2) we can get

$$\begin{aligned} e \,= & {} \, \sum \limits _{i=1}^{L} \{ a k^2 h^2 {m_i} [u_{i} - u^{num}_{i}] + {k_i} [u_{i} - u^{num}_{i}] \} \, \nonumber \\= & {} \, \sum \limits _{i=1}^{L} ( a k^2 h^2 {m_i} \bar{e}_i + {k_i} \bar{e}_i ) \,, \end{aligned}$$
(4)

where \(\bar{e}_i = u_{i} - u^{num}_{i}\) are the errors of function u at the grid points i. As can be seen from Eq. (4), the local truncation error e is a linear combination of the errors of the function u at the grid points i which are included into the stencil equation.

In Sect. 2.1 we consider the development of the new numerical approach for the 2-D Helmholtz equation with zero loading term. The imposition of the Dirichlet and Neumann boundary conditions are described in Sect. 2.2. The extension of the new numerical approach for the 2-D Helmholtz equation with nonzero loading term is presented in Sect. 2.3. Section 3 considers numerical examples and the comparison of the new approach with the conventional finite elements. For the derivation of many analytical expressions presented below we use the computational program “Mathematica”.

2 A new numerical approach for the 2-D Helmholtz equation

2.1 Zero load \(f=0\) in Eq. (1)

Fig. 1
figure 1

The spatial locations of the degrees of freedom \(u_{p}\) (\(p = 1,2,\ldots ,9\)) that contribute to the 9-point uniform stencil for the internal degree of freedom \(u_{5}\) located far from the boundary

Fig. 2
figure 2

The spatial locations of the degrees of freedom \(u_{p}\) (\(p = 1,2,\ldots ,9\)) that contribute to the 9-point nonuniform stencil for the internal degree of freedom \(u_{5}\) located close to the boundary with the Dirichlet boundary conditions

Here, we present 9-point uniform stencils that will be used for the internal grid points located far from the boundary and 9-point non-uniform stencils that will be used for the grid points located close to the boundary with the Dirichlet boundary conditions (the case of the Neumann boundary conditions will be considered separately in Sect. 2.2.2). Let us consider a 2-D bounded domain and a rectangular Cartesian mesh with a mesh size h where h is the size of the mesh along the x-axis and \(b_y h\) is the size of the mesh along the \(y-\)axis (\(b_y\) is the aspect ratio of the mesh); see Figs. 1 and  2. The 9-point stencil considered here is similar to that for the 2-D linear quadrilateral finite elements. The spatial locations of the 8 degrees of freedom that are close to the internal degree of freedom \(u_{5}\) and contribute to the 9-point stencil for this degree of freedom are shown in Fig. 1 for the case when the boundary and the Cartesian mesh are matched or when the degree of freedom \(u_{5}\) is located far from the boundary. In the case of non-matching grids when the grid points do not coincide with the boundary, the neighboring grid points for the internal grid point \(u_5\) that lie outside the physical domain are moved to the boundary of the physical domain as shown in Fig. 2. In order to find the boundary points that are included into the stencil for the degree of freedom \(u_{5}\) (see Fig. 2) we join the central point \(u_{5}\) with the 8 closest grid points; i.e., we have eight straight lines along the x- and y-axes and along the diagonal directions (the dashed lines) of the grid; see Fig. 2. If any of these lines intersects the boundary of the domain then the corresponding grid point (designated as \(\circ \)) should be moved to the boundary (the new location is designated as \(\bullet \)). This means that for all internal points located within the domain we use a 9-point uniform (see Fig. 1) or non-uniform (see Fig. 2) stencil. For convenience, the local numeration of the grid points from 1 to 9 is used in Fig. 2 as well as in the derivations below for the 9-point uniform and non-uniform stencils. To describe the coordinates of the boundary points shown in Fig. 2 we introduce 9 coefficients \( 0 \le d_p \le 1\) (\(p=1,2,\ldots ,9\)) with \(d_5=0\) as follows (see also Fig. 2):

$$\begin{aligned} x_p \,= & {} \, x_{5} \!+\! (i\!-\!2) d_p h \,, \qquad y_p \, = \, y_{5} + (j-2) d_p b_y h \,, \qquad \nonumber \\ p= & {} 3(j-1)+i \,, \qquad i,j=1,2,3 \,. \end{aligned}$$
(5)

Eq. (5) can be also used for the coordinates of the grid points inside the domain with the corresponding coefficients \(d_p\) equal to unity (\(d_p = 1\)). Eq. (2) for the 9-point uniform (see Fig. 1) or nonuniform (see Fig. 2) stencil can be explicitly rewritten as follows:

$$\begin{aligned} a k^2 h^2 \, \sum \limits _{p=1}^{9} m_p u^{num}_p + \sum \limits _{p=1}^{9} k_p u^{num}_p \, = \, \bar{f}_{5} \,, \qquad \end{aligned}$$
(6)

where \(\bar{f}_{5} = 0\) in the case of zero load \(f=0\) in Eq. (1), the unknown coefficients \(m_p\) and \(k_p\) (\(p=1,2,\ldots ,9\)) are to be determined from the minimization of the local truncation error.

Remark 1

Only 17 out of the 18 coefficients \(m_p\), \(k_p\) (\(p=1,2,\ldots ,9\)) in Eq. (6) can be considered as unknown coefficients. This can be explained as follows. In the case of zero load \(f=0\) and \(\bar{f}_{5} = 0\), Eq. (6) can be rescaled by the division of the left and right sides of Eq. (6) by any multiplier \(a_1\). For example, let us select \(a_1=k_{5}\). In this case the rescaled coefficients \({{\bar{m}}}_p\), \({{\bar{k}}}_p\) (\(p=1,2,\ldots ,9\)) of the stencil equation are: \({{\bar{m}}}_p = m_p/k_{5}\) (\(p=1,2,\ldots ,9\)), \({{\bar{k}}}_{5}=1\), \({{\bar{k}}}_p = k_p/k_{5}\) (\(p=1,2,\ldots ,4,6,\ldots ,9\)); i.e., there is only 17 unknown rescaled coefficients. The case of nonzero load \(\bar{f}_{5} \ne 0\) can be similarly treated because the term \(\bar{f}_{5}\) is a linear function of the coefficients \(m_p\) and \(k_p\) (see Eq. (26) below).

For the calculation of the local truncation error, let us expand the exact solution \(u_p\) (\(p = 1,2,\ldots ,4,6,7,\ldots ,9\)) at the grid points into a Taylor series at small \(h \ll 1\) as follows:

$$\begin{aligned} u_{p}= & {} u_{5} + \frac{\partial u_{5}}{\partial x} [(i-2) h d_{p}] + \frac{\partial u_{5}}{\partial y} [( j-2) h d_{p}] \nonumber \\&+\, \frac{\partial ^2 u_{5}}{\partial x^2} \frac{[(i-2) h d_{p}]^2}{2!} \nonumber \\&+\, \frac{\partial ^2 u_{5}}{\partial x \partial y} \frac{[(i-2) h d_{p}][( j-2) h d_{p}]}{2!} + \frac{\partial ^2 u_{5}}{\partial y^2} \frac{(\pm jh)^2}{2!} \qquad \nonumber \\&+\, \frac{\partial ^3 u_{5}}{\partial x^3} \frac{[(i-2) h d_{p}]^3}{3!} + \frac{\partial ^3 u_{5}}{\partial y \partial x^2} \frac{[(i-2) h d_{p}]^2 [( j-2) h d_{p}]}{3!} \nonumber \\&+\, \frac{\partial ^3 u_{5}}{\partial y^2 \partial x} \frac{[(i-2) h d_{p}] [( j-2) h d_{p}]^2}{3!} \nonumber \\&+\, \frac{\partial ^3 u_{5}}{\partial y^3} \frac{[( j-2) h d_{p}]^3}{3!} + \ldots \qquad \end{aligned}$$
(7)

where \(p=3(j-1)+i\) and \(i,j= 1,2,3\). The exact solution \(u_{5}\) to Eq. (1) meets the following equations:

$$\begin{aligned}&\frac{\partial ^2 u_{5}}{\partial x^2} = - \frac{\partial ^2 u_{5}}{\partial y^2} - a k^2 u_{5} \,, \end{aligned}$$
(8)
$$\begin{aligned}&\frac{ \partial ^{(i+j+1)} u_{5}}{\partial y^{i} \partial x^{(1+j)} } = - \frac{\partial ^{(i+j+1)} u_{5}}{\partial y^{(i+2)} \partial x^{(j-1)}} - a k^2 \frac{\partial ^{(i+j-1)} u_{5}}{\partial y^i \partial x^{(j-1)}} \,, \end{aligned}$$
(9)

with \(i=0,1, 2, 3, 4,\ldots \) and \(j=1, 2, 3, 4,\ldots \). Eq. (9) is obtained by the differentiation of Eq. (8) with respect to x and y. Inserting the exact solution given by Eqs. (7), (8), (9) into the stencil equation, Eq. (6), instead of the numerical solution, we will get the following local truncation error in space e:

$$\begin{aligned} e= & {} b_1 u_{5} + h \left( b_2 \frac{\partial u_{5} }{\partial x} + b_3 \frac{\partial u_{5} }{\partial y}\right) \nonumber \\&+ h^2 \left( b_4 k^2 u_{5} + b_5 \frac{\partial ^{2} u_{5} }{\partial x \partial y} +b_6 \frac{\partial ^{2} u_{5} }{\partial y^{2}}\right) \nonumber \\&+\, h^3 \left( b_7 k^2 \frac{\partial u_{5} }{\partial x} + b_8 k^2 \frac{\partial u_{5} }{\partial y} + b_{9} \frac{\partial ^{3} u_{5} }{\partial x \partial y^{2}} + b_{10} \frac{\partial ^{3} u_{5} }{\partial y^{3}}\right) \nonumber \\&+\, h^4 \left( b_{11} k^4 u_{5} + b_{12} k^2 \frac{\partial ^{2} u_{5} }{\partial x \partial y} +b_{13} k^2 \frac{\partial ^{2} u_{5} }{\partial y^{2}} \nonumber \right. \\&\left. + b_{14} \frac{\partial ^{4} u_{5} }{\partial x \partial y^{3}} + b_{15}\frac{\partial ^{4} u_{5} }{\partial y^{4}}\right) \nonumber \\&+\, h^5 \left( b_{16} k^4 \frac{\partial u_{5} }{\partial x} + b_{17} k^4 \frac{\partial u_{5} }{\partial y} + b_{18} k^2 \frac{\partial ^{3} u_{5} }{\partial x \partial y^{2}} \nonumber \right. \\&\left. + b_{19} k^2 \frac{\partial ^{3} u_{5} }{\partial y^{3}} + b_{20} \frac{\partial ^{5} u_{5} }{\partial x \partial y^{4}} + b_{21} \frac{\partial ^{5} u_{5} }{\partial y^{5}}\right) \nonumber \\&+\, h^6 \left( b_{22} k^6 u_{5} + b_{23} k^4 \frac{\partial ^{2} u_{5} }{\partial x \partial y} +b_{24} k^4 \frac{\partial ^{2} u_{5} }{\partial y^{2}} + b_{25} k^2 \frac{\partial ^{4} u_{5} }{\partial x \partial y^{3}} \nonumber \right. \\&\left. + b_{26} k^2 \frac{\partial ^{4} u_{5} }{\partial y^{4}} + b_{27} \frac{\partial ^{6} u_{5} }{\partial x \partial y^{5}} + b_{28} \frac{\partial ^{6} u_{5} }{\partial y^{6}}\right) + O({h}^{7}) \end{aligned}$$
(10)

with the coefficients \(b_p\) (\(p=1,2,\ldots ,28\)) given in “Appendix A”. Here we should mention that the expression for the local truncation error, Eq. (10), only includes the first-order derivatives with respect to x (the higher order derivatives with respect to x are excluded with the help of Eqs. 89).

In order to obtain the optimal order of accuracy of the local truncation error in Eq. (10) at small \(h \ll 1\), we will equate to zero the coefficients \(b_p\) in Eq. (10) for the smallest orders of h. First, let us consider the case of uniform stencils with \(d_i=1\) (\(i=1,2,\ldots ,9\)); see Fig. 1. In this case, the analytical study of coefficients \(b_p\) with the help of Mathematica shows that we can equate to zero the first 21 coefficients \(b_p\) (\(p=1,2,\ldots ,21\)) in Eq. (10). However, some of these coefficients are linearly dependent. Therefore, we will zero the following \(b_p\) coefficients:

$$\begin{aligned} b_p =0 \,, \qquad p=1,2,\ldots ,13,15,17,18,24 \,, \end{aligned}$$
(11)

as well as we use the condition \(k_5=1\) (see the Remark 1 after Eq. (6)). The solution of the algebraic equations, Eq. (11), yields the following coefficients \(m_i\) and \(k_i\) (\(i=1,2,\ldots ,9\)) of the stencil equation, Eq. (6):

$$\begin{aligned} {k_1}= & {} -\frac{1}{20} \,, \; {k_2} = \frac{{b_y}^2-5}{10 ({b_y}^2+1)} \,, \; {k_3} = -\frac{1}{20} \,, \; \nonumber \\ {k_4}= & {} \frac{1-5 {b_y}^2}{10 {b_y}^2+10} \,, \; {k_5} = 1 \,, \nonumber \\ {k_6}= & {} \frac{1-5 {b_y}^2}{10 {b_y}^2+10} \,, \; {k_7} = -\frac{1}{20} \,, \; \nonumber \\ {k_8}= & {} \frac{{b_y}^2-5}{10 ({b_y}^2+1)} \,, \; {k_9} = -\frac{1}{20} \,, \nonumber \\ {m_1}= & {} -\frac{5 {b_y}^2+9}{1200 ({b_y}^2+1)} \,, \; {m_2} = \frac{9-25 {b_y}^2}{600 ({b_y}^2+1)} \,, \; \nonumber \\ {m_3}= & {} -\frac{5 {b_y}^2+9}{1200 ({b_y}^2+1)} \,,\nonumber \\ \; {m_4}= & {} \frac{9-25 {b_y}^2}{600 ({b_y}^2+1)} \,, \; {m_5} = -\frac{125 {b_y}^2+9}{300 ({b_y}^2+1)} \,, \nonumber \\ {m_6}= & {} \frac{9-25 {b_y}^2}{600 ({b_y}^2+1)} \,, \; {m_7} = -\frac{5 {b_y}^2+9}{1200 ({b_y}^2+1)} \,, \; \nonumber \\ {m_8}= & {} \frac{9-25 {b_y}^2}{600 ({b_y}^2+1)} \,, \; {m_9} = -\frac{5 {b_y}^2+9}{1200 ({b_y}^2+1)} \,. \; \end{aligned}$$
(12)

Inserting these coefficients \(m_i\) and \(k_i\) (\(i= 1,2,3,\ldots ,9\)) from Eq. (12) into Eq. (10), we will get the local truncation error in space e for uniform stencils:

$$\begin{aligned} e = \frac{{b_y}^2 {h}^6 \left[ ({b_y}^4-1) \frac{\partial ^{6} u_{5} }{\partial y^{6}} -k^6 u_{5}\right] }{400 ({b_y}^2+1)}+ O(h^{8}) \, , \end{aligned}$$
(13)

i.e., the coefficients \(m_i\) and \(k_i\) (\(i=1,2,\ldots ,9\)) given by Eq. (12) zero all coefficients \(b_p\) (\(p=1,2,\ldots ,21\)) in Eq. (10) up to the fifth order.

Next, let us consider non-uniform stencils; see Fig. 2. If we equate to zero the first 15 coefficients \(b_p = 0\) (\(p=1,2,\ldots ,15\)) in Eq. (10), then, at least, we could obtain the fifth order of the local truncation error. However, for a rectangular mesh with \(b_y \ne 1\), the corresponding system of 15 algebraic equations for some particular cases (e.g., when one point of the 9-point regular stencil lies outside the physical domain and we have a non-uniform stencil with \(d_1 \ne 1\), see Fig. 2) can be analytically solved with the help of Mathematica. These solutions show that all coefficients \(k_i\) in this stencil equation are zeros; i.e., these solutions are inappropriate. Therefore, the maximum possible order of the local truncation error for a non-uniform stencil, Eq. (6), on a rectangular mesh corresponds to the fourth order (this can be shown by equating to zero the first 10 coefficients \(b_p = 0\) (\(p=1,2,\ldots ,10\)) in Eq. 10). Fortunately, for square meshes with \(b_y = 1\), the solution of the system of 15 algebraic equations \(b_p = 0\) (\(p=1,2,\ldots ,15\)) can be analytically solved with the help of Mathematica and yields non-zero coefficients \(m_i\) and \(k_i\) (\(i= 1,2,3,\ldots ,9\)). Therefore, for square meshes the new approach with the non-uniform stencils yields, at least, the fifth order of the local truncation error.

In order to zero the coefficients \(b_p\) (\(p =1,2,\ldots , 10\)) for rectangular meshes and minimize the values of the coefficients \(b_p\) (\(p =11,12,\ldots , 28\)) for the fourth, fifth and sixth orders of the local truncation error for all non-uniform stencils, we use the following procedure. First, let us zero the following coefficients \(b_p\):

$$\begin{aligned} b_p =0 \,, \qquad p=1,2,\ldots ,10 \,, \end{aligned}$$
(14)

Then, for the coefficients \(b_p\) related to the fourth, fifth and sixth orders of the local truncation error we use the least square method with the following residual R:

$$\begin{aligned} R = \sum \limits _{p=11}^{15} b_p^2 + h_1 \sum \limits _{p=16}^{21} b_p^2 + h_2 \sum \limits _{p=22}^{28} b_p^2 \,, \end{aligned}$$
(15)

where \(h_1\) and \(h_2\) are the weighting factors to be selected (e.g., the numerical experiments show that \(h_1 = h_2 = h\) yields accurate results). The inclusion of the sixth order terms is explained by the fact that for uniform square meshes, the fifth order terms do not provide a sufficient number of equations for the calculation of the coefficients \(m_i\) and \(k_i\) (\(i=1,2,\ldots ,9\)). In order to minimize the residual R with the constraints given by Eq. (14), we can form a new residual \(\bar{R}\) with the Lagrange multipliers \(\lambda _p\):

$$\begin{aligned} \bar{R} = \sum \limits _{p=11}^{15} b_p^2 + h_1 \sum \limits _{p=16}^{21} b_p^2 + h_2 \sum \limits _{p=22}^{28} b_p^2 + \sum \limits _{p=1}^{10} \lambda _p b_p \,. \qquad \end{aligned}$$
(16)

The residual \(\bar{R}\) is a quadratic function of coefficients \(m_i\) and \(k_i\) (\(i=1,2,\ldots ,9\)) and a linear function of the Lagrange multipliers \(\lambda _p\); i.e., \(\bar{R}= \bar{R}(m_i, k_i, \lambda _p)\). In order minimize the residual \(\bar{R}(m_i, k_i, \lambda _p)\), the following equations based on the least square method for the residual \(\bar{R}\) can be written down:

$$\begin{aligned}&\frac{\partial \bar{R}}{\partial m_i} =0 \,, \qquad \frac{\partial \bar{R}}{\partial k_i} =0 \,, \qquad i=1,2,\ldots ,9 \,, \end{aligned}$$
(17)
$$\begin{aligned}&\frac{\partial \bar{R}}{\partial \lambda _p} =0 \,, \qquad p=1,2,\ldots ,10 \,, \qquad \end{aligned}$$
(18)

where equation \(\frac{\partial \bar{R}}{\partial k_{5}} =0\) should be replaced by \(k_{5} =1\) because for the homogeneous stencil equation, Eq. (6), with \(\bar{f}_{5} = 0\) one of the coefficients \(m_i\) and \(k_i\) (\(i=1,2,\ldots ,9\)) can be arbitrary selected; e.g., \(k_{5} =1\); see Remark 1 after Eq. (6). Equations (17) and (18) form a system of 28 linear algebraic equations with respect to 18 unknown stencil coefficients \(m_i\) and \(k_i\) (\(i=1,2,\ldots ,9\)) and 10 Lagrange multipliers \(\lambda _p\) (\(p=1,2,\ldots ,10\)). Solving these linear algebraic equations numerically, we can find the coefficients \(m_i\), \(k_i\) (\(i=1,2,\ldots ,9\)) for the 9-point non-uniform stencils.

Remark 2

To estimate the computation costs of the solution of 28 linear algebraic equations formed by Eqs. (17) and (18) we solved \(10^6\) such systems with a general MATLAB solver on a simple student laptop computer (Processor: Intel (R) Core(TM) i5-4210U CPU @ 1.70GHz 2.40GHz). The computation ’wall’ time was \(T=1216 s\) for \(10^6\) systems or the average time for one system was 0.001216s. Because the coefficients \(m_i\) and \(k_i\) (\(i=1,2,\ldots ,9\)) are independently calculated for different non-uniform stencils, the computation time of their calculation for different grid points can be significantly reduced on modern parallel computers. This means that for large global systems of equations, the computation time for the calculation of the coefficients \(m_i\) and \(k_i\) (\(i=1,2,\ldots ,9\)) is very small compared to that for the solution of the global system of equations.

Remark 3

The computation time for pre-processing and assembling the global matrix depends on the implementation of a code. Here we present the computation time estimation for the linear finite elements using our MATLAB code for a relatively large number of degrees of freedom (dof) and a square mesh (the computation time for the calculation of the elemental matrices and assembling the global matrix is independent of the shape of the finite elements). For example, a square mesh with \(N=10^6\) dof includes approximately the same number \(10^6\) of linear finite elements. For this mesh, the calculation of the elemental matrices and assembling the global matrix require approximately 235s of the computation time. For the new approach, the coefficients of the global matrix for uniform internal stencils are calculated analytically (see Eq. 12). For the square mesh with \(N=10^6\) dof, the number of boundary stencils is approximately \(4 \sqrt{N} = 4000\). Therefore, the computation time for the calculation of the coefficients of the global matrix for the new approach is related to that for the boundary stencils and is approximately 5s (see Remark 2); i.e., it is significantly smaller than that for the linear finite elements with the same number of dof.

The new approach provides the fourth (with rectangular Cartesian meshes) or the fifth (with square Cartesian meshes) order of the local truncation error for the nonuniform stencils and the sixth order of the local truncation error for the uniform stencils (see Eq. 13). For the conventional linear finite elements on uniform square meshes, the values of the coefficients \(m_i\) and \(k_i\) (\(i=1,2,\ldots ,9\)) (see [73]) provide the fourth order of the local truncation error:

$$\begin{aligned} e_{conv}^{lin} = \frac{\bar{c} h^4}{12} \left( \frac{\partial ^4 u_{5}}{\partial x^{4}} + \frac{\partial ^4 u_{5}}{\partial y^{4}}\right) + O(h^{6}) \,, \end{aligned}$$
(19)

i.e., the new approach improves the local truncation error in space by two orders compared to that for the conventional linear elements on uniform square meshes.

2.2 Boundary conditions

2.2.1 Dirichlet boundary conditions

The application of the Dirichlet boundary conditions in the new approach is trivial and similar to that for the finite elements. We simply equate the boundary degrees of freedom of the uniform and non-uniform stencils (see Figs. 1,  2) to the values of a given function \(g_2(x,y)\) at the corresponding boundary points; i.e., the Dirichlet boundary conditions are exactly imposed. Here, \(g_2(x,y)\) describes the Dirichlet boundary conditions. The final global discrete system of equations includes the 9-point uniform and nonuniform stencil equations (see Figs. 1,  2) for all internal grid points that lie inside the domain as well as the Dirichlet boundary conditions at the boundary points. These 9-point uniform and nonuniform stencils on square Cartesian meshes provide the fourth order of accuracy of numerical solutions; see the numerical examples in Sect. 3.

Remark 4

As shown in [101], the boundary stencils may have the local truncation error that is one order lower compared to that for internal stencils (this does not worsen the order of accuracy of the global solution).

Remark 5

The proposed technique yields accurate results for the non-uniform stencils even with very small coefficients \(d_i \ll 1\). However, the new technique allows also to exclude very small coefficients \(d_i \ll 1\) from calculations. For example, if \(d_i \ll tol\) for some internal point (see Fig. 2) where tol is a small tolerance (e.g., \(tol = 10^{-3}\)), then the non-uniform stencil for this internal point can be removed from the global system of equations and this point can be moved to the boundary and treated as the boundary point for other stencils. In this case, the corresponding coefficients \(d_i\) for this point in other stencils can be slightly greater than one. According to the derivations in the previous section, all equations will be valid also for \(d_i > 1\). The numerical experiments with a small tolerance \(tol = 10^{-3}\) show that if the point with very small coefficients \(d_i \ll 1\) is moved to the boundary then the coefficients \(d_i\) for this point in other stencils can be taken as \(d_i = 1\) without introducing any significant errors.

2.2.2 Neumann boundary conditions

The imposition of the Neumann boundary conditions for the new approach is different from that for the Dirichlet boundary conditions. Our goal is to use the same 9-point uniform and non-uniform stencils equations as those in Figs. 1 and 2 because this significantly simplifies the implementation of the new approach with Cartesian meshes. We suggest the following 9-point stencil equations for the Neumann boundary conditions:

$$\begin{aligned}&a k^2 h^2 \, \sum \limits _{p=1}^{9} m_p u^{num}_p + \sum \limits _{p=1}^{9} k_p u^{num}_p \, \nonumber \\&\quad = \, \left[ a k^2 h^3 \, \sum \limits _{p=1}^{9} \bar{m}_p g_1(x_p,y_p) + h \, \sum \limits _{p=1}^{9} \bar{k}_p g_1(x_p,y_p)\right] \nonumber \\&\qquad + \bar{f}_{5} \,, \qquad \end{aligned}$$
(20)

where \(\bar{f}_{5} = 0\) in the case of zero load \(f=0\) in Eq. (1), the expression in the square brackets in the right-hand side of Eq. (20) is known and represents the Neumann boundary conditions at the stencil points with the coordinates \(x_p, y_p\) that are located on the boundary with the Neumann boundary conditions (see Fig. 2), the unknown stencil coefficients \(m_p\), \(\bar{m}_p\), \(k_p\), and \(\bar{k}_p\) (\(p=1,2,\ldots ,9\)) are to be determined from the minimization of the local truncation error, \(m_p = 0\) and \(k_p =0\) if a point with the coordinates \(x_p, y_p\) is located on the boundary with the Neumann boundary conditions; otherwise, \(\bar{m}_p = 0\) and \(\bar{k}_p =0\) (this means that Eq. (20) includes only 18 non-zero coefficients \(m_p\), \(\bar{m}_p\), \(k_p\), and \(\bar{k}_p\)), the central grid point with the coordinates \(x_{5}\) and \(y_{5}\) is always the internal point (therefore, \(\bar{m}_{5} = \bar{k}_{5} =0\)). Only 17 out of the 18 nonzero coefficients \(m_p\), \(\bar{m}_p\), \(k_p\), and \(\bar{k}_p\) (\(p=1,2,\ldots ,9\)) in Eq. (20) can be considered as unknown coefficients. This can be explained similar to Remark 1 after Eq. (6).

The local truncation error e of the stencil equation, Eq. (20), can be written down by the replacement of the numerical solution in Eq. (20) by the exact solution as follows:

$$\begin{aligned} e= & {} a k^2 h^2 \, \sum \limits _{p=1}^{9} m_p u_p \nonumber \\&+\, \sum \limits _{p=1}^{9} k_p u_p \, - \, a k^2 h^3 \,\nonumber \\&\sum \limits _{p=1}^{9} \bar{m}_p \left( n_{1p} \frac{\partial {u}_p}{\partial x } +n_{2p} \frac{\partial {u}_p}{\partial y }\right) - h \, \nonumber \\&\sum \limits _{p=1}^{9} \bar{k}_p \left( n_{1p} \frac{\partial {u}_p}{\partial x } +n_{2p} \frac{\partial {u}_p}{\partial y } \right) - \bar{f}_{5} \,, \qquad \end{aligned}$$
(21)

where \(n_{1p}\) and \(n_{2p}\) (\(p=1,2,\ldots ,9\)) are the x- and y-components of the outward unit normal vector \({{\varvec{n}}}_p\) at the boundary point p (see Fig. 2), function u(xy) in Eq. (21) corresponds to the exact solution, the Neumann boundary conditions in the right-hand side of Eq. (20) are expressed in terms of the function u(xy) and are moved to the left-hand side of Eq. (21).

The rest of derivations will be similar to those in Sect. 2.1. Inserting Eqs. (7), (8), (9) into (21), we will get the local truncation error in space e that can be also expressed by Eq. (10) with the coefficients \(b_p\) (\(p=1,2,\ldots ,28\)) given in “Appendix B”. In contrast to Sect. 2.1, now the coefficients \(b_p\) (\(p=1,2,\ldots ,28\)) depend not only on \(m_i\), \(k_i\) and \(d_i\) but also on \(\bar{m}_i\), \(\bar{k}_i\), \(n_{1i}\) and \(n_{2i}\) (\(i=1,2,\ldots ,9\)); see “Appendix B”. For the calculations of the coefficients \(m_i\), \(\bar{m}_i\), \(k_i\), \(\bar{k}_i\) (\(i=1,2,\ldots ,9\)) for the uniform and non-uniform stencils, we will use the least square method with Eqs. (14)–(18). However, Eq. (17) should be modified as follows:

$$\begin{aligned} \frac{\partial \bar{R}}{\partial m_i}= & {} 0 \,, \qquad \frac{\partial \bar{R}}{\partial \bar{m}_i} =0 \,, \qquad \nonumber \\ \frac{\partial \bar{R}}{\partial k_i}= & {} 0 \,, \qquad \frac{\partial \bar{R}}{\partial \bar{k}_i} =0 \,, \qquad i=1,2,\ldots ,9 \,, \end{aligned}$$
(22)

where the partial derivatives of \(\bar{R}\) in Eq. (22) are considered with respect to only non-zero coefficients \(m_i\), \(\bar{m}_i\), \(k_i\), \(\bar{k}_i\) with \(i=1,2,\ldots ,9\) (see also explanations for zero and non-zero coefficients after Eq. 20); i.e., Eq. (22) as well as Eq. (17) provides 18 algebraic equations (similar to Eq. (17), equation \(\frac{\partial \bar{R}}{\partial k_{5}} =0\) should be replaced by \(k_{5} =1\)). Finally, solving 28 linear algebraic equations (Eqs. 22 and 18) numerically, we can find the coefficients \(m_i\), \(\bar{m}_i\), \(k_i\), \(\bar{k}_i\) (\(i=1,2,\ldots ,9\)) for the 9-point uniform and non-uniform stencils. Numerical experiments show that for the Neumann boundary conditions, the coefficients \(h_1 = h_2 =1\) in Eq. (15) provide accurate results.

Remark 6

In contrast to Sect. 2.1, the non-uniform stencils with the Neumann boundary conditions provide the fourth-order of the local truncation error on square meshes (the same as on rectangular meshes). This corresponds to the third order of accuracy of the numerical results for the new approach with the Neumann boundary conditions; see the numerical examples in Sect. 3.

2.3 Nonzero load \(f \ne 0\) in Eq. (1)

The inclusion of non-zero loading term f in the partial differential equation, Eq. (1), leads to the non-zero term \(\bar{f}_{5}\) in the stencil equations, Eqs. (6) and (20) (similar to Eq. 2). The expression for the term \(\bar{f}_{5}\) can be calculated from the procedure used for the derivation of the local truncation error in the case of zero loading function.

In case of non-zero loading function (\(f({\varvec{x}}) \ne 0\)), Eqs. (8) and (9) for the exact solution at \(x=x_5\) and \(y=y_5\) can be modified as follows:

$$\begin{aligned}&\frac{\partial ^2 u_{5}}{\partial x^2} = - \frac{\partial ^2 u_{5}}{\partial y^2} - a k^2 u_{5} + f(x_5, y_5) \,, \end{aligned}$$
(23)
$$\begin{aligned}&\frac{ \partial ^{(i+j+1)} u_{5}}{\partial y^{i} \partial x^{(1+j)} } = - \frac{\partial ^{(i+j+1)} u_{5}}{\partial y^{(i+2)} \partial x^{(j-1)}} \nonumber \\&\quad - a k^2 \frac{\partial ^{(i+j-1)} u_{5}}{\partial y^i \partial x^{(j-1)}} + \frac{\partial ^{(i+j-1)} f(x_5, y_5)}{\partial y^{i} \partial x^{(j-1)}} \, \end{aligned}$$
(24)

with \(i=0,1, 2, 3, 4,\ldots \) and \(j=1, 2, 3, 4,\ldots \). Then, inserting Eqs. (7), (23) and (24) with the exact solution to Eq. (1) into the stencil equation, Eq. (20), with non-zero \(\bar{f}_{5}\) we will get the following local truncation error in space \(e_f\):

$$\begin{aligned}&e_f = e - \left[ \bar{f}_{5} - \Bigg \{ \frac{h^2 f_{5}}{2} (k_{1} d_{1}^2-2 \bar{k}_1 n_{11} d_{1}+d_{3}^2 k_{3}+d_{4}^2 k_{4}\nonumber \right. \\&\quad +\,d_{6}^2 k_{6} +\,d_{7}^2 k_{7}+d_{9}^2 k_{9}+2 d_{3} \bar{k}_3 n_{13}-2 d_{4} \bar{k}_4 n_{14}\nonumber \\&\quad \left. +\,2 d_{6} \bar{k}_6 n_{16}-2 d_{7} \bar{k}_7 n_{17}+2 d_{9} \bar{k}_9 n_{19}) + h^3(\ldots ) + \cdots \!\Bigg \}\!\right] , \qquad \nonumber \\ \end{aligned}$$
(25)

where e is the local truncation error in space given by Eq. (10), \(\bar{f}_{5}\) designates function f(xy) calculated at \(x=x_5\) and \(y=y_5\). Equating to zero the expression in the square brackets in the right-hand side of Eq. (25), we will get the expression for \(\bar{f}_{5}\):

$$\begin{aligned} \bar{f}_{5}= & {} \frac{h^2 f_{5}}{2} (k_{1} d_{1}^2-2 \bar{k}_1 n_{11} d_{1}+d_{3}^2 k_{3}+d_{4}^2 k_{4}+d_{6}^2 k_{6} \nonumber \\&+\,d_{7}^2 k_{7}+d_{9}^2 k_{9}+2 d_{3} \bar{k}_3 n_{13}-2 d_{4} \bar{k}_4 n_{14}+2 d_{6} \bar{k}_6 n_{16}\nonumber \\&-\,2 d_{7} \bar{k}_7 n_{17}+2 d_{9} \bar{k}_9 n_{19}) + h^3(\cdots ) + \cdots \end{aligned}$$
(26)

as well as we will get the same local truncation errors \(e_f = e\) for zero and non-zero loading functions; see the attached file “RHS-Helm.pdf” for the detailed expression of \(\bar{f}_{5}\). This means that the coefficients \(m_i\) and \(k_i\) of the stencil equations are first calculated for zero load \(f = 0\) as described in Sects. 2.1 and 2.2. Then, the nonzero loading term \(\bar{f}_{5}\) given by Eq. (26) is used in the stencil equation, Eqs. (20) and (6).

Remark 7

Eq. (26) for the non-zero load can be also used for the stencil given by Eq. (6). In this case the coefficients \(\bar{m}_i\) and \(\bar{k}_i\) should be taken as \(\bar{m}_i = \bar{k}_i = 0\) (\(i=1,2,\ldots ,9\)).

3 Numerical examples

In this Section the computational efficiency of the new approach developed for the \(2-D\) Helmholtz equation will be demonstrated and compared with the conventional linear (T3 and Q4), quadratic (T6 and Q9) and cubic (T10 and Q16) quadrilateral (Q4, Q9 and Q16) and triangular (T3, T6 and T10) finite elements. The commercial finite element software ’COMSOL’ is used for the finite element simulations. Similar to the finite element terminology, a grid point of a Cartesian mesh will be called a node. In order to compare the accuracy of the new technique with FEM, the relative error \(e_{j}\) for the function u at the \(j^{th}\) node is defined as:

$$\begin{aligned} e_{j} = \frac{\mid u_j^{num} - u_j^{exact} \mid }{ u_{max}^{exact}} \,, \qquad j=1,2,\ldots ,N. \end{aligned}$$
(27)

The maximum relative error \(e^{max}\) for the function u is defined as:

$$\begin{aligned} e^{max} = \max \limits _{j} e_{j} \,, \qquad j=1,2,\ldots ,N. \end{aligned}$$
(28)

In Eqs. (27)–(28) the superscripts \('num'\) and \('exact'\) correspond to the numerical and exact solutions, N is the total number of nodes used in calculations, \(u_{max}^{exact}\) is the maximum absolute value of the exact solution for the function u over the entire domain. In order to compare the efficiency of the conventional finite elements and the new approach, two test problems are considered with the following exact solutions to the Helmholtz equation (Eq. (1) with \(a=1\)):

$$\begin{aligned} u(x, y)= sin(2 \pi x) cos(2 \pi y) \end{aligned}$$
(29)

with \(k^2=8 {\pi }^2\) and zero loading function \(f=0\); and

$$\begin{aligned} u(x, y)=sin[\pi (4 x+ y)] cos[\pi (2 x-3 y)] \end{aligned}$$
(30)

with \(k^2=1\) and non-zero loading function \(f (x, y) = cos[\pi (2 x-3 y)] sin[\pi (4 x+ y)]- 10 {\pi }^2 (2 sin[\pi (6 x-2 y)] +sin[2 \pi (x+ 2 y)])\). For the screened Poisson equation (Eq. (1) with \(a=-1\)), we consider another test problem with the following exact solution:

$$\begin{aligned} u(x, y)= e^{4 \pi (x-1)} cos(2 \pi y) \end{aligned}$$
(31)

with \(k^2=12 {\pi }^2\) and zero loading function \(f=0\).

Fig. 3
figure 3

A trapezoidal plate OPQR (\(\theta =130^{o}\)) with a circular hole of radius 0.25 centered at S(0.6, 0.35) and a quadrilateral hole ABCD (A(0.2, 0.95), B(0.8, 0.75), C(0.75, 1.05), D(0.35, 1.2)) (a) as well as the Cartesian mesh for the new approach (b). Examples of typical quadrilateral (c) and triangular (b) finite element meshes generated by the commercial software COMSOL for the discretization of the plate OPQR

Fig. 4
figure 4

The distribution of the exact solutions for the function u(xy) (a, c) and the relative error e(xy) (b, d) of the numerical solutions on the trapezoidal plate (see Fig. 3a). The numerical solutions of the \(2-D\) Helmholtz equation with zero (a, b) and non-zero (c, d) loading functions and the Dirichlet boundary conditions are obtained by the new approach on the square (\(b_y=1\)) Cartesian mesh of size \(h=1/32\)

Let us consider a trapezoidal plate OPQR with circular and quadrilateral holes; see Fig. 3a. Fig. 3 also shows the Cartesian mesh used for the new approach as well as examples of typical quadrilateral and triangular meshes generated by COMSOL for the conventional finite elements. As can be seen from Fig. 3b, for the new approach the two grid lines of the Cartesian mesh are matched with the edges OP and OR for simplicity. The 9-point uniform and non-uniform stencils are constructed according to the procedures presented in the previous section; see also Figs. 1 and 2. In Sect. 3.1, we solve the test problems for the trapezoidal plate with the Dirichlet boundary conditions imposed along the entire boundary. For the same test problems, the Neumann boundary conditions along a part of the boundary and the Dirichlet boundary conditions along the remaining part of the boundary are considered in Sect. 3.2. In Sect. 3.3, a test problem for the screened Poisson equation with the exact solution given by Eq. (31) is solved. All boundary conditions are calculated according to the exact solutions, Eqs. (29)–(31).

Fig. 5
figure 5

The maximum relative error \(e^{max}\) for the trapezoidal plate (see Fig. 3a) as a function of \(\sqrt{N}\) at mesh refinement in the logarithmic scale; N is the number of degrees of freedom. The numerical solutions of the \(2-D\) Helmholtz equation with zero (a), non-zero (b) loading functions and the Dirichlet boundary conditions are obtained by the new approach on square (\(b_y=1\)) Cartesian meshes (curve 1); by the conventional linear (curves 2 and 5) and high-order (curves 3,4,6,7) finite elements on triangular (curves 2–4) and quadrilateral (curves 5–7) meshes. Symbols \(\bigtriangledown \), \(+\), \(\bigcirc \), \(*\), \(\times \), \(\square \) and \(\diamond \) correspond to the results for the different N used in the calculations

Fig. 6
figure 6

The distribution of the relative error e(xy) of the numerical solutions for the trapezoidal plate shown in Fig. 3a; see Fig. 4a, c for the distribution of the exact solutions for the function u . The numerical solutions of the \(2-D\) Helmholtz equation with zero (a) and non-zero (b) loading functions and the combined Neumann and Dirichlet boundary conditions are obtained by the new approach on the square (\(b_y=1\)) Cartesian mesh of size \(h=1/32\)

3.1 The Dirichlet boundary conditions

Two test problems for the trapezoidal plate (see Fig. 3a) with the Dirichlet boundary conditions along the entire boundary are solved by the new approach and by the conventional finite elements. The exact solutions for these problems are given by Eqs. (29) and (30). Fig. 4 shows the distribution of the exact solutions for the function u as well as the distribution of the relative error e of the numerical solutions obtained by the new approach on the square (\(b_y=1\)) Cartesian mesh of size \(h=1/32\). It can be seen from Fig. 4b,d that the numerical results obtained by the new approach on this mesh are very accurate (the errors are very small).

In order to compare the accuracy of the numerical solutions obtained by the new approach and by the conventional finite elements, Fig. 5 shows the maximum relative error \(e^{max}\) as a function of the number N of degrees of freedom in the logarithmic scale. Because the mesh size \(h \approx 1/\sqrt{N}\) for the new approach, then the slope of the curve 1 at large N (small h) in Fig. 5 approximately corresponds to the order of convergence of the new approach (the same is valid for Figs.  7 and  9a below). As can be seen from Fig. 5, at the same N the numerical results obtained by the new approach are much more accurate than those obtained by the linear and high-order (quadratic and cubic) finite elements. This increase in accuracy is impressive considering the fact that the high-order finite elements have much wider stencils compared to those for the new approach (the width of the stencils for the new approach corresponds to that for the conventional linear quadrilateral finite elements). Therefore, for a given accuracy the new approach requires a significantly less computation time compared to that for the conventional finite elements.

3.2 The Neumann boundary conditions

Here, the same test problems for the trapezoidal plate (see Fig. 3a) as in Sect. 3.2 are solved with the combined Neumann and Dirichlet boundary conditions where the Neumann boundary conditions along the two holes and boundary QR as well as the Dirichlet boundary conditions along boundaries OP, PQ and OR are imposed according to the exact solutions given by Eqs. (29) and (30). Fig. 6a,b shows the distribution of the relative error e of the numerical solutions obtained by the new approach on the square (\(b_y=1\)) Cartesian mesh of size \(h=1/32\) (see Fig. 4a,c for the distribution of the exact solutions). It can be seen from Fig. 6a,b that the numerical results obtained by the new approach on this mesh are accurate for the Neumann boundary conditions as well (the errors are small).

Similar to Fig. 5, Fig. 7 shows the maximum relative error \(e^{max}\) as a function of the number N of degrees of freedom in the logarithmic scale. As can be seen from Fig. 7, at the same N the numerical results obtained by the new approach are more accurate than those obtained by the linear and high-order (quadratic and cubic) finite elements.

Fig. 7
figure 7

The maximum relative error \(e^{max}\) for the trapezoidal plate (see Fig. 3a) as a function of \(\sqrt{N}\) at mesh refinement in the logarithmic scale; N is the number of degrees of freedom. The numerical solutions of the \(2-D\) Helmholtz equation with zero (a), non-zero (b) loading functions and the combined Neumann and Dirichlet boundary conditions are obtained by the new approach on square (\(b_y=1\)) Cartesian meshes (curve 1); by the conventional linear (curves 2 and 5) and high-order (curves 3,4,6,7) finite elements on triangular (curves 2–4) and quadrilateral (curves 5–7) meshes. Symbols \(\bigtriangledown \), \(+\), \(\bigcirc \), \(*\), \(\times \), \(\square \) and \(\diamond \) correspond to the results for the different N used in the calculations

In order to study the convergence and stability of the numerical results obtained by the new approach in more detail, Fig. 8 presents the curves 1 in Figs. 5a and 7a at small changes of the mesh size h (curves 1 and 2 in Fig. 8 correspond to curves 1 in Figs. 5a,  7a, respectively). For this study, we solve the test problem on 1500 Cartesian meshes with the mesh sizes \(h_i = h_1+ \frac{(h_2-h_1)(i-1)}{1499}\) with \(h_1=1/8=0.125\), \(h_2=1/100=0.01\) and \(i=1,2,\ldots ,1500\). As can be seen form Fig. 8, the numerical results obtained by the new approach monotonically converge with the decrease in the grid size h for the Dirichlet boundary conditions; see curve 1 in Fig. 8. For the combined Neumann and Dirichlet boundary conditions, the new approach shows small oscillations in the convergence curve; see curve 2 in Fig. 8. At mesh refinement, these oscillations become smaller at small h. This oscillatory behavior can be explained by a) the complicated dependency of the leading terms of the local truncation error on the coefficients \(d_i\) and b) at small variations of the mesh size h, there is a discontinuous change in the location of the grid points with respect to the irregular boundary (e.g., some grid points that are the internal points for the previous mesh can move to the boundary or outside the boundary for the next mesh); this leads to the discontinuous change of some stencils equations for the meshes with the small difference in h. It is important to mention that small oscillations in the numerical convergence curves are typical for many numerical techniques on irregular domains at small variations of h. For example, the change in the angles of the finite elements at small variations of the element size h also leads to such oscillations in the convergence curves for the finite element techniques. We should also mention that the convergence curves similar to those in Fig. 8 were obtained for test problem with the non-zero loading function solved by the new approach.

Fig. 8
figure 8

The logarithm of the maximum relative error \(e^{max}\) as a function of the mesh size h for the trapezoidal plate (see Fig. 3a). The numerical solutions of the \(2-D\) Helmholtz equation with zero loading function and the Dirichlet boundary conditions (curve 1); and the combined Neumann and Dirichlet boundary condition (curve 2) are obtained by the new approach on square (\(b_y=1\)) Cartesian meshes. Symbol \(\bigcirc \) and \(\square \) correspond to the results for the different h used in the calculations

3.3 The screened Poisson equation

The test problem for the trapezoidal plate (see Fig. 3a) with the Dirichlet boundary conditions along the entire boundary and the exact solution given by Eq. (31) is solved here by the new approach and by the finite element method. Similar to Fig. 5, Fig. 9a shows the maximum relative error \(e^{max}\) as a function of the number N of degrees of freedom in the logarithmic scale. As can be seen from Fig. 9a, at the same N the numerical results obtained by the new approach are much more accurate than those obtained by the linear and high-order (quadratic and cubic) finite elements.

In order to study the convergence and stability of the numerical solutions obtained by the new approach for the screened Poisson equation, we solve the same test problem on 1500 Cartesian meshes with a small variation of the grid size h (see the previous Sect. 3.2 for the selection of h). Fig. 9b presents the convergence curve for 1500 Cartesian meshes. As can be seen, the new approach shows small oscillations in the convergence curve in Fig. 9b. At mesh refinement, these oscillations become smaller at small h. The explanations of these oscillations are discussed in the previous Sect. 3.2. We should mention that similar numerical results have been obtained by the new approach and by the finite elements for the screened Poisson equation with the Neumann boundary conditions as well.

Fig. 9
figure 9

The logarithm of the maximum relative error \(e^{max}\) for the trapezoidal plate (see Fig. 3a) as a function of \(Log_{10} \sqrt{N}\) (a) and as a function of mesh size h (b) at mesh refinement; N is the number of degrees of freedom. The numerical solutions of the \(2-D\) screened Poisson equation with zero loading functions and the Dirichlet boundary conditions are obtained by the new approach on square (\(b_y=1\)) Cartesian meshes (curve 1); by the conventional linear (curves 2 and 5) and high-order (curves 3,4,6,7) finite elements on triangular (curves 2–4) and quadrilateral (curves 5–7) meshes. Symbols \(\bigtriangledown \), \(+\), \(\bigcirc \), \(*\), \(\times \), \(\square \) and \(\diamond \) correspond to the results for the different N (a) and h (b) used in the calculations

It can be concluded that at the same number of degrees of freedom, the new approach yields much more accurate results compared to those obtained by the linear and high-order (quadratic and cubic) finite elements used for the \(2-D\) Helmholtz and screened Poisson equations. It is worth to mention that the high-order finite elements have much wider stencils and require a greater computational time compared to that for the new approach.

4 Concluding remarks

Most of the numerical techniques for the solution of partial differential equations finally reduce to a system of discrete or semi-discrete equations. However, in many cases the corresponding stencil equations of these systems do not provide an optimal accuracy. The idea of the new approach consists in the direct optimization of the coefficients of the stencil equations and it is based on the minimization of the order of the local truncation error. The form and width of the stencil equations in the new approach are assumed (e.g., as it is assumed for the finite-difference method) or can be selected similar to those for known numerical techniques (in this case the accuracy of the known numerical techniques can be significantly improved by the modification of the coefficients of the stencil equations). Another idea of the new approach is the use of simple Cartesian meshes for complex irregular domain. In the considered paper the new approach has been applied to the space discretization of the time-independent Helmholtz equation. 9-point stencils in the 2-D case that are similar to those for the linear quadrilateral finite elements are considered in the paper. The main advantages of the suggested technique can be summarized as follows:

  • The idea of the minimization of the order of the local truncation error of stencil equations can be easily and efficiently applied to the development of new numerical techniques with an optimal accuracy as well as to the accuracy improvement of known numerical methods. The new approach can be equally applied to regular and irregular domains. In contrast to many fictitious domain numerical methods, the new approach uses the exact Dirichlet and Neumann boundary conditions at the actual boundary points without their interpolation using the Cartesian grid points.

  • In contrast to the finite-difference techniques with the coefficients of the stencils calculated through the approximation of separate partial derivatives, the entire partial differential equation is used for the calculation of the stencil coefficients in the new approach. This leads to the optimal accuracy of the proposed technique.

  • At the same computation costs, the new approach yields a much higher order of accuracy than other numerical techniques; e.g., than the finite elements. For example, at the similar 9-point stencils, the accuracy of the new approach is two orders higher than that for the linear finite elements. The numerical results for irregular domains also show that at the same number of degrees of freedom, the new approach is even much more accurate than the quadratic and cubic finite elements with much wider stencils. This also means that at a given accuracy, the new approach significantly reduces the computation time compared to known numerical techniques.

  • Similar to our recent results for regular domains in [73], the order of accuracy of the new approach for the Helmholtz equation on irregular domains with square Cartesian meshes is higher than that with rectangular Cartesian meshes.

  • In contrast to the finite elements, spectral elements, isogeometric elements and other similar techniques used for irregular domains, the new approach uses trivial Cartesian meshes that requires a negligible computation time for their preparation.

  • The new approach does not require the time consuming numerical integration for finding the coefficients of the stencil equations; e.g., as for the high-order finite, spectral and isogeometric elements. For the new technique, the coefficients of the stencil equations for the grid points located far from the boundary are calculated analytically. For the grid points located close to the boundary (with non-uniform and cut stencils), the coefficients of the stencil equations are calculated numerically by the solution of very small local systems of linear algebraic equations.

  • It has been shown that the Helmholtz and screened Poisson equations can be uniformly treated with the new approach.

In the future we plan to consider the stencils with a larger numbers of grid points for a higher order of accuracy (similar to the high-order finite elements or to the high-order finite-difference techniques), to consider a mesh refinement with uniform Cartesian meshes using special stencils for the transition from a fine mesh to a coarse mesh, to consider other boundary conditions (e.g., the Robin conditions), to extend the approach to the 3-D case, to solve real-world problems with the new approach. We also plan to study the application of the new approach to more complicated scalar PDEs and systems of PDEs that include mixed derivatives and higher-order derivatives. For example, in [108] we successfully applied the new approach on regular domains to a system of 2-D elasticity equations that include two PDEs with mixed derivatives.