Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SemiNorm #325

Merged
merged 7 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions psydac/api/ast/tests/poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sympde.expr import integral
from sympde.expr import LinearForm
from sympde.expr import BilinearForm
from sympde.expr import Norm
from sympde.expr import SemiNorm
from sympde.expr.evaluation import TerminalExpr

from psydac.api.ast.fem import AST
Expand Down Expand Up @@ -51,8 +51,8 @@ def test_codegen():
Vh = discretize(V, domain_h)

error = u - sin(pi*x)*sin(pi*y)
l2norm = LogicalExpr(M, Norm(error, domain, kind='l2'))
h1norm = LogicalExpr(M, Norm(error, domain, kind='h1'))
l2norm = LogicalExpr(M, SemiNorm(error, domain, kind='l2'))
h1norm = LogicalExpr(M, SemiNorm(error, domain, kind='h1'))

ast_b = AST(b, TerminalExpr(b)[0],[Vh, Vh])
ast_b = parse(ast_b.expr, settings={'dim':2,'nderiv':1,'mapping':M,'target':domain.logical_domain})
Expand Down
8 changes: 4 additions & 4 deletions psydac/api/ast/tests/system_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sympde.expr import integral
from sympde.expr import LinearForm
from sympde.expr import BilinearForm
from sympde.expr import Norm
from sympde.expr import SemiNorm

from sympde.expr.evaluation import TerminalExpr

Expand Down Expand Up @@ -54,8 +54,8 @@ def test_codegen():
l = LinearForm(v, int_0(dot(f, v)))

error = Matrix([F[0]-Fe[0], F[1]-Fe[1]])
l2norm_F = Norm(error, domain, kind='l2')
h1norm_F = Norm(error, domain, kind='h1')
l2norm_F = SemiNorm(error, domain, kind='l2')
h1norm_F = SemiNorm(error, domain, kind='h1')

# Create computational domain from topological domain
domain_h = discretize(domain, filename=filename)
Expand All @@ -73,7 +73,7 @@ def test_codegen():
stmt_l = parse(ast_l.expr, settings={'dim':2,'nderiv':1, 'mapping':Vh.symbolic_mapping})
print(pycode(stmt_l))

print('============================================Norm===========================================')
print('============================================SemiNorm===========================================')
ast_norm = AST(h1norm_F, TerminalExpr(h1norm_F)[0], Vh)
stmt_n = parse(ast_norm.expr, settings={'dim':2,'nderiv':1, 'mapping':Vh.symbolic_mapping})
print(pycode(stmt_n))
Expand Down
4 changes: 2 additions & 2 deletions psydac/api/discretization.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sympde.expr import LinearForm as sym_LinearForm
from sympde.expr import Functional as sym_Functional
from sympde.expr import Equation as sym_Equation
from sympde.expr import Norm as sym_Norm
from sympde.expr import Norm as sym_Norm, SemiNorm as sym_SemiNorm
from sympde.expr import TerminalExpr

from sympde.topology import BasicFunctionSpace
Expand Down Expand Up @@ -445,7 +445,7 @@ def discretize(a, *args, **kwargs):
kwargs['symbolic_mapping'] = mapping

if isinstance(a, sym_BasicForm):
if isinstance(a, sym_Norm):
if isinstance(a, (sym_Norm,sym_SemiNorm)):
kernel_expr = TerminalExpr(a, domain)
if not mapping is None:
kernel_expr = tuple(LogicalExpr(i, domain) for i in kernel_expr)
Expand Down
6 changes: 3 additions & 3 deletions psydac/api/fem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sympde.expr import BilinearForm as sym_BilinearForm
from sympde.expr import LinearForm as sym_LinearForm
from sympde.expr import Functional as sym_Functional
from sympde.expr import Norm as sym_Norm
from sympde.expr import SemiNorm as sym_SemiNorm
from sympde.topology import Boundary, Interface
from sympde.topology import VectorFunctionSpace
from sympde.topology import ProductSpace
Expand Down Expand Up @@ -1525,7 +1525,7 @@ def assemble(self, **kwargs):

Example
--------------
n = Norm(1.0j*v, domain, kind='l2')
n = SemiNorm(1.0j*v, domain, kind='l2')
nh = discretize(n, domain_h, Vh , **kwargs)
fh = FemField(Vh)
fh.coeffs[:] = 1
Expand Down Expand Up @@ -1555,7 +1555,7 @@ def assemble(self, **kwargs):
args += (v, )

v = self._func(*args)
if isinstance(self.expr, sym_Norm):
if isinstance(self.expr, sym_SemiNorm):
saidctb marked this conversation as resolved.
Show resolved Hide resolved
if not( self.comm is None ):
v = self.comm.allreduce(sendobj=v)

Expand Down
8 changes: 4 additions & 4 deletions psydac/api/tests/test_2d_biharmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sympde.topology import Square
from sympde.topology import Union
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm
from sympde.expr import SemiNorm
from sympde.expr import find, EssentialBC

from psydac.api.discretization import discretize
Expand Down Expand Up @@ -74,9 +74,9 @@ def run_biharmonic_2d_dir(solution, f, dir_zero_boundary, ncells, degree, backen

# Error norms
error = u - solution
l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
h2norm = Norm(error, domain, kind='h2')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')
h2norm = SemiNorm(error, domain, kind='h2')
saidctb marked this conversation as resolved.
Show resolved Hide resolved

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down
18 changes: 9 additions & 9 deletions psydac/api/tests/test_2d_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sympde.topology import Domain, Square
from sympde.topology import IdentityMapping, AffineMapping, PolarMapping
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm
from sympde.expr import SemiNorm
from sympde.expr import find, EssentialBC

from psydac.api.discretization import discretize
Expand Down Expand Up @@ -87,9 +87,9 @@ def run_biharmonic_2d_dir(solution, f, dir_zero_boundary, ncells=None, degree=No

# Error norms
error = u - solution
l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
h2norm = Norm(error, domain, kind='h2')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')
h2norm = SemiNorm(error, domain, kind='h2')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down Expand Up @@ -170,8 +170,8 @@ def run_poisson_2d(solution, f, domain, ncells=None, degree=None, filename=None,

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

l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down Expand Up @@ -223,8 +223,8 @@ def run_helmholtz_2d(solution, kappa, e_w_0, dx_e_w_0, domain, ncells=None, degr

equation = find(u, forall=v, lhs=a(u,v), rhs=l(v))

l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down Expand Up @@ -291,7 +291,7 @@ def run_maxwell_2d(uex, f, alpha, domain, *, ncells=None, degree=None, filename=

equation = find(u, forall=v, lhs=a(u, v), rhs=l(v))

l2norm = Norm(error, domain, kind='l2')
l2norm = SemiNorm(error, domain, kind='l2')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down
6 changes: 3 additions & 3 deletions psydac/api/tests/test_2d_laplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sympde.topology import Square
from sympde.topology import Union
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm
from sympde.expr import SemiNorm
from sympde.expr import find, EssentialBC

from psydac.api.discretization import discretize
Expand Down Expand Up @@ -78,8 +78,8 @@ def run_laplace_2d(solution, f, dir_zero_boundary, dir_nonzero_boundary,

# Error norms
error = u - solution
l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down
8 changes: 4 additions & 4 deletions psydac/api/tests/test_2d_mapping_biharmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from sympde.topology import Domain,Square
from sympde.topology import Union
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm
from sympde.expr import SemiNorm
from sympde.expr import find, EssentialBC

from psydac.api.discretization import discretize
Expand Down Expand Up @@ -100,9 +100,9 @@ def run_biharmonic_2d_dir(filename, solution, f, dir_zero_boundary,

# Error norms
error = u - solution
l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
h2norm = Norm(error, domain, kind='h2')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')
h2norm = SemiNorm(error, domain, kind='h2')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down
6 changes: 3 additions & 3 deletions psydac/api/tests/test_2d_mapping_laplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from sympde.topology import Domain,Square
from sympde.topology import Union
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm
from sympde.expr import SemiNorm
from sympde.expr import find, EssentialBC

from psydac.api.discretization import discretize
Expand Down Expand Up @@ -101,8 +101,8 @@ def run_laplace_2d(filename, solution, f, dir_zero_boundary,

# Error norms
error = u - solution
l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down
6 changes: 3 additions & 3 deletions psydac/api/tests/test_2d_mapping_poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from sympde.topology import Domain
from sympde.topology import Union
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm
from sympde.expr import SemiNorm
from sympde.expr import find, EssentialBC

from psydac.api.discretization import discretize
Expand Down Expand Up @@ -106,8 +106,8 @@ def run_poisson_2d(filename, solution, f, dir_zero_boundary,

# Error norms
error = u - solution
l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down
4 changes: 2 additions & 2 deletions psydac/api/tests/test_2d_multipatch_mapping_maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sympde.topology import IdentityMapping, PolarMapping
from sympde.expr.expr import LinearForm, BilinearForm
from sympde.expr.expr import integral
from sympde.expr.expr import Norm
from sympde.expr.expr import SemiNorm
from sympde.expr.equation import find, EssentialBC

from psydac.api.discretization import discretize
Expand Down Expand Up @@ -78,7 +78,7 @@ def run_maxwell_2d(uex, f, alpha, domain, *, ncells=None, degree=None, filename=

equation = find(u, forall=v, lhs=a(u,v), rhs=l(v))

l2norm = Norm(error, domain, kind='l2')
l2norm = SemiNorm(error, domain, kind='l2')
#+++++++++++++++++++++++++++++++
# 2. Discretization
#+++++++++++++++++++++++++++++++
Expand Down
6 changes: 3 additions & 3 deletions psydac/api/tests/test_2d_multipatch_mapping_poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sympde.topology import IdentityMapping, PolarMapping, AffineMapping
from sympde.expr.expr import LinearForm, BilinearForm
from sympde.expr.expr import integral
from sympde.expr.expr import Norm
from sympde.expr.expr import SemiNorm
from sympde.expr.equation import find, EssentialBC

from psydac.api.discretization import discretize
Expand Down Expand Up @@ -76,8 +76,8 @@ def run_poisson_2d(solution, f, domain, ncells=None, degree=None, filename=None,

equation = find(u, forall=v, lhs=a(u,v), rhs=l(v))

l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down
6 changes: 3 additions & 3 deletions psydac/api/tests/test_2d_multipatch_poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sympde.topology import IdentityMapping, AffineMapping
from sympde.expr.expr import LinearForm, BilinearForm
from sympde.expr.expr import integral
from sympde.expr.expr import Norm
from sympde.expr.expr import SemiNorm
from sympde.expr.equation import find, EssentialBC

from psydac.api.discretization import discretize
Expand Down Expand Up @@ -53,8 +53,8 @@ def run_poisson_2d(solution, f, domain, ncells, degree):

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

l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down
14 changes: 7 additions & 7 deletions psydac/api/tests/test_2d_navier_stokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from sympde.topology import element_of, elements_of
from sympde.topology import Domain, Square, Union
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm
from sympde.expr import SemiNorm
from sympde.expr import find, EssentialBC
from sympde.core import Constant
from sympde.expr import TerminalExpr
Expand Down Expand Up @@ -125,8 +125,8 @@ def run_time_dependent_navier_stokes_2d(filename, dt_h, nt, newton_tol=1e-4, max
equation_stokes = find((du, dp), forall=(v, q), lhs=a_stokes((du, dp), (v, q)), rhs=l_stokes(v, q), bc=bc)

# Define (abstract) norms
l2norm_du = Norm(Matrix([du[0],du[1]]), domain, kind='l2')
l2norm_dp = Norm(dp , domain, kind='l2')
l2norm_du = SemiNorm(Matrix([du[0],du[1]]), domain, kind='l2')
l2norm_dp = SemiNorm(dp , domain, kind='l2')

# ... create the computational domain from a topological domain
domain_h = discretize(domain, filename=filename)
Expand Down Expand Up @@ -262,11 +262,11 @@ def run_steady_state_navier_stokes_2d(domain, f, ue, pe, *, ncells, degree, mult
equation = find((du, dp), forall=(v, q), lhs=a((du, dp), (v, q)), rhs=l(v, q), bc=bc)

# Define (abstract) norms
l2norm_u = Norm(Matrix([u[0]-ue[0],u[1]-ue[1]]), domain, kind='l2')
l2norm_p = Norm(p-pe , domain, kind='l2')
l2norm_u = SemiNorm(Matrix([u[0]-ue[0],u[1]-ue[1]]), domain, kind='l2')
l2norm_p = SemiNorm(p-pe , domain, kind='l2')

l2norm_du = Norm(Matrix([du[0],du[1]]), domain, kind='l2')
l2norm_dp = Norm(dp , domain, kind='l2')
l2norm_du = SemiNorm(Matrix([du[0],du[1]]), domain, kind='l2')
l2norm_dp = SemiNorm(dp , domain, kind='l2')

# ... create the computational domain from a topological domain
domain_h = discretize(domain, ncells=ncells, comm=comm)
Expand Down
6 changes: 3 additions & 3 deletions psydac/api/tests/test_2d_poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sympde.topology import Square
from sympde.topology import Union
from sympde.expr import BilinearForm, LinearForm, integral
from sympde.expr import Norm
from sympde.expr import SemiNorm
from sympde.expr import find, EssentialBC

from psydac.api.discretization import discretize
Expand Down Expand Up @@ -83,8 +83,8 @@ def run_poisson_2d(solution, f, dir_zero_boundary, dir_nonzero_boundary,

# Error norms
error = u - solution
l2norm = Norm(error, domain, kind='l2')
h1norm = Norm(error, domain, kind='h1')
l2norm = SemiNorm(error, domain, kind='l2')
h1norm = SemiNorm(error, domain, kind='h1')

#+++++++++++++++++++++++++++++++
# 2. Discretization
Expand Down
4 changes: 2 additions & 2 deletions psydac/api/tests/test_api_1d_compatible_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sympde.topology import Line
from sympde.expr import BilinearForm, LinearForm
from sympde.expr import integral
from sympde.expr import Norm
from sympde.expr import SemiNorm
from sympde.expr import find

from psydac.fem.basic import FemField
Expand Down Expand Up @@ -39,7 +39,7 @@ def run_system_1_1d_dir(f0, sol, ncells, degree):
l = LinearForm((q,v), int_0(f0*v))

error = F-sol
l2norm_F = Norm(error, domain, kind='l2')
l2norm_F = SemiNorm(error, domain, kind='l2')


equation = find([p,u], forall=[q,v], lhs=a((p,u),(q,v)), rhs=l(q,v))
Expand Down
Loading