shgpy.core.utilities module¶
- shgpy.core.utilities.make_tensor_complex(tensor, prefix=('real_', 'imag_'), suffix=('', ''))¶
Substitute e.g.
xin sympy expression withreal_x+1j*imag_x.In sympy, variables initalized by
x = sympy.symbols('x')are by default assumed to be complex. In order to make this more explicit (e.g. forgenerate_contracted_fourier_transforms()), we replacexbyreal_x + 1j*imag_x.- Parameters:
- tensorndarray
- prefixtuple of str, optional
The prefixes of the newly-created real and imaginary variables. Defaults to
('real_', 'imag_').- suffixtuple of str, optional
The prefixes of the newly-created real and imaginary variables. Defaults to
('', '').
- Returns:
- complex_tensorndarray
- shgpy.core.utilities.make_tensor_real(tensor)¶
Substitute e.g.
xin sympy expression with its real counterpart.In sympy, variables initalized by
x = sympy.symbols('x')are by default assumed to be complex. In order to make this more explicit (e.g. forgenerate_contracted_fourier_transforms()), we replacesympy.Symbol('x')bysympy.Symbol('x', real=True).- Parameters:
- tensorndarray
- Returns:
- real_tensorndarray
- shgpy.core.utilities.map_to_real(sym)¶
Map a sympy.Symbol to its real counterpart.
- shgpy.core.utilities.particularize(tensor, exclude=[], permute_all_indices=False)¶
Particularize tensor (e.g. enforce
chi_ijk = chi_ikj).Because (e.g.)
P_i = chi_ijk E_j E_k,chi_ijkneeds to be symmetric in its last two indices. This symmetry is not documented in SHG tables, so it needs to be implemented manually. Functions using thesolvefunction of sympy.solvers.- Parameters:
- tensorndarray
Tensor to be particularized.
- excludelist of sympy.Symbol objects
Variables to exlude from the solver. Defaults to
[].- permute_all_indicesbool, optional
Whether to permute all indices, not just the last two. Useful for materials where Kleinman symmetry is preserved. Default is False.
- Returns:
- particularized_tensorndarray
- shgpy.core.utilities.rotation_matrix3(n, t)¶
Returns the 3x3 matrix which rotates by t about n
- Parameters:
- nndarray
Axis of rotation (ndim = 3).
- tint, float, …
Angle (in radians) to rotate by.
- Returns:
- rotation_matrix3ndarray of float
- shgpy.core.utilities.rotation_matrix3symb(n, t, ndigits=16)¶
Duplicate of
rotation_matrix3(), but accepts sympy.Symbol angle argument.- Parameters:
- nndarray
Axis of rotation (ndim = 3).
- tsympy.Symbol, …
Angle to rotate by.
- Returns:
- rotation_matrix3symbndarray of sympy.Expr
- shgpy.core.utilities.rotation_matrix_from_two_vectors(v_initial, v_final, accuracy=0.01, ndigits=16)¶
Return rotation matrix which takes v_initial -> v_final.
- Parameters:
- v_initialndarray
- v_finalndarray
- accuracyfloat, optional
Precision to which v_final is achieved. Defaults to 0.1.
- ndigitsint, optional
Number of digits to round off to. Defaults to 16.
- Returns:
- rotation_matrix3ndarray of float
- shgpy.core.utilities.tensor_contract(tensor, index_pairs)¶
Contract a tensor against to pairs of indices.
- Parameters:
- tensorndarray
- index_pairsarray_like of array_like of int
List of pairs of indices, e.g.
[[1, 3], [2, 4]].
- shgpy.core.utilities.tensor_product(*tensors)¶
Tensor product of multiple tensors.
- shgpy.core.utilities.transform(tensor, operation)¶
Transform a tensor by a given operation.
- Parameters:
- tensorndarray
- operationndarray
Operation to transform tensor by. Should be rank 2.
- Returns:
- transformed_tensorndarray
- shgpy.core.utilities.union(*arrays)¶
Union of multiple arrays.