2#include <wmtk/OptimizerParameters.h>
3#include <nlohmann/json.hpp>
4#include <wmtk/Types.hpp>
5#include <wmtk/components/simwild/expression_parser/Expression.hpp>
7using ExpressionPtr = wmtk::components::simwild::expression_parser::ExpressionPtr;
9namespace wmtk::components::topological_offset {
25 ExpressionPtr offset_selection;
26 std::set<std::string> offset_output_tag;
27 std::set<std::string> protected_tags;
30 double target_distance;
31 double target_distance_rel;
35 bool throw_on_nonconvergence;
45 double envelope_size = -1.0;
46 double envelope_size_rel = 1e-3;
52 double offset_dhat_factor;
70 double front_conv_rel;
78 double front_conv_frac()
const {
return front_conv / std::max(target_distance, 1e-16); }
85 bool offset_collapse_veto =
true, offset_swap_veto =
true;
86 bool offset_front_smooth_veto =
false;
87 bool offset_collapse_changed_cells =
true;
146 int stencil_order = 1;
164 bool sorted_marching;
181 int init_optimize_stencil_order = -1;
309 std::string output_path;
314 int phi_grid_resolution;
324 double offset_envelope = -1.;
325 double offset_envelope_rel = -1.;
333 double min_edge_length;
334 double min_edge_length_rel;
338 double min_sizing_scalar;
339 double max_sizing_scalar;
343 double sizing_gradation;
360 for (
const std::string& tag : json_params[
"offset_output_tags"]) {
361 if (tag ==
"ambient") {
363 "'ambient' tag cannot be given explicitly to offset_output_tags, ignoring. To "
364 "set offset to 'ambient', pass offset_output_tags=[].");
367 offset_output_tag.insert(tag);
369 for (
const std::string& tag : json_params[
"protected_tags"]) {
370 if (tag ==
"ambient") {
371 logger().warn(
"'ambient' tag cannot be protected, ignoring.");
374 protected_tags.insert(tag);
376 offset_in = json_params[
"offset_in"];
377 offset_out = json_params[
"offset_out"];
378 target_distance = json_params[
"target_distance"];
379 target_distance_rel = json_params[
"target_distance_rel"];
380 throw_on_nonconvergence = json_params[
"throw_on_nonconvergence"];
382 envelope_size = json_params[
"envelope_size"];
383 envelope_size_rel = json_params[
"envelope_size_rel"];
384 offset_dhat_factor = json_params[
"offset_dhat_factor"];
386 front_conv = json_params[
"front_conv"];
387 front_conv_rel = json_params[
"front_conv_rel"];
388 stencil_order = json_params[
"stencil_order"];
389 stencil_type = json_params[
"EXPERIMENTAL_stencil_type"];
392 "EXPERIMENTAL_stencil_type is \"subdivision\", \"interior\" or \"fem\", not "
396 if (
stencil_type !=
"subdivision" && stencil_order < 1) {
398 "EXPERIMENTAL_stencil_type \"{}\" needs stencil_order >= 1, not {}",
404 sorted_marching = json_params[
"sorted_marching"];
417 "EXPERIMENTAL_band_volume_rule is \"corner_bound\", \"exact\", \"front_flux\", "
418 "\"exact_swept\" or \"surface\", not \"{}\"",
425 "EXPERIMENTAL_split_energy_gate compares the cells' energy, which under "
426 "EXPERIMENTAL_band_volume_rule \"surface\" has no offset term: leave it out");
429 settle_test = json_params[
"EXPERIMENTAL_settle_test"];
432 "EXPERIMENTAL_settle_test is \"stall\" or \"bar\", not \"{}\"",
437 "EXPERIMENTAL_settle_test \"{}\" is read only under "
438 "EXPERIMENTAL_band_volume_rule \"surface\" (this config has \"{}\"): leave it "
445 "settle_stall_eps ({}) is read only by EXPERIMENTAL_settle_test \"stall\": leave "
446 "it out under \"bar\"",
451 "settle_stall_eps ({}) is read only under EXPERIMENTAL_band_volume_rule "
452 "\"surface\" (this config has \"{}\"): leave it out",
459 log_and_throw_error(
"EXPERIMENTAL_gap_refinement needs EXPERIMENTAL_settle_refinement");
461 damping = json_params[
"EXPERIMENTAL_damping"];
464 log_and_throw_error(
"EXPERIMENTAL_damping_factor must be > 0, not {}",
damping_factor);
469 "EXPERIMENTAL_damping_factor {} needs EXPERIMENTAL_damping true",
480 "growth_mode is \"none\", \"linear\", \"smart\" or \"individual_op_reject\", "
487 "linear_growth_steps {} needs growth_mode \"linear\", not \"{}\"",
494 "smart_growth_attempts {} / smart_growth_max_fails {} need growth_mode \"smart\", "
504 "growth_mode \"{}\" needs construction_mode \"max_marchable_fallback\", not "
505 "\"{}\": growth starts at the distance the march traced the front to, and only "
506 "that mode traces below target_distance",
512 "growth_mode \"{}\" and init_optimize both decide the loops that follow a march "
513 "below target_distance: set only one of them",
518 settle_mark = json_params[
"EXPERIMENTAL_settle_mark"];
523 "EXPERIMENTAL_settle_mark is \"max\", \"rms\", \"vertex\", \"vertex_edge\", "
524 "\"vertex_split\" or \"stencil\", not \"{}\"",
527 output_path = json_params[
"output"];
528 save_vtu = json_params[
"save_vtu"];
529 phi_grid_resolution = json_params[
"phi_grid_resolution"];
531 num_threads = json_params[
"num_threads"];
534 min_edge_length = json_params[
"min_edge_length"];
535 min_edge_length_rel = json_params[
"min_edge_length_rel"];
537 min_sizing_scalar = json_params[
"min_sizing_scalar"];
538 max_sizing_scalar = json_params[
"max_sizing_scalar"];
539 sizing_gradation = json_params[
"sizing_gradation"];
544 debug_output = json_params[
"DEBUG_output"];
552 "DEBUG_stencil writes a file beside every debug frame: it needs DEBUG_output (or "
553 "DEBUG_remote_output)");
555 lr = json_params[
"length_rel"];
556 l = json_params[
"length"];
557 stop_energy = json_params[
"stop_energy"];
559 interleaved_smoothing = json_params[
"interleaved_smoothing"];
560 interleaved_smoothing_passes = json_params[
"interleaved_smoothing_passes"];
578 "EXPERIMENTAL_coarsen_guard is \"bar\" or \"no_rise\", not \"{}\"",
583 "EXPERIMENTAL_coarsen_guard \"{}\" is read only with coarsen_pass true: set it, or "
584 "leave the guard out",
587 stuck_refine_stall_eps = json_params[
"stuck_refine_stall_eps"];
588 stuck_refine_cooldown = json_params[
"stuck_refine_cooldown"];
589 stuck_refine_num_worst = json_params[
"stuck_refine_num_worst"];
590 stuck_refine_rings = json_params[
"stuck_refine_rings"];
591 stuck_refine_factor = json_params[
"stuck_refine_factor"];
592 stuck_refine_min_scalar = json_params[
"stuck_refine_min_scalar"];
593 stuck_refine_gradation = json_params[
"stuck_refine_gradation"];
594 stuck_refine_force_split = json_params[
"stuck_refine_force_split"];
605 "EXPERIMENTAL_label_cleanup is \"off\", \"one_sided\", \"one_sided_tips\", "
606 "\"one_sided_at_target\" or \"energy_decrease\", not \"{}\"",
612 "EXPERIMENTAL_label_cleanup \"energy_decrease\" needs "
613 "EXPERIMENTAL_band_volume_rule \"surface\" (this config has \"{}\")",
624 "EXPERIMENTAL_label_cleanup \"{}\" reads the distance through the exact band "
625 "integral, which EXPERIMENTAL_band_volume_rule \"corner_bound\" does not build: "
627 "the clean-up \"off\", or another rule",
635 "EXPERIMENTAL_label_cleanup \"{}\" needs EXPERIMENTAL_front_pocket_split true: it "
636 "runs right before the condition-1 splits that precede the first smoothing pass "
637 "of each operation group",
644 "EXPERIMENTAL_settle_mark \"vertex_split\" needs EXPERIMENTAL_front_pocket_split "
645 "true: its splits are made right before the first smoothing pass of the next turn");
650 w_amips = json_params[
"w_amips"];
655 perform_sanity_checks = json_params[
"perform_sanity_checks"];
658 void init(
const VectorXd& min_,
const VectorXd& max_)
667 preserve_topology =
true;
673 if (target_distance > 0) {
674 target_distance_rel = target_distance / diag_l;
676 target_distance = target_distance_rel * diag_l;
681 if (envelope_size > 0) {
682 envelope_size_rel = envelope_size / diag_l;
684 envelope_size = envelope_size_rel * diag_l;
690 if (front_conv > 0) {
691 front_conv_rel = front_conv / target_distance;
693 front_conv = front_conv_rel * target_distance;
700 if (front_conv > target_distance) {
702 "front_conv {} must be <= target_distance {}: the convergence epsilon cannot be "
703 "coarser than the offset distance it measures, or every front face reads as "
704 "resolved from the first turn",
711 offset_envelope = envelope_size;
712 offset_envelope_rel = envelope_size_rel;
716 if (min_edge_length_rel < 0) {
720 min_edge_length_rel = std::max(envelope_size / std::max(target_distance, 1e-16), 1e-12);
722 if (min_edge_length < 0) {
723 min_edge_length = min_edge_length_rel * target_distance;
725 min_edge_length_rel = min_edge_length / std::max(target_distance, 1e-16);
The parameters tetwild, triwild and simwild all share.
Definition OptimizerParameters.h:29
int project_line_search_nested_steps
Partial-projection bisections tried after it gives up; 0 disables that pass.
Definition OptimizerParameters.h:178
double w_amips
Definition OptimizerParameters.h:172
std::string smoothing_mode
"projected" or "exact"; see SmoothVertexOptions::SmoothingMode.
Definition OptimizerParameters.h:174
bool coarsen_pass
Definition OptimizerParameters.h:238
int coarsen_global_smoothing_passes
Definition OptimizerParameters.h:303
int coarsen_max_rounds
Definition OptimizerParameters.h:327
void init_lengths_from_diagonal(const double diag)
Derive the edge-length and envelope quantities from the bounding-box diagonal.
Definition OptimizerParameters.h:357
bool coarsen_unbounded
Definition OptimizerParameters.h:262
int split_high_valence_threshold
Definition OptimizerParameters.h:72
int coarsen_local_smoothing_passes
Definition OptimizerParameters.h:280
int project_line_search_steps
Bisections tried before the projected search gives up. See SmoothVertexOptions.
Definition OptimizerParameters.h:176
bool colored_smoothing
Definition OptimizerParameters.h:201
int coarsen_smooth_ring
Definition OptimizerParameters.h:296
int num_smoothing_passes
Number and placement of smoothing passes in the shared Wild optimization driver.
Definition OptimizerParameters.h:188
What the offset needs on top of the parameters every wmtk optimizer shares.
Definition Parameters.h:24
std::string label_cleanup
Definition Parameters.h:116
bool gap_refinement
Definition Parameters.h:239
bool allow_mult_comp
Definition Parameters.h:290
bool split_energy_gate
Definition Parameters.h:193
bool damping
Definition Parameters.h:245
bool use_rest_pose
Definition Parameters.h:124
bool pre_smooth
Definition Parameters.h:351
double foldover_angle
Definition Parameters.h:279
int repulsion_rounds
Definition Parameters.h:190
bool optimize_construction
Definition Parameters.h:253
int smart_growth_attempts
growth_mode "smart": the turns an attempt gets to converge. At least 1 (the spec's min).
Definition Parameters.h:270
double offset_amips_weight
Definition Parameters.h:91
std::string offset_field
"smooth" (Phi level set) or "euclidean" (exact distance)
Definition Parameters.h:53
double front_conv_frac() const
Definition Parameters.h:78
int max_iterations
Definition Parameters.h:319
bool sizing_collapse_min
Definition Parameters.h:120
int max_rounds
Definition Parameters.h:127
int smart_growth_max_fails
Definition Parameters.h:273
std::string growth_mode
Definition Parameters.h:265
bool optimize_offset
Definition Parameters.h:38
bool debug_crossings
Log-only: per pass, the front vertices whose ring measure crosses the bar (see the spec).
Definition Parameters.h:93
std::string settle_mark
Definition Parameters.h:308
bool debug_stencil
Definition Parameters.h:287
bool init_optimize
Definition Parameters.h:177
std::string stencil_type
Definition Parameters.h:154
int linear_growth_steps
Definition Parameters.h:268
double damping_factor
Definition Parameters.h:248
bool settle_refinement
Definition Parameters.h:233
std::string front_measure
Definition Parameters.h:163
bool front_spanned_split
Definition Parameters.h:99
double settle_stall_eps
Definition Parameters.h:218
std::string sizing_gradation_mode
Definition Parameters.h:348
bool debug_remote_output
Definition Parameters.h:284
int repulsion_smoothing_passes
Definition Parameters.h:186
bool front_pocket_split
Definition Parameters.h:96
std::string coarsen_guard
Definition Parameters.h:110
std::string construction_mode
Definition Parameters.h:172
double sphere_trace_target_rel_tol
Definition Parameters.h:173
bool exit_no_folds
Definition Parameters.h:102
std::string settle_test
Definition Parameters.h:223
std::string band_volume_rule
Definition Parameters.h:213
bool save_offset_correspondence
Definition Parameters.h:167