Continuous biogas plants#
Mixed-feed CSTR, gas inventory and CHP simulation; see docs/biogas_plants.md.
The first-order substrate pools are a reduced-order approximation, not ADM1. Temperature is maintained by recovered heat and unlimited electric backup heat. Gas dispatch uses each interval’s average production; use short operating intervals.
- class x2power.methods.biogas_plant.DigesterFeedstock(name, wet_mass_kg_per_day, total_solids_fraction, volatile_solids_fraction_ts, biodegradable_vs_fraction, methane_yield_nm3_per_kg_vs_destroyed, decay_rate_per_day, density_kg_per_m3=1000.0, dry_lhv_mj_per_kg=18.0)[source]#
Continuous wet feed; methane yield is per kg of degradable VS destroyed.
total_solids_fractionis wet basis;volatile_solids_fraction_tsis relative to total solids.biodegradable_vs_fractionpartitions incoming VS into degradable and inert pools. Rate constants apply at the declared digester temperature and require calibration. Gas volumes are dry at 0 C, 101325 Pa.- Parameters:
name (str)
wet_mass_kg_per_day (float)
total_solids_fraction (float)
volatile_solids_fraction_ts (float)
biodegradable_vs_fraction (float)
methane_yield_nm3_per_kg_vs_destroyed (float)
decay_rate_per_day (float)
density_kg_per_m3 (float)
dry_lhv_mj_per_kg (float)
- name: str#
- wet_mass_kg_per_day: float#
- total_solids_fraction: float#
- volatile_solids_fraction_ts: float#
- biodegradable_vs_fraction: float#
- methane_yield_nm3_per_kg_vs_destroyed: float#
- decay_rate_per_day: float#
- density_kg_per_m3: float = 1000.0#
- dry_lhv_mj_per_kg: float = 18.0#
- property vs_kg_per_day: float#
- class x2power.methods.biogas_plant.ContinuousDigester(working_volume_m3, temperature_c=37.0, heat_loss_kw_per_k=0.0, feed_heat_capacity_kj_per_kg_k=4.18, minimum_hrt_days=None, maximum_olr_kg_vs_m3_day=None)[source]#
One perfectly mixed working volume; no solids retention or liquid recycle.
HRT and OLR limits only produce diagnostic flags; they are not inhibition kinetics or universal operating recommendations. Heat loss is UA * delta T.
- Parameters:
working_volume_m3 (float)
temperature_c (float)
heat_loss_kw_per_k (float)
feed_heat_capacity_kj_per_kg_k (float)
minimum_hrt_days (float | None)
maximum_olr_kg_vs_m3_day (float | None)
- working_volume_m3: float#
- temperature_c: float = 37.0#
- heat_loss_kw_per_k: float = 0.0#
- feed_heat_capacity_kj_per_kg_k: float = 4.18#
- minimum_hrt_days: float | None = None#
- maximum_olr_kg_vs_m3_day: float | None = None#
- class x2power.methods.biogas_plant.BiogasPlant(feedstocks, digester, generator, gas_storage_capacity_nm3=0.0, methane_fraction=0.6, capture_fraction=0.98, methane_lhv_kwh_per_nm3=9.94, fixed_auxiliary_power_kw=0.0, mixing_power_w_per_m3=0.0, feed_preparation_kwh_per_tonne=0.0, gas_treatment_kwh_per_nm3=0.0, electric_heater_efficiency=1.0)[source]#
Plant parameters shared across intervals, without third-party dependencies.
Storage capacity is dry normal biogas volume, not geometric membrane volume. Generator rating is mandatory and gross electrical. Fixed loads and mixing persist during outages. Treatment electricity applies to all captured gas.
- Parameters:
feedstocks (tuple[DigesterFeedstock, ...])
digester (ContinuousDigester)
generator (Generator)
gas_storage_capacity_nm3 (float)
methane_fraction (float)
capture_fraction (float)
methane_lhv_kwh_per_nm3 (float)
fixed_auxiliary_power_kw (float)
mixing_power_w_per_m3 (float)
feed_preparation_kwh_per_tonne (float)
gas_treatment_kwh_per_nm3 (float)
electric_heater_efficiency (float)
- feedstocks: tuple[DigesterFeedstock, ...]#
- digester: ContinuousDigester#
- gas_storage_capacity_nm3: float = 0.0#
- methane_fraction: float = 0.6#
- capture_fraction: float = 0.98#
- methane_lhv_kwh_per_nm3: float = 9.94#
- fixed_auxiliary_power_kw: float = 0.0#
- mixing_power_w_per_m3: float = 0.0#
- feed_preparation_kwh_per_tonne: float = 0.0#
- gas_treatment_kwh_per_nm3: float = 0.0#
- electric_heater_efficiency: float = 1.0#
- class x2power.methods.biogas_plant.PlantInterval(duration_h=1.0, feed_multipliers=(), generator_availability=1.0, generator_setpoint_fraction=1.0, feed_temperature_c=15.0, ambient_temperature_c=15.0, site_electricity_demand_kw=0.0, site_heat_demand_kw=0.0)[source]#
Constant inputs over one interval; multipliers follow feedstock tuple order.
Empty multipliers use all base rates. Availability is an equivalent capacity derating within the interval; resolve actual outages as separate 0/1 intervals. The CHP follows its setpoint, regardless of external electrical/thermal demand.
- Parameters:
duration_h (float)
feed_multipliers (tuple[float, ...])
generator_availability (float)
generator_setpoint_fraction (float)
feed_temperature_c (float)
ambient_temperature_c (float)
site_electricity_demand_kw (float)
site_heat_demand_kw (float)
- duration_h: float = 1.0#
- feed_multipliers: tuple[float, ...] = ()#
- generator_availability: float = 1.0#
- generator_setpoint_fraction: float = 1.0#
- feed_temperature_c: float = 15.0#
- ambient_temperature_c: float = 15.0#
- site_electricity_demand_kw: float = 0.0#
- site_heat_demand_kw: float = 0.0#
- class x2power.methods.biogas_plant.PlantState(feedstock_names, degradable_vs_kg, inert_vs_kg, stored_biogas_nm3=0.0)[source]#
Inventory passed between calls for the same unchanged plant configuration.
- Parameters:
feedstock_names (tuple[str, ...])
degradable_vs_kg (tuple[float, ...])
inert_vs_kg (tuple[float, ...])
stored_biogas_nm3 (float)
- feedstock_names: tuple[str, ...]#
- degradable_vs_kg: tuple[float, ...]#
- inert_vs_kg: tuple[float, ...]#
- stored_biogas_nm3: float = 0.0#
- class x2power.methods.biogas_plant.PlantResult(power, state, metrics, flags=())[source]#
One interval ledger and end state; no digestate nutrient or full mass balance.
- Parameters:
power (PowerResult)
state (PlantState)
metrics (dict[str, float | None])
flags (tuple[str, ...])
- power: PowerResult#
- state: PlantState#
- metrics: dict[str, float | None]#
- flags: tuple[str, ...] = ()#
- x2power.methods.biogas_plant.initial_plant_state(plant, *, interval=None, steady_state=True, stored_biogas_nm3=0.0)[source]#
Initialize pools at constant-feed equilibrium or at zero VS inventory.
Zero VS means an already full, warm liquid volume with no substrate inventory, not a prediction of microbial startup or digester filling. Gas defaults to zero.
- Parameters:
plant (BiogasPlant)
interval (PlantInterval | None)
steady_state (bool)
stored_biogas_nm3 (float)
- Return type:
- x2power.methods.biogas_plant.simulate_biogas_plant(plant, intervals, *, initial_state=None)[source]#
Integrate feed pools, dispatch captured gas and close electrical/heat ledgers.
Without an explicit state, start at equilibrium for the first interval’s feed rates with an empty gas holder. No automatic inhibition or temperature correction is applied to decay rates. Gas exceeding holder capacity is sent to an unlimited ideal flare. Flared gas volume is not an estimate of methane emitted to air.
- Parameters:
plant (BiogasPlant)
intervals (Sequence[PlantInterval])
initial_state (PlantState | None)
- Return type:
list[PlantResult]
Configuration, tabulation and energy totals for continuous biogas plants.
- x2power.utilities.biogas_plant.plant_from_config(config)[source]#
Read a dedicated plant schema, separate from the existing route scenario schema.
Accepts JSON-compatible dictionaries; unknown constructor fields are rejected. The optional name and assumptions fields are descriptive metadata only.
- Parameters:
config (dict[str, Any])
- Return type:
- x2power.utilities.biogas_plant.plant_profile_rows(results)[source]#
Flatten interval metrics and power values with explicit elapsed timestamps.
- Parameters:
results (Sequence[PlantResult])
- Return type:
list[dict[str, Any]]
- x2power.utilities.biogas_plant.summarize_plant(results)[source]#
Sum additive flows/energies only; do not sum HRT, OLR or stored inventories.
- Parameters:
results (Sequence[PlantResult])
- Return type:
dict[str, float]
Optional Matplotlib figures for continuous biogas-plant ledgers.
- x2power.utilities.plant_plotting.plot_biogas_plant(results, *, title='Biogas plant')[source]#
Plot interval-average flows/powers and gas inventory at interval boundaries.
Storage is an inventory; the other panels show rates, not interval totals. Import is positive in the electrical panel and reported separately from net power.
- Parameters:
results (Sequence[PlantResult])
title (str)