@@ -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
0 commit comments