don't compute silently the wrong von Mises kind

and allow the user to set it explicitly
This commit is contained in:
Martin Diehl 2020-11-05 05:48:12 +01:00
parent 7341b9830a
commit 1fcf9cb721
1 changed files with 14 additions and 6 deletions

View File

@ -789,12 +789,17 @@ class Result:
@staticmethod
def _add_Mises(T_sym):
t = 'strain' if T_sym['meta']['Unit'] == '1' else \
'stress'
def _add_Mises(T_sym,kind):
if kind is None:
if T_sym['meta']['Unit'] == '1':
k = 'strain'
elif T_sym['meta']['Unit'] == 'Pa':
k = 'stress'
if k not in ['stress', 'strain']:
raise ValueError('invalid von Mises kind {kind}')
return {
'data': (mechanics.Mises_strain if t=='strain' else mechanics.Mises_stress)(T_sym['data']),
'data': (mechanics.Mises_strain if k=='strain' else mechanics.Mises_stress)(T_sym['data']),
'label': f"{T_sym['label']}_vM",
'meta': {
'Unit': T_sym['meta']['Unit'],
@ -802,7 +807,7 @@ class Result:
'Creator': 'add_Mises'
}
}
def add_Mises(self,T_sym):
def add_Mises(self,T_sym,kind=None):
"""
Add the equivalent Mises stress or strain of a symmetric tensor.
@ -810,9 +815,12 @@ class Result:
----------
T_sym : str
Label of symmetric tensorial stress or strain dataset.
kind : {'stress', 'strain', None}, optional
Kind of the von Mises equivalent. Defaults to None, in which case
it is selected based on the unit of the dataset ('1' -> strain, 'Pa' -> stress').
"""
self._add_generic_pointwise(self._add_Mises,{'T_sym':T_sym})
self._add_generic_pointwise(self._add_Mises,{'T_sym':T_sym},{'kind':kind})
@staticmethod