CaseFile#

The CaseFile class provides a reader for Fluent case files.

Sample usage#

You can use the CaseFile class by importing it and passing a case file path. This example shows how to have the CaseFile class read a case file (.cas.h5) from the examples repository:

>>>
>>> from ansys.fluent.core import examples
>>> from ansys.fluent.core.filereader.case_file import CaseFile

>>> case_file_name = examples.download_file("Static_Mixer_Parameters.cas.h5", "pyfluent/static_mixer")
>>> reader = CaseFile(case_file_name=case_file_name)
>>> reader.precision()
2
>>> reader.num_dimensions()
3
>>> {p.name: p.value for p in reader.input_parameters()}
{'inlet1_vel': '1 [m/s]', 'inlet1_temp': '300 [K]', 'inlet2_vel': '1 [m/s]', 'inlet2_temp': '350 [K]'}
>>> {p.name: p.units for p in reader.output_parameters()}
{'outlet-temp-avg-op': 'K', 'outlet-vel-avg-op': 'm s^-1'}

Additional features#

Along with basic functionality, the CaseFile class provides many additional features, including these:

  • Supports multiple file formats The CaseFile class can read Fluent case files (CAS, CAS.HF, and CAS.GZ) in both text and binary formats.

  • Takes a project path as an argument The CaseFile class has an option for taking a Fluent project path (FLPRJ) as an argument and locating the case file path:

    >>>
    >>> reader = CaseFile(project_file_name="Dir1/Dir2/project.flprj")
    
  • Reads ``rp_vars`` and ``config_vars`` variables The CaseFile class can provide the rp_vars and config_vars variables:

    >>>
    >>> reader.rp_vars()
    >>> reader.config_vars()
    
  • Extracts mesh data The CaseReader can be used to extract mesh data. This example shows how to have the CaseFile class read a case file (.cas.h5) from the examples repository and extract and use mesh data:

    >>>
    >>> from ansys.fluent.core import examples
    >>> from ansys.fluent.core.filereader.case_file import CaseFile
    
    >>> case_file_name = examples.download_file("elbow1.cas.h5", "pyfluent/file_session")
    >>> reader = CaseFile(case_file_name=case_file_name)
    >>> reader.get_mesh().get_surface_ids()
    [3, 4, 5, 6, 7, 9]
    >>> reader.get_mesh().get_surface_names()
    ['wall',
     'symmetry',
     'pressure-outlet-7',
     'velocity-inlet-6',
     'velocity-inlet-5',
     'default-interior']
    >>> reader.get_mesh().get_surface_locs(3)
    [0, 3629]
    >>> reader.get_mesh().get_connectivity(3)
    array([   4,    3,    2, ...,  727,  694, 3809], dtype=uint32)
    >>> reader.get_mesh().get_vertices(3)
    array([ 0.        , -0.1016    ,  0.        , ...,  0.00620755,
     -0.19304685,  0.03033731])
    

Reader for Fluent case files.

Example#

>>>
>>> from ansys.fluent.core import examples
>>> from ansys.fluent.core.filereader.case_file import CaseFile

>>> case_file_name = examples.download_file("Static_Mixer_Parameters.cas.h5", "pyfluent/static_mixer", return_without_path=False)

>>> reader = CaseFile(case_file_name=case_file_name) # Instantiate a CaseFile class
>>> input_parameters = reader.input_parameters()     # Get lists of input parameters
>>> output_parameters = reader.output_parameters()   # Get lists of output parameters

Classes:

CaseFile([case_file_name, project_file_name])

Class to read a Fluent case file.

CaseVariable(variables[, path])

Provides access to variables defined in the case.

InputParameter(raw_data)

Represents an input parameter.

InputParameterOld(raw_data)

Represents an input parameter (old format).

Mesh(file_handle)

Class to provide mesh data.

OutputParameter(raw_data)

Represents an output parameter.

RPVarProcessor(rp_vars_str)

Class to process RP Vars string to expose required outputs.

SettingsFile([settings_file_name])

Class to read a Fluent Settings file.

class ansys.fluent.core.filereader.case_file.CaseFile(case_file_name=None, project_file_name=None)#

Bases: RPVarProcessor

Class to read a Fluent case file.

Methods

get_mesh()

Get the mesh data.

Methods:

__init__([case_file_name, project_file_name])

Initialize a CaseFile object.

get_mesh()

Get the mesh data.

__init__(case_file_name=None, project_file_name=None)#

Initialize a CaseFile object. Exactly one file path argument must be specified.

Parameters:
case_file_nameOptional[str]

The path of a case file.

project_file_nameOptional[str]

The path of a project file from which the case file is selected.

get_mesh()#

Get the mesh data.

class ansys.fluent.core.filereader.case_file.CaseVariable(variables, path='')#

Bases: object

Provides access to variables defined in the case.

Methods:

__init__(variables[, path])

Initialize CaseVariable.

__init__(variables, path='')#

Initialize CaseVariable.

Parameters:
variablesdict

The variables dictionary.

pathOptional[str]

The path to the variables.

class ansys.fluent.core.filereader.case_file.InputParameter(raw_data)#

Bases: object

Represents an input parameter.

Attributes:
namestr
value

The value of this input parameter, usually a string, qualified by units

Methods:

__init__(raw_data)

Initialize InputParameter.

Attributes:

numeric_value

Get the numeric value of a Fluent input parameter.

units

Get the unit label of a Fluent input parameter.

__init__(raw_data)#

Initialize InputParameter.

Parameters:
raw_dataDict[str, str]

Input parameter data as a nested dictionary.

property numeric_value: float#

Get the numeric value of a Fluent input parameter.

Returns:
float

Numeric value of the Fluent input parameter.

property units: str#

Get the unit label of a Fluent input parameter.

Returns:
str

Unit label of the Fluent input parameter.

class ansys.fluent.core.filereader.case_file.InputParameterOld(raw_data)#

Bases: object

Represents an input parameter (old format).

Attributes:
namestr
value

The value of this input parameter, usually a string, qualified by units

Methods:

__init__(raw_data)

Initialize InputParameter.

Attributes:

numeric_value

Get the numeric value of a Fluent input parameter.

units

Get the unit label of a Fluent input parameter.

__init__(raw_data)#

Initialize InputParameter.

Parameters:
raw_dataList

Input parameter data as a list.

property numeric_value: float#

Get the numeric value of a Fluent input parameter.

Returns:
float

Numeric value of the Fluent input parameter.

property units: str#

Get the unit label of a Fluent input parameter.

Returns:
str

Unit label of the Fluent input parameter.

class ansys.fluent.core.filereader.case_file.Mesh(file_handle)#

Bases: object

Class to provide mesh data.

Methods

get_surface_ids()

Returns list of ids of all available surfaces.

get_surface_names()

Returns list of names of all available surfaces.

get_surface_locs(surface_id)

Returns range of surface locations for a particular surface.

get_connectivity(surface_id)

Returns numpy array of face connectivity data for a particular surface.

get_vertices(surface_id)

Returns numpy array of vertices data for a particular surface.

Methods:

__init__(file_handle)

Initialize the object.

get_connectivity(surface_id)

Returns numpy array of face connectivity data for a particular surface.

get_surface_ids()

Returns list of ids of all available surfaces.

get_surface_locs(surface_id)

Returns range of surface locations for a particular surface.

get_surface_names()

Returns list of names of all available surfaces.

get_vertices(surface_id)

Returns numpy array of vertices data for a particular surface.

__init__(file_handle)#

Initialize the object.

get_connectivity(surface_id)#

Returns numpy array of face connectivity data for a particular surface.

get_surface_ids()#

Returns list of ids of all available surfaces.

get_surface_locs(surface_id)#

Returns range of surface locations for a particular surface.

get_surface_names()#

Returns list of names of all available surfaces.

get_vertices(surface_id)#

Returns numpy array of vertices data for a particular surface.

class ansys.fluent.core.filereader.case_file.OutputParameter(raw_data)#

Bases: object

Represents an output parameter.

Attributes:
namestr

Methods:

__init__(raw_data)

Initialize OutputParameter.

__init__(raw_data)#

Initialize OutputParameter.

Parameters:
raw_datalist

Output parameter as a nested list.

class ansys.fluent.core.filereader.case_file.RPVarProcessor(rp_vars_str)#

Bases: object

Class to process RP Vars string to expose required outputs.

Methods

input_parameters()

Get the input parameters.

output_parameters()

Get the output parameters.

num_dimensions()

Get the dimensionality associated with this case.

precision()

Get the precision associated with this case (single or double).

iter_count()

Get the number of iterations associated with this case.

rp_vars()

Get the rpvars associated with this case.

rp_var

Access the rpvars associated with this case.

has_rp_var(name)

Find if this case has the given rpvar.

config_vars()

Get the config variables associated with this case.

config_var

Access the config variables associated with this case.

has_config_var(name)

Get whether the case has a given variable.

Methods:

__init__(rp_vars_str)

Initialize a RPVarProcessor object.

config_vars()

Get the config variables associated with this case.

has_config_var(name)

Get whether the case has a given variable.

has_rp_var(name)

Find if this case has the given rpvar.

input_parameters()

Get the input parameters.

iter_count()

Get the number of iterations associated with this case.

num_dimensions()

Get the dimensionality associated with this case.

output_parameters()

Get the output parameters.

precision()

Get the precision associated with this case (single or double).

rp_vars()

Get the rpvars associated with this case.

Attributes:

config_var

Access the config variables associated with this case.

rp_var

Access the rpvars associated with this case.

__init__(rp_vars_str)#

Initialize a RPVarProcessor object.

Parameters:
rp_vars_str :str

RP Vars string.

property config_var: CaseVariable#

Access the config variables associated with this case.

Returns:
CaseVariable

The config variables associated with this case.

config_vars()#

Get the config variables associated with this case.

Returns:
dict

The config variables associated with this case.

has_config_var(name)#

Get whether the case has a given variable.

has_rp_var(name)#

Find if this case has the given rpvar.

Parameters:
namestr

Name of the rpvar.

Returns:
bool

Whether this case has the given rpvar.

input_parameters()#

Get the input parameters.

Returns:
Union[List[InputParameter], List[InputParameterOld]]

The list of input parameters.

iter_count()#

Get the number of iterations associated with this case.

Returns:
int

The number of iterations associated with this case.

num_dimensions()#

Get the dimensionality associated with this case.

Returns:
int

The number of dimensions.

output_parameters()#

Get the output parameters.

Returns:
List[OutputParameter]

The list of output parameters.

precision()#

Get the precision associated with this case (single or double).

Returns:
int

Either 1 or 2 to indicate single or double precision respectively.

property rp_var: CaseVariable#

Access the rpvars associated with this case.

Returns:
CaseVariable

The rpvars associated with this case.

rp_vars()#

Get the rpvars associated with this case.

Returns:
dict

The rpvars associated with this case.

class ansys.fluent.core.filereader.case_file.SettingsFile(settings_file_name=None)#

Bases: RPVarProcessor

Class to read a Fluent Settings file.

Methods:

__init__([settings_file_name])

Initialize a SettingsFile object.

__init__(settings_file_name=None)#

Initialize a SettingsFile object. Exactly one file path argument must be specified.

Parameters:
settings_file_nameOptional[str]

The path of a settings file.