@@ -213,13 +213,15 @@ fn plotselection(mesh, selection, grade=nil, filter=nil, transmit=nil) {
213
213
214
214
/** Visualizes a field
215
215
* @param[in] field - the field
216
+ * @param[in] selection - Selection to use
216
217
* @param[in] grade - Grade to show
217
218
* @param[in] colormap - Colormap to use
218
219
* @param[in] style - style to use
219
220
* @param[in] scale - whether or not to scale values */
220
- fn plotfield(field, grade=nil, colormap=nil, style=nil, scale=true, filter=nil, transmit=nil, scalebar=nil, cmin=nil, cmax=nil) {
221
+ fn plotfield(field, selection=nil, grade=nil, colormap=nil, style=nil, scale=true, filter=nil, transmit=nil, scalebar=nil, cmin=nil, cmax=nil) {
221
222
var mesh = field.mesh()
222
223
var shape = field.shape()
224
+ var sel = selection
223
225
224
226
var ngrades = shape.count()
225
227
var showgrades = [] // Grades to show
@@ -242,7 +244,20 @@ fn plotfield(field, grade=nil, colormap=nil, style=nil, scale=true, filter=nil,
242
244
Error("PltFldInt", "Can't use 'interpolate' style: Field lacks values on vertices.").throw()
243
245
}
244
246
247
+ if (sel) { // Ensure we have elements to plot
248
+ if (sel.count(2)==0) { // If the selection didn't include facets, infer them from the vertices
249
+ sel=sel.clone()
250
+ sel.addgrade(2)
251
+ } else if (sel.count(0)==0) { // If the selection didn't include vertices, infer them from the facets
252
+ sel=sel.clone()
253
+ sel.addgrade(0)
254
+ }
255
+
256
+ if (sel.count(2)==0 || sel.count(0)==0) Error("PltSlctnEmpty", "Selection is empty.").throw()
257
+ }
258
+
245
259
for (i in 0...nv) {
260
+ if (sel && !sel[0, i]) continue
246
261
var val = field[0, i]
247
262
if (!isnil(cmin)) val = max(cmin, val)
248
263
if (!isnil(cmax)) val = min(cmax, val)
@@ -260,6 +275,7 @@ fn plotfield(field, grade=nil, colormap=nil, style=nil, scale=true, filter=nil,
260
275
var cmat = Matrix(3, nel) // Make a color matrix
261
276
262
277
for (i in 0...nel) {
278
+ if (sel && !sel[g, i]) continue
263
279
var val = field[g, i]
264
280
if (!isnil(cmin)) val = max(cmin, val)
265
281
if (!isnil(cmax)) val = min(cmax, val)
@@ -272,7 +288,7 @@ fn plotfield(field, grade=nil, colormap=nil, style=nil, scale=true, filter=nil,
272
288
}
273
289
}
274
290
275
- var out = plotmesh(mesh, grade=showgrades, color=col, filter=filter, transmit=transmit)
291
+ var out = plotmesh(mesh, selection=sel, grade=showgrades, color=col, filter=filter, transmit=transmit)
276
292
277
293
if (isobject(scalebar)) {
278
294
var s = scalebar
0 commit comments