Column Transport Guide
The Column class solves the 1D advection-diffusion-reaction equation in porous media, combining spatial transport with chemical reactions.
Creating a Column
from porousmedialab.column import Column
column = Column(length=25, dx=0.2, tend=1, dt=0.001, w=0.2)
Parameters:
length(float): Domain length (e.g., sediment depth in cm)dx(float): Grid spacing (mesh size)tstart(float): Start time of simulation (default0)tend(float): End time of simulationdt(float): Timestepw(float): Default advection velocity (burial rate)ode_method(str): Reaction solver. Options are'scipy'(default),'scipy_sequential','rk4'and'butcher5'.numexpr_threads(int): Optional process-wide numexpr thread count. Applies to'rk4','butcher5'and their rate reconstruction.splitting(str):'lie'(default) or'strang'. Strang splitting gives second-order coupling of transport and kinetics. Equilibrium updates still use first-order splitting.rtol,atol(float): Relative and absolute tolerances for the SciPy solvers. Defaults are1e-3and1e-6. Absolute tolerance is in concentration units.scipy_method(str): Integrator forode_method='scipy'. Options are'LSODA'(default),'BDF','Radau','RK45','RK23'and'DOP853'.'scipy_sequential'supports only'LSODA'.non_negative_rates(bool):True(default) sets negative rates to zero. Set it toFalseto keep both signs. See Solver settings for tolerance limits and how to preserve mass when the dissolving phase is depleted.
Adding Species
column.add_species(
theta=0.9, # Porosity or 1-porosity
name='O2', # Species name
D=368, # Diffusion coefficient
init_conc=0, # Initial concentration (scalar or array)
bc_top_value=0.231, # Top boundary value
bc_top_type='dirichlet',# Top boundary type
bc_bot_value=0, # Bottom boundary value
bc_bot_type='flux', # Bottom boundary type
w=None, # Species-specific advection (optional)
int_transport=True, # Integrate transport
allow_negative=False # Apply the non-negative concentration floor
)
Parameters:
theta(float or array): Porosity for dissolved species, (1-porosity) for solidsname(str): Species identifierD(float): Effective diffusion coefficientinit_conc(float or array): Initial concentration profilebc_top_value,bc_bot_value: Boundary valuesbc_top_type,bc_bot_type: See the boundary types below.w(float): Species-specific advection velocity (uses column default if not set)int_transport(bool):Truefor species with transport,Falsefor immobile speciesallow_negative(bool): Set toTrueto skip the concentration floor for signed variables. The default isFalse.Temperaturecan go negative automatically.
Boundary Conditions
Depth x and velocity w are positive downward. Flux values are measured per
unit bulk area and are positive into the column at either end, downward at the
top and upward at the bottom. In the table, g is the prescribed boundary value.
| Type strings (case-insensitive) | Top | Bottom | Typical use |
|---|---|---|---|
'dirichlet', 'constant' |
C = g |
C = g |
Known concentration |
'neumann', 'flux' |
-theta*D*dC/dx = g |
+theta*D*dC/dx = g |
Zero-gradient outflow or burial |
'danckwerts', 'total_flux' |
-theta*D*dC/dx + theta*w*C = g |
+theta*D*dC/dx - theta*w*C = g |
Deposition, an inlet feed, or a closed boundary |
Advection carries the boundary concentration through a Neumann boundary. A value of zero gives a zero gradient. A Danckwerts boundary includes both diffusion and advection in the prescribed flux and closes at a value of zero. Without advection, the two flux conditions give the same result.
For a feed with concentration C_in and downward velocity w, prescribe
theta*w*C_in at a Danckwerts top boundary. Use zero Neumann flux at the
bottom for a free outlet. A deposition flux also uses 'danckwerts'.
Use 'danckwerts' for inlets. With a 'flux' or 'neumann' inlet
(top w > 0 or bottom w < 0) and a Dirichlet or closed outlet,
concentrations can grow spuriously at cell Péclet numbers
Pe = |w|*dx/D > 2. For uniform porosity, the inlet diagonal
contribution s_b*(1 - Pe/2) becomes negative and anti-diffusive,
where s_b = theta*D*dt/dx**2.
Dissolved vs. Solid Species
Dissolved oxygen above uses the porosity phi for its phase fraction.
Solid organic matter uses 1 - phi.
phi = 0.9
column.add_species(
theta=1-phi,
name='OM',
D=20,
init_conc=10,
bc_top_value=100,
bc_top_type='danckwerts',
bc_bot_value=0,
bc_bot_type='flux'
)
Solids typically have:
- Lower diffusion (bioturbation/mixing): D ≈ 10-50 cm²/yr
- Danckwerts boundary at the top (prescribed deposition)
- Zero diffusive flux at the bottom (solids leave by burial)
Defining Reactions
Same as batch - use constants, rates, and dcdt:
column.constants['k'] = 0.5
column.rates['R1'] = 'k * OM * O2'
column.dcdt['OM'] = '-R1'
column.dcdt['O2'] = '-R1'
Equilibrium in a column
Register an aqueous and a gas species, then call
column.add_partition_equilibrium(aq, gas, Hcc) with their names and the
dimensionless ratio Hcc = C_aq / C_gas. Partitioning conserves
theta_aq * C_aq + theta_gas * C_gas using each species’ own theta.
henry_equilibrium is an alias. For acid-base equilibrium, follow the
Batch Guide.
Running the Simulation
column.solve(verbose=True)
Accessing Results
# Concentration array: shape (N, num_timesteps)
# N = number of spatial points
conc = column.O2.concentration
# Depth array
x = column.x
# Time array
time = column.time
# Get profile at specific time index
profile_at_t10 = column.O2.concentration[:, 10]
# Get time series at specific depth index
timeseries_at_d5 = column.O2.concentration[5, :]
Plotting Methods
# Final concentration profiles for all species
column.plot_profiles()
# Single species profile
column.plot_profile('O2')
# Contour plot (depth vs time)
column.contour_plot('O2')
# Contour plots for all species
column.plot_contourplots()
# Time series at specific depths
column.plot_depths('O2', [1, 5, 10]) # Depths in cm
# Profiles at specific times
column.plot_times('O2', [0.1, 0.5, 1.0]) # Times
# Contour plots of reaction rates
column.reconstruct_rates()
column.plot_contourplots_of_rates()
The SciPy solvers leave estimated_rates at zero during the solve.
reconstruct_rates() evaluates the reaction rates from the stored concentrations.
Flux Estimation
estimate_flux_at_top and estimate_flux_at_bottom return the diffusive plus
advective flux J = theta*(-D*dC/dx + w*C) at the boundary node, signed
positive out of the column: -J at the top (upward) and J at the bottom
(downward). Inflow is negative. theta and w are the values at the boundary
node. The unit is concentration × length / time per unit bulk area.
# Flux at top boundary over time
flux_top = column.estimate_flux_at_top('O2')
# Flux at bottom boundary
flux_bot = column.estimate_flux_at_bottom('O2')
# With specific time indices
flux_top_subset = column.estimate_flux_at_top('O2', idx=slice(0, 100))
# Last stored time only (returns one value)
flux_top_last = column.estimate_flux_at_top('O2', idx=-1)
# Lower order derivative (default is 4)
flux_top = column.estimate_flux_at_top('O2', order=2)
The derivative is a one-sided difference over the order + 1 nodes next to
the boundary (order 1 to 4, default 4), so the grid needs at least
order + 1 nodes. It assumes that the profile and theta are smooth across
these nodes. A porosity step between two of them, or a front thinner than
about three cells, can bias every order by tens of percent. Reduce dx until
such features lie outside the stencil.
The estimate uses the stored profile, which is the state after reactions and
equilibrium. In a column with reactions or equilibrium it can differ from the
flux that the transport step moved across the boundary, and it need not be
zero at a zero-flux boundary. With kinetic reactions the difference is
proportional to dt/dx, so reduce the time step together with dx.
Saving and Loading Profiles
Save final profiles for restart:
column.save_final_profiles()
# Creates CSV files: O2.csv, OM.csv, etc.
Profiles can also be written to a specific directory:
column.save_final_profiles(directory='restart_profiles')
Load profiles as initial conditions:
column.load_initial_conditions()
# Loads from CSV files in current directory
To load from a directory:
column.load_initial_conditions(directory='restart_profiles')
Changing Boundary Conditions
In a custom time loop, pass the time index at which the boundary changes.
The method is quiet by default. Set verbose=True to print the species
and time of the change.
column.change_boundary_conditions(
element='O2',
i=1, # Time index for this example
bc_top_value=0.1,
bc_top_type='dirichlet',
bc_bot_value=0,
bc_bot_type='flux',
verbose=True
)
Complete Example
from porousmedialab.column import Column
# Create sediment column
w = 0.2 # Burial rate (cm/yr)
L = 25 # Depth (cm)
dx = 0.2 # Grid spacing (cm)
t = 1 # Simulation time (years)
dt = 1e-3 # Timestep (years)
phi = 0.9 # Porosity
sediment = Column(L, dx, t, dt, w)
# Add dissolved oxygen
sediment.add_species(
theta=phi,
name='O2',
D=368, # Molecular diffusion
init_conc=0,
bc_top_value=0.231, # Saturation concentration
bc_top_type='dirichlet',
bc_bot_value=0,
bc_bot_type='flux'
)
# Add organic matter (solid)
sediment.add_species(
theta=1-phi,
name='OM',
D=20, # Bioturbation
init_conc=10,
bc_top_value=100, # Total deposition flux
bc_top_type='danckwerts',
bc_bot_value=0,
bc_bot_type='flux'
)
# Add CO2 product
sediment.add_species(
theta=phi,
name='CO2',
D=368,
init_conc=0,
bc_top_value=0,
bc_top_type='dirichlet',
bc_bot_value=0,
bc_bot_type='flux'
)
# Define reaction
sediment.constants['k'] = 1.0
sediment.constants['Km'] = 0.02
sediment.rates['R_ox'] = 'k * OM * O2 / (Km + O2)'
sediment.dcdt['O2'] = '-R_ox'
sediment.dcdt['OM'] = '-R_ox'
sediment.dcdt['CO2'] = 'R_ox'
# Run simulation
sediment.solve()
# Visualize
sediment.plot_profiles()
sediment.contour_plot('O2')
For a larger reaction network, see the sediment diagenesis tutorial.
Transport with time-dependent water flow
Solve a Richards model on column.time and map it onto the transport grid.
Add each species with a standard boundary kind, then bind the aqueous species
that follow the flow. Richards mapping example
flow = model.to_column(column)
column.set_water_flow(flow, species='Cl', advection='upwind')
column.change_boundary_conditions('Cl', 0, 1.0, 'inflow_concentration',
0.0, 'inflow_concentration')
column.solve(verbose=False)
amount = column.inventory('Cl')
exchange = column.boundary_flux('Cl')
For each bound species, the transport step uses the downward Darcy flux q,
the volumetric water content theta for face diffusion, and the total water
storage for solute capacity. Total storage includes elastic storage. It
also weights the areal inventory and the aqueous side of Henry partitioning.
Gas phases keep their constant species theta. Select the aqueous forms of
an acid-base component together.
In the table, Q_in is the inward Darcy flux, q at the top and -q at
the bottom. Boundary exchange is per unit bulk area.
| Boundary kind | Boundary value | Behaviour with water flow |
|---|---|---|
dirichlet, constant |
Concentration | Pin the boundary node to the specified concentration during transport. |
neumann, flux |
Inward diffusive flux | Add advective exchange using the boundary concentration. Use zero diffusive flux for liquid outflow, including liquid exfiltration at the top. |
danckwerts, total_flux |
Inward total flux | Set the sum of advective and diffusive fluxes. A value of zero closes the boundary to solute. |
inflow_concentration |
Concentration of incoming water | At either end, inflow brings Q_in * g for concentration g. Top evaporation retains solute. Bottom drainage exports solute at the boundary concentration. |
A spatially uniform tracer stays uniform when the water-flow balance closes and
the boundary data admit that concentration. For a uniform concentration c,
use c at a Dirichlet boundary, zero Neumann flux, Q_in * c at a Danckwerts
boundary, or c for inflow. Evaporation at an inflow_concentration top
concentrates the remaining solute.
Central advection is the default. Choose advection='upwind' for
advection-dominated flow, and reduce the time step if the Courant number
is high. Check realised amounts with boundary_flux. Set rate=True
to divide by the actual width of each interval. The estimate_flux_*
methods require the constant-flow transport path.
Bind or replace the flow before the first step or after reset(). The column
takes a read-only copy of the input. To detach, first change any
inflow_concentration boundaries to standard kinds and call
column.set_water_flow(None, species='Cl') to release all bound species.
Tips
- Transport stability. Crank-Nicolson is stable at any
dtfor pure diffusion.TransportStabilityWarningreports loss of implicit positivity or an anti-diffusive boundary row. With uniform porosity, a face Péclet number|w|*dx/D > 2can cause oscillations and negative concentrations. The warning identifies non-positive implicit boundary diagonals.desolver.transport_diagnostics(...)reports face and boundary Péclet numbers, the Courant number and the effective Fourier number. - Grid resolution.
Columnuses a uniform grid. Choosedxsmall enough to put several nodes across the steepest front, such as the oxygen penetration depth. - Solver selection: Use
ode_method='scipy'(default) for best performance - Units: Common choices:
- Length: cm
- Time: years or days
- Concentration: mol/L or µmol/cm³
- Diffusion: cm²/time_unit
- Debugging: Check
column.xto verify grid setup