case_snapshot#

Capture the complete setup of a Fluent case and apply it to solver sessions.

Classes:

CaseSnapshot(*args, **kwargs)

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: object

A snapshot of the complete setup of a Fluent case: all its settings and its mesh.

Capture a snapshot once, with from_session() or from_file(), and apply it to any number of solver sessions with apply_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

Fluent version that wrote this snapshot, when known.

__init__(*args, **kwargs)#

Reject direct construction.

Raises:
TypeError

Always: use from_session() or from_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:
*sessionsSolver

Solver sessions to apply the snapshot to.

include_meshbool, optional

Whether each session gets the mesh of the snapshot. The default is True. With False, each session keeps its current mesh.

Raises:
TypeError

If no session is given, or a session is not a solver session.

ValueError

If 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.

RuntimeError

If 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.

ExceptionGroup

If 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_nameos.PathLike | str

Path of a Fluent case file (.cas.h5, .cas or .cas.gz).

Returns:
CaseSnapshot

The snapshot of the case file.

Raises:
FileNotFoundError

If the file does not exist.

ValueError

If 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 session are not included, and the snapshot remains usable after the session exits.

Parameters:
sessionSolver

Solver session with a case or mesh loaded.

Returns:
CaseSnapshot

The snapshot.

Raises:
TypeError

If session is not a solver session.

RuntimeError

If 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_nameos.PathLike | str

Path of the case file to write. Its name must end with the same suffix as the snapshot, such as .cas.h5.

Returns:
pathlib.Path

The absolute path of the written file.

Raises:
RuntimeError

If this snapshot is closed.

ValueError

If the name of file_name ends with a different suffix.