R/kappasRayL.R

Defines functions masterRayl opacHscat opacHescat

## MIT License
##
## Copyright (c) 2018 Oliver Dechant
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions {
##
## The above copyright notice and this permission notice shall be included in all
## copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.

#Rayleigh scattering opacity routines taken from Moog
#Chris Sneden (University of Texas at Austin) and collaborators
#http://www.as.utexas.edu/~chris/moog.html
#source: Opacscat.f

masterRayl <- function(numDeps, numLams, temp, lambdaScale, stagePops, molPops) {
  #This subroutine calculates the opacities from scattering by H I, H2, He I
  #from ATLAS9

  #From Moog source file Opacitymetals.f
  logE <- log10(exp(1))

  masterRScat <- matrix(0.0, numDeps, numLams)

  logUH1 <- logUHe1 <- rep("numeric", 5)
  logGroundPopsH1 <- logGroundPopsHe1 <- rep("numeric", numDeps)
  sigH1 <- sigHe1 <- rep("numeric", numDeps)
  logStatWH1 <- logStatWHe1 <- 0.0

  theta <- 1.0

  species <- "HI"
  logUH1 <- getPartFn2(species)
  species <- "HeI"
  logUHe1 <- getPartFn2(species)

  for (iD in 1:numDeps) {
    thisTemp <- temp[iD,1]
    if (thisTemp <= 130) {
      logStatWH1 <- logUH1[1]
      logStatWHe1 <- logUHe1[1]
    } else if (thisTemp > 130 && thisTemp <= 500) {
        logStatWH1 <- logUH1[2] * (thisTemp - 130)/(500 - 130)
        + logUH1[1] * (500 - thisTemp)/(500 - 130)
        logStatWHe1 <- logUHe1[2] * (thisTemp - 130)/(500 - 130)
        + logUHe1[1] * (500 - thisTemp)/(500 - 130)
    } else if (thisTemp > 500 && thisTemp <= 3000) {
        logStatWH1 <- logUH1[3] * (thisTemp - 500)/(3000 - 500)
        + logUH1[2] * (3000 - thisTemp)/(3000 - 500)
        logStatWHe1 <- logUHe1[3] * (thisTemp - 500)/(3000 - 500)
        + logUHe1[2] * (3000 - thisTemp)/(3000 - 500)
    } else if (thisTemp > 3000 && thisTemp <= 8000) {
        logStatWH1 <- logUH1[4] * (thisTemp - 3000)/(8000 - 3000)
        + logUH1[3] * (8000 - thisTemp)/(8000 - 3000)
        logStatWHe1 <- logUHe1[4] * (thisTemp - 3000)/(8000 - 3000)
        + logUHe1[3] * (8000 - thisTemp)/(8000 - 3000)
    } else if (thisTemp > 8000 && thisTemp < 10000) {
        logStatWH1 <- logUH1[5] * (thisTemp - 8000)/(10000 - 8000)
        + logUH1[4] * (10000 - thisTemp)/(10000 - 8000)
        logStatWHe1 <- logUHe1[5] * (thisTemp - 8000)/(10000 - 8000)
        + logUHe1[4] * (10000 - thisTemp)/(10000 - 8000)
    } else {
      #for temperatures of greater than or equal to 10000K
      logStatWH1 <- logUH1[5]
      logStatWHe1 <- logUHe1[5]
    }
    logGroundPopsH1[iD] <- stagePops[iD,1,1] - logStatWH1
    logGroundPopsHe1[iD] <- stagePops[iD,2,1] - logStatWHe1

    kapRScat <- 0.0

    for (iL in 1:numLams) {
      for (i in 1:numDeps) {
        sigH1[i] <- 0.0
        sigHe1[i] <- 0.0
      }
      sigH1 <- opacHscat(numDeps, temp, lambdaScale[iL], logGroundPopsH1)
      sigHe1 <- opacHescat(numDeps, temp, lambdaScale[iL], logGroundPopsHe1)

      for (iD in 1:numDeps) {
        kapRScat <- sigH1[iD]+sigHe1[iD]
        masterRScat[iD,iL] <- log(kapRScat)
      }
    }
  }

  masterRScat
}

opacHscat <- function(numDeps, temp, lambda2, logGroundPops) {
  #This routine computes H I Rayleigh scattering opacities
  sigH <- rep("numeric", numDeps)

  source("./data/useful.rds")
  freq <- useful[,"c"]/lambda2
  wavetemp <- 2.997925E18/min(freq,2.463E15)
  ww <- wavetemp**2
  sig <- (5.799E-13+(1.422E-6/ww)+(2.784/(ww*ww)))/(ww*ww)

  for (i in 1:numDeps) {
    sigH[i] <- sig*2.0*exp(logGroundPops[i])
  }

  sigH
}

opacHescat <- function(numDeps, temp, lambda2, logGroundPops) {
  #This routine computes H I Rayleigh scattering opacities
  sigHe <- rep("numeric", numDeps)

  source("./data/useful.rds")
  freq <- useful[,"c"]/lambda2
  wavetemp <- 2.997925E18/min(freq,5.15E15)
  ww <- wavetemp**2
  sig <- (5.484E-14/ww/ww)*((1.)+((2.44E5+(5.94E10/(ww-2.90E5)))/ww)**2)

  for (i in 1:numDeps) {
    sigHe[i] <- sig*2.0*exp(logGroundPops[i])
  }

  sigHe
}
increasechief/chromastar documentation built on May 14, 2019, 5:14 a.m.