Skip to content

Commit 069cbc9

Browse files
committed
Some fixes for the examples
- Now all examples include the makens function and the interp function at the end (except for the NZ example which doesn't include bathy) - Other various fixes to ensure everything works and plots smoothly and is clean
1 parent 40eb95e commit 069cbc9

File tree

10 files changed

+90
-49
lines changed

10 files changed

+90
-49
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
m_map/
22
datasets/
33
fort.*
4-
./*.mat
4+
/*.mat

@meshgen/meshgen.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
obj.bbox(1,2) obj.bbox(2,1); ...
308308
obj.bbox(1,1) obj.bbox(2,1); NaN NaN];
309309
end
310-
if any(obj.h0==0), error('h0 was not correctly specified!'), end;
310+
if any(obj.h0==0), error('h0 was not correctly specified!'), end
311311
if isempty(obj.outer), error('no outer boundary specified!'), end
312312
if isempty(obj.bbox), error('no bounding box specified!'), end
313313
obj.fd = @dpoly; % <-default distance fx accepts p and pv (outer polygon).
@@ -681,6 +681,13 @@
681681
% Perform the direct smoothing
682682
[obj.grd.p,obj.grd.t] = direct_smoother_lur(obj.grd.p,...
683683
obj.grd.t,obj.pfix,obj.nscreen);
684+
tq = gettrimeshquan( obj.grd.p, obj.grd.t);
685+
if min(tq.qm) < 0
686+
% Need to clean it again
687+
disp('Overlapping elements due to smoother, cleaning again')
688+
obj.grd = Make_Mesh_Boundaries_Traversable(...
689+
obj.grd,obj.dj_cutoff,obj.nscreen);
690+
end
684691
end
685692

686693
% Checking and displaying element quality

@msh/msh.m

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function write(obj,fname,type)
203203
end
204204
case('b')
205205
figure;
206-
cmap = cmocean('deep');
206+
cmap = cmocean('deep',numticks-1);
207207
if logaxis
208208
q = log10(max(1,abs(obj.b))); % plot on log scale
209209
else
@@ -215,9 +215,9 @@ function write(obj,fname,type)
215215
trisurf(obj.t,obj.p(:,1),obj.p(:,2),q);
216216
view(2); shading interp;
217217
end
218-
cmocean('deep',numticks-1); cb = colorbar;
218+
cb = colorbar;
219219
if logaxis
220-
desiredTicks = round(10.^(linspace(min(q),max(q),numticks)));
220+
desiredTicks = round(10.^(linspace(min(q),max(q),numticks)),1);
221221
caxis([log10(min(desiredTicks)) log10(max(desiredTicks))]);
222222
cb.Ticks = log10(desiredTicks);
223223
for i = 1 : length(desiredTicks)
@@ -508,6 +508,10 @@ function write(obj,fname,type)
508508
if nargin < 2
509509
error('Needs type: one of auto, islands or outer')
510510
end
511+
trim = 0;
512+
if strcmp(type(max(1,end-3):end),'trim')
513+
type = type(1:end-4); trim = 1;
514+
end
511515
switch type
512516
case('auto')
513517
if ~isa(dir,'geodata')
@@ -520,11 +524,7 @@ function write(obj,fname,type)
520524
[~,poly_idx] = extdom_polygon(etbv,obj.p,1);
521525

522526
% Get geodata outer and mainland polygons
523-
outer = [gdat.outer(~isnan(gdat.outer(:,1)),:);
524-
gdat.inner(~isnan(gdat.inner(:,1)),:)];
525-
main = [gdat.mainland(~isnan(gdat.mainland(:,1)),:);
526-
gdat.inner(~isnan(gdat.inner(:,1)),:)];
527-
527+
outer = gdat.outer(~isnan(gdat.outer(:,1)),:);
528528
nope = 0; neta = 0; nbou = 0; nvel = 0;
529529
% Find the polygon that is a combination of ocean
530530
% and mainland boundaries.
@@ -537,13 +537,23 @@ function write(obj,fname,type)
537537
break;
538538
end
539539
end
540+
% Get geodata outer and mainland polygons
541+
outer = [gdat.outer(~isnan(gdat.outer(:,1)),:);
542+
gdat.inner(~isnan(gdat.inner(:,1)),:)];
543+
main = [gdat.mainland(~isnan(gdat.mainland(:,1)),:);
544+
gdat.inner(~isnan(gdat.inner(:,1)),:)];
545+
[~, d_out] = ourKNNsearch(outer',obj.p(idv,:)',1);
540546
[~, d_main] = ourKNNsearch(main',obj.p(idv,:)',1);
541547

542548
% Mainland are nodes where shortest distance to
543549
% mainland and outer are the same and where absolute
544550
% distance to mainland is relatively small
545-
mainland = abs(d_out - d_main) < gdat.h0/111e3 & ...
546-
d_main < 5*gdat.h0/111e3;
551+
if trim
552+
mainland = abs(d_out - d_main) < gdat.h0/111e3 & ...
553+
d_main < 5*gdat.h0/111e3;
554+
else
555+
mainland = abs(d_out - d_main) < gdat.h0/111e3;
556+
end
547557

548558
% indices of switch
549559
Cuts = find(diff(mainland ~= 0));

Example_1_NZ.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
% Example_1_NZ: Mesh the South Island of New Zealand
2+
clearvars; clc;
23
addpath(genpath('utilities/'))
34
addpath(genpath('datasets/'))
45
addpath(genpath('m_map/'))
@@ -20,8 +21,12 @@
2021
'max_el',max_el,'g',grade);
2122
%% STEP 4: Pass your edgefx class object along with some meshing options and
2223
% build the mesh...
23-
mshopt = meshgen('ef',{fh},'bou',{gdat},'nscreen',5,'plot_on',1,'itmax',75);
24-
mshopt = mshopt.build;
24+
mshopts = meshgen('ef',fh,'bou',gdat,'plot_on',1);
25+
mshopts = mshopts.build;
26+
2527
%% STEP 5: Plot it and write a triangulation fort.14 compliant file to disk.
26-
plot(mshopt.grd,'tri');
27-
write(mshopt.grd,'South_Island_NZ');
28+
% Get out the msh class and put on nodestrings
29+
m = mshopts.grd;
30+
m = makens(m,'auto',gdat); % make the nodestring boundary conditions
31+
plot(m,'bd');
32+
write(m,'South_Island_NZ');

Example_2_NY.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
% Example_2_NY: Mesh the New York region in high resolution
2+
clearvars; clc;
23
addpath(genpath('utilities/'))
34
addpath(genpath('datasets/'))
45
addpath(genpath('m_map/'))
56
%% STEP 1: Set mesh extents and set parameters for mesh.
6-
bbox = [-74.5 -73.8 % lon_min lon_max
7-
40.5 40.9]; % lat_min lat_max
87
min_el = 30; % Minimum resolution in meters.
98
max_el = 1e3; % Maximum resolution in meters.
109
max_el_ns = 240; % Maximum resolution nearshore in meters.
@@ -17,16 +16,19 @@
1716
dem = 'PostSandyNCEI.nc';
1817
gdat = geodata('shp',coastline,...
1918
'dem',dem,...
20-
'bbox',bbox,...
2119
'h0',min_el);
2220
%% STEP 3: Create an edge function class.
2321
fh = edgefx('geodata',gdat,...
2422
'fs',R,'max_el_ns',max_el_ns,...
2523
'max_el',max_el,'dt',dt,'g',grade);
2624
%% STEP 4: Pass your edgefx class object along with some meshing options and
2725
% build the mesh...
28-
mshopts = meshgen('ef',{fh},'bou',{gdat},'nscreen',1,'plot_on',1,'itmax',150);
26+
mshopts = meshgen('ef',fh,'bou',gdat,'plot_on',1);
2927
mshopts = mshopts.build;
3028
%% STEP 5: Plot it and write a triangulation fort.14 compliant file to disk.
31-
plot(mshopts.grd,'tri');
32-
write(mshopts.grd,'NY_HR');
29+
% Get out the msh class and put on bathy and nodestrings
30+
m = mshopts.grd;
31+
m = interp(m,gdat); m.b = max(m.b,1); % interpolate bathy to the mesh
32+
m = makens(m,'auto',gdat); % make the nodestring boundary conditions
33+
plot(m,'bd'); plot(m,'blog'); % plot triangulation and bathy
34+
write(m,'NY_HR');

Example_3_ECGC.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
%% STEP 1: set mesh extents and set parameters for mesh.
99
%% The greater US East Coast and Gulf of Mexico region
10-
bbox = [-100 -50; 10 60]; % lon min lon max; lat min lat max
10+
bbox = [-100 -50; 5 55]; % lon min lon max; lat min lat max
1111
min_el = 1e3; % minimum resolution in meters.
1212
max_el = inf; % maximum resolution in meters.
1313
wl = 60; % 60 elements resolve M2 wavelength.
@@ -44,12 +44,13 @@
4444

4545
%% STEP 4: Pass your edgefx class object along with some meshing options
4646
%% and build the mesh...
47-
mshopts = meshgen('ef',{fh1 fh2},'bou',{gdat1 gdat2},...
48-
'nscreen',1,'plot_on',1,'itmax',50);
47+
mshopts = meshgen('ef',{fh1 fh2},'bou',{gdat1 gdat2},'plot_on',1);
4948
mshopts = mshopts.build;
5049

5150
%% Plot and save the msh class object/write to fort.14
5251
m = mshopts.grd; % get out the msh object
52+
m = interp(m,{gdat1 gdat2}); m.b = max(m.b,1); % interpolate bathy to the mesh
5353
m = makens(m,'auto',gdat1); % make the nodestring boundary conditions
5454
plot(m,'bd',1,'Mollweide'); % plot on Mollweide projection with nodestrings
55+
plot(m,'b',1,'Mollweide'); % plot bathy on Mollweide projection
5556
save('ECGC_w_NYHR.mat','m'); write(m,'ECGC_w_NYHR');

Example_4_PRVI.m

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,28 @@
6262
%% Pass your edgefx class objects along with some meshing options
6363
%% and build the mesh...
6464
% (note that the nested edgefxs will be smoothed together with this call)
65-
mshopts = meshgen('ef',fh,'bou',gdat,'nscreen',5,'plot_on',1,'itmax',50);
65+
mshopts = meshgen('ef',fh,'bou',gdat,'plot_on',1,'itmax',50);
6666

6767
% now build the mesh with your options and the edge function.
6868
mshopts = mshopts.build;
6969

70-
%% Get out the msh class from meshgen
70+
% Get out the msh class from meshgen
7171
m = mshopts.grd;
7272

73-
%plot(m,'tri');
74-
75-
%plot(m,'reso');
76-
7773
%% Interpolate on the bathy and gradients (automatically loops over all data)
78-
% m = interp(m,gdat);
74+
m = interp(m,gdat);
7975
% % ensure max depth in domain is 1 m (we find this step useful for coastal
8076
% % meshes to help with connectivity through narrow channels)
81-
% m.b = max(m.b,1);
82-
%
83-
% plot(m,'b');
77+
m.b = max(m.b,1);
8478

79+
%% Make the nodestrings
80+
m = makens(m,'auto',gdat{1}); % make the nodestring boundary conditions
81+
82+
%% Plot and save the msh class object/write to fort.14
83+
plot(m,'bd',1,'Sinusoidal'); % plot on Sinusoidal projection with nodestrings
84+
plot(m,'b',1,'Sinusoidal'); % plot the bathy on Sinusoidal projection
8585
% Save as a msh class
8686
save('PRVI_msh.mat','m');
87-
8887
% Write an ADCIRC fort.14 compliant file to disk.
89-
%write(m,'PRVI_mesh')
88+
write(m,'PRVI_mesh')
9089

Example_5_JBAY.m

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
%Example_2_NY: Mesh the New York Jamaica bay (JBAY region in high resolution.
1+
% Example_5_JBAY: Mesh the New York Jamaica bay (JBAY) region in
2+
% high resolution.
3+
4+
clc; clearvars
5+
26
addpath(genpath('utilities/'));
37
addpath(genpath('datasets/'));
48
addpath(genpath('m_map/'));
@@ -26,8 +30,13 @@
2630
'g',grade);
2731
%% STEP 4: Pass your edgefx class object along with some meshing options and
2832
% build the mesh...
29-
mshopts = meshgen('ef',{fh},'bou',{gdat},'plot_on',1);
33+
mshopts = meshgen('ef',fh,'bou',gdat,'plot_on',1);
3034
% now build the mesh with your options and the edge function.
3135
mshopts = mshopts.build;
32-
%% STEP 5: Plot it
33-
plot(mshopts.grd,'tri');
36+
%% STEP 5: Plot it and save the msh file
37+
% Get out the msh class and put on bathy and nodestrings
38+
m = mshopts.grd;
39+
m = interp(m,gdat); m.b = max(m.b,1); % interpolate bathy to the mesh
40+
m = makens(m,'auto',gdat); % make the nodestring boundary conditions
41+
plot(m,'bd'); plot(m,'blog'); % plot triangulation and bathy
42+
save('JBAY_HR.mat','m')

Example_6_GBAY.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
% Example_6_GBAY: Mesh the Galveston bay (GBAY) region in
2+
% high resolution.
3+
4+
clearvars; clc;
5+
16
addpath(genpath('utilities/'))
27
addpath(genpath('datasets/'))
38
addpath(genpath('m_map/'))
9+
410
%% STEP 1: set mesh extents and set parameters for mesh.
511
bbox = [-95.40 -94.4;
612
29.14 30.09];
@@ -14,7 +20,7 @@
1420
'dem',demfile,...
1521
'bbox',bbox,...
1622
'h0',min_el);
17-
load ECGC_Thalwegs.mat
23+
load ECGC_Thalwegs.mat % Load the Channel thalweg data
1824
%% STEP 3: create an edge function class
1925
fh = edgefx('geodata',gdat,...
2026
'fs',3,...
@@ -28,5 +34,8 @@
2834
% now build the mesh with your options and the edge function.
2935
mshopts = mshopts.build;
3036
%% STEP 5: Plot it and write a triangulation fort.14 compliant file to disk.
31-
plot(mshopts.grd,'tri',0);
32-
write(mshopts.grd,'HoustonShipChannel');
37+
m = mshopts.grd;
38+
m = interp(m,gdat); m.b = max(m.b,1); % interpolate bathy to the mesh
39+
m = makens(m,'auto',gdat); % make the nodestring boundary conditions
40+
plot(m,'bd'); plot(m,'blog'); % plot triangulation and bathy
41+
write(m,'HoustonShipChannel');

utilities/m_trisurf.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77
% Have to have initialized a map first
88

9-
if isempty(MAP_PROJECTION),
9+
if isempty(MAP_PROJECTION)
1010
disp('No Map Projection initialized - call M_PROJ first!');
1111
return;
12-
end;
13-
m_grid('linest','-');
12+
end
1413

1514
[X,Y]=m_ll2xy(long,lat,'clip','on');
1615
colormap(cmap);
17-
hold on; h=trisurf(tri,X,Y,z,'facecolor', 'flat', 'edgecolor', 'none');
18-
shading interp;
16+
hold on; h=trisurf(tri,X,Y,z,'facecolor', 'interp', 'edgecolor', 'none');
17+
m_grid('linest','-');
1918
end

0 commit comments

Comments
 (0)