From: James Ramm on
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


From: fabio freschi on
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(a)hotmail.com> wrote in message <hv09j2$1u3$1(a)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
>
>
From: James Ramm on
"fabio freschi" <fabio.freschi(a)remove.gmail.com> wrote in message <hv56d4$qje$1(a)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(a)hotmail.com> wrote in message <hv09j2$1u3$1(a)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, :)