def __init__(self, a, mat_i, mat_m, mat_0, n): self.n0 = n self.n1 = n self.shape = (3 * self.n0 * self.n1, 3 * self.n0 * self.n1) self.dtype = np.float64 transform = fft.create_real((self.n0, self.n1)) self.green = green.filtered(mat_0.green_operator(), transform.ishape, 1., transform) aux_i = operators.isotropic_4((mat_i.k - mat_0.k) / 2., (mat_i.g - mat_0.g) / 2., dim=2) aux_m = operators.isotropic_4((mat_m.k - mat_0.k) / 2., (mat_m.g - mat_0.g) / 2., dim=2) op_loc = np.empty(transform.ishape, dtype=object) imax = int(np.ceil(n * a - 0.5)) for i0 in range(self.n0): for i1 in range(self.n1): if (i0 < imax) and (i1 < imax): op_loc[i0, i1] = aux_i else: op_loc[i0, i1] = aux_m self.eps2tau = operators.BlockDiagonalOperator2D(op_loc)
def __init__(self, mat_i, mat_m, mat_0, n, a=0.5, dim=3): self.mat_i = mat_i self.mat_m = mat_m self.n = n shape = tuple(itertools.repeat(n, dim)) # ... # End: init # Begin: create (C_i - C_0) and (C_m - C_0) # ... delta_C_i = isotropic_4(dim*(mat_i.k-mat_0.k), 2*(mat_i.g-mat_0.g), dim) delta_C_m = isotropic_4(dim*(mat_m.k-mat_0.k), 2*(mat_m.g-mat_0.g), dim) # ... # End: create (C_i - C_0) and (C_m - C_0) # Begin: create local operator ε ↦ (C-C_0):ε # ... ops = np.empty(shape, dtype=object) ops[:, :] = delta_C_m imax = int(np.ceil(n*a-0.5)) ops[:imax, :imax] = delta_C_i self.eps_to_tau = operators.BlockDiagonalOperator2D(ops) # ... # End: create local operator ε ↦ (C-C_0):ε # Begin: create non-local operator ε ↦ Γ_0[ε] # ... self.green = green.truncated(mat_0.green_operator(), shape, 1., fft.create_real(shape))
def __init__(self, mat_i, mat_m, mat_0, n, a=0.5, dim=3): self.mat_i = mat_i self.mat_m = mat_m self.n = n shape = tuple(itertools.repeat(n, dim)) # ... # End: init # Begin: create (C_i - C_0) and (C_m - C_0) # ... delta_C_i = isotropic_4(dim * (mat_i.k - mat_0.k), 2 * (mat_i.g - mat_0.g), dim) delta_C_m = isotropic_4(dim * (mat_m.k - mat_0.k), 2 * (mat_m.g - mat_0.g), dim) # ... # End: create (C_i - C_0) and (C_m - C_0) # Begin: create local operator ε ↦ (C-C_0):ε # ... ops = np.empty(shape, dtype=object) ops[:, :] = delta_C_m imax = int(np.ceil(n * a - 0.5)) ops[:imax, :imax] = delta_C_i self.eps_to_tau = operators.BlockDiagonalOperator2D(ops) # ... # End: create local operator ε ↦ (C-C_0):ε # Begin: create non-local operator ε ↦ Γ_0[ε] # ... self.green = green.truncated(mat_0.green_operator(), shape, 1.0, fft.create_real(shape))
def local_operators(self): global_shape = self.valid_shape()[0:self.dim] loc = np.empty(global_shape, dtype=object) for index in itertools.product(*map(range, global_shape)): loc[index] = isotropic_4(2. * np.random.rand() - 1, 2. * np.random.rand() - 1, self.dim) return loc
def test_apply(self, sph, dev, flag): """flag allows the specification of various calling sequences: - flag = 0: apply(x) - flag = 1: apply(x, x) - flag = 2: apply(x, y) """ t = isotropic_4(sph, dev, self.dim) eye = np.eye(self.sym()) expected = self.to_array(sph, dev) actual = np.empty_like(eye) for i in range(self.sym()): x = eye[:, i] if flag == 0: base = None elif flag == 1: base = x elif flag == 2: base = np.random.rand(*x.shape) ret = t.apply(eye[:, i], base) if flag != 0: assert ret.base is base actual[:, i] = ret assert_allclose(expected, actual, 1 * ULP, 0 * ULP)
def __init__(self, a, mat_i, mat_m, mat_0, n, comm=MPI.COMM_WORLD): transform = fft.create_real((n, n), comm) self.n0 = transform.ishape[0] self.n1 = transform.ishape[1] self.offset0 = transform.offset0 self.green = green.truncated(mat_0.green_operator(), (n, n), 1., transform) aux_i = operators.isotropic_4(1. / (2. * (mat_i.k - mat_0.k)), 1. / (2. * (mat_i.g - mat_0.g)), dim=2) aux_m = operators.isotropic_4(1. / (2. * (mat_m.k - mat_0.k)), 1. / (2. * (mat_m.g - mat_0.g)), dim=2) ops = np.empty(transform.ishape, dtype=object) ops[:, :] = aux_m imax = int(np.ceil(n * a - 0.5)) ops[:imax - self.offset0, :imax] = aux_i self.tau2eps = operators.BlockDiagonalOperator2D(ops)
def test_to_memoryview(self, sph, dev, flag): t = isotropic_4(sph, dev, self.dim) expected = self.to_array(sph, dev) if flag == 0: base = None elif flag == 1: base = np.random.rand(t.osize, t.isize) actual = t.to_memoryview(base) if flag != 0: assert actual.base is base assert_allclose(expected, actual, 0 * ULP, 0 * ULP)
def operator(self): return isotropic_4(1., 1., self.dim)