Esempio n. 1
0
def test_RF_free_energy():

    import cDFT.minimisation as minimisation
    test_data = minimisation.DFT(0.2, 'Hard Wall', 0.5, 1.0, 1024, 0.005,
                                 'Rosenfeld')
    print(test_data.n0.shape)
    test_wdens = np.genfromtxt(
        '../Tests/Test_data/Wilding_Weighted_densities_RF_free_energy')
    test_data.n0[:] = test_wdens[:, 1]
    test_data.n1[:] = test_wdens[:, 2]
    test_data.n2[:] = test_wdens[:, 3]
    test_data.n3[:] = test_wdens[:, 4]
    test_data.n1v[:] = test_wdens[:, 5]
    test_data.n2v[:] = test_wdens[:, 6]
    test_data.n3neg[:] = 1.0 - test_wdens[:, 4]
    test_data.rho[:] = test_wdens[:, 7]
    free_energy = np.zeros(1024)
    free_energy = Rosenfeld_free_energy(test_data)
    free_energy_excess = np.sum(free_energy[:test_data.N - 3 * test_data.NiR] *
                                0.005)
    free_energy_ideal = np.sum(
        test_data.Temp *
        test_data.rho[test_data.NiR:test_data.N - 2 * test_data.NiR] *
        (np.log(test_data.rho[test_data.NiR:test_data.N - 2 * test_data.NiR]) -
         1.0)) * 0.005
    free_energy_ideal -= np.sum(
        test_data.rho[test_data.NiR:test_data.N - 2 * test_data.NiR] *
        (test_data.mu + np.log(0.38197))) * 0.005
    print(
        f'Excess = {free_energy_excess:.6f}\t Ideal = {free_energy_ideal:.6f}\t total = {free_energy_excess+free_energy_ideal:.6f}\n'
    )
Esempio n. 2
0
def test_RF_derivatives():
    """
    Run this to check the output of the derivatives for the RF function match those
    of the test data provided by the 'spherical_working.c' Wilding program.

    """
    import cDFT.minimisation as minimisation
    test_data = minimisation.DFT(0.2, 'Hard Wall', 0.5, 1.0, 256, 0.05,
                                 'Rosenfeld')
    test_wdens = np.genfromtxt(
        '../Tests/Test_data/Wilding_Weighted_Densities_RF')
    print(test_wdens.shape)
    test_data.n0[:] = test_wdens[:, 1]
    test_data.n1[:] = test_wdens[:, 2]
    test_data.n2[:] = test_wdens[:, 3]
    test_data.n3[:] = test_wdens[:, 4]
    test_data.n1v[:] = test_wdens[:, 5]
    test_data.n2v[:] = test_wdens[:, 6]
    test_data.n3neg[:] = 1.0 - test_wdens[:, 4]

    del test_wdens

    calculate_Rosenfeld_derivatives(test_data)
    with open('../test_RF_derivatives', 'w') as divs:
        divs.write(
            f'i     rho            d2           d3           d2v          \n')
        for i in range(1, test_data.N):
            divs.write(
                f'{i:{3}} {test_data.rho[i]:{7}.{5}} {test_data.d2[i]:{12}.{10}} {test_data.d3[i]:{12}.{10}} {test_data.d2v[i]:{12}.{10}}\n'
            )
Esempio n. 3
0
def test_WB_derivatives():
    """
    Run this to check the ouput of the derivatives for the WB functional match those
    of the test data provided by Roth. 
    """
    import cDFT.minimisation as minimisation
    test_data = minimisation.DFT(0.2, 'Hard Wall', 1.0, 1.0, 256, 0.05,
                                 'Whitebear')
    test_wdens = np.genfromtxt('../Tests/Test_data/Roth_Weighted_Densities_WB')
    print(test_wdens.shape)
    test_data.n0[1:216] = test_wdens[:, 3]
    test_data.n1[1:216] = test_wdens[:, 4]
    test_data.n2[1:216] = test_wdens[:, 5]
    test_data.n3[1:216] = test_wdens[:, 6]
    test_data.n1v[1:216] = test_wdens[:, 7]
    test_data.n2v[1:216] = test_wdens[:, 8]
    test_data.n3neg[1:216] = 1.0 - test_wdens[:, 6]

    del test_wdens

    calculate_Whitebear_derivatives(test_data)
    with open('../test_WB_derivatives', 'w') as divs:
        divs.write(
            f'i     rho            d2           d3           d2v          \n')
        for i in range(1, test_data.N):
            divs.write(
                f'{i:{3}} {test_data.rho[i]:{7}.{5}} {test_data.d2[i]:{12}.{10}} {test_data.d3[i]:{12}.{10}} {test_data.d2v[i]:{12}.{10}}\n'
            )
Esempio n. 4
0
def adsorption_sum_rule(DFT, alpha, file_path, geometry, Rs=None):

    if geometry == 'planar':
        minimise = minimisation.planar(DFT, alpha, file_path)
    elif geometry == 'spherical':
        minimise = minimisation.spherical(DFT, Rs, alpha, file_path)

    minimise.minimise()
    mu_old = minimise.DFT.mu + minimise.DFT.Temp * np.log(
        minimise.DFT.rho_bulk)
    if geometry == 'planar':
        adsorp = adsorption('planar', minimise)
        gamma_old = surface_tension('planar', minimise)
    elif geometry == 'spherical':
        adsorp = adsorption('spherical', minimise)
        gamma_old = surface_tension('spherical', minimise)

    del minimise

    new_DFT = minimisation.DFT(DFT.eta * (1.00001), DFT.Vext_type, DFT.R,
                               DFT.Temp, DFT.N, DFT.dr, DFT.functional)
    if geometry == 'planar':
        minimise = minimisation.planar(new_DFT, alpha, file_path)
    elif geometry == 'spherical':
        minimise = minimisation.spherical(new_DFT, Rs, alpha, file_path)

    mu_new = minimise.DFT.mu + minimise.DFT.Temp * np.log(
        minimise.DFT.rho_bulk)
    minimise.minimise()
    if geometry == 'planar':
        gamma_new = surface_tension('planar', minimise)
    elif geometry == 'spherical':
        gamma_new = surface_tension('spherical', minimise)

    del minimise

    dmu = mu_new - mu_old
    deriv = -1.0 * (gamma_new - gamma_old) / dmu

    print(f'\n----------------------------------------------------')
    print(f'Adsorption = {adsorp:.10f} -dgamma/dmu = {deriv:.10f}')
    print(f'Relative Error = {abs(deriv-adsorp)/adsorp:.10f}')
    print(f'----------------------------------------------------\n')
    return adsorp, deriv
Esempio n. 5
0
In the mean time, enjoy playing around with cDFT!
"""

# To use the package, we import the various files
import cDFT.minimisation as minimisation
import cDFT.output as output
import cDFT.standard_routines as standard_routines
import numpy as np
import matplotlib.pyplot as plt


# The DFT object is specified as packing fraction, interaction, radius of spheres, 
# temperature, number of grid points (recommended to be a power of 2), grid discretisation \
# and functional.
RF = minimisation.DFT(0.2,'Hard Wall',1.0,1.0,2**14,0.005,'Rosenfeld')

# To initiate a planar minimisation, you must give a DFT, a mixing parameter (recommended
# to be between 0.01 and 0.1) and an output filepath. To minimise, then just call the
# minimise routine.
planar = minimisation.planar(RF, 0.1, './RF_planar_example/')
planar.minimise()

# To see the density profile, send the minimisation object to output. This is
# saved to a pdf in the output directory './RF_planar_example/'.
output.plot_single_density(planar)

# For the planar geometry, the surface tension, grand potential and adsorption can be found.
# We can also explore the accuracy of the minimisation using some sum rules relating to these.
# To find the surface tension, or the excess grand potential, use the standard_routines package, 
# specifying first the geometry as a string, and then sending the minimisation object.