Skip to content

Feature/magn#9

Merged
AndreyTavleev merged 5 commits intoAndreyTavleev:masterfrom
Alvkuzin:feature/magn
Feb 5, 2026
Merged

Feature/magn#9
AndreyTavleev merged 5 commits intoAndreyTavleev:masterfrom
Alvkuzin:feature/magn

Conversation

@Alvkuzin
Copy link
Contributor

@Alvkuzin Alvkuzin commented Feb 4, 2026

The magnetic field is added. I created a new file magn from which I import the needed stuff to other modules. The two main additions are:

  1. In BaseVerticalStructure, I added two functions returning zero but to be overwritten by mixins: an additional pressure at the photosphere and an additional source of $dP/dz$. Then I created a class MagneticField which defines these functions (I collected all magn. fields args into a dictionary magn_args) and passed this MagneticField to BaseVerticalStructure or BaseMesaVerticalStructure as a mixin, creating a "magnetic" class for every VS non-mangetic one. I did it for all non-magnetic VS classes without irradiation; irrad. classes were not changed. Everywhere below when I say: 'it was tested for everything' or 'everything takes a new argument', I mean "everything that's without an irradiation".

  2. I created a class ViscousTorque which takes the same dictionary + some other parameters. This class takes care of everything that can be found prior to the VS calculation: torques, inner radius, Teff..., including the functions that determine $\dot{M}$ from $T_\mathrm{eff}$ or $F_\mathrm{vis}$. In case of magn_args=None, it gives the standard expressions: $r_{in} = r_{ISCO} = 3r_g, F = F_{in} + \dot{M} h (1 -\sqrt{(r_{in}/r)} )$, while for the magnetic field, the equations are generalized. The inner radius is now found using the function magn.radius_inner , and there is a magnetic contribution $F_\mathrm{magn}$ to $F$ calculated by magn.magnetic_torque. Note that the mixin MagneticField also initializes ViscousTorques inside, as it needs to calculate $r_0$ from $F$ (e.g., it recalculates $F \rightarrow \dot{M} \rightarrow r_{in}$).

So introducing these two main things, I also rewrote all references to the inner radius and viscous torques everywhere in profiles, e.g., now in StructureChoice the class Torques = ViscousTorques(...) is created, and it takes care of converting Mdot <-> F <-> Teff, and calculates r_in. Now in StructureChoice, if magn_args is None, the old classes are initialized, while if magn_args is not None, the new magnetic classes for VS are chosen. Subsequently, other classes of profiles: VerticalProfile, S_Curve, and Radial_Structure are now taking magn_args as an argument.

The BaseVerticalStructure, and all subsequent functions (VS classes and classes defined in profile) can now take a boolean argument rad_pressure_include which determines whether to take the radiation pressure into account in calculations. Everywhere when it was clear that something like $...+4\sigma_b T^4/3c $ appears, I changed it to rad_pressure(T) that returns the same if rad_pressure_include==True and zero if rad_pressure_include==False.

The classes VerticalProfile, S_Curve, and Radial_Structure now can return namedtuples (if to_return=True) containing some results of calculations. These classes now all have an argument to_save which tells whether to save results in a file. They all now have their corresponding verbose_scurve/verbose_rad arguments which determine whether to print the information as the calculation proceeds.

All additions to the existing methods and functions were made as to follow the backward compatibility. If a user uses the new model as they were using it before, nothing should change for this user.

Using the provided 'tests', I made sure that the tests are successful for the non-magnetic case.

I changed ReadMe slightly; I updated a version number in pyproject.toml, and added a .gitignore.

@AndreyTavleev AndreyTavleev merged commit 2fb139a into AndreyTavleev:master Feb 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants