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
andconfig_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:
|
Class to read a Fluent case file. |
|
Provides access to variables defined in the case. |
|
Represents an input parameter. |
|
Represents an input parameter (old format). |
|
Class to provide mesh data. |
|
Represents an output parameter. |
|
Class to process RP Vars string to expose required outputs. |
|
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.
- 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.
- class ansys.fluent.core.filereader.case_file.InputParameter(raw_data)#
Bases:
object
Represents an input parameter.
- Attributes:
- name
str
- value
The value of this input parameter, usually a string, qualified by units
- name
Methods:
__init__
(raw_data)Initialize InputParameter.
Attributes:
Get the numeric value of a Fluent input parameter.
Get the unit label of a Fluent input parameter.
- __init__(raw_data)#
Initialize InputParameter.
- class ansys.fluent.core.filereader.case_file.InputParameterOld(raw_data)#
Bases:
object
Represents an input parameter (old format).
- Attributes:
- name
str
- value
The value of this input parameter, usually a string, qualified by units
- name
Methods:
__init__
(raw_data)Initialize InputParameter.
Attributes:
Get the numeric value of a Fluent input parameter.
Get the unit label of a Fluent input parameter.
- __init__(raw_data)#
Initialize InputParameter.
- Parameters:
- raw_data
List
Input parameter data as a list.
- raw_data
- class ansys.fluent.core.filereader.case_file.Mesh(file_handle)#
Bases:
object
Class to provide mesh data.
Methods
Returns list of ids of all available surfaces.
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.
Returns list of ids of all available surfaces.
get_surface_locs
(surface_id)Returns range of surface locations for a particular surface.
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:
- name
str
- name
Methods:
__init__
(raw_data)Initialize OutputParameter.
- class ansys.fluent.core.filereader.case_file.RPVarProcessor(rp_vars_str)#
Bases:
object
Class to process RP Vars string to expose required outputs.
Methods
Get the input parameters.
Get the output parameters.
Get the dimensionality associated with this case.
Get the precision associated with this case (single or double).
Get the number of iterations associated with this case.
rp_vars
()Get the rpvars associated with this case.
Access the rpvars associated with this case.
has_rp_var
(name)Find if this case has the given rpvar.
Get the config variables associated with this case.
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.
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.
Get the input parameters.
Get the number of iterations associated with this case.
Get the dimensionality associated with this case.
Get the output parameters.
Get the precision associated with this case (single or double).
rp_vars
()Get the rpvars associated with this case.
Attributes:
Access the config variables associated with this case.
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.
- 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.
- 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.