Exemplo n.º 1
0
def test_3d():
    """Test FE in 3D"""
    def setone(arr):
        arr[0, :, (arr.shape[0] - 1) // 2] = 1.0
        return arr

    assert pipe(
        5,
        lambda x: np.zeros((1, x, x, x), dtype=int),
        setone,
        solve_fe(elastic_modulus=(1.0, 10.0), poissons_ratio=(0.0, 0.0)),
        lambda x: np.allclose(
            [np.mean(x["strain"][0, ..., i]) for i in range(6)],
            [1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        ),
    )
Exemplo n.º 2
0
 def testing(size, macro_strain):
     return pipe(
         size,
         lambda x: np.random.randint(2, size=(1, x, x, x)),
         solve_fe(
             elastic_modulus=(10.0, 1.0),
             poissons_ratio=(0.3, 0.3),
             macro_strain=macro_strain,
         ),
         get("displacement"),
         first,
         lambda x: (
             np.allclose(x[-1, ..., 0] - x[0, ..., 0], size * macro_strain),
             np.allclose(x[0, ..., 1], x[-1, ..., 1]),
         ),
         all,
     )
def test_setting_kernel():
    """Test resetting the coeffs after coeff resize."""

    x_data = generate_delta(n_phases=2, shape=(21, 21)).persist()

    y_data = solve_fe(x_data,
                      elastic_modulus=(100, 130),
                      poissons_ratio=(0.3, 0.3),
                      macro_strain=0.01)["strain"][..., 0].persist()

    model = make_pipeline(PrimitiveTransformer(n_state=2),
                          LocalizationRegressor())

    shape = (30, 30)
    fcoeff = model.fit(x_data, y_data).steps[1][1].coeff
    assert np.allclose(model.steps[1][1].coeff_resize(shape).coeff.shape[:-1],
                       shape)
    model.steps[1][1].coeff = fcoeff
    assert np.allclose(model.predict(x_data), y_data, atol=1e-4)
Exemplo n.º 4
0
 def test(x_data):
     solve_fe(x_data,
              elastic_modulus=(1, 2, 3),
              poissons_ratio=(0.3, 0.3, 0.3))