https://stackoverflow.com/questions/16992713
This commit is contained in:
Martin Diehl 2020-10-28 14:39:41 +01:00
parent 98e0ef3881
commit 855bf124d3
2 changed files with 14 additions and 4 deletions

View File

@ -787,11 +787,14 @@ class Geom:
New material indices.
"""
substituted = self.material.copy()
for from_ma,to_ma in zip(from_material,to_material):
substituted[self.material==from_ma] = to_ma
mapper = dict(zip(from_material,to_material))
def mp(entry):
return mapper[entry] if entry in mapper else entry
mp = np.vectorize(mp)
return Geom(material = substituted,
return Geom(material = mp(self.material).reshape(self.grid),
size = self.size,
origin = self.origin,
comments = self.comments+[util.execution_stamp('Geom','substitute')],

View File

@ -195,6 +195,13 @@ class TestGeom:
modified.substitute(np.arange(default.material.max())+1+offset,
np.arange(default.material.max())+1))
def test_substitute_invariant(self,default):
f = np.unique(default.material.flatten())[:np.random.randint(1,default.material.max())]
t = np.random.permutation(f)
modified = default.substitute(f,t)
assert np.array_equiv(t,f) or (not geom_equal(modified,default))
assert geom_equal(default, modified.substitute(t,f))
@pytest.mark.parametrize('axis_angle',[np.array([1,0,0,86.7]), np.array([0,1,0,90.4]), np.array([0,0,1,90]),
np.array([1,0,0,175]),np.array([0,-1,0,178]),np.array([0,0,1,180])])