Closed jiahui185 closed 2 weeks ago
import numpy as np import openpnm as op import pandas as pd import matplotlib.pyplot as plt import scipy.stats as spst
op.visualization.set_mpl_style() np.random.seed(10) ws = op.Workspace() ws.settings["loglevel"] = 40 np.set_printoptions(precision=5) df = pd.read_csv('Sandstone.csv') print(df) df['R'] = -20.480np.cos(np.deg2rad(140))/df['Pc [Pa]'] fig, ax = plt.subplots() ax.semilogx(2df['R']1e6, df['S_Hg'], 'b.') ax.set_xlabel('Pore Diameter [um]'); pn = op.network.Cubic(shape=[4, 4, 4], connectivity=26) np.random.seed(0) drop = np.random.randint(0, pn.Nt, 500) op.topotools.trim(network=pn, throats=drop) ax = op.visualization.plot_coordinates(pn) ax = op.visualization.plot_connections(pn, ax=ax) np.random.seed(0) # Set the state of the random number generator to "0" pn['pore.seed'] = np.random.rand(pn.Np) from scipy.stats import dweibull dst = dweibull(c=2.9, loc=15e-6, scale=8e-6)
fig, ax = plt.subplots() ax.hist(dst.rvs(10000)1e6, bins=50, edgecolor='k') ax.tick_params(axis='x', labelrotation=45) pn['pore.diameter'] = dst.rvs(pn.Np) fig, ax = plt.subplots() ax.hist(pn['pore.diameter']1e6, edgecolor='k') ax.tick_params(axis='x', labelrotation=45) ax.set_xlabel('Pore Diameter [um]'); f = op.models.geometry.pore_seed.random pn.add_model(propname='pore.seed', model=f, num_range=[0.0, 0.98]) pn.add_model(propname='pore.diameter', model=op.models.geometry.pore_size.generic_distribution, func=dst, seeds='pore.seed') pn.regenerate_models() fig, ax = plt.subplots() ax.hist(pn['pore.diameter'], edgecolor='k') ax.tick_params(axis='x', labelrotation=45); pn.add_model(propname='throat.diameter_1', model=op.models.misc.from_neighbor_pores, prop='pore.diameter', mode='min') pn.add_model(propname='throat.seed', model=op.models.misc.from_neighbor_pores, prop='pore.seed', mode='min') pn.add_model(propname='throat.diameter_2', model=op.models.geometry.throat_size.generic_distribution, func=dst) pn.add_model(propname='throat.diameter', model=op.models.misc.scaled, prop='throat.diameter_2', # This could also be 'throat.diameter_2' factor=0.6, # This could be 1.0 if no scaling is desired ) fig, ax = plt.subplots() ax.hist(pn['pore.diameter']1e6, edgecolor='k', density=True, alpha=0.5, label='pores') ax.hist(pn['throat.diameter']1e6, edgecolor='k', density=True, alpha=0.5, label='throats') ax.tick_params(axis='x', labelrotation=45) ax.legend() ax.set_xlabel('Pore diameter [um]'); pn.add_model(propname='pore.volume', model=op.models.geometry.pore_volume.sphere) pn.add_model(propname='throat.length', model=op.models.geometry.throat_length.spheres_and_cylinders) pn.add_model(propname='throat.total_volume', model=op.models.geometry.throat_volume.cylinder) pn.add_model(propname='throat.lens_volume', model=op.models.geometry.throat_volume.lens) pn.add_model(propname='throat.volume', model=op.models.misc.difference, props=['throat.total_volume', 'throat.lens_volume']) hg = op.phase.Mercury(network=pn) hg.add_model(propname='throat.entry_pressure', model=op.models.physics.capillary_pressure.washburn) hg.regenerate_models() mip = op.algorithms.Drainage(network=pn, phase=hg) mip.set_inlet_BC(pores=pn.pores('surface')) mip.run() pc_sim = mip.pc_curve() fig, ax = plt.subplots() ax.semilogx(pc_sim, 'b-', label='simulation') ax.semilogx(df['Pc [Pa]'], df['S_Hg'], 'r.', label='experiment') ax.legend(); pn.models['throat.diameter@all']['factor'] = 0.5 pn.regenerate_models() hg.regenerate_models() mip = op.algorithms.Drainage(network=pn, phase=hg) mip.set_inlet_BC(pores=pn.pores('surface')) mip.run() pc_sim = mip.pc_curve() fig, ax = plt.subplots() ax.semilogx(pc_sim, 'b-', label='simulation') ax.semilogx(df['Pc [Pa]'], df['S_Hg'], 'r.', label='experiment') ax.legend(); water = op.phase.Phase(network=pn) water.add_model(propname='pore.viscosity', model=op.models.phase.viscosity.water_correlation) print(water) R = pn['throat.diameter']/2 L = pn['throat.length'] mu = water['throat.viscosity'] # See ProTip below water['throat.hydraulic_conductance'] = np.pi*R*4/(8muL) print(water['throat.hydraulic_conductance']) gas = op.phase.Phase(network=pn) gas['pore.diffusivity'] = 1.0 gas['pore.viscosity'] = 1.0 gas.add_model_collection(op.models.collections.physics.basic) gas.regenerate_models() sf = op.algorithms.StokesFlow(network=pn, phase=gas) sf.set_value_BC(pores=pn.pores('xmin'), values=1.0) sf.set_value_BC(pores=pn.pores('xmax'), values=0.0) sf.run() dP = 1.0 L = (4 + 6)1 A = 441 K = sf.rate(pores=pn.pores('xmin'))(L/A)/dP1e12 print(f'Permeability coefficient is {K[0]} Darcy') 在spyder上运行提示KeyError: 'throat.hydraulic_conductance',无法得出渗透系数
import numpy as np import openpnm as op import pandas as pd import matplotlib.pyplot as plt import scipy.stats as spst
op.visualization.set_mpl_style() np.random.seed(10) ws = op.Workspace() ws.settings["loglevel"] = 40 np.set_printoptions(precision=5) df = pd.read_csv('Sandstone.csv') print(df) df['R'] = -20.480np.cos(np.deg2rad(140))/df['Pc [Pa]'] fig, ax = plt.subplots() ax.semilogx(2df['R']1e6, df['S_Hg'], 'b.') ax.set_xlabel('Pore Diameter [um]'); pn = op.network.Cubic(shape=[4, 4, 4], connectivity=26) np.random.seed(0) drop = np.random.randint(0, pn.Nt, 500) op.topotools.trim(network=pn, throats=drop) ax = op.visualization.plot_coordinates(pn) ax = op.visualization.plot_connections(pn, ax=ax) np.random.seed(0) # Set the state of the random number generator to "0" pn['pore.seed'] = np.random.rand(pn.Np) from scipy.stats import dweibull dst = dweibull(c=2.9, loc=15e-6, scale=8e-6)
fig, ax = plt.subplots() ax.hist(dst.rvs(10000)1e6, bins=50, edgecolor='k') ax.tick_params(axis='x', labelrotation=45) pn['pore.diameter'] = dst.rvs(pn.Np) fig, ax = plt.subplots() ax.hist(pn['pore.diameter']1e6, edgecolor='k') ax.tick_params(axis='x', labelrotation=45) ax.set_xlabel('Pore Diameter [um]'); f = op.models.geometry.pore_seed.random pn.add_model(propname='pore.seed', model=f, num_range=[0.0, 0.98]) pn.add_model(propname='pore.diameter', model=op.models.geometry.pore_size.generic_distribution, func=dst, seeds='pore.seed') pn.regenerate_models() fig, ax = plt.subplots() ax.hist(pn['pore.diameter'], edgecolor='k') ax.tick_params(axis='x', labelrotation=45); pn.add_model(propname='throat.diameter_1', model=op.models.misc.from_neighbor_pores, prop='pore.diameter', mode='min') pn.add_model(propname='throat.seed', model=op.models.misc.from_neighbor_pores, prop='pore.seed', mode='min') pn.add_model(propname='throat.diameter_2', model=op.models.geometry.throat_size.generic_distribution, func=dst) pn.add_model(propname='throat.diameter', model=op.models.misc.scaled, prop='throat.diameter_2', # This could also be 'throat.diameter_2' factor=0.6, # This could be 1.0 if no scaling is desired ) fig, ax = plt.subplots() ax.hist(pn['pore.diameter']1e6, edgecolor='k', density=True, alpha=0.5, label='pores') ax.hist(pn['throat.diameter']1e6, edgecolor='k', density=True, alpha=0.5, label='throats') ax.tick_params(axis='x', labelrotation=45) ax.legend() ax.set_xlabel('Pore diameter [um]'); pn.add_model(propname='pore.volume', model=op.models.geometry.pore_volume.sphere) pn.add_model(propname='throat.length', model=op.models.geometry.throat_length.spheres_and_cylinders) pn.add_model(propname='throat.total_volume', model=op.models.geometry.throat_volume.cylinder) pn.add_model(propname='throat.lens_volume', model=op.models.geometry.throat_volume.lens) pn.add_model(propname='throat.volume', model=op.models.misc.difference, props=['throat.total_volume', 'throat.lens_volume']) hg = op.phase.Mercury(network=pn) hg.add_model(propname='throat.entry_pressure', model=op.models.physics.capillary_pressure.washburn) hg.regenerate_models() mip = op.algorithms.Drainage(network=pn, phase=hg) mip.set_inlet_BC(pores=pn.pores('surface')) mip.run() pc_sim = mip.pc_curve() fig, ax = plt.subplots() ax.semilogx(pc_sim, 'b-', label='simulation') ax.semilogx(df['Pc [Pa]'], df['S_Hg'], 'r.', label='experiment') ax.legend(); pn.models['throat.diameter@all']['factor'] = 0.5 pn.regenerate_models() hg.regenerate_models() mip = op.algorithms.Drainage(network=pn, phase=hg) mip.set_inlet_BC(pores=pn.pores('surface')) mip.run() pc_sim = mip.pc_curve() fig, ax = plt.subplots() ax.semilogx(pc_sim, 'b-', label='simulation') ax.semilogx(df['Pc [Pa]'], df['S_Hg'], 'r.', label='experiment') ax.legend(); water = op.phase.Phase(network=pn) water.add_model(propname='pore.viscosity', model=op.models.phase.viscosity.water_correlation) print(water) R = pn['throat.diameter']/2 L = pn['throat.length'] mu = water['throat.viscosity'] # See ProTip below water['throat.hydraulic_conductance'] = np.pi*R*4/(8muL) print(water['throat.hydraulic_conductance']) gas = op.phase.Phase(network=pn) gas['pore.diffusivity'] = 1.0 gas['pore.viscosity'] = 1.0 gas.add_model_collection(op.models.collections.physics.basic) gas.regenerate_models() sf = op.algorithms.StokesFlow(network=pn, phase=gas) sf.set_value_BC(pores=pn.pores('xmin'), values=1.0) sf.set_value_BC(pores=pn.pores('xmax'), values=0.0) sf.run() dP = 1.0 L = (4 + 6)1 A = 441 K = sf.rate(pores=pn.pores('xmin'))(L/A)/dP1e12 print(f'Permeability coefficient is {K[0]} Darcy') 在spyder上运行提示KeyError: 'throat.hydraulic_conductance',无法得出渗透系数