Skip to content

IMPRV: added remesh_patch function #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions @msh/msh.m
Original file line number Diff line number Diff line change
Expand Up @@ -3271,6 +3271,54 @@ function plotter(cmap,round_dec,yylabel,apply_pivot)

end

function [m_remeshed] = remesh_patch(obj, poly, efdx, const_resolution)
%REMESH_PATCH Remeshes the region inside the given polygon.
%
% Syntax:
% [m_remeshed] = remesh_patch(obj, poly, efdx, const_resolution)
%
% Inputs:
% obj - Mesh object containing the original mesh
% poly - Array of polygon vertices
% efdx - Background grid resolution (should be finer than intended min element size)
% const_resolution- Optional, uniform resolution in the patch (in meters)
%
% Outputs:
% m_remeshed - Remeshed region
%
% Usage Example:
% [m_remeshed] = remesh_patch(obj, poly, efdx) % For variable resolution
% [m_remeshed] = remesh_patch(obj, poly, efdx, 50) % For constant 50m resolution

% Check if const_resolution is specified
if nargin < 4
const_resolution = -999;
end

% Extract subdomain enclosed by the polygon
subdomain = extract_subdomain(obj, poly);

% Get polygon from subdomain
poly = get_poly(subdomain);

% Reconstruct edge function (ef) using subdomain and efdx
[ef, efx, efy] = reconstructEdgefx(subdomain, efdx, const_resolution);

% Create gridded interpolant function
fh = griddedInterpolant(efx, efy, ef);
hfun = @(p) fh(p);

% Generate new mesh for the subdomain
subdomain_new = mesh2dgen(poly, hfun);

% Extract subdomain with the hole
m_w_hole = extract_subdomain(obj, poly, "keep_inverse", 1);

% Combine the new and original subdomains
m_remeshed = plus(subdomain_new, m_w_hole, ...
'match', {'djc', 0.0, 'ds', 0, 'db', 0, 'con', 5, 'mqa', 1e-4, 'sc_maxit', 0});
end

function [ef,efx,efy]=reconstructEdgefx(obj,efdx)
% Given a msh object, reconstruct the edge function resolution
% with a resolution equal to efdx in WGS84 degrees.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Unreleased (on current HEAD of the Projection branch)
## Added

- Added new function in `msh` called `remesh_patch` to remesh within specified polygonal domains and insert back into parent mesh.
- Read and write to 2dm format.
- `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
- New stability namelist options to `Make_f15.m` fort.15 generator. https://github.com/CHLNDDEV/OceanMesh2D/pull/283
Expand Down