Importing the package

To use elasticity in a project, first you need to import the package and its desired features:

from elasticityproject.elasticityproject import ElasticityTheory, DirectionalProperties,VRH
from elasticityproject.plots3d import mayaviplot, YoungModulus3DPlot, LinearCompressibility3DPlot

Using the package

To use the package, you have to, first, get the specific crystal class that the material you want to simulate have, then, you have to pass the independent elastic constants as inputs of the class

The following crystal classes are implemented in the code:

  1. isotropic: 2 independent constants

  2. cubic: 3 independent constants

  3. hexagonal: 5 independent constants

  4. trigonal_1: 6 independent constants

  5. trigonal_2: 7 independent constants

  6. tetragonal_1: 6 independent constants

  7. tetragonal_2: 7 independent constants

  8. orthorhombic: 9 independent constants

  9. monoclinic_1: 13 independent constants

  10. monoclinic_2: 13 independent constants

  11. triclinic: 21 independent constants

Using the ElasticityTheory class

To use this class, simply pass the crystal_class input and the individual stiffness_constants. Its important to note that you should pass each stiffness constant as a single argument, arrays are not valid

From this class you can get the following properties:

  1. C: (6x6) numpy array, stiffness matrix based on the given constants and material crystal class

  2. S: (6x6) numpy array | compliance matrix based on the given constants and material crystal class

  3. St: (3x3x3x3) numpy array | compliance tensor based on the given constants and material crystal class

ElasProp = ElasticityTheory('hexagonal', 246.73, 126.66, 104.6,241.26, 58.48 )
ElasProp.C
array([[246.73 , 126.66 , 104.6  ,   0.   ,   0.   ,   0.   ],
       [126.66 , 246.73 , 104.6  ,   0.   ,   0.   ,   0.   ],
       [104.6  , 104.6  , 241.26 ,   0.   ,   0.   ,   0.   ],
       [  0.   ,   0.   ,   0.   ,  58.48 ,   0.   ,   0.   ],
       [  0.   ,   0.   ,   0.   ,   0.   ,  58.48 ,   0.   ],
       [  0.   ,   0.   ,   0.   ,   0.   ,   0.   ,  60.035]])

Using the DirectionalProperties class

To initiate an object of this class, simply pass the crystal_class input and the individual stiffness_constants. Its important to note that you should pass each stiffness constant as a single argument, arrays are not valid. Another important information is that this class should be mostly used by the plots3d module since it is its data foundation. However, if you want to use it without the plotting module, you need to initiate a numpy array with a shape (NxN) for the l direction and (NxNxN) for the n direction.

import numpy as np
#Initiate the class object
DirProp = DirectionalProperties('hexagonal', 246.73, 126.66, 104.6,241.26, 58.48 )
#Create the l direction array input
theta, phi = np.mgrid[0:np.pi:100, 0:2*np.pi:100]
ldir = np.array([np.sin(theta) * np.cos(phi), np.sin(theta) * np.sin(phi), np.cos(theta)])
#Calculate the property
DirProp.LinearCompressibility(ldir)
#Create the n direction array input
n_dir_theta, n_dir_phi, n_dir_psi = np.mgrid[0:np.pi:int(100) * 1j, 0:2*np.pi:int(100) * 1j, 0:2*np.pi:int(100) * 1j]
ndir = np.array([
                    np.sin(n_dir_phi) * np.sin(0)- np.cos(n_dir_theta)*np.cos(n_dir_phi)*np.cos(0),
                    -np.cos(n_dir_phi)*np.sin(0) - np.cos(n_dir_phi)*np.sin(n_dir_phi)*np.cos(0),
                    np.sin(n_dir_phi)*np.cos(0)
                ])
DirProp.ShearModulus(ldir,ndir)
array([[[58.48      , 58.48      , 58.48      , ..., 58.48      ,
         58.48      , 58.48      ],
        [58.18121611, 58.18121611, 58.18121611, ..., 58.18121611,
         58.18121611, 58.18121611],
        [57.31835088, 57.31835088, 57.31835088, ..., 57.31835088,
         57.31835088, 57.31835088],
        ...,
        [57.31835088, 57.31835088, 57.31835088, ..., 57.31835088,
         57.31835088, 57.31835088],
        [58.18121611, 58.18121611, 58.18121611, ..., 58.18121611,
         58.18121611, 58.18121611],
        [58.48      , 58.48      , 58.48      , ..., 58.48      ,
         58.48      , 58.48      ]],

       [[58.5389289 , 58.5389289 , 58.5389289 , ..., 58.5389289 ,
         58.5389289 , 58.5389289 ],
        [58.23930923, 58.23930923, 58.23930923, ..., 58.23930923,
         58.23930923, 58.23930923],
        [57.37405267, 57.37405267, 57.37405267, ..., 57.37405267,
         57.37405267, 57.37405267],
        ...,
        [57.37405267, 57.37405267, 57.37405267, ..., 57.37405267,
         57.37405267, 57.37405267],
        [58.23930923, 58.23930923, 58.23930923, ..., 58.23930923,
         58.23930923, 58.23930923],
        [58.5389289 , 58.5389289 , 58.5389289 , ..., 58.5389289 ,
         58.5389289 , 58.5389289 ]],

       [[58.71619137, 58.71619137, 58.71619137, ..., 58.71619137,
         58.71619137, 58.71619137],
        [58.41405118, 58.41405118, 58.41405118, ..., 58.41405118,
         58.41405118, 58.41405118],
        [57.54158371, 57.54158371, 57.54158371, ..., 57.54158371,
         57.54158371, 57.54158371],
        ...,
        [57.54158371, 57.54158371, 57.54158371, ..., 57.54158371,
         57.54158371, 57.54158371],
        [58.41405118, 58.41405118, 58.41405118, ..., 58.41405118,
         58.41405118, 58.41405118],
        [58.71619137, 58.71619137, 58.71619137, ..., 58.71619137,
         58.71619137, 58.71619137]],

       ...,

       [[58.71619137, 58.71619137, 58.71619137, ..., 58.71619137,
         58.71619137, 58.71619137],
        [58.41405118, 58.41405118, 58.41405118, ..., 58.41405118,
         58.41405118, 58.41405118],
        [57.54158371, 57.54158371, 57.54158371, ..., 57.54158371,
         57.54158371, 57.54158371],
        ...,
        [57.54158371, 57.54158371, 57.54158371, ..., 57.54158371,
         57.54158371, 57.54158371],
        [58.41405118, 58.41405118, 58.41405118, ..., 58.41405118,
         58.41405118, 58.41405118],
        [58.71619137, 58.71619137, 58.71619137, ..., 58.71619137,
         58.71619137, 58.71619137]],

       [[58.5389289 , 58.5389289 , 58.5389289 , ..., 58.5389289 ,
         58.5389289 , 58.5389289 ],
        [58.23930923, 58.23930923, 58.23930923, ..., 58.23930923,
         58.23930923, 58.23930923],
        [57.37405267, 57.37405267, 57.37405267, ..., 57.37405267,
         57.37405267, 57.37405267],
        ...,
        [57.37405267, 57.37405267, 57.37405267, ..., 57.37405267,
         57.37405267, 57.37405267],
        [58.23930923, 58.23930923, 58.23930923, ..., 58.23930923,
         58.23930923, 58.23930923],
        [58.5389289 , 58.5389289 , 58.5389289 , ..., 58.5389289 ,
         58.5389289 , 58.5389289 ]],

       [[58.48      , 58.48      , 58.48      , ..., 58.48      ,
         58.48      , 58.48      ],
        [58.18121611, 58.18121611, 58.18121611, ..., 58.18121611,
         58.18121611, 58.18121611],
        [57.31835088, 57.31835088, 57.31835088, ..., 57.31835088,
         57.31835088, 57.31835088],
        ...,
        [57.31835088, 57.31835088, 57.31835088, ..., 57.31835088,
         57.31835088, 57.31835088],
        [58.18121611, 58.18121611, 58.18121611, ..., 58.18121611,
         58.18121611, 58.18121611],
        [58.48      , 58.48      , 58.48      , ..., 58.48      ,
         58.48      , 58.48      ]]])

Using the VRH class

To use this class, simply pass the crystal_class input and the individual stiffness_constants. Its important to note that you should pass each stiffness constant as a single argument, arrays are not valid

From this class you can get the following properties:

  1. BR: Reuss approximation of linear compressibility

  2. GR: Reuss approximation of shear modulus

  3. BV: Voigt approximation of linear compressibility

  4. GV: Voigt approximation of shear modulus

  5. BH: Hill approximation of linear compressibility

  6. GH: Hill Reuss approximation of shear modulus

  7. BulkModulus: VRH approximation of Bulk Modulus using data from the three approximations

  8. YoungModulus: VRH approximation of Young Modulus using data from the three approximations

  9. PoissonRatio: VRH approximation of Poisson Ratio using data from the three approximations

VRHProp = VRH('hexagonal', 246.73, 126.66, 104.6,241.26, 58.48 )
#Use Reuss approximations
VRHProp.Reuss()
#Use Voigt approximations
VRHProp.Voigt()
#Use Hill approximations
VRHProp.Hill()
#Use VRH approximations
VRHProp.VRH()

Using plots3d module

This module generates the surface plot based on the data generated by the DirectionalProperties class. To use the 3d plot module its necessary to initiate a instance of directional property class to generate the data to be plotted. To this module there are 2 required arguments

  1. property: object, a instance of the object created by the DirectionalProperties class

  2. smoothness: int, degree of smoothness of the generated surface

There is also optional arguments to modify the action of the function:

  1. auto_extent: bool, flag to determine the axes extenxt will be generated automatically or via input

  2. axes_extent: int, extent of the axes, auto extent will override this parameter, default value is 4

  3. labels: array of str, labels of each axis, [0] element is x axis, [1] element is y axis, [2] element is z axis, default value is [‘x (GPa)’, ‘y (GPa)’, ‘z (GPa)’]

  4. offscreen: bool, flag to determine whether the graphics will be renderized in a GUI window or saved in a file

  5. filename: str, name of the generated file if offscren is true, default value is PlottedImage.png

DirProp = DirectionalProperties('orthorhombic', 26.47, 29.77, 21.71, 74.54, 29.76, 70.52, 23.63, 21.40, 30.71)
YoungModulus3DPlot(DirProp, smoothness=50)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[5], line 2
      1 DirProp = DirectionalProperties('orthorhombic', 26.47, 29.77, 21.71, 74.54, 29.76, 70.52, 23.63, 21.40, 30.71)
----> 2 YoungModulus3DPlot(DirProp, smoothness=50)

File ~/checkouts/readthedocs.org/user_builds/elasticity/envs/latest/lib/python3.9/site-packages/elasticityproject/plots3d.py:78, in YoungModulus3DPlot(material, *args, **kwargs)
     74 def YoungModulus3DPlot(material, *args, **kwargs):
     76     E = material.YoungModulus
---> 78     mayaviplot(E, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/elasticity/envs/latest/lib/python3.9/site-packages/elasticityproject/plots3d.py:52, in mayaviplot(property, smoothness, auto_extent, axes_extent, labels, offscreen, filename, *args, **kwargs)
     49 if offscreen:
     50     mlab.options.offscreen = True
---> 52 mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(500, 500))
     53 mlab.clf()
     55 mlab.mesh(x, y, z, scalars=case, colormap='plasma')

File ~/checkouts/readthedocs.org/user_builds/elasticity/envs/latest/lib/python3.9/site-packages/mayavi/tools/figure.py:64, in figure(figure, bgcolor, fgcolor, engine, size)
     62 else:
     63     if engine is None:
---> 64         engine = get_engine()
     65     if figure is None:
     66         name = max(__scene_number_list) + 1

File ~/checkouts/readthedocs.org/user_builds/elasticity/envs/latest/lib/python3.9/site-packages/mayavi/tools/engine_manager.py:94, in EngineManager.get_engine(self)
     91     suitable = [e for e in engines
     92                 if e.__class__.__name__ == 'Engine']
     93 if len(suitable) == 0:
---> 94     return self.new_engine()
     95 else:
     96     # Return the most engine add to the list most recently.
     97     self.current_engine = suitable[-1]

File ~/checkouts/readthedocs.org/user_builds/elasticity/envs/latest/lib/python3.9/site-packages/mayavi/tools/engine_manager.py:139, in EngineManager.new_engine(self)
    135 def new_engine(self):
    136     """ Creates a new engine, envisage or not depending on the
    137         options.
    138     """
--> 139     check_backend()
    140     if options.backend == 'envisage':
    141         from mayavi.plugins.app import Mayavi

File ~/checkouts/readthedocs.org/user_builds/elasticity/envs/latest/lib/python3.9/site-packages/mayavi/tools/engine_manager.py:42, in check_backend()
     37 if (options.backend != 'test' and not options.offscreen) and \
     38    (ETSConfig.toolkit in ('null', '') and env_toolkit != 'null'):
     39     msg = '''Could not import backend for traitsui.  Make sure you
     40     have a suitable UI toolkit like PyQt/PySide or wxPython
     41     installed.'''
---> 42     raise ImportError(msg)

ImportError: Could not import backend for traitsui.  Make sure you
        have a suitable UI toolkit like PyQt/PySide or wxPython
        installed.