enhance grid to store initial conditions
This commit is contained in:
parent
d8de8f8b39
commit
f54849f495
|
@ -34,7 +34,8 @@ class Grid:
|
||||||
material: np.ndarray,
|
material: np.ndarray,
|
||||||
size: FloatSequence,
|
size: FloatSequence,
|
||||||
origin: FloatSequence = np.zeros(3),
|
origin: FloatSequence = np.zeros(3),
|
||||||
comments: Union[str, Sequence[str]] = None):
|
comments: Union[str, Sequence[str]] = None,
|
||||||
|
initial_conditions = None):
|
||||||
"""
|
"""
|
||||||
New geometry definition for grid solvers.
|
New geometry definition for grid solvers.
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ class Grid:
|
||||||
self.size = size # type: ignore
|
self.size = size # type: ignore
|
||||||
self.origin = origin # type: ignore
|
self.origin = origin # type: ignore
|
||||||
self.comments = [] if comments is None else comments # type: ignore
|
self.comments = [] if comments is None else comments # type: ignore
|
||||||
|
self.ic = initial_conditions if initial_conditions is not None else {}
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
"""Give short human-readable summary."""
|
"""Give short human-readable summary."""
|
||||||
|
@ -68,7 +69,7 @@ class Grid:
|
||||||
f'origin: {util.srepr(self.origin," ")} m',
|
f'origin: {util.srepr(self.origin," ")} m',
|
||||||
f'# materials: {mat_N}' + ('' if mat_min == 0 and mat_max+1 == mat_N else
|
f'# materials: {mat_N}' + ('' if mat_min == 0 and mat_max+1 == mat_N else
|
||||||
f' (min: {mat_min}, max: {mat_max})')
|
f' (min: {mat_min}, max: {mat_max})')
|
||||||
])
|
]+(['initial_conditions:']+[f' - {f}' for f in self.ic.keys()] if self.ic else []))
|
||||||
|
|
||||||
|
|
||||||
def __copy__(self) -> 'Grid':
|
def __copy__(self) -> 'Grid':
|
||||||
|
@ -187,11 +188,13 @@ class Grid:
|
||||||
cells = np.array(v.vtk_data.GetDimensions())-1
|
cells = np.array(v.vtk_data.GetDimensions())-1
|
||||||
bbox = np.array(v.vtk_data.GetBounds()).reshape(3,2).T
|
bbox = np.array(v.vtk_data.GetBounds()).reshape(3,2).T
|
||||||
comments = v.comments
|
comments = v.comments
|
||||||
|
ic = {label:v.get(label).reshape(cells,order='F') for label in set(v.labels['Cell Data']) - {'material'}}
|
||||||
|
|
||||||
return Grid(material = v.get('material').reshape(cells,order='F'),
|
return Grid(material = v.get('material').reshape(cells,order='F'),
|
||||||
size = bbox[1] - bbox[0],
|
size = bbox[1] - bbox[0],
|
||||||
origin = bbox[0],
|
origin = bbox[0],
|
||||||
comments = comments)
|
comments = comments,
|
||||||
|
initial_conditions = ic)
|
||||||
|
|
||||||
|
|
||||||
@typing. no_type_check
|
@typing. no_type_check
|
||||||
|
@ -646,7 +649,9 @@ class Grid:
|
||||||
"""
|
"""
|
||||||
v = VTK.from_image_data(self.cells,self.size,self.origin)\
|
v = VTK.from_image_data(self.cells,self.size,self.origin)\
|
||||||
.add(self.material.flatten(order='F'),'material')
|
.add(self.material.flatten(order='F'),'material')
|
||||||
v.comments += self.comments
|
for label,field in self.fields.items():
|
||||||
|
v = v.add(field.flatten(order='F'),label)
|
||||||
|
v.comments = self.comments
|
||||||
|
|
||||||
v.save(fname,parallel=False,compress=compress)
|
v.save(fname,parallel=False,compress=compress)
|
||||||
|
|
||||||
|
@ -683,7 +688,7 @@ class Grid:
|
||||||
|
|
||||||
|
|
||||||
def show(self,
|
def show(self,
|
||||||
colormap: Colormap = Colormap.from_predefined('cividis')) -> None:
|
colormap: Colormap = None) -> None:
|
||||||
"""
|
"""
|
||||||
Show on screen.
|
Show on screen.
|
||||||
|
|
||||||
|
|
|
@ -503,11 +503,21 @@ class VTK:
|
||||||
|
|
||||||
def show(self,
|
def show(self,
|
||||||
label: str = None,
|
label: str = None,
|
||||||
colormap: Colormap = Colormap.from_predefined('cividis')):
|
colormap: Colormap = None):
|
||||||
"""
|
"""
|
||||||
Render.
|
Render.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
label : str, optional
|
||||||
|
Label of the dataset to show.
|
||||||
|
colormap : damask.Colormap, optional
|
||||||
|
Colormap for visualization of dataset.
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
See http://compilatrix.com/article/vtk-1 for further ideas.
|
See http://compilatrix.com/article/vtk-1 for further ideas.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
import wx
|
import wx
|
||||||
|
@ -525,8 +535,9 @@ class VTK:
|
||||||
height = 768
|
height = 768
|
||||||
|
|
||||||
lut = vtk.vtkLookupTable()
|
lut = vtk.vtkLookupTable()
|
||||||
lut.SetNumberOfTableValues(len(colormap.colors))
|
colormap_ = Colormap.from_predefined('cividis') if colormap is None else colormap
|
||||||
for i,c in enumerate(colormap.colors):
|
lut.SetNumberOfTableValues(len(colormap_.colors))
|
||||||
|
for i,c in enumerate(colormap_.colors):
|
||||||
lut.SetTableValue(i,c if len(c)==4 else np.append(c,1.0))
|
lut.SetTableValue(i,c if len(c)==4 else np.append(c,1.0))
|
||||||
lut.Build()
|
lut.Build()
|
||||||
|
|
||||||
|
@ -545,11 +556,11 @@ class VTK:
|
||||||
if label is None:
|
if label is None:
|
||||||
ren.SetBackground(67/255,128/255,208/255)
|
ren.SetBackground(67/255,128/255,208/255)
|
||||||
else:
|
else:
|
||||||
colormap = vtk.vtkScalarBarActor()
|
colormap_vtk = vtk.vtkScalarBarActor()
|
||||||
colormap.SetLookupTable(lut)
|
colormap_vtk.SetLookupTable(lut)
|
||||||
colormap.SetTitle(label)
|
colormap_vtk.SetTitle(label)
|
||||||
colormap.SetMaximumWidthInPixels(width//100)
|
colormap_vtk.SetMaximumWidthInPixels(width//100)
|
||||||
ren.AddActor2D(colormap)
|
ren.AddActor2D(colormap_vtk)
|
||||||
ren.SetBackground(0.3,0.3,0.3)
|
ren.SetBackground(0.3,0.3,0.3)
|
||||||
|
|
||||||
window = vtk.vtkRenderWindow()
|
window = vtk.vtkRenderWindow()
|
||||||
|
|
Loading…
Reference in New Issue