| 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 | if options.exist('layer'):
|
|---|
| 19 | nodes_per_elt = np.shape(md.mesh.elements2d)[1]
|
|---|
| 20 | else:
|
|---|
| 21 | nodes_per_elt = np.shape(md.mesh.elements)[1]
|
|---|
| 22 | #icefront check
|
|---|
| 23 | icefront = np.where(np.abs(np.sum(md.mask.ice_levelset[elements], 1)) != nodes_per_elt)
|
|---|
| 24 |
|
|---|
| 25 | #plot mesh
|
|---|
| 26 | if is2d:
|
|---|
| 27 | ax.triplot(x, y, elements)
|
|---|
| 28 |
|
|---|
| 29 | #highlight elements on neumann
|
|---|
| 30 | if len(icefront[0]) > 0:
|
|---|
| 31 | colors = np.asarray([0.5 for element in elements[icefront]])
|
|---|
| 32 | ax.tripcolor(x, y, elements[icefront], facecolors=colors, alpha=0.5, label='elements on ice front')
|
|---|
| 33 | else:
|
|---|
| 34 | ax = inset_axes(ax, width='100%', height='100%', loc=3, borderpad=0, axes_class=Axes3D)
|
|---|
| 35 |
|
|---|
| 36 | AB = elements[:, 0:2]
|
|---|
| 37 | BC = elements[:, 1:3]
|
|---|
| 38 | CA = np.vstack((elements[:, 2], elements[:, 0])).T
|
|---|
| 39 | DE = elements[:, 3:5]
|
|---|
| 40 | EF = elements[:, 4:]
|
|---|
| 41 | FD = np.vstack((elements[:, 5], elements[:, 3])).T
|
|---|
| 42 | AD = np.vstack((elements[:, 0], elements[:, 3])).T
|
|---|
| 43 | BE = np.vstack((elements[:, 1], elements[:, 4])).T
|
|---|
| 44 | CF = np.vstack((elements[:, 2], elements[:, 5])).T
|
|---|
| 45 |
|
|---|
| 46 | tmpa = np.vstack((AB, BC, CA, DE, EF, FD, AD, BE, CF))
|
|---|
| 47 | #deleting segments that appear multiple times
|
|---|
| 48 | tmpb = np.ascontiguousarray(tmpa).view(np.dtype((np.void, tmpa.dtype.itemsize * tmpa.shape[1])))
|
|---|
| 49 | _, idx = np.unique(tmpb, return_index=True)
|
|---|
| 50 | triel = tmpa[idx]
|
|---|
| 51 |
|
|---|
| 52 | for t, triangle in enumerate(triel):
|
|---|
| 53 | tri = list(zip(x[triangle], y[triangle], z[triangle]))
|
|---|
| 54 | facecolor = [0, 0, 0]
|
|---|
| 55 | if t in icefront:
|
|---|
| 56 | facecolor = [0.5, 0.5, 0.5]
|
|---|
| 57 | pl3 = Line3DCollection([tri], edgecolor='r', facecolor=facecolor)
|
|---|
| 58 | ax.add_collection3d(pl3)
|
|---|
| 59 |
|
|---|
| 60 | ax.set_xlim([min(x), max(x)])
|
|---|
| 61 | ax.set_ylim([min(y), max(y)])
|
|---|
| 62 | ax.set_zlim([min(z), max(z)])
|
|---|
| 63 | #highlight elements on neumann
|
|---|
| 64 |
|
|---|
| 65 | #apply options
|
|---|
| 66 | options.addfielddefault('title', 'Neumann boundary conditions')
|
|---|
| 67 | options.addfielddefault('colorbar', 'off')
|
|---|