# Coordinates to grid cells in Vorpal

I’ve written a macro with a few useful functions to convert between coordinates (in meters) and cells (in…cells). It makes it a bit neater for those blocks which insist on being defined on the grid.

So something horrible like:

lowerBounds = [\$int(floor((-XSTART-WG_A/2.)/DX))\$ \$int(floor((InWGCoupleOffSetY-YSTART)/DY))\$ \$int(floor(OutWGOffsetZ/DZ))\$]

upperBounds = [\$int(ceil((-XSTART+WG_A/2.)/DX))\$ \$int(ceil((InWGCoupleOffSetY-YSTART)/DY))+1\$ \$int(ceil((OutWGOffsetZ+WG_B)/DZ))\$]

turns into something vaguely readable like:

lowerBounds = toGridFloorA(-WG_A/2.,InWGCoupleOffSetY+YSTART,OutWGOffsetZ)

upperBounds = toGridCeilA(WG_A/2.,InWGCoupleOffSetY+YSTART,OutWGOffsetZ+WG_B)

toCoords(x,dx,xstart) should convert the other way from cells to coordinates.

Certain variables must be defined in the pre file (you will probably have these anyway).

If you have a grid defined as follows:

<Grid compGrid>

numCells = [NXGRID NYGRID NZGRID] # set up the cells space

lengths = [LXGRID LYGRID LZGRID] # the length of the cell space

startPositions = [XSTART YSTART ZSTART]

</Grid>

The flowing variables must be defined in the pre file.

• DX, DY, DZ defined as (in this case) LXGRID/ NXGRID and so on.
• XSTART, YSTART, ZSTART defined as the startPositions above.

You need to put this macro in the same folder as the .pre file OR in the macro directory, which is somewhere like this (on windows at least).

C:\Program Files\Tech-X\VORPAL4.2.2\macros

C:\Program Files\Tech-X (Win64)\VORPAL 5.2\Contents\engine\share\macros

Then it is just a case of importing gridCoords.mac. and using the functions.