|
18 | 18 |
|
19 | 19 | from __future__ import annotations |
20 | 20 |
|
| 21 | +import collections |
21 | 22 | from typing import TYPE_CHECKING, Union |
22 | 23 |
|
23 | 24 | import numpy as np |
@@ -408,23 +409,34 @@ def get_boundary_axis( |
408 | 409 | :class:`~pde.grids.boundaries.axis.BoundaryAxisBase`: |
409 | 410 | Appropriate boundary condition for the axis |
410 | 411 | """ |
| 412 | + # Handle special case where two identical conditions are given. In particular, this |
| 413 | + # covers the special case where `data == ("periodic", "periodic")` and similar |
| 414 | + # constructs. These are converted to `data == "periodic"`, so the next check can |
| 415 | + # catch them properly. |
| 416 | + if isinstance(data, collections.abc.Sequence) and data[0] == data[1]: |
| 417 | + data = data[0] |
| 418 | + |
411 | 419 | # handle special case describing potentially periodic boundary conditions |
412 | 420 | if isinstance(data, str) and data.startswith("auto_periodic_"): |
413 | 421 | data = "periodic" if grid.periodic[axis] else data[len("auto_periodic_") :] |
414 | 422 |
|
415 | 423 | # handle different types of data that specify boundary conditions |
416 | 424 | if isinstance(data, BoundaryAxisBase): |
417 | | - # boundary is already an the correct format |
| 425 | + # boundary is already a fully fledged instance |
418 | 426 | bcs = data |
419 | | - elif data == "periodic" or data == ("periodic", "periodic"): |
| 427 | + |
| 428 | + elif data == "periodic" or ( |
| 429 | + isinstance(data, dict) and data.get("type") == "periodic" |
| 430 | + ): |
420 | 431 | # initialize a periodic boundary condition |
421 | 432 | bcs = BoundaryPeriodic(grid, axis) |
422 | | - elif data == "anti-periodic" or data == ("anti-periodic", "anti-periodic"): |
423 | | - # initialize a anti-periodic boundary condition |
| 433 | + |
| 434 | + elif data == "anti-periodic" or ( |
| 435 | + isinstance(data, dict) and data.get("type") == "anti-periodic" |
| 436 | + ): |
| 437 | + # initialize an anti-periodic boundary condition |
424 | 438 | bcs = BoundaryPeriodic(grid, axis, flip_sign=True) |
425 | | - elif isinstance(data, dict) and data.get("type") == "periodic": |
426 | | - # initialize a periodic boundary condition |
427 | | - bcs = BoundaryPeriodic(grid, axis) |
| 439 | + |
428 | 440 | else: |
429 | 441 | # initialize independent boundary conditions for the two sides |
430 | 442 | bcs = BoundaryPair.from_data(grid, axis, data, rank=rank) |
|
0 commit comments