Skip to content

Commit a199c5f

Browse files
authored
Merge branch 'main' into dokken/group_integrals_v2
2 parents 19bdc4a + 019bdc7 commit a199c5f

File tree

4 files changed

+10
-36
lines changed

4 files changed

+10
-36
lines changed

ffcx/analysis.py

+4-21
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def _analyze_form(form: ufl.form.Form, options: typing.Dict) -> ufl.algorithms.f
181181
assert np.allclose(e._points, custom_q[0])
182182
assert np.allclose(e._weights, custom_q[1])
183183

184-
# Determine unique quadrature degree, quadrature scheme and
185-
# precision per each integral data
184+
# Determine unique quadrature degree and quadrature scheme
185+
# per each integral data
186186
for id, integral_data in enumerate(form_data.integral_data):
187187
# Iterate through groups of integral data. There is one integral
188188
# data for all integrals with same domain, itype, subdomain_id
@@ -192,22 +192,6 @@ def _analyze_form(form: ufl.form.Form, options: typing.Dict) -> ufl.algorithms.f
192192
# all integrals in this integral data group, i.e. must be the
193193
# same for for the same (domain, itype, subdomain_id)
194194

195-
# Extract precision
196-
p_default = -1
197-
precisions = set([integral.metadata().get("precision", p_default)
198-
for integral in integral_data.integrals])
199-
precisions.discard(p_default)
200-
201-
if len(precisions) == 1:
202-
p = precisions.pop()
203-
elif len(precisions) == 0:
204-
# Default precision
205-
p = None
206-
else:
207-
raise RuntimeError("Only one precision allowed within integrals grouped by subdomain.")
208-
209-
integral_data.metadata["precision"] = p
210-
211195
qd_default = -1
212196
qr_default = "default"
213197

@@ -228,12 +212,11 @@ def _analyze_form(form: ufl.form.Form, options: typing.Dict) -> ufl.algorithms.f
228212
logger.info(f"Integral {i}, integral group {id}:")
229213
logger.info(f"--- quadrature rule: {qr}")
230214
logger.info(f"--- quadrature degree: {qd}")
231-
logger.info(f"--- precision: {p}")
232215

233-
metadata.update({"quadrature_degree": qd, "quadrature_rule": qr, "precision": p})
216+
metadata.update({"quadrature_degree": qd, "quadrature_rule": qr})
234217
else:
235218
metadata.update({"quadrature_points": custom_q[0], "quadrature_weights": custom_q[1],
236-
"quadrature_rule": "custom", "precision": p})
219+
"quadrature_rule": "custom"})
237220

238221
integral_data.integrals[i] = integral.reconstruct(metadata=metadata)
239222

ffcx/codegeneration/C/c_implementation.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
import warnings
88
import ffcx.codegeneration.lnodes as L
9-
from ffcx.codegeneration.utils import scalar_to_value_type, cdtype_to_numpy
10-
import numpy as np
9+
from ffcx.codegeneration.utils import scalar_to_value_type
1110

1211
math_table = {
1312
"double": {
@@ -139,22 +138,16 @@
139138

140139

141140
class CFormatter(object):
142-
def __init__(self, scalar, precision=None) -> None:
141+
def __init__(self, scalar) -> None:
143142
self.scalar_type = scalar
144143
self.real_type = scalar_to_value_type(scalar)
145-
if precision is None:
146-
np_type = cdtype_to_numpy(self.real_type)
147-
self.precision = np.finfo(np_type).precision + 1
148-
else:
149-
assert isinstance(precision, int)
150-
self.precision = precision
151144

152145
def _format_number(self, x):
153-
p = self.precision
146+
# Use 16sf for precision (good for float64 or less)
154147
if isinstance(x, complex):
155-
return f"({x.real:.{p}}+I*{x.imag:.{p}})"
148+
return f"({x.real:.16}+I*{x.imag:.16})"
156149
elif isinstance(x, float):
157-
return f"{x:.{p}}"
150+
return f"{x:.16}"
158151
return str(x)
159152

160153
def _build_initializer_lists(self, values):

ffcx/codegeneration/C/integrals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def generator(ir, options):
3636
parts = ig.generate()
3737

3838
# Format code as string
39-
CF = CFormatter(options["scalar_type"], ir.precision)
39+
CF = CFormatter(options["scalar_type"])
4040
body = CF.c_format(parts)
4141

4242
# Generate generic FFCx code snippets and add specific parts

ffcx/ir/representation.py

-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ class IntegralIR(typing.NamedTuple):
134134
unique_table_types: typing.Dict[str, str]
135135
integrand: typing.Dict[QuadratureRule, dict]
136136
name: str
137-
precision: int
138137
needs_facet_permutations: bool
139138
coordinate_element: str
140139

@@ -485,7 +484,6 @@ def _compute_integral_ir(form_data, form_index, element_numbers, integral_names,
485484
_offset += np.prod(constant.ufl_shape, dtype=int)
486485

487486
ir["original_constant_offsets"] = original_constant_offsets
488-
ir["precision"] = itg_data.metadata["precision"]
489487

490488
# Create map from number of quadrature points -> integrand
491489
integrands = {rule: integral.integrand() for rule, integral in sorted_integrals.items()}

0 commit comments

Comments
 (0)