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

Make add_arrays return fields to arrays

parent 1b4ace3e
No related branches found
No related tags found
No related merge requests found
...@@ -68,20 +68,27 @@ class DataHandling(ABC): ...@@ -68,20 +68,27 @@ class DataHandling(ABC):
>>> from pystencils.datahandling import create_data_handling >>> from pystencils.datahandling import create_data_handling
>>> dh = create_data_handling((20, 30)) >>> dh = create_data_handling((20, 30))
>>> dh.add_arrays('x, y(9)') >>> x, y =dh.add_arrays('x, y(9)')
>>> print(dh.fields) >>> print(dh.fields)
{'x': x: double[20,30], 'y': y(9): double[20,30]} {'x': x: double[22,32], 'y': y(9): double[22,32]}
>>> assert dh.fields['x'].shape = (20, 30) >>> assert x == dh.fields['x']
>>> assert dh.fields['y'].index_shape = (9,) >>> assert dh.fields['x'].shape == (22, 32)
>>> assert dh.fields['y'].index_shape == (9,)
Args: Args:
description (str): String description of the fields to add description (str): String description of the fields to add
Returns:
Fields representing the just created arrays
""" """
from pystencils.field import _parse_part1 from pystencils.field import _parse_part1
names = []
for name, indices in _parse_part1(description): for name, indices in _parse_part1(description):
names.append(name)
self.add_array(name, values_per_cell=indices) self.add_array(name, values_per_cell=indices)
return (self.fields[n] for n in names)
@abstractmethod @abstractmethod
def has_data(self, name): def has_data(self, name):
"""Returns true if a field or custom data element with this name was added.""" """Returns true if a field or custom data element with this name was added."""
......
...@@ -233,9 +233,11 @@ def test_add_arrays(): ...@@ -233,9 +233,11 @@ def test_add_arrays():
field_description = 'x, y(9)' field_description = 'x, y(9)'
dh = create_data_handling(domain_size=domain_shape, default_ghost_layers=0, default_layout='numpy') dh = create_data_handling(domain_size=domain_shape, default_ghost_layers=0, default_layout='numpy')
dh.add_arrays(field_description) x_, y_ = dh.add_arrays(field_description)
x, y = ps.fields(field_description + ': [3,4,5]') x, y = ps.fields(field_description + ': [3,4,5]')
assert x_ == x
assert y_ == y
assert x == dh.fields['x'] assert x == dh.fields['x']
assert y == dh.fields['y'] assert y == dh.fields['y']
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment