Sdf
ontic.cfd.sdf
¶
Signed Distance Function (SDF) geometry library.
Provides a protocol-based geometry abstraction for immersed boundary methods on structured Cartesian grids. Each SDF maps every point in space to its signed distance from the nearest surface:
d < 0 → inside solid
d = 0 → on the surface
d > 0 → outside (fluid)
All implementations are torch-compatible and differentiable for gradient-based shape optimization.
References
- Mittal & Iaccarino, "Immersed Boundary Methods", Annu. Rev. Fluid Mech. 37:239-261, 2005
- Hart, "Sphere Tracing", Visual Comp. 12(10), 1996
SDFGeometry
¶
Bases: ABC
Abstract base for 2-D signed-distance-function geometries.
Every concrete subclass must implement sdf. The default
is_inside, normal, and surface_points derive from
sdf automatically but may be overridden for efficiency.
Source code in ontic/cfd/sdf.py
bounding_box
abstractmethod
property
¶
Tight axis-aligned bounding box: (x_min, x_max, y_min, y_max).
characteristic_length
abstractmethod
property
¶
Reference length for Reynolds-number computation (metres).
sdf
abstractmethod
¶
Signed distance from each (x, y) to the nearest surface.
Returns:
| Type | Description |
|---|---|
Tensor
|
Same shape as x / y. Negative inside, positive outside. |
is_inside
¶
normal
¶
Outward-pointing unit normal via autograd on sdf.
Falls back to finite-difference if autograd is unavailable.
Source code in ontic/cfd/sdf.py
surface_points
¶
Sample n approximately equi-spaced points on the surface.
Default implementation marches around the bounding box and uses bisection along radial rays from the centroid.
Source code in ontic/cfd/sdf.py
CircleSDF
¶
Bases: SDFGeometry
Circle centred at (cx, cy) with radius r.
Source code in ontic/cfd/sdf.py
EllipseSDF
¶
Bases: SDFGeometry
Axis-aligned ellipse at (cx, cy) with semi-axes a (x) and b (y).
Uses a smooth approximation; exact SDF for an ellipse requires iterative root-finding. The approximation is excellent for immersed-boundary purposes (error < grid spacing).
Source code in ontic/cfd/sdf.py
RectangleSDF
¶
Bases: SDFGeometry
Axis-aligned rectangle centred at (cx, cy).
Source code in ontic/cfd/sdf.py
RoundedRectSDF
¶
Bases: SDFGeometry
Rectangle with rounded corners (radius r).
Source code in ontic/cfd/sdf.py
WedgeSDF
¶
Bases: SDFGeometry
Symmetric sharp wedge pointing into the flow (-x direction).
Leading edge at (tip_x, tip_y), extending in +x by length.
Source code in ontic/cfd/sdf.py
NACA4DigitSDF
¶
Bases: SDFGeometry
NACA 4-digit airfoil profile as an SDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chord
|
float
|
Chord length (metres). |
required |
naca_code
|
str
|
4-digit NACA code, e.g. "0012", "2412". |
'0012'
|
leading_edge_x
|
float
|
Position of the leading edge. |
0.0
|
leading_edge_y
|
float
|
Position of the leading edge. |
0.0
|
aoa_deg
|
float
|
Angle of attack in degrees (positive nose-up). |
0.0
|
Source code in ontic/cfd/sdf.py
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 | |
sdf
¶
Closest-point SDF to the pre-computed surface polygon.
Source code in ontic/cfd/sdf.py
FlatPlateSDF
¶
Bases: SDFGeometry
Thin flat plate aligned with the x-axis.
Source code in ontic/cfd/sdf.py
FinArraySDF
¶
Bases: SDFGeometry
Array of rectangular fins extending from a base plate.
Fins extend in +y from base_y. The base plate itself is included as part of the SDF.
Source code in ontic/cfd/sdf.py
PipeBendSDF
¶
Bases: SDFGeometry
2D representation of a pipe with a circular bend.
The pipe centre-line enters horizontally from the left, bends through bend_angle_deg (default 90°), and exits vertically upward. The wall thickness defines an annular region around the bend.
Source code in ontic/cfd/sdf.py
ConcentricAnnulusSDF
¶
Bases: SDFGeometry
Annular region between two concentric circles.
The SDF is negative in the solid regions (inside the inner circle OR outside the outer circle), i.e. the fluid region (the annular gap) has positive SDF.
For immersed-boundary use: the inner cylinder is the solid body; the outer cylinder is the domain boundary. This SDF represents the inner cylinder only.
Source code in ontic/cfd/sdf.py
MultiBodySDF
¶
Bases: SDFGeometry
CSG union of multiple SDFGeometry objects.
The SDF at each point is min(sdf_1, sdf_2, …) — the standard
signed-distance union operator.
Source code in ontic/cfd/sdf.py
StepSDF
¶
Bases: SDFGeometry
Backward-facing step geometry.
A solid block occupies the upper portion of the channel upstream of the step location, creating a sudden expansion.
::
████████████████████
████████████████████
████████████
████████████ ← step_height
───────────────────── channel floor (y=0)
^
step_x