Commit Graph

17 Commits

Author SHA1 Message Date
Aaron Fenyes
d223df869c Stop Assembly::realize from reacting to itself
Previously, `realize` both tracked and updated the element vectors, so
calling it in a reactive context could start a feedback loop.
2024-11-12 23:33:25 -08:00
Aaron Fenyes
b94280c456 Test representation validity in realization effect 2024-11-12 23:33:25 -08:00
Aaron Fenyes
92b91df435 Use tabular numbers for element vectors 2024-11-12 23:33:25 -08:00
Aaron Fenyes
33dd5dbe82 Make element vectors reactive 2024-11-12 23:33:25 -08:00
Aaron Fenyes
037a0c376f Add an element constructor 2024-11-12 23:33:25 -08:00
Aaron Fenyes
ec1911b889 Simplify memos 2024-11-12 23:33:25 -08:00
Aaron Fenyes
ce9b114dd6 Render constraint lists dynamically 2024-11-12 23:33:25 -08:00
Aaron Fenyes
cc126fc527 Correct typo in comment 2024-11-12 23:33:25 -08:00
Aaron Fenyes
70978c640b Include vector representation in element diff key 2024-11-12 23:33:25 -08:00
Aaron Fenyes
db0a8c2da8 Round element vectors to three decimal places 2024-11-12 23:33:25 -08:00
Aaron Fenyes
4ecb39e73a Specify fonts
This should help the interface look more consistent across platforms.
The font choices are just placeholders: consistency is the main goal.
2024-11-12 23:33:25 -08:00
Aaron Fenyes
7361f1a721 Flag constraints with invalid input 2024-11-12 23:33:25 -08:00
Aaron Fenyes
f2f73b31cf Update title and authors 2024-11-12 23:33:25 -08:00
Aaron Fenyes
dcf5764993 Factor out element outline item 2024-11-12 23:33:25 -08:00
Aaron Fenyes
d526ac9f1f Factor out constraint outline item 2024-11-12 23:33:25 -08:00
707618cdd3 Integrate engine into application prototype (#15)
Port the engine prototype to Rust, integrate it into the application prototype, and use it to enforce the constraints.

### Features

To see the engine in action:

1. Add a constraint by shift-clicking to select two spheres in the outline view and then hitting the 🔗 button
2. Click a summary arrow to see the outline item for the new constraint
2. Set the constraint's Lorentz product by entering a value in the text field at the right end of the outline item
   * *The display should update as soon as you press* Enter *or focus away from the text field*

The checkbox at the left end of a constraint outline item controls whether the constraint is active. Activating a constraint triggers a solution update. (Deactivating a constraint doesn't, since the remaining active constraints are still satisfied.)

### Precision

The Julia prototype of the engine uses a generic scalar type, so you can pass in any type the linear algebra functions are implemented for. The examples use the [adjustable-precision](https://docs.julialang.org/en/v1/base/numbers/#Base.MPFR.setprecision) `BigFloat` type.

In the Rust port of the engine, the scalar type is currently fixed at `f64`. Switching to generic scalars shouldn't be too hard, but I haven't looked into [which other types](https://www.nalgebra.org/docs/user_guide/generic_programming) the linear algebra functions are implemented for.

### Testing

To confirm quantitatively that the Rust port of the engine is working, you can go to the `app-proto` folder and:

* Run some automated tests by calling `cargo test`.
* Inspect the optimization process in a few examples calling the `run-examples` script. The first example that prints is the same as the Irisawa hexlet example from the engine prototype. If you go into `engine-proto/gram-test`, launch Julia, and then

  ```
  include("irisawa-hexlet.jl")
  for (step, scaled_loss) in enumerate(history_alt.scaled_loss)
    println(rpad(step-1, 4), " | ", scaled_loss)
  end
  ```

  you should see that it prints basically the same loss history until the last few steps, when the lower default precision of the Rust engine really starts to show.

### A small engine revision

The Rust port of the engine improves on the Julia prototype in one part of the constraint-solving routine: projecting the Hessian onto the subspace where the frozen entries stay constant. The Julia prototype does this by removing the rows and columns of the Hessian that correspond to the frozen entries, finding the Newton step from the resulting "compressed" Hessian, and then adding zero entries to the Newton step in the appropriate places. The Rust port instead replaces each frozen row and column with its corresponding standard unit vector, avoiding the finicky compressing and decompressing steps.

To confirm that this version of the constraint-solving routine works the same as the original, I implemented it in Julia as `realize_gram_alt_proj`. The solutions we get from this routine match the ones we get from the original `realize_gram` to very high precision, and in the simplest examples (`sphere-in-tetrahedron.jl` and `tetrahedron-radius-ratio.jl`), the descent paths also match to very high precision. In a more complicated example (`irisawa-hexlet.jl`), the descent paths diverge about a quarter of the way into the search, even though they end up in the same place.

Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo>
Reviewed-on: #15
Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net>
Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
2024-11-12 00:46:16 +00:00
86fa682b31 feat: Application prototype (#14)
Creates a prototype user interface for dyna3 in the `app-proto` folder. The interface is dynamically constructed using [Sycamore](https://sycamore.dev).

The prototype includes:

  * An application state model (the `AppState` type)
    * A constraint problem model (the `Assembly` type), used in the application state
  * Two views
    * A 3D rendering of the assembly (the `Display` component)
    * A list of elements and constraints (the `Outline` component)

The following features confirm that the views can reflect and send input to the model:

  * You can select elements by clicking and shift-clicking them in the outline. The selected elements are highlighted in the display.
  * You can add elements using a button above the outline. The new elements appear in the display.

Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo>
Reviewed-on: #14
Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net>
Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
2024-10-21 23:38:27 +00:00