Skip to content

Commit aee2c52

Browse files
committed
refact: add stl_materials to _prepare_stl_dicts() to ensure that it only contains numerical values and not str. Update plot_solids to use 0.3 opacity for vacuum-like values
1 parent ec75ae5 commit aee2c52

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

wakis/gridFIT3D.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from .field import Field
1414
from .logger import Logger
15-
from .materials import material_colors
15+
from .materials import material_colors, material_lib
1616

1717
try:
1818
from mpi4py import MPI
@@ -310,6 +310,7 @@ def mpi_gather_asGrid(self):
310310
return _grid
311311

312312
def _prepare_stl_dicts(self):
313+
#Ensure all the stl data is stored in dicts
313314
if type(self.stl_solids) is not dict:
314315
if type(self.stl_solids) is str:
315316
self.stl_solids = {'Solid 1' : self.stl_solids}
@@ -355,6 +356,25 @@ def _prepare_stl_dicts(self):
355356
self._assign_colors()
356357
print('[!] If `stl_colors` is a list, it must have the same length as `stl_solids`.')
357358

359+
if type(self.stl_materials) is not dict:
360+
if type(self.stl_materials) is str:
361+
self.stl_materials = {'Solid 1' : self.stl_materials}
362+
else:
363+
raise Exception('Attribute `stl_materials` must contain a string or a dictionary')
364+
365+
for key in self.stl_solids.keys():
366+
# if keys are str, convert to array using material library
367+
if type(self.stl_materials[key]) is str:
368+
mat_key = self.stl_materials[key].lower()
369+
eps_r = material_lib[mat_key][0]
370+
mu_r = material_lib[mat_key][1]
371+
372+
self.stl_materials[key] = [eps_r, mu_r]
373+
374+
if len(material_lib[mat_key]) == 3:
375+
sigma = material_lib[mat_key][2]
376+
self.stl_materials[key].append(sigma)
377+
358378
def _mark_cells_in_stl(self):
359379
# Obtain masks with grid cells inside each stl solid
360380
stl_tolerance = np.min([self.dx, self.dy, self.dz])*self.stl_tol
@@ -655,8 +675,8 @@ def plot_solids(self, bounding_box=False, show_grid=False, anti_aliasing=None,
655675
pl.add_mesh(self.grid, opacity=0., name='grid', show_scalar_bar=False)
656676
for key in self.stl_solids:
657677
color = self.stl_colors[key]
658-
if self.stl_materials[key] == 'vacuum':
659-
_opacity = 0.3
678+
if self.stl_materials[key] == [1.0, 1.0, 0.0] or self.stl_materials[key] == [1.0, 1.0]:
679+
_opacity = 0.3 # vacuum
660680
else:
661681
_opacity = opacity
662682
pl.add_mesh(self.read_stl(key), color=color,

0 commit comments

Comments
 (0)