.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-released_examples/05-radiation_headlamp.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_00-released_examples_05-radiation_headlamp.py: .. _ref_radiation_headlamp: Modeling Radiation in a Headlamp Using the Monte Carlo Method ------------------------------------------------------------- This example solves for the radiative and conductive heat transfer within a car headlamp exposed to the sun's rays to determine the severity of any hotspots that form. It uses a Monte Carlo radiation model and the pressure-based solver. This is based on the Fluent tutorial titled "Using the Monte Carlo Radiation Model". **Workflow tasks** The Modeling Radiation Using the Monte Carlo Method example guides you through these tasks: - Creation of a mesh using the Watertight Geometry workflow. - Setting up a Monte Carlo radiation model. - Creation of materials with thermal and radiation properties. - Setting boundary conditions for heat transfer and radiation calculations. - Calculating a solution using the pressure-based solver. **Problem description** The problem considers the headlamp of a parked car exposed to sunlight. The lens focuses incoming radiation onto the internal components of the headlamp, producing thermal hotspots that could cause damage due to thermal stresses or material degradation. .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: default # sphinx_gallery_thumbnail_path = '_static/radiation_headlamp_thumbnail.png' .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. image:: ../../_static/radiation_headlamp_geom.png :width: 500pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 39-48 Example Setup ------------- Before you can use the watertight geometry meshing workflow, you must set up the example and initialize this workflow. Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports, which includes downloading and importing the geometry files. .. GENERATED FROM PYTHON SOURCE LINES 48-59 .. code-block:: default import ansys.fluent.core as pyfluent from ansys.fluent.core import examples headlamp_spaceclaim_file, headlamp_pmdb_file = [ examples.download_file( f, "pyfluent/radiation_headlamp", save_path=pyfluent.EXAMPLES_PATH ) for f in ["headlamp.scdoc", "headlamp.pmdb"] ] .. GENERATED FROM PYTHON SOURCE LINES 60-64 Launch Fluent ~~~~~~~~~~~~~ Launch Fluent as a service in meshing mode with single precision running on four processors. .. GENERATED FROM PYTHON SOURCE LINES 64-72 .. code-block:: default meshing = pyfluent.launch_fluent( precision="single", processor_count=4, mode="meshing", cwd=pyfluent.EXAMPLES_PATH, ) .. GENERATED FROM PYTHON SOURCE LINES 73-76 Initialize workflow ~~~~~~~~~~~~~~~~~~~ Initialize the watertight geometry meshing workflow. .. GENERATED FROM PYTHON SOURCE LINES 76-79 .. code-block:: default meshing.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry") .. GENERATED FROM PYTHON SOURCE LINES 80-88 Watertight geometry meshing workflow ------------------------------------ The fault-tolerant meshing workflow guides you through the several tasks that follow. Import CAD and set length units ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Import the CAD geometry and set the length units to millimeters. .. GENERATED FROM PYTHON SOURCE LINES 88-99 .. code-block:: default geo_import = meshing.workflow.TaskObject["Import Geometry"] geo_import.Arguments.set_state( { "FileName": headlamp_pmdb_file, "LengthUnit": "mm", } ) geo_import.Execute() .. GENERATED FROM PYTHON SOURCE LINES 100-103 Add local sizing ~~~~~~~~~~~~~~~~ Add local sizing controls to the geometry. .. GENERATED FROM PYTHON SOURCE LINES 103-129 .. code-block:: default local_sizing = meshing.workflow.TaskObject["Add Local Sizing"] local_sizing.Arguments.set_state( { "AddChild": "yes", "BOIControlName": "boi_lens", "BOIExecution": "Body Of Influence", "BOIFaceLabelList": ["boi"], "BOISize": 2, } ) local_sizing.AddChildAndUpdate() local_sizing.Arguments.set_state( { "AddChild": "yes", "BOIControlName": "bodysize_lens", "BOIExecution": "Body Size", "BOIFaceLabelList": ["lens"], "BOISize": 2, } ) local_sizing.AddChildAndUpdate() .. GENERATED FROM PYTHON SOURCE LINES 130-133 Generate surface mesh ~~~~~~~~~~~~~~~~~~~~~ Generate the surface mesh. .. GENERATED FROM PYTHON SOURCE LINES 133-146 .. code-block:: default surface_mesh_gen = meshing.workflow.TaskObject["Generate the Surface Mesh"] surface_mesh_gen.Arguments.set_state( { "CFDSurfaceMeshControls": { "MinSize": 1, "MaxSize": 40, } } ) surface_mesh_gen.Execute() .. GENERATED FROM PYTHON SOURCE LINES 147-150 Improve surface mesh ~~~~~~~~~~~~~~~~~~~~ Improve the surface mesh. .. GENERATED FROM PYTHON SOURCE LINES 150-155 .. code-block:: default surface_mesh_gen.InsertNextTask(CommandName="ImproveSurfaceMesh") meshing.workflow.TaskObject["Improve Surface Mesh"].Execute() .. GENERATED FROM PYTHON SOURCE LINES 156-159 Describe geometry ~~~~~~~~~~~~~~~~~ Describe geometry and define the fluid region. .. GENERATED FROM PYTHON SOURCE LINES 159-174 .. code-block:: default describe_geo = meshing.workflow.TaskObject["Describe Geometry"] describe_geo.Arguments.set_state( { "SetupType": "The geometry consists of both fluid and solid regions \ and/or voids", "CappingRequired": "No", "WallToInternal": "No", "InvokeShareTopology": "No", "Multizone": "No", } ) describe_geo.Execute() .. GENERATED FROM PYTHON SOURCE LINES 175-178 Update boundaries ~~~~~~~~~~~~~~~~~ Update the boundaries. .. GENERATED FROM PYTHON SOURCE LINES 178-189 .. code-block:: default update_bc = meshing.workflow.TaskObject["Update Boundaries"] update_bc.Arguments.set_state( { "BoundaryLabelList": ["rad-input"], "BoundaryLabelTypeList": ["wall"], } ) update_bc.Execute() .. GENERATED FROM PYTHON SOURCE LINES 190-193 Create fluid region ~~~~~~~~~~~~~~~~~~~ Create the fluid region. .. GENERATED FROM PYTHON SOURCE LINES 193-199 .. code-block:: default create_regions = meshing.workflow.TaskObject["Create Regions"] create_regions.Arguments.set_state({"NumberOfFlowVolumes": 1}) create_regions.Execute() .. GENERATED FROM PYTHON SOURCE LINES 200-203 Update regions ~~~~~~~~~~~~~~ Update the regions. .. GENERATED FROM PYTHON SOURCE LINES 203-206 .. code-block:: default meshing.workflow.TaskObject["Update Regions"].Execute() .. GENERATED FROM PYTHON SOURCE LINES 207-210 Boundary layers ~~~~~~~~~~~~~~~~~~~ Do not add boundary layers and proceed to the next task. .. GENERATED FROM PYTHON SOURCE LINES 210-216 .. code-block:: default add_boundary_layers = meshing.workflow.TaskObject["Add Boundary Layers"] add_boundary_layers.Arguments.set_state({"AddChild": "no"}) add_boundary_layers.Execute() .. GENERATED FROM PYTHON SOURCE LINES 217-221 Generate volume mesh ~~~~~~~~~~~~~~~~~~~~ Generate the volume mesh, which consists of setting properties for the volume mesh. .. GENERATED FROM PYTHON SOURCE LINES 221-232 .. code-block:: default volume_mesh_gen = meshing.workflow.TaskObject["Generate the Volume Mesh"] volume_mesh_gen.Arguments.set_state( { "VolumeMeshPreferences": { "PolyFeatureAngle": 40, }, }, ) volume_mesh_gen.Execute() .. GENERATED FROM PYTHON SOURCE LINES 233-236 Check mesh in meshing mode ~~~~~~~~~~~~~~~~~~~~~~~~~~ Check the mesh in meshing mode. .. GENERATED FROM PYTHON SOURCE LINES 236-239 .. code-block:: default meshing.tui.mesh.check_mesh() .. GENERATED FROM PYTHON SOURCE LINES 240-243 Save mesh file ~~~~~~~~~~~~~~ Save the mesh file (``headlamp.msh.h5``). .. GENERATED FROM PYTHON SOURCE LINES 243-246 .. code-block:: default meshing.tui.file.write_mesh("headlamp.msh.h5") .. GENERATED FROM PYTHON SOURCE LINES 247-257 Solve and postprocess --------------------- Once you have completed the watertight geometry meshing workflow, you can solve and postprocess the results. Switch to solution mode ~~~~~~~~~~~~~~~~~~~~~~~ Switch to solution mode. Now that a high-quality mesh has been generated using Fluent in meshing mode, you can switch to solver mode to complete the setup of the simulation. .. GENERATED FROM PYTHON SOURCE LINES 257-260 .. code-block:: default solver = meshing.switch_to_solver() .. GENERATED FROM PYTHON SOURCE LINES 261-264 Enable energy and viscosity models ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Set up the energy and viscosity models. .. GENERATED FROM PYTHON SOURCE LINES 264-269 .. code-block:: default models = solver.setup.models models.energy.enabled = True models.viscous.model = "laminar" .. GENERATED FROM PYTHON SOURCE LINES 270-275 Set up radiation model ~~~~~~~~~~~~~~~~~~~~~~ Set up the Monte Carlo radiation model. The number of histories is set to 10 million in order to reduce computation time, but this may need to be increased to obtain accurate results. .. GENERATED FROM PYTHON SOURCE LINES 275-281 .. code-block:: default radiation = models.radiation radiation.model = "monte-carlo" radiation.monte_carlo.number_of_histories = 1e7 radiation.solve_frequency.iteration_interval = 20 .. GENERATED FROM PYTHON SOURCE LINES 282-288 Define materials ~~~~~~~~~~~~~~~~ Create materials to represent the glass and plastic parts of the headlamp. To demonstrate two different methods of creating materials through the settings API, we will create glass using a dictionary and plastic using dot syntax. .. GENERATED FROM PYTHON SOURCE LINES 288-336 .. code-block:: default # --- Properties of glass --- # Density: 2650 [kg/m^3] # Specific heat capacity: 1887 [J/(kg K)] # Thermal conductivity: 7.6 [W/(m K)] # Absorption coefficient: 5.302 # Refractive index: 1.4714 glass = solver.setup.materials.solid.create("glass") glass.set_state( { "chemical_formula": "", "density": { "option": "constant", "value": 2650, }, "specific_heat": { "option": "constant", "value": 1887, }, "thermal_conductivity": { "option": "constant", "value": 7.6, }, "absorption_coefficient": { "option": "constant", "value": 5.302, }, "refractive_index": { "option": "constant", "value": 1.4714, }, } ) # --- Properties of plastic --- # Density: 1545.3 [kg/m^3] # Specific heat capacity: 2302 [J/(kg K)] # Thermal conductivity: 0.316 [W/(m K)] plastic = solver.setup.materials.solid.create("plastic") plastic.chemical_formula = "" plastic.density.value = 1545.3 plastic.specific_heat.value = 2302 plastic.thermal_conductivity.value = 0.316 plastic.absorption_coefficient.value = 0 plastic.refractive_index.value = 1 .. GENERATED FROM PYTHON SOURCE LINES 337-340 Cell Zone Conditions ~~~~~~~~~~~~~~~~~~~~ Set the cell zone conditions for the bezel and the lens. .. GENERATED FROM PYTHON SOURCE LINES 340-358 .. code-block:: default solver.setup.cell_zone_conditions.solid["bezel"].material = "plastic" solver.setup.cell_zone_conditions.copy( from_="bezel", to=[ "holder", "housing", "inner-bezel", "reflector", "rim-bezel", "seating-steel-rim", ], ) lens_cellzone_conds = solver.setup.cell_zone_conditions.solid["lens"] lens_cellzone_conds.material = "glass" lens_cellzone_conds.radiating = True .. GENERATED FROM PYTHON SOURCE LINES 359-362 Boundary Conditions ~~~~~~~~~~~~~~~~~~~ Set the boundary conditions. .. GENERATED FROM PYTHON SOURCE LINES 362-451 .. code-block:: default # --- Set up bezel-enclosure BC --- # Material: plastic # BC type: opaque # Internal emissivity: 1 # Diffuse fraction: 1 bezel_enc_bc = solver.setup.boundary_conditions.wall["bezel-enclosure"] bezel_enc_bc.material = "plastic" bezel_enc_bc.radiation_bc = "Opaque" bezel_enc_bc.in_emiss = 1 bezel_enc_bc.band_diffuse_frac = {"s-": 1} # Get list of wall zones bc_state = solver.setup.boundary_conditions.get_state() # Copy bezel-enclosure BC to all other BCs solver.setup.boundary_conditions.copy( from_="bezel-enclosure", to=bc_state["wall"].keys(), ) # --- Set up enclosure-lens BC --- # Material: glass # BC type: semi-transparent # Diffuse fraction: 0 enc_lens_bc = solver.setup.boundary_conditions.wall["enclosure-lens"] enc_lens_bc.material = "glass" enc_lens_bc.radiation_bc = "Semi Transparent" enc_lens_bc.band_diffuse_frac = {"s-": 0} # Copy enclosure-lens BC to other lens boundary solver.setup.boundary_conditions.copy( from_="enclosure-lens", to=["enclosure-lens-shadow"], ) # --- Set up enclosure-rim-bezel BC --- # Material: plastic # BC type: opaque # Internal emissivity: 0.16 # Diffuse fraction: 0.1 enc_rim_bezel_bc = solver.setup.boundary_conditions.wall["enclosure-rim-bezel"] enc_rim_bezel_bc.material = "plastic" enc_rim_bezel_bc.radiation_bc = "Opaque" enc_rim_bezel_bc.in_emiss = 0.16 enc_rim_bezel_bc.band_diffuse_frac = {"s-": 0.1} # Copy enclosure-rim-bezel BC to other rim bezel boundaries solver.setup.boundary_conditions.copy( from_="enclosure-rim-bezel", to=[ "enclosure-rim-bezel-shadow", "holder-rim-bezel", "holder-rim-bezel-shadow", "housing-rim-bezel", "housing-rim-bezel-shadow", ], ) # --- Set up enclosure:1 (domain boundaries) BC --- # BC type: temperature # Temperature: 298.15 [K] enc1_bc = solver.setup.boundary_conditions.wall["enclosure:1"] enc1_bc.thermal_bc = "Temperature" enc1_bc.t = 298.15 # --- Set up radiation input BC --- # BC type: temperature # Temperature: 298.15 [K] # Boundary source: yes # Direct irradiation: 1200 [W/m^2] # Radiation direction: (-0.848, 0, -0.53) rad_inp_bc = solver.setup.boundary_conditions.wall["rad-input"] rad_inp_bc.thermal_bc = "Temperature" rad_inp_bc.t = 298.15 rad_inp_bc.mc_bsource_p = True rad_inp_bc.band_q_irrad = { "s-": { "option": "value", "value": 1200, } } rad_inp_bc.radiation_direction = [-0.848, 0, -0.53] .. GENERATED FROM PYTHON SOURCE LINES 452-455 Set convergence criteria ~~~~~~~~~~~~~~~~~~~~~~~~ Enable residual plots and set the convergence criteria to 'none'. .. GENERATED FROM PYTHON SOURCE LINES 455-459 .. code-block:: default solver.tui.solve.monitors.residual.plot("yes") solver.tui.solve.monitors.residual.criterion_type("3") .. GENERATED FROM PYTHON SOURCE LINES 460-464 Define surface reports ~~~~~~~~~~~~~~~~~~~~~~ Define a surface report to find the maximum temperature of the inner bezel, then print the state of the report object. .. GENERATED FROM PYTHON SOURCE LINES 464-473 .. code-block:: default solver.solution.report_definitions.surface["max-temp"] = {} max_temp_surf_report = solver.solution.report_definitions.surface["max-temp"] max_temp_surf_report.surface_names = ["enclosure-inner-bezel"] max_temp_surf_report.report_type = "surface-facetmax" max_temp_surf_report.field = "temperature" max_temp_surf_report.print_state() .. GENERATED FROM PYTHON SOURCE LINES 474-477 Define report plots ~~~~~~~~~~~~~~~~~~~ Define a plot of the maximum temperature. .. GENERATED FROM PYTHON SOURCE LINES 477-483 .. code-block:: default solver.solution.monitor.report_plots["max-temp-rplot"] = {} max_temp_rplot = solver.solution.monitor.report_plots["max-temp-rplot"] max_temp_rplot.report_defs = "max-temp" max_temp_rplot.print = True .. GENERATED FROM PYTHON SOURCE LINES 484-487 Save case file ~~~~~~~~~~~~~~ Save the case file (``headlamp.cas.h5``). .. GENERATED FROM PYTHON SOURCE LINES 487-490 .. code-block:: default solver.file.write(file_name="headlamp.cas.h5", file_type="case") .. GENERATED FROM PYTHON SOURCE LINES 491-494 Initialize flow field ~~~~~~~~~~~~~~~~~~~~~ Initialize the solution. .. GENERATED FROM PYTHON SOURCE LINES 494-497 .. code-block:: default solver.solution.initialization.initialize() .. GENERATED FROM PYTHON SOURCE LINES 498-502 Solve for 19 iterations ~~~~~~~~~~~~~~~~~~~~~~~ Solve for 19 iterations. 99 iterations is recommended by the tutorial, but is reduced to 19 for this example for demonstration purposes. .. GENERATED FROM PYTHON SOURCE LINES 502-505 .. code-block:: default solver.solution.run_calculation.iterate(iter_count=19) .. GENERATED FROM PYTHON SOURCE LINES 506-510 Write final case file and data ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enable overwrite so that the original case file will be overwritten. Write the final case file and the data. .. GENERATED FROM PYTHON SOURCE LINES 510-514 .. code-block:: default solver.file.confirm_overwrite = True solver.file.write(file_name="headlamp.cas.h5", file_type="case-data") .. GENERATED FROM PYTHON SOURCE LINES 515-518 Close Fluent ~~~~~~~~~~~~ Close Fluent. .. GENERATED FROM PYTHON SOURCE LINES 518-521 .. code-block:: default solver.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.000 seconds) .. _sphx_glr_download_examples_00-released_examples_05-radiation_headlamp.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 05-radiation_headlamp.py <05-radiation_headlamp.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 05-radiation_headlamp.ipynb <05-radiation_headlamp.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_