diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 3d73861ad..5eca451c6 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -753,7 +753,7 @@ class Geom: if fill is None: fill = np.nanmax(self.material) + 1 dtype = float if np.isnan(fill) or int(fill) != fill or self.material.dtype==np.float else int - Eulers = R.as_Eulers(degrees=True) + Eulers = R.as_Euler_angles(degrees=True) material_in = self.material.copy() # These rotations are always applied in the reference coordinate system, i.e. (z,x,z) not (z,x',z'') diff --git a/python/damask/_orientation.py b/python/damask/_orientation.py index ee2462287..a840a46db 100644 --- a/python/damask/_orientation.py +++ b/python/damask/_orientation.py @@ -86,8 +86,8 @@ class Orientation(Rotation): >>> damask.Orientation.from_random(shape=(3,5),lattice='tetragonal').reduced Disorientation between two specific orientations of hexagonal symmetry: - >>> a = damask.Orientation.from_Eulers(phi=[123,32,21],degrees=True,lattice='hexagonal') - >>> b = damask.Orientation.from_Eulers(phi=[104,11,87],degrees=True,lattice='hexagonal') + >>> a = damask.Orientation.from_Euler_angles(phi=[123,32,21],degrees=True,lattice='hexagonal') + >>> b = damask.Orientation.from_Euler_angles(phi=[104,11,87],degrees=True,lattice='hexagonal') >>> a.disorientation(b) Inverse pole figure color of the e_3 direction for a crystal in "Cube" orientation with cubic symmetry: @@ -95,7 +95,7 @@ class Orientation(Rotation): >>> o.IPF_color(o.to_SST(np.array([0,0,1]))) Schmid matrix (in lab frame) of slip systems of a face-centered cubic crystal in "Goss" orientation: - >>> damask.Orientation.from_Eulers(phi=[0,45,0],degrees=True,lattice='cF').Schmid('slip') + >>> damask.Orientation.from_Euler_angles(phi=[0,45,0],degrees=True,lattice='cF').Schmid('slip') """ @@ -291,9 +291,9 @@ class Orientation(Rotation): @classmethod - @extended_docstring(Rotation.from_Eulers) - def from_Eulers(cls,**kwargs): - return cls(rotation=Rotation.from_Eulers(**kwargs),**kwargs) + @extended_docstring(Rotation.from_Euler_angles) + def from_Euler_angles(cls,**kwargs): + return cls(rotation=Rotation.from_Euler_angles(**kwargs),**kwargs) @classmethod @@ -315,9 +315,9 @@ class Orientation(Rotation): @classmethod - @extended_docstring(Rotation.from_Rodrigues) - def from_Rodrigues(cls,**kwargs): - return cls(rotation=Rotation.from_Rodrigues(**kwargs),**kwargs) + @extended_docstring(Rotation.from_Rodrigues_vector) + def from_Rodrigues_vector(cls,**kwargs): + return cls(rotation=Rotation.from_Rodrigues_vector(**kwargs),**kwargs) @classmethod @@ -496,7 +496,7 @@ class Orientation(Rotation): if self.family is None: raise ValueError('Missing crystal symmetry') - rho_abs = np.abs(self.as_Rodrigues(vector=True)) + rho_abs = np.abs(self.as_Rodrigues_vector(vector=True)) with np.errstate(invalid='ignore'): # using '*'/prod for 'and' @@ -539,7 +539,7 @@ class Orientation(Rotation): if self.family is None: raise ValueError('Missing crystal symmetry') - rho = self.as_Rodrigues(vector=True) + rho = self.as_Rodrigues_vector(vector=True) with np.errstate(invalid='ignore'): if self.family == 'cubic': diff --git a/python/damask/_result.py b/python/damask/_result.py index ca7d8ec71..9859f8c4d 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -597,19 +597,19 @@ class Result: @staticmethod - def _add_Cauchy(P,F): + def _add_stress_Cauchy(P,F): return { - 'data': mechanics.Cauchy(P['data'],F['data']), + 'data': mechanics.stress_Cauchy(P['data'],F['data']), 'label': 'sigma', 'meta': { 'Unit': P['meta']['Unit'], 'Description': "Cauchy stress calculated " f"from {P['label']} ({P['meta']['Description']})" f" and {F['label']} ({F['meta']['Description']})", - 'Creator': 'add_Cauchy' + 'Creator': 'add_stress_Cauchy' } } - def add_Cauchy(self,P='P',F='F'): + def add_stress_Cauchy(self,P='P',F='F'): """ Add Cauchy stress calculated from first Piola-Kirchhoff stress and deformation gradient. @@ -621,7 +621,7 @@ class Result: Label of the dataset containing the deformation gradient. Defaults to ‘F’. """ - self._add_generic_pointwise(self._add_Cauchy,{'P':P,'F':F}) + self._add_generic_pointwise(self._add_stress_Cauchy,{'P':P,'F':F}) @staticmethod @@ -798,7 +798,7 @@ class Result: @staticmethod - def _add_Mises(T_sym,kind): + def _add_equivalent_Mises(T_sym,kind): k = kind if k is None: if T_sym['meta']['Unit'] == '1': @@ -809,7 +809,8 @@ class Result: raise ValueError('invalid von Mises kind {kind}') return { - 'data': (mechanics.Mises_strain if k=='strain' else mechanics.Mises_stress)(T_sym['data']), + 'data': (mechanics.equivalent_strain_Mises if k=='strain' else \ + mechanics.equivalent_stress_Mises)(T_sym['data']), 'label': f"{T_sym['label']}_vM", 'meta': { 'Unit': T_sym['meta']['Unit'], @@ -817,7 +818,7 @@ class Result: 'Creator': 'add_Mises' } } - def add_Mises(self,T_sym,kind=None): + def add_equivalent_Mises(self,T_sym,kind=None): """ Add the equivalent Mises stress or strain of a symmetric tensor. @@ -830,7 +831,7 @@ class Result: it is selected based on the unit of the dataset ('1' -> strain, 'Pa' -> stress'). """ - self._add_generic_pointwise(self._add_Mises,{'T_sym':T_sym},{'kind':kind}) + self._add_generic_pointwise(self._add_equivalent_Mises,{'T_sym':T_sym},{'kind':kind}) @staticmethod @@ -872,19 +873,19 @@ class Result: @staticmethod - def _add_PK2(P,F): + def _add_stress_second_Piola_Kirchhoff(P,F): return { - 'data': mechanics.PK2(P['data'],F['data']), + 'data': mechanics.stress_second_Piola_Kirchhoff(P['data'],F['data']), 'label': 'S', 'meta': { 'Unit': P['meta']['Unit'], 'Description': "2. Piola-Kirchhoff stress calculated " f"from {P['label']} ({P['meta']['Description']})" f" and {F['label']} ({F['meta']['Description']})", - 'Creator': 'add_PK2' + 'Creator': 'add_stress_second_Piola_Kirchhoff' } } - def add_PK2(self,P='P',F='F'): + def add_stress_second_Piola_Kirchhoff(self,P='P',F='F'): """ Add second Piola-Kirchhoff stress calculated from first Piola-Kirchhoff stress and deformation gradient. @@ -896,7 +897,7 @@ class Result: Label of deformation gradient dataset. Defaults to ‘F’. """ - self._add_generic_pointwise(self._add_PK2,{'P':P,'F':F}) + self._add_generic_pointwise(self._add_stress_second_Piola_Kirchhoff,{'P':P,'F':F}) # The add_pole functionality needs discussion. @@ -1297,3 +1298,6 @@ class Result: v.add(u,'u') v.save(f'{self.fname.stem}_inc{inc[3:].zfill(N_digits)}') + + +Result.add_PK2 = Result.add_stress_second_Piola_Kirchhoff diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index 4cf8cfcca..e695ce407 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -66,12 +66,12 @@ class Rotation: def __repr__(self): """Represent rotation as unit quaternion, rotation matrix, and Bunge-Euler angles.""" - return 'Quaternions:\n'+str(self.quaternion) \ + return 'As quaternions:\n'+str(self.quaternion) \ if self.quaternion.shape != (4,) else \ '\n'.join([ 'Quaternion: (real={:.3f}, imag=<{:+.3f}, {:+.3f}, {:+.3f}>)'.format(*(self.quaternion)), 'Matrix:\n{}'.format(np.round(self.as_matrix(),8)), - 'Bunge Eulers / deg: ({:3.2f}, {:3.2f}, {:3.2f})'.format(*self.as_Eulers(degrees=True)), + 'Bunge Eulers / deg: ({:3.2f}, {:3.2f}, {:3.2f})'.format(*self.as_Euler_angles(degrees=True)), ]) @@ -314,7 +314,7 @@ class Rotation: """ return self.quaternion.copy() - def as_Eulers(self, + def as_Euler_angles(self, degrees = False): """ Represent as Bunge-Euler angles. @@ -372,7 +372,7 @@ class Rotation: """ return Rotation._qu2om(self.quaternion) - def as_Rodrigues(self, + def as_Rodrigues_vector(self, vector = False): """ Represent as Rodrigues-Frank vector with separated axis and angle argument. @@ -462,7 +462,7 @@ class Rotation: return Rotation(qu) @staticmethod - def from_Eulers(phi, + def from_Euler_angles(phi, degrees = False, **kwargs): """ @@ -606,7 +606,7 @@ class Rotation: @staticmethod - def from_Rodrigues(rho, + def from_Rodrigues_vector(rho, normalize = False, P = -1, **kwargs): @@ -784,7 +784,7 @@ class Rotation: dg = 1.0 if fractions else _dg(Eulers,degrees) dV_V = dg * np.maximum(0.0,weights.squeeze()) - return Rotation.from_Eulers(Eulers[util.hybrid_IA(dV_V,N,seed)],degrees) + return Rotation.from_Euler_angles(Eulers[util.hybrid_IA(dV_V,N,seed)],degrees) @staticmethod diff --git a/python/damask/mechanics.py b/python/damask/mechanics.py index ef2434e00..bab41a18c 100644 --- a/python/damask/mechanics.py +++ b/python/damask/mechanics.py @@ -5,7 +5,7 @@ from . import tensor import numpy as _np -def Cauchy_Green_deformation_left(F): +def deformation_Cauchy_Green_left(F): """ Calculate left Cauchy-Green deformation tensor (Finger deformation tensor). @@ -23,7 +23,7 @@ def Cauchy_Green_deformation_left(F): return _np.matmul(F,tensor.transpose(F)) -def Cauchy_Green_deformation_right(F): +def deformation_Cauchy_Green_right(F): """ Calculate right Cauchy-Green deformation tensor. @@ -41,7 +41,7 @@ def Cauchy_Green_deformation_right(F): return _np.matmul(tensor.transpose(F),F) -def Cauchy(P,F): +def stress_Cauchy(P,F): """ Calculate the Cauchy stress (true stress). @@ -101,7 +101,7 @@ def maximum_shear(T_sym): return (w[...,0] - w[...,2])*0.5 -def Mises_strain(epsilon): +def equivalent_strain_Mises(epsilon): """ Calculate the Mises equivalent of a strain tensor. @@ -116,10 +116,10 @@ def Mises_strain(epsilon): Von Mises equivalent strain of epsilon. """ - return _Mises(epsilon,2.0/3.0) + return _equivalent_Mises(epsilon,2.0/3.0) -def Mises_stress(sigma): +def equivalent_stress_Mises(sigma): """ Calculate the Mises equivalent of a stress tensor. @@ -134,10 +134,10 @@ def Mises_stress(sigma): Von Mises equivalent stress of sigma. """ - return _Mises(sigma,3.0/2.0) + return _equivalent_Mises(sigma,3.0/2.0) -def PK2(P,F): +def stress_second_Piola_Kirchhoff(P,F): """ Calculate the second Piola-Kirchhoff stress. @@ -226,9 +226,9 @@ def strain(F,t,m): """ if t == 'V': - w,n = _np.linalg.eigh(Cauchy_Green_deformation_left(F)) + w,n = _np.linalg.eigh(deformation_Cauchy_Green_left(F)) elif t == 'U': - w,n = _np.linalg.eigh(Cauchy_Green_deformation_right(F)) + w,n = _np.linalg.eigh(deformation_Cauchy_Green_right(F)) if m > 0.0: eps = 1.0/(2.0*abs(m)) * (+ _np.einsum('...j,...kj,...lj',w**m,n,n) - _np.eye(3)) @@ -304,7 +304,7 @@ def _polar_decomposition(T,requested): return tuple(output) -def _Mises(T_sym,s): +def _equivalent_Mises(T_sym,s): """ Base equation for Mises equivalent of a stress or strain tensor. diff --git a/python/tests/test_Geom.py b/python/tests/test_Geom.py index a9b9c91b5..b9b8d33b2 100644 --- a/python/tests/test_Geom.py +++ b/python/tests/test_Geom.py @@ -223,7 +223,7 @@ class TestGeom: @pytest.mark.parametrize('Eulers',[[32.0,68.0,21.0], [0.0,32.0,240.0]]) def test_rotate(self,default,update,reference_dir,Eulers): - modified = default.rotate(Rotation.from_Eulers(Eulers,degrees=True)) + modified = default.rotate(Rotation.from_Euler_angles(Eulers,degrees=True)) tag = f'Eulers_{util.srepr(Eulers,"-")}' reference = reference_dir/f'rotate_{tag}.vtr' if update: modified.save(reference) diff --git a/python/tests/test_Orientation.py b/python/tests/test_Orientation.py index fe35bda14..8a3f85e78 100644 --- a/python/tests/test_Orientation.py +++ b/python/tests/test_Orientation.py @@ -16,7 +16,7 @@ def reference_dir(reference_dir_base): @pytest.fixture def set_of_rodrigues(set_of_quaternions): - return Rotation(set_of_quaternions).as_Rodrigues()[:200] + return Rotation(set_of_quaternions).as_Rodrigues_vector()[:200] class TestOrientation: @@ -90,8 +90,8 @@ class TestOrientation: assert np.all(Orientation.from_quaternion(q=np.array([1,0,0,0]),lattice='triclinic').as_matrix() == np.eye(3)) - def test_from_Eulers(self): - assert np.all(Orientation.from_Eulers(phi=np.zeros(3),lattice='triclinic').as_matrix() + def test_from_Euler_angles(self): + assert np.all(Orientation.from_Euler_angles(phi=np.zeros(3),lattice='triclinic').as_matrix() == np.eye(3)) def test_from_axis_angle(self): @@ -106,8 +106,8 @@ class TestOrientation: assert np.all(Orientation.from_matrix(R=np.eye(3),lattice='triclinic').as_matrix() == np.eye(3)) - def test_from_Rodrigues(self): - assert np.all(Orientation.from_Rodrigues(rho=np.array([0,0,1,0]),lattice='triclinic').as_matrix() + def test_from_Rodrigues_vector(self): + assert np.all(Orientation.from_Rodrigues_vector(rho=np.array([0,0,1,0]),lattice='triclinic').as_matrix() == np.eye(3)) def test_from_homochoric(self): @@ -208,7 +208,7 @@ class TestOrientation: @pytest.mark.parametrize('lattice',Orientation.crystal_families) def test_disorientation360(self,lattice): o_1 = Orientation(Rotation(),lattice) - o_2 = Orientation.from_Eulers(lattice=lattice,phi=[360,0,0],degrees=True) + o_2 = Orientation.from_Euler_angles(lattice=lattice,phi=[360,0,0],degrees=True) assert np.allclose((o_1.disorientation(o_2)).as_matrix(),np.eye(3)) @pytest.mark.parametrize('lattice',Orientation.crystal_families) @@ -275,16 +275,16 @@ class TestOrientation: @pytest.mark.parametrize('lattice',Orientation.crystal_families) def test_in_FZ_vectorization(self,set_of_rodrigues,lattice): - result = Orientation.from_Rodrigues(rho=set_of_rodrigues.reshape((50,4,-1)),lattice=lattice).in_FZ.reshape(-1) + result = Orientation.from_Rodrigues_vector(rho=set_of_rodrigues.reshape((50,4,-1)),lattice=lattice).in_FZ.reshape(-1) for r,rho in zip(result,set_of_rodrigues[:len(result)]): - assert r == Orientation.from_Rodrigues(rho=rho,lattice=lattice).in_FZ + assert r == Orientation.from_Rodrigues_vector(rho=rho,lattice=lattice).in_FZ @pytest.mark.parametrize('lattice',Orientation.crystal_families) def test_in_disorientation_FZ_vectorization(self,set_of_rodrigues,lattice): - result = Orientation.from_Rodrigues(rho=set_of_rodrigues.reshape((50,4,-1)), + result = Orientation.from_Rodrigues_vector(rho=set_of_rodrigues.reshape((50,4,-1)), lattice=lattice).in_disorientation_FZ.reshape(-1) for r,rho in zip(result,set_of_rodrigues[:len(result)]): - assert r == Orientation.from_Rodrigues(rho=rho,lattice=lattice).in_disorientation_FZ + assert r == Orientation.from_Rodrigues_vector(rho=rho,lattice=lattice).in_disorientation_FZ @pytest.mark.parametrize('proper',[True,False]) @pytest.mark.parametrize('lattice',Orientation.crystal_families) @@ -417,7 +417,7 @@ class TestOrientation: def test_relationship_reference(self,update,reference_dir,model,lattice): reference = reference_dir/f'{lattice}_{model}.txt' o = Orientation(lattice=lattice) - eu = o.related(model).as_Eulers(degrees=True) + eu = o.related(model).as_Euler_angles(degrees=True) if update: coords = np.array([(1,i+1) for i,x in enumerate(eu)]) Table(eu,{'Eulers':(3,)})\ diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index 0613716f6..46b947cdc 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -121,13 +121,13 @@ class TestResult: in_file = default.read_dataset(loc['x'],0) assert np.allclose(in_memory,in_file) - def test_add_Cauchy(self,default): - default.add_Cauchy('P','F') + def test_add_stress_Cauchy(self,default): + default.add_stress_Cauchy('P','F') loc = {'F': default.get_dataset_location('F'), 'P': default.get_dataset_location('P'), 'sigma':default.get_dataset_location('sigma')} - in_memory = mechanics.Cauchy(default.read_dataset(loc['P'],0), - default.read_dataset(loc['F'],0)) + in_memory = mechanics.stress_Cauchy(default.read_dataset(loc['P'],0), + default.read_dataset(loc['F'],0)) in_file = default.read_dataset(loc['sigma'],0) assert np.allclose(in_memory,in_file) @@ -149,7 +149,7 @@ class TestResult: @pytest.mark.parametrize('eigenvalue,function',[('max',np.amax),('min',np.amin)]) def test_add_eigenvalue(self,default,eigenvalue,function): - default.add_Cauchy('P','F') + default.add_stress_Cauchy('P','F') default.add_eigenvalue('sigma',eigenvalue) loc = {'sigma' :default.get_dataset_location('sigma'), 'lambda':default.get_dataset_location(f'lambda_{eigenvalue}(sigma)')} @@ -159,7 +159,7 @@ class TestResult: @pytest.mark.parametrize('eigenvalue,idx',[('max',2),('mid',1),('min',0)]) def test_add_eigenvector(self,default,eigenvalue,idx): - default.add_Cauchy('P','F') + default.add_stress_Cauchy('P','F') default.add_eigenvector('sigma',eigenvalue) loc = {'sigma' :default.get_dataset_location('sigma'), 'v(sigma)':default.get_dataset_location(f'v_{eigenvalue}(sigma)')} @@ -183,7 +183,7 @@ class TestResult: assert np.allclose(in_memory,in_file) def test_add_maximum_shear(self,default): - default.add_Cauchy('P','F') + default.add_stress_Cauchy('P','F') default.add_maximum_shear('sigma') loc = {'sigma' :default.get_dataset_location('sigma'), 'max_shear(sigma)':default.get_dataset_location('max_shear(sigma)')} @@ -196,34 +196,34 @@ class TestResult: m = np.random.random()*2.0 - 1.0 default.add_strain('F',t,m) label = f'epsilon_{t}^{m}(F)' - default.add_Mises(label) + default.add_equivalent_Mises(label) loc = {label :default.get_dataset_location(label), label+'_vM':default.get_dataset_location(label+'_vM')} - in_memory = mechanics.Mises_strain(default.read_dataset(loc[label],0)).reshape(-1,1) + in_memory = mechanics.equivalent_strain_Mises(default.read_dataset(loc[label],0)).reshape(-1,1) in_file = default.read_dataset(loc[label+'_vM'],0) assert np.allclose(in_memory,in_file) def test_add_Mises_stress(self,default): - default.add_Cauchy('P','F') - default.add_Mises('sigma') + default.add_stress_Cauchy('P','F') + default.add_equivalent_Mises('sigma') loc = {'sigma' :default.get_dataset_location('sigma'), 'sigma_vM':default.get_dataset_location('sigma_vM')} - in_memory = mechanics.Mises_stress(default.read_dataset(loc['sigma'],0)).reshape(-1,1) + in_memory = mechanics.equivalent_stress_Mises(default.read_dataset(loc['sigma'],0)).reshape(-1,1) in_file = default.read_dataset(loc['sigma_vM'],0) assert np.allclose(in_memory,in_file) def test_add_Mises_invalid(self,default): - default.add_Cauchy('P','F') + default.add_stress_Cauchy('P','F') default.add_calculation('sigma_y','#sigma#',unit='y') - default.add_Mises('sigma_y') + default.add_equivalent_Mises('sigma_y') assert default.get_dataset_location('sigma_y_vM') == [] def test_add_Mises_stress_strain(self,default): - default.add_Cauchy('P','F') + default.add_stress_Cauchy('P','F') default.add_calculation('sigma_y','#sigma#',unit='y') default.add_calculation('sigma_x','#sigma#',unit='x') - default.add_Mises('sigma_y',kind='strain') - default.add_Mises('sigma_x',kind='stress') + default.add_equivalent_Mises('sigma_y',kind='strain') + default.add_equivalent_Mises('sigma_x',kind='stress') loc = {'y' :default.get_dataset_location('sigma_y_vM'), 'x' :default.get_dataset_location('sigma_x_vM')} assert not np.allclose(default.read_dataset(loc['y'],0),default.read_dataset(loc['x'],0)) @@ -236,13 +236,13 @@ class TestResult: in_file = default.read_dataset(loc['|F|_1'],0) assert np.allclose(in_memory,in_file) - def test_add_PK2(self,default): - default.add_PK2('P','F') + def test_add_stress_second_Piola_Kirchhoff(self,default): + default.add_stress_second_Piola_Kirchhoff('P','F') loc = {'F':default.get_dataset_location('F'), 'P':default.get_dataset_location('P'), 'S':default.get_dataset_location('S')} - in_memory = mechanics.PK2(default.read_dataset(loc['P'],0), - default.read_dataset(loc['F'],0)) + in_memory = mechanics.stress_second_Piola_Kirchhoff(default.read_dataset(loc['P'],0), + default.read_dataset(loc['F'],0)) in_file = default.read_dataset(loc['S'],0) assert np.allclose(in_memory,in_file) @@ -312,7 +312,7 @@ class TestResult: def test_add_overwrite(self,default,overwrite): default.pick('times',default.times_in_range(0,np.inf)[-1]) - default.add_Cauchy() + default.add_stress_Cauchy() loc = default.get_dataset_location('sigma') with h5py.File(default.fname,'r') as f: # h5py3 compatibility diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index 9361008e5..ad4e4e702 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -522,7 +522,7 @@ class TestRotation: def test_Eulers_internal(self,set_of_rotations,forward,backward): """Ensure invariance of conversion from Euler angles and back.""" for rot in set_of_rotations: - m = rot.as_Eulers() + m = rot.as_Euler_angles() o = backward(forward(m)) u = np.array([np.pi*2,np.pi,np.pi*2]) ok = np.allclose(m,o,atol=atol) @@ -559,7 +559,7 @@ class TestRotation: """Ensure invariance of conversion from Rodrigues-Frank vector and back.""" cutoff = np.tan(np.pi*.5*(1.-1e-4)) for rot in set_of_rotations: - m = rot.as_Rodrigues() + m = rot.as_Rodrigues_vector() o = backward(forward(m)) ok = np.allclose(np.clip(m,None,cutoff),np.clip(o,None,cutoff),atol=atol) ok = ok or np.isclose(m[3],0.0,atol=atol) @@ -626,7 +626,7 @@ class TestRotation: (Rotation._eu2ro,eu2ro)]) def test_Eulers_vectorization(self,set_of_rotations,vectorized,single): """Check vectorized implementation for Euler angles against single point calculation.""" - eu = np.array([rot.as_Eulers() for rot in set_of_rotations]) + eu = np.array([rot.as_Euler_angles() for rot in set_of_rotations]) vectorized(eu.reshape(eu.shape[0]//2,-1,3)) co = vectorized(eu) for e,c in zip(eu,co): @@ -649,7 +649,7 @@ class TestRotation: (Rotation._ro2ho,ro2ho)]) def test_Rodrigues_vectorization(self,set_of_rotations,vectorized,single): """Check vectorized implementation for Rodrigues-Frank vector against single point calculation.""" - ro = np.array([rot.as_Rodrigues() for rot in set_of_rotations]) + ro = np.array([rot.as_Rodrigues_vector() for rot in set_of_rotations]) vectorized(ro.reshape(ro.shape[0]//2,-1,4)) co = vectorized(ro) for r,c in zip(ro,co): @@ -687,7 +687,7 @@ class TestRotation: def test_Eulers(self,set_of_rotations,degrees): for rot in set_of_rotations: m = rot.as_quaternion() - o = Rotation.from_Eulers(rot.as_Eulers(degrees),degrees).as_quaternion() + o = Rotation.from_Euler_angles(rot.as_Euler_angles(degrees),degrees).as_quaternion() ok = np.allclose(m,o,atol=atol) if np.isclose(rot.as_quaternion()[0],0.0,atol=atol): ok |= np.allclose(m*-1.,o,atol=atol) @@ -699,8 +699,8 @@ class TestRotation: def test_axis_angle(self,set_of_rotations,degrees,normalize,P): c = np.array([P*-1,P*-1,P*-1,1.]) for rot in set_of_rotations: - m = rot.as_Eulers() - o = Rotation.from_axis_angle(rot.as_axis_angle(degrees)*c,degrees,normalize,P).as_Eulers() + m = rot.as_Euler_angles() + o = Rotation.from_axis_angle(rot.as_axis_angle(degrees)*c,degrees,normalize,P).as_Euler_angles() u = np.array([np.pi*2,np.pi,np.pi*2]) ok = np.allclose(m,o,atol=atol) ok |= np.allclose(np.where(np.isclose(m,u),m-u,m),np.where(np.isclose(o,u),o-u,o),atol=atol) @@ -726,7 +726,7 @@ class TestRotation: c = np.array([P*-1,P*-1,P*-1,1.]) for rot in set_of_rotations: m = rot.as_matrix() - o = Rotation.from_Rodrigues(rot.as_Rodrigues()*c,normalize,P).as_matrix() + o = Rotation.from_Rodrigues_vector(rot.as_Rodrigues_vector()*c,normalize,P).as_matrix() ok = np.allclose(m,o,atol=atol) assert ok and np.isclose(np.linalg.det(o),1.0), f'{m},{o}' @@ -734,8 +734,8 @@ class TestRotation: def test_homochoric(self,set_of_rotations,P): cutoff = np.tan(np.pi*.5*(1.-1e-4)) for rot in set_of_rotations: - m = rot.as_Rodrigues() - o = Rotation.from_homochoric(rot.as_homochoric()*P*-1,P).as_Rodrigues() + m = rot.as_Rodrigues_vector() + o = Rotation.from_homochoric(rot.as_homochoric()*P*-1,P).as_Rodrigues_vector() ok = np.allclose(np.clip(m,None,cutoff),np.clip(o,None,cutoff),atol=atol) ok = ok or np.isclose(m[3],0.0,atol=atol) assert ok and np.isclose(np.linalg.norm(o[:3]),1.0), f'{m},{o},{rot.as_quaternion()}' @@ -819,10 +819,10 @@ class TestRotation: assert r == r.flatten(order).reshape(shape,order) @pytest.mark.parametrize('function',[Rotation.from_quaternion, - Rotation.from_Eulers, + Rotation.from_Euler_angles, Rotation.from_axis_angle, Rotation.from_matrix, - Rotation.from_Rodrigues, + Rotation.from_Rodrigues_vector, Rotation.from_homochoric, Rotation.from_cubochoric]) def test_invalid_shape(self,function): @@ -832,7 +832,7 @@ class TestRotation: @pytest.mark.parametrize('fr,to',[(Rotation.from_quaternion,'as_quaternion'), (Rotation.from_axis_angle,'as_axis_angle'), - (Rotation.from_Rodrigues, 'as_Rodrigues'), + (Rotation.from_Rodrigues_vector, 'as_Rodrigues_vector'), (Rotation.from_homochoric,'as_homochoric'), (Rotation.from_cubochoric,'as_cubochoric')]) def test_invalid_P(self,fr,to): @@ -852,13 +852,13 @@ class TestRotation: @pytest.mark.parametrize('function,invalid',[(Rotation.from_quaternion, np.array([-1,0,0,0])), (Rotation.from_quaternion, np.array([1,1,1,0])), - (Rotation.from_Eulers, np.array([1,4,0])), + (Rotation.from_Euler_angles, np.array([1,4,0])), (Rotation.from_axis_angle, np.array([1,0,0,4])), (Rotation.from_axis_angle, np.array([1,1,0,1])), (Rotation.from_matrix, np.random.rand(3,3)), (Rotation.from_matrix, np.array([[1,1,0],[1,2,0],[0,0,1]])), - (Rotation.from_Rodrigues, np.array([1,0,0,-1])), - (Rotation.from_Rodrigues, np.array([1,1,0,1])), + (Rotation.from_Rodrigues_vector, np.array([1,0,0,-1])), + (Rotation.from_Rodrigues_vector, np.array([1,1,0,1])), (Rotation.from_homochoric, np.array([2,2,2])), (Rotation.from_cubochoric, np.array([1.1,0,0])) ]) def test_invalid_value(self,function,invalid): @@ -904,8 +904,8 @@ class TestRotation: def test_rotate_360deg(self,data): phi_1 = np.random.random() * np.pi phi_2 = 2*np.pi - phi_1 - R_1 = Rotation.from_Eulers(np.array([phi_1,0.,0.])) - R_2 = Rotation.from_Eulers(np.array([0.,0.,phi_2])) + R_1 = Rotation.from_Euler_angles(np.array([phi_1,0.,0.])) + R_2 = Rotation.from_Euler_angles(np.array([0.,0.,phi_2])) assert np.allclose(data,R_2@(R_1@data)) @pytest.mark.parametrize('pwr',[-10,0,1,2.5,np.pi,np.random.random()]) @@ -951,7 +951,7 @@ class TestRotation: def test_misorientation360(self): R_1 = Rotation() - R_2 = Rotation.from_Eulers([360,0,0],degrees=True) + R_2 = Rotation.from_Euler_angles([360,0,0],degrees=True) assert np.allclose(R_1.misorientation(R_2).as_matrix(),np.eye(3)) @pytest.mark.parametrize('angle',[10,20,30,40,50,60,70,80,90,100,120]) @@ -1014,7 +1014,7 @@ class TestRotation: Eulers = grid_filters.cell_coord0(steps,limits) Eulers = np.radians(Eulers) if not degrees else Eulers - Eulers_r = Rotation.from_ODF(weights,Eulers.reshape(-1,3,order='F'),N,degrees,fractions).as_Eulers(True) + Eulers_r = Rotation.from_ODF(weights,Eulers.reshape(-1,3,order='F'),N,degrees,fractions).as_Euler_angles(True) weights_r = np.histogramdd(Eulers_r,steps,rng)[0].flatten(order='F')/N * np.sum(weights) if fractions: assert np.sqrt(((weights_r - weights) ** 2).mean()) < 4 @@ -1032,7 +1032,7 @@ class TestRotation: Eulers = grid_filters.node_coord0(steps,limits)[:-1,:-1,:-1] Eulers = np.radians(Eulers) if not degrees else Eulers - Eulers_r = Rotation.from_ODF(weights,Eulers.reshape(-1,3,order='F'),N,degrees).as_Eulers(True) + Eulers_r = Rotation.from_ODF(weights,Eulers.reshape(-1,3,order='F'),N,degrees).as_Euler_angles(True) weights_r = np.histogramdd(Eulers_r,steps,rng)[0].flatten(order='F')/N * np.sum(weights) assert np.sqrt(((weights_r - weights) ** 2).mean()) < 5 diff --git a/python/tests/test_mechanics.py b/python/tests/test_mechanics.py index 0b4393ed3..4a61f5b1e 100644 --- a/python/tests/test_mechanics.py +++ b/python/tests/test_mechanics.py @@ -4,7 +4,7 @@ import numpy as np from damask import tensor from damask import mechanics -def Cauchy(P,F): +def stress_Cauchy(P,F): sigma = 1.0/np.linalg.det(F) * np.dot(P,F.T) return symmetric(sigma) @@ -22,15 +22,15 @@ def maximum_shear(T_sym): return (w[0] - w[2])*0.5 -def Mises_strain(epsilon): - return Mises(epsilon,2.0/3.0) +def equivalent_strain_Mises(epsilon): + return equivalent_Mises(epsilon,2.0/3.0) -def Mises_stress(sigma): - return Mises(sigma,3.0/2.0) +def equivalent_stress_Mises(sigma): + return equivalent_Mises(sigma,3.0/2.0) -def PK2(P,F): +def stress_second_Piola_Kirchhoff(P,F): S = np.dot(np.linalg.inv(F),P) return symmetric(S) @@ -91,9 +91,8 @@ def polar_decomposition(T,requested): return tuple(output) -def Mises(T_sym,s): - d = deviatoric_part(T_sym) - return np.sqrt(s*(np.sum(d**2.0))) +def equivalent_Mises(T_sym,s): + return np.sqrt(s*(np.sum(deviatoric_part(T_sym)**2.0))) class TestMechanics: @@ -112,14 +111,14 @@ class TestMechanics: for i,v in enumerate(np.reshape(vectorized(test_data),vectorized(test_data_flat).shape)): assert np.allclose(single(test_data_flat[i]),v) - @pytest.mark.parametrize('vectorized,single',[(mechanics.deviatoric_part, deviatoric_part), - (mechanics.maximum_shear , maximum_shear ), - (mechanics.Mises_strain , Mises_strain ), - (mechanics.Mises_stress , Mises_stress ), - (mechanics.rotational_part, rotational_part), - (mechanics.spherical_part , spherical_part ), - (mechanics.stretch_left , stretch_left ), - (mechanics.stretch_right , stretch_right ), + @pytest.mark.parametrize('vectorized,single',[(mechanics.deviatoric_part, deviatoric_part), + (mechanics.maximum_shear, maximum_shear), + (mechanics.equivalent_stress_Mises, equivalent_stress_Mises), + (mechanics.equivalent_strain_Mises, equivalent_strain_Mises), + (mechanics.rotational_part, rotational_part), + (mechanics.spherical_part, spherical_part), + (mechanics.stretch_left, stretch_left), + (mechanics.stretch_right, stretch_right), ]) def test_vectorize_1_arg(self,vectorized,single): epsilon = np.random.rand(self.n,3,3) @@ -127,8 +126,8 @@ class TestMechanics: for i,v in enumerate(np.reshape(vectorized(epsilon_vec),vectorized(epsilon).shape)): assert np.allclose(single(epsilon[i]),v) - @pytest.mark.parametrize('vectorized,single',[(mechanics.Cauchy,Cauchy), - (mechanics.PK2 ,PK2 ) + @pytest.mark.parametrize('vectorized,single',[(mechanics.stress_Cauchy, stress_Cauchy), + (mechanics.stress_second_Piola_Kirchhoff, stress_second_Piola_Kirchhoff) ]) def test_vectorize_2_arg(self,vectorized,single): P = np.random.rand(self.n,3,3) @@ -148,8 +147,8 @@ class TestMechanics: for i,v in enumerate(np.reshape(vectorized(F_vec,t,m),vectorized(F,t,m).shape)): assert np.allclose(single(F[i],t,m),v) - @pytest.mark.parametrize('function',[mechanics.Cauchy, - mechanics.PK2, + @pytest.mark.parametrize('function',[mechanics.stress_Cauchy, + mechanics.stress_second_Piola_Kirchhoff, ]) def test_stress_measures(self,function): """Ensure that all stress measures are equivalent for no deformation.""" @@ -212,8 +211,8 @@ class TestMechanics: def test_deviatoric_Mises(self): """Ensure that Mises equivalent stress depends only on deviatoric part.""" x = np.random.rand(self.n,3,3) - full = mechanics.Mises_stress(x) - dev = mechanics.Mises_stress(mechanics.deviatoric_part(x)) + full = mechanics.equivalent_stress_Mises(x) + dev = mechanics.equivalent_stress_Mises(mechanics.deviatoric_part(x)) assert np.allclose(full, dev) @@ -229,14 +228,14 @@ class TestMechanics: """Ensure that Mises equivalent strain of spherical strain is 0.""" x = np.random.rand(self.n,3,3) sph = mechanics.spherical_part(x,True) - assert np.allclose(mechanics.Mises_strain(sph), + assert np.allclose(mechanics.equivalent_strain_Mises(sph), 0.0) def test_Mises(self): """Ensure that equivalent stress is 3/2 of equivalent strain.""" x = np.random.rand(self.n,3,3) - assert np.allclose(mechanics.Mises_stress(x)/mechanics.Mises_strain(x), + assert np.allclose(mechanics.equivalent_stress_Mises(x)/mechanics.equivalent_strain_Mises(x), 1.5) def test_spherical_no_shear(self):