Exemplo n.º 1
0
def test_tensor2():
    B0 = shenfun.FunctionSpace(8, 'C')
    T = shenfun.TensorProductSpace(comm, (B0, B0))
    x, y = sp.symbols('x,y')
    ue = x**2 + y**2
    ua = shenfun.Array(T, buffer=ue)
    uh = ua.forward()
    M = shenfun.VectorSpace(T)
    gradu = shenfun.project(grad(uh), M)
Exemplo n.º 2
0
def test_tensor2():
    B0 = shenfun.FunctionSpace(8, 'C')
    T = shenfun.TensorProductSpace(comm, (B0, B0))
    x, y = sp.symbols('x,y')
    ue = x**2 + y**2
    ua = shenfun.Array(T, buffer=ue)
    uh = ua.forward()
    M = shenfun.VectorSpace(T)
    gradu = shenfun.project(grad(uh), M)
    V = shenfun.TensorSpace(T)
    gradgradu = shenfun.project(grad(grad(uh)), V)
    g = gradgradu.backward()
    assert np.allclose(g.v[0], 2)
    assert np.allclose(g.v[1], 0)
    assert np.allclose(g.v[2], 0)
    assert np.allclose(g.v[3], 2)
Exemplo n.º 3
0
    def _setup_function_space(self):
        self._nonhomogeneous_bcs = False
        self._function_spaces = []
        vec_space = []
        for i in range(self._dim):
            tens_space = []
            for j in range(self._dim):
                basis = sf.FunctionSpace(self._N[j],
                                         family='legendre',
                                         bc=self._bcs[i][j],
                                         domain=tuple(self._domain[j]))
                if basis.has_nonhomogeneous_bcs:
                    self._nonhomogeneous_bcs = True
                tens_space.append(basis)
            self._function_spaces.append(tens_space)
            vec_space.append(sf.TensorProductSpace(comm, tuple(tens_space)))

        self._V = sf.VectorSpace(vec_space)
    def get_dimensional_solution(self):
        assert hasattr(self, "_solution")
        vec_space = list()
        for i in range(self._dim):
            tens_space = []
            for j in range(self._dim):
                basis = sf.FunctionSpace(self._N[j], family='legendre',
                                         bc=self._bcs[i][j],
                                         domain=tuple(self._domain[j]))
                tens_space.append(basis)
            vec_space.append(sf.TensorProductSpace(sf.comm, tuple(tens_space)))

        V = sf.VectorSpace(vec_space)
        u_hat = sf.Function(V)
        for i in range(self._dim):
            # u has the same expansions coefficients as u_dimless
            u_hat[i] = self._u_ref * self._solution[i]
        return u_hat
Exemplo n.º 5
0
import numpy as np
import sympy as sp
from mpi4py import MPI
import shenfun
from shenfun import inner, div, grad, curl

N = 8
comm = MPI.COMM_WORLD

V = shenfun.FunctionSpace(N, 'C')
u0 = shenfun.TrialFunction(V)

T = shenfun.TensorProductSpace(comm, (V, V))
u1 = shenfun.TrialFunction(V)

TT = shenfun.VectorSpace(T)
u2 = shenfun.TrialFunction(TT)


@pytest.mark.parametrize('basis', (u0, u1, u2))
def test_mul(basis):
    e = shenfun.Expr(basis)
    e2 = 2 * e
    assert np.allclose(np.array(e2.scales()).astype(np.int), 2)
    e2 = e * 2
    assert np.allclose(np.array(e2.scales()).astype(np.int), 2.)
    if e.expr_rank() == 1:
        a = tuple(range(e.dimensions))
        e2 = a * e
        assert np.allclose(np.array(e2.scales()).astype(np.int)[:, 0], (0, 1))