Thread Subject: data gridding on a 2-d mesh with voids

Subject: data gridding on a 2-d mesh with voids

From: Shawn

Date: 24 Dec, 2009 14:49:04

Message: 1 of 10

Hi all,

I'm wrestling with something but simply unfamiliar enough with either the background math or matlab itself to figure it out.

I have a dataset of 2D triangular mesh data from an external solver (actually a slice of an asymmetric 3D FEM simulation), which I'm attempting to plot. I don't have a problem griddding and plotting it with say the method below:

tx = -100:1:100;
ty = -100:1:100;
[XI,YI] = meshgrid(tx,ty);
ZI = griddata(x,y,Efield,XI,YI,'cubic');

What concerns me is that the original mesh itself contains a number of voids, empty regions with no points which define certain objects with fixed boundary conditions. When I grid, of course, it also goes into those regions, so the interpolated values at the boundary are of necessity slightly off (the interior is irrelevant, but the most important information for me lies right near the boundary of the objects, and if that is artificially reduced by averaging with the inside (where its arbitrarily zero), then its a problem.

Suggestions, ideas where to start? From what I understand, griddata can't handle convex regions, so if I set up a 2d grid excluding them then it will surely choke. I imagine the problem must be common but I haven't had luck finding the solution as yet.

Cheers!

Subject: data gridding on a 2-d mesh with voids

From: dpb

Date: 24 Dec, 2009 15:13:43

Message: 2 of 10

Shawn wrote:
...
> I have a dataset of 2D triangular mesh data from an external solver
> (actually a slice of an asymmetric 3D FEM simulation), which I'm
> attempting to plot. ...
> What concerns me is that the original mesh itself contains a number of
> voids, empty regions with no points which define certain objects with
> fixed boundary conditions. When I grid, of course, it also goes into
> those regions, so the interpolated values at the boundary are of
> necessity slightly off (the interior is irrelevant, but the most
> important information for me lies right near the boundary of the
> objects, and if that is artificially reduced by averaging with the
> inside (where its arbitrarily zero), then its a problem.
> Suggestions, ideas where to start? From what I understand, griddata
> can't handle convex regions, so if I set up a 2d grid excluding them
> then it will surely choke. I imagine the problem must be common but I
> haven't had luck finding the solution as yet.

AFAIK ML doesn't deal w/ the problem of arbitrary meshes well at all.
My solution for such problems has always been Tecplot from Tecplot, Inc.
(formerly Amtec Engineering) -- <www.tecplot.com>

Not the c.s-s.m way, but is a tool specifically by FEM'ers for FEM
modelers...

--

Subject: data gridding on a 2-d mesh with voids

From: dpb

Date: 24 Dec, 2009 15:48:58

Message: 3 of 10

dpb wrote:
> Shawn wrote:
> ...
>> I have a dataset of 2D triangular mesh data from an external solver
>> (actually a slice of an asymmetric 3D FEM simulation), which I'm
>> attempting to plot. ...
>> What concerns me is that the original mesh itself contains a number of
>> voids, empty regions with no points which define certain objects with
>> fixed boundary conditions. ...

Something like this, maybe???

<http://www.tecplot.com/showcase/gallery/mesh/18.asp>

--

Subject: data gridding on a 2-d mesh with voids

From: Loren Shure

Date: 24 Dec, 2009 16:48:56

Message: 4 of 10

In article <hgvv10$pos$1@fred.mathworks.com>, sfostner@physics.mcgill.ca
says...
> Hi all,
>
> I'm wrestling with something but simply unfamiliar enough with either the background math or matlab itself to figure it out.
>
> I have a dataset of 2D triangular mesh data from an external solver (actually a slice of an asymmetric 3D FEM simulation), which I'm attempting to plot. I don't have a problem griddding and plotting it with say the method below:
>
> tx = -100:1:100;
> ty = -100:1:100;
> [XI,YI] = meshgrid(tx,ty);
> ZI = griddata(x,y,Efield,XI,YI,'cubic');
>
> What concerns me is that the original mesh itself contains a number of voids, empty regions with no points which define certain objects with fixed boundary conditions. When I grid, of course, it also goes into those regions, so the interpolated values at the boundary are of necessity slightly off (the interior is irrelevant, but the most important information for me lies right near the boundary of the objects, and if that is artificially reduced by averaging with the
inside (where its arbitrarily zero), then its a problem.
>
> Suggestions, ideas where to start? From what I understand, griddata can't handle convex regions, so if I set up a 2d grid excluding them then it will surely choke. I imagine the problem must be common but I haven't had luck finding the solution as yet.
>
> Cheers!

Consider some of these MATLAB tools: trimesh, trisurf
Or perhaps some of the delaunay triangulation tools can help set up the
data in the right form first.

--
Loren
http://blogs.mathworks.com/loren

Subject: data gridding on a 2-d mesh with voids

From: John D'Errico

Date: 24 Dec, 2009 18:17:05

Message: 5 of 10

"Shawn " <sfostner@physics.mcgill.ca> wrote in message <hgvv10$pos$1@fred.mathworks.com>...
> Hi all,
>
> I'm wrestling with something but simply unfamiliar enough with either the background math or matlab itself to figure it out.
>
> I have a dataset of 2D triangular mesh data from an external solver (actually a slice of an asymmetric 3D FEM simulation), which I'm attempting to plot. I don't have a problem griddding and plotting it with say the method below:
>
> tx = -100:1:100;
> ty = -100:1:100;
> [XI,YI] = meshgrid(tx,ty);
> ZI = griddata(x,y,Efield,XI,YI,'cubic');
>
> What concerns me is that the original mesh itself contains a number of voids, empty regions with no points which define certain objects with fixed boundary conditions. When I grid, of course, it also goes into those regions, so the interpolated values at the boundary are of necessity slightly off (the interior is irrelevant, but the most important information for me lies right near the boundary of the objects, and if that is artificially reduced by averaging with the inside (where its arbitrarily zero), then its a problem.
>
> Suggestions, ideas where to start? From what I understand, griddata can't handle convex regions, so if I set up a 2d grid excluding them then it will surely choke. I imagine the problem must be common but I haven't had luck finding the solution as yet.
>
> Cheers!

Griddata will span the interior holes with triangles,
and the triangles must of course be large ones.

If you already have the triangulation at hand, then
the simple way to plot it is to use trisurf. trisurf will
work even if the region is not convex. The holes
will be no problem, since you have the triangles.

If you don't have a triangulation, then the simplest
thing is to use gridfit to fit the entire region. It
too will span the interior holes, but it will interpolate
the edges of the holes far more smoothly than
griddata.

I do have a fully general (and adaptive) code to
model non-convex regions, but I have not yet
gotten it ready for general dispersal. Gridfit should
be sufficient here.

http://www.mathworks.com/matlabcentral/fileexchange/8998

HTH,
John
John

Subject: data gridding on a 2-d mesh with voids

From: Damian

Date: 28 Dec, 2009 13:44:04

Message: 6 of 10

"Shawn " <sfostner@physics.mcgill.ca> wrote in message <hgvv10$pos$1@fred.mathworks.com>...
> Hi all,
>
> I'm wrestling with something but simply unfamiliar enough with either the background math or matlab itself to figure it out.
>
> I have a dataset of 2D triangular mesh data from an external solver (actually a slice of an asymmetric 3D FEM simulation), which I'm attempting to plot. I don't have a problem griddding and plotting it with say the method below:
>
> tx = -100:1:100;
> ty = -100:1:100;
> [XI,YI] = meshgrid(tx,ty);
> ZI = griddata(x,y,Efield,XI,YI,'cubic');
>
> What concerns me is that the original mesh itself contains a number of voids, empty regions with no points which define certain objects with fixed boundary conditions. When I grid, of course, it also goes into those regions, so the interpolated values at the boundary are of necessity slightly off (the interior is irrelevant, but the most important information for me lies right near the boundary of the objects, and if that is artificially reduced by averaging with the inside (where its arbitrarily zero), then its a problem.
>
> Suggestions, ideas where to start? From what I understand, griddata can't handle convex regions, so if I set up a 2d grid excluding them then it will surely choke. I imagine the problem must be common but I haven't had luck finding the solution as yet.
>
> Cheers!

The TriScatteredInterp tool (R2009a and later) was specifically designed to handle this usecase. You first need to create a constrained Delaunay triangulation (DelaunayTri), where the constraints represent the boundary that you wish to respect. You then use the constrained DelaunayTri to create a TriScatteredInterp (interpolant).
This example desmonstrates how to create a constrained Delaunay triangulation.
http://www.mathworks.com/products/demos/shipping/matlab/demoDelaunayTri.html#18

If you haven't used TriScatteredInterp before, here's an overview on Loren's Art of MATLAB blog.
http://blogs.mathworks.com/loren/2009/07/22/computational-geometry-in-matlab-r2009a-part-ii/

When you create the constrained Delaunay you could, if you wish, replicate your FE mesh by constraining all edges and not just the edges on the free boundary. Either way, you should create a TriRep (Triangulation Representation) to represent your FE mesh as it can provide you with the Free Boundary edges or all edges which you will need to constrain your triangulation.

Damian

Subject: data gridding on a 2-d mesh with voids

From: Shawn

Date: 29 Dec, 2009 02:49:04

Message: 7 of 10

Thanks for the great replies all.

I think the constrained delaunay mesh will work best, I actually didn't realize that I didn't have that, as I've been using 2008b up until now. As I have the option, I upgraded to 2009b and am playing with it now.

Tecplot loots like a good tool, but not one I have access to unfortunately.

Subject: data gridding on a 2-d mesh with voids

From: dpb

Date: 29 Dec, 2009 05:30:57

Message: 8 of 10

Shawn wrote:
> Thanks for the great replies all.
> I think the constrained delaunay mesh will work best, I actually didn't
> realize that I didn't have that, as I've been using 2008b up until now.
> As I have the option, I upgraded to 2009b and am playing with it now.
> Tecplot loots like a good tool, but not one I have access to unfortunately.

I'm stuck w/ a much earlier release of ML -- glad to see they apparently
have finally gotten more flexibility for mesh plotting than this release
and earlier. I'll not be giving up Tecplot, though, methinks... :)

--

Subject: data gridding on a 2-d mesh with voids

From: Shawn

Date: 31 Dec, 2009 15:28:03

Message: 9 of 10

Ok, so I have tried a few things, but not sure yet what the best solution is and some input would be nice:

1) I can take the original point cloud and similar to outlined in the original example (7), I can do the triangulation based on that. (in this case its a 2d slice of what was a 3d matrix, but it still works for the most part). I'm still having trouble with the core of the procedure though:
% The Delaunay edges that connect pairs of sample points represent the
% boundary.
delEdges = dt.edges();
validx = delEdges(:,1) <= numpts;
validy = delEdges(:,2) <= numpts;
boundaryEdges = delEdges((validx & validy), :)';
xb = x(boundaryEdges);
yb = y(boundaryEdges);

Not entirely sure what the point of this is, if I read it correctly its really only finding those points with indices < the number of original points on the curve (not the triangular mesh which has much more edges). Does it actually care about the BOUNDARY, or just the original polygon?

I've gotten that far with my data, but from this triangulated cloud I don't know where to go. Now I have a 2d delaunay mesh, but an unconstrained one at that, still. I think.

2) I can also take the ORIGINAL data file, ie a vtk mesh with both 3d tetras and 2d face triangles, and import it into matlab. This gives me 3 matrices, points, cells (however some have 3 vertices specified only, where they are part of the surface mesh), and the actual POINT DATA, eg the relevant quantity specified on each vertex.

However, I'm not so sure about getting that into a delaunaytri structure, I tried creating a dummy structure to do it, then inserting them, interesting enough it removed all duplicate points for me automatically. However, that means that my point data matrix is no longer quite correct, as some points/cells were removed, and I don't know how to deal with that. Well that and the fact that it crashed matlab badly when I tried to plot it, rather than just the boundary elements. :) My bad.

Thoughts, suggestions?

Cheers
Shawn

Subject: data gridding on a 2-d mesh with voids

From: Hualei

Date: 2 Apr, 2010 00:08:04

Message: 10 of 10

Hello Damian
I have a question on constrained Delaunay:
There are say 600 vetices and the boundary is only consisted of 300 points, and it comes up this error message saying "??? Error using ==> DelaunayTri
The column-vectors defining the edges have inconsistent dimensions."

Could you give some advice?

Thank you!
-Hualei
"Damian " <damian.sheehy@mathworks.com> wrote in message <hhacn4$ddq$1@fred.mathworks.com>...
> "Shawn " <sfostner@physics.mcgill.ca> wrote in message <hgvv10$pos$1@fred.mathworks.com>...
> > Hi all,
> >
> > I'm wrestling with something but simply unfamiliar enough with either the background math or matlab itself to figure it out.
> >
> > I have a dataset of 2D triangular mesh data from an external solver (actually a slice of an asymmetric 3D FEM simulation), which I'm attempting to plot. I don't have a problem griddding and plotting it with say the method below:
> >
> > tx = -100:1:100;
> > ty = -100:1:100;
> > [XI,YI] = meshgrid(tx,ty);
> > ZI = griddata(x,y,Efield,XI,YI,'cubic');
> >
> > What concerns me is that the original mesh itself contains a number of voids, empty regions with no points which define certain objects with fixed boundary conditions. When I grid, of course, it also goes into those regions, so the interpolated values at the boundary are of necessity slightly off (the interior is irrelevant, but the most important information for me lies right near the boundary of the objects, and if that is artificially reduced by averaging with the inside (where its arbitrarily zero), then its a problem.
> >
> > Suggestions, ideas where to start? From what I understand, griddata can't handle convex regions, so if I set up a 2d grid excluding them then it will surely choke. I imagine the problem must be common but I haven't had luck finding the solution as yet.
> >
> > Cheers!
>
> The TriScatteredInterp tool (R2009a and later) was specifically designed to handle this usecase. You first need to create a constrained Delaunay triangulation (DelaunayTri), where the constraints represent the boundary that you wish to respect. You then use the constrained DelaunayTri to create a TriScatteredInterp (interpolant).
> This example desmonstrates how to create a constrained Delaunay triangulation.
> http://www.mathworks.com/products/demos/shipping/matlab/demoDelaunayTri.html#18
>
> If you haven't used TriScatteredInterp before, here's an overview on Loren's Art of MATLAB blog.
> http://blogs.mathworks.com/loren/2009/07/22/computational-geometry-in-matlab-r2009a-part-ii/
>
> When you create the constrained Delaunay you could, if you wish, replicate your FE mesh by constraining all edges and not just the edges on the free boundary. Either way, you should create a TriRep (Triangulation Representation) to represent your FE mesh as it can provide you with the Free Boundary edges or all edges which you will need to constrain your triangulation.
>
> Damian

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
constrained Hualei 1 Apr, 2010 20:09:10
delaunay Hualei 1 Apr, 2010 20:09:10
fem Shawn 24 Dec, 2009 09:49:08
triangular Shawn 24 Dec, 2009 09:49:08
griddata Shawn 24 Dec, 2009 09:49:07
rssFeed for this Thread

Contact us at files@mathworks.com