case_snapshot#
Capture the complete setup of a Fluent case and apply it to solver sessions.
Classes:
|
A snapshot of the complete setup of a Fluent case: all its settings and its mesh. |
- class ansys.fluent.core.solver.case_snapshot.CaseSnapshot(*args, **kwargs)#
Bases:
objectA snapshot of the complete setup of a Fluent case: all its settings and its mesh.
Capture a snapshot once, with
from_session()orfrom_file(), and apply it to any number of solver sessions withapply_to(). The snapshot is carried by a Fluent case file, Fluent’s own complete record of a case, so it includes settings that the settings API does not expose. The case file is handled for you, whether Fluent runs locally, in a container, or remotely through a file transfer service. Solution data is not included.Examples
>>> import ansys.fluent.core as pyfluent >>> snapshot = pyfluent.CaseSnapshot.from_session(solver) >>> snapshot.apply_to(worker_1, worker_2) >>> template = pyfluent.CaseSnapshot.from_file("elbow_setup.cas.h5") >>> template.apply_to(refined_solver, include_mesh=False)
Methods:
__init__(*args, **kwargs)Reject direct construction.
apply_to(*sessions[, include_mesh])Apply this snapshot to one or more solver sessions.
close()Delete the temporary copy of a snapshot captured from a session.
from_file(file_name)Create a snapshot from the setup stored in a case file.
from_session(session)Capture the current setup of a solver session.
save(file_name)Write this snapshot to a case file.
Attributes:
Fluent version that wrote this snapshot, when known.
- __init__(*args, **kwargs)#
Reject direct construction.
- Raises:
TypeErrorAlways: use
from_session()orfrom_file().
- apply_to(*sessions, include_mesh=True)#
Apply this snapshot to one or more solver sessions.
The case of each session is replaced. By default, each session also gets the mesh of the snapshot. With
include_mesh=False, each session keeps its current mesh, whose zone names must match those of the snapshot.Every session is checked before any is changed, and several sessions are loaded in parallel.
- Parameters:
- *sessions
Solver Solver sessions to apply the snapshot to.
- include_meshbool,
optional Whether each session gets the mesh of the snapshot. The default is
True. WithFalse, each session keeps its current mesh.
- *sessions
- Raises:
TypeErrorIf no session is given, or a session is not a solver session.
ValueErrorIf a session runs an older Fluent version than the one that wrote this snapshot, has a different dimension, or, with
include_mesh=False, has a mesh with different zone names.RuntimeErrorIf this snapshot is closed, a session cannot exchange files with the client, or, with
include_mesh=False, a session has no mesh or cannot replace its mesh.ExceptionGroupIf applying fails for some of several sessions. It holds the original error of each of them.
- close()#
Delete the temporary copy of a snapshot captured from a session.
Snapshots created with
from_file()never delete that file. Closing twice is harmless.
- property fluent_version: FluentVersion | None#
Fluent version that wrote this snapshot, when known.
It is known for snapshots captured from a session.
- classmethod from_file(file_name)#
Create a snapshot from the setup stored in a case file.
The file is read each time the snapshot is applied, so it must stay in place. It is never modified or deleted.
- Parameters:
- file_name
os.PathLike|str Path of a Fluent case file (
.cas.h5,.casor.cas.gz).
- file_name
- Returns:
CaseSnapshotThe snapshot of the case file.
- Raises:
FileNotFoundErrorIf the file does not exist.
ValueErrorIf the file is not a Fluent case file.
- classmethod from_session(session)#
Capture the current setup of a solver session.
The snapshot is taken immediately: later changes to
sessionare not included, and the snapshot remains usable after the session exits.- Parameters:
- session
Solver Solver session with a case or mesh loaded.
- session
- Returns:
CaseSnapshotThe snapshot.
- Raises:
TypeErrorIf
sessionis not a solver session.RuntimeErrorIf the session has no case loaded, or cannot exchange files with the client.
- save(file_name)#
Write this snapshot to a case file.
- Parameters:
- file_name
os.PathLike|str Path of the case file to write. Its name must end with the same suffix as the snapshot, such as
.cas.h5.
- file_name
- Returns:
pathlib.PathThe absolute path of the written file.
- Raises:
RuntimeErrorIf this snapshot is closed.
ValueErrorIf the name of
file_nameends with a different suffix.