Merge remote-tracking branch 'origin/misc-improvements' into h5py3
This commit is contained in:
commit
bbaeeb02da
2
PRIVATE
2
PRIVATE
|
@ -1 +1 @@
|
|||
Subproject commit 52e51c6a69dec5046eef3e369484256b655acbd9
|
||||
Subproject commit 92b7b1314a9c576a20f073a230e2aaf811cb932a
|
|
@ -24,6 +24,20 @@ class ConfigMaterial(Config):
|
|||
super().save(fname,**kwargs)
|
||||
|
||||
|
||||
@classmethod
|
||||
def load(cls,fname='material.yaml'):
|
||||
"""
|
||||
Load from yaml file.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fname : file, str, or pathlib.Path, optional
|
||||
Filename or file for writing. Defaults to 'material.yaml'.
|
||||
|
||||
"""
|
||||
return super(ConfigMaterial,cls).load(fname)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def from_table(table,constituents={},**kwargs):
|
||||
"""
|
||||
|
|
|
@ -94,7 +94,7 @@ class Result:
|
|||
|
||||
|
||||
def __repr__(self):
|
||||
"""Show selected data."""
|
||||
"""Show summary of file content."""
|
||||
all_selected_increments = self.selection['increments']
|
||||
|
||||
self.pick('increments',all_selected_increments[0:1])
|
||||
|
@ -796,20 +796,26 @@ class Result:
|
|||
|
||||
|
||||
@staticmethod
|
||||
def _add_Mises(T_sym):
|
||||
t = 'strain' if T_sym['meta']['Unit'] == '1' else \
|
||||
'stress'
|
||||
def _add_Mises(T_sym,kind):
|
||||
k = kind
|
||||
if k 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'],
|
||||
'Description': f"Mises equivalent {t} of {T_sym['label']} ({T_sym['meta']['Description']})",
|
||||
'Description': f"Mises equivalent {k} of {T_sym['label']} ({T_sym['meta']['Description']})",
|
||||
'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.
|
||||
|
||||
|
@ -817,9 +823,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
|
||||
|
|
|
@ -197,11 +197,10 @@ class VTK:
|
|||
elif isinstance(self.vtk_data,vtk.vtkPolyData):
|
||||
writer = vtk.vtkXMLPolyDataWriter()
|
||||
|
||||
default_ext = writer.GetDefaultFileExtension()
|
||||
default_ext = '.'+writer.GetDefaultFileExtension()
|
||||
ext = Path(fname).suffix
|
||||
if ext and ext != '.'+default_ext:
|
||||
raise ValueError(f'Given extension "{ext}" does not match default ".{default_ext}"')
|
||||
writer.SetFileName(str(Path(fname).with_suffix('.'+default_ext)))
|
||||
writer.SetFileName(str(fname)+(default_ext if default_ext != ext else ''))
|
||||
|
||||
if compress:
|
||||
writer.SetCompressorTypeToZLib()
|
||||
else:
|
||||
|
|
|
@ -210,6 +210,22 @@ class TestResult:
|
|||
in_file = default.read_dataset(loc['sigma_vM'],0)
|
||||
assert np.allclose(in_memory,in_file)
|
||||
|
||||
def test_add_Mises_invalid(self,default):
|
||||
default.add_Cauchy('P','F')
|
||||
default.add_calculation('sigma_y','#sigma#',unit='y')
|
||||
default.add_Mises('sigma_y')
|
||||
assert default.get_dataset_location('sigma_y_vM') == []
|
||||
|
||||
def test_add_Mises_stress_strain(self,default):
|
||||
default.add_Cauchy('P','F')
|
||||
default.add_calculation('sigma_y','#sigma#',unit='y')
|
||||
default.add_calculation('sigma_x','#sigma#',unit='x')
|
||||
default.add_Mises('sigma_y',kind='strain')
|
||||
default.add_Mises('sigma_x',kind='stress')
|
||||
loc = {'y' :default.get_dataset_location('sigma_y_vM'),
|
||||
'x' :default.get_dataset_location('sigma_x_vM')}
|
||||
assert not np.allclose(default.read_dataset(loc['y'],0),default.read_dataset(loc['x'],0))
|
||||
|
||||
def test_add_norm(self,default):
|
||||
default.add_norm('F',1)
|
||||
loc = {'F': default.get_dataset_location('F'),
|
||||
|
|
|
@ -85,6 +85,12 @@ class TestVTK:
|
|||
assert(False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('fname',['a','a.vtp','a.b','a.b.vtp'])
|
||||
def test_filename_variations(self,tmp_path,fname):
|
||||
points = np.random.rand(102,3)
|
||||
v = VTK.from_poly_data(points)
|
||||
v.save(tmp_path/fname)
|
||||
|
||||
@pytest.mark.parametrize('name,dataset_type',[('this_file_does_not_exist.vtk', None),
|
||||
('this_file_does_not_exist.vtk','vtk'),
|
||||
('this_file_does_not_exist.vtx', None)])
|
||||
|
@ -92,9 +98,10 @@ class TestVTK:
|
|||
with pytest.raises(TypeError):
|
||||
VTK.load(name,dataset_type)
|
||||
|
||||
def test_invalid_extension_write(self,default):
|
||||
with pytest.raises(ValueError):
|
||||
default.save('default.txt')
|
||||
def test_add_extension(self,tmp_path,default):
|
||||
default.save(tmp_path/'default.txt',parallel=False)
|
||||
assert os.path.isfile(tmp_path/'default.txt.vtr')
|
||||
|
||||
|
||||
def test_invalid_get(self,default):
|
||||
with pytest.raises(ValueError):
|
||||
|
|
|
@ -529,7 +529,7 @@ subroutine homogenization_results
|
|||
material_homogenization_type => homogenization_type
|
||||
|
||||
integer :: p
|
||||
character(len=pStringLen) :: group_base,group
|
||||
character(len=:), allocatable :: group_base,group
|
||||
|
||||
!real(pReal), dimension(:,:,:), allocatable :: temp
|
||||
|
||||
|
|
Loading…
Reference in New Issue