| 1 | import numpy as np
|
|---|
| 2 | from processmesh import processmesh
|
|---|
| 3 | from mpl_toolkits.mplot3d.art3d import Line3DCollection
|
|---|
| 4 | from mpl_toolkits.axes_grid1.inset_locator import inset_axes
|
|---|
| 5 | from mpl_toolkits.mplot3d import Axes3D
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | def plot_icefront(md, options, fig, ax):
|
|---|
| 9 | #PLOT_ICEFRONT - plot segment on neumann BC
|
|---|
| 10 | #
|
|---|
| 11 | # Usage:
|
|---|
| 12 | # plot_icefront(md, options, width, i)
|
|---|
| 13 | #
|
|---|
| 14 | # See also: PLOTMODEL
|
|---|
| 15 | #process mesh and data
|
|---|
| 16 | x, y, z, elements, is2d, isplanet = processmesh(md, [], options)
|
|---|
| 17 |
|
|---|
| 18 | icenodes = md.mask.ice_levelset < 0
|
|---|
| 19 | iceelement = np.sum(icenodes[elements], axis=1)
|
|---|
| 20 |
|
|---|
| 21 | if options.exist('layer'):
|
|---|
| 22 | nodes_per_elt = np.shape(md.mesh.elements2d)[1]
|
|---|
| 23 | else:
|
|---|
| 24 | nodes_per_elt = np.shape(md.mesh.elements)[1]
|
|---|
| 25 | #icefront check
|
|---|
| 26 | icefront = np.where(np.logical_and(iceelement != nodes_per_elt, iceelement != 0))
|
|---|
| 27 |
|
|---|
| 28 | #plot mesh
|
|---|
| 29 | if is2d:
|
|---|
| 30 | ax.triplot(x, y, elements)
|
|---|
| 31 |
|
|---|
| 32 | #highlight elements on neumann
|
|---|
| 33 | if len(icefront[0]) > 0:
|
|---|
| 34 | colors = np.asarray([0.5 for element in elements[icefront]])
|
|---|
| 35 | ax.tripcolor(x, y, elements[icefront], facecolors=colors, alpha=0.5, label='elements on ice front')
|
|---|
| 36 | else:
|
|---|
| 37 | ax = inset_axes(ax, width='100%', height='100%', loc=3, borderpad=0, axes_class=Axes3D)
|
|---|
| 38 |
|
|---|
| 39 | AB = elements[:, 0:2]
|
|---|
| 40 | BC = elements[:, 1:3]
|
|---|
| 41 | CA = np.vstack((elements[:, 2], elements[:, 0])).T
|
|---|
| 42 | DE = elements[:, 3:5]
|
|---|
| 43 | EF = elements[:, 4:]
|
|---|
| 44 | FD = np.vstack((elements[:, 5], elements[:, 3])).T
|
|---|
| 45 | AD = np.vstack((elements[:, 0], elements[:, 3])).T
|
|---|
| 46 | BE = np.vstack((elements[:, 1], elements[:, 4])).T
|
|---|
| 47 | CF = np.vstack((elements[:, 2], elements[:, 5])).T
|
|---|
| 48 |
|
|---|
| 49 | tmpa = np.vstack((AB, BC, CA, DE, EF, FD, AD, BE, CF))
|
|---|
| 50 | #deleting segments that appear multiple times
|
|---|
| 51 | tmpb = np.ascontiguousarray(tmpa).view(np.dtype((np.void, tmpa.dtype.itemsize * tmpa.shape[1])))
|
|---|
| 52 | _, idx = np.unique(tmpb, return_index=True)
|
|---|
| 53 | triel = tmpa[idx]
|
|---|
| 54 |
|
|---|
| 55 | for t, triangle in enumerate(triel):
|
|---|
| 56 | tri = list(zip(x[triangle], y[triangle], z[triangle]))
|
|---|
| 57 | facecolor = [0, 0, 0]
|
|---|
| 58 | if t in icefront:
|
|---|
| 59 | facecolor = [0.5, 0.5, 0.5]
|
|---|
| 60 | pl3 = Line3DCollection([tri], edgecolor='r', facecolor=facecolor)
|
|---|
| 61 | ax.add_collection3d(pl3)
|
|---|
| 62 |
|
|---|
| 63 | ax.set_xlim([min(x), max(x)])
|
|---|
| 64 | ax.set_ylim([min(y), max(y)])
|
|---|
| 65 | ax.set_zlim([min(z), max(z)])
|
|---|
| 66 | #highlight elements on neumann
|
|---|
| 67 |
|
|---|
| 68 | #apply options
|
|---|
| 69 | options.addfielddefault('title', 'Neumann boundary conditions')
|
|---|
| 70 | options.addfielddefault('colorbar', 'off')
|
|---|