enhance grid to store initial conditions
This commit is contained in:
parent
d8de8f8b39
commit
f54849f495
|
@ -34,7 +34,8 @@ class Grid:
|
|||
material: np.ndarray,
|
||||
size: FloatSequence,
|
||||
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.
|
||||
|
||||
|
@ -55,7 +56,7 @@ class Grid:
|
|||
self.size = size # type: ignore
|
||||
self.origin = origin # 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:
|
||||
"""Give short human-readable summary."""
|
||||
|
@ -68,7 +69,7 @@ class Grid:
|
|||
f'origin: {util.srepr(self.origin," ")} m',
|
||||
f'# materials: {mat_N}' + ('' if mat_min == 0 and mat_max+1 == mat_N else
|
||||
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':
|
||||
|
@ -187,11 +188,13 @@ class Grid:
|
|||
cells = np.array(v.vtk_data.GetDimensions())-1
|
||||
bbox = np.array(v.vtk_data.GetBounds()).reshape(3,2).T
|
||||
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'),
|
||||
size = bbox[1] - bbox[0],
|
||||
origin = bbox[0],
|
||||
comments = comments)
|
||||
comments = comments,
|
||||
initial_conditions = ic)
|
||||
|
||||
|
||||
@typing. no_type_check
|
||||
|
@ -646,7 +649,9 @@ class Grid:
|
|||
"""
|
||||
v = VTK.from_image_data(self.cells,self.size,self.origin)\
|
||||
.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)
|
||||
|
||||
|
@ -683,7 +688,7 @@ class Grid:
|
|||
|
||||
|
||||
def show(self,
|
||||
colormap: Colormap = Colormap.from_predefined('cividis')) -> None:
|
||||
colormap: Colormap = None) -> None:
|
||||
"""
|
||||
Show on screen.
|
||||
|
||||
|
|
|
@ -503,11 +503,21 @@ class VTK:
|
|||
|
||||
def show(self,
|
||||
label: str = None,
|
||||
colormap: Colormap = Colormap.from_predefined('cividis')):
|
||||
colormap: Colormap = None):
|
||||
"""
|
||||
Render.
|
||||
|
||||
See http://compilatrix.com/article/vtk-1 for further ideas.
|
||||
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.
|
||||
|
||||
"""
|
||||
try:
|
||||
import wx
|
||||
|
@ -525,8 +535,9 @@ class VTK:
|
|||
height = 768
|
||||
|
||||
lut = vtk.vtkLookupTable()
|
||||
lut.SetNumberOfTableValues(len(colormap.colors))
|
||||
for i,c in enumerate(colormap.colors):
|
||||
colormap_ = Colormap.from_predefined('cividis') if colormap is None else colormap
|
||||
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.Build()
|
||||
|
||||
|
@ -545,11 +556,11 @@ class VTK:
|
|||
if label is None:
|
||||
ren.SetBackground(67/255,128/255,208/255)
|
||||
else:
|
||||
colormap = vtk.vtkScalarBarActor()
|
||||
colormap.SetLookupTable(lut)
|
||||
colormap.SetTitle(label)
|
||||
colormap.SetMaximumWidthInPixels(width//100)
|
||||
ren.AddActor2D(colormap)
|
||||
colormap_vtk = vtk.vtkScalarBarActor()
|
||||
colormap_vtk.SetLookupTable(lut)
|
||||
colormap_vtk.SetTitle(label)
|
||||
colormap_vtk.SetMaximumWidthInPixels(width//100)
|
||||
ren.AddActor2D(colormap_vtk)
|
||||
ren.SetBackground(0.3,0.3,0.3)
|
||||
|
||||
window = vtk.vtkRenderWindow()
|
||||
|
|
Loading…
Reference in New Issue