added possibility to read real numbers as microstructure indices (not only integers)

This commit is contained in:
Zhuowen Zhao 2016-03-17 17:40:40 -04:00
parent 36c88cde02
commit d42f8d5fd4
1 changed files with 12 additions and 8 deletions

View File

@ -517,19 +517,23 @@ class ASCIItable():
# ------------------------------------------------------------------
def microstructure_read(self,
grid):
grid,
type = 'i'):
"""read microstructure data (from .geom format)"""
def datatype(item):
return int(item) if type.lower() == 'i' else float(item)
N = grid.prod() # expected number of microstructure indices in data
microstructure = np.zeros(N,'i') # initialize as flat array
microstructure = np.zeros(N,type) # initialize as flat array
i = 0
while i < N and self.data_read():
items = self.data
if len(items) > 2:
if items[1].lower() == 'of': items = [int(items[2])]*int(items[0])
elif items[1].lower() == 'to': items = range(int(items[0]),1+int(items[2]))
else: items = map(int,items)
else: items = map(int,items)
if items[1].lower() == 'of': items = np.ones(datatype(items[0]))*datatype(items[2])
elif items[1].lower() == 'to': items = np.arange(datatype(items[0]),1+datatype(items[2]))
else: items = map(datatype,items)
else: items = map(datatype,items)
s = min(len(items), N-i) # prevent overflow of microstructure array
microstructure[i:i+s] = items[:s]