-
Notifications
You must be signed in to change notification settings - Fork 23
/
example.m
911 lines (679 loc) · 24.4 KB
/
example.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
function example(varargin)
%EXAMPLE build example meshes for JIGSAW(GEO).
%
% EXAMPLE(N) calls the N-TH demo problem. The following
% demo problems are currently available:
%
% - DEMO-1: generate a uniform resolution 150KM global grid.
%
% - DEMO-2: generate a regionally-refined global-grid, with
% a high-resolution "patch" (37.5KM resolution) embedded
% within a uniformly resolved 150KM background grid.
%
% DEMO-3: build "smooth" mesh-spacing functions from noisy
% + discontinuous input data using MARCHE.
%
% - DEMO-4: generate a multi-resolution grid for the arctic
% ocean basin, with local refinement along coastlines and
% shallow ridges. Global grid resolution is 150KM, backgr-
% ound arctic resolution is 67KM and min. adaptive resolu-
% tion is 33KM.
%
% - DEMO-5: generate uniform resolution struct. icosahedral
% and cubedsphere grids.
%
% - DEMO-6: generate a grid for the Australian region, using
% scaled ocean-depth as a mesh-spacing indicator.
%
% - DEMO-7: generate a "multi-part" mesh of the (contiguous)
% USA, using state boundaries to partition the mesh.
%
% See also JIGSAW
%
%-----------------------------------------------------------
% Darren Engwirda
% github.com/dengwirda/jigsaw-geo-matlab
% 12-Sep-2020
%-----------------------------------------------------------
%
close all ; initjig ;
demo = +1;
if (nargin >= 1), demo = varargin{1}; end
switch (demo)
case 1, demo_1 ;
case 2, demo_2 ;
case 3, demo_3 ;
case 4, demo_4 ;
case 5, demo_5 ;
case 6, demo_6 ;
case 7, demo_7 ;
otherwise
error( ...
'example:invalidSelection','Invalid selection!') ;
end
end
function demo_1
% DEMO-1: generate a uniform resolution (150KM) global grid.
% JIGSAW is combined with a bisection procedure to improve
% the regularity of the grid topology.
%------------------------------------ setup files for JIGSAW
rootpath = fileparts( ...
mfilename( 'fullpath' )) ;
opts.geom_file = ... % domain file
fullfile(rootpath,...
'cache','geom.msh') ;
opts.jcfg_file = ... % config file
fullfile(rootpath,...
'cache','opts.jig') ;
opts.mesh_file = ... % output file
fullfile(rootpath,...
'cache','mesh.msh') ;
%------------------------------------ define JIGSAW geometry
geom.mshID = 'ELLIPSOID-MESH' ;
geom.radii = 6371 * ones(3,1) ;
savemsh (opts.geom_file,geom) ;
%------------------------------------ build mesh via JIGSAW!
opts.hfun_scal = 'absolute';
opts.hfun_hmax = +150. ;
opts.mesh_dims = +2 ; % 2-dim. simplexes
opts.optm_qlim = +.95 ;
opts.optm_iter = + 32 ;
rbar = mean(geom.radii) ;
nlev = round(log2( ...
rbar / sin(.4 * pi) / opts.hfun_hmax) ...
) ;
mesh = tetris(opts, nlev - 1) ;
topo = loadmsh( ...
fullfile(rootpath, ...
'files', 'topo.msh')) ;
plotsphere(geom,mesh,[],topo) ;
drawnow ;
set(figure(1),'units','normalized', ...
'position',[.05,.50,.25,.30]) ;
set(figure(2),'units','normalized', ...
'position',[.05,.10,.25,.30]) ;
end
function demo_2
% DEMO-2 -- generate a regionally-refined global grid with a
% high-resolution "patch" (@37.5KM) embedded within a
% uniform background grid (@150.KM).
% JIGSAW is combined with a bisection procedure to improve
% the regularity of the grid topology.
%------------------------------------ setup files for JIGSAW
rootpath = fileparts( ...
mfilename( 'fullpath' )) ;
opts.geom_file = ... % domain file
fullfile(rootpath,...
'cache','geom.msh') ;
opts.jcfg_file = ... % config file
fullfile(rootpath,...
'cache','opts.jig') ;
opts.mesh_file = ... % output file
fullfile(rootpath,...
'cache','mesh.msh') ;
opts.hfun_file = ... % sizing file
fullfile(rootpath,...
'cache','spac.msh') ;
%------------------------------------ define JIGSAW geometry
geom.mshID = 'ELLIPSOID-MESH' ;
geom.radii = 6371 * ones(3,1) ;
savemsh (opts.geom_file,geom) ;
%------------------------------------ compute HFUN over GEOM
topo = loadmsh(fullfile( ...
rootpath, 'files', 'topo.msh' ) );
xpos = topo.point.coord{1};
ypos = topo.point.coord{2};
zlev = reshape( ...
topo.value,length(ypos),length(xpos));
[XPOS,YPOS] = meshgrid(xpos,ypos);
XPOS = XPOS * pi/180 ;
YPOS = YPOS * pi/180 ;
hfun = +150.0 - 112.5 * exp( -( ...
+1.5 * (XPOS + 1.0).^2 ...
+1.5 * (YPOS - 0.5).^2).^4) ;
hmat.mshID = 'ELLIPSOID-GRID';
hmat.radii = geom.radii;
hmat.point.coord{1} = XPOS(1,:) ;
hmat.point.coord{2} = YPOS(:,1) ;
hmat.value = single(hfun);
savemsh(opts.hfun_file,hmat) ;
%------------------------------------ build mesh via JIGSAW!
fprintf(1,' Constructing MESH...\n');
opts.hfun_scal = 'absolute';
opts.hfun_hmax = +inf ;
opts.hfun_hmin = +0.0 ;
opts.mesh_dims = +2 ; % 2-dim. simplexes
opts.optm_qlim = +.95 ;
opts.optm_iter = + 32 ;
rbar = mean(geom.radii(:)) ;
hbar = mean(hmat.value(:)) ;
nlev = round(log2( ...
rbar / sin(.4 * pi) / hbar) ) ;
mesh = tetris(opts, nlev - 1) ;
plotsphere(geom,mesh,hmat,topo) ;
drawnow ;
set(figure(1),'units','normalized', ...
'position',[.30,.50,.25,.30]) ;
set(figure(2),'units','normalized', ...
'position',[.05,.50,.25,.30]) ;
set(figure(3),'units','normalized', ...
'position',[.05,.10,.25,.30]) ;
end
function demo_3
% DEMO-3 --- use MARCHE to build "smooth" mesh-spacing data
% from noisy/discontinuous inputs.
%------------------------------------ setup files for JIGSAW
rootpath = fileparts( ...
mfilename( 'fullpath' )) ;
opts.geom_file = ... % domain file
fullfile(rootpath,...
'cache','geom.msh') ;
opts.jcfg_file = ... % config file
fullfile(rootpath,...
'cache','opts.jig') ;
opts.hfun_file = ... % sizing file
fullfile(rootpath,...
'cache','spac.msh') ;
%------------------------------------ define JIGSAW geometry
geom.mshID = 'ELLIPSOID-MESH' ;
geom.radii = 6371 * ones(3,1) ;
savemsh (opts.geom_file,geom) ;
%------------------------------------ compute HFUN over GEOM
fprintf(1,' Loading TOPO data...\n');
topo = loadmsh(fullfile( ...
rootpath, 'files', 'topo.msh' ) );
fprintf(1,' Forming HFUN data...\n');
xpos = topo.point.coord{1};
ypos = topo.point.coord{2};
zlev = topo.value;
[XPOS,YPOS] = meshgrid (xpos,ypos) ;
hfn0 = +150. ; % global spacing
hfn2 = +33.; % adapt. spacing
hfn3 = +67.; % arctic spacing
hfun = +hfn0*ones(size(zlev)) ;
htop = sqrt(max(-zlev(:),eps))/1. ;
htop = max(htop,hfn2);
htop = min(htop,hfn3);
htop(zlev>0.) = hfn0 ;
hfun(YPOS>=40.) = htop(YPOS>=40.) ;
%------------------------------------ set HFUN grad.-limiter
dhdx = +0.050 ; % max. gradients
hmat.mshID = 'ELLIPSOID-GRID' ;
hmat.radii = geom.radii ;
hmat.point.coord{1} = xpos*pi/180 ;
hmat.point.coord{2} = ypos*pi/180 ;
hmat.value = single(hfun) ;
hmat.slope = dhdx*ones(size(hfun));
savemsh (opts.hfun_file,hmat) ;
%------------------------------------ set HFUN grad.-limiter
hlim = marche(opts) ;
plotsphere(geom,[],hmat,topo) ;
plotsphere(geom,[],hlim,topo) ;
drawnow ;
set(figure(1),'units','normalized', ...
'position',[.05,.50,.25,.30]) ;
title('H(x): raw data');
set(figure(2),'units','normalized', ...
'position',[.30,.50,.25,.30]) ;
title('H(x): smoothed');
end
function demo_4
% DEMO-4 --- generate a multi-resolution grid for the arctic
% ocean basin, with local refinement along coastlines and
% shallow ridges. Global grid resolution is 150KM, backgr-
% ound arctic resolution is 67KM and min. adaptive resolu-
% tion is 33KM.
% JIGSAW is combined with a bisection procedure to improve
% the regularity of the grid topology.
%------------------------------------ setup files for JIGSAW
rootpath = fileparts( ...
mfilename( 'fullpath' )) ;
opts.geom_file = ... % domain file
fullfile(rootpath,...
'cache','geom.msh') ;
opts.jcfg_file = ... % config file
fullfile(rootpath,...
'cache','opts.jig') ;
opts.mesh_file = ... % output file
fullfile(rootpath,...
'cache','mesh.msh') ;
opts.hfun_file = ... % sizing file
fullfile(rootpath,...
'cache','spac.msh') ;
%------------------------------------ define JIGSAW geometry
geom.mshID = 'ELLIPSOID-MESH' ;
geom.radii = 6371 * ones(3,1) ;
savemsh (opts.geom_file,geom) ;
%------------------------------------ compute HFUN over GEOM
fprintf(1,' Loading TOPO data...\n');
topo = loadmsh(fullfile( ...
rootpath, 'files', 'topo.msh' ) );
xpos = topo.point.coord{1};
ypos = topo.point.coord{2};
zlev = reshape( ...
topo.value,length(ypos),length(xpos));
[nlat,nlon] = size(zlev);
radE = 6371.0E+00 ;
fprintf(1,' Forming HFUN data...\n');
[XPOS,YPOS] = meshgrid (xpos,ypos) ;
hfn0 = +150. ; % global spacing
hfn2 = +33.; % adapt. spacing
hfn3 = +67.; % arctic spacing
hfun = +hfn0*ones(nlat,nlon) ;
htop = sqrt(max(-zlev(:),eps))/1. ;
htop = max(htop,hfn2);
htop = min(htop,hfn3);
htop(zlev>0.) = hfn0 ;
hfun(YPOS>=40.) = htop(YPOS>=40.) ;
%------------------------------------ set HFUN grad.-limiter
dhdx = +0.050 ; % max. gradients
hmat.mshID = 'ELLIPSOID-GRID';
hmat.radii = radE ;
hmat.point.coord{1} = xpos*pi/180 ;
hmat.point.coord{2} = ypos*pi/180 ;
hmat.value = single(hfun) ;
hmat.slope = dhdx*ones(size(hfun));
savemsh(opts.hfun_file,hmat) ;
%------------------------------------ set HFUN grad.-limiter
hmat = marche(opts) ;
%------------------------------------ build mesh via JIGSAW!
fprintf(1,' Constructing MESH...\n');
opts.hfun_scal = 'absolute';
opts.hfun_hmax = +inf ;
opts.hfun_hmin = +0.0 ;
opts.mesh_dims = +2 ; % 2-dim. simplexes
opts.optm_qlim = +.95 ;
opts.optm_iter = + 32 ;
rbar = mean(geom.radii(:)) ;
hbar = mean(hmat.value(:)) ;
nlev = round(log2( ...
rbar / sin(.4 * pi) / hbar) ) ;
mesh = tetris(opts, nlev - 1) ;
plotsphere(geom,mesh,hmat,topo) ;
drawnow ;
set(figure(1),'units','normalized', ...
'position',[.30,.50,.25,.30]) ;
set(figure(2),'units','normalized', ...
'position',[.05,.50,.25,.30]) ;
set(figure(3),'units','normalized', ...
'position',[.05,.10,.25,.30]) ;
end
function demo_5
% DEMO-5: generate uniform resolution structured icosahedral
% and cubedsphere grids.
%------------------------------------ setup files for JIGSAW
rootpath = fileparts( ...
mfilename( 'fullpath' )) ;
opts.geom_file = ... % domain file
fullfile(rootpath,...
'cache','geom.msh') ;
opts.jcfg_file = ... % config file
fullfile(rootpath,...
'cache','opts.jig') ;
opts.mesh_file = ... % output file
fullfile(rootpath,...
'cache','mesh.msh') ;
%------------------------------------ define JIGSAW geometry
geom.mshID = 'ELLIPSOID-MESH' ;
geom.radii = 1. * ones(3,1) ;
savemsh (opts.geom_file,geom) ;
%------------------------------------ build mesh via JIGSAW!
topo = loadmsh( ...
fullfile(rootpath, ...
'files', 'topo.msh')) ;
opts.hfun_hmax = +1.;
opts.mesh_dims = +2 ; % 2-dim. simplexes
opts.optm_qtol = +1.E-06 ;
opts.optm_iter = +512 ;
mesh = icosahedron(opts, +6) ;
plotsphere(geom,mesh,[],topo) ;
mesh = cubedsphere(opts, +6) ;
plotsphere(geom,mesh,[],topo) ;
drawnow ;
set(figure(1),'units','normalized', ...
'position',[.05,.50,.25,.30]) ;
set(figure(2),'units','normalized', ...
'position',[.05,.10,.25,.30]) ;
set(figure(3),'units','normalized', ...
'position',[.30,.50,.25,.30]) ;
set(figure(4),'units','normalized', ...
'position',[.30,.10,.25,.30]) ;
end
function demo_6
% DEMO-6 -- generate a 2-dim. grid for the Australian region
% using scaled ocean-depth as a mesh-spacing indicator.
% A local stereographic projection is employed.
%------------------------------------ setup files for JIGSAW
rootpath = fileparts( ...
mfilename( 'fullpath' )) ;
opts.geom_file = ... % domain file
fullfile(rootpath,...
'cache','geom.msh') ;
opts.jcfg_file = ... % config file
fullfile(rootpath,...
'cache','aust.jig') ;
opts.mesh_file = ... % output file
fullfile(rootpath,...
'cache','mesh.msh') ;
opts.hfun_file = ... % sizing file
fullfile(rootpath,...
'cache','spac.msh') ;
%------------------------------------ setup TOPO for spacing
fprintf(1,' Loading TOPO data...\n');
geom = loadmsh(fullfile( ...
rootpath,'files','aust.msh'));
topo = loadmsh(fullfile( ...
rootpath,'files','topo.msh'));
alon = topo.point.coord{1};
alat = topo.point.coord{2};
zlev = reshape( ...
topo.value,length(alat),length(alon));
xmin = min(geom.point.coord(:,1)); % only keep AU-bit
xmax = max(geom.point.coord(:,1));
ymin = min(geom.point.coord(:,2));
ymax = max(geom.point.coord(:,2));
xone = find(alon>=xmin,1,'first');
xend = find(alon<=xmax,1, 'last');
xone = xone - 1 ;
xend = xend + 1 ;
yone = find(alat>=ymin,1,'first');
yend = find(alat<=ymax,1, 'last');
yone = yone - 1 ;
yend = yend + 1 ;
alon = alon(xone:xend) ;
alat = alat(yone:yend) ;
zlev = zlev(yone:yend,xone:xend) ;
%------------------------------------ compute HFUN from TOPO
fprintf(1,' Forming HFUN data...\n');
hmin = +10. ; % min. H(X) [deg.]
hmax = +100. ; % max. H(X)
hfun = sqrt(max(-zlev,eps))/.5 ; % scale with H^1/2
hfun = max(hfun,hmin);
hfun = min(hfun,hmax);
dhdx = +.15 *ones(size(hfun)); % smoothing limits
hmat.mshID = 'ELLIPSOID-GRID';
hmat.radii = 6371.E+00;
hmat.point.coord{1} = ...
alon * pi / 180. ;
hmat.point.coord{2} = ...
alat * pi / 180. ;
hmat.value = hfun ;
hmat.slope = dhdx ;
%------------------------------------ do stereographic proj.
fprintf(1,' Forming PROJ data...\n');
geom.point.coord(:,1:2) = ...
geom.point.coord(:,1:2) * pi/180;
proj.prjID = 'STEREOGRAPHIC';
proj.radii = 6371.E+00;
proj.xbase = 0.5 * ( ...
min(geom.point.coord(:,1)) ...
+ max(geom.point.coord(:,1)) );
proj.ybase = 0.5 * ( ...
min(geom.point.coord(:,2)) ...
+ max(geom.point.coord(:,2)) );
[GPRJ] = project(geom,proj,'fwd');
[HPRJ] = project(hmat,proj,'fwd');
savemsh(opts.geom_file,GPRJ) ;
savemsh(opts.hfun_file,HPRJ) ;
%------------------------------------ set HFUN grad.-limiter
HPRJ = marche (opts) ;
%------------------------------------ build mesh via JIGSAW!
fprintf(1,' Constructing MESH...\n');
opts.hfun_scal = 'absolute'; % null HFUN limits
opts.hfun_hmax = +inf ;
opts.hfun_hmin = 0.00 ;
opts.mesh_dims = +2 ; % 2-dim. simplexes
opts.mesh_eps1 = 1.00 ;
MPRJ = jigsaw (opts) ;
plotplanar(GPRJ,MPRJ,HPRJ) ;
drawnow ;
set(figure(1),'units','normalized', ...
'position',[.05,.50,.25,.30]) ;
set(figure(2),'units','normalized', ...
'position',[.05,.10,.25,.30]) ;
set(figure(3),'units','normalized', ...
'position',[.30,.50,.25,.30]) ;
set(figure(4),'units','normalized', ...
'position',[.30,.10,.25,.30]) ;
end
function demo_7
%DEMO-7 --- generate a "multi-part" mesh of the (contiguous)
% USA, using state boundaries to partition the mesh.
% A local stereographic projection is employed.
%------------------------------------ setup files for JIGSAW
rootpath = fileparts( ...
mfilename( 'fullpath' )) ;
opts.geom_file = ... % domain file
fullfile(rootpath,...
'cache','geom.msh') ;
opts.jcfg_file = ... % config file
fullfile(rootpath,...
'cache','us48.jig') ;
opts.mesh_file = ... % output file
fullfile(rootpath,...
'cache','mesh.msh') ;
%------------------------------------ import GEOM. from file
geom = loadmsh(fullfile( ...
rootpath,'files','us48.msh')) ;
%------------------------------------ do stereographic proj.
geom.point.coord(:,1:2) = ...
geom.point.coord(:,1:2) * pi/180;
proj.prjID = 'STEREOGRAPHIC';
proj.radii = 6371.E+00;
proj.xbase = 0.5 * ( ...
min(geom.point.coord(:,1)) ...
+ max(geom.point.coord(:,1)) );
proj.ybase = 0.5 * ( ...
min(geom.point.coord(:,2)) ...
+ max(geom.point.coord(:,2)) );
[GEOM] = project(geom,proj,'fwd');
savemsh(opts.geom_file,GEOM) ;
%------------------------------------ create mesh via JIGSAW
fprintf(1,' Constructing MESH...\n');
opts.hfun_hmax = .005 ;
opts.mesh_dims = +2 ; % 2-dim. simplexes
opts.mesh_eps1 = +1/6 ;
MESH = jigsaw (opts) ;
plotplanar(GEOM,MESH,[]) ;
drawnow ;
set(figure(1),'units','normalized', ...
'position',[.05,.50,.25,.30]) ;
set(figure(2),'units','normalized', ...
'position',[.30,.50,.25,.30]) ;
set(figure(3),'units','normalized', ...
'position',[.30,.10,.25,.30]) ;
end
function plotsphere(geom,mesh,hfun,topo)
%PLOT-SPHERE draw JIGSAW output for sphere problems.
if (~isempty(topo))
xpos = topo.point.coord{1};
ypos = topo.point.coord{2};
zlev = reshape( ...
topo.value,length(ypos),length(xpos));
else
zlev = [] ;
end
if (~isempty(hfun))
switch (upper(hfun.mshID))
case{'EUCLIDEAN-GRID', ...
'ELLIPSOID-GRID'}
%------------------------------------ disp. 'grid' functions
hfun.value = reshape(hfun.value, ...
length(hfun.point.coord{2}), ...
length(hfun.point.coord{1}) ...
) ;
if (all(size(hfun.value)==size(zlev)))
vals = hfun.value ;
vals(zlev>0.) = inf ;
else
vals = hfun.value ;
end
figure('color','w');
surf(hfun.point.coord{1}*180/pi, ...
hfun.point.coord{2}*180/pi, ...
vals) ;
view(2); axis image; hold on ;
shading interp;
title('JIGSAW HFUN data') ;
end
end
if (~isempty(mesh))
%------------------------------------ draw unstructured mesh
if (~isempty(topo))
[tlev,qlev] = findalt( ...
geom,mesh,xpos,ypos,zlev);
figure('color','w') ;
if (inspect(mesh,'tria3'))
W = tlev <= +0. ;
D = tlev > +0. ;
patch ('faces',mesh.tria3.index(W,1:3), ...
'vertices',mesh.point.coord(:,1:3), ...
'facevertexcdata',tlev(W), ...
'facecolor','flat', ...
'edgecolor','k') ;
hold on; axis image off;
patch ('faces',mesh.tria3.index(D,1:3), ...
'vertices',mesh.point.coord(:,1:3), ...
'facecolor','w', ...
'edgecolor','none');
end
if (inspect(mesh,'quad4'))
W = qlev <= +0. ;
D = qlev > +0. ;
patch ('faces',mesh.quad4.index(W,1:4), ...
'vertices',mesh.point.coord(:,1:3), ...
'facevertexcdata',qlev(W), ...
'facecolor','flat', ...
'edgecolor','k') ;
hold on; axis image off;
patch ('faces',mesh.quad4.index(D,1:4), ...
'vertices',mesh.point.coord(:,1:3), ...
'facecolor','w', ...
'edgecolor','none');
end
set(gca,'clipping','off') ;
caxis([min(zlev(:))*4./3., +0.]);
brighten(+0.75);
else
figure('color','w') ;
if (inspect(mesh,'tria3'))
patch ('faces',mesh.tria3.index(:,1:3), ...
'vertices',mesh.point.coord(:,1:3), ...
'facecolor','w', ...
'edgecolor','k') ;
hold on; axis image off;
end
if (inspect(mesh,'quad4'))
patch ('faces',mesh.quad4.index(:,1:4), ...
'vertices',mesh.point.coord(:,1:3), ...
'facecolor','w', ...
'edgecolor','k') ;
hold on; axis image off;
end
set(gca,'clipping','off') ;
end
drawcost(mesh, hfun) ;
end
end
function plotplanar(geom,mesh,hfun)
%PLOT-PLANAR draw JIGSAW output for planar problems.
if (~isempty(geom))
%------------------------------------ draw domain boundaries
figure('color','w');
patch ('faces',geom.edge2.index(:,1:2), ...
'vertices',geom.point.coord(:,1:2), ...
'facecolor','w', ...
'edgecolor',[.1,.1,.1], ...
'linewidth',1.5) ;
hold on; axis image;
title('JIGSAW GEOM data') ;
end
if (~isempty(hfun))
switch (upper(hfun.mshID))
case{'EUCLIDEAN-GRID', ...
'ELLIPSOID-GRID'}
%------------------------------------ disp. 'grid' functions
hfun.value = reshape(hfun.value, ...
length(hfun.point.coord{2}), ...
length(hfun.point.coord{1}) ...
) ;
figure('color','w') ;
surf(hfun.point.coord{1}, ...
hfun.point.coord{2}, ...
hfun.value) ;
view(2); axis image; hold on ;
shading interp;
title('JIGSAW HFUN data') ;
case{'EUCLIDEAN-MESH', ...
'ELLIPSOID-MESH'}
%------------------------------------ disp. 'mesh' functions
figure('color','w') ;
patch ('faces',hfun.tria3.index(:,1:3), ...
'vertices',hfun.point.coord(:,1:2), ...
'facevertexcdata',hfun.value, ...
'facecolor','flat', ...
'edgecolor','none') ;
view(2); axis image; hold on ;
title('JIGSAW HFUN data') ;
end
end
if (~isempty(mesh))
%------------------------------------ draw unstructured mesh
figure('color','w');
P = mesh.tria3.index (:,4);
if ( all (P == +0))
patch ('faces',mesh.tria3.index(:,1:3), ...
'vertices',mesh.point.coord(:,1:2), ...
'facecolor',[.9,.9,.9], ...
'edgecolor',[.2,.2,.2]) ;
hold on; axis image;
else
for ip = 1 : max(P)
I = P == ip;
patch ('faces',mesh.tria3.index(I,1:3), ...
'vertices',mesh.point.coord(:,1:2), ...
'facecolor', .5*rand(1,3)+.5, ...
'edgecolor',[.2,.2,.2]) ;
hold on; axis image;
end
end
patch ('faces',mesh.edge2.index(:,1:2), ...
'vertices',mesh.point.coord(:,1:2), ...
'facecolor','w', ...
'edgecolor',[.8,.1,.1], ...
'linewidth',2.5) ;
if (~isempty(geom))
patch ('faces',geom.edge2.index(:,1:2), ...
'vertices',geom.point.coord(:,1:2), ...
'facecolor','w', ...
'edgecolor',[.1,.1,.8], ...
'linewidth',1.5) ;
end
title('JIGSAW TRIA mesh') ;
drawcost (mesh,hfun) ;
end
end
function [tlev,qlev] = ...
findalt(geom,mesh,alon,alat,topo)
%FINDALT calc. an "altitude" for each mesh-cell in the mesh.
tlev = []; qlev = [];
xsph = R3toS2( ...
geom.radii, mesh.point.coord(:, 1:3));
xlat = xsph(:,2) * 180 / pi;
xlon = xsph(:,1) * 180 / pi;
xlev = interp2 (alon,alat,topo,xlon,xlat);
if (inspect(mesh,'tria3'))
tlev = xlev (mesh.tria3.index(:,1)) ...
+ xlev (mesh.tria3.index(:,2)) ...
+ xlev (mesh.tria3.index(:,3)) ;
tlev = tlev / +3.0 ;
end
if (inspect(mesh,'quad4'))
qlev = xlev (mesh.quad4.index(:,1)) ...
+ xlev (mesh.quad4.index(:,2)) ...
+ xlev (mesh.quad4.index(:,3)) ...
+ xlev (mesh.quad4.index(:,4)) ;
qlev = qlev / +4.0 ;
end
end