.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/a_models/plot_polytropic_star.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_a_models_plot_polytropic_star.py: ============================= Build a Polytropic Star Model ============================= This example shows how to use the :class:`~pisces.models.stars.polytropes.PolytropicStarModel` to generate the internal structure of a star governed by a polytropic equation of state. We demonstrate two ways to construct a model: 1. From the total **mass and radius** of the star. 2. From the **central density and central temperature** of the core. The resulting model outputs physical profiles for density, pressure, temperature, gravitational potential, and mass. .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. code-block:: Python import tempfile import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 23-25 Imports ------- .. GENERATED FROM PYTHON SOURCE LINES 25-33 .. code-block:: Python import numpy as np from unyt import unyt_quantity from pisces.models.stars.polytropes import PolytropicStarModel # Create a temp directory. tmpdir = tempfile.TemporaryDirectory() .. GENERATED FROM PYTHON SOURCE LINES 34-38 Generate a Polytropic Star from Mass and Radius ----------------------------------------------- Here we create a model for a star with 1 solar mass and 1 solar radius, assuming a polytropic index n = 1.5 (typical for fully convective stars). .. GENERATED FROM PYTHON SOURCE LINES 38-59 .. code-block:: Python mass = unyt_quantity(1, "Msun") radius = unyt_quantity(1, "Rsun") n_index = [0.2, 0.3, 0.5, 1, 1.25, 1.5, 2, 2.5, 3] models = [] for n in n_index: filename = f"{tmpdir.name}/polytrope_example_{n}.h5" models.append( PolytropicStarModel.from_mass_and_radius( filename=filename, mass=mass, radius=radius, polytropic_index=n, overwrite=True, rmax=unyt_quantity(10, "Rsun"), rmin=unyt_quantity(0.01, "Rsun"), ) ) .. rst-class:: sphx-glr-script-out .. code-block:: none Preparing metadata...: 0%| | 0/7 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_polytropic_star.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_polytropic_star.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_