.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples\internal_heat_source.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_auto_examples_internal_heat_source.py: Internal heat source example ============================= This example creates and simulates a plate with a heat source in the middle and different boundary conditions on each side. .. GENERATED FROM PYTHON SOURCE LINES 13-31 .. code-block:: Python # sphinx_gallery_tags = ["network", "solving", "build", "stationary", "geometric"] # sphinx_gallery_thumbnail_path = "_static/examples/internal_heat_source.svg" import os import numpy as np from pyrc import ( Node, InternalHeatSource, SolidBoundaryConditionCell, Viewer, connect_cells_with_resistors, RCNetwork, LinePlot, ) from pyrc.core.materials import Copper .. GENERATED FROM PYTHON SOURCE LINES 32-34 Create the plate as grid of cells ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 34-46 .. code-block:: Python grid_resolution = 15 plate_thickness = 0.003 material = Copper() grid = Node.create_grid( grid_size=(grid_resolution, grid_resolution, 1), delta=(1, 1, plate_thickness), material=material, temperature=20, ) capacitors: list[Node] = grid.flatten().tolist() .. GENERATED FROM PYTHON SOURCE LINES 47-49 Add heat source in a circle at the center ----------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 49-65 .. code-block:: Python radius = 2.5 center_x, center_y = (grid.shape[0] - 1) / 2, (grid.shape[1] - 1) / 2 x, y = np.ogrid[: grid.shape[0], : grid.shape[1]] mask = (x - center_x) ** 2 + (y - center_y) ** 2 <= radius**2 cells_in_circle = grid[mask, 0] for cell in cells_in_circle: cell.add_internal_heat_source( InternalHeatSource( node=cell, specific_power_in_w_per_meter_squared=1000, area_direction=np.array((0, 0, 1)), ) ) .. GENERATED FROM PYTHON SOURCE LINES 66-68 Create boundary conditions and place them adjacent to cell grid ---------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 68-80 .. code-block:: Python bc_x_negative = SolidBoundaryConditionCell(temperature=-10, position=(0, 0, 0), delta=(0.1, 1, plate_thickness)) capacitors[0].place_adjacent(bc_x_negative, "-x") bc_x_positive = SolidBoundaryConditionCell(temperature=-5, position=(0, 0, 0), delta=(0.1, 1, plate_thickness)) capacitors[-1].place_adjacent(bc_x_positive, "x") bc_y_negative = SolidBoundaryConditionCell(temperature=-2, position=(0, 0, 0), delta=(1, 0.1, plate_thickness)) capacitors[0].place_adjacent(bc_y_negative, "-y") bc_y_positive = SolidBoundaryConditionCell(temperature=3, position=(0, 0, 0), delta=(1, 0.1, plate_thickness)) capacitors[-1].place_adjacent(bc_y_positive, "y") boundaries = [bc_x_negative, bc_x_positive, bc_y_negative, bc_y_positive] .. GENERATED FROM PYTHON SOURCE LINES 81-86 View the network with VPython (add debugger breakpoint to view) ---------------------------------------------------------------- The coordinate system arrows are disabled because they are very big for this network. Comment out these lines if you just want to run the code. But during network build up it is nice to see if you placed everything correct. .. GENERATED FROM PYTHON SOURCE LINES 86-91 .. code-block:: Python viewer = Viewer(draw_coordinate_system=False) viewer.add_new_from_list(capacitors) viewer.add_new_from_list(boundaries) .. GENERATED FROM PYTHON SOURCE LINES 92-94 Connect everything with resistors between all Cells ---------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 94-97 .. code-block:: Python resistors = connect_cells_with_resistors([*capacitors, *boundaries]) .. GENERATED FROM PYTHON SOURCE LINES 98-100 Create RCNetwork ----------------- .. GENERATED FROM PYTHON SOURCE LINES 100-104 .. code-block:: Python network = RCNetwork(load_from_pickle=False, load_solution=False) network.rc_objects.set_lists(capacitors=capacitors, resistors=resistors, boundaries=boundaries) .. GENERATED FROM PYTHON SOURCE LINES 105-108 Solve network. --------------- We solve the network stationary (analytical). .. GENERATED FROM PYTHON SOURCE LINES 108-110 .. code-block:: Python network.solve_stationary() .. GENERATED FROM PYTHON SOURCE LINES 111-114 Parse the result to show it in ParaView ---------------------------------------- Open the case in ParaView using the 00_simulation.pvd file .. GENERATED FROM PYTHON SOURCE LINES 114-120 .. code-block:: Python network.rc_solution.write_paraview_data( folder=os.path.normpath(r"/path/to/result/folder"), use_degrees_celsius=False, # temperature is already in °C ) .. GENERATED FROM PYTHON SOURCE LINES 121-122 The result looks like this (or at least quite similar; the picture might be from an earlier version): .. GENERATED FROM PYTHON SOURCE LINES 124-125 .. image:: /_static/examples/internal_heat_source.svg :width: 100% .. rst-class:: sphx-glr-example-tags 🏷 Tags: network, solving, build, stationary, geometric .. _sphx_glr_download_auto_examples_internal_heat_source.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: internal_heat_source.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: internal_heat_source.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: internal_heat_source.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_