From 248922118c7bbbea77e5677de75efe588f258ea3 Mon Sep 17 00:00:00 2001 From: "Keaton J. Burns" Date: Tue, 11 May 2021 10:40:38 -0400 Subject: [PATCH] Add __call__-interpolation for operands --- dedalus/core/field.py | 19 +++++++++++++++++++ examples/bvp/2d_poisson/poisson.py | 4 ++-- .../ivp/2d_rayleigh_benard/rayleigh_benard.py | 14 +++++++------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/dedalus/core/field.py b/dedalus/core/field.py index 73e35da4..8e5dd9a6 100644 --- a/dedalus/core/field.py +++ b/dedalus/core/field.py @@ -96,6 +96,25 @@ def __rpow__(self, other): from .operators import Power return Power(other, self) + def __call__(self, *args, **kw): + """Create Interpolation operator with this operand.""" + return self.interp(*args, **kw) + + def diff(self, *args, **kw): + """Create Differentiation operator with this operand.""" + from .operators import differentiate + return differentiate(self, *args, **kw) + + def integ(self, *args, **kw): + """Create Integration operator with this operand.""" + from .operators import integrate + return integrate(self, *args, **kw) + + def interp(self, *args, **kw): + """Create Interpolation operator with this operand.""" + from .operators import interpolate + return interpolate(self, *args, **kw) + @staticmethod def parse(string, namespace, domain): """Build operand from a string expression.""" diff --git a/examples/bvp/2d_poisson/poisson.py b/examples/bvp/2d_poisson/poisson.py index d616ee89..a7131b9b 100644 --- a/examples/bvp/2d_poisson/poisson.py +++ b/examples/bvp/2d_poisson/poisson.py @@ -26,8 +26,8 @@ problem = de.LBVP(domain, variables=['u','uy']) problem.add_equation("dx(dx(u)) + dy(uy) = -10 * sin(x/2)**2 * (y - y**2)") problem.add_equation("uy - dy(u) = 0") -problem.add_bc("left(u) = left(sin(8*x))") -problem.add_bc("right(uy) = 0") +problem.add_bc("u(y='left') = sin(8*x)") +problem.add_bc("uy(y='right') = 0") # Build solver solver = problem.build_solver() diff --git a/examples/ivp/2d_rayleigh_benard/rayleigh_benard.py b/examples/ivp/2d_rayleigh_benard/rayleigh_benard.py index 2386f4b5..6c4ee97a 100644 --- a/examples/ivp/2d_rayleigh_benard/rayleigh_benard.py +++ b/examples/ivp/2d_rayleigh_benard/rayleigh_benard.py @@ -63,13 +63,13 @@ problem.add_equation("bz - dz(b) = 0") problem.add_equation("uz - dz(u) = 0") problem.add_equation("wz - dz(w) = 0") -problem.add_bc("left(b) = 0") -problem.add_bc("left(u) = 0") -problem.add_bc("left(w) = 0") -problem.add_bc("right(b) = 0") -problem.add_bc("right(u) = 0") -problem.add_bc("right(w) = 0", condition="(nx != 0)") -problem.add_bc("right(p) = 0", condition="(nx == 0)") +problem.add_bc("b(z='left') = 0") +problem.add_bc("u(z='left') = 0") +problem.add_bc("w(z='left') = 0") +problem.add_bc("b(z='right') = 0") +problem.add_bc("u(z='right') = 0") +problem.add_bc("w(z='right') = 0", condition="(nx != 0)") +problem.add_bc("integ(p) = 0", condition="(nx == 0)") # Build solver solver = problem.build_solver(de.timesteppers.RK222)