Skip to content

Commit

Permalink
Make precision work
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrichardson committed Aug 31, 2023
1 parent b4683a5 commit 5198ba6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
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})
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
6 changes: 3 additions & 3 deletions ffcx/codegeneration/C/c_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ def __init__(self, scalar, precision=None) -> None:
self.precision = precision

def _format_number(self, x):
prec = self.precision
p = self.precision
if isinstance(x, complex):
return "({:.{prec}}+I*{:.{prec}})".format(x.real, x.imag, prec=prec)
return f"({x.real:.{p}}+I*{x.imag:.{p}})"
elif isinstance(x, float):
return "{:.{prec}}".format(x, prec=prec)
return f"{x:.{p}}"
return str(x)

def _build_initializer_lists(self, values):
Expand Down
2 changes: 1 addition & 1 deletion ffcx/codegeneration/C/integrals.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def generator(ir, options):
parts = ig.generate()

# Format code as string
CF = CFormatter(options["scalar_type"])
CF = CFormatter(options["scalar_type"], ir.precision)
body = CF.c_format(parts)

# Generate generic FFCx code snippets and add specific parts
Expand Down

0 comments on commit 5198ba6

Please sign in to comment.