Skip to content

gpollo/laplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

25d71d2 · Mar 2, 2017

History

25 Commits
Feb 22, 2017
Mar 2, 2017
Feb 27, 2017
Feb 20, 2017
Feb 20, 2017
Feb 23, 2017
Feb 20, 2017

Repository files navigation

Numerical solver of Laplace's equation

This repository contains a small C code that implements a finite difference solver of Laplace's equation. It also provides a multi-threaded version of the algorithm. To define a boundary conditions, one must create a function like the one showed below.

Running

To run the code, simply clone this repository and edit the main.c file to match the desired problem.

$ git clone https://github.com/TheNiceGuy/laplace
$ mkdir -p laplace/build && cd laplace/build
$ cmake .. && make
$ ./laplace

The matrix will be written in stderr, thus you can save it to a file using simple IO redirection.

$ ./laplace 2> data.csv

A simple script is provided in the scripts folder that can plot the data using matplotlib. The following command will create an image file.

$ ./graph.py data.csv

The following command will show the data directly.

$ ./graph.py data.csv --show

Examples

struct bound* boundaries(struct bound* bound, struct rect* pos) {
    double x = pos->x;
    double y = pos->y;

    if(x < 16 && y <= 0) {
        bound->value =  150;
        bound->cond  = DIRICHLET;
    } else if(48 <= x && x <= 64 && y <= 0) {
        bound->value = -150;
        bound->cond  = DIRICHLET;
    } else if(16 <= x && x< 48 && (y < 12 || y >= 36)) {
        bound->value = 0;
        bound->cond  = NEUMANN;
    } else {
        bound->value = 0;
        bound->cond  = NONE;
    }

    return bound;
}

JFET

struct bound* boundaries(struct bound* bound, struct rect* pos) {
    double x = pos->x;
    double y = pos->y;

    if(x < 16 && y <= 0) {
        bound->value =  150;
        bound->cond  = DIRICHLET;
    } else if(48 <= x && x <= 64 && y <= 0) {
        bound->value = -150;
        bound->cond  = DIRICHLET;
    } else if(16 <= x && x< 48 && (y < 12 || y >= 36)) {
        bound->value = 0;
        bound->cond  = NEUMANN;
    } else if(10 <= x && x < 20 && 25 <= y && y < 30) {
        bound->value = 0;
        bound->cond  = NEUMANN;
    } else if(30 <= x && x < 55 && 15 <= y && y < 18) {
        bound->value = 60;
        bound->cond  = DIRICHLET;
    } else {
        bound->value = 0;
        bound->cond  = NONE;
    }

    return bound;
}

JFET with holes

About

Numerical solver of the 2D Laplace's equation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published