Ejemplo n.º 1
0
def test_material_lookup_slice_match_2():
    """Material is only partially specified, but sufficiently to match."""
    material = steel.SteelMaterial.from_name('A992')
    assert unyt.allclose_units(material.E, 29000 * unyt.ksi)
    assert unyt.allclose_units(material.Fy, 50 * unyt.ksi)
    assert unyt.allclose_units(material.Fu, 65 * unyt.ksi)
    assert unyt.allclose_units(material.Ry, 1.1)
    assert unyt.allclose_units(material.Rt, 1.1)
Ejemplo n.º 2
0
def test_material_lookup_exact_match():
    """Material is specified exactly."""
    material = steel.SteelMaterial.from_name('A500',
                                             grade='C',
                                             application='HSS')
    assert unyt.allclose_units(material.E, 29000 * unyt.ksi)
    assert unyt.allclose_units(material.Fy, 50 * unyt.ksi)
    assert unyt.allclose_units(material.Fu, 62 * unyt.ksi)
    assert unyt.allclose_units(material.Ry, 1.3)
    assert unyt.allclose_units(material.Rt, 1.2)
Ejemplo n.º 3
0
    def test_dict_to_unyt_nested(self):
        unyt_dict = {
            "level1": {
                "my_quantity": {"array": [7.0, 2.5, 6.3], "unit": "K"},
                "level2": {
                    "my_quantity": {"array": [-10, 2.5, 100], "unit": "C"},
                },
            }
        }
        dict_to_unyt(unyt_dict)

        assert u.allclose_units(
            unyt_dict["level1"]["my_quantity"],
            u.unyt_array([7.0, 2.5, 6.3], u.K),
        )
        assert u.allclose_units(
            unyt_dict["level1"]["level2"]["my_quantity"],
            u.unyt_array([-10, 2.5, 100], u.C),
        )
Ejemplo n.º 4
0
 def test_atom_equality(atom1, atom2):
     if not all(isinstance(x, Atom) for x in [atom1, atom2]):
         return False
     if atom1 is atom2:
         return True
     equal = (lambda x1, x2: u.allclose_units(x1, x2)
              if isinstance(x1, u.unyt_array) and isinstance(
                  x2, u.unyt_array) else x1 == x2)
     for prop in atom1.dict(by_alias=True):
         if not equal(atom2.dict().get(prop), atom1.dict().get(prop)):
             return False
     return True
Ejemplo n.º 5
0
    def __eq__(self, other):
        """Overrides the default implementation"""
        if not isinstance(other, type(self)):
            return False

        self_vars = flatten_dict(todict(self))
        other_vars = flatten_dict(todict(other))
        common_vars = self_vars.keys() & other_vars.keys()

        # instances are not equal if any of the common attributes have different values
        for key in common_vars:
            self_val = self_vars[key]
            other_val = other_vars[key]

            if not allclose_units(self_val, other_val, 1e-5):
                warnings.warn(
                    f"Difference in {key}: {self_val} vs {other_val}",
                    RuntimeWarning)
                return False

        return True
Ejemplo n.º 6
0
def allclose_units_mixed(u_iter1, u_iter2):
    """Check if array of quantities with mixed dimensions are equivalent.

    Notes
    -----
    The two iterables provided must contain same number of quantities and
    should be able to passed to Python zip function.

    Parameters
    ----------
    u_iter1: list or iterable of u.unit_quantity
        The first iterable/list of unit quantities
    u_iter2: list or iterable of u.unit_quantity
        The second iterable/list of unit quantities

    Returns
    -------
    bool
        True if iter1 is equivalent to iter2
    """
    for q1, q2 in zip(u_iter1, u_iter2):
        if not u.allclose_units(q1, q2):
            return False
    return True
Ejemplo n.º 7
0
def test_rf_power():
    assert allclose_units(rf_power(223.6 * mV), -0.00026405907247372323 * dBm)
    assert allclose_units(rf_power(1, condition="pk"), 10 * dBm)
    assert allclose_units(rf_power(2, condition="pk-pk"), 10 * dBm)
Ejemplo n.º 8
0
 def test_dict_to_unyt_shallow(self):
     unyt_dict = {"my_quantity": {"array": [7.0, 2.5, 6.3], "unit": "K"}}
     dict_to_unyt(unyt_dict)
     assert u.allclose_units(
         unyt_dict["my_quantity"], u.unyt_array([7.0, 2.5, 6.3], u.K)
     )