Skip to content

Commit 24e4033

Browse files
authored
Add example for a beam heating configuration (#185)
1 parent 088acbc commit 24e4033

File tree

7 files changed

+182
-7
lines changed

7 files changed

+182
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![pydrad CI status](https://github.com/rice-solar-physics/pydrad/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/rice-solar-physics/pydrad/actions)
44
[![Documentation Status](https://readthedocs.org/projects/pydrad/badge/?version=latest)](https://pydrad.readthedocs.io/en/latest/?badge=latest)
55
[![codecov](https://codecov.io/gh/rice-solar-physics/pydrad/branch/master/graph/badge.svg)](https://codecov.io/gh/rice-solar-physics/pydrad)
6+
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8411058.svg)](https://doi.org/10.5281/zenodo.8411058)
67

78
Some Python tools to configure and parse output from the HYDrodynamics and RADiation (HYDRAD) code for field-aligned coronal loop physics.
89

docs/citation.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Citing pydrad
2+
===============
3+
4+
If you make use of pydrad in your work that leads to a publication, it would be
5+
appreciated if you cite the software package.
6+
7+
Please add the following line in your acknowledgements:
8+
9+
*This research used version X.Y.Z (software citation) of the pydrad open source software package.*
10+
11+
The software citation should be the specific `Zenodo DOI`_ for the version used within your work.
12+
The citation for the most current version on Zenodo is
13+
14+
.. code:: bibtex
15+
16+
@software{Barnes2023,
17+
author = {Will Barnes and
18+
Jeffrey Reep and
19+
Stephen Bradshaw},
20+
title = {rice-solar-physics/pydrad: v0.1},
21+
month = oct,
22+
year = 2023,
23+
publisher = {Zenodo},
24+
version = {v0.1},
25+
doi = {10.5281/zenodo.8411058},
26+
url = {https://doi.org/10.5281/zenodo.8411058}
27+
}
28+
29+
In addition to citing pydrad, you should also cite the HYDRAD code itself.
30+
31+
.. _Zenodo DOI: https://doi.org/10.5281/zenodo.8411057

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ code for modeling the field-aligned dynamics of coronal loops.
1616
getting_started
1717
generated/gallery/index
1818
config_tables
19+
citation
1920
code_ref/index
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
"""
2+
===================================
3+
Configure a Beam Heating Simulation
4+
===================================
5+
6+
This example demonstrates a typical configuration of a HYDRAD
7+
simulation with electron beam heating.
8+
"""
9+
import pathlib
10+
import tempfile
11+
12+
import astropy.units as u
13+
14+
from pydrad.configure import Configure
15+
from pydrad.configure.data import get_defaults
16+
from pydrad.configure.util import get_clean_hydrad
17+
18+
#################################################################
19+
# HYDRAD can be used for simulations of solar flares, in addition
20+
# to active region loops. Since flares have significantly stronger
21+
# energy release, however, some of the parameters need to be set
22+
# more stringently than might be done for e.g. nanoflare heating.
23+
# This example will show how to set up a reasonable flare simulation.
24+
#
25+
# Let's start with the defaults:
26+
config = get_defaults()
27+
28+
#################################################################
29+
# Configure the basic parameters of the simulation first. Let's assume a
30+
# loop length of 50 Mm, and run the simulation for one hour of simulation time.
31+
config['general']['loop_length'] = 50 * u.Mm
32+
config['general']['total_time'] = 1 * u.h
33+
34+
#################################################################
35+
# We typically assume that the loop is heated by electron beam heating,
36+
# where electrons are accelerated to tens of keV in energy in the corona,
37+
# and stream towards the chromosphere, where they deposit that energy.
38+
#
39+
# With beam heating, we typically want to use a slightly more detailed
40+
# chromosphere (rather than assuming constant temperature).
41+
# This is for two reasons: (1) it needs to be dense enough to stop the
42+
# beam, and (2) the energy deposition will produce a more realistic
43+
# chromospheric evaporation.
44+
# To do this, we turn on optically thick radiation, which will calculate
45+
# optically thick radiative losses in the chromosphere, produced by
46+
# hydrogen, magnesium, and calcium (based on the formulation by
47+
# Carlsson & Leenaarts 2012). This will also set the chromospheric
48+
# temperature profile to the so-called VAL C model.
49+
config['radiation']['optically_thick_radiation'] = True
50+
51+
#################################################################
52+
# For consistency with VAL C, we also need to set a few boundary conditions:
53+
config['general']['footpoint_height'] = 2.26 * u.Mm
54+
config['initial_conditions']['footpoint_temperature'] = 24000 * u.K
55+
config['initial_conditions']['footpoint_density'] = 4.2489e9 * u.cm**(-3)
56+
config['solver']['minimum_radiation_temperature'] = 24000 * u.K
57+
config['solver']['minimum_temperature'] = 4170 * u.K
58+
59+
#################################################################
60+
# There is one further option for the chromosphere. It is not generally
61+
# recommended, but produces more accurate electron densities. This will
62+
# solve an approximation to radiative transfer for hydrogen with the caveat that
63+
# it will slow the code by well over an order of magnitude. It is most
64+
# useful for users who wish to synthesize chromospheric line profiles.
65+
# Change the value to True if you would like to try using it.
66+
config['radiation']['nlte_chromosphere'] = False
67+
68+
#################################################################
69+
# This takes care of the chromosphere, but we should also set up the radiation
70+
# calculation in the corona (the optically thin losses). Let's use the 15 most
71+
# abundant elements in the Sun for this calculation
72+
config['radiation']['use_power_law_radiative_losses'] = False
73+
config['radiation']['elements_equilibrium'] = ['H','He','C','N','O','Ne','Na','Mg','Al','Si','S','Ar','Ca','Fe','Ni']
74+
75+
#################################################################
76+
# We still need to set up the electron beam itself.
77+
# Let's assume a constant heating for 10 seconds, using a moderate
78+
# energy flux, typical low energy cut-off of 15 keV, and typical spectral index of 5.
79+
config['heating']['beam'] = [
80+
{'time_start': 10.0*u.s,
81+
'flux': 3e10*u.erg/(u.cm**2)/u.s,
82+
'cut_off': 15.0*u.keV,
83+
'index': 5.0},
84+
]
85+
86+
#################################################################
87+
# Finally, let's set parameters to ensure the simulation runs smoothly.
88+
# There are a lot of numerical parameters, so we'll explain what these mean.
89+
#
90+
# First, let's consider the time-stepping. HYDRAD solves its equations explicitly,
91+
# meaning that the CFL condition must be met at all times for numerical stability.
92+
# This means that the time-step, :math:`dt`, must always be sufficiently small to produce
93+
# an accurate numerical solution.
94+
#
95+
# Let's first set "safety" parameters for the radiation and conduction time-scales,
96+
# which simply reduce their values to make it more likely that the CFL condition is met.
97+
config['solver']['safety_radiation'] = 0.1
98+
config['solver']['safety_conduction'] = 0.1
99+
100+
#################################################################
101+
# Since conduction can be extremely limiting, we also set an effective floor:
102+
config['general']['heat_flux_timestep_limit'] = 1e-6 * u.s
103+
104+
#################################################################
105+
# Next, we want to make sure that the grid is spatially resolved
106+
# We are telling the code to refine the grid every time step, and that
107+
# any grid cell can be refined up to 12 times. For extremely strong heating events,
108+
# you might consider increasing this to 14.
109+
config['solver']['adapt_every_n_time_steps'] = 1
110+
config['solver']['initial_refinement_level'] = 12
111+
config['solver']['maximum_refinement_level'] = 12
112+
113+
#################################################################
114+
# Finally, we change a few parameters from their defaults, only for stability
115+
# Do not check for numerical precision errors in the conservation of energy:
116+
config['solver']['enforce_conservation'] = False
117+
118+
#################################################################
119+
# Do not refine the grid on hydrogen energy:
120+
config['solver']['refine_on_hydrogen_energy'] = False
121+
122+
123+
#################################################################
124+
# As in the basic tutorial, we now use the configuration defined here
125+
# to set up the simulation by writing configuration files.
126+
c = Configure(config)
127+
tmpdir = pathlib.Path(tempfile.mkdtemp()) # Change this to wherever you want to save the unedited HYDRAD copy
128+
hydrad_clean = tmpdir / 'hydrad-clean'
129+
get_clean_hydrad(hydrad_clean, from_github=True)
130+
c.setup_simulation(tmpdir / 'test-run', hydrad_clean) # The location of the simulation itself
131+
132+
#################################################################
133+
# This will have set up the simulation, which can now be run! Since
134+
# beam heating simulations can be somewhat slower, it is recommended
135+
# to run this by hand in a terminal. Also, if using Mac, be sure to
136+
# use the "caffeinate" command to keep the computer from sleeping.

pydrad/configure/data/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
Data related to configuration
33
"""
44
import copy
5+
import importlib
56

67
import asdf
7-
import pkg_resources
88

99

1010
def get_defaults():
11-
filename = pkg_resources.resource_filename(
12-
'pydrad',
13-
'configure/data/defaults.asdf',
14-
)
11+
filename = importlib.resources.files(
12+
'pydrad' ) / 'configure/data/defaults.asdf'
1513
with asdf.open(filename) as af:
1614
return copy.deepcopy(dict(af.tree))

pydrad/configure/data/defaults.asdf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ radiation:
7373
density_dependent_rates: false
7474
elements_equilibrium: []
7575
elements_nonequilibrium: []
76-
emissivity_dataset: chianti_v7
76+
emissivity_dataset: chianti_v10
7777
nlte_chromosphere: false
7878
optically_thick_radiation: false
7979
ranges_dataset: ranges
80-
rates_dataset: chianti_v7
80+
rates_dataset: chianti_v10
8181
use_power_law_radiative_losses: true
8282
solver:
8383
cutoff_ion_fraction: 1.0e-15

pydrad/configure/tests/test_configure.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import pytest
77

8+
from pydrad.configure.data import get_defaults
9+
810

911
@pytest.mark.parametrize(
1012
'filename',
@@ -17,3 +19,9 @@
1719
def test_generated_files_exist(hydrad, filename):
1820
generated_file = pathlib.Path(hydrad / filename)
1921
assert generated_file.is_file()
22+
23+
def test_default_config():
24+
default_config = get_defaults()
25+
assert default_config['radiation']['abundance_dataset'] == 'asplund'
26+
assert default_config['initial_conditions']['isothermal'] == False
27+
assert default_config['general']['write_file_physical'] == True

0 commit comments

Comments
 (0)