allow constant (non-label) value in cm.from_table() keys
This commit is contained in:
parent
e210a9873d
commit
1b08f90d6c
|
@ -178,8 +178,9 @@ class ConfigMaterial(Config):
|
||||||
table : damask.Table
|
table : damask.Table
|
||||||
Table that contains material information.
|
Table that contains material information.
|
||||||
**kwargs
|
**kwargs
|
||||||
Keyword arguments where the key is the name and the value specifies
|
Keyword arguments where the key is the property name and
|
||||||
the label of the data column in the table.
|
the value specifies either the label of the data column in the table
|
||||||
|
or a constant value.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
|
@ -211,8 +212,23 @@ class ConfigMaterial(Config):
|
||||||
homogenization: {}
|
homogenization: {}
|
||||||
phase: {}
|
phase: {}
|
||||||
|
|
||||||
|
>>> cm.from_table(t,O='qu',phase='phase',homogenization='SX')
|
||||||
|
material:
|
||||||
|
- constituents:
|
||||||
|
- O: [0.19, 0.8, 0.24, -0.51]
|
||||||
|
v: 1.0
|
||||||
|
phase: Aluminum
|
||||||
|
homogenization: SX
|
||||||
|
- constituents:
|
||||||
|
- O: [0.8, 0.19, 0.24, -0.51]
|
||||||
|
v: 1.0
|
||||||
|
phase: Steel
|
||||||
|
homogenization: SX
|
||||||
|
homogenization: {}
|
||||||
|
phase: {}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
kwargs_ = {k:table.get(v) for k,v in kwargs.items()}
|
kwargs_ = {k:table.get(v) if v in table.labels else np.atleast_2d([v]*len(table)).T for k,v in kwargs.items()}
|
||||||
|
|
||||||
_,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)
|
||||||
|
|
|
@ -96,6 +96,18 @@ class TestConfigMaterial:
|
||||||
for i,m in enumerate(c['material']):
|
for i,m in enumerate(c['material']):
|
||||||
assert m['homogenization'] == 1 and (m['constituents'][0]['O'] == [1,0,1,1]).all()
|
assert m['homogenization'] == 1 and (m['constituents'][0]['O'] == [1,0,1,1]).all()
|
||||||
|
|
||||||
|
def test_from_table_with_constant(self):
|
||||||
|
N = np.random.randint(3,10)
|
||||||
|
a = np.vstack((np.hstack((np.arange(N),np.arange(N)[::-1])),
|
||||||
|
np.ones(N*2),np.zeros(N*2),np.ones(N*2),np.ones(N*2),
|
||||||
|
np.ones(N*2),
|
||||||
|
)).T
|
||||||
|
t = Table(a,{'varying':1,'constant':4,'ones':1})
|
||||||
|
c = ConfigMaterial.from_table(t,**{'phase':'varying','O':'constant','homogenization':1})
|
||||||
|
assert len(c['material']) == N
|
||||||
|
for i,m in enumerate(c['material']):
|
||||||
|
assert m['homogenization'] == 1 and (m['constituents'][0]['O'] == [1,0,1,1]).all()
|
||||||
|
|
||||||
@pytest.mark.parametrize('N,n,kw',[
|
@pytest.mark.parametrize('N,n,kw',[
|
||||||
(1,1,{'phase':'Gold',
|
(1,1,{'phase':'Gold',
|
||||||
'O':[1,0,0,0],
|
'O':[1,0,0,0],
|
||||||
|
|
Loading…
Reference in New Issue