Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
This PR enhances mesh initialization and remeshing workflows for builds using MMG (USEMMG), including persisting the initial element-size hint through remeshing and checkpoints, and adding a new configuration knob to coarsen the initial TetGen mesh before MMG refinement.
Changes:
- Add two-stage TetGen→MMG initialization in
mesh.cxx, including propagation of region/material attributes and an optional per-node initial metric hint. - Gate allocation/interpolation/checkpointing of
init_elem_size_nbehindUSEMMG, and improve its initialization behavior. - Introduce
mesh.mmg_init_coarsening_factorto control coarse TetGen sizing for faster initialization.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| remeshing.cxx | Adjust MMG-related guards; refine init_elem_size_n initialization; update nullptr usage. |
| parameters.hpp | Add mmg_init_coarsening_factor to mesh parameters. |
| input.cxx | Declare/configure mesh.mmg_init_coarsening_factor with a default. |
| output.cxx | Write init_elem_size_n to checkpoint only under USEMMG. |
| mesh.hpp | Extend renumbering_mesh signature to accept an optional init-size hint. |
| mesh.cxx | Implement TetGen+MMG two-stage initialization and carry init_elem_size_n through renumbering. |
| fields.cxx | Stop unconditional allocation of init_elem_size_n in variable allocation. |
| dynearthsol.cxx | Allocate/initialize and checkpoint-restore init_elem_size_n (MMG-gated init). |
| brc-interpolation.cxx | Interpolate init_elem_size_n across remeshing only when USEMMG is enabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| bin_chkpt.read_array(*var.surfinfo.edvacc_surf, "dv surface acc"); | ||
| #ifdef USEMMG | ||
| bin_chkpt.read_array(*var.init_elem_size_n, "init_elem_size_n"); |
There was a problem hiding this comment.
Restart will currently fail (BinaryInput/HDF5Input exits) if the checkpoint was produced by an older build that doesn't contain the new "init_elem_size_n" dataset. Use bin_chkpt.has_array("init_elem_size_n") before reading, and provide a fallback when missing (e.g., initialize_elem_size_n(...) under USEMMG after volumes are available, or initialize to a safe default).
| bin_chkpt.read_array(*var.init_elem_size_n, "init_elem_size_n"); | |
| if (bin_chkpt.has_array("init_elem_size_n")) | |
| bin_chkpt.read_array(*var.init_elem_size_n, "init_elem_size_n"); | |
| else { | |
| for (std::size_t i = 0; i < var.init_elem_size_n->size(); ++i) | |
| (*var.init_elem_size_n)[i] = 0; | |
| } |
| double_vec cra(pregattr ? pregattr : nullptr, | ||
| pregattr ? pregattr + ce : nullptr); |
There was a problem hiding this comment.
This constructs cra using a pointer-range vector constructor with nullptr when pregattr is null. Passing nullptr iterators is undefined behavior for std::vector's range constructor. Prefer an explicit conditional: leave cra empty when pregattr==nullptr, otherwise copy [pregattr, pregattr+ce).
| double_vec cra(pregattr ? pregattr : nullptr, | |
| pregattr ? pregattr + ce : nullptr); | |
| double_vec cra; | |
| if (pregattr) | |
| cra.assign(pregattr, pregattr + ce); |
| n_regions, regattr, max_elem_size, mesh.resolution, *fine_init_metric_n); | ||
| } else { | ||
| // Uniform case: exact constant metric | ||
| const double target = std::pow(max_elem_size / sizefactor, 1.0 / NDIMS); | ||
| fine_init_metric_n->assign(nnode, target); |
There was a problem hiding this comment.
fine_init_metric_n is documented as optional, but it's dereferenced unconditionally here. If this function is ever called with fine_init_metric_n==nullptr (e.g., a caller only wants the refined mesh), this will crash. Add a nullptr guard (similar to the 2D implementation) or make the parameter non-optional.
| allocate_variables(param, var); | ||
| var.init_elem_size_n->resize(var.nnode); |
There was a problem hiding this comment.
In restart(), init_elem_size_n is resized unconditionally. In non-MMG builds this can allocate a large per-node array that is never used (and contradicts the goal of avoiding init_elem_size_n allocation when USEMMG is off). Guard this resize behind USEMMG (and only resize when you will actually read/populate the array).
| allocate_variables(param, var); | |
| var.init_elem_size_n->resize(var.nnode); | |
| allocate_variables(param, var); | |
| #ifdef USEMMG | |
| var.init_elem_size_n->resize(var.nnode); | |
| #endif |
This pull request introduces several improvements and bug fixes related to mesh initialization, remeshing, and checkpointing, particularly for builds using MMG remeshing (guarded by
USEMMG). The changes enhance the handling of theinit_elem_size_nvariable, ensure correct memory allocation and checkpointing, and add a new configuration parameter for mesh coarsening. Below are the most important changes grouped by theme:MMG Remeshing and Element Size Handling:
var.init_elem_size_nonly whenUSEMMGis enabled, preventing unnecessary memory usage and operations in non-MMG builds. (brc-interpolation.cxx,dynearthsol.cxx,fields.cxx) [1] [2] [3] [4]init_elem_size_nto avoid redundant work if already initialized, and ensured correct resizing and zero-filling during restarts and remeshing. (remeshing.cxx,dynearthsol.cxx) [1] [2] [3]init_elem_size_nunderUSEMMG, ensuring this field is correctly persisted and restored. (output.cxx,dynearthsol.cxx) [1] [2]Mesh Configuration and API Changes:
mmg_init_coarsening_factor, to control the coarsening factor for the initial TetGen+MMG mesh generation, and documented its effect on mesh quality and performance. (input.cxx,parameters.hpp) [1] [2]renumbering_meshfunction signature to accept an optionalinit_elem_size_hintparameter, improving flexibility for mesh manipulation routines. (mesh.hpp)Code Maintenance and Bug Fixes:
renumbering_meshby replacingNULLwithnullptrfor better type safety in C++. (remeshing.cxx)remeshing.cxx) [1] [2]These changes collectively improve the robustness and maintainability of the mesh handling code, especially for advanced remeshing workflows using MMG.
Close #47