<commit_before># -*- coding: utf-8 -*-
"""
Created on Wed Jul  2 16:38:29 2014

@author: Jackie
"""
import OpenPNM
import matplotlib.pyplot as plt
import scipy as sp


r"""
returns array
array[0] = saturation
array[1] = relative permeability
array[2] = relative effective diffusivity
"""  
Lc = 40.5e-6
N = 10

#setting up network
sgl = OpenPNM.Network.Cubic(name = 'SGL10BA')
sgl.generate(divisions = [N, N, N], add_boundaries = False, lattice_spacing = [Lc])

#pore size distribution parameters
lmbda = 9e-6
k = 3.5
bmin = 9e-6
xmax = .9

#set up geometries
geo = OpenPNM.Geometry.GenericGeometry(name = 'sgl', network = sgl)
geo.set_locations(pores = sgl.pores('all'), throats = 'all')

Np = sgl.num_pores('sgl')
value = lmbda*(-sp.log(1-sp.random.rand(Np)*xmax))**(-1/k) + bmin
sgl.set_data(prop='diameter',pores=geo.pores(),data=value)

geo.add_method(prop='pore_volume',model='sphere')
geo.add_method(prop='throat_length',model='straight')
geo.add_method(prop='throat_volume',model='cuboid')

connected_pores = sgl.find_connected_pores(geo.throats())
value = [min(sgl.get_data(pores = pair[0], prop = 'diameter'), sgl.get_data(pores = pair[1], prop = 'diameter')) for pair in connected_pores]
sgl.set_data(prop = 'diameter', throats = geo.throats(), data = value)


sgl.regenerate_geometries()

#spatial correlation of pore sizes?!

#constricting sgl by .95 in both the z and y direction  
throats = geo.throats()
connected_pores = sgl.find_connected_pores(throats)
x1 = [sgl['pore.coords'][pair[0]][0] for pair in connected_pores]
x2 = [sgl['pore.coords'][pair[1]][0] for pair in connected_pores]
same_x = [x - y == 0 for x, y in zip(x1,x2)]
factor = [s*.95 + (not s)*1 for s in same_x]
throat_diameters = sgl['throat.diameter'][throats]*factor
sgl.set_data(throats = throats, prop = 'diameter', data = throat_diameters)

#set up fluids 
air = OpenPNM.Fluids.Air(network = sgl, name = 'air')
water = OpenPNM.Fluids.Water(network = sgl, name = 'water')
#MYSTERIOUSLY BROKEN LINE
#water_sgl.add_property(prop = 'contact_angle', model = 'constant', value = 100)
water['pore.contact_angle'] = 100
sgl.regenerate_fluids()

#set up physics 
phys_water = OpenPNM.Physics.GenericPhysics(network=sgl,fluid=water, geometry = geo, name='standard_water_physics')
phys_air = OpenPNM.Physics.GenericPhysics(network=sgl,fluid=air, geometry = geo, name='standard_air_physics')
   
phys_water.add_property(prop='capillary_pressure', model='washburn')
phys_water.add_property(prop='hydraulic_conductance',model='hagen_poiseuille')
phys_water.add_property(prop='diffusive_conductance', model='bulk_diffusion', shape = 'square')

phys_air.add_property(prop='hydraulic_conductance',model='hagen_poiseuille')
phys_air.add_property(prop='diffusive_conductance', model='bulk_diffusion') 


sgl.regenerate_physics()

#late pore filling?!

#running invasion percolation
inlets = sgl.get_pore_indices(labels = ['front'])
outlets = sgl.get_pore_indices(labels = ['back'])

end_condition = 'breakthrough'
    
OP_1 = OpenPNM.Algorithms.OrdinaryPercolation(network=sgl,loglevel=30)
OP_1.setup(invading_fluid = water, defending_fluid = air, inlets = inlets,npts=100)
OP_1.run() 

x_values = []
y_values = []
y2_values = []
z_values = []
z2_values = []

max_capillary_pressure = max(OP_1.get_throat_data(prop = 'inv_Pc'))
#    OP_1.update(max(OP_1.get_throat_data(prop='inv_Pc')))
#    OP_1.update(sp.stats.mstats.mode(OP_1.get_pore_data(prop='inv_Pc')))

for x in range(50):
    OP_1.update(max_capillary_pressure*(x/50.0))
    
    #adding multiphase conductances
    phys_air.add_property(prop='multiphase',model='conduit_conductance',
                      conductance = 'diffusive_conductance', prop_name='conduit_diffusive_conductance',mode='loose')
    phys_water.add_property(prop='multiphase',model='conduit_conductance',
                      conductance = 'diffusive_conductance', prop_name='conduit_diffusive_conductance',mode='loose')
    phys_air.add_property(prop='multiphase',model='conduit_conductance',
                      conductance = 'hydraulic_conductance', prop_name='conduit_hydraulic_conductance',mode='loose')
    phys_water.add_property(prop='multiphase',model='conduit_conductance',
                      conductance = 'hydraulic_conductance', prop_name='conduit_hydraulic_conductance',mode='loose')
    sgl.regenerate_physics()
    
    
    #run Stokes Flow and find Permeability
    #single phase
    Stokes_alg_single_phase_air = OpenPNM.Algorithms.StokesFlow(loggername = 'Stokes', name = 'Stokes_alg_single_phase_air', network = sgl)
    Stokes_alg_single_phase_water = OpenPNM.Algorithms.StokesFlow(loggername = 'Stokes_2', name = 'Stokes_alg_single_phase_water', network = sgl)
    
    Fickian_alg_single_phase_air = OpenPNM.Algorithms.FickianDiffusion(loggername = 'Fickian', name = 'Fickian_alg_single_phase_air', network = sgl)
    Fickian_alg_single_phase_water = OpenPNM.Algorithms.FickianDiffusion(loggername = 'Fickian_2', name = 'Fickian_alg_single_phase_water', network = sgl)
    
    Stokes_alg_multi_phase_air = OpenPNM.Algorithms.StokesFlow(loggername = 'Stokes', name = 'Stokes_alg_multi_phase_air', network = sgl)
    Stokes_alg_multi_phase_water = OpenPNM.Algorithms.StokesFlow(loggername = 'Stokes_2', name = 'Stokes_alg_multi_phase_water', network = sgl)
    <commit_msg>Added boundary pores<commit_after># -*- coding: utf-8 -*-
"""
Created on Wed Jul  2 16:38:29 2014

@author: Jackie
"""
import OpenPNM
import matplotlib.pyplot as plt
import scipy as sp


r"""
returns array
array[0] = saturation
array[1] = relative permeability
array[2] = relative effective diffusivity
"""  
Lc = 40.5e-6
N = 10

#setting up network
sgl = OpenPNM.Network.Cubic(name = 'SGL10BA')
sgl.generate(divisions = [N, N, N], add_boundaries = True, lattice_spacing = [Lc])

#pore size distribution parameters
lmbda = 9e-6
k = 3.5
bmin = 9e-6
xmax = .9

#set up geometries
geo = OpenPNM.Geometry.GenericGeometry(name = 'sgl', network = sgl)
geo.set_locations(pores = sgl.pores('all'), throats = 'all')

Np = sgl.num_pores('sgl')
value = lmbda*(-sp.log(1-sp.random.rand(Np)*xmax))**(-1/k) + bmin
sgl.set_data(prop='diameter',pores=geo.pores(),data=value)

geo.add_method(prop='pore_volume',model='sphere')
geo.add_method(prop='throat_length',model='straight')
geo.add_method(prop='throat_volume',model='cuboid')

connected_pores = sgl.find_connected_pores(geo.throats())
value = [min(sgl.get_data(pores = pair[0], prop = 'diameter'), sgl.get_data(pores = pair[1], prop = 'diameter')) for pair in connected_pores]
sgl.set_data(prop = 'diameter', throats = geo.throats(), data = value)


sgl.regenerate_geometries()

#spatial correlation of pore sizes?!

#constricting sgl by .95 in both the z and y direction  
throats = geo.throats()
connected_pores = sgl.find_connected_pores(throats)
x1 = [sgl['pore.coords'][pair[0]][0] for pair in connected_pores]
x2 = [sgl['pore.coords'][pair[1]][0] for pair in connected_pores]
same_x = [x - y == 0 for x, y in zip(x1,x2)]
factor = [s*.95 + (not s)*1 for s in same_x]
throat_diameters = sgl['throat.diameter'][throats]*factor
sgl.set_data(throats = throats, prop = 'diameter', data = throat_diameters)

#set up fluids 
air = OpenPNM.Fluids.Air(network = sgl, name = 'air')
water = OpenPNM.Fluids.Water(network = sgl, name = 'water')
#MYSTERIOUSLY BROKEN LINE
#water_sgl.add_property(prop = 'contact_angle', model = 'constant', value = 100)
water['pore.contact_angle'] = 100
sgl.regenerate_fluids()

#set up physics 
phys_water = OpenPNM.Physics.GenericPhysics(network=sgl,fluid=water, geometry = geo, name='standard_water_physics')
phys_air = OpenPNM.Physics.GenericPhysics(network=sgl,fluid=air, geometry = geo, name='standard_air_physics')
   
phys_water.add_property(prop='capillary_pressure', model='washburn')
phys_water.add_property(prop='hydraulic_conductance',model='hagen_poiseuille')
phys_water.add_property(prop='diffusive_conductance', model='bulk_diffusion', shape = 'square')

phys_air.add_property(prop='hydraulic_conductance',model='hagen_poiseuille')
phys_air.add_property(prop='diffusive_conductance', model='bulk_diffusion') 


sgl.regenerate_physics()

#late pore filling?!

#running invasion percolation
inlets = sgl.get_pore_indices(labels = ['top','boundary'],mode='intersection')
outlets = sgl.get_pore_indices(labels = ['bottom','boundary'],mode='intersection')

end_condition = 'breakthrough'
    
OP_1 = OpenPNM.Algorithms.OrdinaryPercolation(network=sgl,loglevel=30)
OP_1.setup(invading_fluid = water, defending_fluid = air, inlets = inlets,npts=100)
OP_1.run() 

x_values = []
y_values = []
y2_values = []
z_values = []
z2_values = []

max_capillary_pressure = max(OP_1.get_throat_data(prop = 'inv_Pc'))
#    OP_1.update(max(OP_1.get_throat_data(prop='inv_Pc')))
#    OP_1.update(sp.stats.mstats.mode(OP_1.get_pore_data(prop='inv_Pc')))

for x in range(50):
    OP_1.update(max_capillary_pressure*(x/50.0))
    
    #adding multiphase conductances
    phys_air.add_property(prop='multiphase',model='conduit_conductance',
                      conductance = 'diffusive_conductance', prop_name='conduit_diffusive_conductance',mode='strict')
    phys_water.add_property(prop='multiphase',model='conduit_conductance',
                      conductance = 'diffusive_conductance', prop_name='conduit_diffusive_conductance',mode='strict')
    phys_air.add_property(prop='multiphase',model='conduit_conductance',
                      conductance = 'hydraulic_conductance', prop_name='conduit_hydraulic_conductance',mode='strict')
    phys_water.add_property(prop='multiphase',model='conduit_conductance',
                      conductance = 'hydraulic_conductance', prop_name='conduit_hydraulic_conductance',mode='strict')
    sgl.regenerate_physics()
    
    
    #run Stokes Flow and find Permeability
    #single phase
    Stokes_alg_single_phase_air = OpenPNM.Algorithms.StokesFlow(loggername = 'Stokes', name = 'Stokes_alg_single_phase_air', network = sgl)
    Stokes_alg_single_phase_water = OpenPNM.Algorithms.StokesFlow(loggername = 'Stokes_2', name = 'Stokes_alg_single_phase_water', network = sgl)
    
    Fickian_alg_single_phase_air = OpenPNM.Algorithms.FickianDiffusion(loggername = 'Fickian', name = 'Fickian_alg_single_phase_air', network = sgl)
    Fickian_alg_single_phase_water = OpenPNM.Algorithms.FickianDiffusion(loggername = 'Fickian_2', name = 'Fickian_alg_single_phase_water', network = sgl)
    
    Stokes_alg_multi_phase_air = OpenPNM.Algorithms.StokesFlow(loggername = 'Stokes', name = 'Stokes_alg_multi_phase_air', network = sgl)
    Stokes_alg_multi_phase_water = OpenPNM.Algorithms.StokesFlow(loggername = 'Stokes_2', name = 'Stokes_alg_multi_phase_water', network = sgl)
    
{'fraction_non_alphanumeric': 0.13466941374789287, 'fraction_numerical': 0.01460947743023038, 'mean_word_length': 6.011818778726198, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5472992', 'n_tokens_mistral': 4104, 'n_tokens_neox': 3884, 'n_words': 644}