Source code for elasticityproject.plots3d


#from mayavi import mlab
from mayavi import mlab
import numpy as np

#def mayaviplot(material_property, smoothness=151, auto_extent=True,axes_extent=1,labels=['x (GPa)', 'y (GPa)', 'z (GPa)'],filename='Young3D.png', offscreen=False, *args, **kwargs):
[docs]def mayaviplot(property, smoothness, auto_extent=True ,axes_extent=4,labels=['x (GPa)', 'y (GPa)', 'z (GPa)'], offscreen=False, filename='PlottedImage.png', *args, **kwargs): ''' Generates the surface plot based on the data generated by the DirectionalProperties class Parameters ---------- property: object a instance of the object created by the DirectionalProperties class smoothness: int degree of smoothness of the generated surface auto_extent: bool, optional flag to determine the axes extenxt will be generated automatically or via input axes_extent: int, optional extent of the axes, auto extent will override this parameter labels: array of str, optional labels of each axis, [0] element is x, [1] element is y, [2] element is z offscreen: bool, optional flag to determine whether the graphics will be renderized in a GUI window or saved in a file filename: str, optional name of the generated file if offscren is true Returns ---------- Example: ---------- DirProp = DirectionalProperties('orthorhombic', 26.47, 29.77, 21.71, 74.54, 29.76, 70.52, 23.63, 21.40, 30.71) YoungModulus3DPlot(DirProp, smoothness=N,auto_extent=True) ''' smoothness = int(smoothness) * 1j theta, phi = np.mgrid[0:np.pi:smoothness, 0:2*np.pi:smoothness] ldir = np.array([np.sin(theta) * np.cos(phi), np.sin(theta) * np.sin(phi), np.cos(theta)]) case = property(ldir) x = case * ldir[0] y = case * ldir[1] z = case * ldir[2] if offscreen: mlab.options.offscreen = True mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(500, 500)) mlab.clf() mlab.mesh(x, y, z, scalars=case, colormap='plasma') mlab.mesh(x, y, z, representation='wireframe', color=(.2, .2, .2), opacity=.1) if auto_extent: auto_extent=[x.max(),y.max(),z.max()] axes_extent=max(auto_extent) extent = [-axes_extent, axes_extent, -axes_extent, axes_extent, -axes_extent, axes_extent] ax = mlab.axes(extent=extent, xlabel=labels[0], ylabel=labels[1], zlabel=labels[2]) ax.axes.font_factor = 2 mlab.outline(extent=extent) if offscreen: mlab.savefig(filename) else: mlab.show()
[docs]def YoungModulus3DPlot(material, *args, **kwargs): E = material.YoungModulus mayaviplot(E, *args, **kwargs)
[docs]def LinearCompressibility3DPlot(material, *args, **kwargs): B = material.LinearCompressibility mayaviplot(B, *args, **kwargs)