예제 #1
0
def test_stress():
    from pymks.datasets import make_elastic_stress_random
    from pymks import MKSHomogenizationModel, DiscreteIndicatorBasis
    sample_size = 200
    grain_size = [(5, 5), (6, 4), (4, 6), (2, 2)]
    n_samples = [sample_size] * len(grain_size)
    elastic_modulus = (410, 200)
    poissons_ratio = (0.28, 0.3)
    macro_strain = 0.001
    size = (21, 21)
    X, y = make_elastic_stress_random(n_samples=n_samples,
                                      size=size,
                                      grain_size=grain_size,
                                      elastic_modulus=elastic_modulus,
                                      poissons_ratio=poissons_ratio,
                                      macro_strain=macro_strain,
                                      seed=0)
    dbasis = DiscreteIndicatorBasis(n_states=2, domain=[0, 1])
    model = MKSHomogenizationModel(basis=dbasis, n_components=3, degree=3)
    model.fit(X, y)
    test_sample_size = 1
    n_samples = [test_sample_size] * len(grain_size)
    X_new, y_new = make_elastic_stress_random(n_samples=n_samples,
                                              size=size,
                                              grain_size=grain_size,
                                              elastic_modulus=elastic_modulus,
                                              poissons_ratio=poissons_ratio,
                                              macro_strain=macro_strain,
                                              seed=3)
    y_result = model.predict(X_new)
    assert np.allclose(np.round(y_new, decimals=2),
                       np.round(y_result, decimals=2))
예제 #2
0
def test_stress():
    from pymks.datasets import make_elastic_stress_random
    from pymks import MKSHomogenizationModel, DiscreteIndicatorBasis
    sample_size = 200
    grain_size = [(5, 5), (6, 4), (4, 6), (2, 2)]
    n_samples = [sample_size] * len(grain_size)
    elastic_modulus = (410, 200)
    poissons_ratio = (0.28, 0.3)
    macro_strain = 0.001
    size = (21, 21)
    X, y = make_elastic_stress_random(n_samples=n_samples, size=size,
                                      grain_size=grain_size,
                                      elastic_modulus=elastic_modulus,
                                      poissons_ratio=poissons_ratio,
                                      macro_strain=macro_strain, seed=0)
    dbasis = DiscreteIndicatorBasis(n_states=2, domain=[0, 1])
    model = MKSHomogenizationModel(basis=dbasis, n_components=3, degree=3)
    model.fit(X, y)
    test_sample_size = 1
    n_samples = [test_sample_size] * len(grain_size)
    X_new, y_new = make_elastic_stress_random(
        n_samples=n_samples, size=size, grain_size=grain_size,
        elastic_modulus=elastic_modulus, poissons_ratio=poissons_ratio,
        macro_strain=macro_strain, seed=3)
    y_result = model.predict(X_new)
    assert np.allclose(np.round(y_new, decimals=2),
                       np.round(y_result, decimals=2))
예제 #3
0
def test_make_elastic_stress_randome():
    X, y = make_elastic_stress_random(n_samples=1, elastic_modulus=(1, 1),
                                      poissons_ratio=(1, 1),
                                      grain_size=(3, 3), macro_strain=1.0)
    assert np.allclose(y, np.ones(y.shape))
    X, y = make_elastic_stress_random(n_samples=1, grain_size=(1, 1),
                                      elastic_modulus=(100, 200),
                                      size=(2, 2), poissons_ratio=(1, 3),
                                      macro_strain=1., seed=4)
    X_result = np.array([[[1, 1],
                          [0, 1]]])
    assert float(np.round(y, decimals=5)[0]) == 228.74696
    assert np.allclose(X, X_result)
    X, y = make_elastic_stress_random(n_samples=1, grain_size=(1, 1, 1),
                                      elastic_modulus=(100, 200),
                                      poissons_ratio=(1, 3),  seed=5,
                                      macro_strain=1., size=(2, 2, 2))
    X_result = np.array([[[1, 1],
                          [1, 0]],
                         [[1, 1],
                          [0, 0]]])
    assert np.allclose(X, X_result)
    assert y.astype(int) == 145
예제 #4
0
macro_strain = 0.001

n_phases = 2
grain_size = [(40, 2), (10, 2), (2, 40), (2, 10)]

grain_size1 = (40, 2)
grain_size2 = (10, 2)
grain_size3 = (2, 40)
grain_size4 = (2, 10)
power = [1, 2, 5, 10]
# Create Samples and calculate stresses

dataset1, stresses1 = make_elastic_stress_random(n_samples=n_samples,
                                                 size=size,
                                                 grain_size=grain_size,
                                                 elastic_modulus=elastic_modulus,
                                                 poissons_ratio=poissons_ratio,
                                                 macro_strain=macro_strain,
                                                 seed=0, power=power[0])
dataset2, stresses2 = make_elastic_stress_random(n_samples=n_samples,
                                                 size=size,
                                                 grain_size=grain_size,
                                                 elastic_modulus=elastic_modulus,
                                                 poissons_ratio=poissons_ratio,
                                                 macro_strain=macro_strain,
                                                 seed=0, power=power[1])
dataset3, stresses3 = make_elastic_stress_random(n_samples=n_samples,
                                                 size=size,
                                                 grain_size=grain_size,
                                                 elastic_modulus=elastic_modulus,
                                                 poissons_ratio=poissons_ratio,