Skip to content

Commit 199aa52

Browse files
committed
Clean up integration interface
1 parent f220b84 commit 199aa52

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

dedalus/core/operators.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,20 +1085,40 @@ def integrate(arg, spaces=None):
10851085
arg = Integrate(arg, space)
10861086
return arg
10871087

1088-
1088+
@alias("integ")
10891089
class Integrate(LinearOperator, metaclass=MultiClass):
10901090
"""
1091-
Integration along one dimension.
1091+
Definite integration over operand bases.
10921092
10931093
Parameters
10941094
----------
10951095
operand : number or Operand object
1096-
space : Space object
1097-
1096+
coords : Coordinate or CoordinateSystem object, or list of these
10981097
"""
10991098

11001099
name = "Integrate"
11011100

1101+
@classmethod
1102+
def _preprocess_args(cls, operand, coord=None):
1103+
# Handle zeros
1104+
if operand == 0:
1105+
raise SkipDispatchException(output=0)
1106+
# Integrate over all operand bases by default
1107+
if coord is None:
1108+
coord = [basis.coordsystem for basis in operand.domain.bases]
1109+
# Recurse over multiple coordinates
1110+
if isinstance(coord, (tuple, list)):
1111+
if len(coord) > 1:
1112+
operand = Integrate(operand, coord[:-1])
1113+
coord = coord[-1]
1114+
# Resolve strings to coordinates
1115+
if isinstance(coord, str):
1116+
coord = operand.domain.get_coord(coord)
1117+
# Check coordinate type
1118+
if not isinstance(coord, (coords.Coordinate, coords.CoordinateSystem)):
1119+
raise ValueError("coords must be Coordinate or str")
1120+
return (operand, coord), {}
1121+
11021122
@classmethod
11031123
def _check_args(cls, operand, coords):
11041124
# Dispatch by operand basis
@@ -1109,18 +1129,6 @@ def _check_args(cls, operand, coords):
11091129
return True
11101130
return False
11111131

1112-
@classmethod
1113-
def _preprocess_args(cls, operand, coord):
1114-
if isinstance(operand, Number):
1115-
raise SkipDispatchException(output=operand)
1116-
if isinstance(coord, (coords.Coordinate, coords.CoordinateSystem)):
1117-
pass
1118-
elif isinstance(coord, str):
1119-
coord = operand.domain.get_coord(coord)
1120-
else:
1121-
raise ValueError("coord must be Coordinate or str")
1122-
return (operand, coord), {}
1123-
11241132
def __init__(self, operand, coord):
11251133
SpectralOperator.__init__(self, operand)
11261134
# Require integrand is a scalar

examples/ivp_2d_rayleigh_benard/rayleigh_benard.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import logging
2929
logger = logging.getLogger(__name__)
3030

31-
# TODO: cleanup integ shortcuts
32-
3331

3432
# Parameters
3533
Lx, Lz = 4, 1
@@ -63,7 +61,6 @@
6361
nu = (Rayleigh / Prandtl)**(-1/2)
6462
x, z = dist.local_grids(xbasis, zbasis)
6563
ex, ez = coords.unit_vector_fields(dist)
66-
integ = lambda A: d3.Integrate(d3.Integrate(A, 'x'), 'z')
6764
lift_basis = zbasis.clone_with(a=1/2, b=1/2) # First derivative basis
6865
lift = lambda A: d3.Lift(A, lift_basis, -1)
6966
grad_u = d3.grad(u) + ez*lift(tau_u1) # First-order reduction

examples/ivp_2d_shear_flow/shear_flow.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import logging
2525
logger = logging.getLogger(__name__)
2626

27-
# TODO: cleanup integ shortcuts
28-
2927

3028
# Parameters
3129
Lx, Lz = 1, 2
@@ -55,7 +53,6 @@
5553
D = nu / Schmidt
5654
x, z = dist.local_grids(xbasis, zbasis)
5755
ex, ez = coords.unit_vector_fields(dist)
58-
integ = lambda A: d3.Integrate(d3.Integrate(A, 'x'), 'z')
5956

6057
# Problem
6158
problem = d3.IVP([u, s, p, tau_p], namespace=locals())

examples/ivp_ball_internally_heated_convection/internally_heated_convection.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@
7575
lift = lambda A: d3.Lift(A, basis, -1)
7676
strain_rate = d3.grad(u) + d3.trans(d3.grad(u))
7777
shear_stress = d3.angular(d3.radial(strain_rate(r=1), index=1))
78-
integ = lambda A: d3.Integrate(A, coords)
79-
rad = d3.RadialComponent
8078

8179
# Problem
8280
problem = d3.IVP([p, u, T, tau_p, tau_u, tau_T], namespace=locals())
@@ -85,7 +83,7 @@
8583
problem.add_equation("dt(T) - kappa*lap(T) + lift(tau_T) = - dot(u,grad(T)) + kappa*T_source")
8684
problem.add_equation("shear_stress = 0") # Stress free
8785
problem.add_equation("radial(u(r=1)) = 0") # No penetration
88-
problem.add_equation("rad(grad(T)(r=1)) = -2")
86+
problem.add_equation("radial(grad(T)(r=1)) = -2")
8987
problem.add_equation("integ(p) = 0") # Pressure gauge
9088

9189
# Solver

examples/ivp_disk_libration/libration.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
# Substitutions
5454
phi, r = dist.local_grids(basis)
5555
nu = Ekman
56-
integ = lambda A: d3.Integrate(A, coords)
5756
lift = lambda A: d3.Lift(A, basis, -1)
5857

5958
# Background librating flow
@@ -83,7 +82,7 @@
8382
snapshots = solver.evaluator.add_file_handler('snapshots', sim_dt=0.1, max_writes=20)
8483
snapshots.add_task(-d3.div(d3.skew(u)), scales=(4, 1), name='vorticity')
8584
scalars = solver.evaluator.add_file_handler('scalars', sim_dt=0.01)
86-
scalars.add_task(integ(0.5*d3.dot(u,u)), name='KE')
85+
scalars.add_task(d3.integ(0.5*d3.dot(u,u)), name='KE')
8786

8887
# Flow properties
8988
flow = d3.GlobalFlowProperty(solver, cadence=100)

examples/ivp_shell_convection/shell_convection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
lift = lambda A: d3.Lift(A, lift_basis, -1)
7070
grad_u = d3.grad(u) + rvec*lift(tau_u1) # First-order reduction
7171
grad_b = d3.grad(b) + rvec*lift(tau_b1) # First-order reduction
72-
integ = lambda A: d3.Integrate(A, coords)
7372

7473
# Problem
7574
problem = d3.IVP([p, b, u, tau_p, tau_b1, tau_b2, tau_u1, tau_u2], namespace=locals())

0 commit comments

Comments
 (0)