Kern-ADM1-Modell¶
pyadm1.core.adm1.ADM1
¶
Main class implementing ADM1 as pure ODE system.
This class manages the ADM1 state, parameters, and provides methods for simulation including influent stream creation, gas production calculation, and state tracking.
Attributes:
| Name | Type | Description |
|---|---|---|
V_liq |
Liquid volume [m³] |
|
T_ad |
float
|
Operating temperature [K] |
feedstock |
Feedstock
|
Feedstock object for substrate management |
Example
feedstock = Feedstock(feeding_freq=48) adm1 = ADM1(feedstock, V_liq=2000, T_ad=308.15) adm1.create_influent([15, 10, 0, 0, 0, 0, 0, 0, 0, 0], 0)
Source code in pyadm1/core/adm1.py
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 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 | |
Attributes¶
AcvsPro
property
¶
Acetic/Propionic acid ratios over all simulations.
P_GAS
property
¶
Gas pressures over all simulations [bar].
Q_CH4
property
¶
Methane production rates over all simulations [m³/d].
Q_CO2
property
¶
CO2 production rates over all simulations [m³/d].
Q_GAS
property
¶
Biogas production rates over all simulations [m³/d].
TAC
property
¶
TA concentrations over all simulations [g CaCO3 eq/L].
T_ad
property
¶
Operating temperature [K].
VFA
property
¶
VFA concentrations over all simulations [g/L].
VFA_TA
property
¶
VFA/TA ratios over all simulations.
feedstock
property
¶
Feedstock object.
pH_l
property
¶
pH values over all simulations.
Functions¶
ADM1_ODE(t, state_zero)
¶
Calculate derivatives for ADM1 ODE system.
This is the main ODE function that computes dy/dt for all 37 state variables. Uses process rate equations and stoichiometric relationships.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Current time [days] (not used, system is autonomous) |
required |
state_zero
|
List[float]
|
Current ADM1 state vector (37 elements) |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, ...]
|
Tuple of 37 derivatives (dy/dt) |
Note
This method is called by the ODE solver and should not be called directly by users.
Source code in pyadm1/core/adm1.py
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 | |
__init__(feedstock, V_liq=1977.0, V_gas=304.0, T_ad=308.15)
¶
Initialize ADM1 model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feedstock
|
Feedstock
|
Feedstock object containing substrate information. E.g. used to calculate ADM1 input stream. |
required |
V_liq
|
float
|
Liquid volume [m³] |
1977.0
|
V_gas
|
float
|
Gas volume [m³] |
304.0
|
T_ad
|
float
|
Operating temperature [K] (default: 308.15 = 35°C) |
308.15
|
Source code in pyadm1/core/adm1.py
calc_gas(pi_Sh2, pi_Sch4, pi_Sco2, pTOTAL)
¶
Calculate biogas production rates from partial pressures.
Uses the ideal gas law and Henry's constants to calculate gas flow rates from the gas phase partial pressures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pi_Sh2
|
float
|
Hydrogen partial pressure [bar] |
required |
pi_Sch4
|
float
|
Methane partial pressure [bar] |
required |
pi_Sco2
|
float
|
CO2 partial pressure [bar] |
required |
pTOTAL
|
float
|
Total gas pressure [bar] |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float, float, float]
|
Tuple containing: - q_gas: Total biogas flow rate [m³/d] - q_ch4: Methane flow rate [m³/d] - q_co2: CO2 flow rate [m³/d] - p_gas: Total gas partial pressure (excl. H2O) [bar] |
Example
q_gas, q_ch4, q_co2, p_gas = adm1.calc_gas(5e-6, 0.55, 0.42, 0.98) print(f"Biogas: {q_gas:.1f} m³/d, Methane: {q_ch4:.1f} m³/d")
Source code in pyadm1/core/adm1.py
clear_calibration_parameters()
¶
Clear all calibration parameters and revert to substrate-dependent calculations.
Example
adm1.clear_calibration_parameters()
Source code in pyadm1/core/adm1.py
create_influent(Q, i)
¶
Create ADM1 input stream from volumetric flow rates.
Calculates the ADM1 influent state by mixing substrate streams according to their volumetric flow rates. The resulting influent composition is stored internally for use in ODE calculations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
List[float]
|
Volumetric flow rates for each substrate [m³/d] Length must equal number of substrates in feedstock |
required |
i
|
int
|
Time step index for accessing influent dataframe |
required |
Example
adm1.create_influent([15, 10, 0, 0, 0, 0, 0, 0, 0, 0], 0)
Source code in pyadm1/core/adm1.py
get_calibration_parameters()
¶
Get currently set calibration parameters.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Current calibration parameters as {param_name: value}. |
Example
params = adm1.get_calibration_parameters() print(params)
Source code in pyadm1/core/adm1.py
print_params_at_current_state(state_ADM1xp)
¶
Calculate and store process parameters from current state.
Computes key process indicators including pH, VFA, TAC, and gas production rates. Also stores values in tracking lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_ADM1xp
|
List[float]
|
Current ADM1 state vector (37 elements) |
required |
Example
adm1.print_params_at_current_state(state_vector)
Source code in pyadm1/core/adm1.py
save_final_state_in_csv(simulate_results, filename='digester_final.csv')
¶
Save final ADM1 state vector to CSV file.
Exports only the last state from simulation results, which can be used as initial state for subsequent simulations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulate_results
|
List[List[float]]
|
List of ADM1 state vectors from simulation |
required |
filename
|
str
|
Output CSV filename |
'digester_final.csv'
|
Example
results = [[0.01]37, [0.02]37, [0.03]*37] adm1.save_final_state_in_csv(results, 'final_state.csv')
Source code in pyadm1/core/adm1.py
set_calibration_parameters(parameters)
¶
Set calibration parameters that override substrate-dependent calculations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
dict
|
Parameter values as {param_name: value}. |
required |
Example
adm1.set_calibration_parameters({ ... 'k_dis': 0.55, ... 'k_hyd_ch': 11.0, ... 'Y_su': 0.105 ... })
Source code in pyadm1/core/adm1.py
pyadm1.core.adm_params.ADMParams
¶
Static class containing ADM1 model parameters.
Source code in pyadm1/core/adm_params.py
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 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 | |
Functions¶
getADMgasparams(R, T_base, T_ad)
staticmethod
¶
Get gas phase parameters including Henry constants.
Parameters¶
R : float Gas constant [bar·M^-1·K^-1] T_base : float Base temperature [K] 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
getADMinhibitionparams()
staticmethod
¶
Get pH inhibition parameters.
Returns¶
Tuple[float, float, float, float, float, float] K_pH_aa, nn_aa, K_pH_ac, n_ac, K_pH_h2, n_h2
Source code in pyadm1/core/adm_params.py
getADMparams(R, T_base, T_ad)
staticmethod
¶
Get all ADM1 stoichiometric and kinetic parameters.
Parameters¶
R : float Gas constant [bar·M^-1·K^-1] T_base : float Base temperature [K] T_ad : float Digester temperature [K]
Returns¶
Tuple[float, ...] All ADM1 parameters (87 values)
Source code in pyadm1/core/adm_params.py
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 | |
pyadm1.core.adm_equations.BiochemicalProcesses
¶
Combined biochemical process calculations for ADM1.
This class orchestrates the calculation of all process rates including inhibition factors and stoichiometric relationships.
Source code in pyadm1/core/adm_equations.py
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 | |
Functions¶
calculate_acid_base_rates(state, acid_base_params)
staticmethod
¶
Calculate acid-base reaction rates for ODE implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
List[float]
|
ADM1 state vector (37 elements) |
required |
acid_base_params
|
dict
|
Dictionary containing K_a and k_AB values |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float, float, float, float, float]
|
Tuple of 6 acid-base rates (Rho_A_4 through Rho_A_11) |
Source code in pyadm1/core/adm_equations.py
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 | |
calculate_gas_transfer_rates(state, gas_params, RT, V_liq, V_gas, p_ext)
staticmethod
¶
Calculate gas-liquid transfer and gas outlet rates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
List[float]
|
ADM1 state vector (37 elements) |
required |
gas_params
|
dict
|
Dictionary containing k_L_a, K_H constants, k_p |
required |
RT
|
float
|
Gas constant × temperature [bar·m³/kmol] |
required |
V_liq
|
float
|
Liquid volume [m³] |
required |
V_gas
|
float
|
Gas volume [m³] |
required |
p_ext
|
float
|
External pressure [bar] |
required |
Returns: Tuple of 4 rates (Rho_T_8, Rho_T_9, Rho_T_10, Rho_T_11)
Source code in pyadm1/core/adm_equations.py
calculate_inhibition_factors(S_H_ion, S_h2, S_nh4_ion, S_nh3, K_pH_aa, nn_aa, K_pH_ac, n_ac, K_pH_h2, n_h2, K_S_IN, K_I_h2_fa, K_I_h2_c4, K_I_h2_pro, K_I_nh3)
staticmethod
¶
Calculate all inhibition factors for ADM1 processes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S_H_ion
|
float
|
Hydrogen ion concentration [M] |
required |
S_h2
|
float
|
Hydrogen gas concentration [kg COD/m³] |
required |
S_nh4_ion
|
float
|
Ammonium concentration [M] |
required |
S_nh3
|
float
|
Free ammonia concentration [M] |
required |
K_pH_aa
|
float
|
pH inhibition constant for amino acid degraders [M] |
required |
nn_aa
|
float
|
Hill coefficient for aa pH inhibition [-] |
required |
K_pH_ac
|
float
|
pH inhibition constant for acetate degraders [M] |
required |
n_ac
|
float
|
Hill coefficient for ac pH inhibition [-] |
required |
K_pH_h2
|
float
|
pH inhibition constant for hydrogen degraders [M] |
required |
n_h2
|
float
|
Hill coefficient for h2 pH inhibition [-] |
required |
K_S_IN
|
float
|
Nitrogen half-saturation constant [M] |
required |
K_I_h2_fa
|
float
|
H2 inhibition constant for LCFA degraders [kg COD/m³] |
required |
K_I_h2_c4
|
float
|
H2 inhibition constant for C4 degraders [kg COD/m³] |
required |
K_I_h2_pro
|
float
|
H2 inhibition constant for propionate degraders [kg COD/m³] |
required |
K_I_nh3
|
float
|
Ammonia inhibition constant [M] |
required |
Returns:
| Type | Description |
|---|---|
float
|
Tuple of inhibition factors (I_pH_aa, I_pH_ac, I_pH_h2, I_IN_lim, |
float
|
I_h2_fa, I_h2_c4, I_h2_pro, I_nh3, I_5 through I_12) |
Source code in pyadm1/core/adm_equations.py
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 | |
calculate_process_rates(state, inhibitions, kinetic_params, substrate_params, hydro_factor=1.0)
staticmethod
¶
Calculate all 19 biochemical process rates for ADM1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
List[float]
|
ADM1 state vector (37 elements) |
required |
inhibitions
|
Tuple[float, ...]
|
Tuple of inhibition factors from calculate_inhibition_factors |
required |
kinetic_params
|
dict
|
Dictionary of kinetic parameters (k_m, K_S, k_dec, etc.) |
required |
substrate_params
|
dict
|
Dictionary of substrate-dependent parameters (k_dis, k_hyd_ch, k_hyd_pr, k_hyd_li) |
required |
hydro_factor
|
float
|
Optional TS-dependent hydrolysis factor [-]. Values above 1 are interpreted as digester TS [%]. |
1.0
|
Returns:
| Type | Description |
|---|---|
Tuple[float, ...]
|
Tuple of 19 process rates (Rho_1 through Rho_19) |
Source code in pyadm1/core/adm_equations.py
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 | |
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]
|
|