API Reference¶
This page is generated from the Python docstrings. For task-oriented usage, start with the component pages and examples.
gbmsc_pde
¶
Grid-Based Multinode Shepard Collocation solvers for PDEs.
BoundaryConditions
¶
Boundary-condition container for rectangular source-node rows.
Conditions are registered by flattened source-node id. Dirichlet rows
replace the corresponding PDE row by u_i = value. Neumann and Robin
rows use the derivative matrices assembled by the PDE solver. Scalars are
broadcast to all supplied nodes; arrays must have the same length as
nodes.
Source code in src/gbmsc_pde/boundary/conditions.py
10 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 | |
add_dirichlet(nodes, values)
¶
Add Dirichlet conditions u_i = value on rectangular grid nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
int or ndarray
|
Flattened source-node ids. |
required |
values
|
float or ndarray
|
Scalar value or one value per node. |
required |
Source code in src/gbmsc_pde/boundary/conditions.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
add_neumann(nodes, outwardnormal, fluxes)
¶
Add Neumann conditions du/dn = flux on grid nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
int or ndarray
|
Flattened source-node ids. |
required |
outwardnormal
|
tuple
|
Normal components |
required |
fluxes
|
float or ndarray
|
Scalar flux or one flux per node. |
required |
Source code in src/gbmsc_pde/boundary/conditions.py
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 | |
add_neumann_as_second_condition(nodes, outwardnormal, fluxes, rows)
¶
Add Neumann equations on user-selected matrix rows.
This compatibility method is for augmented systems where a Neumann
boundary equation should be imposed as an additional/second condition
rather than replacing the row associated with node.
Source code in src/gbmsc_pde/boundary/conditions.py
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 | |
add_robin(nodes, outwardnormal, alphas, betas, values)
¶
Add Robin conditions alpha*u + beta*du/dn = value on grid nodes.
alphas, betas, and values may be scalars or arrays with
one entry per node.
Source code in src/gbmsc_pde/boundary/conditions.py
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 | |
apply(A, b, Mx, My)
¶
Apply all registered conditions to an assembled rectangular system.
Source code in src/gbmsc_pde/boundary/conditions.py
223 224 225 226 227 228 229 230 231 | |
GBMSCApproximation
¶
Grid-Based Shepard approximation on a structured grid.
The approximation blends local tensor-product Lagrange polynomials defined
on sampled subgrids of a :class:~gbmsc_pde.source_grid.grid.SourceGrid. It is used
both for interpolation at arbitrary coordinates and for sparse nodal
differential operators in the rectangular-domain PDE solver.
For nodal PDE operators, support_mode controls the normalization:
"active"
Use only sampled subgrids that contain the evaluated source node. This
is the original sparse rectangular-domain PDE mode.
"all"
Keep the sparse active contributors at source nodes, but normalize the
Shepard denominator over all sampled subgrids.
"nodal_limit"
Use the source-node limiting formula. The common singular factor is
cancelled from all active subgrids containing the source node before
evaluating the weight values and derivatives.
Interpolation at arbitrary query coordinates uses all sampled subgrids.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
SourceGrid
|
Structured source grid. |
step |
tuple[int, int]
|
Sampling stride for local subgrids. |
subgrids_step_row |
(ndarray, shape(S, m))
|
Flattened sampled local subgrid node ids, where
|
support_mode |
{active, all, nodal_limit}
|
Nodal operator normalization mode. |
Source code in src/gbmsc_pde/approximation/shepard.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 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 1090 1091 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 | |
__init__(grid, step=(1, 1), mu=2.005, eps=1e-12, support_mode='active')
¶
Initialize the Grid-Based Shepard approximation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
SourceGrid
|
Structured source grid providing source-node coordinates, local subgrids, and pairwise distances. |
required |
step
|
tuple[int, int]
|
Sampling stride for local subgrid starts. |
(1, 1)
|
mu
|
float
|
Shepard exponent parameter. The implementation stores |
2.005
|
eps
|
float
|
Distance floor used to avoid division by zero and logarithms of zero. |
1e-12
|
support_mode
|
(active, all, nodal_limit)
|
Nodal PDE-operator support mode. |
"active"
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Source code in src/gbmsc_pde/approximation/shepard.py
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 | |
eval_weight_functions_at_nodes_all_denominator_minmax_shift(second_derivatives=True, block_s=64)
¶
Compute nodal Shepard weights with active contributors and all denominator.
The returned arrays have the same (S, m) shape as
:meth:eval_weight_functions_at_nodes_data_minmax_shift: one row for
each retained/sampled subgrid and one column for each local node. Only
the normalization denominator is enlarged to all sampled subgrids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
second_derivatives
|
bool
|
Whether to also return second derivatives of the weights. |
True
|
block_s
|
int
|
Number of sampled subgrids processed per vectorized block. |
64
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ...]
|
|
Source code in src/gbmsc_pde/approximation/shepard.py
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 | |
eval_weight_functions_at_nodes_data_minmax_shift(second_derivatives=True, block_s=128)
¶
Compute active-mode nodal Shepard weights and derivatives.
For each source-node row, only subgrids containing that source node participate in both the contributors and the denominator. The implementation uses shifted log-ratios,
f_i = 1 / sum_j exp(z_j), z_j = mu * (A_i - A_j)
and evaluates exp(z_j - max(z)) instead of directly forming
exp(z_j).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
second_derivatives
|
bool
|
Whether to also return second derivatives of the weights. |
True
|
block_s
|
int
|
Number of sampled subgrids processed per vectorized block. |
128
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ...]
|
|
Source code in src/gbmsc_pde/approximation/shepard.py
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 | |
eval_weight_functions_at_nodes_nodal_limit(second_derivatives=True, block_s=128)
¶
Compute source-node limiting Shepard weights and derivatives.
For each source-node row, only subgrids containing that source node participate. The common singular factor is cancelled analytically before forming the normalized Shepard fraction. In the vectorized metric sums this is equivalent to using a neutral self-distance and zero self-contributions for first and second metric derivatives.
Source code in src/gbmsc_pde/approximation/shepard.py
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 1090 1091 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 | |
interpolator(x, y, u, *, return_derivatives=False, chunk=1000, interpolation_mode='exact_nodal', tolerance=1e-12, Mx=None, My=None)
¶
Interpolate a source-node field at arbitrary coordinates.
Query interpolation uses all sampled subgrids as contributors and normalizes the Shepard weights over all sampled subgrids. Computation is chunked and performed in log space to avoid overflow in the raw weights.
interpolation_mode="exact_nodal" returns exact nodal values when a
query point coincides with a source node within tolerance. Other
query points use true distances without an epsilon floor.
interpolation_mode="regularized" preserves the legacy epsilon-floor
behavior for all query points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(n_eval))
|
Query coordinates. |
required |
y
|
(array_like, shape(n_eval))
|
Query coordinates. |
required |
u
|
(array_like, shape(N))
|
Source-node values ordered like |
required |
return_derivatives
|
bool
|
If true, also return first derivatives |
False
|
chunk
|
int
|
Number of query points processed per block. |
1000
|
interpolation_mode
|
(exact_nodal, regularized)
|
Query distance policy. |
"exact_nodal"
|
tolerance
|
float
|
Source-node hit tolerance for |
1e-12
|
Mx
|
sparse matrices
|
Existing first-derivative operators. When
|
None
|
My
|
sparse matrices
|
Existing first-derivative operators. When
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in src/gbmsc_pde/approximation/shepard.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 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 | |
lagrange_derivatives_x_direction()
¶
Return repeated 1D Lagrange derivative matrices in the x direction.
Source code in src/gbmsc_pde/approximation/shepard.py
822 823 824 825 826 | |
lagrange_derivatives_y_direction()
¶
Return repeated 1D Lagrange derivative matrices in the y direction.
Source code in src/gbmsc_pde/approximation/shepard.py
828 829 830 831 832 | |
LinearPDE
¶
Linear PDE builder on a structured rectangular source grid.
The assembled equation has the form
div(D grad u) + v . grad u + r u = f
where diffusion and convection coefficients may be scalar, two-component constants, or field callables. Boundary conditions are applied separately by the solver/boundary-condition layer.
Source code in src/gbmsc_pde/pde/problem.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 | |
add_convection_term(coeff)
¶
Add convection coefficients for v . grad u.
Source code in src/gbmsc_pde/pde/problem.py
37 38 39 | |
add_diffusion_term(coeff)
¶
Add diffusion coefficients for div(D grad u).
Source code in src/gbmsc_pde/pde/problem.py
33 34 35 | |
add_reaction_term(coeff)
¶
Add reaction coefficient r for r*u.
Source code in src/gbmsc_pde/pde/problem.py
41 42 43 | |
add_source_term(source)
¶
Add right-hand side source field f.
Source code in src/gbmsc_pde/pde/problem.py
45 46 47 | |
assemble()
¶
Assemble A u = b on all rectangular source nodes.
Returns:
| Type | Description |
|---|---|
(A, b, Mx, My, Mxx, Myy)
|
Sparse PDE matrix, right-hand side, first-derivative matrices, and second-derivative matrices. |
Source code in src/gbmsc_pde/pde/problem.py
49 50 51 52 53 54 55 56 57 58 59 | |
LinearSolver
¶
Linear-system solver for rectangular-domain PDE problems.
LinearSolver assembles the PDE rows from :class:LinearPDE, applies
node-indexed boundary conditions, and solves the resulting square sparse
system for the source-node vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pde
|
LinearPDE
|
Configured rectangular linear PDE builder. |
required |
bcs
|
BoundaryConditions
|
Boundary conditions registered on flattened grid nodes. |
required |
Source code in src/gbmsc_pde/solvers/linear.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 | |
assemble()
¶
Assemble and boundary-modify the rectangular collocation system.
Returns:
| Type | Description |
|---|---|
(A, b, Mx, My, Mxx, Myy)
|
Boundary-modified sparse system, right-hand side, and first
and second derivative matrices. The same objects are stored on
|
Source code in src/gbmsc_pde/solvers/linear.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
solve(solver='direct', tol=1e-08, maxiter=None, preconditioner=None, return_data=False)
¶
Assemble, apply boundary conditions, and solve the linear system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
(direct, cg, gmres, bicgstab)
|
Linear solver. |
'direct'
|
tol
|
float
|
Tolerance for iterative solvers. |
1e-08
|
maxiter
|
int
|
Maximum iterations (defaults to N). |
None
|
preconditioner
|
object
|
Preconditioner LinearOperator, sparse matrix, or |
None
|
return_data
|
bool
|
If true, return |
False
|
Returns:
| Type | Description |
|---|---|
ndarray or tuple
|
Solution vector |
Source code in src/gbmsc_pde/solvers/linear.py
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 | |
SourceGrid
¶
Structured two-dimensional tensor-product grid.
SourceGrid is the rectangular-domain source-node container used by the
Grid-Based Multinode Shepard Collocation approximation. It stores the
global source nodes, all sliding local tensor-product subgrids, flattened
node coordinates, and pairwise coordinate differences used by the weight
formulas.
Attributes:
| Name | Type | Description |
|---|---|---|
grid_shape |
tuple[int, int]
|
Number of grid nodes |
subgrid_shape |
tuple[int, int]
|
Number of nodes in each local interpolation window |
N |
int
|
Total number of source nodes, equal to |
coords |
(ndarray, shape(N, 2))
|
Flattened source-node coordinates ordered consistently with
|
subgrids |
(ndarray, shape(N_x - n_x + 1, N_y - n_y + 1, n_x, n_y))
|
Sliding-window node-index view. |
diff_x, diff_y, dist |
(ndarray, shape(N, N))
|
Pairwise coordinate differences and squared Euclidean distances. |
Source code in src/gbmsc_pde/source_grid/grid.py
4 5 6 7 8 9 10 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 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 | |
__init__(grid_shape=(10, 10), subgrid_shape=(3, 3), xlim=(0.0, 1.0), ylim=(0.0, 1.0), limits=None)
¶
Initialize a rectangular structured grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_shape
|
tuple[int, int]
|
Number of source nodes in the x and y directions. |
(10, 10)
|
subgrid_shape
|
tuple[int, int]
|
Size of each local tensor-product interpolation window. |
(3, 3)
|
xlim
|
tuple[float, float]
|
Coordinate limits of the rectangular domain. |
(0.0, 1.0)
|
ylim
|
tuple[float, float]
|
Coordinate limits of the rectangular domain. |
(0.0, 1.0)
|
limits
|
tuple[tuple[float, float], tuple[float, float]]
|
Compatibility alias for |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If either shape is not two-dimensional, if a local subgrid is
larger than the global grid, or if |
Source code in src/gbmsc_pde/source_grid/grid.py
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 | |
boundary_indices()
¶
Return flattened node indices for the rectangular boundary.
The returned dictionary includes both geometric names
"left", "right", "bottom", "top" and coordinate
aliases "x_min", "x_max", "y_min", "y_max".
"all" contains the unique union of all four sides.
Source code in src/gbmsc_pde/source_grid/grid.py
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 | |
eval_function_at_nodes(f)
¶
Evaluate a scalar field at every source node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
callable
|
Function with signature |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(N))
|
Field values ordered like |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
RuntimeError
|
If |
ValueError
|
If the result cannot be converted to an array with shape
|
Source code in src/gbmsc_pde/source_grid/grid.py
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 | |
plot(solution, view='3d', cmap='viridis', contour_levels=20, show_colorbar=True, xlabel='X', ylabel='Y', zlabel='', title='', figsize=(5, 4), show=True)
¶
Plot a discrete scalar solution on this structured grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
ndarray
|
Solution values as either a flat |
required |
view
|
('2d', contour, contourf, '3d')
|
Plot style for the discrete solution. |
"2d"
|
show
|
bool
|
Whether to display the plot with |
True
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
Matplotlib figure and axes objects. |
Source code in src/gbmsc_pde/source_grid/grid.py
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 | |
subgrids_with_step(step=(1, 1))
¶
Return sampled local subgrids at a fixed stride.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
tuple[int, int]
|
Sampling stride |
(1, 1)
|
Returns:
| Type | Description |
|---|---|
subgrids, subgrids_x, subgrids_y : tuple[ndarray, ndarray, ndarray]
|
Sampled two-dimensional node windows and their one-dimensional x/y index windows. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the stride is not positive or is incompatible with the grid and local-window sizes. |
Source code in src/gbmsc_pde/source_grid/grid.py
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 | |
gbmsc_pde.source_grid.grid.SourceGrid
¶
Structured two-dimensional tensor-product grid.
SourceGrid is the rectangular-domain source-node container used by the
Grid-Based Multinode Shepard Collocation approximation. It stores the
global source nodes, all sliding local tensor-product subgrids, flattened
node coordinates, and pairwise coordinate differences used by the weight
formulas.
Attributes:
| Name | Type | Description |
|---|---|---|
grid_shape |
tuple[int, int]
|
Number of grid nodes |
subgrid_shape |
tuple[int, int]
|
Number of nodes in each local interpolation window |
N |
int
|
Total number of source nodes, equal to |
coords |
(ndarray, shape(N, 2))
|
Flattened source-node coordinates ordered consistently with
|
subgrids |
(ndarray, shape(N_x - n_x + 1, N_y - n_y + 1, n_x, n_y))
|
Sliding-window node-index view. |
diff_x, diff_y, dist |
(ndarray, shape(N, N))
|
Pairwise coordinate differences and squared Euclidean distances. |
Source code in src/gbmsc_pde/source_grid/grid.py
4 5 6 7 8 9 10 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 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 | |
__init__(grid_shape=(10, 10), subgrid_shape=(3, 3), xlim=(0.0, 1.0), ylim=(0.0, 1.0), limits=None)
¶
Initialize a rectangular structured grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_shape
|
tuple[int, int]
|
Number of source nodes in the x and y directions. |
(10, 10)
|
subgrid_shape
|
tuple[int, int]
|
Size of each local tensor-product interpolation window. |
(3, 3)
|
xlim
|
tuple[float, float]
|
Coordinate limits of the rectangular domain. |
(0.0, 1.0)
|
ylim
|
tuple[float, float]
|
Coordinate limits of the rectangular domain. |
(0.0, 1.0)
|
limits
|
tuple[tuple[float, float], tuple[float, float]]
|
Compatibility alias for |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If either shape is not two-dimensional, if a local subgrid is
larger than the global grid, or if |
Source code in src/gbmsc_pde/source_grid/grid.py
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 | |
boundary_indices()
¶
Return flattened node indices for the rectangular boundary.
The returned dictionary includes both geometric names
"left", "right", "bottom", "top" and coordinate
aliases "x_min", "x_max", "y_min", "y_max".
"all" contains the unique union of all four sides.
Source code in src/gbmsc_pde/source_grid/grid.py
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 | |
eval_function_at_nodes(f)
¶
Evaluate a scalar field at every source node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
callable
|
Function with signature |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(N))
|
Field values ordered like |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
RuntimeError
|
If |
ValueError
|
If the result cannot be converted to an array with shape
|
Source code in src/gbmsc_pde/source_grid/grid.py
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 | |
plot(solution, view='3d', cmap='viridis', contour_levels=20, show_colorbar=True, xlabel='X', ylabel='Y', zlabel='', title='', figsize=(5, 4), show=True)
¶
Plot a discrete scalar solution on this structured grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
ndarray
|
Solution values as either a flat |
required |
view
|
('2d', contour, contourf, '3d')
|
Plot style for the discrete solution. |
"2d"
|
show
|
bool
|
Whether to display the plot with |
True
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
Matplotlib figure and axes objects. |
Source code in src/gbmsc_pde/source_grid/grid.py
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 | |
subgrids_with_step(step=(1, 1))
¶
Return sampled local subgrids at a fixed stride.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
tuple[int, int]
|
Sampling stride |
(1, 1)
|
Returns:
| Type | Description |
|---|---|
subgrids, subgrids_x, subgrids_y : tuple[ndarray, ndarray, ndarray]
|
Sampled two-dimensional node windows and their one-dimensional x/y index windows. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the stride is not positive or is incompatible with the grid and local-window sizes. |
Source code in src/gbmsc_pde/source_grid/grid.py
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 | |
gbmsc_pde.approximation.shepard.GBMSCApproximation
¶
Grid-Based Shepard approximation on a structured grid.
The approximation blends local tensor-product Lagrange polynomials defined
on sampled subgrids of a :class:~gbmsc_pde.source_grid.grid.SourceGrid. It is used
both for interpolation at arbitrary coordinates and for sparse nodal
differential operators in the rectangular-domain PDE solver.
For nodal PDE operators, support_mode controls the normalization:
"active"
Use only sampled subgrids that contain the evaluated source node. This
is the original sparse rectangular-domain PDE mode.
"all"
Keep the sparse active contributors at source nodes, but normalize the
Shepard denominator over all sampled subgrids.
"nodal_limit"
Use the source-node limiting formula. The common singular factor is
cancelled from all active subgrids containing the source node before
evaluating the weight values and derivatives.
Interpolation at arbitrary query coordinates uses all sampled subgrids.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
SourceGrid
|
Structured source grid. |
step |
tuple[int, int]
|
Sampling stride for local subgrids. |
subgrids_step_row |
(ndarray, shape(S, m))
|
Flattened sampled local subgrid node ids, where
|
support_mode |
{active, all, nodal_limit}
|
Nodal operator normalization mode. |
Source code in src/gbmsc_pde/approximation/shepard.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 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 1090 1091 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 | |
__init__(grid, step=(1, 1), mu=2.005, eps=1e-12, support_mode='active')
¶
Initialize the Grid-Based Shepard approximation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
SourceGrid
|
Structured source grid providing source-node coordinates, local subgrids, and pairwise distances. |
required |
step
|
tuple[int, int]
|
Sampling stride for local subgrid starts. |
(1, 1)
|
mu
|
float
|
Shepard exponent parameter. The implementation stores |
2.005
|
eps
|
float
|
Distance floor used to avoid division by zero and logarithms of zero. |
1e-12
|
support_mode
|
(active, all, nodal_limit)
|
Nodal PDE-operator support mode. |
"active"
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Source code in src/gbmsc_pde/approximation/shepard.py
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 | |
eval_weight_functions_at_nodes_all_denominator_minmax_shift(second_derivatives=True, block_s=64)
¶
Compute nodal Shepard weights with active contributors and all denominator.
The returned arrays have the same (S, m) shape as
:meth:eval_weight_functions_at_nodes_data_minmax_shift: one row for
each retained/sampled subgrid and one column for each local node. Only
the normalization denominator is enlarged to all sampled subgrids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
second_derivatives
|
bool
|
Whether to also return second derivatives of the weights. |
True
|
block_s
|
int
|
Number of sampled subgrids processed per vectorized block. |
64
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ...]
|
|
Source code in src/gbmsc_pde/approximation/shepard.py
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 | |
eval_weight_functions_at_nodes_data_minmax_shift(second_derivatives=True, block_s=128)
¶
Compute active-mode nodal Shepard weights and derivatives.
For each source-node row, only subgrids containing that source node participate in both the contributors and the denominator. The implementation uses shifted log-ratios,
f_i = 1 / sum_j exp(z_j), z_j = mu * (A_i - A_j)
and evaluates exp(z_j - max(z)) instead of directly forming
exp(z_j).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
second_derivatives
|
bool
|
Whether to also return second derivatives of the weights. |
True
|
block_s
|
int
|
Number of sampled subgrids processed per vectorized block. |
128
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ...]
|
|
Source code in src/gbmsc_pde/approximation/shepard.py
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 | |
eval_weight_functions_at_nodes_nodal_limit(second_derivatives=True, block_s=128)
¶
Compute source-node limiting Shepard weights and derivatives.
For each source-node row, only subgrids containing that source node participate. The common singular factor is cancelled analytically before forming the normalized Shepard fraction. In the vectorized metric sums this is equivalent to using a neutral self-distance and zero self-contributions for first and second metric derivatives.
Source code in src/gbmsc_pde/approximation/shepard.py
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 1090 1091 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 | |
interpolator(x, y, u, *, return_derivatives=False, chunk=1000, interpolation_mode='exact_nodal', tolerance=1e-12, Mx=None, My=None)
¶
Interpolate a source-node field at arbitrary coordinates.
Query interpolation uses all sampled subgrids as contributors and normalizes the Shepard weights over all sampled subgrids. Computation is chunked and performed in log space to avoid overflow in the raw weights.
interpolation_mode="exact_nodal" returns exact nodal values when a
query point coincides with a source node within tolerance. Other
query points use true distances without an epsilon floor.
interpolation_mode="regularized" preserves the legacy epsilon-floor
behavior for all query points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(n_eval))
|
Query coordinates. |
required |
y
|
(array_like, shape(n_eval))
|
Query coordinates. |
required |
u
|
(array_like, shape(N))
|
Source-node values ordered like |
required |
return_derivatives
|
bool
|
If true, also return first derivatives |
False
|
chunk
|
int
|
Number of query points processed per block. |
1000
|
interpolation_mode
|
(exact_nodal, regularized)
|
Query distance policy. |
"exact_nodal"
|
tolerance
|
float
|
Source-node hit tolerance for |
1e-12
|
Mx
|
sparse matrices
|
Existing first-derivative operators. When
|
None
|
My
|
sparse matrices
|
Existing first-derivative operators. When
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in src/gbmsc_pde/approximation/shepard.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 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 | |
lagrange_derivatives_x_direction()
¶
Return repeated 1D Lagrange derivative matrices in the x direction.
Source code in src/gbmsc_pde/approximation/shepard.py
822 823 824 825 826 | |
lagrange_derivatives_y_direction()
¶
Return repeated 1D Lagrange derivative matrices in the y direction.
Source code in src/gbmsc_pde/approximation/shepard.py
828 829 830 831 832 | |
gbmsc_pde.approximation.shepard.lagrange_1d(X_nodes, xq=None, *, with_first_derivatives=True, with_second_derivatives=False, barycentric_weights=None)
¶
Barycentric Lagrange basis — log-stable and unified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_nodes
|
(m,) ndarray(float)
|
Distinct node coordinates. |
required |
xq
|
Optional[ndarray]
|
Query points. If None, the function treats |
None
|
with_first_derivatives
|
bool
|
Return first derivatives L' as well. |
True
|
with_second_derivatives
|
bool
|
Return second derivatives L'' in addition (only valid if
|
False
|
Returns:
| Type | Description |
|---|---|
Query mode (`xq` not None)
|
L : (l, m)
L, Lp : if |
Nodal mode (`xq` is None → treated as `xq=X_nodes`)
|
I, L1 : if |
Source code in src/gbmsc_pde/approximation/shepard.py
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 | |
gbmsc_pde.operators.differential.build_differential_operators(approximation)
¶
Build sparse nodal derivative operators on the source grid.
The returned matrices act on flattened source-node vectors ordered like
approximation.grid.coords. Rows are evaluated at source nodes. The
row support is determined by approximation.support_mode:
"active"
Active contributors and active denominator; this is the original
rectangular sparse PDE mode.
"all"
Active contributors with an all-subgrid denominator for nodal rows.
"nodal_limit"
Active source-node contributors with the common singular factor
cancelled before weight derivatives are evaluated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
approximation
|
GBMSCApproximation
|
Prepared Grid-Based Shepard approximation. |
required |
Returns:
| Type | Description |
|---|---|
Mx, My, Mxx, Myy : tuple[spmatrix, spmatrix, spmatrix, spmatrix]
|
Sparse first- and second-derivative matrices. |
Source code in src/gbmsc_pde/operators/differential.py
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 | |
gbmsc_pde.pde.problem.LinearPDE
¶
Linear PDE builder on a structured rectangular source grid.
The assembled equation has the form
div(D grad u) + v . grad u + r u = f
where diffusion and convection coefficients may be scalar, two-component constants, or field callables. Boundary conditions are applied separately by the solver/boundary-condition layer.
Source code in src/gbmsc_pde/pde/problem.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 | |
add_convection_term(coeff)
¶
Add convection coefficients for v . grad u.
Source code in src/gbmsc_pde/pde/problem.py
37 38 39 | |
add_diffusion_term(coeff)
¶
Add diffusion coefficients for div(D grad u).
Source code in src/gbmsc_pde/pde/problem.py
33 34 35 | |
add_reaction_term(coeff)
¶
Add reaction coefficient r for r*u.
Source code in src/gbmsc_pde/pde/problem.py
41 42 43 | |
add_source_term(source)
¶
Add right-hand side source field f.
Source code in src/gbmsc_pde/pde/problem.py
45 46 47 | |
assemble()
¶
Assemble A u = b on all rectangular source nodes.
Returns:
| Type | Description |
|---|---|
(A, b, Mx, My, Mxx, Myy)
|
Sparse PDE matrix, right-hand side, first-derivative matrices, and second-derivative matrices. |
Source code in src/gbmsc_pde/pde/problem.py
49 50 51 52 53 54 55 56 57 58 59 | |
gbmsc_pde.boundary.conditions.BoundaryConditions
¶
Boundary-condition container for rectangular source-node rows.
Conditions are registered by flattened source-node id. Dirichlet rows
replace the corresponding PDE row by u_i = value. Neumann and Robin
rows use the derivative matrices assembled by the PDE solver. Scalars are
broadcast to all supplied nodes; arrays must have the same length as
nodes.
Source code in src/gbmsc_pde/boundary/conditions.py
10 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 | |
add_dirichlet(nodes, values)
¶
Add Dirichlet conditions u_i = value on rectangular grid nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
int or ndarray
|
Flattened source-node ids. |
required |
values
|
float or ndarray
|
Scalar value or one value per node. |
required |
Source code in src/gbmsc_pde/boundary/conditions.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
add_neumann(nodes, outwardnormal, fluxes)
¶
Add Neumann conditions du/dn = flux on grid nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
int or ndarray
|
Flattened source-node ids. |
required |
outwardnormal
|
tuple
|
Normal components |
required |
fluxes
|
float or ndarray
|
Scalar flux or one flux per node. |
required |
Source code in src/gbmsc_pde/boundary/conditions.py
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 | |
add_neumann_as_second_condition(nodes, outwardnormal, fluxes, rows)
¶
Add Neumann equations on user-selected matrix rows.
This compatibility method is for augmented systems where a Neumann
boundary equation should be imposed as an additional/second condition
rather than replacing the row associated with node.
Source code in src/gbmsc_pde/boundary/conditions.py
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 | |
add_robin(nodes, outwardnormal, alphas, betas, values)
¶
Add Robin conditions alpha*u + beta*du/dn = value on grid nodes.
alphas, betas, and values may be scalars or arrays with
one entry per node.
Source code in src/gbmsc_pde/boundary/conditions.py
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 | |
apply(A, b, Mx, My)
¶
Apply all registered conditions to an assembled rectangular system.
Source code in src/gbmsc_pde/boundary/conditions.py
223 224 225 226 227 228 229 230 231 | |
gbmsc_pde.boundary.applier.BoundaryConditionApplier
¶
Apply a boundary-condition container to a linear system.
Source code in src/gbmsc_pde/boundary/applier.py
7 8 9 10 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 | |
apply(A, b, Mx, My)
¶
Return a system with all registered boundary conditions enforced.
Source code in src/gbmsc_pde/boundary/applier.py
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 | |
gbmsc_pde.solvers.linear.LinearSolver
¶
Linear-system solver for rectangular-domain PDE problems.
LinearSolver assembles the PDE rows from :class:LinearPDE, applies
node-indexed boundary conditions, and solves the resulting square sparse
system for the source-node vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pde
|
LinearPDE
|
Configured rectangular linear PDE builder. |
required |
bcs
|
BoundaryConditions
|
Boundary conditions registered on flattened grid nodes. |
required |
Source code in src/gbmsc_pde/solvers/linear.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 | |
assemble()
¶
Assemble and boundary-modify the rectangular collocation system.
Returns:
| Type | Description |
|---|---|
(A, b, Mx, My, Mxx, Myy)
|
Boundary-modified sparse system, right-hand side, and first
and second derivative matrices. The same objects are stored on
|
Source code in src/gbmsc_pde/solvers/linear.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
solve(solver='direct', tol=1e-08, maxiter=None, preconditioner=None, return_data=False)
¶
Assemble, apply boundary conditions, and solve the linear system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
(direct, cg, gmres, bicgstab)
|
Linear solver. |
'direct'
|
tol
|
float
|
Tolerance for iterative solvers. |
1e-08
|
maxiter
|
int
|
Maximum iterations (defaults to N). |
None
|
preconditioner
|
object
|
Preconditioner LinearOperator, sparse matrix, or |
None
|
return_data
|
bool
|
If true, return |
False
|
Returns:
| Type | Description |
|---|---|
ndarray or tuple
|
Solution vector |
Source code in src/gbmsc_pde/solvers/linear.py
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 | |