curvey.flow¤
flow
¤
Definitions of flow infrastructure and implementations of some common flows
AbstractCurvatureFlow
¤
Bases: AbstractFlow[TData]
, Generic[TData]
Abstract superclass for curvature flows
Parameters:
Name | Type | Description | Default |
---|---|---|---|
curvature_fn |
Callable[[Curve], ndarray] | None
|
A function |
None
|
rescale |
Literal['length', 'area'] | None
|
If this is 'length' or 'area', the recurve length/area is rescaled to the original's length or area, preventing the usual curvature flow shrinkage. |
None
|
Source code in src\curvey\flow.py
default_curvature_fn(curve: Curve) -> ndarray
staticmethod
¤
poststep(curve: Curve, solver: Solver[TData]) -> Curve
¤
Called after stepping the curve, but before logging it
This is called after attaching additional curve metadata requested by curve loggers.
Subclasses can raise RetryStep
or StopEarly
here if necessary, or further process the
curve.
Source code in src\curvey\flow.py
AbstractFlow
¤
Bases: Generic[TData]
Abstract superclass for curve flow
The basic contract is that Flow
objects don't maintain any state specific
to the solution of a flow. All state is stored in the curve metadata
or in the Solver.data
class, which is generic over the TData
type.
Two methods for subclasses to implement: step
, which steps the curve by the
supplied timestep, and solver
, which constructs the auxillary Solver
object with
flow-specific data: TData
.
Source code in src\curvey\flow.py
poststep(curve: Curve, solver: Solver[TData]) -> Curve
¤
Called after stepping the curve, but before logging it
This is called after attaching additional curve metadata requested by curve loggers.
Subclasses can raise RetryStep
or StopEarly
here if necessary, or further process the
curve.
Source code in src\curvey\flow.py
solver(initial: Curve, **kwargs) -> Solver[TData]
abstractmethod
¤
Construct a Solver
to solve curve flow over time
**kwargs are all passed to the Solver
constructor.
CurveShorteningFlow
¤
Bases: AbstractCurvatureFlow[_CsfData]
Basic curve shortening flow
At each iteration, vertices coordinates are moved by , for timestep and vertex curvatures and normal .
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resample_mode |
InterpType | None
|
Type of interpolation to use when resampling, one of ('linear', 'cubic', 'pchip'). |
'cubic'
|
**kwargs |
Remaining kwargs are passed to the |
{}
|
Source code in src\curvey\flow.py
default_curvature_fn(curve: Curve) -> ndarray
staticmethod
¤
poststep(curve: Curve, solver: Solver[TData]) -> Curve
¤
Called after stepping the curve, but before logging it
This is called after attaching additional curve metadata requested by curve loggers.
Subclasses can raise RetryStep
or StopEarly
here if necessary, or further process the
curve.
Source code in src\curvey\flow.py
solver(initial: Curve, **kwargs) -> Solver[_CsfData]
¤
Construct a CurveShorteningFlow
Solver
**kwargs are all passed to the Solver
constructor.
Source code in src\curvey\flow.py
RetryStep
¤
Bases: Exception
This can be raised in a custom Solver.step_fn
to retry the current step
Usually after adjusting the timestep or some other state.
SingularityFreeMeanCurvatureFlow
¤
Bases: AbstractCurvatureFlow
Singularity free mean curvature flow
As defined in
That paper suggests this shouldn't really be necessary in the planar curve case, as curves in the continuous case can't form singularities anyway, but it does seem to be much more numerically stable than the traditional approach, and doesn't require resampling the curve.
See also the explanation in
Mean Curvature Flow and Applications. Maria Eduarda Duarte and Leonardo Sacht. 2017.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
All kwargs passed to |
{}
|
Source code in src\curvey\flow.py
default_curvature_fn(curve: Curve) -> ndarray
staticmethod
¤
poststep(curve: Curve, solver: Solver[TData]) -> Curve
¤
Called after stepping the curve, but before logging it
This is called after attaching additional curve metadata requested by curve loggers.
Subclasses can raise RetryStep
or StopEarly
here if necessary, or further process the
curve.
Source code in src\curvey\flow.py
solver(initial: Curve, **kwargs) -> Solver[_SfmcfData]
¤
Construct a solver for this flow
All **kwargs are passed to the Solver
constructor.
Source code in src\curvey\flow.py
Solver
¤
Bases: Generic[TData]
Auxillary class for solving curve Flow
s
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flow |
AbstractFlow
|
The |
required |
initial |
Curve
|
The initial |
required |
timestep |
float | None
|
For fixed timesteps |
None
|
timestep_fn |
Callable[[Solver], float] | None
|
A function |
None
|
history |
bool
|
If true, the |
True
|
max_step |
int | None
|
Maximum number of iterations to run. |
None
|
stop_on_non_simple |
bool
|
A step whose |
False
|
verbose |
bool
|
If true, curve state information and stopping messages are printed to stdout on each iteration. |
False
|
log |
bool
|
If true, the printed log messages as in |
False
|
data |
TData
|
Flow specific data. |
required |
step_fn |
Callable[[Solver], Curve] | None
|
A function |
None
|
Source code in src\curvey\flow.py
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 |
|
add_curve_loggers(**kwargs: Callable[[Curve], Any]) -> Self
¤
Log additional information as curve metadata
e.g. solver.add_curve_loggers(foo=foo_fn, bar=bar_fn) will store the results of
the function calls
foo_fn(curve)and
bar_fn(curve)` in the curve metadata 'foo' and 'bar'
properties.
Returns:
Type | Description |
---|---|
self
|
|
Source code in src\curvey\flow.py
add_stop_fn(fn: Callable[[Solver], bool]) -> Self
¤
Add a custom stop function. The run is stopped early if fn(curve)
returns True
Returns:
Type | Description |
---|---|
self
|
|
attach_metadata(curve: Curve, time: float, step: int | None = None, **kwargs) -> Curve
¤
Store requested metadata on the curve
Parameters:
Name | Type | Description | Default |
---|---|---|---|
curve |
Curve
|
The curve after the most recent step. |
required |
time |
float
|
The time of the curve in the solution. |
required |
step |
int | None
|
Which step this curve belongs to. This is almost always left None; it defaults
to |
None
|
**kwargs |
Additional metadata to store as key=value pairs. |
{}
|
Returns:
Type | Description |
---|---|
curve
|
The curve with metadata attached. |
Source code in src\curvey\flow.py
log(msg: str, *args, **kwargs)
¤
Log a message
This is always sent to the module logging.logger
at debug level.
If self.verbose
is true, it's also printed to stdout.
If self.log
is true, it's saved as a str in self.log_history
Source code in src\curvey\flow.py
run()
¤
Solve the flow by stepping the curve through time
If no stop criterion are specified by max_step
, add_stop_fn
, or
stop_on_param_limits
, this might run forever.
Returns:
Type | Description |
---|---|
self
|
|
Source code in src\curvey\flow.py
step() -> Curve
¤
Call Flow.step
with the current state and timestep
Source code in src\curvey\flow.py
stop_on_param_limits(param: str, min_val=None, max_val=None, param_fn: Callable[[Curve], Any] | None = None) -> Self
¤
Add a custom stop function based on a parameter value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param |
str
|
The name of the parameter. This is usually a curve metadata object, e.g. one logged
via |
required |
min_val |
The run is stopped if the parameter value < |
None
|
|
max_val |
The run is stopped if the parameter value > |
None
|
|
param_fn |
Callable[[Curve], Any] | None
|
An optional function |
None
|
Returns:
Type | Description |
---|---|
self
|
|
Source code in src\curvey\flow.py
StopEarly
¤
Bases: Exception
This can be raised in a custom Solver.step_fn
to stop the current run
Usually after reaching some stopping criterion.
WillmoreFlow
¤
Bases: AbstractCurvatureFlow[_WillmoreFlowData]
Willmore Flow
As explained in Robust Fairing via Conformal Curvature Flow. Keenan Crane, Ulrich Pinkall, and Peter Schröder. 2014.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_width |
float | None
|
|
None
|
filter_shape |
int | None
|
The and parameters in Crane §4. These filter the curvature flow direction and can be used to prioritize high or low frequency smoothing. |
None
|
constrain |
bool
|
Whether to apply the closed curve constraints on the curvature flow direction at each
timestep. See method |
True
|
solve_vertices |
bool
|
Whether to distribute length discretization errors.
See method |
True
|
realign |
bool
|
Whether to realign the curve at each timestep to the preceeding one. Because flipping
back and forth between extrinsic and intrinsic representations loses rotation and
translation information, this helps visually align the curve at each step, but may be
an unnecessary computation each iteration if alignment isn't important. See method
|
True
|
tgt_curvature |
ndarray | None
|
Vector of target vertex curvatures to flow towards. |
None
|
Source code in src\curvey\flow.py
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 |
|
autotimestep_fn(min_step: float | None = 1e-05, max_step: float | None = 0.9) -> Callable[[Solver], float]
staticmethod
¤
Construct an adaptive timestep function
For curve , calculates the timestep as , for energy , defined
in WillmoreFlow.energy
. This value is then clamped to min_step
and max_step
,
if supplied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_step |
float | None
|
Minimum timestep. |
1e-05
|
max_step |
float | None
|
Maximum timestep |
0.9
|
Returns:
Type | Description |
---|---|
timestep_fn
|
A function |
Source code in src\curvey\flow.py
constrain_flow(curve: Curve, dk: ndarray) -> ndarray
staticmethod
¤
Constrain curvature flow as per Crane §5
Constraints are
- end points must meet:
- tangents must agree at endpoints: .
Parameters:
Name | Type | Description | Default |
---|---|---|---|
curve |
Curve
|
The curve to constrain flow for. |
required |
dk |
ndarray
|
A |
required |
Returns:
Type | Description |
---|---|
dk_constrained
|
the curvature flow direction after applying the constraints. |
Source code in src\curvey\flow.py
default_curvature_fn(curve: Curve) -> ndarray
staticmethod
¤
energy(curve: Curve, tgt_curvature: ndarray | _Sentinel | None = _Sentinel.DEFAULT) -> float
¤
Calculate curve energy
By default uses self.tgt_curvature
, but can be overridden with the supplied
tgt_curvature
.
If tgt_curvature
is None, calculates the Willmore energy
for vertex curvatures and dual edge lengths .
If tgt_curvature
is not None, calculates
for target vertex curvatures .
Source code in src\curvey\flow.py
filter_flow_direction(curve: Curve, dk: ndarray) -> ndarray
¤
Filter curvature flow gradient
Source code in src\curvey\flow.py
solver(initial: Curve, stop_tol: float | None = None, stop_on_energy_increase: bool = False, **kwargs) -> Solver[_WillmoreFlowData]
¤
Construct a Solver
for the flow
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial |
Curve
|
The initial |
required |
stop_tol |
float | None
|
Optional stopping tolerance. See |
None
|
stop_on_energy_increase |
bool
|
Stop the first time energy is increased. The step with increased energy is discarded. |
False
|
**kwargs |
Remaining kwargs passed to the |
{}
|
Notes
If neither timestep
nor timestep_fn
are supplied to the solver, sets the solver
timestep_fn
to self.autotimestep_fn
for adaptive timestep selection. When
tgt_curvatures
is None, it's probably safe to just use a reasonably large timestep < 1,
but an adaptive timestep seems to be safer for targeted curvature flow.
Source code in src\curvey\flow.py
step(curve: Curve, timestep: float, solver: Solver[_WillmoreFlowData]) -> Curve
¤
Step the curve along its Willmore energy gradient
Source code in src\curvey\flow.py
stop_on_gradient_tolerance(tol: float) -> Callable[[Solver], bool]
staticmethod
¤
Construct a Solver
stopping function for the supplied tolerance