Skip to content

Commit 6a377c8

Browse files
committed
Make copies of direct-Field and duplicate tasks to avoid processing issues and transform noise in coeff outputs
1 parent 7925795 commit 6a377c8

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

dedalus/core/evaluator.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from .future import FutureField, FutureLockedField
1515
from .field import Field, LockedField
16+
from .operators import Copy
1617
from ..tools.cache import CachedAttribute
1718
from ..tools.general import OrderedSet
1819
from ..tools.general import oscillate
@@ -127,22 +128,19 @@ def evaluate_handlers(self, handlers, id=None, **kw):
127128
# Attempt evaluation
128129
tasks = self.attempt_tasks(tasks, id=id)
129130

130-
# # Transform all outputs to coefficient layout to dealias
131-
## D3 note: need to worry about this for redundent tasks?
132-
# outputs = OrderedSet([t['out'] for h in handlers for t in h.tasks])
133-
# self.require_coeff_space(outputs)
134-
135-
# # Copy redundant outputs so processing is independent
136-
# outputs = set()
137-
# for handler in handlers:
138-
# for task in handler.tasks:
139-
# if task['out'] in outputs:
140-
# task['out'] = task['out'].copy()
141-
# else:
142-
# outputs.add(task['out'])
131+
# Transform all outputs to coefficient layout to dealias
143132
outputs = OrderedSet([t['out'] for h in handlers for t in h.tasks if not isinstance(t['out'], LockedField)])
144133
self.require_coeff_space(outputs)
145134

135+
# Copy redundant outputs so processing is independent
136+
outputs = set()
137+
for handler in handlers:
138+
for task in handler.tasks:
139+
if task['out'] in outputs:
140+
task['out'] = task['out'].copy()
141+
else:
142+
outputs.add(task['out'])
143+
146144
# Process
147145
for handler in handlers:
148146
handler.process(**kw)
@@ -285,10 +283,9 @@ def add_task(self, task, layout='g', name=None, scales=None):
285283
# Create operator
286284
if isinstance(task, str):
287285
op = FutureField.parse(task, self.vars, self.dist)
286+
elif isinstance(task, Field):
287+
op = Copy(task)
288288
else:
289-
# op = FutureField.cast(task, self.domain)
290-
# op = Cast(task)
291-
# TODO: figure out if we need to copying here
292289
op = task
293290
# Check scales
294291
if isinstance(op, (LockedField, FutureLockedField)):

dedalus/core/operators.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from .domain import Domain
2121
from . import coords
22-
from .field import Operand, Field
22+
from .field import Operand, Field, LockedField
2323
from .future import Future, FutureField, FutureLockedField
2424
from ..tools.array import reshape_vector, apply_matrix, add_sparse, axindex, axslice, perm_matrix, copyto, sparse_block_diag, interleave_matrices
2525
from ..tools.cache import CachedAttribute, CachedMethod
@@ -1492,6 +1492,8 @@ class Copy(LinearOperator):
14921492

14931493
def __init__(self, operand, out=None):
14941494
super().__init__(operand, out=out)
1495+
if isinstance(operand, (LockedField, FutureLockedField)):
1496+
raise ValueError("Not yet implemented for locked fields.")
14951497
# LinearOperator requirements
14961498
self.operand = operand
14971499
# FutureField requirements

0 commit comments

Comments
 (0)