Makai
Graphical user interface to mesh preparation and manipulation.
Building and running the code:
$ git clone --recursive git@gitlab.com:oceanbox/makai.git
$ cd makai
$ nix-shell
$ rustup update stable
$ cargo run --release
There is also a non-gtk branch.
Later we can also compile to WebAssembly following https://github.com/emilk/eframe_template#compiling-for-the-web.
Implementation design choices
There are two parts which are programmed using async programming:
- Loading and pre-processing polygons (since this can take some time)
- Meshing, mesh refinement, and mesh relaxation (since this can take many seconds)
Using the first example (polygons), this is achieved using 2 variables:
polygons: Vec<polygon::Polygon>,
polygons_promise: Option<Promise<Result<Vec<polygon::Polygon>>>>,
It could be done with only 1:
polygons_promise: Option<Promise<Result<Vec<polygon::Polygon>>>>,
The reason why I went from 1 to 2 variables is that it makes the code for manipulating the promise simpler. In the GUI we need to manipulate polygons and mesh in many places and when the manipulation takes no time at all, it can be blocking, and it made the code simpler to work with a concrete structure instead of a "vague" promise which would need to be unpacked and error-handled at every operation.
This turned out to be a good solution when the creation takes a lot of time and can fail and the manipulation takes no time and cannot fail (so easily).
Fetching the promise and then moving the data over to the simple structure once it's fetched also makes the error handling more localized.
Input format
The code reads a file containing blocks with boundary, island, or
polygon.
boundary and island blocks contain not only x and y coordinates but also
resolution at the coastal points. polygon blocks contain only x and y
coordinates and do not define any coastal resolution. Apart from this
difference, all are just polygons.
boundary and island blocks can specify fixed edges.
The file can contain an arbitrary number of such blocks and the file does not start with a number telling how many blocks follow. This is so that we can add or remove blocks without changing the beginning of a file.
Example boundary block with 2 fixed edges, 4 vertices, and each vertex carrying a coastal resolution of 0.25:
boundary 4 2
0.0 0.0 0.25
1.0 0.0 0.25
1.0 1.0 0.25
0.0 1.0 0.25
0 1
1 2
Example island block with 0 fixed edges and 5 vertices:
island 5 0
0.1 0.1 0.25
0.3 0.1 0.25
0.3 0.3 0.25
0.1 0.3 0.25
0.2 0.2 0.25
Example file containing multiple blocks (one boundary, two islands, one polygon without any coastal resolution coefficients):
boundary 4 2
0.0 0.0 0.25
1.0 0.0 0.25
1.0 1.0 0.25
0.0 1.0 0.25
0 1
1 2
island 5 0
0.1 0.1 0.25
0.3 0.1 0.25
0.3 0.3 0.25
0.1 0.3 0.25
0.2 0.2 0.25
island 3 0
0.6 0.6 0.35
0.8 0.6 0.35
0.8 0.8 0.35
polygon 4
2.0 2.0
3.0 2.0
3.0 3.0
2.0 3.0
How to read "Norgeskyst" polygons
The "Norgeskyst.txt" file which was at times shared via DropBox can be found at https://gitlab.com/oceanbox/norgeskyst. However its format is custom and slightly different from the format that Makai/meshrefine understand.
Go to https://gitlab.com/oceanbox/norgeskyst and use
https://gitlab.com/oceanbox/norgeskyst/-/blob/main/convert.sh to generate
coast.txt (name does not matter) which will be in the correct input format
for Makai.