Skip to content

Commit bb68439

Browse files
committed
Merge branch 'faster-rotation-matmul' into 'development'
unified rotation of vectors, 2nd order tensors, and 4th order tensors See merge request damask/DAMASK!1203
2 parents 4ce9f26 + bd1f084 commit bb68439

6 files changed

Lines changed: 164 additions & 154 deletions

File tree

python/damask/_geomgrid.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ def __setitem__(self, k: str, v: Union[int, float, np.ndarray]):
6363
"""
6464
if not ( isinstance(v, numbers.Real)
6565
or (isinstance(v, np.ndarray) and v.shape in [(), (1,), (3,)])
66-
or (isinstance(v, np.ndarray) and len(v.shape) >= 3 and
66+
or (isinstance(v, np.ndarray) and v.ndim >= 3 and
6767
v.shape[:3] == self.cells and v.shape[3:] in [(), (1,), (3,)])
6868
):
6969
raise ValueError(f'initial condition "{k}" must be [a field of] scalars or three-dimensional vectors')
7070

7171
super().__setitem__(k,
72-
v if isinstance(v, np.ndarray) and len(v.shape) >= 3 and v.shape[:3] == self.cells else
72+
v if isinstance(v, np.ndarray) and v.ndim >= 3 and v.shape[:3] == self.cells else
7373
np.broadcast_to(v, self.cells + v.shape) if isinstance(v, np.ndarray) else
7474
np.broadcast_to(v, self.cells)
7575
)
@@ -134,7 +134,7 @@ def __repr__(self) -> str:
134134
f'origin: {util.srepr(self.origin," ")} m',
135135
f'# materials: {mat_N}' + ('' if mat_min == 0 and mat_max == mat_N-1 else
136136
f' (min: {mat_min}, max: {mat_max})')
137-
]+(['initial_conditions:']+[f' - {f}'+(f' {data.shape[3:]}' if len(data.shape)>3 else '')
137+
]+(['initial_conditions:']+[f' - {f}'+(f' {data.shape[3:]}' if data.ndim>3 else '')
138138
for f,data in self.initial_conditions.items()] if self.initial_conditions else []))
139139

140140

@@ -210,7 +210,7 @@ def material(self) -> np.ndarray:
210210
@material.setter
211211
def material(self,
212212
material: np.ndarray):
213-
if len(material.shape) != 3:
213+
if material.ndim != 3:
214214
raise ValueError(f'invalid material shape {material.shape}')
215215
if material.dtype not in [np.float32,np.float64, np.int32,np.int64]:
216216
raise TypeError(f'invalid material data type "{material.dtype}"')
@@ -1138,7 +1138,7 @@ def assemble(self,
11381138
Cell count of resulting grid matches shape of index map.
11391139
"""
11401140
cells = idx.shape[:3]
1141-
flat = (idx if len(idx.shape)==3 else grid_filters.ravel_index(idx)).flatten(order='F')
1141+
flat = (idx if idx.ndim==3 else grid_filters.ravel_index(idx)).flatten(order='F')
11421142
ic = {k: v.reshape((-1,)+v.shape[3:],order='F')[flat]
11431143
.reshape(cells+v.shape[3:],order='F') for k,v in self.initial_conditions.items()}
11441144

python/damask/_orientation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,8 +1680,8 @@ def Schmid(self, *,
16801680
>>> O = damask.Orientation.from_Euler_angles(phi=[0,45,0],degrees=True,lattice='cF')
16811681
>>> np.round(O.Schmid(N_slip=[12])[0],3)
16821682
array([[ 0. , 0. , 0. ],
1683-
[ 0.577, -0. , 0.816],
1684-
[ 0. , 0. , 0. ]])
1683+
[ 0.577, 0. , 0.816],
1684+
[-0. , -0. , -0. ]])
16851685
16861686
Schmid matrix (in lab frame) of first {110}, {112}, and {123} slip systems of
16871687
a body-centered cubic crystal in "rotated cube" orientation.
@@ -1723,7 +1723,7 @@ def Schmid(self, *,
17231723
"""
17241724
return np.moveaxis(~self @
17251725
super().Schmid(N_slip=N_slip,
1726-
N_twin=N_twin)[(np.newaxis,)*len(self.shape)],
1726+
N_twin=N_twin)[(np.newaxis,)*self.ndim],
17271727
-3,
17281728
0)
17291729

0 commit comments

Comments
 (0)