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
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
viscosity(*args, **kwargs)
staticmethod
Calculates dynamic viscosity (Pa s).
Source code in g-adopt/gadopt/level_set_tools.py
98 99 100 101 |
|
thermal_expansion(*args, **kwargs)
staticmethod
Calculates volumetric thermal expansion coefficient (K^-1).
Source code in g-adopt/gadopt/level_set_tools.py
103 104 105 106 |
|
thermal_conductivity(*args, **kwargs)
staticmethod
Calculates thermal conductivity (W m^-1 K^-1).
Source code in g-adopt/gadopt/level_set_tools.py
108 109 110 111 |
|
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
113 114 115 116 |
|
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
118 119 120 121 |
|
thermal_diffusivity(*args, **kwargs)
classmethod
Calculates thermal diffusivity (m^2 s^-1).
Source code in g-adopt/gadopt/level_set_tools.py
123 124 125 126 |
|
LevelSetSolver(level_set, velocity, tstep, tstep_alg, subcycles, epsilon, reini_params=None, solver_params=None)
Solver for the conservative level-set approach.
Solves the advection and reinitialisation equations for a level set function.
Attributes:
Name | Type | Description |
---|---|---|
mesh |
The UFL mesh where values of the level set function exist. |
|
level_set |
The Firedrake function for the level set. |
|
func_space_lsgp |
The UFL function space where values of the projected level-set gradient are calculated. |
|
level_set_grad_proj |
The Firedrake function for the projected level-set gradient. |
|
proj_solver |
An integer or a float representing the reference density. |
|
reini_params |
A dictionary containing parameters used in the reinitialisation approach. |
|
ls_solver |
The G-ADOPT timestepper object for the advection equation. |
|
reini_ts |
The G-ADOPT timestepper object for the reinitialisation equation. |
|
subcycles |
An integer specifying the number of advection solves to perform. |
Initialises the solver instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level_set |
Function
|
The Firedrake function for the level set. |
required |
velocity |
ListTensor
|
The UFL expression for the velocity. |
required |
tstep |
Constant
|
The Firedrake function over the Real space for the simulation time step. |
required |
tstep_alg |
ABCMeta
|
The class for the timestepping algorithm used in the advection solver. |
required |
subcycles |
int
|
An integer specifying the number of advection solves to perform. |
required |
epsilon |
Constant
|
A UFL constant denoting the thickness of the hyperbolic tangent profile. |
required |
reini_params |
Optional[dict]
|
A dictionary containing parameters used in the reinitialisation approach. |
None
|
solver_params |
Optional[dict]
|
A dictionary containing solver parameters used in the advection and reinitialisation approaches. |
None
|
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
gradient_L2_proj()
Constructs a projection solver.
Projects the level-set gradient from a discontinuous function space to the equivalent continuous one.
Returns:
Type | Description |
---|---|
LinearVariationalSolver
|
A Firedrake solver capable of projecting a discontinuous gradient field on |
LinearVariationalSolver
|
a continuous function space. |
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
update_level_set_gradient(*args, **kwargs)
Calls the gradient projection solver.
Can be used as a callback.
Source code in g-adopt/gadopt/level_set_tools.py
277 278 279 280 281 282 |
|
set_up_solvers()
Sets up the time steppers for advection and reinitialisation.
Source code in g-adopt/gadopt/level_set_tools.py
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 |
|
solve(step)
Updates the level-set function.
Calls advection and reinitialisation solvers within a subcycling loop. The reinitialisation solver can be iterated and might not be called at each simulation time step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step |
int
|
An integer representing the current simulation step. |
required |
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 332 333 334 335 336 337 338 |
|
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
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
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
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 |
|
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
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
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
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 |
|
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
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 |
|