From 1fcf9cb721aa5230f9e790bdd0a4b8d4e06a5d4f Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 5 Nov 2020 05:48:12 +0100 Subject: [PATCH] don't compute silently the wrong von Mises kind and allow the user to set it explicitly --- python/damask/_result.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index 66cc39785..9ac76259d 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -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