Exemplo n.º 1
0
def test_mesh():
    """
    mesh should return a meshed array with increasing/decreasing grid size.
    """
    dis = mesh(n=100, a=1)
    d = dis[1:] - dis[:-1]
    assert len(dis) == 100
    assert np.all(d[1:] > d[:-1])

    dis = mesh(n=100, a=-1)
    d = dis[1:] - dis[:-1]
    assert np.all(d[1:] < d[:-1])
Exemplo n.º 2
0
def test_SFplot():
    """
    SFplot should return an axes object when a DiffProfile and time is passed
    """
    diffsys = DiffSystem(Xr=[0, 1], X=[0, 1], DC=[1e-14, 1e-13])
    dis = mesh(0, 1000, 201)
    profile_init = step(dis, 500, diffsys)
    time = 200 * 3600
    profile = sphSim(profile_init, diffsys, time)
    ax = SFplot(profile, time, Xlim=[0, 1], label='test')

    assert isinstance(ax, Axes)
Exemplo n.º 3
0
def test_automesh():
    """
    automesh should return a meshed array whose length is within its range.
    """
    diffsys = DiffSystem(Xr=[0, 1], X=[0, 1], DC=[1e-14, 1e-13])
    dis = mesh(0, 1000, 201)
    profile_init = step(dis, 500, diffsys)
    time = 200 * 3600
    profile = sphSim(profile_init, diffsys, time)
    dism = automesh(profile, diffsys, n=[300, 400])

    assert len(dism) >= 300 and len(dism) <= 400
Exemplo n.º 4
0
def test_dispfunc():
    """
    disfunc and profilefunc should give functions to copy profile data.
    """
    diffsys = DiffSystem(Xr=[0, 1], X=[0, 1], DC=[1e-14, 1e-13])
    dis = mesh(0, 1000, 201)
    profile_init = step(dis, 500, diffsys)
    time = 200 * 3600
    profile = sphSim(profile_init, diffsys, time)

    fX = profilefunc(profile)
    fdis = disfunc(profile.dis, profile.X)

    assert np.all(abs(splev(dis, fX) - profile.X) < 0.01)
    assert np.all(abs(splev(profile.X, fdis) - dis) < 0.1)
Exemplo n.º 5
0
def test_sphsim():
    """
    Single-phase system simulation.
    Offset of the simulated matano plane should be very small.
    """
    diffsys = DiffSystem(Xr=[0, 1], X=[0, 1], DC=[1e-14, 1e-14])
    dis = mesh(0, 1000, 201)
    profile_init = step(dis, 500, diffsys)
    time = 200 * 3600
    profile_final = sphSim(profile_init, diffsys, time)

    mpi = matanocalc(profile_init, [0, 1])
    mpf = matanocalc(profile_final, [0, 1])

    assert isinstance(profile_final, DiffProfile)
    assert len(profile_final.If) == diffsys.Np + 1
    assert abs(mpi - mpf) < 1
Exemplo n.º 6
0
def test_mphsim():
    """
    Multiple-phase system simulation.
    Offset of the simulated matano plane should be very small.
    """
    Xr = [[0, .4], [.6, 1]]
    X = np.linspace(0, 1, 101)
    DC = np.linspace(1, 2, 101) * 1e-14
    diffsys = DiffSystem(Xr=Xr, X=X, DC=DC)
    dis = mesh(0, 1000, 201)
    profile_init = step(dis, 500, diffsys)
    time = 200 * 3600
    profile_final = mphSim(profile_init, diffsys, time)

    mpi = matanocalc(profile_init, [0, 1])
    mpf = matanocalc(profile_final, [0, 1])

    assert isinstance(profile_final, DiffProfile)
    assert len(profile_final.If) == diffsys.Np + 1
    assert abs(mpi - mpf) < 1
Exemplo n.º 7
0
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from pydiffusion.core import DiffSystem
from pydiffusion.utils import step, mesh
from pydiffusion.simulation import mphSim
from pydiffusion.plot import profileplot, DCplot
from pydiffusion.io import read_csv, save_csv

# Create diffusion system with constant DC
diffsys = DiffSystem(Xr=[0, 1], X=[0, 1], DC=[1e-14, 1e-14], name='Constant D')

# Create initial step profile
dis = mesh(0, 1000, 501)
profile_init = step(dis, 500, diffsys, name='Intitial step profile')

fig = plt.figure(figsize=(16, 6))
ax1, ax2 = fig.add_subplot(121), fig.add_subplot(122)
ax1.set_title('Diffusion Coefficients', fontsize=15)
ax2.set_title('Initial Step Profile', fontsize=15)
DCplot(diffsys, ax1)
profileplot(profile_init, ax2)

# Diffusion simulation using the setups
time = 200 * 3600
profile_final = mphSim(profile_init, diffsys, time)

ax = profileplot(profile_init, ls='--')
profileplot(profile_final, ax, c='r')

# Read diffusion coefficients data of Ni-Mo system