|
| 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. |
0 commit comments