         case DIM_2: radiusZ = 0; break;
     }
 
-    for (uint i = idx + idx*interactionRadius + iterx; i < xSize; i += gridOffsetx)
-    {
-        for (uint j = idy + idy*interactionRadius + itery; j < ySize; j += gridOffsety)
-        {
-            for (uint k = idz + idz*interactionRadius + iterz; k < zSize; k += gridOffsetz)
+    for (uint i = idx + idx * interactionRadius + iterx; i < xSize; i += gridOffsetx)
+    {
+        for (uint j = idy + idy * interactionRadius + itery; j < ySize; j += gridOffsety)
+        {
+            for (uint k = idz + idz * interactionRadius + iterz; k < zSize; k += gridOffsetz)
             {
                 index = gridIndex(i, j, k);
-
                 spinValue = data[index] - 1;
 
                 // Пропустить, если немагнитная частица

    int index, radiusX, radiusY, radiusZ;
    uchar spinValue;
    uint xx, yy, zz;
    double gridSpinEnergy, dist, probplus, probminus, probability;

    radiusX = radiusY = radiusZ = interactionRadius;
    switch (dimension)


double cudaMagnetization(Grid *g)
{
    kernelMagnetization<<<blocks, threads>>>(g->deviceMatrix, tempMatrix);
    double sum = 0.0;
    uint dataSize = g->xSize * g->ySize * g->zSize;
    thrust::device_ptr<double> ptr(tempMatrix);
