Skip to content

Suggestion for reading in the gasIIdust() in molinit.c #148

@cleevesli

Description

@cleevesli

Hey all,

I use LIME to create line simulations from pre-tabulated chemical models, so it involves a lot of interpolation. The code has always been a bit slow even though I try to use fast interpolation techniques, and so finally last week I spent a little time trying to figure out why. The reason was actually pretty simple, in the kappa() function, the ordering of the for-loop essentially has the code retrieve the gas-to-dust mass ratio for every level in the molecule, which -- if gasIIdust is being interpolated -- ends up being one of the slowest steps.

As a suggestion, switching the ordering of the for-loop and then splitting out the 230 GHz "fix" as a second loop was a huge speed increase for me. It might be a second slower for those using a constant value of of gasIIdust, but for me it took a ~4 hour run down to < 20 minutes for a model with 7500 points.

Below is my suggestion. I can't think of any situation this wouldn't work for, gasIIdust shouldn't depend on molecular properties or frequency.

Best,
ilse

Original code in kappa in molinit.c:

  for(iline=0;iline<m[s].nline;iline++){
    for(id=0;id<par->ncell;id++){
      gasIIdust(g[id].x[0],g[id].x[1],g[id].x[2],&gtd);
      g[id].mol[s].knu[iline]=kappatab[iline]*2.4*AMU/gtd*g[id].dens[0];

      /* Check if input model supplies a dust temperature. Otherwise use the kinetic temperature. */
      if(g[id].t[1]==-1) {
        g[id].mol[s].dust[iline]=planckfunc(iline,g[id].t[0],m,s);
      } else {
        g[id].mol[s].dust[iline]=planckfunc(iline,g[id].t[1],m,s);
      }
    }
    /* Fix the normalization at 230GHz. */
    m[s].norm=planckfunc(0,par->tcmb,m,0);
    m[s].norminv=1./m[s].norm;
    if(par->tcmb>0.) m[s].cmb[iline]=planckfunc(iline,par->tcmb,m,s)/m[s].norm;
    else m[s].cmb[iline]=0.;
    m[s].local_cmb[iline]=planckfunc(iline,2.728,m,s)/m[s].norm;
  }

New version:

  for(id=0;id<par->ncell;id++){
    gasIIdust(g[id].x[0],g[id].x[1],g[id].x[2],&gtd);

    for(iline=0;iline<m[s].nline;iline++){
      g[id].mol[s].knu[iline]=kappatab[iline]*2.4*AMU/gtd*g[id].dens[0];
      /* Check if input model supplies a dust temperature. Otherwise use the kinetic temperature. */
      if(g[id].t[1]==-1) {
        g[id].mol[s].dust[iline]=planckfunc(iline,g[id].t[0],m,s);
      } else {
        g[id].mol[s].dust[iline]=planckfunc(iline,g[id].t[1],m,s);
      }
    }
  }

  // fix the normalization at 230GHz
  for(iline=0;iline<m[s].nline;iline++){
    m[s].norm=planckfunc(0,par->tcmb,m,0);
    m[s].norminv=1./m[s].norm;
    if(par->tcmb>0.) m[s].cmb[iline]=planckfunc(iline,par->tcmb,m,s)/m[s].norm;
    else m[s].cmb[iline]=0.;
    m[s].local_cmb[iline]=planckfunc(iline,2.728,m,s)/m[s].norm;
  }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions