def create(cls, config: 'SimulationConfig'): """Generate a new state object from a config.""" shape = ( config.getint('simulation', 'nz'), config.getint('simulation', 'ny'), config.getint('simulation', 'nx'), ) spacing = ( config.getfloat('simulation', 'dz'), config.getfloat('simulation', 'dy'), config.getfloat('simulation', 'dx'), ) grid = RectangularGrid.construct_uniform(shape, spacing) state = State(time=0.0, grid=grid, config=config) for module in state.config.modules: if hasattr(state, module.name): # prevent modules from overriding existing class attributes raise ValueError( f'The name "{module.name}" is a reserved token.') with validation_context(f'{module.name} (construction)'): state._extra[module.name] = module.StateClass( global_state=state) module.construct(state) return state
def __init__(self, shape: ShapeType, space: SpacingType, scale: int, randomness: int): self.scale = scale self.randomness = randomness self.shape = (shape[0] * scale, shape[1] * scale, shape[2] * scale) self.space = space self.grid = RectangularGrid.construct_uniform(self.shape, self.space) self.geo = self.grid.allocate_variable(dtype=np.dtype(np.int8)) self.geo.fill(2) self.fixed = np.zeros(self.shape) self.duct_f: List[Union[Sphere, Cylinder]] = [] self.sac_f: List[Union[Sphere, Cylinder]] = []
def create(cls, config: 'SimulationConfig'): """Generate a new state object from a config.""" voxel_volume = config.getfloat('simulation', 'voxel_volume') lung_tissue = get_geometry_file( config.get('simulation', 'geometry_path')) # python type checker isn't enough to understand this assert len(lung_tissue.shape) == 3 # noinspection PyTypeChecker shape: Tuple[int, int, int] = lung_tissue.shape space_volume = voxel_volume * np.product(shape) spacing = ( config.getfloat('simulation', 'dz'), config.getfloat('simulation', 'dy'), config.getfloat('simulation', 'dx'), ) grid = RectangularGrid.construct_uniform(shape, spacing) state = State( time=0.0, grid=grid, config=config, lung_tissue=lung_tissue, voxel_volume=voxel_volume, space_volume=space_volume, ) for module in state.config.modules: if hasattr(state, module.name): # prevent modules from overriding existing class attributes raise ValueError( f'The name "{module.name}" is a reserved token.') with validation_context(f'{module.name} (construction)'): state._extra[module.name] = module.StateClass( global_state=state) module.construct(state) return state
def grid(): # a 100 x 100 x 100 unit grid yield RectangularGrid.construct_uniform((10, 10, 10), (10, 10, 10))
def grid(): shape = [10, 20, 30] spacing = [1, 1, 1] yield RectangularGrid.construct_uniform(shape=shape, spacing=spacing)
def grid(): yield RectangularGrid.construct_uniform(shape=(3, 3, 3), spacing=(1, 1, 1))