Esempio n. 1
0
def test_grid_field_zeros_ones_empty():
    """Test creating scalar fields with zeros, empty, and ones."""
    fields = ModelDataFields()
    fields.new_field_location('grid', 1)    
    assert_raises(ValueError, fields.zeros, 'grid')
    assert_raises(ValueError, fields.empty, 'grid')
    assert_raises(ValueError, fields.ones, 'grid')
Esempio n. 2
0
def test_getitem():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert_dict_equal(dict(), fields['node'])
    assert_raises(GroupError, lambda k: fields[k], 'cell')
    assert_raises(KeyError, lambda k: fields[k], 'cell')
Esempio n. 3
0
def test_getitem():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert_dict_equal(dict(), fields['node'])
    assert_raises(GroupError, lambda k: fields[k], 'cell')
    assert_raises(KeyError, lambda k: fields[k], 'cell')
Esempio n. 4
0
def test_grid_field_zeros_ones_empty():
    """Test creating scalar fields with zeros, empty, and ones."""
    fields = ModelDataFields()
    fields.new_field_location('grid', 1)
    assert_raises(ValueError, fields.zeros, 'grid')
    assert_raises(ValueError, fields.empty, 'grid')
    assert_raises(ValueError, fields.ones, 'grid')
Esempio n. 5
0
def test_grid_field_add_zeros_ones_empty():
    """Test creating scalar fields with add_zeros, add_empty, and add_ones."""
    fields = ModelDataFields()
    fields.new_field_location('grid', 1)

    assert_raises(ValueError, fields.add_zeros, 'value', at='grid')
    assert_raises(ValueError, fields.add_empty, 'value', at='grid')
    assert_raises(ValueError, fields.add_ones, 'value', at='grid')
Esempio n. 6
0
def test_grid_field_add_zeros_ones_empty():
    """Test creating scalar fields with add_zeros, add_empty, and add_ones."""
    fields = ModelDataFields()
    fields.new_field_location('grid', 1)
    
    assert_raises(ValueError, fields.add_zeros, 'value', at='grid')
    assert_raises(ValueError, fields.add_empty, 'value', at='grid')
    assert_raises(ValueError, fields.add_ones, 'value', at='grid')
Esempio n. 7
0
def test_add_existing_field_default():
    """Test default is to not replace existing field."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.add_empty('z', at='node')

    assert_raises(FieldError, fields.add_empty, 'z', at='node')
    assert_raises(FieldError, fields.add_ones, 'z', at='node')
    assert_raises(FieldError, fields.add_zeros, 'z', at='node')
Esempio n. 8
0
def test_add_existing_field_with_noclobber():
    """Test noclobber raises an error with an existing field."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.add_empty('z', at='node')

    assert_raises(FieldError, fields.add_empty, 'z', at='node', noclobber=True)
    assert_raises(FieldError, fields.add_ones, 'z', at='node', noclobber=True)
    assert_raises(FieldError, fields.add_zeros, 'z', at='node', noclobber=True)
Esempio n. 9
0
def test_add_existing_field_default():
    """Test default is to not replace existing field."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.add_empty('z', at='node')

    assert_raises(FieldError, fields.add_empty, 'z', at='node')
    assert_raises(FieldError, fields.add_ones, 'z', at='node')
    assert_raises(FieldError, fields.add_zeros, 'z', at='node')
Esempio n. 10
0
def test_getitem():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    assert dict() == fields["node"]
    with pytest.raises(GroupError):
        fields["cell"]
    with pytest.raises(KeyError):
        fields["cell"]
Esempio n. 11
0
def test_add_existing_field_with_noclobber():
    """Test noclobber raises an error with an existing field."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.add_empty('z', at='node')

    assert_raises(FieldError, fields.add_empty, 'z', at='node', noclobber=True)
    assert_raises(FieldError, fields.add_ones, 'z', at='node', noclobber=True)
    assert_raises(FieldError, fields.add_zeros, 'z', at='node', noclobber=True)
Esempio n. 12
0
def test_at_attribute():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert_dict_equal(dict(), fields.at_node)
    assert_raises(AttributeError, lambda: fields.at_cell)

    fields.add_ones('z', at='node')
    assert_array_equal(np.ones(12), fields.at_node['z'])
Esempio n. 13
0
def test_at_attribute():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert_dict_equal(dict(), fields.at_node)
    assert_raises(AttributeError, lambda: fields.at_cell)

    fields.add_ones('z', at='node')
    assert_array_equal(np.ones(12), fields.at_node['z'])
Esempio n. 14
0
def test_getitem():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert dict() == fields['node']
    with pytest.raises(GroupError):
        fields['cell']
    with pytest.raises(KeyError):
        fields['cell']
Esempio n. 15
0
def test_getitem():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    assert dict() == fields["node"]
    with pytest.raises(GroupError):
        fields["cell"]
    with pytest.raises(KeyError):
        fields["cell"]
Esempio n. 16
0
def test_getitem():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert dict() == fields['node']
    with pytest.raises(GroupError):
        fields['cell']
    with pytest.raises(KeyError):
        fields['cell']
Esempio n. 17
0
def test_at_attribute():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    assert dict() == fields.at_node
    with pytest.raises(AttributeError):
        fields.at_cell

    fields.add_ones("z", at="node")
    assert_array_equal(np.ones(12), fields.at_node["z"])
Esempio n. 18
0
def test_at_attribute():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert dict() == fields.at_node
    with pytest.raises(AttributeError):
        fields.at_cell

    fields.add_ones('z', at='node')
    assert_array_equal(np.ones(12), fields.at_node['z'])
Esempio n. 19
0
def test_at_attribute():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert dict() == fields.at_node
    with pytest.raises(AttributeError):
        fields.at_cell

    fields.add_ones('z', at='node')
    assert_array_equal(np.ones(12), fields.at_node['z'])
Esempio n. 20
0
def test_at_attribute():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    assert dict() == fields.at_node
    with pytest.raises(AttributeError):
        fields.at_cell

    fields.add_ones("z", at="node")
    assert_array_equal(np.ones(12), fields.at_node["z"])
Esempio n. 21
0
def test_nd_field():
    """Test creating fields that are nd in shape."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    fields.add_field('new_value', np.ones((12,4,5)), at='node')
    fields.add_field('newer_value', np.ones((12,4)), at='node')

    assert_raises(ValueError, fields.add_field, 'newest_value', np.ones((13,4,5)), at='node')
    assert_raises(ValueError, fields.add_field, 'newestest_value', np.ones((13)), at='node')
Esempio n. 22
0
def test_add_field_with_clobber():
    """Test adding a field with clobber on."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert fields.add_empty('a', at='node') is not fields.add_empty('a', at='node', noclobber=False)
    assert fields.add_ones('b', at='node') is not fields.add_ones('b', at='node', noclobber=False)
    assert fields.add_zeros('c', at='node') is not fields.add_zeros('c', at='node', noclobber=False)
Esempio n. 23
0
def test_grid_field_zeros_ones_empty():
    """Test creating scalar fields with zeros, empty, and ones."""
    fields = ModelDataFields()
    fields.new_field_location("grid", 1)
    with pytest.raises(ValueError):
        fields.zeros("grid")
    with pytest.raises(ValueError):
        fields.empty("grid")
    with pytest.raises(ValueError):
        fields.ones("grid")
Esempio n. 24
0
def test_grid_field_zeros_ones_empty():
    """Test creating scalar fields with zeros, empty, and ones."""
    fields = ModelDataFields()
    fields.new_field_location("grid", 1)
    with pytest.raises(ValueError):
        fields.zeros("grid")
    with pytest.raises(ValueError):
        fields.empty("grid")
    with pytest.raises(ValueError):
        fields.ones("grid")
Esempio n. 25
0
def test_scalar_field():
    """Test adding a generic scalar field."""
    fields = ModelDataFields()
    fields.new_field_location('all_over_the_place', 1)

    assert_dict_equal(dict(), fields.at_all_over_the_place)
    assert_raises(AttributeError, lambda: fields.at_cell)

    fields.at_all_over_the_place['const'] = 1.
    assert_array_equal(np.array(1.), fields.at_all_over_the_place['const'])
    
    val = np.array(2.)
    fields.at_all_over_the_place['const'] = val
    assert_is(val, fields.at_all_over_the_place['const'])
Esempio n. 26
0
def test_scalar_field():
    """Test adding a generic scalar field."""
    fields = ModelDataFields()
    fields.new_field_location('all_over_the_place', 1)

    assert_dict_equal(dict(), fields.at_all_over_the_place)
    assert_raises(AttributeError, lambda: fields.at_cell)

    fields.at_all_over_the_place['const'] = 1.
    assert_array_equal(np.array(1.), fields.at_all_over_the_place['const'])

    val = np.array(2.)
    fields.at_all_over_the_place['const'] = val
    assert_is(val, fields.at_all_over_the_place['const'])
Esempio n. 27
0
def test_add_field_with_clobber():
    """Test adding a field with clobber on."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert_is_not(fields.add_empty('a', at='node'),
                  fields.add_empty('a', at='node', noclobber=False))
    assert_is_not(fields.add_ones('b', at='node'),
                  fields.add_ones('b', at='node', noclobber=False))
    assert_is_not(fields.add_zeros('c', at='node'),
                  fields.add_zeros('c', at='node', noclobber=False))
Esempio n. 28
0
def test_scalar_field():
    """Test adding a generic scalar field."""
    fields = ModelDataFields()
    fields.new_field_location("all_over_the_place", 1)

    assert dict() == fields.at_all_over_the_place
    with pytest.raises(AttributeError):
        fields.at_cell

    fields.at_all_over_the_place["const"] = 1.
    assert_array_equal(np.array(1.), fields.at_all_over_the_place["const"])

    val = np.array(2.)
    fields.at_all_over_the_place["const"] = val
    assert val is fields.at_all_over_the_place["const"]
Esempio n. 29
0
def test_scalar_field():
    """Test adding a generic scalar field."""
    fields = ModelDataFields()
    fields.new_field_location("all_over_the_place", 1)

    assert dict() == fields.at_all_over_the_place
    with pytest.raises(AttributeError):
        fields.at_cell

    fields.at_all_over_the_place["const"] = 1.0
    assert_array_equal(np.array(1.0), fields.at_all_over_the_place["const"])

    val = np.array(2.0)
    fields.at_all_over_the_place["const"] = val
    assert val is fields.at_all_over_the_place["const"]
Esempio n. 30
0
def test_add_field_with_noclobber():
    """Test noclobber does not raise an error with an new field."""
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    fields.add_empty("a", at="node", noclobber=True)
    assert "a" in fields["node"]

    fields.add_ones("b", at="node", noclobber=True)
    assert "b" in fields["node"]

    fields.add_zeros("c", at="node", noclobber=True)
    assert "c" in fields["node"]
Esempio n. 31
0
def test_add_field_with_noclobber():
    """Test noclobber does not raise an error with an new field."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    fields.add_empty('a', at='node', noclobber=True)
    assert 'a' in fields['node']

    fields.add_ones('b', at='node', noclobber=True)
    assert 'b' in fields['node']

    fields.add_zeros('c', at='node', noclobber=True)
    assert 'c' in fields['node']
Esempio n. 32
0
def test_add_field_with_noclobber():
    """Test noclobber does not raise an error with an new field."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    fields.add_empty('a', at='node', noclobber=True)
    assert_true('a' in fields['node'])

    fields.add_ones('b', at='node', noclobber=True)
    assert_true('b' in fields['node'])

    fields.add_zeros('c', at='node', noclobber=True)
    assert_true('c' in fields['node'])
Esempio n. 33
0
def test_add_field_with_clobber_off():
    """Test clobber does not raise an error with an new field."""
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    fields.add_empty("a", at="node", clobber=False)
    assert "a" in fields["node"]

    fields.add_ones("b", at="node", clobber=False)
    assert "b" in fields["node"]

    fields.add_zeros("c", at="node", clobber=False)
    assert "c" in fields["node"]
Esempio n. 34
0
def test_add_ones_return_value():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.new_field_location('cell', 2)

    rtn_value = fields.add_ones('z', at='node')
    assert_array_equal(rtn_value, np.ones(12))
    assert rtn_value is fields['node']['z']
    assert rtn_value is fields.field_values('node', 'z')

    rtn_value = fields.add_ones('z', at='cell')
    assert_array_equal(rtn_value, np.ones(2))
    assert rtn_value is fields['cell']['z']
    assert rtn_value is fields.field_values('cell', 'z')
Esempio n. 35
0
def test_delete_field():
    fields = ModelDataFields()
    fields.new_field_location('link', 17)

    assert_dict_equal(dict(), fields.at_link)
    assert_raises(AttributeError, lambda: fields.at_node)

    fields.add_zeros('link', 'vals')
    assert_array_equal(np.zeros(17), fields.at_link['vals'])

    assert_raises(KeyError, lambda: fields.delete_field('node', 'vals'))
    fields.delete_field('link', 'vals')
    assert_raises(KeyError, lambda: fields.field_units('link', 'vals'))
    assert_raises(KeyError, lambda: fields.at_link['vals'])
Esempio n. 36
0
def test_add_multiple_groups():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.new_field_location('cell', 2)
    fields.new_field_location('face', 7)
    fields.new_field_location('link', 7)
    assert set(['node', 'cell', 'face', 'link']) == fields.groups
Esempio n. 37
0
def test_add_ones_return_value():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.new_field_location('cell', 2)

    rtn_value = fields.add_ones('z', at='node')
    assert_array_equal(rtn_value, np.ones(12))
    assert_is(rtn_value, fields['node']['z'])
    assert_is(rtn_value, fields.field_values('node', 'z'))

    rtn_value = fields.add_ones('z', at='cell')
    assert_array_equal(rtn_value, np.ones(2))
    assert_is(rtn_value, fields['cell']['z'])
    assert_is(rtn_value, fields.field_values('cell', 'z'))
Esempio n. 38
0
def test_add_multiple_groups():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.new_field_location('cell', 2)
    fields.new_field_location('face', 7)
    fields.new_field_location('link', 7)
    assert_set_equal(set(['node', 'cell', 'face', 'link']), fields.groups)
Esempio n. 39
0
def test_add_field_with_clobber():
    """Test adding a field with clobber on."""
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    assert fields.add_empty("a", at="node") is not fields.add_empty(
        "a", at="node", noclobber=False
    )
    assert fields.add_ones("b", at="node") is not fields.add_ones(
        "b", at="node", noclobber=False
    )
    assert fields.add_zeros("c", at="node") is not fields.add_zeros(
        "c", at="node", noclobber=False
    )
Esempio n. 40
0
def test_delete_field():
    fields = ModelDataFields()
    fields.new_field_location('link', 17)

    assert_dict_equal(dict(), fields.at_link)
    assert_raises(AttributeError, lambda: fields.at_node)

    fields.add_zeros('link', 'vals')
    assert_array_equal(np.zeros(17), fields.at_link['vals'])

    assert_raises(KeyError, lambda: fields.delete_field('node', 'vals'))
    fields.delete_field('link', 'vals')
    assert_raises(KeyError, lambda: fields.field_units('link', 'vals'))
    assert_raises(KeyError, lambda: fields.at_link['vals'])
Esempio n. 41
0
def test_add_multiple_groups():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.new_field_location("cell", 2)
    fields.new_field_location("face", 7)
    fields.new_field_location("link", 7)
    assert set(["node", "cell", "face", "link"]) == fields.groups
Esempio n. 42
0
def test_add_multiple_groups():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.new_field_location("cell", 2)
    fields.new_field_location("face", 7)
    fields.new_field_location("link", 7)
    assert set(["node", "cell", "face", "link"]) == fields.groups
Esempio n. 43
0
def test_add_ones_return_value():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.new_field_location("cell", 2)

    rtn_value = fields.add_ones("z", at="node")
    assert_array_equal(rtn_value, np.ones(12))
    assert rtn_value is fields["node"]["z"]
    assert rtn_value is fields.field_values("node", "z")

    rtn_value = fields.add_ones("z", at="cell")
    assert_array_equal(rtn_value, np.ones(2))
    assert rtn_value is fields["cell"]["z"]
    assert rtn_value is fields.field_values("cell", "z")
Esempio n. 44
0
def test_add_ones_return_value():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.new_field_location("cell", 2)

    rtn_value = fields.add_ones("z", at="node")
    assert_array_equal(rtn_value, np.ones(12))
    assert rtn_value is fields["node"]["z"]
    assert rtn_value is fields.field_values("node", "z")

    rtn_value = fields.add_ones("z", at="cell")
    assert_array_equal(rtn_value, np.ones(2))
    assert rtn_value is fields["cell"]["z"]
    assert rtn_value is fields.field_values("cell", "z")
Esempio n. 45
0
def test_setting_units(name, unit_str):
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.add_field(name, np.empty(12), at="node", units=unit_str[::-1])
    assert fields.field_units("node", name) == unit_str[::-1]

    fields["node"].set_units(name, unit_str)
    assert fields.field_units("node", name) == unit_str
Esempio n. 46
0
def test_add_field_with_clobber():
    """Test adding a field with clobber on."""
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    assert fields.add_empty("a",
                            at="node") is not fields.add_empty("a",
                                                               at="node",
                                                               clobber=True)
    assert fields.add_ones("b", at="node") is not fields.add_ones("b",
                                                                  at="node",
                                                                  clobber=True)
    assert fields.add_zeros("c",
                            at="node") is not fields.add_zeros("c",
                                                               at="node",
                                                               clobber=True)
Esempio n. 47
0
def test_ones():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.new_field_location('cell', 2)

    value_array = fields.ones('node')
    assert_array_equal(np.ones(12), value_array)

    value_array = fields.ones('cell')
    assert_array_equal(np.ones(2), value_array)
Esempio n. 48
0
def test_ones():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.new_field_location("cell", 2)

    value_array = fields.ones("node")
    assert_array_equal(np.ones(12), value_array)

    value_array = fields.ones("cell")
    assert_array_equal(np.ones(2), value_array)
Esempio n. 49
0
def test_ones():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.new_field_location('cell', 2)

    value_array = fields.ones('node')
    assert_array_equal(np.ones(12), value_array)

    value_array = fields.ones('cell')
    assert_array_equal(np.ones(2), value_array)
Esempio n. 50
0
def test_ones():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.new_field_location("cell", 2)

    value_array = fields.ones("node")
    assert_array_equal(np.ones(12), value_array)

    value_array = fields.ones("cell")
    assert_array_equal(np.ones(2), value_array)
Esempio n. 51
0
def test_nd_field():
    """Test creating fields that are nd in shape."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    fields.add_field('new_value', np.ones((12, 4, 5)), at='node')
    fields.add_field('newer_value', np.ones((12, 4)), at='node')

    assert_raises(ValueError,
                  fields.add_field,
                  'newest_value',
                  np.ones((13, 4, 5)),
                  at='node')
    assert_raises(ValueError,
                  fields.add_field,
                  'newestest_value',
                  np.ones((13)),
                  at='node')
Esempio n. 52
0
def test_grid_field_as_array():
    """Test adding an array as a grid field."""
    fields = ModelDataFields()
    fields.new_field_location('grid', 1)

    fields.at_grid['const'] = [1., 2.]
    assert_array_equal(np.array([1., 2.]), fields.at_grid['const'])

    val = np.array([1., 2.])
    fields.at_grid['const'] = val
    assert_is(val, fields.at_grid['const'])

    val.shape = (1, 1, 2, 1)
    fields.at_grid['const'] = val
    assert_array_equal(np.array([1., 2.]), fields.at_grid['const'])
    assert_is(val, fields.at_grid['const'])
Esempio n. 53
0
def test_grid_field_as_array():
    """Test adding an array as a grid field."""
    fields = ModelDataFields()
    fields.new_field_location("grid", 1)

    fields.at_grid["const"] = [1., 2.]
    assert_array_equal(np.array([1., 2.]), fields.at_grid["const"])

    val = np.array([1., 2.])
    fields.at_grid["const"] = val
    assert val is fields.at_grid["const"]

    val.shape = (1, 1, 2, 1)
    fields.at_grid["const"] = val
    assert_array_equal(np.array([1., 2.]), fields.at_grid["const"])
    assert val is fields.at_grid["const"]
Esempio n. 54
0
def test_grid_field_as_array():
    """Test adding an array as a grid field."""
    fields = ModelDataFields()
    fields.new_field_location("grid", 1)

    fields.at_grid["const"] = [1.0, 2.0]
    assert_array_equal(fields.at_grid["const"], [[1.0, 2.0]])

    val = np.array([1.0, 2.0])
    fields.at_grid["const"] = val
    assert np.shares_memory(val, fields.at_grid["const"])

    val.shape = (1, 1, 2, 1)
    fields.at_grid["const"] = val
    assert_array_equal(fields.at_grid["const"], np.array([[1.0, 2.0]]))
    assert np.shares_memory(val, fields.at_grid["const"])
Esempio n. 55
0
def test_grid_field_as_array():
    """Test adding an array as a grid field."""
    fields = ModelDataFields()
    fields.new_field_location('grid', 1)

    fields.at_grid['const'] = [1., 2.]
    assert_array_equal(np.array([1., 2.]), fields.at_grid['const'])

    val = np.array([1., 2.])
    fields.at_grid['const'] = val
    assert val is fields.at_grid['const']

    val.shape = (1, 1, 2, 1)
    fields.at_grid['const'] = val
    assert_array_equal(np.array([1., 2.]), fields.at_grid['const'])
    assert val is fields.at_grid['const']
Esempio n. 56
0
def test_add_existing_field_with_clobber_off():
    """Test clobber raises an error with an existing field."""
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.add_empty("z", at="node")

    with pytest.raises(FieldError):
        fields.add_empty("z", at="node", clobber=False)
    with pytest.raises(FieldError):
        fields.add_ones("z", at="node", clobber=False)
    with pytest.raises(FieldError):
        fields.add_zeros("z", at="node", clobber=False)
Esempio n. 57
0
def test_add_existing_field_default():
    """Test default is to not replace existing field."""
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.add_empty("z", at="node")

    with pytest.raises(FieldError):
        fields.add_empty("z", at="node")
    with pytest.raises(FieldError):
        fields.add_ones("z", at="node")
    with pytest.raises(FieldError):
        fields.add_zeros("z", at="node")
Esempio n. 58
0
def test_new_field_location():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    assert_set_equal(set(['node']), fields.groups)
Esempio n. 59
0
def test_add_existing_group():
    fields = ModelDataFields()
    fields.new_field_location('node', size=12)
    assert_raises(ValueError, fields.new_field_location, 'node', size=24)
Esempio n. 60
0
def test_add_ones():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.new_field_location('cell', 2)

    fields.add_ones('z', at='node')
    assert_array_equal(np.ones(12), fields['node']['z'])
    assert_array_equal(np.ones(12), fields.field_values('node', 'z'))

    fields.add_ones('z', at='cell')
    assert_array_equal(np.ones(2), fields['cell']['z'])
    assert_array_equal(np.ones(2), fields.field_values('cell', 'z'))