Skip to content

Commit 4c6bd87

Browse files
authored
Merge pull request sirocco-rt#1128 from sirocco-rt/dense
Handling of low frequency photons in macro mode
2 parents 8cae85a + 2806065 commit 4c6bd87

10 files changed

Lines changed: 150 additions & 40 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
The code is under active development, but we are looking for beta users to test the code, and potentially use it for their own research. If you are interested in using Sirocco please contact Knox Long via long[at]stsci[dot]edu
1111
or James Matthews via james[dot]matthews[at]physics[dot]ox[dot]ac[dot]uk.
1212

13-
Documentation is hosted on [ReadTheDocs]((https://sirocco-rt.readthedocs.io).
13+
Documentation is hosted on [ReadTheDocs](https://sirocco-rt.readthedocs.io).
1414

1515
## Installation
1616

‎py_progs/plot_wind.py‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ def get_data(filename='fiducial_agn_master.txt', var='t_r',grid='ij',inwind='',s
140140
This routine reads and scales the data from a single variable that is read from an ascii table
141141
representation of one or more of the parameters in a windsave file
142142
143+
The grid obptions:
144+
145+
ij
146+
log
147+
lin
148+
143149
'''
144150

145151
try:
@@ -182,8 +188,6 @@ def get_data(filename='fiducial_agn_master.txt', var='t_r',grid='ij',inwind='',s
182188
ylogmin=numpy.log10(xmin/10)
183189
x=numpy.select([x>1],[numpy.log10(x)],default=xlogmin)
184190
y=numpy.select([y>1],[numpy.log10(y)],default=ylogmin)
185-
# x=numpy.log10(x)
186-
# y=numpy.log10(y)
187191
xlabel='log(x)'
188192
ylabel='log(z)'
189193
else:
@@ -333,15 +337,51 @@ def doit(filename='fiducial_agn.master.txt', var='t_r',grid='ij',inwind='',scale
333337
return plotfile
334338

335339

340+
def steer(argv):
341+
'''
342+
Controlling routine for py_wind
343+
'''
336344

345+
xfile=''
346+
xvar=''
347+
xgrid='ij'
348+
xmin=-1e50
349+
xmax=1e50
350+
xscale='guess'
351+
352+
i=1
353+
while i<len(argv):
354+
if argv[i][0:2]=='-h':
355+
print(__doc__)
356+
return
357+
elif argv[i]=='-log':
358+
xgrid='log'
359+
elif argv[i][0:4]=='-lin':
360+
xgrid='linear'
361+
elif argv[i][0:4]=='-min':
362+
i+=1
363+
xmin=eval(argv[i])
364+
elif argv[i][0:4]=='-max':
365+
i+=1
366+
xmax=eval(argv[i])
367+
elif argv[i][0]=='-':
368+
print('Unknown options :',argv)
369+
return
370+
elif xfile=='':
371+
xfile=argv[i]
372+
elif xvar=='':
373+
xvar=argv[i]
374+
i+=1
337375

338376

377+
doit(filename=xfile, var=xvar,grid=xgrid,inwind='',scale='log',zmin=xmin,zmax=xmax,
378+
plot_dir='',root='')
339379

340380

341381
# Next lines permit one to run the routine from the command line
342382
if __name__ == "__main__":
343383
import sys
344384
if len(sys.argv)>2:
345-
doit(sys.argv[1],sys.argv[2])
385+
steer(sys.argv)
346386
else:
347-
print('usage: plot_wind filename variable')
387+
print(__doc__)

‎source/communicate_plasma.c‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ broadcast_plasma_grid (const int n_start, const int n_stop, const int n_cells_ra
5050

5151
d_xsignal (files.root, "%-20s Begin communicating plasma grid\n", "NOK");
5252
const int n_cells_max = get_max_cells_per_rank (NPLASMA);
53+
//OLD const int comm_buffer_size = calculate_comm_buffer_size (1 + n_cells_max * (1 + 20 + nphot_total + nions + NXBANDS + 2 * N_PHOT_PROC),
54+
//OLD n_cells_max * (71 + 11 * nions + nlte_levels + 2 * nphot_total + n_inner_tot +
55+
//OLD 11 * NXBANDS + NBINS_IN_CELL_SPEC + 6 * NFLUX_ANGLES +
56+
//OLD N_DMO_DT_DIRECTIONS + 12 * NFORCE_DIRECTIONS));
57+
5358
const int comm_buffer_size = calculate_comm_buffer_size (1 + n_cells_max * (1 + 20 + nphot_total + nions + NXBANDS + 2 * N_PHOT_PROC),
54-
n_cells_max * (71 + 11 * nions + nlte_levels + 2 * nphot_total + n_inner_tot +
59+
n_cells_max * (73 + 11 * nions + nlte_levels + 2 * nphot_total + n_inner_tot +
5560
11 * NXBANDS + NBINS_IN_CELL_SPEC + 6 * NFLUX_ANGLES +
5661
N_DMO_DT_DIRECTIONS + 12 * NFORCE_DIRECTIONS));
5762
char *comm_buffer = malloc (comm_buffer_size);
@@ -117,6 +122,8 @@ broadcast_plasma_grid (const int n_start, const int n_stop, const int n_cells_ra
117122
MPI_Pack (&cell->ntot_agn, 1, MPI_INT, comm_buffer, comm_buffer_size, &position, MPI_COMM_WORLD);
118123
MPI_Pack (&cell->nscat_es, 1, MPI_INT, comm_buffer, comm_buffer_size, &position, MPI_COMM_WORLD);
119124
MPI_Pack (&cell->nscat_res, 1, MPI_INT, comm_buffer, comm_buffer_size, &position, MPI_COMM_WORLD);
125+
MPI_Pack (&cell->nscat_bf, 1, MPI_INT, comm_buffer, comm_buffer_size, &position, MPI_COMM_WORLD);
126+
MPI_Pack (&cell->nscat_ff, 1, MPI_INT, comm_buffer, comm_buffer_size, &position, MPI_COMM_WORLD);
120127
MPI_Pack (&cell->mean_ds, 1, MPI_DOUBLE, comm_buffer, comm_buffer_size, &position, MPI_COMM_WORLD);
121128
MPI_Pack (&cell->n_ds, 1, MPI_INT, comm_buffer, comm_buffer_size, &position, MPI_COMM_WORLD);
122129
MPI_Pack (&cell->nrad, 1, MPI_INT, comm_buffer, comm_buffer_size, &position, MPI_COMM_WORLD);
@@ -272,6 +279,8 @@ broadcast_plasma_grid (const int n_start, const int n_stop, const int n_cells_ra
272279
MPI_Unpack (comm_buffer, comm_buffer_size, &position, &cell->ntot_agn, 1, MPI_INT, MPI_COMM_WORLD);
273280
MPI_Unpack (comm_buffer, comm_buffer_size, &position, &cell->nscat_es, 1, MPI_INT, MPI_COMM_WORLD);
274281
MPI_Unpack (comm_buffer, comm_buffer_size, &position, &cell->nscat_res, 1, MPI_INT, MPI_COMM_WORLD);
282+
MPI_Unpack (comm_buffer, comm_buffer_size, &position, &cell->nscat_bf, 1, MPI_INT, MPI_COMM_WORLD);
283+
MPI_Unpack (comm_buffer, comm_buffer_size, &position, &cell->nscat_ff, 1, MPI_INT, MPI_COMM_WORLD);
275284
MPI_Unpack (comm_buffer, comm_buffer_size, &position, &cell->mean_ds, 1, MPI_DOUBLE, MPI_COMM_WORLD);
276285
MPI_Unpack (comm_buffer, comm_buffer_size, &position, &cell->n_ds, 1, MPI_INT, MPI_COMM_WORLD);
277286
MPI_Unpack (comm_buffer, comm_buffer_size, &position, &cell->nrad, 1, MPI_INT, MPI_COMM_WORLD);
@@ -593,10 +602,12 @@ broadcast_updated_plasma_properties (const int n_start_rank, const int n_stop_ra
593602

594603
d_xsignal (files.root, "%-20s Begin communicating updated plasma properties\n", "NOK");
595604
const int n_cells_max = get_max_cells_per_rank (NPLASMA);
596-
const int num_ints = 1 + n_cells_max * (20 + nphot_total + 2 * NXBANDS + 2 * N_PHOT_PROC + nions);
605+
//OLD const int num_ints = 1 + n_cells_max * (20 + nphot_total + 2 * NXBANDS + 2 * N_PHOT_PROC + nions);
606+
const int num_ints = 1 + n_cells_max * (22 + nphot_total + 2 * NXBANDS + 2 * N_PHOT_PROC + nions);
597607
const int num_doubles =
598608
n_cells_max * (71 + 1 * 3 + 9 * 4 + 6 * NFLUX_ANGLES + 3 * NFORCE_DIRECTIONS + 9 * nions + 1 * nlte_levels + 3 * nphot_total +
599609
1 * n_inner_tot + 9 * NXBANDS + 1 * NBINS_IN_CELL_SPEC);
610+
600611
const int size_of_comm_buffer = calculate_comm_buffer_size (num_ints, num_doubles);
601612
char *const comm_buffer = malloc (size_of_comm_buffer);
602613
if (comm_buffer == NULL)
@@ -662,6 +673,8 @@ broadcast_updated_plasma_properties (const int n_start_rank, const int n_stop_ra
662673
MPI_Pack (&plasmamain[n_plasma].ntot_wind, 1, MPI_INT, comm_buffer, size_of_comm_buffer, &position, MPI_COMM_WORLD);
663674
MPI_Pack (&plasmamain[n_plasma].ntot_agn, 1, MPI_INT, comm_buffer, size_of_comm_buffer, &position, MPI_COMM_WORLD);
664675
MPI_Pack (&plasmamain[n_plasma].nscat_es, 1, MPI_INT, comm_buffer, size_of_comm_buffer, &position, MPI_COMM_WORLD);
676+
MPI_Pack (&plasmamain[n_plasma].nscat_bf, 1, MPI_INT, comm_buffer, size_of_comm_buffer, &position, MPI_COMM_WORLD);
677+
MPI_Pack (&plasmamain[n_plasma].nscat_ff, 1, MPI_INT, comm_buffer, size_of_comm_buffer, &position, MPI_COMM_WORLD);
665678
MPI_Pack (&plasmamain[n_plasma].mean_ds, 1, MPI_DOUBLE, comm_buffer, size_of_comm_buffer, &position, MPI_COMM_WORLD);
666679
MPI_Pack (&plasmamain[n_plasma].n_ds, 1, MPI_INT, comm_buffer, size_of_comm_buffer, &position, MPI_COMM_WORLD);
667680
MPI_Pack (&plasmamain[n_plasma].nrad, 1, MPI_INT, comm_buffer, size_of_comm_buffer, &position, MPI_COMM_WORLD);
@@ -830,6 +843,8 @@ broadcast_updated_plasma_properties (const int n_start_rank, const int n_stop_ra
830843
MPI_Unpack (comm_buffer, size_of_comm_buffer, &position, &plasmamain[n_plasma].ntot_wind, 1, MPI_INT, MPI_COMM_WORLD);
831844
MPI_Unpack (comm_buffer, size_of_comm_buffer, &position, &plasmamain[n_plasma].ntot_agn, 1, MPI_INT, MPI_COMM_WORLD);
832845
MPI_Unpack (comm_buffer, size_of_comm_buffer, &position, &plasmamain[n_plasma].nscat_es, 1, MPI_INT, MPI_COMM_WORLD);
846+
MPI_Unpack (comm_buffer, size_of_comm_buffer, &position, &plasmamain[n_plasma].nscat_bf, 1, MPI_INT, MPI_COMM_WORLD);
847+
MPI_Unpack (comm_buffer, size_of_comm_buffer, &position, &plasmamain[n_plasma].nscat_ff, 1, MPI_INT, MPI_COMM_WORLD);
833848
MPI_Unpack (comm_buffer, size_of_comm_buffer, &position, &plasmamain[n_plasma].mean_ds, 1, MPI_DOUBLE, MPI_COMM_WORLD);
834849
MPI_Unpack (comm_buffer, size_of_comm_buffer, &position, &plasmamain[n_plasma].n_ds, 1, MPI_INT, MPI_COMM_WORLD);
835850
MPI_Unpack (comm_buffer, size_of_comm_buffer, &position, &plasmamain[n_plasma].nrad, 1, MPI_INT, MPI_COMM_WORLD);

‎source/macro_accelerate.c‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ f_kpkt_emit_accelerate (xplasma, freq_min, freq_max)
808808

809809
/* JM 1511 -- Fix for issue 187. We need band limits for free free packet
810810
generation (see call to one_ff below) */
811-
ff_freq_min = xband.f1[0];
811+
ff_freq_min = 0.0; // since #1128 the low frequency limit is always zero for free-free
812812
ff_freq_max = ALPHA_FF * xplasma->t_e / H_OVER_K;
813813

814814
/* ksl This is a Bandaid for when the temperatures are very low */
@@ -887,30 +887,35 @@ f_kpkt_emit_accelerate (xplasma, freq_min, freq_max)
887887
/* consult issues #187, #492 regarding free-free */
888888
penorm += eprbs = mplasma->cooling_ff + mplasma->cooling_ff_lofreq;
889889

890-
total_ff_lofreq = total_free (xplasma, xplasma->t_e, 0, ff_freq_min);
890+
//total_ff_lofreq = total_free (xplasma, xplasma->t_e, 0, ff_freq_min);
891+
//total_ff = total_free (xplasma, xplasma->t_e, ff_freq_min, ff_freq_max);
891892
total_ff = total_free (xplasma, xplasma->t_e, ff_freq_min, ff_freq_max);
892893

893894
/*
895+
* Calculate the band-limited free-free luminosity by incrementing penorm_band.
894896
* Do not increment penorm_band when the total free-free luminosity is zero
895897
*/
896-
897-
if (freq_min > ff_freq_min)
898-
{
899-
if (total_ff > 0)
900-
penorm_band += total_free (xplasma, xplasma->t_e, freq_min, freq_max) / total_ff * mplasma->cooling_ff;
901-
}
902-
else if (freq_max > ff_freq_min)
903-
{
904-
if (total_ff > 0)
905-
penorm_band += total_free (xplasma, xplasma->t_e, ff_freq_min, freq_max) / total_ff * mplasma->cooling_ff;
906-
if (total_ff_lofreq > 0)
907-
penorm_band += total_free (xplasma, xplasma->t_e, freq_min, ff_freq_min) / total_ff_lofreq * mplasma->cooling_ff_lofreq;
908-
}
909-
else
910-
{
911-
if (total_ff_lofreq > 0)
912-
penorm_band += total_free (xplasma, xplasma->t_e, freq_min, freq_max) / total_ff_lofreq * mplasma->cooling_ff_lofreq;
913-
}
898+
if (total_ff > 0)
899+
penorm_band += total_free (xplasma, xplasma->t_e, freq_min, freq_max) / total_ff * mplasma->cooling_ff;
900+
901+
/* we used to have to do some extra stuff here due to low frequency free-free behaviour, see #1128 */
902+
// if (freq_min > ff_freq_min)
903+
// {
904+
// if (total_ff > 0)
905+
// penorm_band += total_free (xplasma, xplasma->t_e, freq_min, freq_max) / total_ff * mplasma->cooling_ff;
906+
// }
907+
// else if (freq_max > ff_freq_min)
908+
// {
909+
// if (total_ff > 0)
910+
// penorm_band += total_free (xplasma, xplasma->t_e, ff_freq_min, freq_max) / total_ff * mplasma->cooling_ff;
911+
// if (total_ff_lofreq > 0)
912+
// penorm_band += total_free (xplasma, xplasma->t_e, freq_min, ff_freq_min) / total_ff_lofreq * mplasma->cooling_ff_lofreq;
913+
// }
914+
// else
915+
// {
916+
// if (total_ff_lofreq > 0)
917+
// penorm_band += total_free (xplasma, xplasma->t_e, freq_min, freq_max) / total_ff_lofreq * mplasma->cooling_ff_lofreq;
918+
// }
914919

915920
penorm += eprbs = mplasma->cooling_adiabatic;
916921

‎source/matom.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ kpkt (p, nres, escape, mode)
10541054
}
10551055
else if (destruction_choice < (mplasma->cooling_bftot + cooling_bbtot + mplasma->cooling_ff + mplasma->cooling_ff_lofreq))
10561056
{
1057-
/*this is ff at a frequency that is so low frequency that it is not worth tracking further */
1057+
/*this is ff at a frequency that is so low frequency that it is not worth tracking further */
10581058
*escape = TRUE;
10591059
*nres = NRES_FF;
10601060
p->istat = P_LOFREQ_FF;
@@ -1065,7 +1065,7 @@ kpkt (p, nres, escape, mode)
10651065
else if (destruction_choice <
10661066
(mplasma->cooling_bftot + cooling_bbtot + mplasma->cooling_ff + mplasma->cooling_ff_lofreq + cooling_adiabatic))
10671067
{
1068-
/* It is a k-packat that is destroyed by adiabatic cooling */
1068+
/* It is a k-packat that is destroyed by adiabatic cooling */
10691069

10701070
if (geo.adiabatic == 0 || mode == KPKT_MODE_CONTINUUM)
10711071
{

‎source/photon2d.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,23 @@ translate_in_wind (w, p, tau_scat, tau, nres)
465465
ds_current = calculate_ds (w, p, tau_scat, tau, nres, smax, &istat);
466466

467467
if (p->nres == NRES_ES)
468+
{
468469
xplasma->nscat_es++;
470+
}
471+
if (p->nres > NLINES)
472+
{
473+
xplasma->nscat_bf++;
474+
}
475+
469476
else if (p->nres > 0)
477+
{
470478
xplasma->nscat_res++;
479+
}
480+
else if (p->nres == NRES_FF)
481+
{
482+
xplasma->nscat_ff++;
483+
}
484+
471485

472486
/* We now increment the radiation field in the cell, translate the photon and wrap
473487
* things up. For simple atoms, the routine radiation also reduces

‎source/resonate.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,14 @@ calculate_ds (w, p, tau_scat, tau, nres, smax, istat)
425425
*
426426
* * -1 implies electron scattering
427427
* * -2 implies free-free
428-
* * 0 or greater implies a specific photionization process was responsible (and
429-
* also that the program was operating in macro-atom mode.
428+
* * Greater that NLINES implies a specific photionization process was responsible
430429
*
431430
* @details
432431
* This routine is called to determine which of several continuum proceseses
433432
* cause a photon to be scattered or absorbed. In addition to electron scattering
434433
* and free-free absorption, the routine can identify which photoionization process
435-
* is implicated.
434+
* is implicated assuming we are in macro-atom mode, when photoionization is considred
435+
* as a scattering process..
436436
*
437437
* ### Notes ###
438438
*
@@ -443,10 +443,14 @@ calculate_ds (w, p, tau_scat, tau, nres, smax, istat)
443443
* which of the processes was responsible. Data for the opacity due to
444444
* photonionization is passed remotely via the PlasmaPtr.
445445
*
446-
* In a program running in the two level approximation, only electron scattering
447-
* and ff and bf are treated as absorption processes. In macro atom, ff and
448-
* photoionization are treated as a scattering
449-
* processes.
446+
* In a program running in the two level approximation, electron scattering
447+
* and ff are treated as scattering processes; bf is treated as absorption processes
448+
* and so in that case, the routine chooses between es and ff scatering.
449+
* In macro atom, ff and photoionization are treated as a scattering
450+
* processes, so any one of these can be returned
451+
*
452+
* In order to avoid confusion with bb processes, the bf option returns
453+
* a value that is larger than NLINES.
450454
*
451455
**********************************************************/
452456

‎source/sirocco.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ extern int NWAVE_NOW; /**< Either NWAVE_IONIZ or NWAVE_EXTRACT depending
141141
*/
142142
#define NWAVE_MIN 100 /**< The minimum number of wavelength bins in during spectral cycles
143143
*/
144-
#define MAXSCAT 2000
144+
#define MAXSCAT 20000
145145

146146
/* Define the structures */
147147
#include "math_struc.h"
@@ -936,6 +936,8 @@ typedef struct plasma
936936

937937
int nscat_es; /**< The number of electrons scatters in the cell */
938938
int nscat_res; /**< The number of resonant line scatters in the cell */
939+
int nscat_bf; /**< Number of bf scatters in the cell. (macro_only) */
940+
int nscat_ff; /**< Number of ff scatters in the cell. (macro_only) */
939941

940942
double mean_ds; /**< Mean photon path length in a cell. */
941943
int n_ds; /**< Number of times a path lengyh was added; needed to compute mean_ds */

‎source/wind_updates2d.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ init_plasma_rad_properties (void)
557557
plasmamain[i].ntot_bl = 0;
558558
plasmamain[i].nscat_es = 0;
559559
plasmamain[i].nscat_res = 0;
560+
plasmamain[i].nscat_bf = 0;
561+
plasmamain[i].nscat_ff = 0;
560562
plasmamain[i].ntot_wind = 0;
561563
plasmamain[i].nrad = 0;
562564
plasmamain[i].nioniz = 0;

‎source/windsave2table_sub.c‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ create_master_table (ndom, rootname)
154154
{
155155
char filename[132];
156156
double *c[50], *converge;
157-
char column_name[50][20];
158-
char one_line[1024], start[1024], one_value[20];
157+
char column_name[50][24];
158+
char one_line[1024], start[1024], one_value[24];
159159
char name[132]; /* file name extension */
160160

161161

@@ -227,9 +227,21 @@ create_master_table (ndom, rootname)
227227
c[17] = get_one (ndom, "nioniz");
228228
strcpy (column_name[17], "nioniz");
229229

230+
c[18] = get_one (ndom, "nscat_es");
231+
strcpy (column_name[18], "nscat_es");
232+
233+
c[19] = get_one (ndom, "nscat_res");
234+
strcpy (column_name[19], "nscat_res");
235+
236+
c[20] = get_one (ndom, "nscat_ff");
237+
strcpy (column_name[20], "nscat_ff");
238+
239+
c[21] = get_one (ndom, "nscat_bf");
240+
strcpy (column_name[21], "nscat_bf");
241+
230242

231243
/* This should be the maxium number above +1 */
232-
ncols = 18;
244+
ncols = 22;
233245

234246

235247
converge = get_one (ndom, "converge");
@@ -1479,6 +1491,22 @@ get_one (ndom, variable_name)
14791491
{
14801492
x[n] = plasmamain[nplasma].nioniz;
14811493
}
1494+
else if (strcmp (variable_name, "nscat_es") == 0)
1495+
{
1496+
x[n] = plasmamain[nplasma].nscat_es;
1497+
}
1498+
else if (strcmp (variable_name, "nscat_res") == 0)
1499+
{
1500+
x[n] = plasmamain[nplasma].nscat_res;
1501+
}
1502+
else if (strcmp (variable_name, "nscat_bf") == 0)
1503+
{
1504+
x[n] = plasmamain[nplasma].nscat_bf;
1505+
}
1506+
else if (strcmp (variable_name, "nscat_ff") == 0)
1507+
{
1508+
x[n] = plasmamain[nplasma].nscat_ff;
1509+
}
14821510
else if (strcmp (variable_name, "heat_shock") == 0)
14831511
{
14841512
x[n] = plasmamain[nplasma].heat_shock;

0 commit comments

Comments
 (0)