boundary conditions for differentiate()
See original GitHub issueIs your feature request related to a problem?
I need to take centered finite difference of data
of length N along the dimension ‘X’, with boundary conditions (BCs) specified in flexible ways. Before this, we need to pad data
with BCs (length becoming N+2) so that the indicing will not be out-of-range.
Commonly used BCs are:
fixed
- fill with fixed values so derivatives at BCs are(BC - data[-1])/dx
and(data[0] - BC)/dx
;extend
- fill BCs with second outer-most values so that derivatives at BCs are exactly zero;periodic
- fill BCs cyclic so that the derivatives are also cyclic.
Describe the solution you’d like
The implementation of differentiate('X')
would be like:
# padded with BCs into N+2
data_pad = pad_BCs(data, type='periodic')
# it is safe to take finite difference
for i in range(len(data))
diff[i] = data_pad [i+1] - data_pad [i-1]
The pad_BCs
function could be easily implemented with np.pad()
function.
Then we can call:
data.differentiate('X', BCs='periodic')
We may also specify different kind of BCs at the two boundaries:
data.differentiate('X', BCs=['extend', 'fixed'], fill_values=0)
Describe alternatives you’ve considered
No response
Additional context
I am not clear how differentiate()
is implemented and just want to know if this can be implemented in a straightforward way.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Differential Equations - Boundary Value Problems
With boundary value problems we will have a differential equation and we will specify the function and/or derivatives at different points, which ...
Read more >Finite Difference Methods for Boundary Value Problems
Learn how to handle different boundary conditions. (). Finite Differences ... Compute error when solution is known. (). Finite Differences.
Read more >Boundary value problem - Wikipedia
In mathematics, in the field of differential equations, a boundary value problem is a differential equation together with a set of additional constraints, ......
Read more >Stable Boundary Conditions and Difference Schemes ... - jstor
STABLE BOUNDARY CONDITIONS AND DIFFERENCE SCHEMES. FOR NAVIER-STOKES EQUATIONS*. PRAVIR DUTTt. Abstract. The Navier-Stokes equations at high Reynolds ...
Read more >Answered: Differentiate the three possible types… | bartleby
MathCalculusDifferentiate the three possible types of boundary conditions that can be used for second-order partial differential equations, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
+1 for xgcm.
On the xarray side, I think we should just recommend composing
pad
withdiff
ordifferentiate
. We’ll need to add a “extrapolate” option for the padded coordinate variables for this to work.yes all of the grid methods (
grid.diff
etc) are now internally using grid_ufuncs. The axis methods are still going through the old code path, but will be deprecated soon! Please let us know how you get along with the new functionality, we are very curious for user feedback!