2
$\begingroup$

After exporting the solution (u) and the mesh (p, e, t) from pdetool to workspace, I need to compute the solution at a set of predefined points. These predefined points where the solution is sought are not uniformly spaced and are scattered in the xy space. I know that if one has the solution (u) from pde toolbox, it can be exported to a uniform grid using either griddata :

[u1,x1,y1] = gridfit(x,y,u,xnodes,ynodes)

or the function tri2grid . I believe both gridfit and tri2grid need the output sampling points to be monotonically increasing which unfortunately is not my case. How do I export/interpolate the solution to a non-uniform/scattered grid?

$\endgroup$
3
$\begingroup$

To interpolate/extrapolate solution on a uniform grid to a non-uniform grid, or vice versa, using the $\mathtt{TriScatteredInterp}$ class is the way to go.

Let say your u is associated with nodes: p, an array size $(\text{ # of nodes})\times (\text{Dimension})$, is originally where your solution u is defined on, so that size(u,1) = size(p,1). The the following commmand let you create an interpolant class (abstractly):

uI = triScatteredInterp(p(:,1),p(:,2),u,'natural'); 

for two dimensional data, or

uI = triScatteredInterp(p(:,1),p(:,2),p(:,3),u,'natural'); 

for 3D data. I personally prefer 'natural' as method here, 'nearest' is not that nice for PDE solution, and 'linear' will result in loss of interpolation near boundary where two sides data are needed.

Now to get the values on the non-uniform grid, what is best about triScatteredInterp class is that it works like a function, you can use feval to evaluate like a function handle: say your non-uniform grid points are array q

 uInterp_at_q = uI(q(:,1),q(:,2));

in 2D or

 uInterp_at_q = uI(q(:,1),q(:,2),q(:,3));

in 3D. And uInterp_at_q(i,1) is the value of the interpolant associated with the $i$-th node q(i,:).


Notice mathworks' doc says that

TriScatteredInterp will be removed in a future release. Use scatteredInterpolant instead.

The usage will almost the same, just scatteredInterpolant has an extra extrapolation method switch.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.