Skip to content

Commit 3fa9741

Browse files
Keith Robertsrecovery
andauthored
IMPRV: added remesh_patch function (#300)
Co-authored-by: Keith Roberts <[email protected]>
1 parent 3221b94 commit 3fa9741

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

@msh/msh.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,6 +3271,54 @@ function plotter(cmap,round_dec,yylabel,apply_pivot)
32713271

32723272
end
32733273

3274+
function [m_remeshed] = remesh_patch(obj, poly, efdx, const_resolution)
3275+
%REMESH_PATCH Remeshes the region inside the given polygon.
3276+
%
3277+
% Syntax:
3278+
% [m_remeshed] = remesh_patch(obj, poly, efdx, const_resolution)
3279+
%
3280+
% Inputs:
3281+
% obj - Mesh object containing the original mesh
3282+
% poly - Array of polygon vertices
3283+
% efdx - Background grid resolution (should be finer than intended min element size)
3284+
% const_resolution- Optional, uniform resolution in the patch (in meters)
3285+
%
3286+
% Outputs:
3287+
% m_remeshed - Remeshed region
3288+
%
3289+
% Usage Example:
3290+
% [m_remeshed] = remesh_patch(obj, poly, efdx) % For variable resolution
3291+
% [m_remeshed] = remesh_patch(obj, poly, efdx, 50) % For constant 50m resolution
3292+
3293+
% Check if const_resolution is specified
3294+
if nargin < 4
3295+
const_resolution = -999;
3296+
end
3297+
3298+
% Extract subdomain enclosed by the polygon
3299+
subdomain = extract_subdomain(obj, poly);
3300+
3301+
% Get polygon from subdomain
3302+
poly = get_poly(subdomain);
3303+
3304+
% Reconstruct edge function (ef) using subdomain and efdx
3305+
[ef, efx, efy] = reconstructEdgefx(subdomain, efdx, const_resolution);
3306+
3307+
% Create gridded interpolant function
3308+
fh = griddedInterpolant(efx, efy, ef);
3309+
hfun = @(p) fh(p);
3310+
3311+
% Generate new mesh for the subdomain
3312+
subdomain_new = mesh2dgen(poly, hfun);
3313+
3314+
% Extract subdomain with the hole
3315+
m_w_hole = extract_subdomain(obj, poly, "keep_inverse", 1);
3316+
3317+
% Combine the new and original subdomains
3318+
m_remeshed = plus(subdomain_new, m_w_hole, ...
3319+
'match', {'djc', 0.0, 'ds', 0, 'db', 0, 'con', 5, 'mqa', 1e-4, 'sc_maxit', 0});
3320+
end
3321+
32743322
function [ef,efx,efy]=reconstructEdgefx(obj,efdx)
32753323
% Given a msh object, reconstruct the edge function resolution
32763324
% with a resolution equal to efdx in WGS84 degrees.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
157157

158158
### Unreleased (on current HEAD of the Projection branch)
159159
## Added
160+
161+
- Added new function in `msh` called `remesh_patch` to remesh within specified polygonal domains and insert back into parent mesh.
160162
- Read and write to 2dm format.
161163
- `namelist` and `RSTIMNC` input arguments for `Make_f15.m` fort.15 generator. updated the help message for all input argumebts to `Make_f15`. https://github.com/CHLNDDEV/OceanMesh2D/pull/283
162164
- New stability namelist options to `Make_f15.m` fort.15 generator. https://github.com/CHLNDDEV/OceanMesh2D/pull/283

0 commit comments

Comments
 (0)