Core ADM1 Model¶
pyadm1.core.adm1.ADM1
¶
ADM1da – 41-state ODE system.
Implements the sub-fraction disintegration/hydrolysis approach, temperature-dependent kinetics, and modified inhibition kinetics described in Schlattmann (2011); SIMBA# biogas 4.2 Tutorial.
Usage¶
from pyadm1 import Feedstock fs = Feedstock([...], feeding_freq=24) adm = ADM1(fs, V_liq=1200, V_gas=216, T_ad=315.15) adm.set_influent_dataframe(fs.get_influent_dataframe(Q=[11.4, 6.1])) adm.create_influent(Q=[11.4, 6.1], i=0) state0 = [0.01] * STATE_SIZE dydt = adm.ADM_ODE(0.0, state0)
Source code in pyadm1/core/adm1.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | |
Attributes¶
AcvsPro
property
¶
History of the acetate-to-propionate ratio.
P_GAS
property
¶
History of total headspace pressure [bar].
Q_CH4
property
¶
History of methane flow rate [m^3/d].
Q_CO2
property
¶
History of carbon dioxide flow rate [m^3/d].
Q_GAS
property
¶
History of total biogas flow rate [m^3/d].
Q_H2O
property
¶
History of water-vapour flow rate [m^3/d].
TAC
property
¶
History of total alkalinity (TAC).
T_ad
property
¶
Operating temperature [K].
VFA
property
¶
History of total volatile fatty acid concentration [kg HAc-eq/m^3].
VFA_TA
property
¶
History of the VFA/TA (FOS/TAC) ratio.
feedstock
property
¶
Feedstock object.
model_name
property
¶
Short identifier for this model variant.
pH_l
property
¶
History of liquid-phase pH.
Functions¶
ADM_ODE(t, state)
¶
Compute dy/dt for the 41-element ADM1 state vector.
The system is autonomous; t is present only to satisfy the scipy solver interface.
Source code in pyadm1/core/adm1.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 | |
__init__(feedstock, V_liq=1977.0, V_gas=304.0, T_ad=308.15)
¶
Initialize the ADM1 model.
Parameters¶
feedstock : Feedstock
Feedstock object (used by create_influent when no external
influent DataFrame has been provided via set_influent_dataframe).
V_liq : float
Liquid digester volume [m³].
V_gas : float
Gas headspace volume [m³].
T_ad : float
Operating temperature [K] (default 308.15 K = 35 °C).
Source code in pyadm1/core/adm1.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
calc_gas(pi_Sh2, pi_Sch4, pi_Sco2, pTOTAL)
¶
Calculate biogas production rates, normalised to standard reference conditions (theta = 20 °C, P = 1.01325 bar; ADM1da convention).
Returns¶
q_gas, q_ch4, q_co2, q_h2o, p_gas
Source code in pyadm1/core/adm1.py
clear_calibration_parameters()
¶
Clear all calibration parameters and restore defaults.
Source code in pyadm1/core/adm1.py
create_influent(Q, i, rho=None)
¶
Build the influent vector for time step i.
If an external influent DataFrame has been set via
set_influent_dataframe(), that DataFrame is used. Otherwise
the feedstock object is used to derive the influent.
Source code in pyadm1/core/adm1.py
get_calibration_parameters()
¶
get_state_size()
¶
print_params_at_current_state(state)
¶
Compute and store process indicators (pH, gas) from the current state.
Source code in pyadm1/core/adm1.py
resume_from_broken_simulation(Q_CH4)
¶
set_calibration_parameters(parameters)
¶
Set calibration overrides for kinetic / gas parameters.
Kinetic-rate keys (k_m_*, k_hyd_*, k_dis_*, Y_*,
K_S_*, k_dec_*) are applied directly into the live kinetic
dict consumed by the ODE. Henry-constant keys (K_H_co2,
K_H_ch4, K_H_h2) overwrite the corresponding attributes.
k_p and k_L_a continue to be looked up from
self._calibration_params at their respective call sites.
Source code in pyadm1/core/adm1.py
set_influent_dataframe(df)
¶
Store an external ADM1 influent DataFrame.
The DataFrame must have columns matching INFLUENT_COLUMNS (37
liquid-state columns + Q). Once set, create_influent() reads
from this DataFrame instead of deriving values from the feedstock.
Source code in pyadm1/core/adm1.py
set_influent_density(rho_in, rho_sludge=1000.0)
¶
Retained for API compatibility; stored but no longer affects Q_out.
pyadm1.core.adm1.STATE_SIZE = 41
module-attribute
¶
pyadm1.core.adm1.INFLUENT_COLUMNS = ['S_su', 'S_aa', 'S_fa', 'S_va', 'S_bu', 'S_pro', 'S_ac', 'S_h2', 'S_ch4', 'S_co2', 'S_nh4', 'S_I', 'X_PS_ch', 'X_PS_pr', 'X_PS_li', 'X_PF_ch', 'X_PF_pr', 'X_PF_li', 'X_S_ch', 'X_S_pr', 'X_S_li', 'X_I', 'X_su', 'X_aa', 'X_fa', 'X_c4', 'X_pro', 'X_ac', 'X_h2', 'S_cation', 'S_anion', 'S_va_ion', 'S_bu_ion', 'S_pro_ion', 'S_ac_ion', 'S_hco3_ion', 'S_nh3', 'Q']
module-attribute
¶
pyadm1.core.adm1.get_state_zero_from_csv(csv_file)
¶
Load an ADM1 initial state vector from a CSV file.
The CSV must have columns matching INFLUENT_COLUMNS (without Q)
plus the four gas-phase columns (p_gas_h2, p_gas_ch4, p_gas_co2, pTOTAL).
Source code in pyadm1/core/adm1.py
pyadm1.core.adm_params.ADMParams
¶
Static parameter class for the ADM1da model.
Source code in pyadm1/core/adm_params.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
Functions¶
apply_temperature_corrections(kinetic, theta, T_ad)
staticmethod
¶
Return a copy of kinetic with rates corrected to T_ad.
Uses: k(T) = k(35 °C) · θ^(T[°C] − 35)
Source code in pyadm1/core/adm_params.py
getADMgasparams(R, T_base, T_ad)
staticmethod
¶
Get gas phase parameters including Henry constants.
Parameters¶
R : float Gas constant [bar·m³·kmol⁻¹·K⁻¹] T_base : float Reference temperature [K] (298.15) T_ad : float Digester temperature [K]
Returns¶
Tuple[float, float, float, float, float, float] p_gas_h2o, k_p, k_L_a, K_H_co2, K_H_ch4, K_H_h2
Source code in pyadm1/core/adm_params.py
get_inhibition_params(R, T_base, T_ad)
staticmethod
¶
Return inhibition-related parameters and acid-base constants.
Parameters¶
R : float Gas constant [bar m³ kmol⁻¹ K⁻¹]. T_base : float Reference temperature [K] (25 °C = 298.15 K). T_ad : float Operating temperature [K].
Source code in pyadm1/core/adm_params.py
get_kinetic_params()
staticmethod
¶
Return kinetic parameters at the reference temperature (35 °C).
Source code in pyadm1/core/adm_params.py
get_product_fractions()
staticmethod
¶
Return fermentation product fractions.
Source code in pyadm1/core/adm_params.py
get_stoichiometric_params()
staticmethod
¶
Return carbon/nitrogen content and disintegration/hydrolysis fractions.
Returns¶
dict Stoichiometric constants (ADM1da defaults; Schlattmann 2011).
Source code in pyadm1/core/adm_params.py
get_temperature_factors()
staticmethod
¶
Return Arrhenius θ correction factors per organism/process group.
Source code in pyadm1/core/adm_params.py
pyadm1.core.solver.ODESolver
¶
ODE solver wrapper for ADM1 system.
Provides a clean interface to scipy's solve_ivp with appropriate settings for stiff biogas process ODEs. Uses BDF (Backward Differentiation Formula) method which is suitable for stiff systems.
Example
def ode_func(t, y): ... return [-0.5 * y[0], 0.5 * y[0] - 0.1 * y[1]] solver = ODESolver() result = solver.solve(ode_func, [0, 10], [1.0, 0.0]) print(result.y[:, -1]) # Final state
Source code in pyadm1/core/solver.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
Functions¶
__init__(config=None)
¶
Initialize ODE solver with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[SolverConfig]
|
Solver configuration. If None, uses default BDF settings. |
None
|
solve(fun, t_span, y0, t_eval=None, dense_output=False)
¶
Solve ODE system over time span.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun
|
Callable[[float, List[float]], List[float]]
|
Right-hand side of ODE system dy/dt = fun(t, y) |
required |
t_span
|
Tuple[float, float]
|
Integration time span (t_start, t_end) [days] |
required |
y0
|
List[float]
|
Initial state vector |
required |
t_eval
|
Optional[ndarray]
|
Times at which to store solution. If None, uses automatic time points with 0.05 day resolution |
None
|
dense_output
|
bool
|
If True, returns continuous solution object |
False
|
Returns:
| Type | Description |
|---|---|
OdeResult
|
OdeResult object with solution (from scipy.integrate.solve_ivp) |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If integration fails |
Source code in pyadm1/core/solver.py
solve_sequential(fun, t_points, y0)
¶
Solve ODE system sequentially through multiple time points.
Useful for simulations where conditions change at specific times (e.g., substrate feed changes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun
|
Callable[[float, List[float]], List[float]]
|
Right-hand side of ODE system |
required |
t_points
|
List[float]
|
List of time points [days] |
required |
y0
|
List[float]
|
Initial state vector |
required |
Returns:
| Type | Description |
|---|---|
List[List[float]]
|
List of state vectors at each time point |
Source code in pyadm1/core/solver.py
solve_to_steady_state(fun, y0, max_time=1000.0, steady_state_tol=1e-06, check_interval=10.0)
¶
Integrate until steady state is reached or max time exceeded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun
|
Callable[[float, List[float]], List[float]]
|
Right-hand side of ODE system |
required |
y0
|
List[float]
|
Initial state vector |
required |
max_time
|
float
|
Maximum integration time [days] |
1000.0
|
steady_state_tol
|
float
|
Tolerance for steady state detection |
1e-06
|
check_interval
|
float
|
Interval for checking steady state [days] |
10.0
|
Returns:
| Type | Description |
|---|---|
List[float]
|
Tuple of (final_state, final_time, converged) |
float
|
|
bool
|
|
Tuple[List[float], float, bool]
|
|
Source code in pyadm1/core/solver.py
pyadm1.core.solver.AdaptiveODESolver
¶
Bases: ODESolver
Adaptive ODE solver that adjusts tolerances based on solution behavior.
Monitors the solution and can tighten tolerances if instabilities are detected, or relax them for faster computation when solution is smooth.
Source code in pyadm1/core/solver.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
Functions¶
__init__(config=None, adaptive=True, min_rtol=1e-08, max_rtol=0.0001)
¶
Initialize adaptive ODE solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[SolverConfig]
|
Base solver configuration |
None
|
adaptive
|
bool
|
Enable adaptive tolerance adjustment |
True
|
min_rtol
|
float
|
Minimum relative tolerance |
1e-08
|
max_rtol
|
float
|
Maximum relative tolerance |
0.0001
|
Source code in pyadm1/core/solver.py
solve(fun, t_span, y0, t_eval=None, dense_output=False)
¶
Solve with adaptive tolerance adjustment.
Same interface as parent class but monitors solution quality.
Source code in pyadm1/core/solver.py
pyadm1.core.solver.SolverConfig
dataclass
¶
Configuration for ODE solver.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
str
|
Integration method ('BDF' for stiff ODEs) |
rtol |
float
|
Relative tolerance for solver |
atol |
float
|
Absolute tolerance for solver |
min_step |
float
|
Minimum allowed time step [days] |
max_step |
float
|
Maximum allowed time step [days] |
first_step |
Optional[float]
|
Initial step size [days] |
Source code in pyadm1/core/solver.py
pyadm1.core.solver.create_solver(method='BDF', adaptive=False, **kwargs)
¶
Factory function to create appropriate solver instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Integration method ('BDF' recommended for ADM1) |
'BDF'
|
adaptive
|
bool
|
Use adaptive tolerance adjustment |
False
|
**kwargs
|
Additional configuration parameters for SolverConfig |
{}
|
Returns:
| Type | Description |
|---|---|
ODESolver
|
Configured solver instance |
Example
solver = create_solver(method='BDF', rtol=1e-7)
Use solver for integration...¶