예제 #1
0
def test_multiphase_FE_strain():
    from pymks import MKSRegressionModel
    from pymks.datasets import make_elastic_FE_strain_delta
    from pymks.datasets import make_elastic_FE_strain_random
    from pymks.bases import DiscreteIndicatorBasis

    L = 21
    i = 3
    elastic_modulus = (80, 100, 120)
    poissons_ratio = (0.3, 0.3, 0.3)
    macro_strain = 0.02
    size = (L, L)

    X_delta, strains_delta = \
        make_elastic_FE_strain_delta(elastic_modulus=elastic_modulus,
                                     poissons_ratio=poissons_ratio,
                                     size=size, macro_strain=macro_strain)
    basis = DiscreteIndicatorBasis(len(elastic_modulus))
    MKSmodel = MKSRegressionModel(basis)
    MKSmodel.fit(X_delta, strains_delta)
    np.random.seed(99)
    X, strain = make_elastic_FE_strain_random(n_samples=1,
                                              elastic_modulus=elastic_modulus,
                                              poissons_ratio=poissons_ratio,
                                              size=size,
                                              macro_strain=macro_strain)
    strain_pred = MKSmodel.predict(X)

    assert np.allclose(strain_pred[0, i:-i],
                       strain[0, i:-i],
                       rtol=1e-2,
                       atol=6.1e-3)
예제 #2
0
def test_multiphase_FE_strain():
    from pymks import MKSRegressionModel
    from pymks.datasets import make_elastic_FE_strain_delta
    from pymks.datasets import make_elastic_FE_strain_random
    from pymks.bases import DiscreteIndicatorBasis

    L = 21
    i = 3
    elastic_modulus = (80, 100, 120)
    poissons_ratio = (0.3, 0.3, 0.3)
    macro_strain = 0.02
    size = (L, L)

    X_delta, strains_delta = \
        make_elastic_FE_strain_delta(elastic_modulus=elastic_modulus,
                                     poissons_ratio=poissons_ratio,
                                     size=size, macro_strain=macro_strain)
    basis = DiscreteIndicatorBasis(len(elastic_modulus))
    MKSmodel = MKSRegressionModel(basis)
    MKSmodel.fit(X_delta, strains_delta)
    np.random.seed(99)
    X, strain = make_elastic_FE_strain_random(n_samples=1,
                                              elastic_modulus=elastic_modulus,
                                              poissons_ratio=poissons_ratio,
                                              size=size,
                                              macro_strain=macro_strain)
    strain_pred = MKSmodel.predict(X)

    assert np.allclose(strain_pred[0, i:-i], strain[0, i:-i],
                       rtol=1e-2, atol=6.1e-3)
예제 #3
0
def test_setting_kernel():
    from pymks.datasets import make_elastic_FE_strain_delta
    from pymks import MKSLocalizationModel
    from pymks import PrimitiveBasis
    elastic_modulus = (100, 130)
    poissons_ratio = (0.3, 0.3)
    X_delta, y = make_elastic_FE_strain_delta(size=(21, 21),
                                              elastic_modulus=elastic_modulus,
                                              poissons_ratio=poissons_ratio)
    p_basis = PrimitiveBasis(2)
    model = MKSLocalizationModel(basis=p_basis)
    model.fit(X_delta, y)
    coefs = model.coef_
    model.resize_coeff((30, 30))
    model.coef_ = coefs
    assert np.allclose(model.predict(X_delta), y, atol=1e-4)
예제 #4
0
def test_setting_kernel():
    from pymks.datasets import make_elastic_FE_strain_delta
    from pymks import MKSLocalizationModel
    from pymks import PrimitiveBasis
    elastic_modulus = (100, 130)
    poissons_ratio = (0.3, 0.3)
    X_delta, y = make_elastic_FE_strain_delta(size=(21, 21),
                                              elastic_modulus=elastic_modulus,
                                              poissons_ratio=poissons_ratio)
    p_basis = PrimitiveBasis(2)
    model = MKSLocalizationModel(basis=p_basis)
    model.fit(X_delta, y)
    coefs = model.coef_
    model.resize_coeff((30, 30))
    model.coef_ = coefs
    assert np.allclose(model.predict(X_delta), y, atol=1e-4)
예제 #5
0
def get_delta_data(nx, ny):
    from pymks.datasets import make_elastic_FE_strain_delta
    return make_elastic_FE_strain_delta(elastic_modulus=(1, 1.1),
                                        poissons_ratio=(0.3, 0.3),
                                        size=(nx, ny))
예제 #6
0
def get_delta_data(nx, ny):
    from pymks.datasets import make_elastic_FE_strain_delta
    return make_elastic_FE_strain_delta(elastic_modulus=(1, 1.1),
                                        poissons_ratio=(0.3, 0.3),
                                        size=(nx, ny))
예제 #7
0
def test_make_elastic_FE_strain_delta():
    elastic_modulus = (1., 2.)
    poissons_ratio = (0.3, 0.3)
    X, y = make_elastic_FE_strain_delta(elastic_modulus=elastic_modulus,
                                        poissons_ratio=poissons_ratio,
                                        size=(5, 5))