Exemplo n.º 1
0
def test_get_location_scoping():
    scop = Scoping()
    scop._set_location("Nodal")
    assert scop._get_location() == "Nodal"
    scop = Scoping()
    scop._set_location(dpf.core.locations.nodal)
    assert scop._get_location() == "Nodal"
Exemplo n.º 2
0
def test_auto_delete_scoping_local():
    scop = Scoping()
    s = scop.as_local_scoping()
    s.append(1)
    del s
    with scop.as_local_scoping() as s:
        assert s[0] == 1
Exemplo n.º 3
0
def elshape_body_sc():
    """Returns a scopings continer with 20 scoping split on body and elshape"""
    sc = ScopingsContainer()
    sc.labels = ["elshape", "body"]
    for i in range(0, 20):
        mscop = {"elshape": i + 1, "body": 0}
        scop = Scoping()
        scop.ids = range(0, i + 1)
        sc.add_scoping(mscop, scop)
    return sc
Exemplo n.º 4
0
def test_throw_if_unsufficient_version():
    scop = Scoping()
    ids = range(1, int(2e6))
    with pytest.raises(dpf_errors.DpfVersionNotSupported):
        scop.ids = ids
    ids = range(1, int(3e6))
    with pytest.raises(dpf_errors.DpfVersionNotSupported):
        scop.ids = ids
    ids = range(1, 2000)
    scop.ids = ids
    ids_check = scop.ids
    assert np.allclose(ids, ids_check)
Exemplo n.º 5
0
def scoping_by_load_steps(load_steps, server=None):
    """Create a specific :class:`ansys.dpf.core.Scoping` for a given list of load steps.

    The returned scoping describes a specific time frequency support element
    for a given list of load steps.

    Parameters
    ----------
    load_steps : list[int]
        List of load steps IDs of the specific time frequency scoping.
    server : DpfServer, optional
        Server with the channel connected to the remote or local instance.
        The default is ``None``, in which case an attempt is made to use the
        global server.

    Returns
    -------
    scoping : Scoping
        Scoping targeting several load_steps.
    """
    if not isinstance(load_steps, list):
        raise dpf_errors.InvalidTypeError("list", "load_steps")
    scoping = Scoping(server=server,
                      ids=load_steps,
                      location=locations.time_freq_step)
    return scoping
Exemplo n.º 6
0
def scoping_by_sets(cumulative_sets, server=None):
    """Create a specific :class:`ansys.dpf.core.Scoping` for a given list of cumulative set indices.

    The returned scoping describes a specific time frequency support element for a given
    list of cumulative sets of indices.

    Parameters
    ----------
    cumulative_sets : list[int]
        List of cumulative indices of the sets.
     server : DpfServer, optional
        Server with the channel connected to the remote or local instance.
        The default is ``None``, in which case an attempt is made to use the
        global server.

    Returns
    -------
    scoping : Scoping
        Scoping targeting severals sets (referenced by cumulative indices).
    """
    if not isinstance(cumulative_sets, list):
        raise dpf_errors.InvalidTypeError("list", "cumulative_sets")
    scoping = Scoping(server=server,
                      ids=cumulative_sets,
                      location=locations.time_freq)
    return scoping
Exemplo n.º 7
0
def scoping_by_step_and_substep(load_step_id, subset_id, time_freq_support):
    """Create a specific :class:`ansys.dpf.core.Scoping` for a given step and subset.

    The returned scoping describes a specific time frequency support element for a given
    step and substep.

    Parameters
    ----------
    load_step_id : int
        ID of the load step.
    subset_id : int
        ID of the subset.
    time_freq_support : TimeFreqSupport

    Returns
    -------
    scoping : Scoping
        Scoping based on a given step and substep of a time frequency support.
    """
    set_index = time_freq_support.get_cumulative_index(load_step_id - 1,
                                                       subset_id - 1)
    scoping = Scoping(ids=[set_index + 1],
                      location=locations.time_freq,
                      server=time_freq_support._server)
    return scoping
Exemplo n.º 8
0
def test_as_local_scoping2():
    scop = Scoping()
    with scop.as_local_scoping() as loc:
        loc.location = "Nodal"
        loc.ids = range(1, 101)
        for i in range(0, 100):
            assert loc.id(i) == i + 1
            assert loc.index(i + 1) == i
        assert hasattr(loc, "_is_set") is True
        assert loc._is_set is True
    assert scop.ids == list(range(1, 101))
    assert scop.location == "Nodal"
    with scop.as_local_scoping() as loc:
        assert loc.location == "Nodal"
        for i in range(0, 100):
            assert loc.id(i) == i + 1
            assert loc.index(i + 1) == i
        assert hasattr(loc, "_is_set") is False
Exemplo n.º 9
0
def test_set_get_scoping_scopings_container_new_label(elshape_body_sc):
    sc = elshape_body_sc
    assert sc.get_available_ids_for_label("elshape") == list(range(1, 21))
    for i in range(0, 20):
        scopingid = sc.get_scoping({"elshape": i + 1, "body": 0})._message.id
        assert scopingid != 0
        assert sc.get_scoping(i)._message.id != 0
        assert sc.get_scoping({"elshape": i + 1, "body": 0})._message.id != 0
        assert sc[i]._message.id != 0
        assert sc.get_label_space(i) == {"elshape": i + 1, "body": 0}
        assert sc.get_scoping({
            "elshape": i + 1,
            "body": 0
        }).ids == list(range(0, i + 1))
    sc.add_label("time")
    for i in range(0, 20):
        mscop = {"elshape": i + 1, "body": 0, "time": 1}
        scop = Scoping()
        scop.ids = range(0, i + 10)
        sc.add_scoping(mscop, scop)
    assert len(sc.get_scopings({"elshape": i + 1, "body": 0})) == 2
    for i in range(0, 20):
        scopingid = sc.get_scoping({
            "elshape": i + 1,
            "body": 0,
            "time": 1
        })._message.id
        assert scopingid != 0
        assert sc.get_scoping(i + 20)._message.id != 0
        assert sc[i]._message.id != 0
        assert sc.get_label_space(i + 20) == {
            "elshape": i + 1,
            "body": 0,
            "time": 1
        }
        assert sc.get_scoping({
            "elshape": i + 1,
            "body": 0,
            "time": 1
        }).ids == list(range(0, i + 10))
        assert sc.get_scoping({
            "elshape": i + 1,
            "time": 1
        }).ids == list(range(0, i + 10))
Exemplo n.º 10
0
def test_get_location_property_scoping():
    scop = Scoping()
    scop.location = "Nodal"
    assert scop.location == "Nodal"
    scop = Scoping()
    scop.location = dpf.core.locations.nodal
    assert scop.location == "Nodal"
Exemplo n.º 11
0
def elemental_scoping(element_ids, server=None):
    """Create a specific elemental :class:`ansys.dpf.core.Scoping` associated with a mesh.

    Parameters
    ----------
    element_ids : list[int]
        List of IDs for the elements.
    server : DpfServer, optional
        Server with the channel connected to the remote or local instance.
        The default is ``None``, in which case an attempt is made to use the
        global server.

    Returns
    -------
    scoping : Scoping
    """
    scoping = Scoping(server=server, ids=element_ids, location=locations.elemental)
    return scoping
Exemplo n.º 12
0
def scoping_on_all_time_freqs(tf_support_or_model):
    """Create a specific :class:`ansys.dpf.core.Scoping` with all time or
    frequency sets of a :class:`ansys.dpf.core.TimeFreqSupport` or a class:`ansys.dpf.core.Model`

    Parameters
    ----------
    tf_support_or_model : TimeFreqSupport, Model

    Returns
    -------
    scoping : Scoping
        Scoping with all time or frequency sets IDs.
    """
    if isinstance(tf_support_or_model, Model):
        tf_support_or_model = tf_support_or_model.metadata.time_freq_support
    return Scoping(ids=range(1,
                             len(tf_support_or_model.time_frequencies) + 1),
                   location=locations.time_freq,
                   server=tf_support_or_model._server)
Exemplo n.º 13
0
def scoping_by_load_step(load_step, server=None):
    """Create a specific ``ansys.dpf.core.Scoping`` for a given load step.

    The returned scoping describes a specific time frequency support element
    for a given load step.

    Parameters
    ----------
    load_step : int
        Load step ID of the specific time frequency scoping.
     server : DpfServer, optional
        Server with the channel connected to the remote or local instance.
        The default is ``None``, in which case an attempt is made to use the
        global server.

    Returns
    -------
    scoping : Scoping
        Scoping targeting one load step.
    """
    scoping = Scoping(server=server,
                      ids=[load_step],
                      location=locations.time_freq_step)
    return scoping
Exemplo n.º 14
0
def scoping_by_set(cumulative_set, server=None):
    """Create a specific :class:`ansys.dpf.core.Scoping` for a given cumulative set index.

    The returned scoping describes a specific time frequency support element for a given
    cumulative set index.

    Parameters
    ----------
    cumulative_set : int
        Cumulative index of the set.
    server : DpfServer, optional
        Server with the channel connected to the remote or local instance.
        The default is ``None``, in which case an attempt is made to use the
        global server.

    Returns
    -------
    scoping : Scoping
        Scoping targeting one set (referenced by cumulative index).
    """
    scoping = Scoping(server=server,
                      ids=[cumulative_set],
                      location=locations.time_freq)
    return scoping
Exemplo n.º 15
0
def test_print_scoping():
    scop = Scoping()
    ids = [1, 2, 3, 5, 8, 9, 10]
    scop.ids = ids
    print(scop)
Exemplo n.º 16
0
def test_set_get_ids_scoping():
    scop = Scoping()
    ids = [1, 2, 3, 5, 8, 9, 10]
    scop.ids = ids
    assert scop.ids == ids
Exemplo n.º 17
0
def test_create_scoping():
    scop = Scoping()
    assert scop._message.id
Exemplo n.º 18
0
def test_set_get_ids_long_scoping():
    scop = Scoping()
    ids = range(1, 1000000)
    scop.ids = ids
    assert np.allclose(scop.ids, ids)
Exemplo n.º 19
0
def test_iter_scoping():
    scop = Scoping()
    ids = [1, 2, 3, 5, 8, 9, 10]
    scop.ids = ids
    for i, id in enumerate(scop):
        assert id == ids[i]
Exemplo n.º 20
0
def test_create_scoping_with_ids_location():
    scop = Scoping(ids=[1, 2, 3, 5, 8, 9, 10], location=dpf.core.locations.elemental)
    assert scop._message.id
    assert scop.ids == [1, 2, 3, 5, 8, 9, 10]
    assert scop.location == dpf.core.locations.elemental
Exemplo n.º 21
0
def test_set_get_entity_data_scoping():
    scop = Scoping()
    ids = [1, 2, 3, 5, 8, 9, 10]
    scop.ids = ids
    scop.set_id(0, 11)
    assert scop._get_id(0) == 11
    assert scop._get_index(11) == 0
    scop.set_id(1, 12)
    assert scop._get_id(1) == 12
    assert scop._get_index(12) == 1
Exemplo n.º 22
0
def test_delete_auto_scoping():
    scop = Scoping()
    scop2 = Scoping(scoping=scop)
    scop.__del__()
    with pytest.raises(Exception):
        scop2.ids
Exemplo n.º 23
0
def test_createbycopy_scoping():
    scop = Scoping()
    scop2 = Scoping(scoping=scop._message)
    assert scop._message.id == scop2._message.id
Exemplo n.º 24
0
def test_count_scoping():
    scop = Scoping()
    ids = [1, 2, 3, 5, 8, 9, 10]
    scop.ids = ids
    assert scop._count() == len(ids)
Exemplo n.º 25
0
def test_delete_scoping():
    scop = Scoping()
    scop.__del__()
    with pytest.raises(Exception):
        scop.ids