simplified

This commit is contained in:
Martin Diehl 2022-01-14 20:44:34 +01:00
parent 01cc6ffd2c
commit b796bc0697
1 changed files with 5 additions and 7 deletions

View File

@ -4,7 +4,7 @@ import warnings
import multiprocessing as mp import multiprocessing as mp
from functools import partial from functools import partial
import typing import typing
from typing import Union, Optional, TextIO, List, Sequence, Literal, Dict, Callable from typing import Union, Optional, TextIO, List, Sequence, Literal
from pathlib import Path from pathlib import Path
import numpy as np import numpy as np
@ -1069,13 +1069,11 @@ class Grid:
Updated grid-based geometry. Updated grid-based geometry.
""" """
def mp(entry: np.ndarray, mapper:Dict[np.ndarray, np.ndarray]) -> np.ndarray: material = self.material.copy()
return mapper[entry] if entry in mapper else entry for f,t in zip(from_material,to_material): # ToDo Python 3.10 has strict mode for zip
material[self.material==f] = t
mp_: Callable = np.vectorize(mp) return Grid(material = material,
mapper = dict(zip(from_material,to_material))
return Grid(material = mp_(self.material,mapper).reshape(self.cells),
size = self.size, size = self.size,
origin = self.origin, origin = self.origin,
comments = self.comments+[util.execution_stamp('Grid','substitute')], comments = self.comments+[util.execution_stamp('Grid','substitute')],