Numerical approximation of the 2nd derivative across a diffuse interface

In summary, the conversation discusses creating a diffuse interface using MATLAB code and using numerical methods to approximate the second derivative of a function in the normal direction to the interface. The approach involves projecting a line from each node and estimating the value of the function through linear interpolation. However, the error in this approach can be large and there may be a need for a different method. Possible solutions include using a polar coordinate grid or varying the mesh size to improve the accuracy of the approximation. The goal of the conversation is not clear, as it is not stated whether the approximation is for a known function or an arbitrary unknown function.
  • #1
Dilon
3
0
Imagine you create a diffuse interface in space and determine which side of the interface you are on by a local scalar value that can be between 0 and 1. We could create a circle, centered in a rectangular ynum-by-xnum grid, with such a diffuse interface with the following MATLAB code:

Code:
xnum = 100; % grid nodes in x direction
ynum = 100; % grid nodes in y direction

xgrid       =  (-(xnum/2-1/2):1:(xnum/2-1/2)) ;  x = repmat(xgrid,[ynum 1]); % grid distance in x direction
ygrid       =  (-(ynum/2-1/2):1:(ynum/2-1/2))';  y = repmat(ygrid,[1 xnum]); % grid distance in y direction
r =  sqrt(x.^2+y.^2); % distance from central node

L = 10; % thickness of diffuse interface
radii = 40; % radius of circle

F = 1-(1+sin((pi/L)*(r-radii)))/2; % create diffuse interface
F(r<(radii-L/2))       =  1; % create diffuse interface
F(r>(radii+L/2))       =  0; % create diffuse interface

What I want to do is, use numerical methods on the regular grid to get the best approximation of the second derivative of F in the direction normal to the interface, for every node within the interface. To start, I get surface normal components as

Code:
dfdy       =  abs(circshift(F,[1 0])-circshift(F,[-1 0]))/2; % first derivative of f in y direction
dfdx       =  abs(circshift(F,[0 1])-circshift(F,[0 -1]))/2; % first derivative of f in x direction
normy = dfdy./sqrt(dfdy.^2+dfdx.^2); % surface normal, y component
normx = dfdx./sqrt(dfdy.^2+dfdx.^2); % surface normal, x component

However, even with this information, I do not see an easy way to compute the derivatives across the interface in the normal direction using the gridded data. My best effort so far has been to project a line from each node, in the direction of the surface normal, until it intersects the edge of the local cell (see below). At this position the value of F is estimated by linear interpolation between nodes a and b. The same is done in the backward direction and using the known distance, the 2nd derivative at node i is found as

Code:
dfdn2 = (F0+F1-F*2)/d^2

This part of the code is a big loop so I just explain it in this illustration:

interface.jpg


I've compared my numerical prediction to the true value for the second derivative across the interface, which is:

Code:
dfd2actual     = (1-2.*F).*((pi/L)^2/2)

My approach works okay, but it is not very precise, with errors that can be quite large (>5%).

Is there perhaps a better way to do this?? I planned to try cubic interpolation instead of linear interpolation to improve things, but maybe a different approach is better.
 
Physics news on Phys.org
  • #2
Ok, I'm a little lost in the specifics, but I have a couple of diagnostic questions.

Why not do this with a polar coordinate grid? In this case, it would make the normal derivatives a heck of a lot simpler. Is this a test case for a bigger project that requires cartesian coordinates?

How does the error you reported (the ~5% one) scale with the mesh size? Vary the mesh size and see how your error scales. If this is a simple truncation error, it should scale down with a finer mesh, and you can brute force your way through with a higher mesh count at the cost of more RAM usage. (Note: by mesh size I'm referring to what you call xnum and ynum.)
 
  • #3
Dilon said:
What I want to do is, use numerical methods on the regular grid to get the best approximation of the second derivative of F in the direction normal to the interface, for every node within the interface.

Your goal isn't clear. You illustrate taking a known function on the grid and approximating a set of directional second derivatives of that function. In that case "best approximation" is clearly defined because we can compare the approximation method to the actual directional second derivatives of the function.

However, it's possible that your example is intended as a test of approximation methods that will be used when you don't have a known function and only have data on grid points - or have a known function that is very time consuming to compute and intend only to compute it at grid points.

If your are developing an approximation for an abitrary unknown function, it isn't clear what "best approximation" means. There may not be a best approximation method or even a good approximation method that works for any arbitrary function. I think answering your question depends on narrowing down what kind of functions you want to approximate.
 

1. What is numerical approximation of the 2nd derivative?

Numerical approximation of the 2nd derivative is a method used in mathematics and science to estimate the second derivative of a function at a given point. It involves using a finite difference scheme to calculate an approximation of the second derivative, rather than using the exact mathematical formula.

2. What is a diffuse interface?

A diffuse interface is a boundary or interface between two substances or phases that is not clearly defined or sharp. It is characterized by a gradual change in properties, such as composition or density, rather than a sudden transition.

3. Why is numerical approximation of the 2nd derivative important in studying diffuse interfaces?

Numerical approximation of the 2nd derivative is important in studying diffuse interfaces because it allows us to accurately model and analyze the behavior of these interfaces in various systems and processes. It helps us understand how the properties change across the interface and how these changes affect the overall behavior of the system.

4. What are the different approaches to numerical approximation of the 2nd derivative?

There are several approaches to numerical approximation of the 2nd derivative, including the central difference method, the forward difference method, and the backward difference method. These methods differ in the way they calculate the derivative and the accuracy of their results.

5. What are some applications of numerical approximation of the 2nd derivative across a diffuse interface?

Numerical approximation of the 2nd derivative across a diffuse interface has many practical applications in fields such as physics, chemistry, and engineering. It is commonly used to model and analyze phase transitions, chemical reactions, diffusion processes, and other phenomena involving diffuse interfaces.

Similar threads

  • Programming and Computer Science
Replies
4
Views
2K
  • Classical Physics
Replies
6
Views
864
Replies
2
Views
1K
Replies
1
Views
1K
  • Special and General Relativity
Replies
1
Views
1K
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Advanced Physics Homework Help
Replies
7
Views
1K
  • Calculus and Beyond Homework Help
Replies
5
Views
4K
  • Linear and Abstract Algebra
Replies
2
Views
2K
Back
Top