lizzy
The LIZZY namespace exposes the LizzyModel class, which provides all the user-facing APIs to interact with Lizzy. It also exposes the SolverType enum, which contains the available solver types to choose from.
- class lizzy.LizzyModel
The main class for defining simulations in Lizzy. This class wraps all subcomponents of the solver and exposes all user-facing APIs. Provides access to methods for reading a mesh, assigning properties, configuring the solver, saving results and more. A script typically begins with the instantiation of a LizzyModel.
Properties
- property assigned_materials: Dict[str, PorousMaterial]
Dictionary of assigned materials in the model. (read-only)
- property existing_materials: Dict[str, PorousMaterial]
Dictionary of existing materials in the model. A material can be existing (after being created with
create_material()) but not assigned to any mesh region. (read-only)
Model setup methods
- read_mesh_file(mesh_file_path: str | PathLike) None
Reads a mesh file and initialises the mesh. Currently only .MSH format is supported (Version 4 ASCII).
- Parameters:
mesh_file_path (str) – Path to the mesh file from the current working folder.
- set_simulation_parameters(*, output_interval: float = 10, fill_tolerance: float = 0.01, end_step_when_sensor_triggered: bool = False, lightweight: bool = False, in_memory_solve: bool = False, progress_bar: bool = False) None
Set values to one or more simulation parameters using keyword arguments.
- Parameters:
**kwargs –
Keyword arguments corresponding to parameter names and their new values. Valid keywords are:
output_interval(float, optional): interval of simulation time between solution write-outs [s]. A negative value will write-out every numerical time step (not recommended). Default: 10fill_tolerance(float, optional): tolerance on the fill factor to consider a CV as filled. Default: 0.01end_step_when_sensor_triggered(bool, optional): if True, ends current solution step and creates a write-out when a sensor changes state. Default: Falselightweight(bool, optional): if True, disables Solution packing after each solve, saving memory and computation time.save_results()cannot be used in lightweight mode. Default: Falsein_memory_solve(bool, optional): if False (default), solution data is written incrementally to disk during the solve, reducing memory footprint for large simulations. If True, solution data is accumulated in memory and written at the end viasave_results(). Default: Falseprogress_bar(bool, optional): if True, shows a progress bar during the solution. Default: False
Examples
>>> model.set_simulation_parameters(output_interval=50)
- Raises:
AttributeError – If any key in kwargs does not correspond to a known attribute.
- create_resin(name: str, viscosity: float) Resin
Create a new resin that can then be selected and used in the model.
- assign_resin(resin_selector: Resin | str) None
Assign an existing resin to the model.
- Parameters:
resin_selector (Resin | str) – The resin object or name of the resin to assign. Must correspond to an existing resin created with
create_resin().
Note
Resin is a global property and does not need to be assigned to specific mesh regions. Only one resin can be assigned to the model, and it will be used for the entire simulation domain.
- create_material(name: str, k_vals: tuple[float, float, float], porosity: float, thickness: float) PorousMaterial
Create a new material that can then be selected and used in the model.
- Parameters:
name (str) – Unique name of the new material.
k_vals (tuple[float, float, float]) – Permeability values in the three principal directions (k1, k2, k3) [m²]. All values must be positive.
porosity (float) – Volumetric porosity of the material (porosity = 1 - fibre volume fraction). Must be between 0 and 1 (exclusive).
thickness (float) – Thickness of the material in the out-of-plane direction [m]. Must be positive.
- Returns:
Reference to the created material.
- Return type:
- assign_material(material_selector: PorousMaterial | str, mesh_tag: str, rosette: Rosette = None) None
Assign an existing material to a labeled mesh region.
- Parameters:
material_selector (str) – Label of the material to assign. Must correspond to an existing material created with LizzyModel.create_material.
mesh_tag (str) – Label of the mesh region where to assign the material.
rosette (Rosette, optional) – Orientation rosette to apply to the material. If none provided, a default rosette with k1 aligned with the global X axis is assigned.
Mesh management methods
- get_elements() list[Triangle]
Returns the list of all mesh elements.
- Returns:
List of all Triangle elements in the mesh.
- Return type:
list of
Triangle
Inlet management methods
- create_pressure_inlet(name: str, initial_pressure_value: float) PressureInlet
Creates a new inlet where a pressure boundary condition is applied.
- Parameters:
- Returns:
The created inlet.
- Return type:
- create_flowrate_inlet(name: str, initial_flowrate_value: float) FlowRateInlet
Creates a new inlet where a volumetric flow rate boundary condition is applied.
- Parameters:
- Returns:
The created inlet.
- Return type:
- assign_inlet(inlet_selector: Inlet | str, boundary_tag: str) None
Selects an inlet from created ones and assigns it to the indicated mesh boundary.
- change_inlet_pressure(inlet_selector: Inlet | str, pressure_value: float, mode: Literal['set', 'delta'] = 'set')
Changes the pressure value at the selected inlet to a new value, according to the selected mode.
- Parameters:
inlet_selector (Inlet | str) – Either the inlet object to assign, or the name of an existing inlet.
pressure_value (float) – The new pressure value to set at the inlet.
mode ({'set', 'delta'}, optional) –
How to apply the new pressure value:
set(default): directly set the new pressure value.delta: increment the existing pressure by the given value.
- Raises:
ValueError – If the mode is not one of the allowed values.
- open_inlet(inlet_selector: Inlet | str)
Sets the selected inlet state to open. When open, the inlet applies its p_value as a Dirichlet boundary condition. An inlet can be opened at any time during the simulation.
Vent management methods
- create_vent(name: str, vacuum_pressure: float = 0.0) Vent
Creates a new vent where a vacuum pressure boundary condition is applied.
Sensor management methods
- create_sensor(name: str, coords: tuple[float, float, float]) None
Create a virtual sensor at the specified position and add it to the model.
- print_sensor_readings()
Prints to the console the current readings of each sensor: time, pressure, fill factor and velocity.
Solver methods
- initialise_solver(solver_type: SolverType = SolverType.ITERATIVE_PETSC, solver_tol: float = 1e-08, solver_max_iter: int = 1000, solver_verbose: bool = False, **solver_kwargs)
Initialize the solver for the filling simulation.
- Parameters:
solver_type (SolverType) – Type of linear solver (DIRECT_DENSE, DIRECT_SPARSE, ITERATIVE_PETSC). Default is ITERATIVE_PETSC and will revert to DIRECT_SPARSE is PETSc is not installed.
solver_tol (float) – Convergence tolerance for iterative solvers
solver_max_iter (int) – Maximum iterations for iterative solvers
solver_verbose (bool) – Print solver convergence information
**solver_kwargs – Additional solver-specific keyword arguments
- Raises:
ConfigurationError – If required components (resin, materials, inlets, vents) are not properly assigned.
- solve(time_interval: float = None) Solution
Advance the filling simulation from the current time until the part is filled.
- Returns:
solution – A Solution object storing the solution fields up to the time step reached. Returns None if in_memory_solve=False (streaming mode).
- Return type:
- solve_time_interval(time_interval: float) Solution
Advance the filling simulation from the current time for the specified time interval.
- initialise_new_solution()
Initialises a new solution, resetting all simulation variables. The part will be emptied and initial boundary conditions restored. This method can be called to reset a simulation and run a new one, without resetting the model.
- save_results(result_name: str = None, solution: Solution = None, save_permeability: bool = False, **kwargs)
Save the results contained in the solution dictionary into an XDMF file.
- Parameters:
solution (
Solution, optional) – The solution that should be written to the XDMF file. If none passed, the latest solution present in the model will be used.result_name (str, optional) – The name of the solution file that will be created. If none passed, the name of the mesh file with appended ‘_RES’ will be used.
save_permeability (bool, optional) – If True, include the full 3x3 permeability tensor as a cell field in the output. Default is False.
- class lizzy.SolverType(*values)
Bases:
EnumEnum representing the available pressure solver types.
- Parameters:
DIRECT_DENSE (SolverType) – Direct solver using dense matrix factorization.
DIRECT_SPARSE (SolverType) – Direct solver using sparse matrix factorization.
ITERATIVE_PETSC (SolverType) – Iterative solver using PETSc.
- DIRECT_DENSE = 1
- DIRECT_SPARSE = 2
- ITERATIVE_PETSC = 3