Cheat Sheet Pyfluent
Cheat Sheet Pyfluent
Version: 0.30.2
Launch and exit a meshing session Add local sizing Generate volume mesh
import ansys.fluent.core as pyfluent wt.add_local_sizing.add_child_to_task() wt.create_volume_mesh.volume_fill.set_state(
meshing = pyfluent.launch_fluent( wt.add_local_sizing() "poly-hexcore")
mode=pyfluent.FluentMode.MESHING) vfc = wt.create_volume_mesh.volume_fill_controls
meshing.exit() vfc.hex_max_cell_length.set_state(0.3)
wt.create_volume_mesh()
Generate surface mesh
Launch and exit a solver session csm = wt.create_surface_mesh Switch to solution mode
csmc = csm.cfd_surface_mesh_controls
solver = pyfluent.launch_fluent( csmc.max_size.set_state(0.3) solver = meshing.switch_to_solver()
mode=pyfluent.FluentMode.SOLVER) wt.create_surface_mesh()
solver.exit()
Boundary conditions
Dimension, Precision, Processor count, Product Describe geometry import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
version wt.describe_geometry.update_child_tasks( file_name =
setup_type_changed=False) examples.download_file("mixing_elbow.cas.h5",
solver = pyfluent.launch_fluent( wt.describe_geometry.setup_type.set_state("The "pyfluent/mixing_elbow")
dimension=pyfluent.Dimension.THREE, geometry consists of only fluid regions with solver = pyfluent.launch_fluent()
precision=pyfluent.Precision.DOUBLE, no voids") solver.settings.file.read_case(
processor_count=2, wt.describe_geometry.update_child_tasks( file_name=file_name)
product_version=pyfluent.FluentVersion.v251 setup_type_changed=True) cold_inlet = pyfluent.VelocityInlet(solver,
) wt.describe_geometry() name="cold-inlet")
cold_inlet.momentum.velocity.set_state(0.4)
inlet_turbulence = cold_inlet.turbulence
Connect to an existing instance of Fluent turbulence_specification =
Update boundaries inlet_turbulence.turbulence_specification
turbulence_specification.allowed_values()
fluent = pyfluent.connect_to_fluent(
ub = wt.update_boundaries turbulence_specification.set_state("Intensity and
ip="127.0.0.1",
ub.boundary_label_list.set_state(["wall-inlet"]) Hydraulic Diameter")
port=50000,
ub.boundary_label_type_list.set_state(["wall"]) turbulent_intensity =
password="abcdefg")
ub.old_boundary_label_list.set_state( inlet_turbulence.turbulent_intensity
["wall-inlet"]) turbulent_intensity.min(),
ub.old_boundary_label_type_list.set_state( turbulent_intensity.max()
Watertight geometry meshing workflow ["velocity-inlet"]) turbulent_intensity.set_state(0.5)
ub() inlet_turbulence.hydraulic_diameter.set_state("4
import ansys.fluent.core as pyfluent [in]")
from ansys.fluent.core import examples cold_inlet.thermal.temperature.set_state(293.15)
import_file_name =
examples.download_file('mixing_elbow.pmdb', Update regions
'pyfluent/mixing_elbow') Cell zone conditions
meshing = pyfluent.launch_fluent( wt.update_regions()
mode="meshing", elbow_fluid =
precision=pyfluent.Precision.DOUBLE, pyfluent.solver.FluidCellZone(solver,
processor_count=2 name="elbow-fluid")
) Add boundary layers elbow_fluid.laminar.set_state(True)
wt = meshing.watertight()
wt.import_geometry.file_name.set_state( wt.add_boundary_layer.add_child_to_task()
import_file_name) wt.add_boundary_layer.bl_control_name.set_state("smooth-transition_1")
Copy material from database
wt.import_geometry.length_unit.set_state('in') wt.add_boundary_layer.insert_compound_child_task()
wt.import_geometry() wt.add_boundary_layer_child_1() import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
file_name = vs.k_epsilon_model.get_state() Steady or transient solution model
examples.download_file("mixing_elbow.cas.h5", vs.k_omega_model.is_active()
"pyfluent/mixing_elbow") vs.k_epsilon_model.allowed_values() setup = pyfluent.solver.Setup(solver)
solver = pyfluent.launch_fluent() vs_ops = vs.options solver_time = setup.general.solver.time
solver.settings.file.read_case(file_name=file_name) vs_ops.production_kato_launder_enabled.is_active() solver_time.get_state()
materials = pyfluent.Materials(solver) vs_ops.production_kato_launder_enabled.get_state() solver_time.allowed_values()
fluids = materials.fluid vs.k_epsilon_model.set_state("realizable") solver_time.set_state("unsteady-1st-order")
fluids.make_a_copy(from_="air",to="air-2") vs_ops.production_kato_launder_enabled.is_active()
air_copy = fluids["air-2"]
air_copy.viscosity.value.set_state(1.81e-05) Pressure-based or density-based solver
cz = solver.settings.setup.cell_zone_conditions Discrete phase model
cz.fluid["elbow-fluid"].material.set_state("air-2") setup = pyfluent.solver.Setup(solver)
dpm = pyfluent.solver.DiscretePhase(solver) solver_type = setup.general.solver.type
dpm_models = dpm.physical_models solver_type.get_state()
Access the object state using pprint dpm_vmf = dpm_models.virtual_mass_force solver_type.allowed_values()
dpm_vmf.enabled.get_state() solver_type.set_state("density-based-explicit")
from pprint import pprint dpm_vmf.virtual_mass_factor.is_active() solver_type.get_state()
pprint(air_copy.get_state(), width=1) dpm_vmf.enabled.set_state(True)
pprint(air_copy.viscosity.option.allowed_values(), dpm_vmf.virtual_mass_factor.get_state()
width=1) Velocity coupling scheme and gradient options
Radiation model methods = pyfluent.solver.Methods(solver)
flow_scheme = methods.p_v_coupling.flow_scheme
Create new material rn = pyfluent.solver.Radiation(solver) flow_scheme.allowed_values()
from pprint import pprint flow_scheme.set_state("Coupled")
mysolid = materials.solid.create("mysolid") pprint(rn.get_state(), width=1) gradient_scheme = methods.gradient_scheme
mysolid.chemical_formula.set_state("SiO2") pprint(rn.model.allowed_values(), width=1) gradient_scheme.allowed_values()
mysolid.density.value.set_state(2650) rn.model.set_state("monte-carlo") gradient_scheme.set_state("green-gauss-node-based")
mysolid.specific_heat.value.set_state(1887) pprint(rn.get_state(), width=1)
mysolid.thermal_conductivity.value.set_state(7.6) rn.monte_carlo.number_of_histories.set_state(1e7)
rn.multiband.create("solar").set_state({ Solution controls
"start": 0,
Energy model "end": 2.8, controls = pyfluent.solver.Controls(solver)
}) pvc = controls.p_v_controls
import ansys.fluent.core as pyfluent rn.multiband.create("thermal-ir").set_state({ emur = pvc.explicit_momentum_under_relaxation
from ansys.fluent.core import examples "start": 2.8, emur.min()
file_name = "end": 100, emur.max()
examples.download_file("mixing_elbow.cas.h5", }) emur.set_state(0.4)
"pyfluent/mixing_elbow") radiation_freq = rn.solve_frequency flow_courant_number = pvc.flow_courant_number
solver = pyfluent.launch_fluent() pprint(radiation_freq.get_state(), width=1) flow_courant_number.min()
solver.settings.file.read_case(file_name=file_name) pprint(rn.get_state(), width=1) flow_courant_number.max()
energy = pyfluent.solver.Energy(solver) flow_courant_number.set_state(0.3)
energy.enabled.get_state()
from pprint import pprint Species model
pprint(energy.get_state(), width=1) Create a report definition
energy.enabled.set_state(False) solver.settings.file.read_case(file_name=file_name)
pprint(energy.get_state(), width=1) species = pyfluent.solver.Species(solver) rep_defs =
energy.enabled.set_state(True) species.get_state() pyfluent.solver.ReportDefinitions(solver)
pprint(energy.get_state(), width=1) from pprint import pprint surface = rep_defs.surface
energy.viscous_dissipation.set_state(True) pprint(species.model.option.allowed_values(), defn_name = "outlet-temp-avg"
pprint(energy.get_state(), width=1) width=1) surface[defn_name] = {}
species.model.option.set_state("species-transport") out_temp = surface[defn_name]
pprint(species.get_state(), width=1) out_temp.report_type.set_state("surface-massavg")
Viscous model species.model.material.get_state() out_temp.field.set_state("temperature")
species.model.material.allowed_values()
vs = pyfluent.solver.Viscous(solver)
from pprint import pprint Initialize and solve
pprint(vs.get_state(), width=1) Battery model
pprint(vs.model.allowed_values(), width=1) solution = solver.settings.solution
vs.options.corner_flow_correction.is_active() battery = pyfluent.solver.Battery(solver) solution.initialization.hybrid_initialize()
vs.model.set_state('k-epsilon') battery.enabled.set_state(True) solution.run_calculation.iterate(iter_count=100)
vs.options.corner_flow_correction.is_active() battery.solution_method.allowed_values()
CaseFile reader Single-phase FileSession Display temperature contour at symmetry
from ansys.fluent.core import examples from ansys.fluent.core import examples contour1 = graphics.Contours["mesh-1"]
from ansys.fluent.core.filereader.case_file import from ansys.fluent.core.file_session import contour1.node_values = False
CaseFile FileSession contour1.field = "SV_T"
case_file_name = examples.download_file( case_file_name = contour1.surfaces_list = ['symmetry']
"Static_Mixer_Parameters.cas.h5", examples.download_file("elbow1.cas.h5", contour1.display('w2')
"pyfluent/static_mixer") "pyfluent/file_session")
reader = CaseFile(case_file_name=case_file_name) data_file_name =
reader.precision() examples.download_file("elbow1.dat.h5",
reader.num_dimensions() "pyfluent/file_session") Display velocity vector data at symmetry and
{p.name: p.value for p in fs = FileSession() wall
reader.input_parameters()} fs.read_case(case_file_name)
{p.name: p.units for p in fs.read_data(data_file_name)
velocity_vector =
reader.output_parameters()} fs.fields.field_info.get_scalar_field_range("SV_T")
graphics.Vectors["velocity-vector"]
fs.fields.field_info.get_surfaces_info()
velocity_vector.field = "SV_T"
fs.fields.field_info.get_scalar_fields_info()
velocity_vector.surfaces_list = ['symmetry',
'wall']
Additionl features velocity_vector.display("w3")
Multiphase FileSession
reader = CaseFile(
project_file_name="Dir1/Dir2/project.flprj") from ansys.fluent.core import examples
reader.rp_vars() from ansys.fluent.core.file_session import
reader.config_vars() FileSession
case_file_name = examples.download_file(
"mixing_elbow_mul_ph.cas.h5",
"pyfluent/file_session")
Extract mesh data data_file_name = examples.download_file(
"mixing_elbow_mul_ph.dat.h5",
from ansys.fluent.core import examples "pyfluent/file_session")
from ansys.fluent.core.filereader.case_file import fs = FileSession()
CaseFile fs.read_case(case_file_name)
case_file_name = fs.read_data(data_file_name)
examples.download_file("elbow1.cas.h5", fs.fields.field_info.get_scalar_field_range(
"pyfluent/file_session") "phase-2:SV_P")
reader = CaseFile(case_file_name=case_file_name) fs.fields.field_info.get_scalar_fields_info()
reader.get_mesh().get_surface_ids()
reader.get_mesh().get_surface_names()
reader.get_mesh().get_surface_locs(3) Post-processing using ansys-fluent-visualization
reader.get_mesh().get_connectivity(3)
reader.get_mesh().get_vertices(3) from ansys.fluent.visualization import set_config
Figure 1: Temperature contour
set_config(blocking=True,
set_view_on_display="isometric")
import ansys.fluent.core as pyfluent Accessing field data objects
DataFile reader from ansys.fluent.visualization.matplotlib import
Plots import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples from ansys.fluent.visualization.pyvista import from ansys.fluent.core import examples
from ansys.fluent.core.filereader.data_file import Graphics case_path = examples.download_file(
DataFile from ansys.fluent.core.file_session import file_name="exhaust_system.cas.h5",
from ansys.fluent.core.filereader.case_file import FileSession directory="pyfluent/exhaust_system"
CaseFile fileSession=FileSession() )
data_file_name = fileSession.read_case("elbow1.cas.h5") data_path = examples.download_file(
examples.download_file("elbow1.dat.h5", fileSession.read_data("elbow1.dat.h5") file_name="exhaust_system.dat.h5",
"pyfluent/file_session") graphics = Graphics(session=fileSession) directory="pyfluent/exhaust_system"
reader = DataFile( )
data_file_name=data_file_name, solver = pyfluent.launch_fluent(
case_file_handle=CaseFile(case_file_name)) Display mesh at wall mode=pyfluent.FluentMode.SOLVER)
reader.case_file solver.settings.file.read_case_data(
reader.variables() mesh1 = graphics.Meshes["mesh-1"] file_name=case_path
reader.get_phases() mesh1.show_edges = True )
reader.get_face_variables("phase-1") mesh1.surfaces_list = [ "wall"] field_data = solver.fields.field_data
mesh1.display("w1")
Get surface data Accessing field info objects Usage of reduction context
from ansys.fluent.core.services.field_data import import ansys.fluent.core as pyfluent import ansys.fluent.core as pyfluent
SurfaceDataType solver = pyfluent.launch_fluent( init = solver.settings.solution.initialization
data = field_data.get_surface_data( mode=pyfluent.FluentMode.SOLVER) init.hybrid_initialize()
surfaces=["inlet"], solver.settings.file.read(file_type="case-dats", inlet = pyfluent.VelocityInlets(solver)
data_types=[SurfaceDataType.Vertices] file_name=mixing_elbow_case_path) solver.fields.reduction.area(
) init = solver.settings.solution.initialization locations=[inlet["inlet1"]]
data["inlet"][SurfaceDataType.Vertices].shape init.hybrid_initialize() )
data["inlet"][SurfaceDataType.Vertices][5] field_info = solver.fields.field_info solver.fields.reduction.area(
faces_normal_and_centroid_data = locations=["inlet1"],
field_data.get_surface_data( ctxt=solver)
data_types=[SurfaceDataType.FacesNormal, Get fields info and range
SurfaceDataType.FacesCentroid],
surfaces=["inlet"] field_info.get_scalar_fields_info()
) field_info.get_range("velocity") Current reduction capabilities
inlet = faces_normal_and_centroid_data["inlet"] field_info.get_range("cell-weight")
inlet[SurfaceDataType.FacesNormal].shape reduction.area(locations)
inlet[SurfaceDataType.FacesCentroid][15] reduction.area_average(expression, locations)
faces_connectivity_data = Get vector fields and surfaces info reduction.area_integral(expression, locations)
field_data.get_surface_data( reduction.volume(locations)
data_types=[SurfaceDataType.FacesConnectivity], field_info.get_vector_fields_info() reduction.volume_average(expression, locations)
surfaces=["inlet"] field_info.get_surfaces_info() reduction.volume_integral(expression, locations)
) reduction.centroid(locations)
inlet = faces_connectivity_data["inlet"] reduction.force(locations)
inlet[SurfaceDataType.FacesConnectivity][5] Accessing reduction functions reduction.pressure_force(locations)
reduction.viscous_force(locations)
import ansys.fluent.core as pyfluent reduction.moment(expression, locations)
Get scalar field data from ansys.fluent.core.solver.function import reduction.count(locations)
reduction reduction.count_if(condition, locations)
abs_press_data = field_data.get_scalar_field_data( from ansys.fluent.core.examples import reduction.minimum(expression, locations)
field_name="absolute-pressure", download_file reduction.maximum(expression, locations)
surfaces=["inlet"] reduction.mass_average(expression, locations)
) solver1 = pyfluent.launch_fluent( reduction.mass_integral(expression, locations)
abs_press_data["inlet"].shape mode=pyfluent.FluentMode.SOLVER reduction.mass_flow_average_absolute(expression,
abs_press_data["inlet"][120] ) locations)
case_path = download_file( reduction.mass_flow_average(expression, locations)
file_name="exhaust_system.cas.h5", reduction.mass_flow_integral(expression, locations)
directory="pyfluent/exhaust_system") reduction.sum(expression, locations, weight)
Get vector field data data_path = download_file( reduction.sum_if(expression, condition, locations,
file_name="exhaust_system.dat.h5", weight)
velocity_vector_data = directory="pyfluent/exhaust_system")
field_data.get_vector_field_data( solver1.settings.file.read_case_data(
field_name="velocity", file_name=case_path
surfaces=["inlet", "inlet1"] ) Reduction example use cases
)
velocity_vector_data["inlet"].shape solver2 = pyfluent.launch_fluent( import ansys.fluent.core as pyfluent
velocity_vector_data["inlet1"].shape mode=pyfluent.FluentMode.SOLVER inlet = pyfluent.VelocityInlets(solver)
)
case_path = download_file( area_inlet_1 = solver.fields.reduction.area(
Get pathlines field data "elbow1.cas.h5", locations=[inlet["inlet1"]])
"pyfluent/file_session" area_inlet = solver.fields.reduction.area(
path_lines_data = ) locations=[inlet])
field_data.get_pathlines_field_data( data_path = download_file( solver.fields.reduction.centroid(
field_name="velocity", "elbow1.dat.h5", locations=[inlet["inlet2"]])
surfaces=["inlet"] "pyfluent/file_session" po_1 = pyfluent.PressureOutlets(solver1)
) ) po_2 = pyfluent.PressureOutlets(solver2)
path_lines_data["inlet"]["vertices"].shape solver2.settings.file.read_case_data( solver.fields.reduction.minimum(
len(path_lines_data["inlet"]["lines"]) file_name=case_path expression="AbsolutePressure",
path_lines_data["inlet"]["velocity"].shape ) locations=[po_1, po_2],
path_lines_data["inlet"]["lines"][100] )
solver = solver1 solver.fields.reduction.sum(
expression="AbsolutePressure", domain_name="mixture")
locations=[inlet], sv_t_wall_fluid.domain sd = field_data.get_surface_data
weight="Area") sv_t_wall_fluid.zones sd.surface_ids.allowed_values()
solver.fields.reduction.sum_if( fluid_temp = sv_t_wall_fluid['fluid']
expression="AbsolutePressure", fluid_temp.size
condition="AbsolutePressure > 0[Pa]", fluid_temp.dtype Monitor convergence of a solution
locations=[inlet], fluid_temp
weight="Area") # get started with case and data loaded
import ansys.fluent.core as pyfluent
Set solution variable data from ansys.fluent.core import examples
Accessing solution variable objects import pandas as pd
wall_temp_array = from tabulate import tabulate
import ansys.fluent.core as pyfluent solution_variable_data.create_empty_array( solver =
from ansys.fluent.core import examples "SV_T", "wall", "mixture") pyfluent.launch_fluent(start_transcript=False)
import_filename = fluid_temp_array = import_case = examples.download_file(
examples.download_file("mixing_elbow.msh.h5", solution_variable_data.create_empty_array( file_name="exhaust_system.cas.h5",
"pyfluent/mixing_elbow") "SV_T", "fluid", "mixture") directory="pyfluent/exhaust_system"
solver = pyfluent.launch_fluent( wall_temp_array[:] = 500 )
mode=pyfluent.FluentMode.SOLVER) fluid_temp_array[:] = 600 import_data = examples.download_file(
solver.settings.file.read(file_type="case", zone_names_to_solution_variable_data = file_name="exhaust_system.dat.h5",
file_name=import_filename) {'wall':wall_temp_array, directory="pyfluent/exhaust_system"
solution_variable_info = 'fluid':fluid_temp_array} )
solver.fields.solution_variable_info solution_variable_data.set_data( solver.file.read_case_data(file_name=import_case)
solution_variable_data = solution_variable_name="SV_T", # check the active report plot monitors using the
solver.fields.solution_variable_data zone_names_to_solution_variable_data= settings relevant object
zone_names_to_solution_variable_data, solver.settings.solution.monitor.report_plots()
domain_name="mixture") # initialize so that monitors object is usable
Get zone information solver.solution.initialization.hybrid_initialize()
# check which monitors are available
zones_info = sorted(solver.monitors.get_monitor_set_names())
Multiple requests in a single transaction # create and register a callback function that will
solution_variable_info.get_zones_info()
zones_info.domains def display_monitor_table(
transaction =
zones_info.zones monitor_set_name="mass-bal-rplot"):
solver.fields.field_data.new_transaction()
zone_info = zones_info['wall'] def display_table():
zone_info data =
transaction.add_surfaces_request(
zone_info.name solver.monitors.get_monitor_set_data(
surfaces=[1],
zone_info.count monitor_set_name=monitor_set_name)
data_types=[SurfaceDataType.Vertices,
zone_info.zone_id # extract iteration numbers
SurfaceDataType.FacesCentroid]
zone_info.zone_type iterations = data[0]
)
# filter out additional callbacks
transaction.add_scalar_fields_request(
if len(iterations) >
surfaces=[1, 2],
display_table.iter_count:
Get solution variable information field_name="pressure",
display_table.iter_count =
node_value=True,
len(iterations)
wall_fluid_info = boundary_value=True
# extract results
solution_variable_info.get_variables_info( )
results = data[1]
zone_names=['wall' , "fluid"], transaction.add_vector_fields_request(
# create a DataFrame
domain_name="mixture") surfaces=[1, 2], field_name="velocity"
df = pd.DataFrame(results,
wall_fluid_info.solution_variables )
index=iterations)
solution_variable_info_centroid = df.index.name = 'Iteration'
wall_fluid_info['SV_CENTROID'] payload_data = transaction.get_fields()
df.reset_index(inplace=True)
solution_variable_info_centroid # The streamed data contains
solution_variable_info_centroid.name duplicates, so eliminate them
solution_variable_info_centroid.dimension Field data allowed values df = df.drop_duplicates(subset=
solution_variable_info_centroid.field_type 'Iteration')
sfd = field_data.get_scalar_field_data print(tabulate(df, headers='keys',
sfd.field_name.allowed_values() tablefmt='psql'))
Get solution variable data sfd.surface_name.allowed_values() display_table.iter_count = 0
return display_table
sv_t_wall_fluid= solution_variable_data.get_data( transaction = field_data.new_transaction()
solution_variable_name="SV_T", asfr = transaction.add_scalar_fields_request register_id = solver.monitors.register_callback(
zone_names=["fluid", "wall"], asfr.field_name.allowed_values() display_monitor_table())
# run the solver and see the full tabulated hyd_dia.get_state() Record Fluent interactions as Python scripts
monitor data on each iteration hyd_dia.state_with_units() (journals)
solver.solution.run_calculation.iterate( hyd_dia.set_state(Quantity(15, "mm"))
iter_count=10) hyd_dia.state_with_units() solver.journal.start(
diam = hyd_dia.as_quantity() file_name="pyfluent_journal.py")
diam solver.journal.stop()
Observing events diam = diam * 2
diam
from ansys.fluent.core import MeshingEvent, hyd_dia.set_state(diam) PyFluent logging functionality
SolverEvent hyd_dia.as_quantity()
def on_case_loaded(session, event_info): import ansys.fluent.core as pyfluent
print("Case loaded. Index = ", config_dict = pyfluent.logging.get_default_config()
event_info.index) Local file transfer service config_dict['handlers']['pyfluent_file'][
callback = meshing.events.register_callback( 'filename'] = 'test.log'
MeshingEvent.CASE_LOADED, on_case_loaded) import ansys.fluent.core as pyfluent pyfluent.logging.enable(custom_config=config_dict)
def on_iteration_ended(session, event_info): from ansys.fluent.core import examples pyfluent.logging.list_loggers()
print("Iteration ended. Index = ", from ansys.fluent.core.utils.file_transfer_service logger = pyfluent.logging.get_logger(
event_info.index) import LocalFileTransferStrategy 'pyfluent.networking')
callback_id = solver.events.register_callback( logger.setLevel('ERROR')
SolverEvent.ITERATION_ENDED, mesh_file_name = examples.download_file( pyfluent.logging.set_global_level('DEBUG')
on_iteration_ended) "mixing_elbow.msh.h5",
"pyfluent/mixing_elbow")
meshing_session = pyfluent.launch_fluent( API search
mode=pyfluent.FluentMode.MESHING,
Transfer a case or mesh file between PyFluent file_transfer_service= # Semantic search
sessions LocalFileTransferStrategy()) import ansys.fluent.core as pyfluent
meshing_session.upload( pyfluent.search("font")
import ansys.fluent.core as pyfluent file_name=mesh_file_name,
from ansys.fluent.core.examples import remote_file_name="elbow.msh.h5") # Whole word search
download_file meshing_session.meshing.File.ReadMesh( pyfluent.search("ApplicationFontSize",
from ansys.fluent.core.utils.data_transfer import FileName="elbow.msh.h5") match_whole_word=True)
transfer_case meshing_session.meshing.File.WriteMesh(
mesh_file_name = download_file( FileName="write_elbow.msh.h5") # Wildcard pattern search
"mixing_elbow.msh.h5", meshing_session.download( pyfluent.search("local*", wildcard=True)
"pyfluent/mixing_elbow" file_name="write_elbow.msh.h5",
) local_directory="<local_directory_path>")
pure_meshing_session = pyfluent.launch_fluent( Containerization of Fluent
mode=pyfluent.FluentMode.PURE_MESHING
) Remote file transfer service # Within the PyFluent source navigate to the
pure_meshing_session.tui.file.read_mesh( `docker` directory.
import_file_name import ansys.fluent.core as pyfluent cd pyfluent/docker
) from ansys.fluent.core import examples
solver_session = pyfluent.launch_fluent( from ansys.fluent.core.utils.file_transfer_service # Copy needed files
mode=pyfluent.FluentMode.SOLVER import RemoteFileTransferStrategy python copy_docker_files.py <path to 'ansys_inc'
) directory> <path to 'docker/fluent_<version>'
transfer_case( case_file_name = examples.download_file( directory>
source_instance=meshing, solvers=[solver], "mixing_elbow.cas.h5",
file_type="mesh", file_name_stem='', "pyfluent/mixing_elbow") # Build the Docker image
num_files_to_try=1, clean_up_temp_file=True, solver_session = pyfluent.launch_fluent( sudo docker build -t ansys_inc <path to
overwrite_previous=True mode=pyfluent.FluentMode.SOLVER, 'docker/fluent_<version>' directory>
) file_transfer_service=
RemoteFileTransferStrategy())
solver_session.upload( Run Docker container using the command line
PyAnsys Units to work in arbitrary physical file_name=case_file_name,
examples remote_file_name="elbow.cas.h5") # Solver mode
solver_session.file.read_case( sudo docker run -it --name ansys-inc -e
from ansys.units import Quantity file_name="elbow.cas.h5") ANSYSLMD_LICENSE_FILE=<license file or
bc = solver.settings.setup.boundary_conditions solver_session.file.write_case( server> ansys_inc 3ddp -gu
vi = bc.velocity_inlet file_name="write_elbow.cas.h5") # Meshing mode
hyd_dia = solver_session.download( sudo docker run -it --name ansys-inc -e
vi["hot-inlet"].turbulence.hydraulic_diameter file_name="write_elbow.cas.h5", ANSYSLMD_LICENSE_FILE=<license file or
hyd_dia.set_state(.02) local_directory="<local_directory_path>") server> ansys_inc 3ddp -gu -meshing
Run Docker container using PyFluent solver = pyfluent.launch_fluent( session.scheme_eval.exec(('(ti-menu-load-string
container_dict=custom_config) "/report/system/proc-stats")',))
import os # Returns TUI output string
import ansys.fluent.core as pyfluent session.scheme_eval.string_eval("(+ 2 3)")
os.environ["ANSYSLMD_LICENSE_FILE"] = "<license session.scheme_eval.string_eval("(rpgetvar
file or server>" Scheme code evaluation 'mom/relax)")
session.scheme_eval.scheme_eval("(+ 2 3)")
custom_config = { import ansys.fluent.core as pyfluent session.scheme_eval.scheme_eval("(rpgetvar
'fluent_image': 'ansys_inc:latest', S = pyfluent.services.scheme_eval.Symbol 'mom/relax)")
'mount_source': f"{os.getcwd()}", session.scheme_eval.eval([S('+'), 2, 3])
'auto_remove': False} session.scheme_eval.eval([S('rpgetvar'),
[S('string->symbol'), "mom/relax"]])
PyFluent Documentation Getting started Examples API reference FAQ Discussions Issues