Frame: add adaptive mesh refinement

This commit is contained in:
wyj committed 2026-08-28 23:06:53 -04:00
1 parent 4aa5f6666a
commit 48dcf4e707
7 files changed
+768 -72

No files matched your search

+32
View File
@@ -160,6 +160,38 @@ int main(void) {
goto done;
}
frame_lens_mesh_destroy(&fine_mesh);
/* Refinement probes are temporary until their generation is complete. A
* shared diagonal probe must produce one stable midpoint and conforming
* children only after its endpoint has been installed. */
FrameLensMesh adaptive_mesh = {0};
const RefinementConfig refine = {.max_level = 1,
.angle_absolute_rad = 1e-4,
.angle_relative = 1e-4,
.min_edge_pixels = 1.0,
.min_area_pixels2 = 1.0};
if (frame_lens_mesh_build_coarse(&adaptive_mesh, width, height, 100, 30.0))
goto done;
for (size_t i = 0; i < adaptive_mesh.vertex_count; ++i) {
adaptive_mesh.vertices[i].traced = 1;
adaptive_mesh.vertices[i].status = RAY_ENDPOINT_ESCAPED;
adaptive_mesh.vertices[i].n_infinity[0] = 1.0;
}
if (frame_lens_mesh_prepare_generation(&adaptive_mesh, &refine) != 1) {
fputs("adaptive shared-edge probe setup regression failed\n", stderr);
frame_lens_mesh_destroy(&adaptive_mesh);
goto done;
}
const RayEndpoint bent_probe = {.n_infinity = {0.0, 1.0, 0.0},
.frequency_ratio = 1.0,
.status = RAY_ENDPOINT_ESCAPED};
if (frame_lens_mesh_install_sample(&adaptive_mesh, 0, &bent_probe) ||
frame_lens_mesh_finish_generation(&adaptive_mesh, &refine) != 1 ||
adaptive_mesh.vertex_count != 5 || adaptive_mesh.triangle_count != 4) {
fputs("adaptive shared-edge split regression failed\n", stderr);
frame_lens_mesh_destroy(&adaptive_mesh);
goto done;
}
frame_lens_mesh_destroy(&adaptive_mesh);
result = 0;
done:
frame_lens_mesh_destroy(&mesh);
+20
View File
@@ -1,4 +1,5 @@
#include "geodesic.h"
#include "frame.h"
#include <math.h>
#include <stdio.h>
@@ -56,6 +57,25 @@ int main(void) {
central.status, inside_shadow.status, outside_shadow.status);
goto done;
}
/* A coarse field covering the shadow must genuinely refine: its initial
* capture/escape-discontinuous triangles are a separate trigger from the
* smooth direction-error criterion. */
FrameLensMesh mesh = {0};
const RefinementConfig refinement = {.max_level = 1,
.angle_absolute_rad = 1e-5,
.angle_relative = 1e-5,
.min_edge_pixels = 1.0,
.min_area_pixels2 = 1.0};
if (frame_lens_mesh_build_coarse(&mesh, 48, 48, 24, 40.0) ||
frame_lens_mesh_trace(&mesh, &spacetime, &observer, &trace) ||
frame_lens_mesh_refine(&mesh, &spacetime, &observer, &trace,
&refinement) ||
mesh.vertex_count <= 9 || mesh.triangle_count <= 8) {
fputs("Schwarzschild adaptive-refinement regression failed\n", stderr);
frame_lens_mesh_destroy(&mesh);
goto done;
}
frame_lens_mesh_destroy(&mesh);
result = 0;
done:
spacetime_destroy(&spacetime);