def __init__(self, blocks): blocks = np.array(blocks) assert 1 <= blocks.ndim <= 2 if self.blocked_source and self.blocked_range: assert blocks.ndim == 2 elif self.blocked_source: if blocks.ndim == 1: blocks.shape = (1, len(blocks)) else: if blocks.ndim == 1: blocks.shape = (len(blocks), 1) self.blocks = blocks assert all( isinstance(op, OperatorInterface) or op is None for op in self._operators()) # check if every row/column contains at least one operator assert all( any(blocks[i, j] is not None for j in range(blocks.shape[1])) for i in range(blocks.shape[0])) assert all( any(blocks[i, j] is not None for i in range(blocks.shape[0])) for j in range(blocks.shape[1])) # find source/range spaces for every column/row source_spaces = [None for j in range(blocks.shape[1])] range_spaces = [None for i in range(blocks.shape[0])] for (i, j), op in np.ndenumerate(blocks): if op is not None: assert source_spaces[j] is None or op.source == source_spaces[j] source_spaces[j] = op.source assert range_spaces[i] is None or op.range == range_spaces[i] range_spaces[i] = op.range # turn Nones to ZeroOperators for (i, j) in np.ndindex(blocks.shape): if blocks[i, j] is None: self.blocks[i, j] = ZeroOperator(range_spaces[i], source_spaces[j]) self.source = BlockVectorSpace( source_spaces) if self.blocked_source else source_spaces[0] self.range = BlockVectorSpace( range_spaces) if self.blocked_range else range_spaces[0] self.num_source_blocks = len(source_spaces) self.num_range_blocks = len(range_spaces) self.linear = all(op.linear for op in self._operators()) self.build_parameter_type(*self._operators())
def __init__(self, subdomain, solution_space, grid, block_space): self.subdomain, self.grid, self.block_space = subdomain, grid, block_space self.neighborhood = grid.neighborhood_of(subdomain) self.source = solution_space.subspaces[subdomain] self.range = BlockVectorSpace( [solution_space.subspaces[ii] for ii in self.neighborhood], 'OI_{}'.format(subdomain))
def test_blockspace(): from pymor.vectorarrays.block import BlockVectorSpace, BlockVectorArray from pymor.core.pickle import dump, load b = BlockVectorSpace([]) with tempfile.TemporaryFile('wb') as dp_file: dump(b, file=dp_file)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.range = BlockVectorSpace([self.global_space.subspaces[ii] for ii in self.grid.neighborhood_of(self.jj)], 'OI_{}'.format(self.jj)) self.source = BlockVectorSpace([self.global_space.subspaces[ii] for ii in self.grid.neighborhood_of(self.kk)], 'OI_{}'.format(self.kk)) if self.subdomain not in self._matrices: matrix = make_local_elliptic_matrix_operator(self.grid, self.subdomain, self.block_space.local_space(self.subdomain), self.lambda_bar, self.kappa) matrix.assemble() matrix = matrix.matrix() self._matrices[self.subdomain] = DuneXTMatrixOperator(matrix, range_id='domain_{}'.format(self.subdomain), source_id='domain_{}'.format(self.subdomain)) self.matrix = self._matrices[self.subdomain] self.range_index = self.grid.neighborhood_of(self.jj).index(self.subdomain) self.source_index = self.grid.neighborhood_of(self.kk).index(self.subdomain)
def test_block_identity_lincomb(): space = NumpyVectorSpace(10) space2 = BlockVectorSpace([space, space]) identity = BlockDiagonalOperator([IdentityOperator(space), IdentityOperator(space)]) identity2 = IdentityOperator(space2) ones = space.ones() ones2 = space2.make_array([ones, ones]) idid = identity + identity2 assert almost_equal(ones2 * 2, idid.apply(ones2)) assert almost_equal(ones2 * 2, idid.apply_adjoint(ones2)) assert almost_equal(ones2 * 0.5, idid.apply_inverse(ones2)) assert almost_equal(ones2 * 0.5, idid.apply_inverse_adjoint(ones2))
def __init__(self, subdomain, solution_space, grid, block_space, global_rt_space, subdomain_rt_spaces, lambda_xi, kappa): self.grid = grid self.block_space = block_space self.global_rt_space = global_rt_space self.subdomain_rt_spaces = subdomain_rt_spaces self.subdomain = subdomain self.neighborhood = grid.neighborhood_of(subdomain) self.lambda_xi = lambda_xi self.kappa = kappa self.source = solution_space.subspaces[subdomain] vector_type = solution_space.subspaces[0].vector_type self.range = BlockVectorSpace([ DuneXTVectorSpace(vector_type, subdomain_rt_spaces[ii].size(), 'LOCALRT_' + str(ii)) for ii in self.grid.neighborhood_of(subdomain) ], 'RT_{}'.format(subdomain))
def _block_vector_spaces(draw, np_data_list, compatible, count, dims): ret = [] rr = draw(hyst.randoms()) def _block_dims(d): bd = [] while d > 1: block_size = rr.randint(1, d) bd.append(block_size) d -= block_size if d > 0: bd.append(d) return bd for c, (d, ar) in enumerate(zip(dims, np_data_list)): # only redraw after initial for (potentially) incompatible arrays if c == 0 or (not compatible and c > 0): block_dims = _block_dims(d) constituent_spaces = [NumpyVectorSpace(dim) for dim in block_dims] # TODO this needs to be relaxed again assume(len(constituent_spaces)) ret.append((BlockVectorSpace(constituent_spaces), ar)) return ret
def block_vector_array_factory(length, dims, seed): return BlockVectorSpace( [NumpyVectorSpace(dim) for dim in dims]).from_numpy( numpy_vector_array_factory(length, sum(dims), seed).to_numpy())
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) assert self.subdomain == self.kk == self.jj self.range = BlockVectorSpace([self.global_space.subspaces[ii] for ii in self.neighborhood], 'OI_{}'.format(self.subdomain))