limits hold for sum and individual

This commit is contained in:
Martin Diehl 2023-02-02 08:23:44 +01:00
parent 46ad436d76
commit 008d3cca6f
1 changed files with 12 additions and 9 deletions

View File

@ -541,24 +541,27 @@ class ConfigMaterial(Config):
ex = dict((keyword, -len(val)) for keyword,val in dim.items()) ex = dict((keyword, -len(val)) for keyword,val in dim.items())
N_materials,N_constituents = 1,1 N_materials,N_constituents = 1,1
shaped = {} shape = {}
for arg,val in zip(['homogenization','phase','v','O','V_e'],[homogenization,phase,v,O,V_e]): for arg,val in zip(['homogenization','phase','v','O','V_e'],[homogenization,phase,v,O,V_e]):
if val is None: continue if val is None: continue
shaped[arg] = np.array(val) shape[arg] = np.array(val)
s = shaped[arg].shape[:ex.get(arg,None)] # type: ignore s = shape[arg].shape[:ex.get(arg,None)] # type: ignore
N_materials = max(N_materials,s[0]) if len(s)>0 else N_materials N_materials = max(N_materials,s[0]) if len(s)>0 else N_materials
N_constituents = max(N_constituents,s[1]) if len(s)>1 else N_constituents N_constituents = max(N_constituents,s[1]) if len(s)>1 else N_constituents
shaped['v'] = np.array(shaped.get('v',1./N_constituents),float) shape['v'] = np.array(shape.get('v',1./N_constituents),float)
mat: Sequence[dict] = [{'constituents':[{} for _ in range(N_constituents)]} for _ in range(N_materials)] mat: Sequence[dict] = [{'constituents':[{} for _ in range(N_constituents)]} for _ in range(N_materials)]
for k,v in shaped.items(): for k,v in shape.items():
target = (N_materials,N_constituents) + dim.get(k,()) target = (N_materials,N_constituents) + dim.get(k,())
obj = np.broadcast_to(np.array(v).reshape(util.shapeshifter(np.array(v).shape,target,'right')),target) obj = np.broadcast_to(np.array(v).reshape(util.shapeshifter(np.array(v).shape,target,'right')),target)
if k == 'v': if k == 'v':
total = obj if len(np.atleast_1d(obj)) == 1 else np.sum(obj,axis=-1) if np.min(obj) < 0 or np.max(obj) > 1:
if np.min(obj) < 0 or np.min(total) < 0 or np.max(total) > 1: raise ValueError('volume fraction "v" out of range')
if len(np.atleast_1d(obj)) > 1:
total = np.sum(obj,axis=-1)
if np.min(total) < 0 or np.max(total) > 1:
raise ValueError('volume fraction "v" out of range') raise ValueError('volume fraction "v" out of range')
if k == 'O' and not np.allclose(1.0,np.linalg.norm(obj,axis=-1)): if k == 'O' and not np.allclose(1.0,np.linalg.norm(obj,axis=-1)):
raise ValueError('orientation "O" is not a unit quaterion') raise ValueError('orientation "O" is not a unit quaterion')
@ -574,8 +577,8 @@ class ConfigMaterial(Config):
dup = self.copy() dup = self.copy()
dup['material'] = dup['material'] + mat if 'material' in dup else mat dup['material'] = dup['material'] + mat if 'material' in dup else mat
for what in [item for item in ['phase','homogenization'] if item in shaped]: for what in [item for item in ['phase','homogenization'] if item in shape]:
for k in np.unique(shaped[what]): # type: ignore for k in np.unique(shape[what]): # type: ignore
if k not in dup[what]: dup[what][str(k)] = None if k not in dup[what]: dup[what][str(k)] = None
return dup return dup