Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trapped photon in macro atom mode #385

Closed
kslong opened this issue May 27, 2018 · 5 comments
Closed

Trapped photon in macro atom mode #385

kslong opened this issue May 27, 2018 · 5 comments
Assignees
Labels
bug Bugs in the code macro-atom Issues to do with macro-atoms

Comments

@kslong
Copy link
Collaborator

kslong commented May 27, 2018

I am encountering a trapped photon problem with the current dev version of the code for the following .pf file:

warm_macro.pf.txt

The problem arises during the detailed spectral stage, on the very first photon one is trying to generate (namely 66637). The trapping is occurring because this loop is never being escaped:

screenshot_779

in photo_gen_matom.c

The reason the loop is never escaped is because in the routine kpkt, there are a set of options to determine what kind of photon is being produced. The choice puts the photon into this region of the code:

screenshot_780

and *escape sets to 0, and you return. At that point, i is always 0 (nres 576) which is likely Ly-alpha. This triggers a repeat.

screenshot_781

mplasma is as above.

If I take this at face value, it looks like we want to generate a line photons, but we cannot because all the line cooling is due to a macro atom, and we are not allowed to generate a line photon for a macro atp,

Note that the logic of the kpkt routine is fairly obscure. There seems to have been a choice made to avoid generating more than one random number. There are various confusing places where one subtracts from the destruction_choice and then adds back to it.

Note: It is possible that this is a layered problem in the sense that there are other errors that are putting us into this situation, but it still seems to me one should be able to extract oneself from this problem, given what is here.

@jhmatthews I think you are probably going to have to solve (or at least comment on this).

@kslong kslong added the bug Bugs in the code label May 27, 2018
@kslong
Copy link
Collaborator Author

kslong commented May 27, 2018

The problem also arises in the same model with cylindrical coordinates. Like the routine with spherical coordinates this routine also produces other errors, that may be related specifically, the routine produces errors, like
cdf_gen_from_array: all y's were zero or xmin xmax out of range of array x-- returning uniform distribution 0

That is coming from a call from one_fb, namely

fb (xplasma, xplasma->t_e, fb_x[nnn], nions, FB_FULL)

where this is always returning 0. It's hard to know how related this is to our bug, as this is associated with fb, whereas the problem looks to be due to bb. It's possible though that fb_tot should be a lot larger than it appears in mplasma above.

@jhmatthews
Copy link
Collaborator

Ok, this is a tricky one. I agree that the procedure here is a little convoluted. photo_gen_kpkt wants to produce photons from the k->r process, but not photons where a kpkt excites a macro-atom (i.e. k->A*->r or similar in Lucy's notation). Hence we keep creating kpkts and just wait until a k->r process happens, as Knox says.

It's not clear to me that this is just due to the section of kpkt regarding lines - the bf cooling rate is comparable to the bb cooling rate so just because it was a line process this time doesn't mean it always will be.

I think fundamentally the issue is that the kpkt emissivity is non-zero, but the chances of a k->r packet lying in the wavelength range 6500->6600 are absolutely tiny. But I've a feeling there might be other issues here too. E.g., should the emissivity be non-zero? Regardless, clearly the code should be able to deal with this situation in a nicer way.

@jhmatthews
Copy link
Collaborator

First observation is that if you increase the wavelength range to 3000-6500 this problem goes away, which implies my above guess is right.

@kslong
Copy link
Collaborator Author

kslong commented Dec 2, 2018

I have run ito another example of this in trying to look at #290

original.pf.txt

This .pf file takes a good while to run, unfortunately

@jhmatthews What to we want to happen in this case?

@jhmatthews jhmatthews added the macro-atom Issues to do with macro-atoms label Apr 3, 2019
@kslong kslong mentioned this issue Apr 6, 2019
kslong added a commit that referenced this issue Apr 6, 2019
Corrections to enable C345 macro atom models to avoid various errors.   See #486 #385 #423 #425 

* changes to set a max ion stage if it is not Z+1

* fixed if statement in matrix_ion

* Changed version to 83a
@kslong
Copy link
Collaborator Author

kslong commented Apr 12, 2019

This error no longer occurs with the two examples we have used in the past, and so I am closing this issue.

It should be noted that for original.pf, the creation of the detailed spectra can much longer than the the ionization cycles.

Specifically, for original.pf the ionization cycles running with 16 processors take 45 minutes, while the detailed spectral runs minutes 132 minutes. It would be interesting to try to speed up the spectral runs.

Here is the updated .pf file for the longer of the two runs
original.pf.txt

This is an agn type model where we are trying to get the detailed spectrum from 3800 to 5500 A running 10**8 photons per cycle, which undoubtedly is part of the reason the detailed spectral cycles are slow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs in the code macro-atom Issues to do with macro-atoms
Projects
None yet
Development

No branches or pull requests

2 participants