Level set tools
level_set_tools
This module provides a set of classes and functions enabling multi-material
capabilities. Users initialise level-set fields using the interface_thickness
and
assign_level_set_values
functions. Given the level-set functions, users can define
material-dependent physical properties via the material_field
function. To evolve
level-set fields, users instantiate the LevelSetSolver
class, choosing if they require
advection, reinitialisation, or both, and then call the solve
method to request a
solver update. Finally, they may call the material_entrainment
and min_max_height
functions to calculate useful simulation diagnostics.
LevelSetSolver(level_set, /, *, adv_kwargs=None, reini_kwargs=None)
Solver for the conservative level-set approach.
Advects and reinitialises a level-set field.
Attributes:
Name | Type | Description |
---|---|---|
solution |
The Firedrake function holding level-set values |
|
solution_grad |
The Firedrake function holding level-set gradient values |
|
solution_space |
The Firedrake function space where the level set lives |
|
mesh |
The Firedrake mesh representing the numerical domain |
|
advection |
A boolean specifying whether advection is set up |
|
reinitialisation |
A boolean specifying whether reinitialisation is set up |
|
adv_kwargs |
A dictionary holding the parameters used to set up advection |
|
reini_kwargs |
A dictionary holding the parameters used to set up reinitialisation |
|
adv_solver |
A G-ADOPT GenericTransportSolver tackling advection |
|
gradient_solver |
A Firedrake LinearVariationalSolver to calculate the level-set gradient |
|
reini_integrator |
A G-ADOPT time integrator tackling reinitialisation |
|
step |
An integer representing the number of advection steps already made |
Initialises the solver instance.
Valid keys for adv_kwargs
:
| Argument | Required | Description |
| :-------------- | :------: | :---------------------------------------------: |
| u | True | Velocity field (Function
) |
| timestep | True | Integration time step (Constant
) |
| time_integrator | False | Time integrator (class in time_stepper.py
) |
| bcs | False | Boundary conditions (dict
, G-ADOPT API) |
| solver_params | False | Solver parameters (dict
, PETSc API) |
| subcycles | False | Advection iterations in one time step (int
) |
Valid keys for reini_kwargs
:
| Argument | Required | Description |
| :-------------- | :------: | :---------------------------------------------: |
| epsilon | True | Interface thickness (float
or Function
) |
| timestep | False | Integration step in pseudo-time (int
) |
| time_integrator | False | Time integrator (class in time_stepper.py
) |
| solver_params | False | Solver parameters (dict
, PETSc API) |
| steps | False | Pseudo-time integration steps (int
) |
| frequency | False | Advection steps before reinitialisation (int
) |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set
|
Function
|
The Firedrake function holding the level-set field |
required |
adv_kwargs
|
dict[str, Any] | None
|
A dictionary with parameters used to set up advection |
None
|
reini_kwargs
|
dict[str, Any] | None
|
A dictionary with parameters used to set up reinitialisation |
None
|
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
reinitialisation_frequency()
Implements default strategy for the reinitialisation frequency.
Reinitialisation becomes less frequent as mesh resolution increases, with the underlying assumption that the minimum cell size occurs along the material interface. The current strategy is to apply reinitialisation at every time step up to a certain cell size and then scale the frequency with the decrease in cell size.
Source code in g-adopt/gadopt/level_set_tools.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 |
|
set_gradient_solver()
Constructs a solver to determine the level-set gradient.
The weak form is derived through integration by parts and includes a term accounting for boundary flux.
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
set_up_solvers()
Sets up time integrators for advection and reinitialisation as required.
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
update_gradient(*args, **kwargs)
Calls the gradient solver.
Can be provided as a forcing to time integrators.
Source code in g-adopt/gadopt/level_set_tools.py
534 535 536 537 538 539 |
|
reinitialise()
Performs reinitialisation steps.
Source code in g-adopt/gadopt/level_set_tools.py
541 542 543 544 |
|
solve(disable_advection=False, disable_reinitialisation=False)
Updates the level-set function by means of advection and reinitialisation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
disable_advection
|
bool
|
A boolean to disable the advection solve. |
False
|
disable_reinitialisation
|
bool
|
A boolean to disable the reinitialisation solve. |
False
|
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
interface_thickness(level_set_space, scale=0.35)
Default strategy for the thickness of the conservative level set profile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set_space
|
WithGeometry
|
The Firedrake function space of the level-set field |
required |
scale
|
float
|
A float to control interface thickness values relative to cell sizes |
0.35
|
Returns:
Type | Description |
---|---|
Function
|
A Firedrake function holding the interface thickness values |
Source code in g-adopt/gadopt/level_set_tools.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
assign_level_set_values(level_set, epsilon, /, interface_geometry, *, interface=None, interface_coordinates=None, interface_callable=None, interface_args=None, boundary_coordinates=None)
Updates level-set field given interface thickness and signed-distance function.
Generates signed-distance function values at level-set nodes and overwrites level-set data according to the conservative level-set method using the provided interface thickness. By convention, the 1-side of the conservative level set lies inside the geometrical object outlined by the interface alone or extended with domain boundary segments (to form a closed loop).
This function uses Shapely
to generate a geometrical representation of the
interface. It handles simple base scenarios for which the interface can be described
by a plane curve, a polygonal chain (open or closed), or a circle. In these cases, a
mathematical description of the latter geometrical objects is sufficient to generate
the interface. For more complex objects, users should set up their own geometrical
representation via Shapely
and provide it to this function.
Currently implemented base scenarios to generate the signed-distance function:
- The material interface is a plane curve described by a parametric equation of the
form (x, y) = (x(t), y(t))
. In this case, interface_geometry
should be curve
and interface_callable
must be provided along with any interface_args
to
implement the parametric equation. interface_callable
can be a user-defined
Callable
or a str
matching an implemented preset. Additionally,
boundary_coordinates
must be supplied as a list
of coordinates along domain
boundaries to enclose the 1-side of the conservative level set.
- The material interface is a polygonal chain, and interface_geometry
takes the
value polygon
. If the polygonal chain is closed, either interface_coordinates
or interface_callable
must be provided. The former is a list
of vertex
coordinates (first and last coordinates must match to ensure a closed chain),
whilst the latter is a str
matching one of the implemented presets. If the
polygonal chain is open, interface_coordinates
remains a list
of vertex
coordinates, but first and last coordinates differ, and boundary_coordinates
must be supplied as a list
of coordinates along domain boundaries to enclose the
1-side of the conservative level set.
- The material interface is a circle, and interface_geometry
takes the value
circle
. In this case, interface_coordinates
must be provided as a tuple
holding the coordinates of the circle's centre and the circle's radius.
Implemented interface geometry presets and associated arguments: | Interface | Arguments | | :-------- | :------------------------------------------------: | | line | slope, intercept | | cosine | amplitude, wavelength, vertical_shift, phase_shift | | rectangle | ref_vertex_coords, edge_sizes |
If the desired interface geometry cannot be generated using a base scenario,
interface_geometry
takes the value shapely
and interface
must be provided,
either as a shapely.LineString
or shapely.Polygon
. In the former case,
boundary_coordinates
must also be supplied as a list
of coordinates along domain
boundaries to enclose the 1-side of the conservative level set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set
|
Function
|
A Firedrake function for the targeted level-set field |
required |
epsilon
|
float | Function
|
A float or Firedrake function representing the interface thickness |
required |
interface_geometry
|
str
|
A string specifying the geometry to create |
required |
interface
|
LineString | Polygon | None
|
A Shapely LineString or Polygon describing the interface |
None
|
interface_coordinates
|
list[tuple[float, float]] | tuple[tuple[float, float], float] | None
|
A sequence or an array-like with shape (N, 2) of coordinates defining the interface or a sequence containing a circle's centre coordinates and radius |
None
|
interface_callable
|
Callable | str | None
|
A callable implementing the parametric equation describing the interface or a string matching an implemented callable preset |
None
|
interface_args
|
tuple[Any, ...] | None
|
A tuple of arguments provided to the interface callable |
None
|
boundary_coordinates
|
list[tuple[float, float]] | None
|
A sequence or an array-like with shape (N, 2) of coordinates along boundaries |
None
|
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
reinitialisation_term(eq, trial)
Term for the conservative level set reinitialisation equation.
Implements terms on the right-hand side of Equation 17 from Parameswaran, S., & Mandal, J. C. (2023). A stable interface-preserving reinitialization equation for conservative level set method. European Journal of Mechanics-B/Fluids, 98, 40-63.
Source code in g-adopt/gadopt/level_set_tools.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
material_interface(level_set, field_value, other_side, interface)
Generates UFL algebra describing a physical property across a material interface.
Ensures that the correct expression is assigned to each material based on the level-set field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set
|
Function
|
A Firedrake function representing the level-set field |
required |
field_values
|
A float corresponding to the value of a physical property for a given material |
required | |
other_side
|
float | Expr
|
A float or UFL instance expressing the field value outside the material |
required |
interface
|
str
|
A string specifying how property transitions between materials are calculated |
required |
Returns:
Type | Description |
---|---|
UFL instance for a term of the physical-property algebraic expression |
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
material_field_from_copy(level_set, field_values, interface)
Generates UFL algebra by consuming level_set
and field_values
lists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set
|
list[Function]
|
A list of one or multiple Firedrake level-set functions |
required |
field_values
|
list[float]
|
A list of physical property values specific to each material |
required |
interface
|
str
|
A string specifying how property transitions between materials are calculated |
required |
Returns:
Type | Description |
---|---|
Expr
|
UFL algebra representing the physical property throughout the domain |
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
material_field(level_set, field_values, interface)
Generates UFL algebra describing a physical property across the domain.
Calls material_field_from_copy
using a copy of the level-set list, preventing the
potential original one from being consumed by the function call. Ordering of
field_values
must be consistent with level_set
, such that the last element
corresponds to the field value on the 1-side of the last conservative level set.
Note: When requesting the sharp_adjoint
interface, calling Stokes solver may
raise DIVERGED_FNORM_NAN
if the nodal level-set value is exactly 0.5 (i.e.
denoting the location of the material interface).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set
|
Function | list[Function]
|
A Firedrake function for the level set (or a list thereof) |
required |
field_values
|
list[float]
|
A list of physical-property values specific to each material |
required |
interface
|
str
|
A string specifying how property transitions between materials are calculated |
required |
Returns:
Type | Description |
---|---|
Expr
|
UFL algebra representing the physical property throughout the domain |
Raises:
Type | Description |
---|---|
ValueError
|
Incorrect interface strategy supplied |
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
material_entrainment(level_set, /, *, material_size, entrainment_height, side, direction, skip_material_size_check=False)
Calculates the proportion of a material located above or below a given height.
For the diagnostic calculation to be meaningful, the level-set side provided must spatially isolate the target material.
Note: This function checks if the total volume or area occupied by the target
material matches the material_size
value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set
|
Function
|
A Firedrake function for the level-set field |
required |
material_size
|
float
|
A float representing the total volume or area occupied by the target material |
required |
entrainment_height
|
float
|
A float representing the height above which to calculate entrainment |
required |
side
|
int
|
An integer ( |
required |
direction
|
str
|
A string ( |
required |
skip_material_size_check
|
bool
|
A boolean enabling to skip the consistency check of the material volume or area |
False
|
Returns:
Type | Description |
---|---|
float
|
A float corresponding to the material fraction above or below the target height |
Raises:
Type | Description |
---|---|
AssertionError
|
Material volume or area notably different from |
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
min_max_height(level_set, epsilon, *, side, mode)
Calculates the maximum or minimum height of a material interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set
|
Function
|
A Firedrake function for the level set field |
required |
epsilon
|
float | Function
|
A float or Firedrake function denoting the thickness of the material interface |
required |
side
|
int
|
An integer ( |
required |
mode
|
str
|
A string ("min" or "max") specifying which extremum height is sought |
required |
Returns:
Type | Description |
---|---|
float
|
A float corresponding to the material interface extremum height |
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|