Marching squares for wall-bounded and periodic boundaries.
On one hand just for fun (99%). On the other hand (1%) I wanted to extend contour in Matplotlib for periodic domains.
- C compiler
- GNU make (not essential but recommended)
- Gnuplot (not essential but recommended)
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
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 besizes[0]
)ys
y
coordinate (length of this vector should besizes[1]
)values
Two-dimensional scalar field
nclusters
Result, number of clusters
clusters
Result, all polygonal chains
Minor but non-trivial things are documented here.