zwicker-group / py-pde

Python package for solving partial differential equations using finite differences.
https://py-pde.readthedocs.io
MIT License
402 stars 51 forks source link

Generic expression in boundary condition #416

Closed yohad closed 7 months ago

yohad commented 1 year ago

Hi,

I'm trying to understand how to encode the following boundary condition:

A * d^2f/dx^2 + B * (df/dx)^2 + C * df/dx = 0

I saw that the MixedBC class does something similar but not quite what I need. Is there a way to pass this expression directly to ExpressionBC?

Thanks

david-zwicker commented 1 year ago

This boundary condition is currently not implemented (since it is second order). In fact, it is not straight-forward to implement this condition on curvilinear coordinates, but it should be possible to do it on Cartesian coordinates. The way to go is to discretize the differential operators and then use the boundary condition to solve for the virtual point outside the boundary using the two points inside the domain next to the boundary. Concretely, one would need to subclass pde.grids.boundaries.axis.ConstBC2ndOrderBase to implement this analogously to CurvatureBC (which simply imposes a constant second derivative).

yohad commented 1 year ago

Fortunately, I'm only interested in Cartesian coordinates. I see that ConstBC2ndOrderBase only supports linear terms of the virtual points while I need a term for (df/dx)^2. I see that the linear terms are being calculated multiple times in functions of ConstBC2ndOrderBase so I would need to change them all, right?

david-zwicker commented 1 year ago

Good point – I missed the non-linear term. This will certainly complicated things, since the boundary condition is not necessarily unique (there could in principle be multiple solutions for the same values of the nearby grid points). However, if you can somehow determine the correct value of the virtual point, you could also directly inherit from BCBase and overwrite the set_ghost_cells and make_virtual_point_evaluator methods.