/* Support for solving heat equation in rectangular grid */
#include <stdbool.h>

/* Parameters */
#define CONDUCTIVITY 0.8

/* Representation of grid. */
typedef struct {
    int nrow;
    int ncol;
    double *data; // Size = (nrow+2) X (ncol+2)
    double *ndata; // Size = (nrow+2) X (ncol+2)
} grid_t;

/* Representation of boundary conditions */
typedef struct {
    int nrow;
    int ncol;
    double *northRow;    // ncol
    double *eastColumn; // nrow
    double *southRow;   // ncol
    double *westColumn; // nrow
} boundary_t;

/*
  Locate value within grid array.
  Compensate for extra values on boundary
*/
#define GINDEX(g, r, c) (((r)+1)*((g)->ncol+2)+((c)+1))


grid_t *new_grid(int nrow, int ncol);
void free_grid(grid_t *g);

boundary_t *create_boundary(int nrow, int ncol, char mode);
void free_boundary(boundary_t *bc);

void initialize_grid(grid_t *g, boundary_t *bc);
int run_grid(grid_t *g, int maxSteps, double epsilon, bool verbose);
void show_grid(grid_t *g);

int solve(int nrow, int ncol, char mode, double epsilon, int maxSteps, bool verbose);
