Commit d9f7b949 authored by Luís de Sousa's avatar Luís de Sousa
Browse files

Reformulated edges indexing taking double border into account.

parent bb2cb747
......@@ -256,21 +256,15 @@ namespace CA {
// has caLevels*2 + 1 border in the X direction and caLevels*2
// border in the Y direction.
// The two diagonal edge buffers are different, due to the extra
// introduced to create a direct correspondence to a square grid.
// Both the northwest/southeast and southwest/northeast buffers
// have an irregular edge row (along the xx axis) again due to
// the extra cells.
_cagrid.eb_ns_y_border = caLevels;
_cagrid.eb_we_x_border = caLevels;
_cagrid.eb_ns_x_size = _cagrid.x_size + _cagrid.eb_ns_y_border*2;
_cagrid.eb_ns_x_size = _cagrid.x_size;
_cagrid.eb_ns_y_size = _cagrid.y_size + _cagrid.eb_we_x_border*2 + 1; // Notice the +1.
_cagrid.eb_nwse_x_size = _cagrid.x_size + _cagrid.eb_ns_y_border*2 + 1;
_cagrid.eb_nwse_y_size = _cagrid.y_size + _cagrid.eb_we_x_border*2 + 1;
_cagrid.eb_nwse_y_size = _cagrid.y_size;
_cagrid.eb_swne_x_size = _cagrid.eb_nwse_x_size;
_cagrid.eb_swne_y_size = _cagrid.eb_nwse_y_size;
......@@ -279,7 +273,8 @@ namespace CA {
// Set the starting point for the three sub-buffers in the main buffer.
_cagrid.eb_ns_start = 0; // The north/South is first.
_cagrid.eb_nwse_start = _cagrid.eb_ns_x_size * _cagrid.eb_ns_y_size;
_cagrid.eb_swne_start = _cagrid.eb_nwse_x_size * _cagrid.eb_nwse_y_size;
_cagrid.eb_swne_start = _cagrid.eb_nwse_start +
_cagrid.eb_nwse_x_size * _cagrid.eb_nwse_y_size;
_cagrid.print = false;
}
......
......@@ -1093,8 +1093,8 @@ inline void caActivateAlarmMask(CA_GRID grid, CA_ALARMS_O alarms, CA_STATE mask,
// ---- CELL BUFFERS ----
//! Note that the odd/even neighbourhood selection methods are actually backwards.
//! CADDIES is shifting the internal (0,0) index to the (-1,-1) cell in the original
//! grid coordinates. Therefore column 0 in original falls into an odd column in
//! the structures created by CADDIES.
//! grid coordinates. Therefore column 0 in the original grid falls into an odd column
//! in the structures created by CADDIES.
//! Read the real value of the cell from the given buffer at the given cell number.
inline _caReal caReadCellBuffReal(CA_GRID grid, CA_CELLBUFF_REAL_I src, int cell_number)
......@@ -1292,14 +1292,11 @@ inline void getXY(int cell_number, _caUnsigned main_x, _caUnsigned main_y,
inline void computeEdgeIndexes(CA_GRID grid, _caUnsigned x, _caUnsigned y,
_caUnsigned& i_ns, _caUnsigned& i_nwse, _caUnsigned& i_swne)
{
i_ns = (y + grid.eb_ns_y_border) * grid.eb_ns_x_size
+ (x + grid.eb_we_x_border) + grid.eb_ns_start;
i_ns = grid.eb_ns_start + y * grid.eb_ns_x_size + x;
_caUnsigned i_diag = (y + grid.eb_ns_y_border) * grid.eb_nwse_x_size
+ (x + grid.eb_we_x_border);
i_nwse = grid.eb_nwse_start + y * grid.eb_nwse_x_size + x + 1;
i_nwse = i_diag + grid.eb_nwse_start;
i_swne = i_diag + grid.eb_swne_start;
i_swne = grid.eb_swne_start + y * grid.eb_swne_x_size + x + 2;
}
//! Read the real value of the edge from the given buffer at the given
......@@ -1324,12 +1321,12 @@ inline _caReal caReadEdgeBuffReal(CA_GRID grid, CA_EDGEBUFF_REAL_I src,
switch(edge_number)
{
case 0: value = 0.0; break;
case 1: value = src[i_swne + 1]; break;
case 1: value = src[i_swne]; break;
case 2: value = src[i_ns]; break;
case 3: value = src[i_nwse]; break;
case 4: value = src[i_swne]; break;
case 4: value = src[i_swne + grid.eb_swne_x_size - 1]; break;
case 5: value = src[i_ns + grid.eb_ns_x_size]; break;
case 6: value = src[i_nwse + 1]; break;
case 6: value = src[i_nwse + grid.eb_nwse_x_size + 1]; break;
}
}
else //even
......@@ -1337,12 +1334,12 @@ inline _caReal caReadEdgeBuffReal(CA_GRID grid, CA_EDGEBUFF_REAL_I src,
switch(edge_number)
{
case 0: value = 0.0; break;
case 1: value = src[i_swne + grid.eb_swne_x_size]; break;
case 1: value = src[i_swne]; break;
case 2: value = src[i_ns]; break;
case 3: value = src[i_nwse]; break;
case 4: value = src[i_swne]; break;
case 4: value = src[i_swne - 1]; break;
case 5: value = src[i_ns + grid.eb_ns_x_size]; break;
case 6: value = src[i_nwse + grid.eb_nwse_x_size]; break;
case 6: value = src[i_nwse + 1]; break;
}
}
......@@ -1366,22 +1363,20 @@ inline void caReadEdgeBuffRealEdgeArray(CA_GRID grid, CA_EDGEBUFF_REAL_I src,
computeEdgeIndexes(grid, x, y, i_ns, i_nwse, i_swne);
values[0] = 0.0;
values[1] = src[i_swne];
values[2] = src[i_ns];
values[3] = src[i_nwse];
values[5] = src[i_ns + grid.eb_ns_x_size];
if(grid.main_x % 2) //odd
{
values[1] = src[i_swne + 1];
values[3] = src[i_nwse];
values[4] = src[i_swne];
values[6] = src[i_nwse + 1];
values[4] = src[i_swne + grid.eb_swne_x_size - 1];
values[6] = src[i_nwse + grid.eb_nwse_x_size + 1];
}
else //even
{
values[1] = src[i_swne + grid.eb_swne_x_size];
values[3] = src[i_nwse];
values[4] = src[i_swne];
values[6] = src[i_nwse + grid.eb_nwse_x_size];
values[4] = src[i_swne - 1];
values[6] = src[i_nwse + 1];
}
}
......@@ -1400,26 +1395,26 @@ inline void caWriteEdgeBuffReal(CA_GRID grid, CA_EDGEBUFF_REAL_IO dst, int edge_
{
switch(edge_number)
{
case 0: break;
case 1: dst[i_swne + 1] = value; break;
case 2: dst[i_ns] = value; break;
case 3: dst[i_nwse] = value; break;
case 4: dst[i_swne] = value; break;
case 5: dst[i_ns + grid.eb_ns_x_size] = value; break;
case 6: dst[i_nwse + 1] = value; break;
case 0: break;
case 1: dst[i_swne] = value; break;
case 2: dst[i_ns] = value; break;
case 3: dst[i_nwse] = value; break;
case 4: dst[i_swne + grid.eb_swne_x_size - 1] = value; break;
case 5: dst[i_ns + grid.eb_ns_x_size] = value; break;
case 6: dst[i_nwse + grid.eb_nwse_x_size + 1] = value; break;
}
}
else //even
{
switch(edge_number)
{
case 0: break;
case 1: dst[i_swne + grid.eb_swne_x_size] = value; break;
case 2: dst[i_ns] = value; break;
case 3: dst[i_nwse] = value; break;
case 4: dst[i_swne] = value; break;
case 5: dst[i_ns + grid.eb_ns_x_size] = value; break;
case 6: dst[i_nwse + grid.eb_nwse_x_size] = value; break;
case 0: break;
case 1: dst[i_swne] = value; break;
case 2: dst[i_ns] = value; break;
case 3: dst[i_nwse] = value; break;
case 4: dst[i_swne - 1] = value; break;
case 5: dst[i_ns + grid.eb_ns_x_size] = value; break;
case 6: dst[i_nwse + 1] = value; break;
}
}
}
......@@ -1446,26 +1441,26 @@ inline _caState caReadEdgeBuffState(CA_GRID grid, CA_EDGEBUFF_STATE_I src,
{
switch(edge_number)
{
case 0: value = 0.0; break;
case 1: value = src[i_swne + 1]; break;
case 2: value = src[i_ns]; break;
case 3: value = src[i_nwse]; break;
case 4: value = src[i_swne]; break;
case 5: value = src[i_ns + grid.eb_ns_x_size]; break;
case 6: value = src[i_nwse + 1]; break;
case 0: value = 0.0; break;
case 1: value = src[i_swne]; break;
case 2: value = src[i_ns]; break;
case 3: value = src[i_nwse]; break;
case 4: value = src[i_swne + grid.eb_swne_x_size - 1]; break;
case 5: value = src[i_ns + grid.eb_ns_x_size]; break;
case 6: value = src[i_nwse + grid.eb_nwse_x_size + 1]; break;
}
}
else //even
{
switch(edge_number)
{
case 0: value = 0.0; break;
case 1: value = src[i_swne + grid.eb_swne_x_size]; break;
case 2: value = src[i_ns]; break;
case 3: value = src[i_nwse]; break;
case 4: value = src[i_swne]; break;
case 0: value = 0.0; break;
case 1: value = src[i_swne]; break;
case 2: value = src[i_ns]; break;
case 3: value = src[i_nwse]; break;
case 4: value = src[i_swne - 1]; break;
case 5: value = src[i_ns + grid.eb_ns_x_size]; break;
case 6: value = src[i_nwse + grid.eb_nwse_x_size]; break;
case 6: value = src[i_nwse + 1]; break;
}
}
......@@ -1488,25 +1483,21 @@ inline void caReadEdgeBuffStateEdgeArray(CA_GRID grid, CA_EDGEBUFF_STATE_I src,
computeEdgeIndexes(grid, x, y, i_ns, i_nwse, i_swne);
values[0] = 0.0;
values[1] = src[i_swne];
values[2] = src[i_ns];
values[3] = src[i_nwse];
values[5] = src[i_ns + grid.eb_ns_x_size];
if(grid.main_x % 2) //odd
{
values[0] = 0.0;
values[1] = src[i_swne + 1];
values[2] = src[i_ns];
values[3] = src[i_nwse];
values[4] = src[i_swne];
values[5] = src[i_ns + grid.eb_ns_x_size];
values[6] = src[i_nwse + 1];
values[4] = src[i_swne + grid.eb_swne_x_size - 1];
values[6] = src[i_nwse + grid.eb_nwse_x_size + 1];
}
else //even
{
values[0] = 0.0;
values[1] = src[i_swne + grid.eb_swne_x_size];
values[2] = src[i_ns];
values[3] = src[i_nwse];
values[4] = src[i_swne];
values[5] = src[i_ns + grid.eb_ns_x_size];
values[6] = src[i_nwse + grid.eb_nwse_x_size];
values[4] = src[i_swne - 1];
values[6] = src[i_nwse + 1];
}
}
......@@ -1527,25 +1518,25 @@ inline void caWriteEdgeBuffState(CA_GRID grid, CA_EDGEBUFF_STATE_IO dst, int edg
switch(edge_number)
{
case 0: break;
case 1: dst[i_swne + 1] = value; break;
case 2: dst[i_ns] = value; break;
case 3: dst[i_nwse] = value; break;
case 4: dst[i_swne] = value; break;
case 5: dst[i_ns + grid.eb_ns_x_size] = value; break;
case 6: dst[i_nwse + 1] = value; break;
case 1: dst[i_swne] = value; break;
case 2: dst[i_ns] = value; break;
case 3: dst[i_nwse] = value; break;
case 4: dst[i_swne + grid.eb_swne_x_size - 1] = value; break;
case 5: dst[i_ns + grid.eb_ns_x_size] = value; break;
case 6: dst[i_nwse + grid.eb_nwse_x_size + 1] = value; break;
}
}
else //even
{
switch(edge_number)
{
case 0: break;
case 1: dst[i_swne + grid.eb_swne_x_size] = value; break;
case 2: dst[i_ns] = value; break;
case 3: dst[i_nwse] = value; break;
case 4: dst[i_swne] = value; break;
case 5: dst[i_ns + grid.eb_ns_x_size] = value; break;
case 6: dst[i_nwse + grid.eb_nwse_x_size] = value; break;
case 0: break;
case 1: dst[i_swne] = value; break;
case 2: dst[i_ns] = value; break;
case 3: dst[i_nwse] = value; break;
case 4: dst[i_swne - 1] = value; break;
case 5: dst[i_ns + grid.eb_ns_x_size] = value; break;
case 6: dst[i_nwse + 1] = value; break;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment