<s> import numpy as np <EOL> import scipy as sp <EOL> import OpenPNM <EOL> import pytest <EOL> def test_linear_solvers ( ) : <EOL> pn = OpenPNM . Network . Cubic ( [ <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:30> ] , spacing = <NUM_LIT> ) <EOL> geom = OpenPNM . Geometry . Toray090 ( network = pn , <EOL> pores = pn . pores ( ) , <EOL> throats = pn . throats ( ) ) <EOL> air = OpenPNM . Phases . Air ( network = pn ) <EOL> phys_air = OpenPNM . Physics . Standard ( network = pn , <EOL> phase = air , <EOL> pores = pn . pores ( ) , <EOL> throats = pn . throats ( ) ) <EOL> BC1_pores = pn . pores ( labels = [ '<STR_LIT:left>' ] ) <EOL> BC2_pores = pn . pores ( labels = [ '<STR_LIT:right>' ] ) <EOL> alg_1 = OpenPNM . Algorithms . FickianDiffusion ( network = pn , phase = air ) <EOL> alg_1 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = <NUM_LIT:1> , <EOL> pores = BC1_pores ) <EOL> alg_1 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = <NUM_LIT:0> , <EOL> pores = BC2_pores ) <EOL> alg_1 . run ( iterative_solver = '<STR_LIT>' ) <EOL> alg_2 = OpenPNM . Algorithms . FickianDiffusion ( network = pn , phase = air ) <EOL> alg_2 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = - <NUM_LIT> , <EOL> pores = BC1_pores ) <EOL> alg_2 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = <NUM_LIT:0> , <EOL> pores = BC2_pores ) <EOL> alg_2 . run ( iterative_solver = '<STR_LIT>' ) <EOL> alg_3 = OpenPNM . Algorithms . FickianDiffusion ( network = pn , phase = air ) <EOL> alg_3 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = - <NUM_LIT> , <EOL> pores = BC1_pores ) <EOL> alg_3 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = <NUM_LIT:0> , <EOL> pores = BC2_pores ) <EOL> alg_3 . run ( ) <EOL> alg_4 = OpenPNM . Algorithms . FickianDiffusion ( network = pn , phase = air ) <EOL> alg_4 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = - <NUM_LIT> , <EOL> pores = BC1_pores ) <EOL> alg_4 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = <NUM_LIT:0> , <EOL> pores = BC2_pores ) <EOL> alg_4 . setup ( ) <EOL> alg_4 . solve ( ) <EOL> assert round ( sp . absolute ( alg_1 . rate ( BC1_pores ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) == round ( sp . absolute ( alg_1 . rate ( BC2_pores ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> assert round ( sp . absolute ( alg_2 . rate ( BC2_pores ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) == round ( sp . absolute ( sp . unique ( alg_2 [ '<STR_LIT>' ] ) ) [ <NUM_LIT:0> ] * <EOL> len ( BC1_pores ) , <NUM_LIT:16> ) <EOL> assert round ( sp . absolute ( alg_3 . rate ( BC2_pores ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) == round ( sp . absolute ( sp . unique ( alg_3 [ '<STR_LIT>' ] ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> assert round ( sp . absolute ( alg_4 . rate ( BC2_pores ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) == round ( sp . absolute ( sp . unique ( alg_4 [ '<STR_LIT>' ] ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> assert round ( sp . absolute ( sp . sum ( alg_1 . rate ( BC1_pores , mode = '<STR_LIT>' ) ) ) , <NUM_LIT:16> ) == round ( sp . absolute ( alg_1 . rate ( BC1_pores ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> assert round ( sp . absolute ( sp . sum ( alg_2 . rate ( BC2_pores , mode = '<STR_LIT>' ) ) ) , <NUM_LIT:16> ) == round ( sp . absolute ( alg_2 . rate ( BC2_pores ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> assert round ( sp . absolute ( sp . sum ( alg_3 . rate ( BC2_pores , mode = '<STR_LIT>' ) ) ) , <NUM_LIT:16> ) == round ( sp . absolute ( alg_3 . rate ( BC2_pores ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> assert round ( sp . absolute ( sp . sum ( alg_4 . rate ( BC2_pores , mode = '<STR_LIT>' ) ) ) , <NUM_LIT:16> ) == round ( sp . absolute ( alg_4 . rate ( BC2_pores ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> def test_add_boundary ( ) : <EOL> pn = OpenPNM . Network . Cubic ( shape = [ <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ] ) <EOL> pn . add_boundaries ( ) <EOL> keys_expected = { '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' } <EOL> keys_found = set ( pn . keys ( ) ) <EOL> symmetric_diff = keys_found ^ keys_expected <EOL> assert not symmetric_diff <EOL> def test_open_air_diffusivity ( ) : <EOL> pn = OpenPNM . Network . Cubic ( [ <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ] , spacing = <NUM_LIT:1> ) <EOL> pn . add_boundaries ( ) <EOL> Ps = pn . pores ( '<STR_LIT>' , mode = '<STR_LIT>' ) <EOL> Ts = pn . find_neighbor_throats ( pores = Ps , mode = '<STR_LIT>' , flatten = True ) <EOL> geom = OpenPNM . Geometry . Cube_and_Cuboid ( network = pn , pores = Ps , throats = Ts ) <EOL> geom [ '<STR_LIT>' ] = <NUM_LIT> <EOL> geom [ '<STR_LIT>' ] = <NUM_LIT> <EOL> geom . regenerate ( [ '<STR_LIT>' , '<STR_LIT>' ] , mode = '<STR_LIT>' ) <EOL> Ps = pn . pores ( '<STR_LIT>' ) <EOL> Ts = pn . find_neighbor_throats ( pores = Ps , mode = '<STR_LIT>' ) <EOL> boun = OpenPNM . Geometry . Boundary ( network = pn , <EOL> pores = Ps , <EOL> throats = Ts , <EOL> shape = '<STR_LIT>' ) <EOL> air = OpenPNM . Phases . Air ( network = pn ) <EOL> Ps = pn . pores ( ) <EOL> Ts = pn . throats ( ) <EOL> phys_air = OpenPNM . Physics . Standard ( network = pn , <EOL> phase = air , <EOL> pores = Ps , <EOL> throats = Ts ) <EOL> BC1_pores = pn . pores ( labels = [ '<STR_LIT>' ] ) <EOL> BC2_pores = pn . pores ( labels = [ '<STR_LIT>' ] ) <EOL> Diff = OpenPNM . Algorithms . FickianDiffusion ( network = pn , <EOL> phase = air ) <EOL> Diff . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = <NUM_LIT> , <EOL> pores = BC1_pores ) <EOL> Diff . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = <NUM_LIT> , <EOL> pores = BC2_pores ) <EOL> Diff . run ( ) <EOL> Diff . return_results ( ) <EOL> Diff_deff = Diff . calc_eff_diffusivity ( ) / np . mean ( air [ '<STR_LIT>' ] ) <EOL> assert np . round ( Diff_deff , <NUM_LIT:3> ) == <NUM_LIT:1> <EOL> def test_thermal_conduction ( ) : <EOL> divs = [ <NUM_LIT:10> , <NUM_LIT:50> ] <EOL> Lc = <NUM_LIT:0.1> <EOL> pn = OpenPNM . Network . Cubic ( shape = divs , spacing = Lc ) <EOL> pn . add_boundaries ( ) <EOL> pn . trim ( pores = pn . pores ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> Ps = pn . pores ( '<STR_LIT>' ) <EOL> Ts = pn . throats ( ) <EOL> geom = OpenPNM . Geometry . GenericGeometry ( network = pn , <EOL> pores = Ps , <EOL> throats = Ts ) <EOL> geom [ '<STR_LIT>' ] = Lc ** <NUM_LIT:2> <EOL> geom [ '<STR_LIT>' ] = Lc <EOL> geom [ '<STR_LIT>' ] = <NUM_LIT> <EOL> geom [ '<STR_LIT>' ] = Lc ** <NUM_LIT:2> <EOL> Ps = pn . pores ( '<STR_LIT>' ) <EOL> boun = OpenPNM . Geometry . GenericGeometry ( network = pn , pores = Ps ) <EOL> boun [ '<STR_LIT>' ] = Lc ** <NUM_LIT:2> <EOL> boun [ '<STR_LIT>' ] = <NUM_LIT> <EOL> Cu = OpenPNM . Phases . GenericPhase ( network = pn ) <EOL> Cu [ '<STR_LIT>' ] = <NUM_LIT:1.0> <EOL> phys = OpenPNM . Physics . GenericPhysics ( network = pn , <EOL> phase = Cu , <EOL> pores = pn . pores ( ) , <EOL> throats = pn . throats ( ) ) <EOL> mod = OpenPNM . Physics . models . thermal_conductance . series_resistors <EOL> phys . add_model ( propname = '<STR_LIT>' , model = mod ) <EOL> phys . regenerate ( ) <EOL> Fourier_alg = OpenPNM . Algorithms . FourierConduction ( network = pn , phase = Cu ) <EOL> inlets = pn . pores ( '<STR_LIT>' ) <EOL> outlets = pn . pores ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> T_in = <NUM_LIT:30> * sp . sin ( sp . pi * pn [ '<STR_LIT>' ] [ inlets , <NUM_LIT:1> ] / <NUM_LIT:5> ) + <NUM_LIT:50> <EOL> Fourier_alg . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = T_in , <EOL> pores = inlets ) <EOL> Fourier_alg . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = <NUM_LIT:50> , <EOL> pores = outlets ) <EOL> Fourier_alg . run ( ) <EOL> Fourier_alg . return_results ( ) <EOL> Cu [ '<STR_LIT>' ] = <NUM_LIT:30> * sp . sinh ( sp . pi * pn [ '<STR_LIT>' ] [ : , <NUM_LIT:0> ] / <NUM_LIT:5> ) / sp . sinh ( sp . pi / <NUM_LIT:5> ) * sp . sin ( sp . pi * pn [ '<STR_LIT>' ] [ : , <NUM_LIT:1> ] / <NUM_LIT:5> ) + <NUM_LIT:50> <EOL> b = Cu [ '<STR_LIT>' ] [ pn . pores ( geom . name ) ] <EOL> a = Cu [ '<STR_LIT>' ] [ pn . pores ( geom . name ) ] <EOL> a = sp . reshape ( a , ( divs [ <NUM_LIT:0> ] , divs [ <NUM_LIT:1> ] ) ) <EOL> b = sp . reshape ( b , ( divs [ <NUM_LIT:0> ] , divs [ <NUM_LIT:1> ] ) ) <EOL> diff = a - b <EOL> assert sp . amax ( np . absolute ( diff ) ) < <NUM_LIT> <EOL> def test_Darcy_alg ( ) : <EOL> divs = [ <NUM_LIT:1> , <NUM_LIT:50> , <NUM_LIT:10> ] <EOL> Lc = <NUM_LIT> <EOL> pn = OpenPNM . Network . Cubic ( shape = divs , spacing = Lc ) <EOL> pn . add_boundaries ( ) <EOL> Ps = pn . pores ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> pn . trim ( pores = Ps ) <EOL> Ps = pn . pores ( '<STR_LIT>' , mode = '<STR_LIT>' ) <EOL> Ts = pn . find_neighbor_throats ( pores = Ps , mode = '<STR_LIT>' , flatten = True ) <EOL> geom = OpenPNM . Geometry . Toray090 ( network = pn , pores = Ps , throats = Ts ) <EOL> Ps = pn . pores ( '<STR_LIT>' ) <EOL> Ts = pn . find_neighbor_throats ( pores = Ps , mode = '<STR_LIT>' ) <EOL> boun = OpenPNM . Geometry . Boundary ( network = pn , pores = Ps , throats = Ts ) <EOL> air = OpenPNM . Phases . Air ( network = pn ) <EOL> Ps = pn . pores ( ) <EOL> Ts = pn . throats ( ) <EOL> phys = OpenPNM . Physics . GenericPhysics ( network = pn , <EOL> phase = air , <EOL> pores = Ps , <EOL> throats = Ts ) <EOL> from OpenPNM . Physics import models as pm <EOL> phys . add_model ( propname = '<STR_LIT>' , <EOL> model = pm . hydraulic_conductance . hagen_poiseuille , <EOL> calc_pore_len = False ) <EOL> phys . regenerate ( ) <EOL> Darcy1 = OpenPNM . Algorithms . StokesFlow ( network = pn , phase = air ) <EOL> inlets = pn . pores ( '<STR_LIT>' ) <EOL> Ps = pn . pores ( '<STR_LIT>' ) <EOL> outlets = Ps [ pn [ '<STR_LIT>' ] [ Ps , <NUM_LIT:1> ] < ( divs [ <NUM_LIT:1> ] * Lc / <NUM_LIT:2> ) ] <EOL> P_out = <NUM_LIT:0> <EOL> Q_in = <NUM_LIT> * ( Lc ** <NUM_LIT:2> ) * divs [ <NUM_LIT:1> ] * divs [ <NUM_LIT:0> ] <EOL> Darcy1 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = - Q_in , <EOL> pores = inlets ) <EOL> Darcy1 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = P_out , <EOL> pores = outlets ) <EOL> Darcy1 . run ( ) <EOL> Darcy1 . return_results ( ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( air [ '<STR_LIT>' ] ) <EOL> Darcy2 = OpenPNM . Algorithms . StokesFlow ( network = pn , phase = air ) <EOL> inlets = pn . pores ( '<STR_LIT>' ) <EOL> outlets = pn . pores ( '<STR_LIT>' ) <EOL> P_out = <NUM_LIT:10> <EOL> P_in = <NUM_LIT:1000> <EOL> Darcy2 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = P_in , <EOL> pores = inlets ) <EOL> Darcy2 . set_boundary_conditions ( bctype = '<STR_LIT>' , <EOL> bcvalue = P_out , <EOL> pores = outlets ) <EOL> Darcy2 . run ( ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( Darcy2 [ '<STR_LIT>' ] ) <EOL> Q = - Darcy2 . rate ( inlets ) <EOL> K = Q * air [ '<STR_LIT>' ] [ <NUM_LIT:0> ] * divs [ <NUM_LIT:2> ] * Lc / ( divs [ <NUM_LIT:0> ] * divs [ <NUM_LIT:1> ] * Lc ** <NUM_LIT:2> * ( P_in - P_out ) ) <EOL> Vp = sp . sum ( pn [ '<STR_LIT>' ] ) + sp . sum ( pn [ '<STR_LIT>' ] ) <EOL> Vb = sp . prod ( divs ) * Lc ** <NUM_LIT:3> <EOL> e = Vp / Vb <EOL> print ( '<STR_LIT>' , K , '<STR_LIT>' , e ) <EOL> a = round ( sp . absolute ( Darcy1 . rate ( outlets ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> pore_prop = '<STR_LIT>' <EOL> b = round ( sp . absolute ( sp . unique ( Darcy1 [ pore_prop ] ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> assert a == b <EOL> a = round ( sp . absolute ( Darcy2 . rate ( inlets ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> b = round ( sp . absolute ( Darcy2 . rate ( outlets ) ) [ <NUM_LIT:0> ] , <NUM_LIT:16> ) <EOL> assert a == b </s>
