Finite Volume Model
Finite Volume Dispersion Model module.
Methods and classes for the finite volume method for the dispersion model.
FiniteVolume
dataclass
Bases: DispersionModel
Dispersion model object which creates a coupling matrix using a finite volume solver.
Uses an advection-diffusion solver to create the coupling matrix between a set of source locations and a set of sensor locations.
Attributes:
| Name | Type | Description |
|---|---|---|
dimensions |
list
|
list of FiniteVolumeDimension for each grid dimension (e.g., x, y, z). |
diffusion_constants |
ndarray
|
array of diffusion constants [x,y,z], units m^2/s. |
site_layout |
Union[SiteLayout, None]
|
the layout of the site including cylinder coordinates and radii. (default is None). If None, no obstacles are considered in the model. |
dt |
float
|
time step (s) (default is None). (If None, the time step is set using the CFL condition). |
implicit_solver |
bool
|
if True, the solver uses implicit methods. (default is False). |
courant_number |
float
|
Courant number which and represents the fraction of the grid cell that a fluid particle can travel in one time step. It is used in calculating dt when not specified. Default is 0.5 which means that a fluid particle can travel half the grid cell in one time step. |
burn_in_steady_state |
bool
|
if True, the model runs a burn-in period to reach steady state before computing coupling. (default is True). |
use_lookup_table |
bool
|
if True, uses a lookup table for coupling matrix interpolation (default is True). |
grid_coordinates |
ndarray
|
shape=(total_number_cells, number_dimensions), coordinates of the grid points. |
source_grid_link |
csr_array
|
is a sparse matrix linking the source map to the grid coordinates. |
cell_volume |
float
|
volume of a single grid cell. |
total_number_cells |
int
|
total number of cells in the grid. |
grid_size |
tuple
|
size of the grid in each dimension. |
grid_centers |
list
|
centers of the grid cells in each dimension. |
number_dimensions |
int
|
number of dimensions in the grid. |
adv_diff_terms |
dict
|
contains advection and diffusion terms for the solver matrix. |
coupling_lookup_table |
ndarray
|
coupling matrix calculated for each grid cell in grid_coordinates computed when use_lookup_table=True. It is used for interpolation of coupling values for new source locations without the need to re-run the FV solver. |
forward_matrix |
dia_array
|
the solver matrix for the finite volume method. |
_forward_matrix_transpose |
dia_array
|
the transpose of the solver matrix for the finite volume method. |
Source code in src/pyelq/dispersion_model/finite_volume.py
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 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 | |
__post_init__()
Post-initialization checks and setup.
Creates the grid and neighbourhood for the finite volume solver, and uses the site layout to mask any obstacles from the solver grid.
Source code in src/pyelq/dispersion_model/finite_volume.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
compute_coupling(sensor_object, met_windfield, gas_object=None, output_stacked=False, **kwargs)
Compute the coupling matrix for the finite volume method using a lookup table.
If self.use_lookup_table == False, or if self.coupling_lookup_table is None, the coupling matrix is computed using the FV solver and stored in self.coupling_lookup_table. Otherwise, the coupling matrix is computed using a lookup table approach from the previously computed coupling matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_object
|
SensorGroup
|
sensor object containing sensor observations. |
required |
met_windfield
|
MeteorologyWindfield
|
meteorology object containing site layout and timeseries of wind data. |
required |
gas_object
|
Union[GasSpecies, None]
|
optional input, a gas species object to correctly calculate the gas density which is used in the conversion of the units of the Gaussian plume coupling. Defaults to None. |
None
|
output_stacked
|
bool
|
if True, the coupling is stacked across sensors into a single np.ndarray. Otherwise, the coupling is returned as a dictionary with an entry per sensor. Defaults to False. |
False
|
**kwargs
|
additional keyword arguments. To accommodate some arguments used in GaussianPlume.compute_coupling but not required in FiniteVolume. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
output |
Union[ndarray, dict]
|
List of arrays, single array or dictionary containing the plume coupling in hr/kg. If a dictionary of sensor objects is passed in and output_stacked=False, this function returns a dictionary consistent with the input dictionary keys, containing the corresponding plume coupling outputs for each sensor. If a dictionary of sensor objects is passed in and output_stacked=True, this function returns an np.ndarray containing the stacked coupling matrices. |
Source code in src/pyelq/dispersion_model/finite_volume.py
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 | |
compute_coupling_sections(sensor_object, met_windfield, gas_object)
Compute the coupling sections for the finite volume method.
Sections are defined by the source_on attribute of the sensor object. If source_on is None (not specified) or all ones, then it is treated as a single section of data and directly moves on to computing the coupling matrix.
If there are multiple sections, then the coupling matrix is computed for each section separately and combined into a single coupling matrix. This avoids computational effort computing the forward model through time steps that are not required and can speed up the computational time substantially in this case. Sections are defined by the source_on attribute of the sensor object which indicates which time steps the source is on where 0 indicates the source is off and integers starting from 1 indicate different source on sections.
To avoid additional computational effort when a source is not emitting we do not compute the forward model when the source_on attribute of the sensor object is set to 0. When a source starts emitting we can either assume it was already emitting and calculate an equilibrium state by setting the burn_in_steady_state attribute to True. Or we assume it starts right then and set this burn_in_steady_state attribute to False. When a source stops emitting there is still some gas present in the area of interest and it will take some time for this gas to disperse out of the area. However we assume the solution will not improve enough during this time to warrant the additional computational effort to compute the forward model for this period. Which is why we stop computing the forward model again when the source_on attribute switches from 1 to 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_object
|
SensorGroup
|
sensor data object. |
required |
meteorology_object
|
MeteorologyWindfield
|
wind field data object. |
required |
gas_object
|
GasSpecies
|
gas species object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
coupling_sensor |
dict
|
coupling for each sensor, keys corresponding to each sensor: e.g. coupling_sensor['sensor_1'] is the coupling matrix for sensor 1. |
Source code in src/pyelq/dispersion_model/finite_volume.py
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 | |
finite_volume_time_step_solver(sensor_object, met_windfield, gas_object)
Compute the finite volume coupling matrix, by time-stepping the solver.
This function calculates the coupling between emission sources and sensor measurements based on a spatial wind field derived from meteorological data. The resulting coupling matrices model the transport of gas through a discretized domain. The coupling between emissions in all solver grid cells and concentrations in the same set of grid cells is calculated by time-stepping a finite volume solver for the advection-diffusion equation. In time bins where sensor observations occur, the coupling between any source locations in the source map and the locations where sensor observations were obtained are extracted and stored in the rows of the coupling matrix.
If dt is not specified, it will be set automatically using a CFL-like condition via self.set_delta_time_cfl(). If burn_in_steady_state is True, the model runs a burn-in period to reach steady state before computing any coupling values. The wind field during the burn-in period is assumed to be constant and the same as the wind field at the first time-step.
If the coupling matrix is unstable (norm > 1e3), an error is raised suggesting to check the CFL number and dt. This condition is checked every 10% of the time steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_object
|
SensorGroup
|
sensor data object. |
required |
meteorology_object
|
MeteorologyWindfield
|
wind field data object. |
required |
gas_object
|
GasSpecies
|
gas species object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
coupling_sensor |
dict
|
coupling matrix for each sensor and sources defined by source_grid_link units hr/kg. coupling_sensor keys corresponding to each source, e.g. coupling_sensor['sensor_1'] = coupling matrix for sensor 1 with shape=(number of observations (sensor_1), number of sources). |
Source code in src/pyelq/dispersion_model/finite_volume.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 | |
interpolate_coupling_lookup_to_source_map(sensor_object)
Compute the coupling matrix by interpolation from a lookup table.
A coupling matrix from all solver grid centres to all observations is pre-computed and stored on the class. Coupling columns for new source locations can then be computed by interpolation from these pre-computed values.
The coupling matrix used for lookup is taken from self.coupling_lookup_table which is a sparse matrix computed in self.finite_volume_time_step_solver().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_object
|
SensorGroup
|
sensor data object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
interpolated_coupling |
dict
|
interpolated coupling matrix for each sensor and sources (units hr/kg). |
Source code in src/pyelq/dispersion_model/finite_volume.py
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 | |
propagate_solver_single_time_step(met_windfield, coupling_matrix=None)
Time-step the finite volume solver.
Time-step the finite volume solver to map the coupling matrix at time t to the coupling matrix at time (t + dt).
For each time step, the forward matrix is computed based on the current wind field. The coupling matrix is then evolved by a single time-step using either an implicit or explicit solver approach, depending on the value of self.implicit_solver.
coupling_matrix will be a sparse csc_array with shape=(total_number_cells, number of sources)
If minimum_contribution is set, all elements in the coupling matrix smaller than this number will be set to 0. This can speed up computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
met_windfield
|
MeteorologyWindfield
|
meteorology object containing wind field information. |
required |
coupling_matrix
|
Union[(sparse.csc_array, None]
|
shape=(self.total_number_cells, number of sources). coupling matrix matrix on the finite volume grid if None will get preallocated for future time steps |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
coupling_matrix |
csc_array
|
shape=(self.total_number_cells, number of sources). Coupling matrix on the finite volume grid. Represents the contribution of each cell to the source term in the transport equation. |
Source code in src/pyelq/dispersion_model/finite_volume.py
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 | |
compute_forward_matrix(met_windfield)
Construct the forward solver matrix. This can be used to step the solution forward in time.
The matrix forward_matrix is constructed using the advection and diffusion terms computed for each face in the grid.
The overall matrix equation for the FV solver is
(V / dt) * [c^(n+1) - c^(n)] + F @ c^(n) - G @ c^(n) = s
where F is the matrix of advection term coefficients, G is the matrix of diffusion term coefficients, and s is the source term.
Rearranging gives
c^(n+1) = R @ c^(n) + (dt / V) * s
where R = I - (dt / V) * (F - G).
The diagonals of the matrix are constructed using self._construct_diagonals_advection_diffusion() and combined using self._combine_advection_diffusion_terms().
On first run, the matrix is constructed using self._construct_diagonal_matrix(). On subsequent runs, the matrix is updated using self._update_diagonal_matrix() which saves computational time by updating the sparse matrix in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
met_windfield
|
MeteorologyWindfield
|
meteorology object containing wind field information. |
required |
Source code in src/pyelq/dispersion_model/finite_volume.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 | |
compute_time_bins(sensor_object, meteorology_object)
Compute discretized time bins for aligning sensor observations and meteorological data.
This method constructs a uniform time grid (bins) based on the observation time range of the given sensors.
The time resolution is determined by self.dt. If self.dt is not specified, it will be set automatically
using a CFL-like condition via self.set_delta_time_cfl() based on the meteorology object.
Once the time bins are established
- Each sensor's observation times are digitized to determine which time bin each observation belongs to.
- A KDTree is used to find the closest meteorological time index corresponding to each time bin, mapping the wind field to the solver grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_object
|
SensorGroup
|
Sensor data object |
required |
meteorology_object
|
Meteorology
|
Meteorology data object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
time_bins |
DatetimeIndex
|
The array of uniformly spaced time bins (based on |
time_index_sensor |
dict
|
A dictionary mapping each sensor ID to its array of time bin indices. |
time_index_met |
ndarray
|
An array mapping each time bin to the closest meteorological time index. |
Source code in src/pyelq/dispersion_model/finite_volume.py
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 | |
set_delta_time_cfl(meteorology_object)
Use CFL condition to set the time step.
The CFL condition is a stability criterion for numerical methods used in solving partial differential equations. It ensures that the numerical solution remains stable and converges to the true solution.
The CFL condition for advection is given by
dt <= min(dx / |u|)
for all dimensions, where dx is the grid spacing and u is the velocity. This method calculates the maximum velocity in each dimension and sets the time step accordingly.
The diffusion term is also considered in the CFL condition
dt <= (dx^2) / (2 * K)
for all dimensions, where K is self.diffusion_constants.
dt is set to the minimum of the advection and diffusion time steps multiplied by self.courant_number.
dt is rounded to the nearest 0.1s due to usage in pd.date_range in other parts of the code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meteorology_object
|
Meteorology
|
meteorology object containing timeseries of wind data. |
required |
Source code in src/pyelq/dispersion_model/finite_volume.py
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 | |
interpolate_coupling_grid_to_sensor(sensor_object, scaled_coupling, time_index_sensor, i_time, coupling_sensor)
Interpolate coupling grid values to sensor locations.
Calculate the coupling for each sensor at a given time step. This function interpolates plume coupling values from the coupling matrix to each sensor's location for a specific time step, and updates the output dictionary with the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_object
|
SensorGroup
|
object containing sensor data. |
required |
scaled_coupling
|
csr_array
|
The sparse matrix representing coupling values between sources and grid cells for the current time step. |
required |
time_index_sensor
|
ndarray
|
An array mapping each sensor to its corresponding time step index. |
required |
i_time
|
int
|
The index of the current time step. |
required |
coupling_sensor
|
dict
|
The output dictionary to be updated with coupling values for each sensor. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
coupling_sensor |
dict
|
The updated output dictionary with interpolated coupling values at each sensor location for the current time step. |
Source code in src/pyelq/dispersion_model/finite_volume.py
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 | |
FiniteVolumeDimension
dataclass
Individual grid dimension for the finite volume method.
Assuming that each solver dimension is a regular grid, this class stores grid properties, such as cell edges, centre points and cell widths.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
name of this dimension (e.g., 'x', 'y', 'z'). |
number_cells |
int
|
number of cells in this dimension. |
limits |
list
|
limits of this dimension (e.g., [0, 100]). |
external_boundary_type |
list
|
type of boundary condition for the faces in this dimension e.g., external_boundary_type=['dirichlet', 'neumann']. If only 1 type is specified, it is used for both faces of this dimension. |
cell_edges |
ndarray
|
shape=(self.number_cells + 1,) edge locations for the cells in this dimension. |
cell_centers |
ndarray
|
shape=(self.number_cells,) central locations of the cells in this dimension. |
cell_width |
float
|
width of the cells in this dimension. |
faces |
list(FiniteVolumeFaceLeft, FiniteVolumeFaceRight
|
list of objects corresponding to the left and right (-ve and +ve) faces of this dimension. |
Source code in src/pyelq/dispersion_model/finite_volume.py
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 | |
__post_init__()
Post-initialization processing.
Validates the external boundary types and initializes the face objects for the dimension. Also calls get_dimensions to calculate and store geometric properties of the dimension.
Raises:
| Type | Description |
|---|---|
ValueError
|
external_boundary_type must one of ['dirichlet', 'neumann']. |
ValueError
|
number_cells must be at least 2. |
Source code in src/pyelq/dispersion_model/finite_volume.py
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 | |
get_dimensions()
Setup the face properties for the finite volume method.
This function calculates and stores the grid cell edges, cell centres and cell widths, and assigns the cell width values to the cell faces.
Source code in src/pyelq/dispersion_model/finite_volume.py
908 909 910 911 912 913 914 915 916 917 918 919 | |
FiniteVolumeFace
dataclass
Bases: ABC
Face type for a grid cell in the finite volume method.
Attributes:
| Name | Type | Description |
|---|---|---|
external_boundary_type |
str
|
The type of boundary condition for the face. either 'dirichlet' or 'neumann'. |
cell_face_area |
float
|
The area of the face. |
cell_volume |
float
|
The volume of the face. |
cell_width |
float
|
The width of the cell in the direction normal to the face. |
boundary_type |
ndarray
|
shape=(total_number_cells, 1). The type of boundary condition for the face. Each entry is a string, either 'internal', 'dirichlet' or 'neumann'. |
neighbour_index |
ndarray
|
shape=(total_number_cells, 1). The index of the neighboring cell across the face. |
adv_diff_terms |
dict
|
The advection and diffusion terms for the face. Dictionary has two entries: "advection" and "diffusion", each containing a SolverDiagonals object. |
Source code in src/pyelq/dispersion_model/finite_volume.py
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 | |
normal
abstractmethod
property
Abstract property to be defined in subclasses.
set_boundary_type(external_boundaries, site_layout=None)
Set the boundary condition for the face based on the external boundary type.
External boundaries are set to 'dirichlet' or 'neumann' based on the specified external_boundary_type. Internal boundaries are set to 'internal'.
The function also handles the case where the face is affected by an obstacle. Obstacle boundaries are set to 'neumann'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
external_boundaries
|
ndarray
|
shape=(total_number_cells, 1). Boolean array indicating which faces are external boundaries. |
required |
site_layout
|
Union[SiteLayout, None]
|
SiteLayout object containing obstacle information. Defaults to None. |
None
|
Source code in src/pyelq/dispersion_model/finite_volume.py
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | |
assign_advection(wind_vector)
Assigns the advection terms for the defined set of interfaces to adv_diff_terms['advection'].
Uses an upwind scheme for the discretization of the advection term: https://en.wikipedia.org/wiki/Upwind_scheme#:~:text=In#20computational#20physics#2C#20the#20term,derivatives#20in#20a#20flow#20field.
Upwind scheme for a single dimension has the following form
F_i = A * [u^{+} * (c_i - c_{i-1}) + u^{-} * (c_{i+1} - c_{i})]
where u^{+} = -min(-u, 0) and u^{-} = max(-u, 0), A is the face area, and indices corresponding to other dimensions have been dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wind_vector
|
ndarray
|
shape=(total_number_cells, 1). Wind speed vector in dimension of this face e.g. x, y, z. |
required |
Source code in src/pyelq/dispersion_model/finite_volume.py
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 | |
assign_diffusion(diffusion_constants)
Assigns the diffusion terms for the defined set of interfaces to adv_diff_terms['diffusion'].
If diffusion is already set this function is skipped as the diffusion term is constant.
The diffusion term for a single dimension has the following form
G_i = K * A * [(c_{i+1} - c_i) / delta - (c_i - c_{i-1}) / delta]
where K is the diffusion constant, A is the face area, delta is the cell width, and indices corresponding to other dimensions have been dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diffusion_constants (float)
|
diffusion coefficient in this dimension. |
required |
Source code in src/pyelq/dispersion_model/finite_volume.py
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 | |
FiniteVolumeFaceLeft
dataclass
Bases: FiniteVolumeFace
Set up face properties specific to a left-facing cell (i.e. outward normal is the negative unit vector).
Attributes:
| Name | Type | Description |
|---|---|---|
direction |
str
|
direction of the face, either 'left' or 'right'. |
shift |
int
|
shift in the grid index to find the neighbour cell. -1 for left face. |
normal |
int
|
normal vector for the face. -1 for left face. |
Source code in src/pyelq/dispersion_model/finite_volume.py
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 | |
FiniteVolumeFaceRight
dataclass
Bases: FiniteVolumeFace
Set up face properties specific to a right-facing cell (i.e. outward normal is the positive unit vector).
Attributes:
| Name | Type | Description |
|---|---|---|
direction |
str
|
direction of the face, either 'left' or 'right'. |
shift |
int
|
shift in the grid index to find the neighbour cell. +1 for right face. |
normal |
int
|
normal vector for the face. +1 for right face. |
Source code in src/pyelq/dispersion_model/finite_volume.py
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 | |
SolverDiagonals
dataclass
Storage for the diagonals of the solver matrix for the finite volume method on a regular grid.
This class holds the diagonal components to construct the solver matrix. It is used for advection, diffusion and combined terms.
Attributes:
| Name | Type | Description |
|---|---|---|
B |
Union[ndarray, None]
|
shape=(total_number_cells, 1 + number_faces). Array containing all solver diagonals, i.e. containing all diagonals from self.B_central and self.B_neighbour. The first column is the central diagonal and the remaining columns are the off-diagonal terms. |
B_central |
Union[ndarray, None]
|
shape=(total_number_cells, 1). Array containing the central diagonal of the solver matrix. |
B_neighbour |
Union[ndarray, None]
|
shape=(total_number_cells, number_faces). Array containing the off-diagonals of the solver matrix. |
b_dirichlet |
Union[ndarray, None]
|
shape=(total_number_cells, 1). Vector containing contributions from Dirichlet boundary conditions at edge cells. |
b_neumann |
Union[ndarray, None]
|
shape=(total_number_cells, 1). Vector containing contributions from Neumann boundary conditions. |
Source code in src/pyelq/dispersion_model/finite_volume.py
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 | |