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

Rename CNodes as LNodes, add typing, process AST separately from creating it. #594

Merged
merged 13 commits into from
Sep 4, 2023
8 changes: 7 additions & 1 deletion demo/CellGeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# A functional M involving a bunch of cell geometry quantities.
import basix.ufl
from ufl import (CellVolume, Circumradius, Coefficient, FacetArea, FacetNormal,
SpatialCoordinate, ds, dx, tetrahedron)
SpatialCoordinate, ds, dx, tetrahedron, TrialFunction)
from ufl.geometry import FacetEdgeVectors

cell = tetrahedron
V = basix.ufl.element("P", cell.cellname(), 1)
Expand All @@ -17,3 +18,8 @@
area = FacetArea(cell)

M = u * (x[0] * vol * rad) * dx + u * (x[0] * vol * rad * area) * ds # + u*area*avg(n[0]*x[0]*vol*rad)*dS

# Test some obscure functionality
fev = FacetEdgeVectors(cell)
v = TrialFunction(V)
L = fev[0, 0] * v * ds
39 changes: 39 additions & 0 deletions demo/ComplexPoisson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (C) 2023 Chris Richardson
#
# This file is part of FFCx.
#
# FFCx is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FFCx is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with FFCx. If not, see <http://www.gnu.org/licenses/>.
#
# The bilinear form a(u, v) and linear form L(v) for
# Poisson's equation using bilinear elements on bilinear mesh geometry.
import basix.ufl
from ufl import (Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction,
dx, grad, inner)

coords = basix.ufl.element("P", "triangle", 2, rank=1)
mesh = Mesh(coords)
dx = dx(mesh)

element = basix.ufl.element("P", mesh.ufl_cell().cellname(), 2)
space = FunctionSpace(mesh, element)

u = TrialFunction(space)
v = TestFunction(space)
f = Coefficient(space)

# Test literal complex number in form
k = 3.213 + 1.023j

a = k * inner(grad(u), grad(v)) * dx
L = inner(k * f, v) * dx
2 changes: 2 additions & 0 deletions demo/MetaData.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@
+ inner(c, c) * inner(grad(u), grad(v)) * dx(1, degree=4)\
+ inner(c, c) * inner(grad(u), grad(v)) * dx(1, degree=2)\
+ inner(grad(u), grad(v)) * dx(1, degree=-1)

L = v * dx(0, metadata={"precision": 1})
6 changes: 5 additions & 1 deletion demo/test_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ def test_demo(file):
# Skip demos that use elements not yet implemented in Basix
pytest.skip()

opts = ""
if "Complex" in file:
opts = '--scalar_type "double _Complex"'

extra_flags = "-Wunused-variable -Werror -fPIC "
assert os.system(f"cd {demo_dir} && ffcx {file}.py") == 0
assert os.system(f"cd {demo_dir} && ffcx {opts} {file}.py") == 0
assert os.system(f"cd {demo_dir} && "
"CPATH=../ffcx/codegeneration/ "
f"gcc -I/usr/include/python{sys.version_info.major}.{sys.version_info.minor} {extra_flags}"
Expand Down
2 changes: 1 addition & 1 deletion ffcx/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _analyze_form(form: ufl.form.Form, options: typing.Dict) -> ufl.algorithms.f
p = precisions.pop()
elif len(precisions) == 0:
# Default precision
p = np.finfo("double").precision + 1 # == 16
p = None
else:
raise RuntimeError("Only one precision allowed within integrals grouped by subdomain.")

Expand Down
Loading
Loading