lballabio / QuantLib

The QuantLib C++ library
http://quantlib.org
Other
5.26k stars 1.78k forks source link

Question The Neumann Boundary Value in PDE #1990

Closed tony21248772 closed 3 days ago

tony21248772 commented 3 months ago

image

boring-cyborg[bot] commented 3 months ago

Thanks for posting! It might take a while before we look at your issue, so don't worry if there seems to be no feedback. We'll get to it.

lballabio commented 2 months ago

The Neumann condition fixes the value $V$ of the first derivative on the boundary. On a finite-difference grid, the derivative at the (e.g., left) boundary is the one-sided numerical derivative $\displaystyle\frac{u_1 - u_0}{h}$ where $h$ is the distance between the corresponding nodes on the grid. So the Neumann condition can be written as

$$\frac{u_1 - u_0}{h} = V$$

and in order to enforce it, in applyAfterApplying we modify the value of $u_0$ by setting it as

$$u_0 = u_1 - h \times V$$

which is equivalent to the above. Now, the code in applyAfterApplying seems to be missing the $h$, but that's because the documentation of the NeumannBC class says:

//! Neumann boundary condition (i.e., constant derivative)
/*! \warning The value passed must not be the value of the derivative.
             Instead, it must be comprehensive of the grid step
             between the first two points--i.e., it must be the
             difference between f[0] and f[1].

that is, the variable value_ stored in the class corresponds to $h \times V$.

github-actions[bot] commented 2 weeks ago

This issue was automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment, or this will be closed in two weeks.

github-actions[bot] commented 3 days ago

This issue was automatically closed because it has been stalled for two weeks with no further activity.