code: public double[] gridToGridArray(double[][][] grid) {
          if (grid == null) {
              grid = this.grid;
          }
          gridArray = new double[dim[0] * dim[1] * dim[2] + 3];
          int dimCounter = 0;
          for (int z = 0; z < grid[0][0].length; z++) {
              for (int y = 0; y < grid[0].length; y++) {
                  for (int x = 0; x < grid.length; x++) {
                      gridArray[dimCounter] = grid[x][y][z];
                      dimCounter++;
                  }
              }
          }
          return gridArray;
      }
docs: Method transforms the grid to an array.