Boundary conditions
jax_lab.core.boundary_conditions.BoundaryCondition
Bases: object
Base class for boundary conditions in a LBM simulation.
This class provides a general structure for implementing boundary conditions. It includes methods for preparing the
boundary attributes and for applying the boundary condition. Specific boundary conditions should be implemented as
subclasses of this class, with the apply method overridden as necessary.
Attributes
lattice (Lattice): The lattice used in the simulation.
nx (int): The number of nodes in the x direction.
ny (int): The number of nodes in the y direction.
nz (int): The number of nodes in the z direction.
dim (int): The number of dimensions in the simulation (2 or 3).
precision_policy (PrecisionPolicy): The precision policy used in the simulation.
indices (array-like): The indices of the boundary nodes.
name (str or None): The name of the boundary condition. This should be set in subclasses.
is_solid (bool): Whether the boundary condition is for a solid boundary. This should be set in subclasses.
is_dynamic (bool): Whether the boundary condition is dynamic (changes over time). This should be set in subclasses.
needs_extra_configuration (bool): Whether the boundary condition requires extra configuration. This should be set in subclasses.
implementation_step (str): The lattice Boltzmann algorithm step at which the boundary condition is applied.
Source code in jax_lab/core/boundary_conditions.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 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 | |
apply
Applies the boundary condition.
Parameters
fout (jax.Array): Output distribution functions.
fin (jax.Array): Input distribution functions.
Returns
None
Notes
This method should be overridden in subclasses to implement the specific boundary condition. The method should modify the output distribution functions in place to apply the boundary condition.
Source code in jax_lab/core/boundary_conditions.py
configure
Configures the boundary condition.
Parameters
boundary_mask (array-like): The grid mask for the boundary voxels.
Returns
None
Notes
This method should be overridden in subclasses if the boundary condition requires extra configuration.
Source code in jax_lab/core/boundary_conditions.py
create_local_mask_and_normal_arrays
Creates local mask and normal arrays for the boundary condition.
Parameters
grid_mask (array-like): The grid mask for the lattice.
Returns
None
Notes
This method creates local mask and normal arrays for the boundary condition based on the grid mask.
If the boundary condition requires extra configuration, the configure method is called.
Source code in jax_lab/core/boundary_conditions.py
equilibrium
Compute equilibrium distribution function.
Parameters
rho (jax.numpy.ndarray): The density at each node in the lattice.
u (jax.numpy.ndarray): The velocity at each node in the lattice.
Returns
(jax.numpy.ndarray): The equilibrium distribution function at each node in the lattice.
Notes
This method computes the equilibrium distribution function based on the density and velocity. The computation is performed in the compute precision specified by the precision policy. The result is not cast to the output precision as this is function is used inside other functions that require the compute precision.
Source code in jax_lab/core/boundary_conditions.py
get_boundary_mask
Add jax.device_count() to the self.indices in x-direction, and 1 to the self.indices other directions This is to make sure the boundary condition is applied to the correct nodes as grid_mask is expanded by (jax.device_count(), 1, 1)
Parameters
grid_mask (array-like): The grid mask for the lattice.
Returns
boundaryMask : (array-like)
Source code in jax_lab/core/boundary_conditions.py
get_missing_indices
Returns two int8 arrays the same shape as boundary_mask. The non-zero entries of these arrays indicate missing directions that require BCs (imissing) as well as their corresponding opposite directions (iknown).
Parameters
boundary_mask (array-like): The boundary mask for the lattice.
Returns
(tuple of array-like): The missing and known indices for the boundary condition.
Notes
This method calculates the missing and known indices based on the boundary mask. The missing indices are the non-zero entries of the boundary mask, and the known indices are their corresponding opposite directions.
Source code in jax_lab/core/boundary_conditions.py
get_missing_mask
Returns three boolean arrays the same shape as boundary_mask. Note: these boundary masks are useful for reduction (eg. summation) operators of selected q-directions.
Parameters
boundary_mask (array-like): The boundary mask for the lattice.
Returns
(tuple of array-like): The missing, known, and middle masks for the boundary condition.
Notes
This method calculates the missing, known, and middle masks based on the boundary mask. The missing mask is the boundary mask, the known mask is the opposite directions of the missing mask, and the middle mask is the directions that are neither missing nor known.
Source code in jax_lab/core/boundary_conditions.py
get_normals
Calculates the normal vectors at the boundary nodes.
Parameters
boundary_mask (array-like): The boundary mask for the lattice.
Returns
(array-like): The normal vectors at the boundary nodes.
Notes
This method calculates the normal vectors by dotting the boundary mask with the main lattice directions.
Source code in jax_lab/core/boundary_conditions.py
momentum_exchange_force
Using the momentum exchange method to compute the boundary force vector exerted on the solid geometry based on [1] as described in [3]. Ref [2] shows how [1] is applicable to curved geometries only by using a bounce-back method (e.g. Bouzidi) that accounts for curved boundaries. NOTE: this function should be called after BC’s are imposed. [1] A.J.C. Ladd, Numerical simulations of particular suspensions via a discretized Boltzmann equation. Part 2 (numerical results), J. Fluid Mech. 271 (1994) 311-339. [2] R. Mei, D. Yu, W. Shyy, L.-S. Luo, Force evaluation in the lattice Boltzmann method involving curved geometry, Phys. Rev. E 65 (2002) 041203. [3] Caiazzo, A., & Junk, M. (2008). Boundary forces in lattice Boltzmann: Analysis of momentum exchange algorithm. Computers & Mathematics with Applications, 55(7), 1415-1423.
Parameters
f_poststreaming (jax.numpy.ndarray): The post-streaming distribution function at each node in the lattice.
f_postcollision (jax.numpy.ndarray): The post-collision distribution function at each node in the lattice.
Returns
(jax.numpy.ndarray): The force exerted on the solid geometry at each boundary node.
Notes
This method computes the force exerted on the solid geometry at each boundary node using the momentum exchange method. The force is computed based on the post-streaming and post-collision distribution functions. This method should be called after the boundary conditions are imposed.
Source code in jax_lab/core/boundary_conditions.py
momentum_flux
Compute the momentum flux.
Parameters
fneq (jax.numpy.ndarray): The non-equilibrium distribution function at each node in the lattice.
Returns
(jax.numpy.ndarray): The momentum flux at each node in the lattice.
Notes
This method computes the momentum flux by dotting the non-equilibrium distribution function with the lattice direction vectors.
Source code in jax_lab/core/boundary_conditions.py
prepare_populations
Prepares the distribution functions for the boundary condition.
Parameters
fout (jax.numpy.ndarray): The incoming distribution functions.
fin (jax.numpy.ndarray): The outgoing distribution functions.
implementation_step (str): The step in the lattice Boltzmann method algorithm at which the preparation is applied.
Returns
(jax.numpy.ndarray): The prepared distribution functions.
Notes
This method should be overridden in subclasses if the boundary condition requires preparation of the distribution functions during post-collision or post-streaming. See ExtrapolationBoundaryCondition for an example.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.BounceBack
Bases: BoundaryCondition
Bounce-back boundary condition for a lattice Boltzmann method simulation.
This class implements a full-way bounce-back boundary condition, where particles hitting the boundary are reflected back in the direction they came from. The boundary condition is applied after the collision step.
Attributes
name (str): The name of the boundary condition. For this class, it is “BounceBackFullway”.
implementation_step (str): The step in the lattice Boltzmann method algorithm at which the boundary condition is applied. For this class, it is “PostCollision”.
theta (jax.numpy.ndarray; Default: None): Contact angle, applied for multiphase flows and only set for wall boundary conditions.
phi (jax.numpy.ndarray; Default: None): Contact angle parameter phi, applied for multiphase flows and only set for wall boundary conditions.
delta_rho (jax.numpy.ndarray; Default: None): Contact angle parameter delta_rho, applied for multiphase flows and only set for wall boundary conditions.
Source code in jax_lab/core/boundary_conditions.py
apply
Applies the bounce-back boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
fin (jax.numpy.ndarray): The input distribution functions.
Returns
(jax.numpy.ndarray): The modified output distribution functions after applying the boundary condition.
Notes
This method applies the bounce-back boundary condition by reflecting the input distribution functions at the boundary nodes in the opposite direction.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.BounceBackMoving
Bases: BoundaryCondition
Moving bounce-back boundary condition for a lattice Boltzmann method simulation.
This class implements a moving bounce-back boundary condition, where particles hitting the boundary are reflected back in the direction they came from, with an additional velocity due to the movement of the boundary. The boundary condition is applied after the collision step.
Attributes
name (str): The name of the boundary condition. For this class, it is “BounceBackFullwayMoving”.
implementation_step (str): The step in the lattice Boltzmann method algorithm at which the boundary condition is applied. For this class, it is “PostCollision”.
is_dynamic (bool): Whether the boundary condition is dynamic (changes over time). For this class, it is True.
update_function (function): A function that updates the boundary condition. For this class, it is a function that updates the boundary
condition based on the current time step. The signature of the function is update_function(time) -> (indices, vel),
theta (jax.numpy.ndarray; Default: None): Contact angle, applied for multiphase flows and only set for wall boundary conditions.
phi (jax.numpy.ndarray; Default: None): Contact angle parameter phi, applied for multiphase flows and only set for wall boundary conditions.
delta_rho (pytree of jax.numpy.ndarray; Default: None): Contact angle parameter delta_rho, applied for multiphase flows and only set for wall boundary conditions.
Source code in jax_lab/core/boundary_conditions.py
apply
Applies the moving bounce-back boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
fin (jax.numpy.ndarray): The input distribution functions.
time (int): The current time step.
Returns
(jax.numpy.ndarray): The modified output distribution functions after applying the boundary condition.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.BounceBackHalfway
Bases: BoundaryCondition
Halfway bounce-back boundary condition for a lattice Boltzmann method simulation.
This class implements a halfway bounce-back boundary condition. The boundary condition is applied after the streaming step.
Attributes
name (str): The name of the boundary condition. For this class, it is “BounceBackHalfway”.
implementation_step (str): The step in the lattice Boltzmann method algorithm at which the boundary condition is applied. For this class, it is “PostStreaming”.
needs_extra_configuration (bool): Whether the boundary condition needs extra configuration before it can be applied. For this class, it is True.
is_solid (bool): Whether the boundary condition represents a solid boundary. For this class, it is True.
solid_indices (tuple): Original solid-node indices, stored by configure before self.indices is shifted to the adjacent fluid nodes. Used by multiphase wetting schemes.
vel (array-like): The prescribed value of velocity vector for the boundary condition. No-slip BC is assumed if vel=None (default).
theta (jax.numpy.ndarray; Default: None): Contact angle, applied for multiphase flows and only set for wall boundary conditions.
phi (jax.numpy.ndarray; Default: None): Contact angle parameter phi, applied for multiphase flows and only set for wall boundary conditions.
delta_rho (pytree of jax.numpy.ndarray; Default: None): Contact angle parameter delta_rho, applied for multiphase flows and only set for wall boundary conditions.
Source code in jax_lab/core/boundary_conditions.py
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 | |
apply
Applies the halfway bounce-back boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
fin (jax.numpy.ndarray): The input distribution functions.
Returns
(jax.numpy.ndarray): The modified output distribution functions after applying the boundary condition.
Source code in jax_lab/core/boundary_conditions.py
configure
Configures the boundary condition.
Parameters
boundary_mask (array-like): The grid mask for the boundary voxels.
Returns
None
Notes
This method performs an index shift for the halfway bounce-back boundary condition. It updates the indices of the boundary nodes to be the indices of fluid nodes adjacent of the solid nodes.
Source code in jax_lab/core/boundary_conditions.py
prepare_populations
Pin solid-node populations to the rest equilibrium (rho = 1, u = 0).
Halfway bounce-back never constrains the populations at the solid nodes, so they evolve freely and can diverge. This is harmless in single phase simulations but multiphase wetting schemes read wall densities, so the solid nodes are reset after every streaming step. The wetted wall density used in the force computation is overwritten by apply_contact_angle, so the pinned value never enters the wetting force directly.
Parameters
fout (jax.numpy.ndarray): The post-streaming or post-collision distribution functions.
fin (jax.numpy.ndarray): The pre-collision or post-collision distribution functions.
implementation_step (str): The step at which the preparation is applied.
Returns
(jax.numpy.ndarray): The distribution functions with solid nodes reset after streaming.
Source code in jax_lab/core/boundary_conditions.py
reflect_missing
staticmethod
Core halfway bounce-back math: set each missing direction to the post-streaming value coming from its known (opposite) direction. Pure function of its arguments (no BC-instance state), so it is reusable both by apply() (global indices) and by a local (per-shard) bounce-back kernel operating on a gathered block with the same (n, q) shape.
Parameters
fbd (jax.numpy.ndarray): Post-streaming distribution functions at the boundary nodes, shape (n, q).
fin_bd (jax.numpy.ndarray): Post-streaming distribution functions at the same boundary nodes, shape (n, q).
imissing (array-like): Missing-direction indices, shape (n, q).
iknown (array-like): Known (opposite) direction indices, shape (n, q).
Returns
(jax.numpy.ndarray): fbd with each missing direction set from its known direction.
Source code in jax_lab/core/boundary_conditions.py
velocity_correction
staticmethod
Core halfway bounce-back velocity-forcing math, factored out of impose_boundary_vel so it is reusable by a local (per-shard) bounce-back kernel. Pure function of its arguments; vel=0 is a safe no-op, so a local kernel merging several boundary conditions can always call this instead of conditionally skipping it per boundary condition.
Parameters
fbd (jax.numpy.ndarray): Distribution functions at the boundary nodes, shape (n, q).
imissing (array-like): Missing-direction indices, shape (n, q).
iknown (array-like): Known (opposite) direction indices, shape (n, q).
vel (jax.numpy.ndarray): Prescribed velocity vector, shape (n, dim).
w (jax.numpy.ndarray): Lattice weights, shape (q,).
c (jax.numpy.ndarray): Lattice velocity vectors, shape (dim, q).
Returns
(jax.numpy.ndarray): fbd with the velocity correction applied.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.EquilibriumBC
Bases: BoundaryCondition
Equilibrium boundary condition for a lattice Boltzmann method simulation.
This class implements an equilibrium boundary condition, where the distribution function at the boundary nodes is set to the equilibrium distribution function. The boundary condition is applied after the streaming step.
Attributes
name (str): The name of the boundary condition. For this class, it is “EquilibriumBC”.
implementation_step (str): The step in the lattice Boltzmann method algorithm at which the boundary condition is applied. For this class, it is “PostStreaming”.
out (jax.numpy.ndarray): The equilibrium distribution function at the boundary nodes.
Source code in jax_lab/core/boundary_conditions.py
apply
Applies the equilibrium boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
fin (jax.numpy.ndarray): The input distribution functions.
Returns
(jax.numpy.ndarray): The modified output distribution functions after applying the boundary condition.
Notes
This method applies the equilibrium boundary condition by setting the output distribution functions at the boundary nodes to the equilibrium distribution function.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.DoNothing
Bases: BoundaryCondition
Preserve post-collision populations at selected boundary nodes.
Parameters
indices (tuple of numpy.ndarray): Boundary-node indices.
grid_info (dict): Grid and lattice metadata.
precision_policy (PrecisionPolicy): Compute and output precision policy.
Notes
Streaming is skipped at these nodes by returning the post-collision populations after streaming. This avoids values wrapping into the domain from the opposite side of the rolled population array.
Source code in jax_lab/core/boundary_conditions.py
apply
Applies the do-nothing boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
fin (jax.numpy.ndarray): The input distribution functions.
Returns
jax.numpy.ndarray The modified output distribution functions after applying the boundary condition.
Notes
This method applies the do-nothing boundary condition by simply returning the input distribution functions at the boundary nodes.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.ZouHe
Bases: BoundaryCondition
Zou-He boundary condition for a lattice Boltzmann method simulation.
This class implements the Zou-He boundary condition, which is a non-equilibrium bounce-back boundary condition. It can be used to set inflow and outflow boundary conditions with prescribed pressure or velocity.
Attributes
name (str): The name of the boundary condition. For this class, it is “ZouHe”.
implementation_step (str): The step in the lattice Boltzmann method algorithm at which the boundary condition is applied. For this class,it is “PostStreaming”.
type (str): The type of the boundary condition. It can be either ‘velocity’ for a prescribed velocity boundary condition, or ‘pressure’ for a prescribed pressure boundary condition.
prescribed (float or array-like): The prescribed values for the boundary condition. It can be either the prescribed velocities for a ‘velocity’
boundary condition, or the prescribed pressures for a ‘pressure’ boundary condition.
References
Zou, Q., & He, X. (1997). On pressure and velocity boundary conditions for the lattice Boltzmann BGK model. Physics of Fluids, 9(6), 1591-1598. doi:10.1063/1.869307
Source code in jax_lab/core/boundary_conditions.py
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 | |
apply
Applies the Zou-He boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
_ (jax.numpy.ndarray): The input distribution functions. This is not used in this method.
Returns
(jax.numpy.ndarray): The modified output distribution functions after applying the boundary condition.
Notes
This method applies the Zou-He boundary condition by first computing the equilibrium distribution functions based on the prescribed values and the type of boundary condition, and then setting the unknown distribution functions based on the non-equilibrium bounce-back method. Tangential velocity is not ensured to be zero by adding transverse contributions based on Hecth & Harting (2010) (doi:10.1088/1742-5468/2010/01/P01018) as it caused numerical instabilities at higher Reynolds numbers. One needs to use “Regularized” BC at higher Reynolds.
Source code in jax_lab/core/boundary_conditions.py
bounceback_nonequilibrium
Calculate unknown populations using bounce-back of non-equilibrium populations a la original Zou & He formulation
Source code in jax_lab/core/boundary_conditions.py
calculate_equilibrium
This is the ZouHe method of calculating the missing macroscopic variables at the boundary.
Source code in jax_lab/core/boundary_conditions.py
calculate_rho
Calculate density based on the prescribed velocity (Zou/He BC)
Source code in jax_lab/core/boundary_conditions.py
calculate_vel
Calculate velocity based on the prescribed pressure/density (Zou/He BC)
Source code in jax_lab/core/boundary_conditions.py
configure
Correct boundary indices to ensure that only voxelized surfaces with normal vectors along main cartesian axes are assigned this type of BC.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.Regularized
Bases: ZouHe
Regularized boundary condition for a lattice Boltzmann method simulation.
This class implements the regularized boundary condition, which is a non-equilibrium bounce-back boundary condition with additional regularization. It can be used to set inflow and outflow boundary conditions with prescribed pressure or velocity.
Attributes
name (str): The name of the boundary condition. For this class, it is “Regularized”.
Qi (numpy.ndarray): The Qi tensor, which is used in the regularization of the distribution functions.
References
Latt, J. (2007). Hydrodynamic limit of lattice Boltzmann equations. PhD thesis, University of Geneva.
Latt, J., Chopard, B., Malaspinas, O., Deville, M., & Michler, A. (2008). Straight velocity boundaries in the
lattice Boltzmann method. Physical Review E, 77(5), 056703. doi:10.1103/PhysRevE.77.056703
Source code in jax_lab/core/boundary_conditions.py
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 | |
apply
Applies the regularized boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
_ (jax.numpy.ndarray): The input distribution functions. This is not used in this method.
Returns
(jax.numpy.ndarray): The modified output distribution functions after applying the boundary condition.
Notes
This method applies the regularized boundary condition by first computing the equilibrium distribution functions based on the prescribed values and the type of boundary condition, then setting the unknown distribution functions based on the non-equilibrium bounce-back method, and finally regularizing the distribution functions.
Source code in jax_lab/core/boundary_conditions.py
construct_symmetric_lattice_moment
Construct the symmetric lattice moment Qi.
The Qi tensor is used in the regularization of the distribution functions. It is defined as Qi = cc - cs^2*I, where cc is the tensor of lattice velocities, cs is the speed of sound, and I is the identity tensor.
Source code in jax_lab/core/boundary_conditions.py
regularize_fpop
Regularizes the distribution functions by adding non-equilibrium contributions based on second moments of fpop.
Parameters
fpop (jax.numpy.ndarray): The distribution functions.
feq (jax.numpy.ndarray): The equilibrium distribution functions.
Returns
(jax.numpy.ndarray): The regularized distribution functions.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.ExtrapolationOutflow
Bases: BoundaryCondition
Extrapolation outflow boundary condition for a lattice Boltzmann method simulation.
This class implements the extrapolation outflow boundary condition, which is a type of outflow boundary condition that uses extrapolation to avoid strong wave reflections.
Attributes
name (str): The name of the boundary condition. For this class, it is “ExtrapolationOutflow”.
sound_speed (float): The speed of sound in the simulation.
References
Geier, M., Schönherr, M., Pasquali, A., & Krafczyk, M. (2015). The cumulant lattice Boltzmann equation in three dimensions: Theory and validation. Computers & Mathematics with Applications, 70(4), 507-547. doi:10.1016/j.camwa.2015.05.001.
Source code in jax_lab/core/boundary_conditions.py
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 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 1085 1086 1087 1088 1089 | |
apply
Applies the extrapolation outflow boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
fin (jax.numpy.ndarray): The input distribution functions.
Returns
(jax.numpy.ndarray): The modified output distribution functions after applying the boundary condition.
Source code in jax_lab/core/boundary_conditions.py
configure
Configure one inward fluid neighbour for every boundary node.
Parameters
boundary_mask (np.ndarray): The grid mask for the boundary voxels.
Source code in jax_lab/core/boundary_conditions.py
prepare_populations
Prepares the distribution functions for the boundary condition.
Parameters
fout (jax.numpy.ndarray): The incoming distribution functions.
fin (jax.numpy.ndarray): The outgoing distribution functions.
implementation_step (str): The step in the lattice Boltzmann method algorithm at which the preparation is applied.
Returns
(jax.numpy.ndarray): The prepared distribution functions.
Notes
Because this function is called “PostCollision”, f_poststreaming refers to previous time step or t-1
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.InterpolatedBounceBackBouzidi
Bases: BounceBackHalfway
A local single-node version of the interpolated bounce-back boundary condition due to Bouzidi for a lattice Boltzmann method simulation.
This class implements a interpolated bounce-back boundary condition. The boundary condition is applied after the streaming step.
Attributes
name (str): The name of the boundary condition. For this class, it is “InterpolatedBounceBackBouzidi”. implicit_distances (array-like): An array of shape (nx,ny,nz) indicating the signed-distance field from the solid walls weights (array-like): An array of shape (number_of_bc_cells, q) initialized as None and constructed using implicit_distances array during runtime. These “weights” are associated with the fractional distance of fluid cell to the boundary position defined as: weights(dir_i) = |x_fluid - x_boundary(dir_i)| / |x_fluid - x_solid(dir_i)|.
theta (jax.numpy.ndarray; Default: None): Contact angle, applied for multiphase flows and only set for wall boundary conditions.
phi (jax.numpy.ndarray; Default: None): Contact angle parameter phi, applied for multiphase flows and only set for wall boundary conditions.
delta_rho (jax.numpy.ndarray; Default: None): Contact angle parameter delta_rho, applied for multiphase flows and only set for wall boundary conditions.
Source code in jax_lab/core/boundary_conditions.py
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 | |
apply
Applies the halfway bounce-back boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
fin (jax.numpy.ndarray): The input distribution functions.
Returns
(jax.numpy.ndarray): The modified output distribution functions after applying the boundary condition.
Source code in jax_lab/core/boundary_conditions.py
interpolate_missing
staticmethod
Core Bouzidi interpolated bounce-back math. Pure function of its arguments (no BC-instance state), so it is reusable both by apply() (global indices) and by a local (per-shard) bounce-back kernel operating on a gathered block with the same (n, q) shape.
Parameters
fbd (jax.numpy.ndarray): Post-streaming distribution functions at the boundary nodes, shape (n, q).
fin_bd (jax.numpy.ndarray): Post-collision distribution functions at the boundary nodes, shape (n, q).
fout_bd (jax.numpy.ndarray): Post-streaming distribution functions at the boundary nodes, shape (n, q).
imissing (array-like): Missing-direction indices, shape (n, q).
iknown (array-like): Known (opposite) direction indices, shape (n, q).
weights (array-like): Proximity-ratio interpolation weights, shape (n, q).
Returns
(jax.numpy.ndarray): fbd with each missing direction set from the interpolated value.
Source code in jax_lab/core/boundary_conditions.py
set_proximity_ratio
Creates the interpolation data needed for the boundary condition.
Returns
None. The function updates the object’s weights attribute in place.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.InterpolatedBounceBackDifferentiable
Bases: InterpolatedBounceBackBouzidi
A differentiable variant of the “InterpolatedBounceBackBouzidi” BC scheme. This BC is now differentiable at self.weight = 0.5 unlike the original Bouzidi scheme which switches between 2 equations at weight=0.5. Refer to [1] (their Appendix E) for more information.
References
[1] Geier, M., Schönherr, M., Pasquali, A., & Krafczyk, M. (2015). The cumulant lattice Boltzmann equation in three dimensions: Theory and validation. Computers & Mathematics with Applications, 70(4), 507-547. doi:10.1016/j.camwa.2015.05.001.
This class implements a interpolated bounce-back boundary condition. The boundary condition is applied after the streaming step.
Attributes
name (str): The name of the boundary condition. For this class, it is “InterpolatedBounceBackDifferentiable”.
Source code in jax_lab/core/boundary_conditions.py
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 | |
apply
Applies the halfway bounce-back boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
fin (jax.numpy.ndarray): The input distribution functions.
Returns
jax.numpy.ndarray The modified output distribution functions after applying the boundary condition.
Source code in jax_lab/core/boundary_conditions.py
interpolate_missing
staticmethod
Core differentiable interpolated bounce-back math. Pure function of its arguments (no BC-instance state), so it is reusable both by apply() (global indices) and by a local (per-shard) bounce-back kernel operating on a gathered block with the same (n, q) shape.
Parameters
fbd (jax.numpy.ndarray): Post-streaming distribution functions at the boundary nodes, shape (n, q).
fin_bd (jax.numpy.ndarray): Post-collision distribution functions at the boundary nodes, shape (n, q).
fout_bd (jax.numpy.ndarray): Post-streaming distribution functions at the boundary nodes, shape (n, q).
imissing (array-like): Missing-direction indices, shape (n, q).
iknown (array-like): Known (opposite) direction indices, shape (n, q).
weights (array-like): Proximity-ratio interpolation weights, shape (n, q).
Returns
(jax.numpy.ndarray): fbd with each missing direction set from the interpolated value.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.ExtrapolationOutflowMultiphase
Bases: BoundaryCondition
Extrapolation boundary condition for multiphase flows.
Attributes
name (str): The name of the boundary condition. For this class, it is “NonEquilibriumExtrapolation”.
References
- Zhao-Li, G., Chu-Guang, Z. & Bao-Chang, S. Non-equilibrium extrapolation method for velocity and pressure boundary conditions in the lattice Boltzmann method. Chinese Phys. 11, 366-374 (2002).
Source code in jax_lab/core/boundary_conditions.py
apply
Applies the non-equilibrium extrapolation boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
_ (jax.numpy.ndarray): The input distribution functions, not used in this function
Returns
jax.numpy.ndarray The modified output distribution functions after applying the boundary condition.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.NonEquilibriumExtrapolation
Bases: BoundaryCondition
Non-equilibrium extrapolation boundary condition.
Attributes
name (str): The name of the boundary condition. For this class, it is “NonEquilibriumExtrapolation”.
References
- Zhao-Li, G., Chu-Guang, Z. & Bao-Chang, S. Non-equilibrium extrapolation method for velocity and pressure boundary conditions in the lattice Boltzmann method. Chinese Phys. 11, 366-374 (2002).
Source code in jax_lab/core/boundary_conditions.py
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 | |
apply
Applies the non-equilibrium extrapolation boundary condition. Density and velocity are evaluated only at the boundary and neighbor nodes (not over the whole domain) before being indexed.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
_ (jax.numpy.ndarray): The input distribution functions, not used in this function
Returns
jax.numpy.ndarray The modified output distribution functions after applying the boundary condition.
Source code in jax_lab/core/boundary_conditions.py
find_neighbors
Locate the nearest neighbouring fluid site (one per boundary node, along the inward normal) used to extrapolate the non-equilibrium part of the distribution. Must be called after self.normals is available, i.e. after BoundaryCondition.create_local_mask_and_normal_arrays has run.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.ExactNonEquilibriumExtrapolation
Bases: BoundaryCondition
Non-equilibrium extrapolation boundary condition but with added correction step to correct the density at the boundary node.
Attributes
name (str): The name of the boundary condition. For this class, it is “ExactNonEquilibriumExtrapolation”.
References
-
Zhao-Li, G., Chu-Guang, Z. & Bao-Chang, S. Non-equilibrium extrapolation method for velocity and pressure boundary conditions in the lattice Boltzmann method. Chinese Phys. 11, 366-374 (2002).
-
Fei, L., Qin, F., Zhao, J., Derome, D. & Carmeliet, J. Lattice Boltzmann modelling of isothermal two-component evaporation in porous media. Journal of Fluid Mechanics 955, A18 (2023).
Source code in jax_lab/core/boundary_conditions.py
1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 | |
apply
Applies the non-equilibrium extrapolation boundary condition. Density and velocity are evaluated only at the boundary and neighbor nodes (not over the whole domain) before being indexed.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
_ (jax.numpy.ndarray): The input distribution functions, not used in this function
Returns
(jax.numpy.ndarray): The modified output distribution functions after applying the boundary condition.
Source code in jax_lab/core/boundary_conditions.py
compute_NEQ_weights
Define the weight function used to correct the distribution values obtained Non-Equilibrium extrapolation boundary condition.
Typically, it is defined as:
w(i) = g1 if |x - x’| = 1 = g2 if |x - x’| = sqrt(2) = 0, otherwise
Here d is the dimension of problem and x’ are the neighboring points.
Some examples values could be: For D2Q9: g1 = 1/3 and g2 = 1/12 For D3Q19 g1 = 1/6 and g2 = 1/12
Returns
G_ff: jax.numpy.ndarray. Dimension: (q, )
Source code in jax_lab/core/boundary_conditions.py
find_neighbors
Locate the nearest neighbouring fluid site (one per boundary node, along the inward normal) used to extrapolate the non-equilibrium part of the distribution. Must be called after self.normals is available, i.e. after BoundaryCondition.create_local_mask_and_normal_arrays has run.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.ConvectiveOutflow
Bases: BoundaryCondition
Extrapolation outflow boundary condition for a lattice Boltzmann method simulation.
This class implements the extrapolation outflow boundary condition, which is a type of outflow boundary condition that uses extrapolation to avoid strong wave reflections.
Attributes
name (str): The name of the boundary condition. For this class, it is “ConvectiveOutflow”.
References
- Lou, Q., Guo, Z. & Shi, B. Evaluation of outflow boundary conditions for two-phase lattice Boltzmann equation. Phys. Rev. E 87, 063301 (2013). doi: doi.org/10.1103/PhysRevE.87.063301
Source code in jax_lab/core/boundary_conditions.py
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 | |
apply
Applies the convective outflow boundary condition.
Parameters
fout (jax.numpy.ndarray): The output distribution functions.
fin (jax.numpy.ndarray): The input distribution functions.
Returns
jax.numpy.ndarray The modified output distribution functions after applying the boundary condition.
Source code in jax_lab/core/boundary_conditions.py
configure
Correct boundary indices to ensure that only voxelized surfaces with normal vectors along main cartesian axes are assigned this type of BC.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.ThermalBoundaryCondition
Bases: object
Base class for thermal (temperature field) boundary conditions used by the hybrid thermal solver in thermal.py.
Unlike the LBM boundary conditions above which act on distribution functions, thermal boundary conditions act directly on the temperature field of the finite difference solver.
Parameters
indices (tuple of numpy.ndarray): Tuple of index arrays selecting the boundary nodes, one array per spatial axis (e.g. tuple(wall_indices.T)).
Source code in jax_lab/core/boundary_conditions.py
apply
Apply the boundary condition to the temperature field.
Parameters
T (jax.numpy.ndarray): Temperature field of shape (nx, ny, 1) in 2D or (nx, ny, nz, 1) in 3D.
timestep (int): Current timestep, available for time dependent conditions.
Returns
jax.numpy.ndarray: Temperature field with the boundary condition applied.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.DirichletTemperature
Bases: ThermalBoundaryCondition
Dirichlet (prescribed temperature) boundary condition: T = T_w at the boundary nodes.
Parameters
indices (tuple of numpy.ndarray): Index arrays of the boundary nodes.
prescribed (float or numpy.ndarray): Prescribed wall temperature. Either a scalar applied to all nodes or an array of shape (n, 1) with one value per boundary node.
Source code in jax_lab/core/boundary_conditions.py
jax_lab.core.boundary_conditions.NeumannTemperature
Bases: ThermalBoundaryCondition
Neumann (prescribed normal temperature gradient) boundary condition, imposed with a first order one-sided difference over unit spacing: T_wall = T_interior + q, where q = dT/dn is the prescribed gradient along the outward normal (q = 0 gives an adiabatic wall).
Assumes the interior neighbor of every boundary node lies one node along the negated outward normal. Corner nodes shared with a Dirichlet boundary should be listed in the Dirichlet condition as well, appended after this one, so the Dirichlet value takes precedence.
Parameters
indices (tuple of numpy.ndarray): Index arrays of the boundary nodes.
normal (sequence of int): Outward unit normal of the boundary, e.g. (0, 1) for the top wall in 2D or (0, 0, -1) for the bottom wall in 3D.
prescribed (float or numpy.ndarray): Prescribed outward normal gradient. Either a scalar or an array of shape (n, 1). Defaults to 0 (adiabatic).