Skip to content
Snippets Groups Projects
Commit 703816fe authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Allow adding arrays from fields, warn only if run fails

parent 19116526
Branches
Tags
No related merge requests found
......@@ -15,6 +15,7 @@ import numpy as np
import pystencils.datahandling
import pystencils.kernel_wrapper
import pystencils.timeloop
from pystencils.data_types import create_type
from pystencils.field import FieldType
......@@ -149,7 +150,11 @@ class GraphDataHandling(pystencils.datahandling.SerialDataHandling):
def run(self, time_steps=1):
former_call_queue = copy(self.parent.call_queue)
self.parent.call_queue = []
try:
super().run(time_steps)
except Exception as e:
import warnings
warnings.warn(e)
self.parent.call_queue = former_call_queue
former_call_queue.append(TimeloopRun(self, time_steps))
......@@ -181,6 +186,27 @@ class GraphDataHandling(pystencils.datahandling.SerialDataHandling):
if layout is None:
layout = self.default_layout
if gpu is None:
gpu = self.default_target in self._GPU_LIKE_TARGETS
# Weird code happening in super class
if not hasattr(values_per_cell, '__len__'):
values_per_cell = (values_per_cell, )
if len(values_per_cell) == 1 and values_per_cell[0] == 1:
values_per_cell = ()
if isinstance(name, pystencils.Field):
rtn = name
name = name.name
super().add_array(rtn.name,
rtn.values_per_cell(),
rtn.dtype.numpy_dtype,
rtn.latex_name,
1,
cpu=cpu,
gpu=gpu,
field_type=rtn.field_type)
else:
rtn = super().add_array(name,
values_per_cell,
dtype,
......@@ -191,13 +217,6 @@ class GraphDataHandling(pystencils.datahandling.SerialDataHandling):
gpu,
alignment,
field_type)
# Weird code happening in super class
if not hasattr(values_per_cell, '__len__'):
values_per_cell = (values_per_cell, )
if len(values_per_cell) == 1 and values_per_cell[0] == 1:
values_per_cell = ()
if shape:
rtn = self._fields[name] = pystencils.Field.create_fixed_size(name,
shape,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment