Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions psydac/api/tests/test_2d_biharmonic.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: UTF-8 -*-

from mpi4py import MPI
from sympy import pi, cos, sin, symbols
from sympy.utilities.lambdify import implemented_function
from sympy import pi, sin, symbols
import pytest

from sympde.calculus import grad, dot
Expand Down
31 changes: 15 additions & 16 deletions psydac/api/tests/test_2d_complex.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
# -*- coding: UTF-8 -*-
import os

from collections import OrderedDict

from mpi4py import MPI
import pytest
import numpy as np
from sympy import pi, cos, sin, symbols, conjugate, exp
from sympy import pi, cos, sin, symbols, exp
from sympy import Tuple, Matrix
from sympy import lambdify

from sympde.calculus import grad, dot, cross, curl
from sympde.calculus import grad, dot, inner, cross, curl
from sympde.calculus import minus, plus
from sympde.calculus import laplace
from sympde.topology import ScalarFunctionSpace, VectorFunctionSpace
from sympde.topology import element_of, elements_of
from sympde.topology import NormalVector
from sympde.topology import Union
from sympde.topology import Domain, Square
from sympde.topology import IdentityMapping, AffineMapping, PolarMapping
from sympde.topology import IdentityMapping, PolarMapping
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm, SemiNorm
from sympde.expr import find, EssentialBC
Expand Down Expand Up @@ -166,12 +165,12 @@ def run_poisson_2d(solution, f, domain, ncells=None, degree=None, filename=None,
- 0.5*dot(grad(minus(v)), nn) * minus(u) - 0.5*dot(grad(minus(u)), nn) * minus(v) + kappa *minus(u)*minus(v)\
+ 0.5*dot(grad( plus(v)), nn) * plus(u) + 0.5*dot(grad( plus(u)), nn) * plus(v) + kappa * plus(u)* plus(v)

expr = dot(grad(u), grad(v))
expr = inner(grad(u), grad(v))

a = BilinearForm((u, v), integral(domain, expr) + integral(I, expr_I))
l = LinearForm(v, integral(domain, f*v))

equation = find(u, forall=v, lhs=1j*a(u,v), rhs=1j*l(v), bc=bc)
equation = find(u, forall=v, lhs=1j*a(u, v), rhs=1j*l(v), bc=bc)

l2norm = Norm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')
Expand Down Expand Up @@ -215,7 +214,7 @@ def run_helmholtz_2d(solution, kappa, e_w_0, dx_e_w_0, domain, ncells=None, degr

error = u - solution

expr = dot(grad(u),grad(v)) - 2 * kappa ** 2 * u * v
expr = inner(grad(u), grad(v)) - 2 * kappa ** 2 * u * v
boundary_expr = - 1j * kappa * u * v
x_boundary = Union(domain.get_boundary(axis=0, ext=-1), domain.get_boundary(axis=0, ext=1))

Expand Down Expand Up @@ -280,11 +279,11 @@ def run_maxwell_2d(uex, f, alpha, domain, *, ncells=None, degree=None, filename=
+k*cross(nn, jump(u))*curl(avr(v))\
+kappa*cross(nn, jump(u))*cross(nn, jump(v))

expr1 = curl(u)*curl(v) + alpha*dot(u,v)
expr1_b = -cross(nn, v) * curl(u) -k*cross(nn, u) * curl(v) + kappa * cross(nn, u) * cross(nn, v)
expr1 = curl(u) * curl(v) + alpha * inner(u,v)
expr1_b = -cross(nn, v) * curl(u) -k * cross(nn, u) * curl(v) + kappa * cross(nn, u) * cross(nn, v)

expr2 = dot(f,v)
expr2_b = -k*cross(nn, uex)*curl(v) + kappa * cross(nn, uex) * cross(nn, v)
expr2 = inner(f,v)
expr2_b = -k * cross(nn, uex) * curl(v) + kappa * cross(nn, uex) * cross(nn, v)

# Bilinear form a: V x V --> R
a = BilinearForm((u, v), integral(domain, expr1) + integral(boundary, expr1_b) + integral(I, expr1_I))
Expand Down Expand Up @@ -425,8 +424,8 @@ def test_complex_helmholtz_2d(plot_sol=False):

if plot_sol:
from psydac.fem.plotting_utilities import get_plotting_grid, get_grid_vals
from psydac.fem.plotting_utilities import get_patch_knots_gridlines, my_small_plot
from psydac.feec.pull_push import pull_2d_h1
from psydac.fem.plotting_utilities import my_small_plot
from psydac.feec.pull_push import pull_2d_h1

Id_mapping = IdentityMapping('M', 2)
# print(f'domain.interior = {domain.interior}')
Expand Down Expand Up @@ -537,9 +536,9 @@ def teardown_function():
else:

from psydac.fem.plotting_utilities import get_plotting_grid, get_grid_vals
from psydac.fem.plotting_utilities import get_patch_knots_gridlines, my_small_plot
from psydac.api.tests.build_domain import build_pretzel
from psydac.feec.pull_push import pull_2d_hcurl
from psydac.fem.plotting_utilities import my_small_plot
from psydac.api.tests.build_domain import build_pretzel
from psydac.feec.pull_push import pull_2d_hcurl

domain = build_pretzel()
x,y = domain.coordinates
Expand Down
5 changes: 2 additions & 3 deletions psydac/api/tests/test_2d_laplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from sympy.utilities.lambdify import implemented_function
import pytest

from sympde.calculus import grad, dot
from sympde.calculus import laplace
from sympde.calculus import grad, dot, inner
from sympde.topology import ScalarFunctionSpace
from sympde.topology import element_of
from sympde.topology import NormalVector
Expand Down Expand Up @@ -58,7 +57,7 @@ def run_laplace_2d(solution, f, dir_zero_boundary, dir_nonzero_boundary,
nn = NormalVector('nn')

# Bilinear form a: V x V --> R
a = BilinearForm((u, v), integral(domain, dot(grad(u), grad(v)) + u * v))
a = BilinearForm((u, v), integral(domain, inner(grad(u), grad(v)) + u * v))

# Linear form l: V --> R
l0 = LinearForm(v, integral(domain, f * v))
Expand Down
8 changes: 3 additions & 5 deletions psydac/api/tests/test_2d_mapping_biharmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
# Please note that the logical coordinates (x1, x2) correspond to the polar
# coordinates (r, theta), but with reversed order: hence x1=theta and x2=r

from mpi4py import MPI
from sympy import pi, cos, sin, symbols
import pytest
import os
import numpy as np

from sympy import pi, cos, sin, symbols

from sympde.calculus import grad, dot
from sympde.calculus import laplace
from sympde.topology import ScalarFunctionSpace
from sympde.topology import element_of
from sympde.topology import NormalVector
from sympde.topology import Domain,Square
from sympde.topology import Domain
from sympde.topology import Union
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm, SemiNorm
Expand Down
13 changes: 5 additions & 8 deletions psydac/api/tests/test_2d_mapping_laplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@
# Please note that the logical coordinates (x1, x2) correspond to the polar
# coordinates (r, theta), but with reversed order: hence x1=theta and x2=r

from mpi4py import MPI
from sympy import pi, cos, sin, symbols
import pytest
import os
import numpy as np

from sympde.calculus import grad, dot
from sympde.calculus import laplace
from sympy import pi, cos, symbols

from sympde.calculus import grad, dot, inner
from sympde.topology import ScalarFunctionSpace
from sympde.topology import element_of
from sympde.topology import NormalVector
from sympde.topology import Domain,Square
from sympde.topology import Domain
from sympde.topology import Union
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm, SemiNorm
Expand Down Expand Up @@ -82,7 +79,7 @@ def run_laplace_2d(filename, solution, f, dir_zero_boundary,
nn = NormalVector('nn')

# Bilinear form a: V x V --> R
a = BilinearForm((u, v), integral(domain, dot(grad(u), grad(v)) + u * v))
a = BilinearForm((u, v), integral(domain, inner(grad(u), grad(v)) + u * v))

# Linear form l: V --> R
l0 = LinearForm(v, integral(domain, f * v))
Expand Down
5 changes: 3 additions & 2 deletions psydac/api/tests/test_2d_mapping_poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
# coordinates (r, theta), but with reversed order: hence x1=theta and x2=r

import os

from mpi4py import MPI
from sympy import pi, cos, sin, symbols
import pytest
import numpy as np

from sympde.calculus import grad, dot
from sympde.calculus import grad, dot, inner
from sympde.calculus import laplace
from sympde.topology import ScalarFunctionSpace
from sympde.topology import element_of
Expand Down Expand Up @@ -87,7 +88,7 @@ def run_poisson_2d(filename, solution, f, dir_zero_boundary,
nn = NormalVector('nn')

# Bilinear form a: V x V --> R
a = BilinearForm((u, v), integral(domain, dot(grad(u),grad(v))))
a = BilinearForm((u, v), integral(domain, inner(grad(u), grad(v))))

# Linear form l: V --> R
l0 = LinearForm(v, integral(domain, f * v))
Expand Down
29 changes: 9 additions & 20 deletions psydac/api/tests/test_2d_navier_stokes.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# -*- coding: UTF-8 -*-

import os

import pytest
import numpy as np
from sympy import pi, cos, sin, sqrt, exp, ImmutableDenseMatrix as Matrix, Tuple, lambdify
from sympy import pi, cos, sin, exp, ImmutableDenseMatrix as Matrix, Tuple
from scipy.sparse.linalg import spsolve
from scipy.sparse.linalg import gmres as sp_gmres
from scipy.sparse.linalg import minres as sp_minres
from scipy.sparse.linalg import cg as sp_cg
from scipy.sparse.linalg import bicg as sp_bicg
from scipy.sparse.linalg import bicgstab as sp_bicgstab

from sympde.calculus import grad, dot, inner, div, curl, cross
from sympde.calculus import grad, inner, div
from sympde.calculus import Transpose, laplace
from sympde.topology import NormalVector
from sympde.topology import ScalarFunctionSpace, VectorFunctionSpace
from sympde.topology import ProductSpace
from sympde.topology import element_of, elements_of
Expand Down Expand Up @@ -111,16 +106,16 @@ def run_time_dependent_navier_stokes_2d(filename, dt_h, nt, newton_tol=1e-4, max
Re = 1e4

Fl = lambda u,p: Re**-1*inner(grad(u), grad(v)) - div(u)*q - p*div(v) + 1e-10*p*q
F = lambda u,p: dot(Transpose(grad(u))*u,v) + Fl(u,p)
F = lambda u,p: inner(Transpose(grad(u))*u,v) + Fl(u,p)

l = LinearForm((v, q), integral(domain, dot(u,v)-dot(u0,v) + dt/2 * (F(u,p) + F(u0,p0)) ))
l = LinearForm((v, q), integral(domain, inner(u,v)-inner(u0,v) + dt/2 * (F(u,p) + F(u0,p0)) ))
a = linearize(l, (u,p), trials=(du, dp))

equation = find((du, dp), forall=(v, q), lhs=a((du, dp), (v, q)), rhs=l(v, q), bc=bc)

# Use the stokes equation to compute the initial solution
a_stokes = BilinearForm(((du,dp),(v, q)), integral(domain, Fl(du,dp)) )
l_stokes = LinearForm((v, q), integral(domain, dot(v,Tuple(0,0)) ))
l_stokes = LinearForm((v, q), integral(domain, inner(v,Tuple(0,0)) ))

equation_stokes = find((du, dp), forall=(v, q), lhs=a_stokes((du, dp), (v, q)), rhs=l_stokes(v, q), bc=bc)

Expand Down Expand Up @@ -249,12 +244,12 @@ def run_steady_state_navier_stokes_2d(domain, f, ue, pe, *, ncells, degree, mult

boundary = Union(*[domain.get_boundary(**kw) for kw in get_boundaries(1,2)])

a_b = BilinearForm(((u,p),(v, q)), integral(boundary, dot(u,v)) )
l_b = LinearForm((v, q), integral(boundary, dot(ue, v)) )
a_b = BilinearForm(((u,p),(v, q)), integral(boundary, inner(u,v)) )
l_b = LinearForm((v, q), integral(boundary, inner(ue, v)) )

equation_b = find((u, p), forall=(v, q), lhs=a_b((u, p), (v, q)), rhs=l_b(v, q))

l = LinearForm((v, q), integral(domain, dot(Transpose(grad(u))*u, v) + inner(grad(u), grad(v)) - div(u)*q - p*div(v) - dot(f, v)) )
l = LinearForm((v, q), integral(domain, inner(Transpose(grad(u))*u, v) + inner(grad(u), grad(v)) - div(u)*q - p*div(v) - inner(f, v)) )
a = linearize(l, (u,p), trials=(du, dp))

bc = EssentialBC(du, 0, boundary)
Expand Down Expand Up @@ -357,9 +352,6 @@ def test_st_navier_stokes_2d():
assert (ux.diff(x) + uy.diff(y)).simplify() == 0

# ... Compute right-hand side
from sympde.calculus import laplace, grad
from sympde.expr import TerminalExpr

a = TerminalExpr(-mu*laplace(ue), domain)
b = TerminalExpr( grad(ue), domain)
c = TerminalExpr( grad(pe), domain)
Expand Down Expand Up @@ -411,9 +403,6 @@ def test_st_navier_stokes_2d_parallel():
assert (ux.diff(x) + uy.diff(y)).simplify() == 0

# ... Compute right-hand side
from sympde.calculus import laplace, grad
from sympde.expr import TerminalExpr

a = TerminalExpr(-mu*laplace(ue), domain)
b = TerminalExpr( grad(ue), domain)
c = TerminalExpr( grad(pe), domain)
Expand Down
4 changes: 2 additions & 2 deletions psydac/api/tests/test_2d_poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sympy.utilities.lambdify import implemented_function
import pytest

from sympde.calculus import grad, dot
from sympde.calculus import grad, dot, inner
from sympde.topology import ScalarFunctionSpace
from sympde.topology import element_of
from sympde.topology import NormalVector
Expand Down Expand Up @@ -63,7 +63,7 @@ def run_poisson_2d(solution, f, dir_zero_boundary, dir_nonzero_boundary,
nn = NormalVector('nn')

# Bilinear form a: V x V --> R
a = BilinearForm((u, v), integral(domain, dot(grad(u), grad(v))))
a = BilinearForm((u, v), integral(domain, inner(grad(u), grad(v))))

# Linear form l: V --> R
l0 = LinearForm(v, integral(domain, f * v))
Expand Down
6 changes: 3 additions & 3 deletions psydac/api/tests/test_api_1d_compatible_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sympy import pi, sin
from scipy.sparse.linalg import spsolve

from sympde.calculus import dot, div
from sympde.calculus import inner, div
from sympde.topology import VectorFunctionSpace, ScalarFunctionSpace
from sympde.topology import ProductSpace
from sympde.topology import element_of
Expand Down Expand Up @@ -35,8 +35,8 @@ def run_system_1_1d_dir(f0, sol, ncells, degree):

int_0 = lambda expr: integral(domain , expr)

a = BilinearForm(((p,u),(q,v)), int_0(dot(p,q) + div(q)*u + div(p)*v))
l = LinearForm((q,v), int_0(f0*v))
a = BilinearForm(((p, u), (q, v)), int_0(inner(p, q) + div(q) * u + div(p) * v))
l = LinearForm((q, v), int_0(f0 * v))

error = F-sol
l2norm_F = Norm(error, domain, kind='l2')
Expand Down
Loading