Level set tools
level_set_tools
This module provides a set of classes and functions enabling multi-material
capabilities. Users initialise materials by instantiating the Material
class and
define the physical properties of material interfaces using field_interface
. They
instantiate the LevelSetSolver
class by providing relevant parameters and call the
solve
method to request a solver update. Finally, they may call the entrainment
function to calculate material entrainment in the simulation.
Material(*, density=None, B=None, RaB=None)
dataclass
A material with physical properties for the level-set approach.
Expects material buoyancy to be defined using a value for either the reference density, buoyancy number, or compositional Rayleigh number.
Contains static methods to calculate the physical properties of a material. Methods implemented here describe properties in the simplest non-dimensional simulation setup and must be overriden for more complex scenarios.
Attributes:
Name | Type | Description |
---|---|---|
density |
Optional[Number]
|
An integer or a float representing the reference density. |
B |
Optional[Number]
|
An integer or a float representing the buoyancy number. |
RaB |
Optional[Number]
|
An integer or a float representing the compositional Rayleigh number. |
density_B_RaB |
Optional[Number]
|
A string to notify how the buoyancy term is calculated. |
__post_init__()
Checks instance field values.
Raises:
Type | Description |
---|---|
ValueError
|
Incorrect field types. |
Source code in g-adopt/gadopt/level_set_tools.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
viscosity(*args, **kwargs)
staticmethod
Calculates dynamic viscosity (Pa s).
Source code in g-adopt/gadopt/level_set_tools.py
103 104 105 106 |
|
thermal_expansion(*args, **kwargs)
staticmethod
Calculates volumetric thermal expansion coefficient (K^-1).
Source code in g-adopt/gadopt/level_set_tools.py
108 109 110 111 |
|
thermal_conductivity(*args, **kwargs)
staticmethod
Calculates thermal conductivity (W m^-1 K^-1).
Source code in g-adopt/gadopt/level_set_tools.py
113 114 115 116 |
|
specific_heat_capacity(*args, **kwargs)
staticmethod
Calculates specific heat capacity at constant pressure (J kg^-1 K^-1).
Source code in g-adopt/gadopt/level_set_tools.py
118 119 120 121 |
|
internal_heating_rate(*args, **kwargs)
staticmethod
Calculates internal heating rate per unit mass (W kg^-1).
Source code in g-adopt/gadopt/level_set_tools.py
123 124 125 126 |
|
thermal_diffusivity(*args, **kwargs)
classmethod
Calculates thermal diffusivity (m^2 s^-1).
Source code in g-adopt/gadopt/level_set_tools.py
128 129 130 131 |
|
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
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 |
|
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
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 |
|
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
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 |
|
set_up_solvers()
Sets up time integrators for advection and reinitialisation as required.
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
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
558 559 560 561 562 563 |
|
reinitialise()
Performs reinitialisation steps.
Source code in g-adopt/gadopt/level_set_tools.py
565 566 567 568 |
|
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
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 |
|
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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
assign_level_set_values(level_set, epsilon, /, interface_geometry, 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.
Three scenarios are currently implemented to generate the signed-distance function:
- The material interface is described by a mathematical function y = f(x). In this
case, interface_geometry
should be "curve" and interface_callable
must be
provided along with any interface_args
to implement the aforementioned
mathematical function.
- The material interface is a polygon, and interface_geometry
takes the value
"polygon". In this case, interface_coordinates
must exclude the polygon sides
that do not act as a material interface and coincide with domain boundaries. The
coordinates of these sides should be provided using the boundary_coordinates
argument such that the concatenation of the two coordinate objects describes a
closed polygonal chain.
- The material interface is a circle, and interface_geometry
takes the value
"circle". In this case, interface_coordinates
is a list holding the coordinates
of the circle's centre and the circle radius. No other arguments are required.
Geometrical objects underpinning material interfaces are generated using Shapely.
Implemented interface geometry presets and associated arguments: | Curve | Arguments | | :-------- | :------------------------------------------------: | | line | slope, intercept | | cosine | amplitude, wavelength, vertical_shift, phase_shift | | rectangle | ref_vertex_coords, edge_sizes |
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_coordinates
|
list[list[float]] | list[list[float], float] | None
|
A sequence or an array-like with shape (N, 2) of numeric coordinate pairs defining the interface or a list containing centre coordinates and radius |
None
|
interface_callable
|
Callable | str | None
|
A callable implementing the mathematical function depicting 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[list[float]] | ndarray | None
|
A sequence of numeric coordinate pairs or an array-like with shape (N, 2) |
None
|
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
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
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
field_interface_recursive(level_set, material_value, method)
Sets physical property expressions for each material.
Ensures that the correct expression is assigned to each material based on the level-set functions. Property transition across material interfaces are expressed according to the provided method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set
|
list
|
A list of level-set UFL functions. |
required |
material_value
|
list
|
A list of physical property values applicable to each material. |
required |
method
|
str
|
A string specifying the nature of property transitions between materials. |
required |
Returns:
Type | Description |
---|---|
Expr
|
A UFL expression to calculate physical property values throughout the domain. |
Raises:
Type | Description |
---|---|
ValueError
|
Incorrect method name supplied. |
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
field_interface(level_set, material_value, method)
Executes field_interface_recursive with a modified argument.
Calls field_interface_recursive using a copy of the level-set list to ensure the original one is not consumed by the function call.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set
|
list
|
A list of level-set UFL functions. |
required |
material_value
|
list
|
A list of physical property values applicable to each material. |
required |
method
|
str
|
A string specifying the nature of property transitions between materials. |
required |
Returns:
Type | Description |
---|---|
Expr
|
A UFL expression to calculate physical property values throughout the domain. |
Source code in g-adopt/gadopt/level_set_tools.py
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 |
|
density_RaB(Simulation, level_set, func_space_interp, method='sharp')
Sets up buoyancy-related fields.
Assigns UFL expressions to buoyancy-related fields based on the way the Material class was initialised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Simulation
|
A class representing the current simulation. |
required | |
level_set
|
list
|
A list of level-set UFL functions. |
required |
func_space_interp
|
WithGeometry
|
A continuous UFL function space where material fields are calculated. |
required |
method
|
Optional[str]
|
An optional string specifying the nature of property transitions between materials. |
'sharp'
|
Returns:
Type | Description |
---|---|
Constant
|
A tuple containing the reference density field, the density difference field, |
Constant | Expr
|
the density field, the UFL expression for the compositional Rayleigh number, |
Function
|
the compositional Rayleigh number field, and a boolean indicating if the |
Constant | Expr
|
simulation is expressed in dimensionless form. |
Raises:
Type | Description |
---|---|
ValueError
|
Inconsistent buoyancy-related field across materials. |
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
entrainment(level_set, material_area, entrainment_height)
Calculates entrainment diagnostic.
Determines the proportion of a material that is located above a given height.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set
|
Function
|
A level-set Firedrake function. |
required |
material_area
|
Number
|
An integer or a float representing the total area occupied by a material. |
required |
entrainment_height
|
Number
|
An integer or a float representing the height above which the entrainment diagnostic is determined. |
required |
Returns:
Type | Description |
---|---|
A float corresponding to the calculated entrainment diagnostic. |
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|