Ejemplo n.º 1
0
def test_save_load():
    p = PointMass(n=0, m=10.0, tag="pointmass")
    file = Path(tempdir) / "point_mass.toml"
    p.save(file)
    p_loaded = p.load(file)

    assert p == p_loaded
Ejemplo n.º 2
0
def test_local_index():
    n = 0
    mx = 1.0
    my = 2.0
    p = PointMass(n=n, mx=mx, my=my)

    assert p.dof_local_index().x_0 == 0
    assert p.dof_local_index().y_0 == 1
Ejemplo n.º 3
0
    def random_var(self, is_random, *args):
        """Generate a list of objects as random attributes.

        This function creates a list of objects with random values for selected
        attributes from ross.PointMass.

        Parameters
        ----------
        is_random : list
            List of the object attributes to become stochastic.
        *args : dict
            Dictionary instanciating the ross.PointMass class.
            The attributes that are supposed to be stochastic should be
            set as lists of random variables.

        Returns
        -------
        f_list : generator
            Generator of random objects.
        """
        args_dict = args[0]
        new_args = []
        for i in range(len(args_dict[is_random[0]])):
            arg = []
            for key, value in args_dict.items():
                if key in is_random:
                    arg.append(value[i])
                else:
                    arg.append(value)
            new_args.append(arg)
        f_list = (PointMass(*arg) for arg in new_args)

        return f_list
Ejemplo n.º 4
0
def test_point_mass():
    # fmt: off
    m0 = np.array([[10.0, 0], [0, 10.0]])
    # fmt: on

    p = PointMass(n=0, m=10.0)

    assert_allclose(m0, p.M())
    assert_allclose(np.zeros((2, 2)), p.K())
    assert_allclose(np.zeros((2, 2)), p.C())
    assert_allclose(np.zeros((2, 2)), p.G())
Ejemplo n.º 5
0
def test_pickle():
    p = PointMass(n=0, m=10.0, tag="pointmass")
    p_pickled = pickle.loads(pickle.dumps(p))
    assert p == p_pickled