diff --git a/doc/source/_static/ahmed_body_model_pressure_coeff.png b/doc/source/_static/ahmed_body_model_pressure_coeff.png index ab057e0..23fcbd1 100644 Binary files a/doc/source/_static/ahmed_body_model_pressure_coeff.png and b/doc/source/_static/ahmed_body_model_pressure_coeff.png differ diff --git a/doc/source/_static/ahmed_body_model_velocity_mag.png b/doc/source/_static/ahmed_body_model_velocity_mag.png index 3b7be7c..e9e4865 100644 Binary files a/doc/source/_static/ahmed_body_model_velocity_mag.png and b/doc/source/_static/ahmed_body_model_velocity_mag.png differ diff --git a/doc/source/_static/cht_avg_pressure.png b/doc/source/_static/cht_avg_pressure.png index d6d3d36..f2cf90b 100644 Binary files a/doc/source/_static/cht_avg_pressure.png and b/doc/source/_static/cht_avg_pressure.png differ diff --git a/doc/source/_static/cht_mesh.png b/doc/source/_static/cht_mesh.png new file mode 100644 index 0000000..07a50df Binary files /dev/null and b/doc/source/_static/cht_mesh.png differ diff --git a/doc/source/_static/cht_temp_contour.png b/doc/source/_static/cht_temp_contour.png new file mode 100644 index 0000000..2cbe7ad Binary files /dev/null and b/doc/source/_static/cht_temp_contour.png differ diff --git a/doc/source/_static/cht_vector.png b/doc/source/_static/cht_vector.png new file mode 100644 index 0000000..1ea71ba Binary files /dev/null and b/doc/source/_static/cht_vector.png differ diff --git a/doc/source/_static/cht_xy_pressure.png b/doc/source/_static/cht_xy_pressure.png index 7955b1b..86e67a9 100644 Binary files a/doc/source/_static/cht_xy_pressure.png and b/doc/source/_static/cht_xy_pressure.png differ diff --git a/examples/00-released_examples/00-ablation.py b/examples/00-released_examples/00-ablation.py index e116551..466c113 100644 --- a/examples/00-released_examples/00-ablation.py +++ b/examples/00-released_examples/00-ablation.py @@ -13,7 +13,7 @@ # the damaging effects of external high temperatures caused by shock wave and viscous # heating. The ablative material is chipped away due to surface reactions that remove a # significant amount of heat and keep the vehicle surface temperature below the melting -# point. In this tutorial, Fluent ablation model is demonstrated for a reendtry vehicle +# point. In this tutorial, Fluent ablation model is demonstrated for a reentry vehicle # geometry simplified as a 3D wedge. # # This tutorial demonstrates how to do the following: @@ -32,16 +32,15 @@ # (displayed in yellow). As the ablative coating chips away, the surface of the wall # moves. The moving of the surface is modeled using dynamic meshes. The surface moving # rate is estimated by Vieille's empirical law: -# -# where r is the surface moving rate, p is the absolute pressure, and A and n are model -# parameters. In the considered case, A = 5 and n = 0.1. - -#################################################################################### +############################################################################### # .. math:: # # r = A \cdot p^n +############################################################################### +# where r is the surface moving rate, p is the absolute pressure, and A and n are model +# parameters. In the considered case, A = 5 and n = 0.1. #%% # .. image:: ../../_static/ablation-problem-schematic.png @@ -81,29 +80,35 @@ from ansys.fluent.visualization import set_config -set_config(blocking=True, set_view_on_display="isometric") +set_config(blocking=True, set_view_on_display="xz") #################################################################################### # Launch Fluent session with solver mode # ================================================================================== -session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=4) +session = pyfluent.launch_fluent( + precision="double", + processor_count=4, +) #################################################################################### # Import mesh # ================================================================================== -session.tui.file.read_case(import_filename) +session.file.read_case(file_name=import_filename) #################################################################################### # Define models # ================================================================================== -session.tui.define.models.solver.density_based_implicit("yes") -session.tui.define.models.unsteady_1st_order("yes") -session.tui.define.operating_conditions.operating_pressure("0") -session.tui.define.models.energy("yes") -session.tui.define.models.ablation("yes") +general = session.setup.general +general.solver.type = "density-based-implicit" +general.solver.time = "unsteady-1st-order" +general.operating_conditions.operating_pressure = 0 + +models = session.setup.models +models.energy.enabled = True +models.ablation.enabled = True ################################################################### # Define material @@ -117,35 +122,41 @@ # Following is alternative Settings API method to define material properties # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ session.setup.materials.fluid["air"]() -session.setup.materials.fluid["air"] = {"density": {"option": "ideal-gas"}} +session.setup.materials.fluid["air"] = { + "density": { + "option": "ideal-gas", + }, +} ############################ # Define boundary conditions # ========================== -session.setup.boundary_conditions.change_type( - zone_list=["inlet"], new_type="pressure-far-field" +bc = session.setup.boundary_conditions +bc.set_zone_type( + zone_list=["inlet"], + new_type="pressure-far-field", ) -session.setup.boundary_conditions.pressure_far_field["inlet"] = { - "gauge_pressure": 13500, - "t": 4500, - "m": 3, - "turb_intensity": 0.001, -} -session.setup.boundary_conditions.pressure_outlet["outlet"] = { - "gauge_pressure": 13500, - "prevent_reverse_flow": True, -} + +inlet_bc = bc.pressure_far_field["inlet"] +inlet_bc.gauge_pressure.value = 13500 +inlet_bc.t.value = 4500 +inlet_bc.m.value = 3 +inlet_bc.turbulent_intensity = 0.001 + +outlet_bc = bc.pressure_outlet["outlet"] +outlet_bc.momentum.gauge_pressure.value = 13500 +outlet_bc.momentum.prevent_reverse_flow = True ############################################# # Ablation boundary condition (Vielles Model) # ++++++++++++++++++++++++++++++++++++++++++++ # Once you have specified the ablation boundary conditions for the wall, # Ansys Fluent automatically enables the Dynamic Mesh model with the Smoothing and -# Remeshing options, #creates the wall-ablation dynamic mesh zone, and configure +# Remeshing options, creates the wall-ablation dynamic mesh zone, and configure # appropriate dynamic mesh settings. -session.setup.boundary_conditions.wall["wall_ablation"] = { +session.setup.boundary_conditions.wall["wall_ablation"].ablation = { "ablation_select_model": "Vielle's Model", "ablation_vielle_a": 5, "ablation_vielle_n": 0.1, @@ -240,111 +251,152 @@ # Define solver settings # ======================= -session.tui.define.models.unsteady_2nd_order("yes") -session.tui.solve.set.limits( - "1", "5e+10", "1", "25000", "1e-14", "1e-20", "100000", "0.2" -) -session.tui.solve.monitors.residual.convergence_criteria( - "1e-3", "1e-3", "1e-3", "1e-3", "1e-6", "1e-3", "1e-3" -) +session.setup.general.solver.time = "unsteady-2nd-order" + +session.solution.controls.limits = { + "min_pressure": 1, + "max_pressure": 5e10, + "min_temperature": 1, + "max_temperature": 25000, + "min_tke": 1e-14, + "min_omega": 1e-20, + "max_turb_visc_ratio": 100000, + "positivity_rate": 0.2, +} + +eqns = session.solution.monitor.residual.equations +eqns["continuity"].absolute_criteria = 1e-3 +eqns["x-velocity"].absolute_criteria = 1e-3 +eqns["y-velocity"].absolute_criteria = 1e-3 +eqns["z-velocity"].absolute_criteria = 1e-3 +eqns["energy"].absolute_criteria = 1e-6 +eqns["k"].absolute_criteria = 1e-3 +eqns["omega"].absolute_criteria = 1e-3 ############################################ # Create report definitions # ========================== -session.tui.solve.report_definitions.add( - "drag_force_x", "drag", "thread-names", "wall_ablation", "()", "scaled?", "no", "q" -) -session.tui.solve.report_plots.add( - "drag_force_x", "report-defs", "drag_force_x", "()", "q" -) -session.tui.solve.report_plots.axes( - "drag_force_x", "numbers", "float", "4", "exponential", "2", "q" -) -session.tui.solve.report_files.add( - "drag_force_x", - "report-defs", - "drag_force_x", - "()", - "file-name", - "drag_force_x.out", - "q", -) -session.tui.solve.report_definitions.add( - "pressure_avg_abl_wall", - "surface-areaavg", - "field", - "pressure", - "surface-names", - "wall_ablation", - "()", - "q", -) -session.tui.solve.report_plots.add( - "pressure_avg_abl_wall", "report-defs", "pressure_avg_abl_wall", "()", "q" -) -session.tui.solve.report_plots.axes( - "pressure_avg_abl_wall", "numbers", "float", "4", "exponential", "2", "q" -) -session.tui.solve.report_files.add( - "pressure_avg_abl_wall", - "report-defs", - "pressure_avg_abl_wall", - "()", - "file-name", - "pressure_avg_abl_wall.out", - "q", -) -session.tui.solve.report_definitions.add( - "recede_point", - "surface-vertexmax", - "field", - "z-coordinate", - "surface-names", - "wall_ablation", - "()", - "q", -) -session.tui.solve.report_plots.add( - "recede_point", "report-defs", "recede_point", "()", "q" -) -session.tui.solve.report_plots.axes( - "recede_point", "numbers", "float", "4", "exponential", "2", "q" -) -session.tui.solve.report_files.add( - "recede_point", - "report-defs", - "recede_point", - "()", - "file-name", - "recede_point.out", - "q", -) +report_defs = session.solution.report_definitions +report_defs.drag["drag_force_x"] = { + "zones": ["wall_ablation"], + "report_output_type": "Drag Force", +} +report_defs.surface["pressure_avg_abl_wall"] = { + "report_type": "surface-areaavg", + "field": "pressure", + "surface_names": ["wall_ablation"], +} +report_defs.surface["recede_point"] = { + "report_type": "surface-vertexmax", + "field": "z-coordinate", + "surface_names": ["wall_ablation"], +} + +############################################ +# Create report plots +# =================== + +report_plots = session.solution.monitor.report_plots +report_plots["drag_force_x"] = { + "report_defs": ["drag_force_x"], + "axes": { + "x": { + "number_format": { + "format_type": "float", + "precision": 4, + }, + }, + "y": { + "number_format": { + "format_type": "exponential", + "precision": 2, + }, + }, + }, +} +report_plots["pressure_avg_abl_wall"] = { + "report_defs": ["pressure_avg_abl_wall"], + "axes": { + "x": { + "number_format": { + "format_type": "float", + "precision": 4, + }, + }, + "y": { + "number_format": { + "format_type": "exponential", + "precision": 2, + }, + }, + }, +} +report_plots["recede_point"] = { + "report_defs": ["recede_point"], + "axes": { + "x": { + "number_format": { + "format_type": "float", + "precision": 4, + }, + }, + "y": { + "number_format": { + "format_type": "exponential", + "precision": 2, + }, + }, + }, +} + +############################################ +# Create report files +# =================== + +report_files = session.solution.monitor.report_files +report_files["drag_force_x"] = { + "report_defs": ["drag_force_x"], + "file_name": "drag_force_x.out", +} +report_files["pressure_avg_abl_wall"] = { + "report_defs": ["pressure_avg_abl_wall"], + "file_name": "pressure_avg_abl_wall.out", +} +report_files["recede_point"] = { + "report_defs": ["recede_point"], + "file_name": "recede_point.out", +} ############################################ # Initialize and Save case # ======================== -session.tui.solve.initialize.compute_defaults.pressure_far_field("inlet") -session.tui.solve.initialize.initialize_flow() -session.tui.solve.set.transient_controls.time_step_size("1e-6") +session.solution.initialization.compute_defaults( + from_zone_type="pressure-far-field", + from_zone_name="inlet", +) +session.solution.initialization.standard_initialize() +session.solution.run_calculation.transient_controls.time_step_size = 1e-6 -save_case_data_as = Path(save_path) / "ablation.cas.h5" -session.tui.file.write_case(save_case_data_as) +session.file.write_case(file_name=save_path / "ablation.cas.h5") ############################################ # Run the calculation # =================== # Note: It may take about half an hour to finish the calculation. -session.tui.solve.dual_time_iterate(100, 20) +session.solution.run_calculation.dual_time_iterate( + time_step_count=100, + max_iter_per_step=20, +) ############################################### # Save simulation data # ==================== # Write case and data files -save_case_data_as = Path(save_path) / "ablation_Solved.cas.h5" -session.tui.file.write_case_data(save_case_data_as) + +session.file.write_case_data(file_name=save_path / "ablation_Solved.cas.h5") #################################################################################### # Post Processing @@ -381,7 +433,7 @@ #%% # .. image:: ../../_static/ablation-recede_point.png # :align: center -# :alt: Recede point (albation) +# :alt: Recede point (ablation) #%% # Recede point (deformation due to ablation) @@ -391,19 +443,24 @@ # ================ # Following contours are displayed in the Fluent GUI: -session.tui.display.surface.plane_surface("mid_plane", "zx-plane", "0") +results = session.results + +results.surfaces.plane_surface["mid_plane"] = { + "method": "zx-plane", + "y": 0, +} -session.results.graphics.contour["contour_pressure"] = { +results.graphics.contour["contour_pressure"] = { "field": "pressure", "surfaces_list": ["mid_plane"], } -session.results.graphics.contour.display(object_name="contour_pressure") +results.graphics.contour.display(object_name="contour_pressure") -session.results.graphics.contour["contour_mach"] = { +results.graphics.contour["contour_mach"] = { "field": "mach-number", "surfaces_list": ["mid_plane"], } -session.results.graphics.contour.display(object_name="contour_mach") +results.graphics.contour.display(object_name="contour_mach") ############################################### # Post processing with PyVista (3D visualization) diff --git a/examples/00-released_examples/00-ahmed_body_workflow.py b/examples/00-released_examples/00-ahmed_body_workflow.py index cc62f38..e36d281 100644 --- a/examples/00-released_examples/00-ahmed_body_workflow.py +++ b/examples/00-released_examples/00-ahmed_body_workflow.py @@ -56,13 +56,16 @@ ####################################################################################### # Configure specific settings for this example # ===================================================================================== -set_config(blocking=True, set_view_on_display="isometric") +set_config(blocking=True, set_view_on_display="zy") ####################################################################################### # Launch Fluent session with meshing mode # ===================================================================================== -session = pyfluent.launch_fluent(mode="meshing", cleanup_on_exit=True) -session.check_health() +session = pyfluent.launch_fluent( + mode="meshing", + processor_count=4, +) +session.health_check_service.status() ####################################################################################### # Meshing Workflow @@ -234,74 +237,86 @@ ####################################################################################### # Define Materials # ===================================================================================== -session.tui.define.materials.change_create("air", "air", "yes", "constant", density) -session.tui.define.models.viscous.ke_realizable("yes") -session.tui.define.models.viscous.curvature_correction("yes") +session.setup.materials.fluid["air"].density.value = density + +viscous = session.setup.models.viscous +viscous.model = "k-epsilon" +viscous.k_epsilon_model = "realizable" +viscous.options.curvature_correction = True ####################################################################################### # Define Boundary Conditions # ===================================================================================== inlet = session.setup.boundary_conditions.velocity_inlet["inlet"] -inlet.turb_intensity = 0.05 -inlet.vmag = inlet_velocity -inlet.turb_viscosity_ratio = 5 +inlet.turbulence.turbulent_intensity = 0.05 +inlet.momentum.velocity.value = inlet_velocity +inlet.turbulence.turbulent_viscosity_ratio_real = 5 outlet = session.setup.boundary_conditions.pressure_outlet["outlet"] -outlet.turb_intensity = 0.05 +outlet.turbulence.turbulent_intensity = 0.05 ####################################################################################### # Define Reference Values # ===================================================================================== -session.tui.report.reference_values.area(inlet_area) -session.tui.report.reference_values.density(density) -session.tui.report.reference_values.velocity(inlet_velocity) +reference_values = session.setup.reference_values +session.setup.reference_values.area = inlet_area +session.setup.reference_values.density = density +session.setup.reference_values.velocity = inlet_velocity ####################################################################################### # Define Solver Settings # ===================================================================================== -session.tui.solve.set.p_v_coupling(24) +session.solution.methods.p_v_coupling.flow_scheme = "Coupled" -session.tui.solve.set.discretization_scheme("pressure", 12) -session.tui.solve.set.discretization_scheme("k", 1) -session.tui.solve.set.discretization_scheme("epsilon", 1) -session.tui.solve.initialize.set_defaults("k", 0.000001) +discretization_scheme = session.solution.methods.discretization_scheme +discretization_scheme["pressure"] = "second-order" +discretization_scheme["k"] = "second-order-upwind" +discretization_scheme["epsilon"] = "second-order-upwind" -session.tui.solve.monitors.residual.convergence_criteria( - 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001 -) +session.solution.initialization.defaults["k"] = 1e-6 + +for criterion in [ + "continuity", + "x-velocity", + "y-velocity", + "z-velocity", + "k", + "epsilon", +]: + session.solution.monitor.residual.equations[criterion].absolute_criteria = 0.0001 ####################################################################################### # Define Report Definitions # ===================================================================================== -session.tui.solve.report_definitions.add( - "cd-mon1", - "drag", - "thread-names", - "*ahmed*", - "()", - "scaled?", - "yes", - "force-vector", - "0 0 1", - "q", -) -session.tui.define.parameters.output_parameters.create("report-definition", "cd-mon1") -session.tui.solve.report_plots.add("cd-mon1", "report-defs", "cd-mon1", "()", "q") +session.solution.report_definitions.drag["cd-mon1"] = { + "zones": "*ahmed*", + "force_vector": [0, 0, -1], +} +session.parameters.output_parameters.report_definitions["cd-mon1-op"] = { + "report_definition": "cd-mon1", +} +session.solution.monitor.report_plots["cd-mon1"] = { + "report_defs": ["cd-mon1"], +} ####################################################################################### # Initialize and Run Solver # ===================================================================================== -session.tui.solve.set.number_of_iterations(5) -session.tui.solve.initialize.initialize_flow() -session.tui.solve.iterate() +session.solution.initialization.standard_initialize() +session.solution.run_calculation.iterate(iter_count=100) ####################################################################################### # Post-Processing Workflow # ===================================================================================== -session.tui.surface.iso_surface("x-coordinate", "xmid", "()", "()", 0, "()") +session.results.surfaces.iso_surface["xmid"] = { + "field": "x-coordinate", + "iso_values": [0.0], +} + graphics_session1 = pv.Graphics(session) + contour1 = graphics_session1.Contours["contour-1"] contour1.field = "velocity-magnitude" contour1.surfaces_list = ["xmid"] @@ -338,7 +353,7 @@ # ===================================================================================== save_case_data_as = Path(save_path) / "ahmed_body_final.cas.h5" -session.tui.file.write_case_data(save_case_data_as) +session.file.write_case_data(file_name=save_case_data_as) ####################################################################################### # Close the session diff --git a/examples/00-released_examples/01-brake.py b/examples/00-released_examples/01-brake.py index fcf0f03..87a7fd7 100644 --- a/examples/00-released_examples/01-brake.py +++ b/examples/00-released_examples/01-brake.py @@ -24,6 +24,7 @@ import ansys.fluent.core as pyfluent from ansys.fluent.core import examples +from ansys.fluent.visualization import set_config ############################################################################### # PyVista @@ -35,16 +36,30 @@ # -------------------- import matplotlib.pyplot as plt +########################################################################### +# Configure PyFluent Visualization +# ================================ +# Set the following options: +# +# * ``blocking=True``: Block the execution thread when a plot is displayed. +# This will allow you to inspect it before proceeding. To proceed, close the +# plot. +# * ``set_view_on_display="isometric"``: Set the default view in a plot to +# isometric. + +set_config(blocking=True, set_view_on_display="isometric") + ############################################################################### # Specifying save path # ==================== # save_path can be specified as Path("E:/", "pyfluent-examples-tests") or # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. + save_path = Path(pyfluent.EXAMPLES_PATH) import_filename = examples.download_file( - "brake.msh", + "brake.msh.h5", "pyfluent/examples/Brake-Thermal-PyVista-Matplotlib", save_path=save_path, ) @@ -58,62 +73,55 @@ # -------------------------------------- session = pyfluent.launch_fluent( - mode="solver", show_gui=False, version="3ddp", precision="double", processor_count=2 + mode="solver", + show_gui=False, + precision="double", + processor_count=4, ) -session.check_health() +session.health_check_service.status() #################################################################################### # Import mesh # ------------ -session.tui.file.read_case(import_filename) +session.file.read_case(file_name=import_filename) ############################ # Define models and material # -------------------------- -session.tui.define.models.energy("yes", "no", "no", "no", "yes") -session.tui.define.models.unsteady_2nd_order_bounded("Yes") -session.tui.define.materials.copy("solid", "steel") + +energy = session.setup.models.energy +energy.enabled = True +energy.viscous_dissipation = False +energy.pressure_work = False +energy.kinetic_energy = False +energy.inlet_diffusion = True + +session.setup.general.solver.time = "unsteady-2nd-order-bounded" + +session.setup.materials.database.copy_by_name(type="solid", name="steel") ######################################### # Solve only energy equation (conduction) # --------------------------------------- -session.tui.solve.set.equations("flow", "no", "kw", "no") + +equations = session.solution.controls.equations +equations["flow"] = False +equations["kw"] = False ############################################ # Define disc rotation # -------------------- # (15.79 rps corresponds to 100 km/h car speed # with 0.28 m of axis height from ground) -session.tui.define.boundary_conditions.set.solid( - "disc1", - "disc2", - "()", - "solid-motion?", - "yes", - "solid-omega", - "no", - -15.79, - "solid-x-origin", - "no", - -0.035, - "solid-y-origin", - "no", - -0.821, - "solid-z-origin", - "no", - 0.045, - "solid-ai", - "no", - 0, - "solid-aj", - "no", - 1, - "solid-ak", - "no", - 0, - "q", -) + +session.setup.cell_zone_conditions.solid["disc1"].solid_motion = { + "solid_motion": True, + "solid_omega": -15.79, + "solid_motion_axis_origin": [-0.035, -0.821, 0.045], + "solid_motion_axis_direction": [0, 1, 0], +} +session.setup.cell_zone_conditions.copy(from_="disc1", to="disc2") ################################################### # Apply frictional heating on pad-disc surfaces @@ -121,17 +129,16 @@ # Wall thickness 0f 2 mm has been assumed and 2e9 w/m3 is the heat generation which # has been calculated from kinetic energy change due to braking. -session.tui.define.boundary_conditions.set.wall( - "wall_pad-disc1", - "wall-pad-disc2", - "()", - "wall-thickness", - 0.002, - "q-dot", - "no", - 2e9, - "q", -) +boundary_conditions = session.setup.boundary_conditions +boundary_conditions.wall["wall_pad-disc1"].thermal = { + "wall_thickness": { + "value": 0.002, + }, + "q_dot": { + "value": 2e9, + }, +} +boundary_conditions.copy(from_="wall_pad-disc1", to="wall-pad-disc2") ############################################################ # Apply convection cooling on outer surfaces due to air flow @@ -139,25 +146,22 @@ # Outer surfaces are applied a constant htc of 100 W/(m2 K) # and 300 K free stream temperature -session.tui.define.boundary_conditions.set.wall( - "wall-disc*", - "wall-geom*", - "()", - "thermal-bc", - "yes", - "convection", - "convective-heat-transfer-coefficient", - "no", - 100, - "q", -) +wall_disc_thermal_bcs = boundary_conditions.wall["wall-disc*"].thermal +wall_disc_thermal_bcs.thermal_bc = "Convection" +wall_disc_thermal_bcs.h.value = 100 +wall_disc_thermal_bcs.tinf.value = 300 + +wall_geom_thermal_bcs = boundary_conditions.wall["wall-geom*"].thermal +wall_geom_thermal_bcs.thermal_bc = "Convection" +wall_geom_thermal_bcs.h.value = 100 +wall_geom_thermal_bcs.tinf.value = 300 ############################################### # Initialize # ---------- # Initialize with 300 K temperature -session.tui.solve.initialize.initialize_flow() +session.solution.initialization.standard_initialize() ############################################### # Post processing setup @@ -167,43 +171,27 @@ # * Set views and camera # * Set animation object -session.tui.solve.report_definitions.add( - "max-pad-temperature", - "volume-max", - "field", - "temperature", - "zone-names", - "geom-1-innerpad", - "geom-1-outerpad", -) -session.tui.solve.report_definitions.add( - "max-disc-temperature", - "volume-max", - "field", - "temperature", - "zone-names", - "disc1", - "disc2", -) +volume_reports = session.solution.report_definitions.volume +volume_reports["max-pad-temperature"] = { + "report_type": "volume-max", + "cell_zones": ["geom-1-innerpad", "geom-1-outerpad"], + "field": "temperature", +} +volume_reports["max-disc-temperature"] = { + "report_type": "volume-max", + "cell_zones": ["disc1", "disc2"], + "field": "temperature", +} -session.tui.solve.report_plots.add( - "max-temperature", - "report-defs", - "max-pad-temperature", - "max-disc-temperature", - "()", -) +session.solution.monitor.report_plots["max-temperature"] = { + "report_defs": ["max-pad-temperature", "max-disc-temperature"], +} report_file_path = Path(save_path) / "max-temperature.out" -session.tui.solve.report_files.add( - "max-temperature", - "report-defs", - "max-pad-temperature", - "max-disc-temperature", - "()", - "file-name", - str(report_file_path), -) +session.solution.monitor.report_files["max-temperature"] = { + "report_defs": ["max-pad-temperature", "max-disc-temperature", "flow-time"], + "file_name": str(report_file_path), +} session.results.graphics.contour["contour-1"] = { @@ -235,45 +223,32 @@ } -session.tui.display.objects.create( - "contour", - "temperature", - "field", - "temperature", - "surface-list", - "wall*", - "()", - "color-map", - "format", - "%0.1f", - "q", - "range-option", - "auto-range-off", - "minimum", - 300, - "maximum", - 400, - "q", - "q", -) +session.results.graphics.contour["temperature"] = { + "field": "temperature", + "surfaces_list": "wall*", + "color_map": { + "format": "%0.1f", + }, + "range_option": { + "option": "auto-range-off", + "auto_range_off": { + "minimum": 300.0, + "maximum": 400.0, + }, + }, +} +views = session.results.graphics.views +views.restore_view(view_name="top") +views.camera.zoom(factor=2) +views.save_view(view_name="animation-view") -session.tui.display.views.restore_view("top") -session.tui.display.views.camera.zoom_camera(2) -session.tui.display.views.save_view("animation-view") - -session.tui.solve.animate.objects.create( - "animate-temperature", - "animate-on", - "temperature", - "frequency-of", - "flow-time", - "flow-time-frequency", - 0.05, - "view", - "animation-view", - "q", -) +session.solution.calculation_activity.solution_animations["animate-temperature"] = { + "animate_on": "temperature", + "frequency_of": "flow-time", + "flow_time_frequency": 0.05, + "view": "animation-view", +} ############################################### # Run simulation @@ -282,15 +257,19 @@ # * Set time step size # * Set number of time steps and maximum number of iterations per time step -session.tui.solve.set.transient_controls.time_step_size(0.01) -session.tui.solve.dual_time_iterate(200, 5) +run_calculation = session.solution.run_calculation +run_calculation.transient_controls.time_step_size = 0.01 +run_calculation.dual_time_iterate( + time_step_count=200, + max_iter_per_step=5, +) ############################################### # Save simulation data # -------------------- # Write case and data files save_case_data_as = Path(save_path) / "brake-final.cas.h5" -session.tui.file.write_case_data(save_case_data_as) +session.file.write_case_data(file_name=save_case_data_as) ############################################### # Post processing with PyVista (3D visualization) @@ -306,12 +285,6 @@ # -------------------------- contour1 = graphics_session1.Contours["temperature"] -############################################### -# Check available options for contour object -# ------------------------------------------- - -contour1() - ############################################### # Set contour properties # ---------------------- @@ -328,7 +301,6 @@ "wall-geom-1-outerpad", ] contour1.range.option = "auto-range-off" -contour1() contour1.range.auto_range_off.minimum = 300 contour1.range.auto_range_off.maximum = 400 @@ -371,7 +343,6 @@ # Plot graph # ---------- - plt.title("Maximum Temperature", fontdict={"color": "darkred", "size": 20}) plt.plot(X, Z, label="Max. Pad Temperature", color="red") plt.plot(X, Y, label="Max. Disc Temperature", color="blue") diff --git a/examples/00-released_examples/02-DOE_ML.py b/examples/00-released_examples/02-DOE_ML.py index 0c2f10a..e8b0b89 100644 --- a/examples/00-released_examples/02-DOE_ML.py +++ b/examples/00-released_examples/02-DOE_ML.py @@ -29,6 +29,7 @@ # ================================= from pathlib import Path +import re import ansys.fluent.core as pyfluent from ansys.fluent.core import examples @@ -65,12 +66,11 @@ # ====================================== solver = pyfluent.launch_fluent( - product_version="23.1.0", mode="solver", show_gui=False, - version="3d", precision="double", processor_count=2, + cwd=save_path, ) solver.health_check_service.check_health() @@ -79,7 +79,7 @@ # Read case # ========= -solver.tui.file.read_case(import_filename) +solver.file.read_case(file_name=import_filename) ############################################################################### # Design of Experiments @@ -90,31 +90,31 @@ coldVelArr = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7]) hotVelArr = np.array([0.8, 1, 1.2, 1.4, 1.6, 1.8, 2.0]) -resArr = np.zeros((coldVelArr.shape[0], hotVelArr.shape[0])) +resIdx = np.zeros((coldVelArr.shape[0], hotVelArr.shape[0]), dtype=np.int64) +# Create outlet temperature data file and erase contents +open(save_path / "outlet_temp.txt", "w").close() + +resCount = 0 for idx1, coldVel in np.ndenumerate(coldVelArr): for idx2, hotVel in np.ndenumerate(hotVelArr): - solver.setup.boundary_conditions.velocity_inlet["cold-inlet"].vmag = { - "option": "value", - "value": coldVel, - } - - solver.setup.boundary_conditions.velocity_inlet["hot-inlet"].vmag = { - "option": "value", - "value": hotVel, - } - - solver.tui.solve.initialize.initialize_flow("yes") - solver.tui.solve.iterate(200) - - res_tui = solver.scheme_eval.exec( - ( - "(ti-menu-load-string " - '"/report/surface-integrals/mass-weighted-avg outlet () ' - 'temperature no")', - ) + inlets = solver.setup.boundary_conditions.velocity_inlet + inlets["cold-inlet"].momentum.velocity.value = coldVel + inlets["hot-inlet"].momentum.velocity.value = hotVel + + solver.solution.initialization.standard_initialize() + solver.solution.run_calculation.iterate(iter_count=200) + + # Write mass-weighted average outlet temperature to file + solver.results.report.surface_integrals.mass_weighted_avg( + surface_names=["outlet"], + report_of="temperature", + write_to_file=True, + file_name="outlet_temp.txt", + append_data=True, ) - resArr[idx1][idx2] = eval(res_tui.split(" ")[-1]) + resIdx[idx1][idx2] = resCount + resCount += 1 #################################################################### @@ -123,6 +123,18 @@ solver.exit() +#################################################################### +# Read in Outlet Temperatures +# =========================== + +# Extract numbers from file +with open(save_path / "outlet_temp.txt", "r") as f: + data = f.read() +dataNumbers = np.array(re.findall(r"\d+\.\d+", data), dtype=np.float64) + +# Put results into array by index +resArr = dataNumbers[resIdx] + #################################### # Plot Response Surface using Plotly # ================================== diff --git a/examples/00-released_examples/03-CHT.py b/examples/00-released_examples/03-CHT.py index ed0b18d..df66658 100644 --- a/examples/00-released_examples/03-CHT.py +++ b/examples/00-released_examples/03-CHT.py @@ -27,18 +27,27 @@ # ================================= import csv -import os from pathlib import Path import ansys.fluent.core as pyfluent from ansys.fluent.core import examples -import ansys.fluent.visualization as viz # noqa: F401 +from ansys.fluent.visualization import set_config from ansys.fluent.visualization.matplotlib import Plots # noqa: F401 -from ansys.fluent.visualization.matplotlib import matplot_windows_manager # noqa: F401 -from ansys.fluent.visualization.pyvista import Graphics, pyvista_windows_manager -from ansys.fluent.visualization.pyvista.pyvista_windows_manager import PyVistaWindow +from ansys.fluent.visualization.pyvista import Graphics import matplotlib.pyplot as plt -import pyvista as pv + +########################################################################### +# Configure PyFluent Visualization +# ================================ +# Set the following options: +# +# * ``blocking=True``: Block the execution thread when a plot is displayed. +# This will allow you to inspect it before proceeding. To proceed, close the +# plot. +# * ``set_view_on_display="isometric"``: Set the default view in a plot to +# isometric. + +set_config(blocking=True, set_view_on_display="isometric") ########################################################################### # Specifying save path @@ -64,12 +73,11 @@ # ======================================= meshing = pyfluent.launch_fluent( - product_version="23.2.0", mode="meshing", - version="3d", precision="double", show_gui=True, processor_count=4, + cwd=save_path, ) meshing.health_check_service.check_health() @@ -335,11 +343,12 @@ meshing.workflow.TaskObject["Run Custom Journal"].Rename(NewName=r"set-periodicity") meshing.workflow.TaskObject["set-periodicity"].Arguments.update_dict( { - r"JournalString": r"""/bo rps translational semi-auto periodic-1-high periodic-2-high periodic-3-high periodic-4-high , 0 0 -2.3 # noqa: E501 -/bo rps translational semi-auto periodic-5* , 0 0 -2.3 -/bo rps translational semi-auto periodic-6-high , 0 0 -2.3 -/bo rps translational semi-auto periodic-7-high , 0 0 -2.3 -""", + r"JournalString": r"""/bo rps translational semi-auto periodic-1-high """ + + r"""periodic-2-high periodic-3-high periodic-4-high , 0 0 -2.3 + /bo rps translational semi-auto periodic-5* , 0 0 -2.3 + /bo rps translational semi-auto periodic-6-high , 0 0 -2.3 + /bo rps translational semi-auto periodic-7-high , 0 0 -2.3 + """, } ) @@ -452,7 +461,7 @@ # Mesh Check; Review Fluent transcript for errors # =============================================== -solver.tui.mesh.check() +solver.mesh.check() ############################################################################# # Create a few boundary list for display and post-processing @@ -480,98 +489,88 @@ mesh1.show_edges = True mesh1.surfaces_list = wall_list mesh1.display("window-1") -p = pyvista_windows_manager.get_plotter("window-1") -p.view_isometric() -p.add_axes() -p.add_floor(offset=1, show_edges=False) -light = pv.Light(light_type="headlight") -p.add_light(light) + +#%% +# .. image:: ../../_static/cht_mesh.png +# :align: center +# :alt: Mesh + +#%% +# Mesh ############################################################################### # Temperature, Energy, Laminar Viscous Model # ========================================== -# * Set Temperature Unit # * Enable Energy Equation # * Enable Laminar Viscous Model -solver.tui.define.units("temperature", "C") solver.setup.models.energy.enabled = True -solver.setup.models.viscous.model.set_state("laminar") +solver.setup.models.viscous.model = "laminar" ############################################################################# # Change a few material properties of default Air # =============================================== -air_dict = solver.setup.materials.fluid["air"].get_state() -air_dict["density"]["value"] = 1.2 -air_dict["viscosity"]["value"] = 1.5e-5 -air_dict["thermal_conductivity"]["value"] = 0.026 -air_dict["specific_heat"]["value"] = 1006.0 -solver.setup.materials.fluid["air"].set_state(air_dict) +air_matl = solver.setup.materials.fluid["air"] +air_matl.density.value = 1.2 +air_matl.viscosity.value = 1.5e-5 +air_matl.thermal_conductivity.value = 0.026 +air_matl.specific_heat.value = 1006.0 ############################################################################# # Change a few material properties of default Aluminum # ==================================================== -al_dict = solver.setup.materials.solid["aluminum"].get_state() -al_dict["density"]["value"] = 2719.0 -al_dict["thermal_conductivity"]["value"] = 200.0 -al_dict["specific_heat"]["value"] = 871.0 -solver.setup.materials.solid["aluminum"].set_state(al_dict) +al_matl = solver.setup.materials.solid["aluminum"] +al_matl.density.value = 2719.0 +al_matl.thermal_conductivity.value = 200.0 +al_matl.specific_heat.value = 871.0 ############################################################################# # Copy Copper and change a few material properties of default Copper # ================================================================== -solver.tui.define.materials.copy("solid", "copper") -cu_dict = solver.setup.materials.solid["copper"].get_state() -cu_dict["density"]["value"] = 8978.0 -cu_dict["thermal_conductivity"]["value"] = 340.0 -cu_dict["specific_heat"]["value"] = 381.0 -solver.setup.materials.solid["copper"].set_state(cu_dict) +solver.setup.materials.database.copy_by_name( + type="solid", + name="copper", +) + +cu_matl = solver.setup.materials.solid["copper"] +cu_matl.density.value = 8978.0 +cu_matl.thermal_conductivity.value = 340.0 +cu_matl.specific_heat.value = 381.0 ############################################################################# # Set Tube Cell Zone Material as Copper # ===================================== -tube_dict = solver.setup.cell_zone_conditions.solid["solid-tube-1"].get_state() -tube_dict["material"] = "copper" -solver.setup.cell_zone_conditions.solid["solid-tube-1"].set_state(tube_dict) - -tube_dict = solver.setup.cell_zone_conditions.solid["solid-tube-2"].get_state() -tube_dict["material"] = "copper" -solver.setup.cell_zone_conditions.solid["solid-tube-2"].set_state(tube_dict) +solid_cellzone_conds = solver.setup.cell_zone_conditions.solid +solid_cellzone_conds["solid-tube-1"].material = "copper" +solid_cellzone_conds["solid-tube-2"].material = "copper" ############################################################################# # Set Boundary Condition for Inlet and Outlet # =========================================== -inlet_dict = solver.setup.boundary_conditions.velocity_inlet["inlet"].get_state() -inlet_dict["vmag"]["value"] = 4.0 -inlet_dict["t"]["value"] = 293.15 # Need to specify in Kelvin -solver.setup.boundary_conditions.velocity_inlet["inlet"].set_state(inlet_dict) +bc = solver.setup.boundary_conditions -outlet_dict = solver.setup.boundary_conditions.pressure_outlet["outlet"].get_state() -outlet_dict["t0"]["value"] = 293.15 -solver.setup.boundary_conditions.pressure_outlet["outlet"].set_state(outlet_dict) +bc.velocity_inlet["inlet"].momentum.velocity.value = 4.0 +bc.velocity_inlet["inlet"].thermal.t.value = 293.15 # Need to specify in Kelvin + +bc.pressure_outlet["outlet"].thermal.t0.value = 293.15 ############################################################################# # Set Thermal Boundary Condition for Wall Inner Tube # ================================================== -wall_dict = solver.setup.boundary_conditions.wall["wall-inner-tube-1"].get_state() -wall_dict["thermal_bc"] = "Convection" -solver.setup.boundary_conditions.wall["wall-inner-tube-1"].set_state( - wall_dict -) # This step is necessary as 'h' is not available in Adiabatic Dictionary - -wall_dict = solver.setup.boundary_conditions.wall["wall-inner-tube-1"].get_state() -wall_dict["h"]["value"] = 1050.0 -wall_dict["tinf"]["value"] = 353.15 -solver.setup.boundary_conditions.wall["wall-inner-tube-1"].set_state(wall_dict) +inner_tube_bc = solver.setup.boundary_conditions.wall["wall-inner-tube-1"] +inner_tube_bc.thermal.thermal_bc = "Convection" +inner_tube_bc.thermal.h.value = 1050.0 +inner_tube_bc.thermal.tinf.value = 353.15 -solver.tui.define.boundary_conditions.copy_bc( - "wall-inner-tube-1", "wall-inner-tube-2", "()" +solver.setup.boundary_conditions.copy( + from_="wall-inner-tube-1", + to="wall-inner-tube-2", ) ############################################################################# @@ -584,137 +583,120 @@ # Define Report Definitions # ========================= -solver.tui.solve.report_definitions.add( - "outlet-enthalpy-flow", - "surface-flowrate", - "field", - "enthalpy", - "surface-names", - "outlet", - "()", - "q", -) -solver.tui.solve.report_definitions.add( - "avg-pressure-inlet", - "surface-areaavg", - "field", - "pressure", - "surface-names", - "inlet", - "()", - "q", -) -solver.tui.solve.report_definitions.add( - "max-vel-louvers4", - "volume-max", - "field", - "velocity-magnitude", - "zone-names", - "fluid-tet-4", - "()", - "q", -) -solver.tui.solve.report_definitions.add( - "wall-shear-int", - "surface-integral", - "field", - "wall-shear", - "surface-names", - "wall-fluid-sweep-fin-solid-sweep-fin-shadow", - "wall-fluid-tet-1-solid-tet-1", - "wall-fluid-tet-2-solid-tet-2", - "wall-fluid-tet-3-solid-tet-3", - "wall-fluid-tet-4-solid-tet-4", - "()", - "q", -) +report_defs = solver.solution.report_definitions + +report_defs.surface["outlet-enthalpy-flow"] = { + "report_type": "surface-flowrate", + "field": "enthalpy", + "surface_names": ["outlet"], +} +report_defs.surface["avg-pressure-inlet"] = { + "report_type": "surface-areaavg", + "field": "pressure", + "surface_names": ["inlet"], +} +report_defs.volume["max-vel-louvers4"] = { + "report_type": "volume-max", + "field": "velocity-magnitude", + "cell_zones": ["fluid-tet-4"], +} +report_defs.surface["wall-shear-int"] = { + "report_type": "surface-integral", + "field": "wall-shear", + "surface_names": [ + "wall-fluid-sweep-fin-solid-sweep-fin-shadow", + "wall-fluid-tet-1-solid-tet-1", + "wall-fluid-tet-2-solid-tet-2", + "wall-fluid-tet-3-solid-tet-3", + "wall-fluid-tet-4-solid-tet-4", + ], +} + +############################################################################# +# Define Report Plots +# =================== -solver.tui.solve.report_plots.add( - "outlet-enthalpy-flow-plot", "report-defs", "outlet-enthalpy-flow", "()", "q" -) -solver.tui.solve.report_files.add( - "outlet-enthalpy-flow-file", - "report-defs", - "outlet-enthalpy-flow", - "()", - "file-name", - "outlet-enthalpy-flow.out", - "q", -) +report_plots = solver.solution.monitor.report_plots -solver.tui.solve.report_plots.add( - "avg-pressure-inlet-plot", "report-defs", "avg-pressure-inlet", "()", "q" -) -solver.tui.solve.report_files.add( - "avg-pressure-inlet-file", - "report-defs", - "avg-pressure-inlet", - "()", - "file-name", - "avg-pressure-inlet.out", - "q", -) +report_plots["outlet-enthalpy-flow-plot"] = { + "report_defs": ["outlet-enthalpy-flow"], +} +report_plots["avg-pressure-inlet-plot"] = { + "report_defs": ["avg-pressure-inlet"], +} +report_plots["max-vel-louvers4-plot"] = { + "report_defs": ["max-vel-louvers4"], +} +report_plots["wall-shear-int-plot"] = { + "report_defs": ["wall-shear-int"], +} -solver.tui.solve.report_plots.add( - "max-vel-louvers4-plot", "report-defs", "max-vel-louvers4", "()", "q" -) -solver.tui.solve.report_files.add( - "max-vel-louvers4-file", - "report-defs", - "max-vel-louvers4", - "()", - "file-name", - "max-vel-louvers4.out", - "q", -) +############################################################################# +# Define Report Files +# =================== -solver.tui.solve.report_plots.add( - "wall-shear-int-plot", "report-defs", "wall-shear-int", "()", "q" -) -solver.tui.solve.report_files.add( - "wall-shear-int-file", - "report-defs", - "wall-shear-int", - "()", - "file-name", - "wall-shear-int.out", - "q", -) +report_files = solver.solution.monitor.report_files + +report_files["outlet-enthalpy-flow-file"] = { + "report_defs": ["outlet-enthalpy-flow"], + "file_name": "outlet-enthalpy-flow.out", +} +report_files["avg-pressure-inlet-file"] = { + "report_defs": ["avg-pressure-inlet"], + "file_name": "avg-pressure-inlet.out", +} +report_files["max-vel-louvers4-file"] = { + "report_defs": ["max-vel-louvers4"], + "file_name": "max-vel-louvers4.out", +} +report_files["wall-shear-int-file"] = { + "report_defs": ["wall-shear-int"], + "file_name": "wall-shear-int.out", +} ############################################################################# # Hybrid Initialization; Slit Interior between Solid Zones; Save Case # =================================================================== -solver.tui.solve.initialize.hyb_initialization() -solver.tui.mesh.modify_zones.slit_interior_between_diff_solids() -save_case_as = str(Path(pyfluent.EXAMPLES_PATH) / "hx-fin-2mm.cas.h5") -solver.tui.file.write_case(save_case_as) -solver.tui.solve.initialize.hyb_initialization() +solver.solution.initialization.hybrid_initialize() +solver.setup.boundary_conditions.slit_interior_between_diff_solids() +save_case_as = Path(pyfluent.EXAMPLES_PATH) / "hx-fin-2mm.cas.h5" +solver.file.write_case(file_name=save_case_as) ############################################################################# # Set Aggressive Length Scale Method; Run Calculation & Save Data # =============================================================== -solver.tui.solve.set.pseudo_time_method.global_time_step_settings( - "yes", "0", "1", "yes", "1" -) -solver.tui.solve.iterate("250") -save_case_data_as = str(Path(pyfluent.EXAMPLES_PATH) / "hx-fin-2mm.dat.h5") -solver.tui.file.write_case_data(save_case_data_as) +time_step_method = solver.solution.run_calculation.pseudo_time_settings.time_step_method + +time_step_method.time_step_method = "automatic" +time_step_method.length_scale_methods = "aggressive" + +solver.solution.run_calculation.iterate(iter_count=250) +solver.file.write_case_data(file_name=save_case_as) ############################################################################# # Post-Processing Mass Balance Report # =================================== -inlet_mfr = solver.scheme_eval.exec( - ('(ti-menu-load-string "/report/fluxes/mass-flow no inlet () no")',) -).split(" ")[-1] -outlet_mfr = solver.scheme_eval.exec( - ('(ti-menu-load-string "/report/fluxes/mass-flow no outlet () no")',) -).split(" ")[-1] -net_mfr = solver.scheme_eval.exec( - ('(ti-menu-load-string "/report/fluxes/mass-flow no inlet outlet () no")',) -).split(" ")[-1] +fluxes = solver.results.report.fluxes + +inlet_mfr = fluxes.mass_flow( + all_boundary_zones=False, + zones=["inlet"], + write_to_file=False, +) +outlet_mfr = fluxes.mass_flow( + all_boundary_zones=False, + zones=["outlet"], + write_to_file=False, +) +net_mfr = fluxes.mass_flow( + all_boundary_zones=False, + zones=["inlet", "outlet"], + write_to_file=False, +) + print("Mass Balance Report\n") print("Inlet (kg/s): ", inlet_mfr) print("Outlet (kg/s): ", outlet_mfr) @@ -724,9 +706,11 @@ # Heat Balance Report # =================== -htr = solver.scheme_eval.exec( - ('(ti-menu-load-string "/report/fluxes/heat-transfer yes no")',) -).split(" ")[-1] +htr = fluxes.heat_transfer( + all_boundary_zones=True, + write_to_file=False, +) + print("Heat Balance Report\n") print("Net Imbalance (Watt): ", htr) @@ -737,13 +721,15 @@ fig, axs = plt.subplots(2, 2, figsize=(10, 8)) fig.suptitle("Monitor Plots") -outFilesList = [] -fileList = os.listdir(os.getcwd()) -for tempFile in fileList: - fName, ext = os.path.splitext(tempFile) - if ext == ".out": - outFilesList.append(tempFile) -outFilesList.sort() +rFilesList = [ + "avg-pressure-inlet.out", + "max-vel-louvers4.out", + "outlet-enthalpy-flow.out", + "wall-shear-int.out", +] + +# Append current working directory to each filename +outFilesList = [save_path / fName for fName in rFilesList] index = 0 for ax in axs.flat: @@ -790,39 +776,26 @@ contour1.surfaces_list = wall_list contour1.display("window-2") -p = pyvista_windows_manager.get_plotter("window-2") -p.view_isometric() -p.add_axes() -p.add_floor(offset=1, show_edges=False) -p.add_title( - "Contour of Temperature on Walls", font="courier", color="grey", font_size=10 -) -light = pv.Light(light_type="headlight") -p.add_light(light) - -p.remove_scalar_bar() -p.add_scalar_bar( - "Temperature [K]", - interactive=True, - vertical=False, - title_font_size=20, - label_font_size=15, - outline=False, - position_x=0.5, - fmt="%10.1f", -) +#%% +# .. image:: ../../_static/cht_temp_contour.png +# :align: center +# :alt: Temperature Contour + +#%% +# Temperature Contour ############################################################################# # Create Iso-Surface of X=0.012826 m # ================================== -solver.tui.surface.iso_surface( - "x-coordinate", "x=0.012826", "()", "()", "0.012826", "()" -) +solver.results.surfaces.iso_surface["x=0.012826"] = { + "field": "x-coordinate", + "iso_values": [0.012826], +} ############################################################################# -# Vecotor Plot -# ============ +# Vector Plot +# =========== graphics_session1 = Graphics(solver) vector1 = graphics_session1.Vectors["vector-1"] @@ -831,29 +804,13 @@ vector1.skip = 5 vector1.display("window-3") -p = pyvista_windows_manager.get_plotter("window-3") -p.view_isometric() -p.add_axes() -# p.add_floor( offset=1, show_edges=False) -p.add_title("Vector Plot", font="courier", color="grey", font_size=10) -light = pv.Light(light_type="headlight") -p.add_light(light) - -p.remove_scalar_bar() -p.add_scalar_bar( - "Velocity [m/s]", - interactive=True, - vertical=False, - title_font_size=20, - label_font_size=15, - outline=False, - position_x=0.5, - fmt="%10.1f", -) +#%% +# .. image:: ../../_static/cht_vector.png +# :align: center +# :alt: Vector Plot -o = PyVistaWindow(None, None) -o._fetch_mesh(mesh1) -o._display_mesh(mesh1, p) +#%% +# Vector Plot ############################################################################# # XY Plot of Pressure diff --git a/examples/00-released_examples/04-TylerSofrinModes.py b/examples/00-released_examples/04-TylerSofrinModes.py index 2f4b759..6c57ba6 100644 --- a/examples/00-released_examples/04-TylerSofrinModes.py +++ b/examples/00-released_examples/04-TylerSofrinModes.py @@ -84,7 +84,6 @@ ####################################################################################### # Import required libraries/modules # ===================================================================================== -import math from pathlib import Path import random @@ -110,7 +109,7 @@ import_filename = examples.download_file( "axial_comp_fullWheel_DFT_23R2.cas.h5", "pyfluent/examples/Tyler-Sofrin-Modes-Compressor", -) # noqa: E501 +) examples.download_file( "axial_comp_fullWheel_DFT_23R2.dat.h5", @@ -122,7 +121,8 @@ # Launch Fluent session # ===================================================================================== session = pyfluent.launch_fluent( - show_gui=True, processor_count=4, product_version="23.2.0" + show_gui=True, + processor_count=4, ) ####################################################################################### @@ -132,7 +132,7 @@ # .. note:: # The dat file should correspond to the already completed DFT simulation. -session.tui.file.read_case_data(import_filename) +session.file.read_case_data(file_name=import_filename) ####################################################################################### # Define User constant/variables @@ -164,9 +164,11 @@ # Create monitor points # ===================================================================================== for angle in range(0, 360, d_theta): - x = math.cos(math.radians(angle)) * r - y = math.sin(math.radians(angle)) * r - session.tui.surface.point_surface("point-" + str(angle), x, y, z) + x = np.cos(np.deg2rad(angle)) * r + y = np.sin(np.deg2rad(angle)) * r + session.results.surfaces.point_surface["point-" + str(angle)] = { + "point": [x, y, z], + } ####################################################################################### # Compute Fourier coefficients at each monitor point (An, Bn) @@ -177,38 +179,34 @@ for angle_ind, angle in enumerate(range(0, 360, d_theta)): for n_ind, variable in enumerate(varname): if len(variable) >= 4 and variable[:4] == "mean": - session.solution.report_definitions.surface["mag-report"] = { + report_defs = session.solution.report_definitions + + report_defs.surface["mag-report"] = { "report_type": "surface-vertexavg", "surface_names": ["point-" + str(angle)], "field": str(variable), } - mag = session.solution.report_definitions.compute( - report_defs=["mag-report"] - ) + mag = report_defs.compute(report_defs=["mag-report"]) mag = mag[0]["mag-report"][0] An[n_ind][angle_ind] = mag Bn[n_ind][angle_ind] = 0 else: - session.solution.report_definitions.surface["mag-report"] = { + report_defs.surface["mag-report"] = { "report_type": "surface-vertexavg", "surface_names": ["point-" + str(angle)], "field": str(variable) + "-mag", } - mag = session.solution.report_definitions.compute( - report_defs=["mag-report"] - ) + mag = report_defs.compute(report_defs=["mag-report"]) mag = mag[0]["mag-report"][0] - session.solution.report_definitions.surface["phase-report"] = { + report_defs.surface["phase-report"] = { "report_type": "surface-vertexavg", "surface_names": ["point-" + str(angle)], "field": str(variable) + "-phase", } - phase = session.solution.report_definitions.compute( - report_defs=["phase-report"] - ) + phase = report_defs.compute(report_defs=["phase-report"]) phase = phase[0]["phase-report"][0] - An[n_ind][angle_ind] = mag * math.cos(phase) - Bn[n_ind][angle_ind] = -mag * math.sin(phase) + An[n_ind][angle_ind] = mag * np.cos(phase) + Bn[n_ind][angle_ind] = -mag * np.sin(phase) ####################################################################################### @@ -219,7 +217,7 @@ # This step is only required if data is to be processed with other standalone # tools. Update the path to the file accordingly. -fourier_coefficients_file = Path(save_path, "FourierCoefficients.txt") +fourier_coefficients_file = save_path / "FourierCoefficients.txt" with open(fourier_coefficients_file, "w") as f: f.write("n theta An Bn \n") @@ -256,17 +254,17 @@ for n_ind, variable in enumerate(varname): # loop over n modes for m_ind, m in enumerate(m_mode): # loop over m modes for angle_ind, angle in enumerate( - np.arange(0, math.radians(360), math.radians(d_theta)) + np.arange(0, np.deg2rad(360), np.deg2rad(d_theta)) ): # loop over all angles, in radians - Anm[n_ind][m_ind] += An[n_ind][angle_ind] * math.cos(m * angle) - Bn[n_ind][ + Anm[n_ind][m_ind] += An[n_ind][angle_ind] * np.cos(m * angle) - Bn[n_ind][ angle_ind - ] * math.sin(m * angle) - Bnm[n_ind][m_ind] += An[n_ind][angle_ind] * math.sin(m * angle) + Bn[n_ind][ + ] * np.sin(m * angle) + Bnm[n_ind][m_ind] += An[n_ind][angle_ind] * np.sin(m * angle) + Bn[n_ind][ angle_ind - ] * math.cos(m * angle) - Anm[n_ind][m_ind] = Anm[n_ind][m_ind] / (2 * math.pi) * math.radians(d_theta) - Bnm[n_ind][m_ind] = Bnm[n_ind][m_ind] / (2 * math.pi) * math.radians(d_theta) - Pnm[n_ind][m_ind] = math.sqrt(Anm[n_ind][m_ind] ** 2 + Bnm[n_ind][m_ind] ** 2) + ] * np.cos(m * angle) + Anm[n_ind][m_ind] = Anm[n_ind][m_ind] / (2 * np.pi) * np.deg2rad(d_theta) + Bnm[n_ind][m_ind] = Bnm[n_ind][m_ind] / (2 * np.pi) * np.deg2rad(d_theta) + Pnm[n_ind][m_ind] = np.sqrt(Anm[n_ind][m_ind] ** 2 + Bnm[n_ind][m_ind] ** 2) # P_00 is generally orders of magnitude larger than that of other modes. # Giving focus to other modes by setting P_00 equal to zero diff --git a/examples/00-released_examples/06-lunar_lander_thermal.py b/examples/00-released_examples/06-lunar_lander_thermal.py index 21c39cd..ad4e8ee 100644 --- a/examples/00-released_examples/06-lunar_lander_thermal.py +++ b/examples/00-released_examples/06-lunar_lander_thermal.py @@ -73,7 +73,7 @@ ) for f in [ "lander_geom.scdoc", - "lander_mesh.msh", + "lander_mesh.msh.h5", "apollo17_temp_data.csv", ] ]