ITADN

Cut Meshes: Bug fix for scaling and sampling

#202Pull Requestcgt3 创建于 2025-08-15
C
cgt3commented
## Summary of Issues: 1. The shifting and scaling factors for physical frame bases are not calculated correctly. 2. Point sampling in cut elements is extremely inefficient and can cause the program to crash. ## Issues: ### 1) Shifting and Scaling Factor Computation **Offending functions:** 1. ```PhysicalFrame``` constructors (lns:27-46) in ```src/physical_frame_basis.jl``` 2. ```construct_physical_frame_elements``` in ```src/cut_cell_meshes.jl``` **Current functionality:** The ```PhysicalFrame``` constructors generate shifting and scaling factors to map points on the physical cut element into the reference domain. The shifting is calculated such that the centroid of the cut element (as calculated as the average of points sampled on the cut element's boundary) is mapped to the origin of the reference element and the scaling factor is calculated s.t. the bounding volume of the scaled cut element has sides of length 2 (same as the reference element). **The Issue:** The shifting and scaling factors are not fully independent of one another: once one is chosen, the other is constrained. You cannot both map the cut element's centroid to the reference element's origin AND have the cut element's bounding volume scaled to a 2 x 2 box. Doing both results in the shifted/scaled cut element not being fully encased in the reference domain; i.e., some mapped points will not be in the reference domain. Additionally, a denser sampling of points on the boundary is needed to accurately calculate the shifting/scaling factors: currently only the cut element's stop points/corners are being used, which will yield poor shifting/scaling factors for cut elements with outward bulging cut faces. **Proposed Corrections:** 1. **Point sampling:** We supplement the cut element's boundary's stop points with a fine sampling of points on a cut element's boundaries in ```construct_physical_frame_elements``` in ```src/cut_cell_meshes.jl```. These points are then used to calculate the shifting and scaling factors. 4. **Shifting and scaling factors:** The calculation of the shifting and scaling factors must be changed. There are two natural approaches: 1. **centroid -> origin**: compute the shifting factor as before so that the centroid of the cut element is mapped ot the reference domain's origin, but change the scaling factor so that all point in the cut element are mapped to the reference element. The shifting/scaling for this approach are given in the function ```get_shifting_and_scaling_cg``` in ```src/physical_frame_basis.jl```. **This is the change used in this pull request as it is consistent with our cut DG papers**. 2. **maximize the size of the mapped cut element:** compute the scaling as before so that the cut element's bounding volume is mapped to a 2 x 2 bounding volume, but change the shifting factors so that the 2 x 2 box is contained in the reference domain. This option has the benefit of maximizing the size of the mapped cut element and is implemented in the function ```get_shifting_and_scaling_maxfill``` in ```src/physical_frame_basis.jl```. ### 2) Cut Element Point Sampling **Offending Functions:** 1. ```map_nodes_to_background_cell``` in ```src/physical_frame_basis.jl``` 2. ```generate_sampling_points``` in ```src/cut_cell_meshes.jl``` **Current functionality:** The function ```generate_sampling_points``` uses ```map_nodes_to_background_cell``` to map a uniform grid of points on the reference element to a cut element's Cartesian background element *using the shifting/scaling indicated by the Cartesian background element*. ```generate_sampling_points``` then tests the mapped points against the cut element's boundary via ```is_contained``` and discards points outside the cut element. **The Issue:** When cut elements are extremely small, very few of the mapped points actually reside in the cut element, triggering re-sampling using a finer grid. For sufficiently small cut elements, re-sampling is triggered so many times that sampling may take several minutes to run and in some cases the grid becomes so fine that Julia runs out of memory and crashes. **Proposed Correction:** An easy fix here is to map points on the reference element to the **bounding volume** of the cut element instead of the Cartesian background element. The shifting and scaling factors used in the construction of the physical frame basis on every cut element define such a bounding volume; these should be used in place of mapping to the Cartesian background element. This new mapping results in a a good number of sampling points within the cut element and is given in the function ```map_nodes_to_cutcell_boundingbox``` in ```src/physical_frame_basis.jl```. It is much more robust and has worked on cut elements with volume ratios as small as 1e-10 and greatly improved the conditioning of the moment-fitting based cut quadrature rules. It is still fallible, but the cases where it fails are harder to trigger; see the appendix of [https://doi.org/10.1016/j.jcp.2024.113528](url) for information on these cases.
合并状态:未合并 关闭于 2025-08-16 3 条评论