示例#1
0
b = 2
x, y = symbols("x,y")
ue = (cos(4 * np.pi * y) +
      sin(2 * x)) * (1 - y**2) + a * (1 + y) / 2. + b * (1 - y) / 2.
fe = ue.diff(x, 2) + ue.diff(y, 2)

# Lambdify for faster evaluation
ul = lambdify((x, y), ue, 'numpy')
fl = lambdify((x, y), fe, 'numpy')

# Size of discretization
N = (eval(sys.argv[-2]), eval(sys.argv[-2]))

SD = Basis(N[1], scaled=True, bc=(a, b))
K1 = R2CBasis(N[0])
T = TensorProductSpace(comm, (K1, SD), axes=(1, 0))
X = T.local_mesh(
    True
)  # With broadcasting=True the shape of X is local_shape, even though the number of datapoints are still the same as in 1D
u = TrialFunction(T)
v = TestFunction(T)

# Get f on quad points
fj = fl(*X)

# Compute right hand side of Poisson equation
f_hat = Array(T)
f_hat = inner(v, fj, output_array=f_hat)
if basis == 'legendre':
    f_hat *= -1.
示例#2
0
# Use sympy to compute a rhs, given an analytical solution
x, y, z = symbols("x,y,z")
ue = cos(4 * x) + sin(4 * y) + sin(6 * z)
fe = ue.diff(x, 2) + ue.diff(y, 2) + ue.diff(z, 2)

ul = lambdify((x, y, z), ue, 'numpy')
fl = lambdify((x, y, z), fe, 'numpy')

# Size of discretization
N = (14, 15, 16)

K0 = C2CBasis(N[0])
K1 = C2CBasis(N[1])
K2 = R2CBasis(N[2])
T = TensorProductSpace(comm, (K0, K1, K2))
X = T.local_mesh(
    True
)  # With broadcasting=True the shape of X is local_shape, even though the number of datapoints are still the same as in 1D
u = TrialFunction(T)
v = TestFunction(T)

# Get f on quad points
fj = fl(*X)

# Compute right hand side
f_hat = inner(v, fj)

# Solve Poisson equation
A = inner(v, div(grad(u)))
f_hat = A.solve(f_hat)
示例#3
0
x, y, z = symbols("x,y,z")
ue = (cos(4*x) + sin(2*y) + sin(4*z))*(1-y**2)
fe = ue.diff(x, 2) + ue.diff(y, 2) + ue.diff(z, 2)

# Lambdify for faster evaluation
ul = lambdify((x, y, z), ue, 'numpy')
fl = lambdify((x, y, z), fe, 'numpy')

# Size of discretization
#N = [eval(sys.argv[-1])]*3

SD = Basis(N[0])
K1 = C2CBasis(N[1])
K2 = R2CBasis(N[2])
#T = TensorProductSpace(comm, (SD, K1, K2), axes=(0, 1, 2))
T = TensorProductSpace(comm, (K1, K1, K1), axes=(0, 1, 2))
X = T.local_mesh(True)
u = TrialFunction(T)
v = TestFunction(T)

K = T.local_wavenumbers()

if True:
    # inspect data layout
    # see poisson3D example on github
    print(comm.Get_rank(), ' spectral ', T.local_slice()) # spectral space
    print(comm.Get_rank(), ' spectral kx=',K[0][[0,-1],0,0],', ky =',K[1][0,[0,-1],0],' kz =',K[2][0,0,[0,-1]]) # spectral space
    print(comm.Get_rank(), ' physical ', T.local_slice(spectral=False)) # physical space
    print(comm.Get_rank(), ' physical x=',X[0][[0,-1],0,0],', y =',X[1][0,[0,-1],0],' z =',X[2][0,0,[0,-1]]) # physical space
    sys.exit()
示例#4
0
      sin(4 * z)) * (1 - x**2) + a * (1 + x) / 2. + b * (1 - x) / 2.
fe = ue.diff(x, 2) + ue.diff(y, 2) + ue.diff(z, 2)

# Lambdify for faster evaluation
ul = lambdify((x, y, z), ue, 'numpy')
fl = lambdify((x, y, z), fe, 'numpy')

# Size of discretization
N = eval(sys.argv[-2])
N = [N, N + 1, N + 2]
#N = (14, 15, 16)

SD = Basis(N[0], bc=(a, b))
K1 = C2CBasis(N[1])
K2 = R2CBasis(N[2])
T = TensorProductSpace(comm, (SD, K1, K2), axes=(0, 1, 2), slab=True)
X = T.local_mesh(
)  # With broadcasting=True the shape of X is local_shape, even though the number of datapoints are still the same as in 1D
u = TrialFunction(T)
v = TestFunction(T)

K = T.local_wavenumbers()

# Get f on quad points
fj = fl(*X)

# Compute right hand side of Poisson equation
f_hat = inner(v, fj)
if basis == 'legendre':
    f_hat *= -1.
示例#5
0
# Use sympy to compute a rhs, given an analytical solution
a = 2.
x, y = symbols("x,y")
ue = (cos(4 * y) * sin(2 * x)) * (1 - x**2) * (1 - y**2)
fe = a * ue - ue.diff(x, 2) - ue.diff(y, 2)

# Lambdify for faster evaluation
ul = lambdify((x, y), ue, 'numpy')
fl = lambdify((x, y), fe, 'numpy')

# Size of discretization
N = (32, 34)

SD0 = Basis(N[0], scaled=True)
SD1 = Basis(N[1], scaled=True)
T = TensorProductSpace(comm, (SD0, SD1))
X = T.local_mesh(True)
u = TrialFunction(T)
v = TestFunction(T)

# Get f on quad points
fj = fl(*X)

# Compute right hand side of Poisson equation
f_hat = inner(v, fj)

# Get left hand side of Poisson equation
matrices = inner(grad(v), grad(u))
matrices += inner(v, a * u)

# Create Helmholtz linear algebra solver