explicit arguments to guide the user

This commit is contained in:
Martin Diehl 2023-02-02 08:38:50 +01:00
parent 008d3cca6f
commit 6682f58f86
1 changed files with 34 additions and 12 deletions

View File

@ -180,8 +180,12 @@ class ConfigMaterial(Config):
@staticmethod @staticmethod
def from_table(table: Table, def from_table(table: Table,*,
**kwargs) -> 'ConfigMaterial': homogenization: Optional[Union[str,StrSequence]] = None,
phase: Optional[Union[str,StrSequence]] = None,
v: Optional[Union[str,FloatSequence]] = None,
O: Optional[Union[str,FloatSequence]] = None,
V_e: Optional[Union[str,FloatSequence]] = None) -> 'ConfigMaterial':
""" """
Generate from an ASCII table. Generate from an ASCII table.
@ -189,16 +193,33 @@ class ConfigMaterial(Config):
---------- ----------
table : damask.Table table : damask.Table
Table that contains material information. Table that contains material information.
**kwargs homogenization: (array-like) of str, optional
Keyword arguments where the key is the property name and Homogenization label.
the value specifies either the label of the data column in the table phase: (array-like) of str, optional
or a constant value. Phase label (per constituent).
v: (array-like) of float or str, optional
Constituent volume fraction (per constituent).
Defaults to 1/N_constituent.
O: (array-like) of damask.Rotation or np.array/list of shape(4) or str, optional
Orientation as unit quaternion (per constituent).
V_e: (array-like) of np.array/list of shape(3,3) or str, optional
Left elastic stretch (per constituent).
Returns Returns
------- -------
new : damask.ConfigMaterial new : damask.ConfigMaterial
Material configuration from values in table. Material configuration from values in table.
Notes
-----
If the value of an argument is a string that is a column label,
data from the table is used to fill the corresponding entry in
the material configuration. Otherwise, the value is used directly.
First index of array-like values that are defined per constituent
runs over materials, whereas second index runs over constituents.
Examples Examples
-------- --------
>>> import damask >>> import damask
@ -240,15 +261,16 @@ class ConfigMaterial(Config):
phase: {Aluminum: null, Steel: null} phase: {Aluminum: null, Steel: null}
""" """
kwargs_ = {k:table.get(v) if v in table.labels else np.atleast_2d([v]*len(table)).T for k,v in kwargs.items()} kwargs = {}
for arg,val in zip(['homogenization','phase','v','O','V_e'],[homogenization,phase,v,O,V_e]):
if val is not None:
kwargs[arg] = table.get(val) if val in table.labels else np.atleast_2d([val]*len(table)).T # type: ignore
_,idx = np.unique(np.hstack(list(kwargs_.values())),return_index=True,axis=0) _,idx = np.unique(np.hstack(list(kwargs.values())),return_index=True,axis=0)
idx = np.sort(idx) idx = np.sort(idx)
kwargs_ = {k:np.atleast_1d(v[idx].squeeze()) for k,v in kwargs_.items()} kwargs = {k:np.atleast_1d(v[idx].squeeze()) for k,v in kwargs.items()}
for what in ['phase','homogenization']:
if what not in kwargs_: kwargs_[what] = what+'_label'
return ConfigMaterial().material_add(**kwargs_) return ConfigMaterial().material_add(**kwargs)
@property @property