Skip to content

Commit

Permalink
Minor fixes for better scalar behavior
Browse files Browse the repository at this point in the history
hg hash: 016f609813fe95864d10f2a0ad38f6fca5b23c4f
  • Loading branch information
kburns committed Nov 2, 2019
1 parent 54e1964 commit 0f7514f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion dedalus/core/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,17 @@ def as_ncc_operator(self, frozen_arg_basis_meta, cutoff, max_terms, cacheid=None
if basis.separable:
if not self.meta[basis.name]['constant']:
raise ValueError("{} is non-constant along separable direction '{}'.".format(self, basis.name))
# Scatter transverse-constant coefficients
basis = domain.bases[-1]
coeffs = np.zeros(basis.coeff_size, dtype=basis.coeff_dtype)
# Scatter transverse-constant coefficients
self.require_coeff_space()
if domain.dist.rank == 0:
select = (0,) * (domain.dim - 1)
np.copyto(coeffs, self.data[select])
domain.dist.comm_cart.Bcast(coeffs, root=0)
# Revert to scalar behavior for constants
if self.meta[-1]['constant']:
return coeffs[0]
# Build matrix
ncc_basis_meta = self.meta[-1]
arg_basis_meta = dict(frozen_arg_basis_meta)
Expand Down
6 changes: 6 additions & 0 deletions dedalus/core/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,12 @@ class TimeDerivative(LinearOperator, FutureField):

name = 'dt'

def __new__(cls, arg0, **kw):
if not isinstance(arg0, Operand):
return 0
else:
return object.__new__(cls)

@property
def base(self):
return TimeDerivative
Expand Down
5 changes: 3 additions & 2 deletions dedalus/tests/test_ivp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ def test_heat_1d_periodic(benchmark, x_basis_class, Nx, timestepper, dtype):
x = domain.grid(0)
F['g'] = -np.sin(x)
# Problem
problem = de.IVP(domain, variables=['u'])
problem = de.IVP(domain, variables=['u','ux'])
problem.meta['u']['x']['parity'] = -1
problem.parameters['F'] = F
problem.add_equation("-dt(u) + dx(dx(u)) = F")
problem.add_equation("-dt(u) + dx(ux) = F")
problem.add_equation("ux - dx(u) = 0")
# Solver
solver = problem.build_solver(timestepper)
dt = 1e-5
Expand Down

0 comments on commit 0f7514f

Please sign in to comment.