Skip to content

NaokiHori/MarchingSquares

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Marching Squares

License LastCommit CI Documentation

https://github.com/NaokiHori/MarchingSquares/blob/main/.github/thumbnail.png

Overview

Marching squares for wall-bounded and periodic boundaries.

Motivation

On one hand just for fun (99%). On the other hand (1%) I wanted to extend contour in Matplotlib for periodic domains.

Dependency

  • C compiler
  • GNU make (not essential but recommended)
  • Gnuplot (not essential but recommended)

Quick start

Sample dataset is attached (in data directory) for stand-alone execution:

$ make
$ ./a.out

Result is written to clusters.dat, which is an ASCII file containing coordinates of each polygonal chain. They can be visualised by Gnuplot, e.g.,

$ plot 'clusters.dat' u 1:2 w lp

API

The main function of this library is make_clusters, which is declared as

int make_clusters(
    const bool periods[2],
    const double lengths[2],
    const size_t sizes[2],
    const double threshold,
    const double * restrict xs,
    const double * restrict ys,
    const double * restrict values,
    size_t * restrict nclusters,
    cluster_t *** restrict clusters
);

Parameters:

  • periods

    Boundary condition of two directions, periodic (true) or not (false)

  • lengths

    Physical sizes

  • sizes

    Number of grid points

  • threshold

    Threshold to draw contour lines

  • xs

    x coordinate (length of this vector should be sizes[0])

  • ys

    y coordinate (length of this vector should be sizes[1])

  • values

    Two-dimensional scalar field

  • nclusters

    Result, number of clusters

  • clusters

    Result, all polygonal chains

Documentation

Minor but non-trivial things are documented here.