-
Notifications
You must be signed in to change notification settings - Fork 27
/
jigsaw.m
336 lines (314 loc) · 11.8 KB
/
jigsaw.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
function [varargout] = jigsaw(opts)
%JIGSAW an interface to the JIGSAW mesh generator.
%
% MESH = JIGSAW(OPTS);
%
% Call the JIGSAW mesh generator using the config. options
% specified in the OPTS structure. See the SAVEMSH/LOADMSH
% routines for a description of the MESH output structure.
%
% OPTS is a user-defined set of meshing options:
%
% REQUIRED fields:
% ---------------
%
% OPTS.GEOM_FILE - 'GEOMNAME.MSH', a string containing the
% name of the geometry file (is required at input).
% See SAVEMSH for additional details regarding the cr-
% eation of *.MSH files.
%
% OPTS.JCFG_FILE - 'JCFGNAME.JIG', a string containing the
% name of the cofig. file (will be created on output).
%
% OPTS.MESH_FILE - 'MESHNAME.MSH', a string containing the
% name of the output file (will be created on output).
%
% OPTIONAL fields (INIT):
% ----------------------
%
% OPTS.INIT_FILE - 'INITNAME.MSH', a string containing the
% name of the initial distribution file (is required
% at input).
%
% OPTS.INIT_NEAR - {default = 1.E-8} relative "zip" tol.
% applied when processing initial conditions. In cases
% where "sharp-feature" detection is active, nodes in
% the initial set are zipped to their nearest feature
% node if the separation length is less than NEAR*SCAL
% where SCAL is the max. bounding-box dimension.
%
% OPTIONAL fields (GEOM):
% ----------------------
%
% OPTS.GEOM_SEED - {default=8} number of "seed" vertices
% used to initialise mesh generation.
%
% OPTS.GEOM_FEAT - {default=false} attempt to auto-detect
% "sharp-features" in the input geometry. Features can
% lie adjacent to 1-dim. entities, (i.e. geometry
% "edges") and/or 2-dim. entities, (i.e. geometry
% "faces") based on both geometrical and/or topologic-
% al constraints. Geometrically, features are located
% between any neighbouring entities that subtend
% angles less than GEOM_ETAX degrees, where "X" is the
% (topological) dimension of the feature. Topological-
% ly, features are located at the apex of any non-man-
% ifold connections.
%
% OPTS.GEOM_ETA1 - {default=45deg} 1-dim. feature-angle,
% features are located between any neighbouring
% "edges" that subtend angles less than ETA1 deg.
%
% OPTS.GEOM_ETA2 - {default=45deg} 2-dim. feature angle,
% features are located between any neighbouring
% "faces" that subtend angles less than ETA2 deg.
%
% OPTIONAL fields (HFUN):
% ----------------------
%
% OPTS.HFUN_FILE - 'HFUNNAME.MSH', a string containing the
% name of the mesh-size file (is required at input).
% The mesh-size function is specified as a general pi-
% ecewise linear function, defined at the vertices of
% an unstructured triangulation. See SAVEMSH for addi-
% tional details.
%
% OPTS.HFUN_SCAL - {default='relative'} scaling type for
% mesh-size fuction. HFUN_SCAL='relative' interprets
% mesh-size values as percentages of the (mean) length
% of the axis-aligned bounding-box (AABB) associated
% with the geometry. HFUN_SCAL='absolute' interprets
% mesh-size values as absolute measures.
%
% OPTS.HFUN_HMAX - {default=0.02} max. mesh-size function
% value. Interpreted based on SCAL setting.
%
% OPTS.HFUN_HMIN - {default=0.00} min. mesh-size function
% value. Interpreted based on SCAL setting.
%
% OPTIONAL fields (MESH):
% ----------------------
%
% OPTS.MESH_DIMS - {default=3} number of "topological" di-
% mensions to mesh. DIMS=K meshes K-dimensional featu-
% res, irrespective of the number of spatial dim.'s of
% the problem (i.e. if the geometry is 3-dimensional
% and DIMS=2 a surface mesh will be produced).
%
% OPTS.MESH_KERN - {default='delfront'} meshing kernal,
% choice of the standard Delaunay-refinement algorithm
% (KERN='delaunay') or the Frontal-Delaunay method
% (KERN='delfront').
%
% OPTS.MESH_ITER - {default=+INF} max. number of mesh ref-
% inement iterations. Set ITER=N to see progress after
% N iterations.
%
% OPTS.MESH_TOP1 - {default=false} enforce 1-dim. topolog-
% ical constraints. 1-dim. edges are refined until all
% embedded nodes are "locally 1-manifold", i.e. nodes
% are either centred at topological "features", or lie
% on 1-manifold complexes.
%
% OPTS.MESH_TOP2 - {default=false} enforce 2-dim. topolog-
% ical constraints. 2-dim. trias are refined until all
% embedded nodes are "locally 2-manifold", i.e. nodes
% are either centred at topological "features", or lie
% on 2-manifold complexes.
%
% OPTS.MESH_RAD2 - {default=1.05} max. radius-edge ratio
% for 2-tria elements. 2-trias are refined until the
% ratio of the element circumradii to min. edge length
% is less-than RAD2.
%
% OPTS.MESH_RAD3 - {default=2.05} max. radius-edge ratio
% for 3-tria elements. 3-trias are refined until the
% ratio of the element circumradii to min. edge length
% is less-than RAD3.
%
% OPTS.MESH_OFF2 - {default=0.90} radius-edge ratio target
% for insertion of "shape"-type offcentres for 2-tria
% elements. When refining an element II, offcentres
% are positioned to form a new "frontal" element JJ
% that satisfies JRAD <= OFF2.
%
% OPTS.MESH_OFF3 - {default=1.10} radius-edge ratio target
% for insertion of "shape"-type offcentres for 3-tria
% elements. When refining an element II, offcentres
% are positioned to form a new "frontal" element JJ
% that satisfies JRAD <= OFF3.
%
% OPTS.MESH_SNK2 - {default=0.20} inflation tolerance for
% insertion of "sink" offcentres for 2-tria elements.
% When refining an element II, "sinks" are positioned
% at the centre of the largest adj. circumball staisf-
% ying |JBAL-IBAL| < SNK2 * IRAD, where IRAD is the
% radius of the circumball, and [IBAL,JBAL] are the
% circumball centres.
%
% OPTS.MESH_SNK3 - {default=0.33} inflation tolerance for
% insertion of "sink" offcentres for 3-tria elements.
% When refining an element II, "sinks" are positioned
% at the centre of the largest adj. circumball staisf-
% ying |JBAL-IBAL| < SNK3 * IRAD, where IRAD is the
% radius of the circumball, and [IBAL,JBAL] are the
% circumball centres.
%
% OPTS.MESH_EPS1 - {default=0.33} max. surface-discretisa-
% tion error multiplier for 1-edge elements. 1-edge
% elements are refined until the surface-disc. error
% is less-than EPS1 * HFUN(X).
%
% OPTS.MESH_EPS2 - {default=0.33} max. surface-discretisa-
% tion error multiplier for 2-tria elements. 2-tria
% elements are refined until the surface-disc. error
% is less-than EPS2 * HFUN(X).
%
% OPTS.MESH_VOL3 - {default=0.00} min. volume-length ratio
% for 3-tria elements. 3-tria elements are refined
% until the volume-length ratio exceeds VOL3. Can be
% used to supress "sliver" elements.
%
% OPTIONAL fields (OPTM):
% ----------------------
%
% OPTS.OPTM_KERN - {default='odt+dqdx'} mesh optimisation
% kernel, choice of an Optimal Delaunay Tessellation
% strategy (KERN='odt+dqdx') or a Centroidal Voronoi
% Tessellation method (KERN='cvt+dqdx'). In both
% cases a hybrid formulation is employed, using a
% "blend" of the ODT/CVT updates, and gradients of a
% "fall-back" mesh quality function Q.
%
% OPTS.OPTM_ITER - {default=16} max. number of mesh optim-
% isation iterations. Set ITER=N to see progress after
% N iterations.
%
% OPTS.OPTM_QTOL - {default=1.E-04} tolerance on mesh cost
% function for convergence. Iteration on a given node
% is terminated if adjacent element cost-functions are
% improved by less than QTOL.
%
% OPTS.OPTM_QLIM - {default=0.9375} threshold on mesh cost
% function above which gradient-based optimisation is
% attempted.
%
% OPTS.OPTM_TRIA - {default= true} allow for optimisation
% of TRIA grid geometry.
%
% OPTS.OPTM_DUAL - {default=false} allow for optimisation
% of DUAL grid geometry.
%
% OPTS.OPTM_ZIP_ - {default= true} allow for "merge" oper-
% ations on sub-face topology.
%
% OPTS.OPTM_DIV_ - {default= true} allow for "split" oper-
% ations on sub-face topology.
%
% OPTIONAL fields (MISC):
% ----------------------
%
% OPTS.VERBOSITY - {default=0} verbosity of log-file gene-
% rated by JIGSAW. Set VERBOSITY >= 1 for more output.
%
% See also LOADMSH, SAVEMSH
%
% JIGSAW is a "restricted" Delaunay-refinement and optimi-
% sation algorithm for 2- and 3-dimensional meshes. Please
% see the following for additional details:
%
% * D. Engwirda, (2018): "Generalised primal-dual grids for
% unstructured co-volume schemes", J. Comput. Phys., 375
% 155--176.
% https://doi.org/10.1016/j.jcp.2018.07.025
%
% * D. Engwirda & D. Ivers, (2016): "Off-centre Steiner poi-
% nts for Delaunay-refinement on curved surfaces", Comput-
% er-Aided Design, 72, 157--171.
% https://doi.org/10.1016/j.cad.2015.10.007
%
% * D. Engwirda, (2016): "Conforming Restricted Delaunay
% Mesh Generation for Piecewise Smooth Complexes", Proced-
% ia Engineering, 163, 84--96.
% https://doi.org/10.1016/j.proeng.2016.11.024
%
% * D. Engwirda, (2015): "Voronoi-based Point-placement for
% Three-dimensional Delaunay-refinement", Procedia Engin-
% eering, 124, 330--342.
% https://doi.org/10.1016/j.proeng.2015.10.143
%
% * D. Engwirda, (2014): "Locally-optimal Delaunay-refineme-
% nt and optimisation-based mesh generation", Ph.D. Thesis
% School of Mathematics and Statistics, Univ. of Sydney.
% https://hdl.handle.net/2123/13148
%
%-----------------------------------------------------------
% Darren Engwirda
% github.com/dengwirda/jigsaw-matlab
% 18-Apr-2021
%-----------------------------------------------------------
%
jexename = '' ;
if ( isempty(opts))
error('JIGSAW: insufficient inputs!!') ;
end
if (~isempty(opts) && ~isstruct(opts))
error('JIGSAW: invalid input types!!') ;
end
savejig(opts.jcfg_file,opts);
%---------------------------- set-up path for "local" binary
if (strcmp(jexename,''))
filename = ...
mfilename('fullpath') ;
filepath = ...
fileparts( filename ) ;
if (ispc())
jexename = [filepath, ...
'\external\jigsaw\bin\jigsaw.exe'];
elseif (ismac ())
jexename = [filepath, ...
'/external/jigsaw/bin/jigsaw'];
elseif (isunix())
jexename = [filepath, ...
'/external/jigsaw/bin/jigsaw'];
end
end
if (exist(jexename,'file')~=2), jexename=''; end
%---------------------------- search machine path for binary
if (strcmp(jexename,''))
if (ispc())
jexename = 'jigsaw.exe' ;
elseif (ismac ())
jexename = 'jigsaw' ;
elseif (isunix())
jexename = 'jigsaw' ;
end
end
if (exist(jexename,'file')~=2), jexename=''; end
%---------------------------- call JIGSAW and capture stdout
if (exist(jexename,'file')==2)
[status, result] = system( ...
['"',jexename,'"',' ','"',opts.jcfg_file,'"'], ...
'-echo') ;
%---------------------------- OCTAVE doesn't handle '-echo'!
if (exist('OCTAVE_VERSION', 'builtin') > 0)
fprintf(1, '%s', result) ;
end
else
%---------------------------- couldn't find JIGSAW's backend
error([ ...
'JIGSAW''s executable not found -- ', ...
'has JIGSAW been compiled from src?', ...
'See COMPILE for additional detail.', ...
] ) ;
end
if (nargout == +1)
%---------------------------- read mesh if output requested!
if (status == +0)
varargout{1} = loadmsh (opts.mesh_file) ;
else
varargout{1} = [];
end
end
end