Skip to content

Commit

Permalink
remove dim_fudge_factor changes and bump oversampling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Sep 24, 2021
1 parent a5dc153 commit 6e04fb7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 62 deletions.
29 changes: 3 additions & 26 deletions pytential/symbolic/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from sys import intern
from warnings import warn
from functools import wraps, partial
from contextlib import contextmanager

import numpy as np
from pymbolic.primitives import ( # noqa: F401,N813
Expand Down Expand Up @@ -1009,29 +1008,11 @@ def _scaled_max_curvature(ambient_dim, dim=None, dofdesc=None):

# {{{ qbx-specific geometry

_EXPANSION_RADII_FUDGE_FACTOR = None


@contextmanager
def _expansion_radii_fudge_factor(factor: float):
global _EXPANSION_RADII_FUDGE_FACTOR
_EXPANSION_RADII_FUDGE_FACTOR = factor

try:
yield None
finally:
_EXPANSION_RADII_FUDGE_FACTOR = None


def _expansion_radii_factor(ambient_dim, dim):
if dim is None:
dim = ambient_dim - 1

if _EXPANSION_RADII_FUDGE_FACTOR is None:
dim_fudge_factor = 0.5 if dim == 2 else 1.0
else:
dim_fudge_factor = _EXPANSION_RADII_FUDGE_FACTOR

dim_fudge_factor = 0.5 if dim == 2 else 1.0
return 0.5 * dim_fudge_factor


Expand Down Expand Up @@ -1083,13 +1064,9 @@ def _close_target_tunnel_radii(ambient_dim, dim=None,

@_deprecate_kwargs("where", "dofdesc")
def expansion_radii(ambient_dim, dim=None, granularity=None, dofdesc=None):
dofdesc = as_dofdesc(dofdesc)

factor = _expansion_radii_factor(ambient_dim, dim)
element_radius = _quad_resolution(ambient_dim, dim=dim,
granularity=granularity, dofdesc=dofdesc)

return cse(factor * element_radius,
return cse(factor * _quad_resolution(ambient_dim, dim=dim,
granularity=granularity, dofdesc=dofdesc),
"expansion_radii",
cse_scope.DISCRETIZATION)

Expand Down
69 changes: 33 additions & 36 deletions test/test_stokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,25 @@ def test_exterior_stokes(actx_factory, ambient_dim, visualize=False):
else:
raise ValueError(f"unsupported dimension: {ambient_dim}")

from pytential.symbolic.primitives import _expansion_radii_fudge_factor
with _expansion_radii_fudge_factor(1.25):
for resolution in resolutions:
h_max, errors = run_exterior_stokes(actx_factory,
ambient_dim=ambient_dim,
target_order=target_order,
qbx_order=qbx_order,
source_ovsmp=source_ovsmp,
resolution=resolution,
visualize=visualize)

for eoc, e in zip(eocs, errors):
eoc.add_data_point(h_max, e)
for resolution in resolutions:
h_max, errors = run_exterior_stokes(actx_factory,
ambient_dim=ambient_dim,
target_order=target_order,
qbx_order=qbx_order,
source_ovsmp=source_ovsmp,
resolution=resolution,
visualize=visualize)

for eoc, e in zip(eocs, errors):
eoc.add_data_point(h_max, e)

for eoc in eocs:
print(eoc.pretty_print(
abscissa_format="%.8e",
error_format="%.8e",
eoc_format="%.2f"))

for eoc in eocs:
# This convergence data is not as clean as it could be. See
# https://github.com/inducer/pytential/pull/32
# for some discussion.
Expand Down Expand Up @@ -416,30 +415,29 @@ def ref_result(self):

@pytest.mark.parametrize("cls", [
partial(eid.StarfishTestCase, resolutions=[16, 32, 64, 96, 128]),
partial(eid.SphereTestCase, resolutions=[0, 1, 2]),
partial(eid.SpheroidTestCase, resolutions=[0, 1, 2]),
])
def test_stokeslet_identity(actx_factory, cls, visualize=False):
if visualize:
logging.basicConfig(level=logging.INFO)

case = cls(fmm_backend=None, fmm_tol=None,
target_order=5, qbx_order=3, source_ovsmp=4)
source_ovsmp = 4 if cls.func.ambient_dim == 2 else 8
case = cls(fmm_backend=None,
target_order=5, qbx_order=3, source_ovsmp=source_ovsmp)
identity = StokesletIdentity(case.ambient_dim)
logger.info("\n%s", str(case))

from pytools.convergence import EOCRecorder
eocs = [EOCRecorder() for _ in range(case.ambient_dim)]

from pytential.symbolic.primitives import _expansion_radii_fudge_factor
with _expansion_radii_fudge_factor(1.0):
for resolution in case.resolutions:
h_max, errors = run_stokes_identity(
actx_factory, case, identity,
resolution=resolution,
visualize=visualize)
for resolution in case.resolutions:
h_max, errors = run_stokes_identity(
actx_factory, case, identity,
resolution=resolution,
visualize=visualize)

for eoc, e in zip(eocs, errors):
eoc.add_data_point(h_max, e)
for eoc, e in zip(eocs, errors):
eoc.add_data_point(h_max, e)

for eoc in eocs:
print(eoc.pretty_print(
Expand Down Expand Up @@ -476,30 +474,29 @@ def ref_result(self):

@pytest.mark.parametrize("cls", [
partial(eid.StarfishTestCase, resolutions=[16, 32, 64, 96, 128]),
partial(eid.SphereTestCase, resolutions=[0, 1, 2]),
partial(eid.SpheroidTestCase, resolutions=[0, 1, 2]),
])
def test_stresslet_identity(actx_factory, cls, visualize=False):
if visualize:
logging.basicConfig(level=logging.INFO)

source_ovsmp = 4 if cls.func.ambient_dim == 2 else 8
case = cls(fmm_backend=None,
target_order=5, qbx_order=3, source_ovsmp=4)
target_order=5, qbx_order=3, source_ovsmp=source_ovsmp)
identity = StressletIdentity(case.ambient_dim)
logger.info("\n%s", str(case))

from pytools.convergence import EOCRecorder
eocs = [EOCRecorder() for _ in range(case.ambient_dim)]

from pytential.symbolic.primitives import _expansion_radii_fudge_factor
with _expansion_radii_fudge_factor(1.0):
for resolution in case.resolutions:
h_max, errors = run_stokes_identity(
actx_factory, case, identity,
resolution=resolution,
visualize=visualize)
for resolution in case.resolutions:
h_max, errors = run_stokes_identity(
actx_factory, case, identity,
resolution=resolution,
visualize=visualize)

for eoc, e in zip(eocs, errors):
eoc.add_data_point(h_max, e)
for eoc, e in zip(eocs, errors):
eoc.add_data_point(h_max, e)

for eoc in eocs:
print(eoc.pretty_print(
Expand Down

0 comments on commit 6e04fb7

Please sign in to comment.