Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to find connectivity matrix

Subject: how to find connectivity matrix

From: James Ramm

Date: 12 Jun, 2010 15:37:06

Message: 1 of 3

hi
I wish to define an unstructured grid in a VTK file, for which I need to give all the points in my grid (fine) and the connectivity - i.e. for each cell I need to give the indices of the points which make up said cell. (ugh).
I know triangulations and such will give indices for each tetrahedron, but I wish to define cubes. Does anyone know a good way to do this.

Some more detail on the grid:
It is basically a series of 2D grids which have equal X and Y spacing. The Z spacing between each grid may change for each point, hence the need to explicitly define each cell. Thus for each (xyz) point I would like to give the index of this point and its 7 neighbours, defining the hexahedron. Any algorithm would also need to know when it comes to the edge of the grid, so that opposite edges are not linked.


Thanks for any help

   

Subject: how to find connectivity matrix

From: fabio freschi

Date: 14 Jun, 2010 12:13:24

Message: 2 of 3

Hi
I have a piece of code for creating connectivity of hexahedra, supposing that points are generated according to
1) increasing x
2) increasing y
3) increasing z
e.g. for two cubes connected in x-direction
P = [
0 0 0
1 0 0
2 0 0
0 1 0
1 1 0
2 1 0
0 0 1
1 0 1
2 0 1
0 1 1
1 1 1
2 1 1
];

With this hypothesis node coordinates are not necessary and connectivity matrix can be defined with the following piece of code (where npx, npy, npz are the number of point for each axis, in the previous example npx = 3, npy = 2, npz = 2):

nodes = 1:int32(npx*npy*npz);
nodes = reshape(nodes,npx,npy,npz);
ncube = (npx-1)*(npy-1)*(npz-1);

H = zeros(ncube,8,'int32');
H(:,1) = reshape(nodes(1:npx-1,1:npy-1,1:npz-1),ncube,1);
H(:,2) = reshape(nodes(2:npx,1:npy-1,1:npz-1),ncube,1);
H(:,3) = reshape(nodes(2:npx,2:npy,1:npz-1),ncube,1);
H(:,4) = reshape(nodes(1:npx-1,2:npy,1:npz-1),ncube,1);
H(:,5) = reshape(nodes(1:npx-1,1:npy-1,2:npz),ncube,1);
H(:,6) = reshape(nodes(2:npx,1:npy-1,2:npz),ncube,1);
H(:,7) = reshape(nodes(2:npx,2:npy,2:npz),ncube,1);
H(:,8) = reshape(nodes(1:npx-1,2:npy,2:npz),ncube,1);

hope this helps
Fabio

"James Ramm" <theres_ambrosia_there@hotmail.com> wrote in message <hv09j2$1u3$1@fred.mathworks.com>...
> hi
> I wish to define an unstructured grid in a VTK file, for which I need to give all the points in my grid (fine) and the connectivity - i.e. for each cell I need to give the indices of the points which make up said cell. (ugh).
> I know triangulations and such will give indices for each tetrahedron, but I wish to define cubes. Does anyone know a good way to do this.
>
> Some more detail on the grid:
> It is basically a series of 2D grids which have equal X and Y spacing. The Z spacing between each grid may change for each point, hence the need to explicitly define each cell. Thus for each (xyz) point I would like to give the index of this point and its 7 neighbours, defining the hexahedron. Any algorithm would also need to know when it comes to the edge of the grid, so that opposite edges are not linked.
>
>
> Thanks for any help
>
>

Subject: how to find connectivity matrix

From: James Ramm

Date: 16 Jun, 2010 11:22:07

Message: 3 of 3

"fabio freschi" <fabio.freschi@remove.gmail.com> wrote in message <hv56d4$qje$1@fred.mathworks.com>...
> Hi
> I have a piece of code for creating connectivity of hexahedra, supposing that points are generated according to
> 1) increasing x
> 2) increasing y
> 3) increasing z
> e.g. for two cubes connected in x-direction
> P = [
> 0 0 0
> 1 0 0
> 2 0 0
> 0 1 0
> 1 1 0
> 2 1 0
> 0 0 1
> 1 0 1
> 2 0 1
> 0 1 1
> 1 1 1
> 2 1 1
> ];
>
> With this hypothesis node coordinates are not necessary and connectivity matrix can be defined with the following piece of code (where npx, npy, npz are the number of point for each axis, in the previous example npx = 3, npy = 2, npz = 2):
>
> nodes = 1:int32(npx*npy*npz);
> nodes = reshape(nodes,npx,npy,npz);
> ncube = (npx-1)*(npy-1)*(npz-1);
>
> H = zeros(ncube,8,'int32');
> H(:,1) = reshape(nodes(1:npx-1,1:npy-1,1:npz-1),ncube,1);
> H(:,2) = reshape(nodes(2:npx,1:npy-1,1:npz-1),ncube,1);
> H(:,3) = reshape(nodes(2:npx,2:npy,1:npz-1),ncube,1);
> H(:,4) = reshape(nodes(1:npx-1,2:npy,1:npz-1),ncube,1);
> H(:,5) = reshape(nodes(1:npx-1,1:npy-1,2:npz),ncube,1);
> H(:,6) = reshape(nodes(2:npx,1:npy-1,2:npz),ncube,1);
> H(:,7) = reshape(nodes(2:npx,2:npy,2:npz),ncube,1);
> H(:,8) = reshape(nodes(1:npx-1,2:npy,2:npz),ncube,1);
>
> hope this helps
> Fabio
>
> "James Ramm" <theres_ambrosia_there@hotmail.com> wrote in message <hv09j2$1u3$1@fred.mathworks.com>...
> > hi
> > I wish to define an unstructured grid in a VTK file, for which I need to give all the points in my grid (fine) and the connectivity - i.e. for each cell I need to give the indices of the points which make up said cell. (ugh).
> > I know triangulations and such will give indices for each tetrahedron, but I wish to define cubes. Does anyone know a good way to do this.
> >
> > Some more detail on the grid:
> > It is basically a series of 2D grids which have equal X and Y spacing. The Z spacing between each grid may change for each point, hence the need to explicitly define each cell. Thus for each (xyz) point I would like to give the index of this point and its 7 neighbours, defining the hexahedron. Any algorithm would also need to know when it comes to the edge of the grid, so that opposite edges are not linked.
> >
> >
> > Thanks for any help
> >
> >

Thanks fabio for the reply, its given me an idea or two, :)

Tags for this Thread

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.

Contact us