Geometry Module (softpotato.geometry)¶
The softpotato.geometry subpackage provides spatial coordinate abstractions, finite-difference differential operators (\(\nabla^2\), \(\nabla\)), normal interfacial flux evaluation, and active electrode surface integration across planar, spherical, and cylindrical domains.
Coordinate Geometries and Differential Operators¶
| Geometry Class & Aliases | Symmetry Factor (\(p\)) | Laplacian Operator (\(\nabla^2 c\)) | Active Surface Area (\(A\)) |
|---|---|---|---|
PlanarGeometry ('planar', 'cartesian', '1d', 'linear') |
\(p = 0\) | \(\dfrac{\partial^2 c}{\partial x^2}\) | User-specified \(A\) (default \(1.0\)) |
CylindricalGeometry ('cylindrical', 'cylinder', 'wire') |
\(p = 1\) | \(\dfrac{\partial^2 c}{\partial r^2} + \dfrac{1}{r}\dfrac{\partial c}{\partial r}\) | \(2 \pi r_0 L\) |
SphericalGeometry ('spherical', 'sphere', 'hemispherical', 'hemisphere') |
\(p = 2\) | \(\dfrac{\partial^2 c}{\partial r^2} + \dfrac{2}{r}\dfrac{\partial c}{\partial r}\) | \(4 \pi r_0^2\) (full sphere) or \(2 \pi r_0^2\) (hemisphere) |
Module Contents¶
geometry
¶
Spatial coordinate geometries and differential operators for electrochemical simulation.
This subpackage abstracts coordinate system metrics, spatial finite-difference operators (\(\nabla^2\), \(\nabla\)), normal interfacial flux evaluation, and active electrode surface integration:
Available built-in geometries include:
PlanarGeometry("planar", \(p = 0\)): 1D Cartesian linear diffusion perpendicular to a planar macroelectrode.SphericalGeometry("spherical","hemispherical", \(p = 2\)): 1D radial diffusion to a full spherical or hemispherical electrode.CylindricalGeometry("cylindrical", \(p = 1\)): 1D axisymmetric radial diffusion to a cylindrical wire or fiber microelectrode.
Examples:
Evaluating spatial operators across planar, spherical, and cylindrical geometries:
>>> import numpy as np
>>> from softpotato.geometry import (
... PlanarGeometry,
... SphericalGeometry,
... CylindricalGeometry,
... get_geometry,
... )
>>>
>>> planar = get_geometry("planar", area=1.0)
>>> x = np.linspace(0.0, 1.0, 51)
>>> bool(np.allclose(planar.laplacian(x**2, x), 2.0))
True
>>>
>>> sphere = SphericalGeometry(r0=1e-4)
>>> r = np.linspace(1.0, 5.0, 201)
>>> bool(np.max(np.abs(sphere.laplacian(1.0 / r, r)[1:-1])) < 1e-4)
True
>>>
>>> cylinder = CylindricalGeometry(r0=5e-6, length=1e-2)
>>> bool(np.max(np.abs(cylinder.laplacian(np.log(r), r)[1:-1])) < 1e-4)
True
Geometry
¶
Bases: ABC
Abstract base class representing spatial domain coordinate geometry.
Encapsulates coordinate metrics, finite-difference differential operators (\(\nabla^2\), \(\nabla\)), normal interfacial flux evaluation, and active electrode surface area integration for 1D and curvilinear coordinate systems:
where \(p = 0\) corresponds to planar Cartesian coordinates (\(x\)), \(p = 1\) to cylindrical radial coordinates (\(r\)), and \(p = 2\) to spherical radial coordinates (\(r\)).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Canonical identifier of the coordinate geometry (e.g., |
dimension |
int
|
Number of active spatial dimensions discretized by the geometry. |
coordinate_name |
str
|
Symbol of the primary spatial coordinate (e.g., |
p |
int
|
Radial symmetry factor (\(p = 0\) planar, \(p = 1\) cylindrical, \(p = 2\) spherical). |
Source code in src/softpotato/geometry/base.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
area
abstractmethod
property
¶
Active electrode surface area \(A\) in \(\text{m}^2\) or \(\text{cm}^2\).
symmetry_factor
property
¶
Radial coordinate symmetry exponent \(p \in \{0, 1, 2\}\).
validate_grid
¶
Validate that a spatial grid satisfies the coordinate domain constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
ndarray or Mesh1D
|
1D array or mesh of spatial coordinates. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Validated 1D floating-point coordinate grid. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/softpotato/geometry/base.py
laplacian
abstractmethod
¶
laplacian(c: ndarray, grid: ndarray | Mesh1D, bc_left: Any = None, bc_right: Any = None, t: float = 0.0) -> np.ndarray
Evaluate the spatial Laplacian \(\nabla^2 c\) at interior and boundary points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
ndarray
|
1D concentration profile array of shape |
required |
grid
|
ndarray or Mesh1D
|
1D spatial coordinate array or mesh of shape |
required |
bc_left
|
BoundaryCondition
|
Boundary condition at the inner/left boundary (\(i = 0\)). |
None
|
bc_right
|
BoundaryCondition
|
Boundary condition at the outer/right boundary (\(i = N - 1\)). |
None
|
t
|
float
|
Evaluation time in seconds for time-dependent boundary conditions. |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of \(\nabla^2 c\) values of shape |
Source code in src/softpotato/geometry/base.py
laplacian_matrix
abstractmethod
¶
laplacian_matrix(grid: ndarray | Mesh1D, bc_left: Any = None, bc_right: Any = None) -> tuple[np.ndarray, np.ndarray]
Return banded matrix representation of \(\nabla^2\) for implicit solvers.
Constructs the tridiagonal finite-difference operator \(\mathbf{L}\) in
scipy.linalg.solve_banded (1, 1) format of shape (3, N), together
with a boundary gradient scaling vector \(\mathbf{b}_{\text{scale}}\) of
shape (N,) such that for Neumann boundary gradients \(g_{\text{left}}\),
\(g_{\text{right}}\):
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
ndarray or Mesh1D
|
1D spatial coordinate array or mesh of shape |
required |
bc_left
|
BoundaryCondition
|
Boundary condition at the left boundary (\(i = 0\)). |
None
|
bc_right
|
BoundaryCondition
|
Boundary condition at the right boundary (\(i = N - 1\)). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
L_banded |
ndarray
|
Banded tridiagonal matrix of shape |
bc_scale |
ndarray
|
1D boundary gradient multiplier array of shape |
Source code in src/softpotato/geometry/base.py
surface_flux
abstractmethod
¶
surface_flux(c: ndarray, grid: ndarray | Mesh1D, diffusivity: float, side: str = 'left') -> float | np.ndarray
Calculate normal interfacial diffusion flux \(J = -D (\partial c / \partial n)\) at a boundary.
Follows the electrode-normal convention where the unit normal \(\mathbf{n}\) points from the boundary into the solution domain (\(+\hat{x}\) or \(+\hat{r}\) at the left boundary, and \(-\hat{x}\) or \(-\hat{r}\) at the right boundary).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
ndarray
|
Concentration profile of shape |
required |
grid
|
ndarray or Mesh1D
|
1D spatial coordinate array or mesh of shape |
required |
diffusivity
|
float
|
Species diffusion coefficient \(D > 0\). |
required |
side
|
('left', 'right')
|
Domain boundary at which to evaluate the normal flux. |
'left'
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Interfacial flux \(J\) (scalar |
Source code in src/softpotato/geometry/base.py
current
abstractmethod
¶
current(flux: float | ndarray, n_electrons: int = 1, side: Literal['left', 'right'] = 'left', grid: ndarray | Mesh1D | None = None) -> float | np.ndarray
Integrate normal flux over the active electrode surface to compute Faradaic current.
Computes the total Faradaic current \(I = n F A J\) according to IUPAC sign conventions (cathodic reduction \(I < 0\) when reactant flux into solution is negative, \(J < 0\)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flux
|
float or ndarray
|
Normal interfacial diffusion flux \(J\) at the electrode surface. |
required |
n_electrons
|
int
|
Number of electrons transferred per reaction (\(n > 0\)). |
1
|
side
|
('left', 'right')
|
Domain boundary at which to compute the Faradaic current. |
'left'
|
grid
|
ndarray or Mesh1D
|
Spatial grid coordinates used to determine surface area if coordinate-dependent. |
None
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Faradaic current \(I\) in Amperes (\(\text{A}\)). |
Source code in src/softpotato/geometry/base.py
UnknownGeometryError
¶
Bases: KeyError, ValueError
Exception raised when an unrecognized geometry identifier is requested.
Source code in src/softpotato/geometry/base.py
CylindricalGeometry
¶
Bases: Geometry
1D cylindrical radial coordinate geometry (\(p = 1\)).
Models axisymmetric radial diffusion to or from a cylindrical wire or carbon fiber microelectrode of radius \(r_0 > 0\) and length \(L > 0\) across radial domain \(r \in [r_0, r_{\max}]\):
Neglecting end effects (\(L \gg r_0\)), the active lateral electrode surface area at \(r = r_0\) is:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r0
|
float
|
Cylinder radius \(r_0 > 0\) in meters or cm. Defaults to |
None
|
length
|
float
|
Active cylinder length \(L > 0\) in meters or cm. |
1.0
|
radius
|
float
|
Keyword alias for |
None
|
L
|
float
|
Keyword alias for |
None
|
area
|
float
|
Explicit surface area override \(A > 0\). If None, computed analytically as \(A = 2 \pi r_0 L\). |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Geometry identifier ( |
dimension |
int
|
Spatial dimension ( |
coordinate_name |
str
|
Primary coordinate symbol ( |
p |
int
|
Symmetry factor ( |
r0 |
float
|
Cylinder radius \(r_0 > 0\). |
length |
float
|
Cylinder length \(L > 0\). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import numpy as np
>>> from softpotato.geometry import CylindricalGeometry
>>> geom = CylindricalGeometry(r0=5e-6, length=1e-2)
>>> r = np.linspace(1.0, 5.0, 201)
>>> c = np.log(r) # Harmonic profile in cylindrical coordinates: ∇²(ln r) = 0
>>> lap = geom.laplacian(c, r)
>>> bool(np.max(np.abs(lap[1:-1])) < 1e-4)
True
Source code in src/softpotato/geometry/cylindrical.py
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 | |
validate_grid
¶
Validate radial grid bounds (\(r_0 > 0\)) and infer r0 if not explicitly set.
Source code in src/softpotato/geometry/cylindrical.py
laplacian
¶
laplacian(c: ndarray, grid: ndarray | Mesh1D, bc_left: Any = None, bc_right: Any = None, t: float = 0.0) -> np.ndarray
Evaluate the cylindrical Laplacian \(\nabla^2 c = \frac{\partial^2 c}{\partial r^2} + \frac{1}{r}\frac{\partial c}{\partial r}\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
ndarray
|
1D concentration array of shape |
required |
grid
|
ndarray or Mesh1D
|
1D radial coordinate grid \(r \in [r_0, r_{\max}]\) of shape |
required |
bc_left
|
BoundaryCondition
|
Inner boundary condition at \(r = r_0\). |
None
|
bc_right
|
BoundaryCondition
|
Outer boundary condition at \(r = r_{\max}\). |
None
|
t
|
float
|
Time in seconds for evaluating time-dependent boundary conditions. |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of \(\nabla^2 c\) values of shape |
Source code in src/softpotato/geometry/cylindrical.py
laplacian_matrix
¶
laplacian_matrix(grid: ndarray | Mesh1D, bc_left: Any = None, bc_right: Any = None) -> tuple[np.ndarray, np.ndarray]
Assemble banded matrix representation of the cylindrical Laplacian \(\nabla^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
ndarray or Mesh1D
|
1D radial grid \(r\) of shape |
required |
bc_left
|
BoundaryCondition
|
Inner boundary condition at \(r = r_0\). |
None
|
bc_right
|
BoundaryCondition
|
Outer boundary condition at \(r = r_{\max}\). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
L_banded |
ndarray
|
Banded tridiagonal operator matrix of shape |
bc_scale |
ndarray
|
Boundary gradient scaling vector of shape |
Source code in src/softpotato/geometry/cylindrical.py
surface_flux
¶
surface_flux(c: ndarray, grid: ndarray | Mesh1D, diffusivity: float, side: str = 'left') -> float | np.ndarray
Calculate normal interfacial diffusion flux \(J = -D (\partial c / \partial n)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
ndarray
|
Concentration array of shape |
required |
grid
|
ndarray or Mesh1D
|
1D radial grid \(r\) of shape |
required |
diffusivity
|
float
|
Species diffusion coefficient \(D > 0\). |
required |
side
|
('left', 'right')
|
Boundary side at which to evaluate the normal flux. |
'left'
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Normal interfacial diffusion flux \(J\). |
Source code in src/softpotato/geometry/cylindrical.py
current
¶
current(flux: float | ndarray, n_electrons: int = 1, side: Literal['left', 'right'] = 'left', grid: ndarray | Mesh1D | None = None) -> float | np.ndarray
Integrate normal flux over the cylindrical electrode surface \(I = n F A J\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flux
|
float or ndarray
|
Interfacial diffusion flux \(J\). |
required |
n_electrons
|
int
|
Number of electrons transferred per reaction (\(n > 0\)). |
1
|
side
|
('left', 'right')
|
Domain boundary at which to compute the Faradaic current. |
'left'
|
grid
|
ndarray or Mesh1D
|
Spatial grid coordinates used to determine outer boundary area when |
None
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Faradaic current \(I\) in Amperes (\(\text{A}\)). |
Source code in src/softpotato/geometry/cylindrical.py
PlanarGeometry
¶
Bases: Geometry
1D planar Cartesian coordinate geometry (\(p = 0\)).
Models semi-infinite or finite linear diffusion perpendicular to a flat macroelectrode along spatial coordinate \(x \in [x_0, x_{\max}]\):
The active electrode surface area is constant (\(A\)), yielding Faradaic current:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
float
|
Active electrode surface area \(A\) in \(\text{m}^2\) or \(\text{cm}^2\) (\(A > 0\)). |
1.0
|
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Geometry identifier ( |
dimension |
int
|
Spatial dimension ( |
coordinate_name |
str
|
Primary coordinate symbol ( |
p |
int
|
Symmetry factor ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import numpy as np
>>> from softpotato.geometry import PlanarGeometry
>>> geom = PlanarGeometry(area=0.5)
>>> x = np.linspace(0.0, 1.0, 21)
>>> c = x**2 # d²(x²)/dx² = 2.0 everywhere
>>> lap = geom.laplacian(c, x)
>>> bool(np.allclose(lap, 2.0))
True
>>> flux = geom.surface_flux(x, x, diffusivity=1e-5, side="left")
>>> round(flux, 8)
-1e-05
Source code in src/softpotato/geometry/planar.py
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 | |
laplacian
¶
laplacian(c: ndarray, grid: ndarray | Mesh1D, bc_left: Any = None, bc_right: Any = None, t: float = 0.0) -> np.ndarray
Evaluate the 1D Cartesian Laplacian \(\nabla^2 c = \partial^2 c / \partial x^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
ndarray
|
1D concentration array of shape |
required |
grid
|
ndarray or Mesh1D
|
1D spatial grid \(x\) of shape |
required |
bc_left
|
BoundaryCondition
|
Left boundary condition at \(x_0\). |
None
|
bc_right
|
BoundaryCondition
|
Right boundary condition at \(x_{N-1}\). |
None
|
t
|
float
|
Time in seconds for evaluating time-dependent boundary conditions. |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of \(\partial^2 c / \partial x^2\) values of shape |
Source code in src/softpotato/geometry/planar.py
laplacian_matrix
¶
laplacian_matrix(grid: ndarray | Mesh1D, bc_left: Any = None, bc_right: Any = None) -> tuple[np.ndarray, np.ndarray]
Assemble banded matrix representation of \(\partial^2 / \partial x^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
ndarray or Mesh1D
|
1D spatial grid \(x\) of shape |
required |
bc_left
|
BoundaryCondition
|
Left boundary condition at \(x_0\). |
None
|
bc_right
|
BoundaryCondition
|
Right boundary condition at \(x_{N-1}\). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
L_banded |
ndarray
|
Banded tridiagonal operator matrix of shape |
bc_scale |
ndarray
|
Boundary gradient scaling vector of shape |
Source code in src/softpotato/geometry/planar.py
surface_flux
¶
surface_flux(c: ndarray, grid: ndarray | Mesh1D, diffusivity: float, side: str = 'left') -> float | np.ndarray
Calculate normal interfacial diffusion flux \(J = -D (\partial c / \partial n)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
ndarray
|
Concentration array of shape |
required |
grid
|
ndarray or Mesh1D
|
1D spatial grid \(x\) of shape |
required |
diffusivity
|
float
|
Species diffusion coefficient \(D > 0\). |
required |
side
|
('left', 'right')
|
Boundary side at which to evaluate the normal flux. |
'left'
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Normal interfacial diffusion flux \(J\). |
Source code in src/softpotato/geometry/planar.py
current
¶
current(flux: float | ndarray, n_electrons: int = 1, side: Literal['left', 'right'] = 'left', grid: ndarray | Mesh1D | None = None) -> float | np.ndarray
Compute Faradaic current \(I = n F A J\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flux
|
float or ndarray
|
Interfacial diffusion flux \(J\). |
required |
n_electrons
|
int
|
Number of electrons transferred per reaction (\(n > 0\)). |
1
|
side
|
('left', 'right')
|
Domain boundary at which to compute the Faradaic current. |
'left'
|
grid
|
ndarray
|
Spatial grid coordinates (unused for planar geometry). |
None
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Faradaic current \(I\) in Amperes (\(\text{A}\)). |
Source code in src/softpotato/geometry/planar.py
SphericalGeometry
¶
Bases: Geometry
1D spherical radial coordinate geometry (\(p = 2\)).
Models radial diffusion to or from a spherical microelectrode, hanging mercury drop electrode (HMDE), or hemispherical microelectrode on an insulating plane across radial domain \(r \in [r_0, r_{\max}]\) with \(r_0 > 0\):
The active electrode surface area at \(r = r_0\) is:
- Full sphere (
hemisphere=False): \(A = 4 \pi r_0^2\) - Hemisphere (
hemisphere=True): \(A = 2 \pi r_0^2\)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r0
|
float
|
Electrode radius \(r_0 > 0\) in meters or cm. Defaults to |
None
|
hemisphere
|
bool
|
If True, computes surface area for a hemisphere (\(A = 2 \pi r_0^2\)) instead of a full sphere (\(A = 4 \pi r_0^2\)). |
False
|
radius
|
float
|
Keyword alias for |
None
|
mode
|
('sphere', 'hemisphere')
|
Alternative specification of full sphere vs. hemisphere geometry. |
'sphere'
|
area
|
float
|
Explicit surface area override \(A > 0\). If None, computed analytically
from \(r_0\) and |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Geometry identifier ( |
dimension |
int
|
Spatial dimension ( |
coordinate_name |
str
|
Primary coordinate symbol ( |
p |
int
|
Symmetry factor ( |
r0 |
float
|
Electrode radius \(r_0 > 0\). |
hemisphere |
bool
|
Whether the electrode is a hemisphere on an insulating substrate. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import numpy as np
>>> from softpotato.geometry import SphericalGeometry
>>> geom = SphericalGeometry(r0=1e-4)
>>> r = np.linspace(1.0, 5.0, 201)
>>> c = 1.0 / r # Harmonic profile in spherical coordinates: ∇²(1/r) = 0
>>> lap = geom.laplacian(c, r)
>>> bool(np.max(np.abs(lap[1:-1])) < 1e-4)
True
Source code in src/softpotato/geometry/spherical.py
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 | |
area
property
¶
Active electrode surface area \(A = 4\pi r_0^2\) (or \(2\pi r_0^2\) for hemisphere).
validate_grid
¶
Validate radial grid bounds (\(r_0 > 0\)) and infer r0 if not explicitly set.
Source code in src/softpotato/geometry/spherical.py
laplacian
¶
laplacian(c: ndarray, grid: ndarray | Mesh1D, bc_left: Any = None, bc_right: Any = None, t: float = 0.0) -> np.ndarray
Evaluate the spherical Laplacian \(\nabla^2 c = \frac{\partial^2 c}{\partial r^2} + \frac{2}{r}\frac{\partial c}{\partial r}\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
ndarray
|
1D concentration array of shape |
required |
grid
|
ndarray or Mesh1D
|
1D radial coordinate grid \(r \in [r_0, r_{\max}]\) of shape |
required |
bc_left
|
BoundaryCondition
|
Inner boundary condition at \(r = r_0\). |
None
|
bc_right
|
BoundaryCondition
|
Outer boundary condition at \(r = r_{\max}\). |
None
|
t
|
float
|
Time in seconds for evaluating time-dependent boundary conditions. |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of \(\nabla^2 c\) values of shape |
Source code in src/softpotato/geometry/spherical.py
laplacian_matrix
¶
laplacian_matrix(grid: ndarray | Mesh1D, bc_left: Any = None, bc_right: Any = None) -> tuple[np.ndarray, np.ndarray]
Assemble banded matrix representation of the spherical Laplacian \(\nabla^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
ndarray or Mesh1D
|
1D radial grid \(r\) of shape |
required |
bc_left
|
BoundaryCondition
|
Inner boundary condition at \(r = r_0\). |
None
|
bc_right
|
BoundaryCondition
|
Outer boundary condition at \(r = r_{\max}\). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
L_banded |
ndarray
|
Banded tridiagonal operator matrix of shape |
bc_scale |
ndarray
|
Boundary gradient scaling vector of shape |
Source code in src/softpotato/geometry/spherical.py
surface_flux
¶
surface_flux(c: ndarray, grid: ndarray | Mesh1D, diffusivity: float, side: str = 'left') -> float | np.ndarray
Calculate normal interfacial diffusion flux \(J = -D (\partial c / \partial n)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
ndarray
|
Concentration array of shape |
required |
grid
|
ndarray or Mesh1D
|
1D radial grid \(r\) of shape |
required |
diffusivity
|
float
|
Species diffusion coefficient \(D > 0\). |
required |
side
|
('left', 'right')
|
Boundary side at which to evaluate the normal flux. |
'left'
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Normal interfacial diffusion flux \(J\). |
Source code in src/softpotato/geometry/spherical.py
current
¶
current(flux: float | ndarray, n_electrons: int = 1, side: Literal['left', 'right'] = 'left', grid: ndarray | Mesh1D | None = None) -> float | np.ndarray
Integrate normal flux over the spherical or hemispherical surface \(I = n F A J\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flux
|
float or ndarray
|
Interfacial diffusion flux \(J\). |
required |
n_electrons
|
int
|
Number of electrons transferred per reaction (\(n > 0\)). |
1
|
side
|
('left', 'right')
|
Domain boundary at which to compute the Faradaic current. |
'left'
|
grid
|
ndarray or Mesh1D
|
Spatial grid coordinates used to determine outer boundary area when |
None
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Faradaic current \(I\) in Amperes (\(\text{A}\)). |
Source code in src/softpotato/geometry/spherical.py
get_geometry
¶
Instantiate or resolve a spatial coordinate geometry by name or instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name_or_instance
|
str or Geometry
|
Registered geometry identifier (case-insensitive) such as |
'planar'
|
**kwargs
|
Any
|
Configuration parameters forwarded to the geometry constructor:
|
{}
|
Returns:
| Type | Description |
|---|---|
Geometry
|
Resolved |
Raises:
| Type | Description |
|---|---|
UnknownGeometryError
|
If |
TypeError
|
If |
ValueError
|
If keyword arguments are supplied when |
Examples:
>>> from softpotato.geometry import get_geometry
>>> planar = get_geometry("planar", area=0.05)
>>> planar.area
0.05
>>> sphere = get_geometry("spherical", r0=1e-4)
>>> sphere.coordinate_name
'r'
>>> get_geometry(planar) is planar
True
Source code in src/softpotato/geometry/base.py
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 | |
list_geometries
¶
Return a sorted list of all registered geometry names and aliases.
Returns:
| Type | Description |
|---|---|
list[str]
|
Alphabetically sorted list of registered geometry identifiers. |
Examples:
>>> from softpotato.geometry import list_geometries
>>> geoms = list_geometries()
>>> "planar" in geoms and "spherical" in geoms and "cylindrical" in geoms
True
Source code in src/softpotato/geometry/base.py
register_geometry
¶
Decorator to register a custom geometry class under a given alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name identifier to associate with the decorated geometry class. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[type[Geometry]], type[Geometry]]
|
Class decorator registering the subclass in |
Examples:
>>> from softpotato.geometry import Geometry, register_geometry, get_geometry
>>> @register_geometry("custom_planar_demo")
... class CustomPlanar(Geometry):
... @property
... def area(self) -> float:
... return 2.0
... def laplacian(self, c, grid, bc_left=None, bc_right=None, t=0.0):
... return self._eval_1d_laplacian(c, grid, bc_left, bc_right, t)
... def laplacian_matrix(self, grid, bc_left=None, bc_right=None):
... return self._build_1d_laplacian_matrix(grid, bc_left, bc_right)
... def surface_flux(self, c, grid, diffusivity, side="left"):
... return self._eval_1d_surface_flux(c, grid, diffusivity, side)
... def current(self, flux, n_electrons=1):
... return self._eval_1d_current(flux, n_electrons)
>>> geom = get_geometry("custom_planar_demo")
>>> geom.area
2.0