explicit is better then implicit:

user should sort Table according to coordinates to create geometry. This
allows to have consistent behavior for from_table in Geom and
ConfigMaterial. We always ensure to keep the order
This commit is contained in:
Martin Diehl 2020-10-29 07:17:41 +01:00
parent 1b2cd6caf6
commit 3be0c462a8
2 changed files with 7 additions and 16 deletions

View File

@ -26,7 +26,7 @@ class ConfigMaterial(Config):
@staticmethod @staticmethod
def from_table(table,coordinates=None,constituents={},**kwargs): def from_table(table,constituents={},**kwargs):
""" """
Load from an ASCII table. Load from an ASCII table.
@ -34,10 +34,6 @@ class ConfigMaterial(Config):
---------- ----------
table : damask.Table table : damask.Table
Table that contains material information. Table that contains material information.
coordinates : str, optional
Label of spatial coordiates. Used for sorting and performing a
sanity check. Default to None, in which case no sorting or checking is
peformed.
constituents : dict, optional constituents : dict, optional
Entries for 'constituents'. The key is the name and the value specifies Entries for 'constituents'. The key is the name and the value specifies
the label of the data column in the table the label of the data column in the table
@ -54,7 +50,7 @@ class ConfigMaterial(Config):
pos pos pos qu qu qu qu phase homog pos pos pos qu qu qu qu phase homog
0 0 0 0 0.19 0.8 0.24 -0.51 Aluminum SX 0 0 0 0 0.19 0.8 0.24 -0.51 Aluminum SX
1 1 0 0 0.8 0.19 0.24 -0.51 Steel SX 1 1 0 0 0.8 0.19 0.24 -0.51 Steel SX
>>> cm.from_table(t,'pos',{'O':'qu','phase':'phase'},homogenization='homog') >>> cm.from_table(t,{'O':'qu','phase':'phase'},homogenization='homog')
material: material:
- constituents: - constituents:
- O: [0.19, 0.8, 0.24, -0.51] - O: [0.19, 0.8, 0.24, -0.51]
@ -68,17 +64,12 @@ class ConfigMaterial(Config):
homogenization: SX homogenization: SX
""" """
if coordinates is not None: constituents_ = {k:table.get(v) for k,v in constituents.items()}
t = table.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) kwargs_ = {k:table.get(v) for k,v in kwargs.items()}
grid_filters.coord0_check(t.get(coordinates))
else:
t = table
constituents_ = {k:t.get(v) for k,v in constituents.items()}
kwargs_ = {k:t.get(v) for k,v in kwargs.items()}
_,idx = np.unique(np.hstack(list({**constituents_,**kwargs_}.values())),return_index=True,axis=0) _,idx = np.unique(np.hstack(list({**constituents_,**kwargs_}.values())),return_index=True,axis=0)
idx = np.sort(idx)
constituents_ = {k:v[idx].squeeze() for k,v in constituents_.items()} constituents_ = {k:v[idx].squeeze() for k,v in constituents_.items()}
kwargs_ = {k:v[idx].squeeze() for k,v in kwargs_.items()} kwargs_ = {k:v[idx].squeeze() for k,v in kwargs_.items()}

View File

@ -255,13 +255,13 @@ class Geom:
table : damask.Table table : damask.Table
Table that contains material information. Table that contains material information.
coordinates : str coordinates : str
Label of the column containing the spatial coordinates. Label of the column containing the vector of spatial coordinates.
Need to be ordered (1./x fast, 3./z slow).
labels : str or list of str labels : str or list of str
Label(s) of the columns containing the material definition. Label(s) of the columns containing the material definition.
Each unique combintation of values results in a material. Each unique combintation of values results in a material.
""" """
coords = table.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]).get(coordinates)
grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(coords) grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(coords)
labels_ = [labels] if isinstance(labels,str) else labels labels_ = [labels] if isinstance(labels,str) else labels