R/lineProf.R

Defines functions delta

## 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.
source("./R/useful.R")
source("./R/toolbox.R")

c <- useful[, "c"]
logC <- useful[, "logC"]
logK <- useful[, "logK"]
amu <- useful[, "amu"]
ln10 <- log(10)
ln2 <- log(2)
lnSqRtPi <- 0.5 * log(pi)
sqPi <- sqrt(pi)
logE <- log10(exp(1))


delta <- function(linePoints, lam0In, numDeps, tauRos, massIn, xiTIn, teff) {
  lam0 <- lam0In
  logLam0 <- log(lam0)

  logE <- log10(exp(1))

  # return a 2D numPoints x numDeps array of normalized line profile points (phi)

  lineProf <- vector("numeric", numDeps)
  logTeff <- log(teff)
  xiT <- xiTIn * 1.0E5
  logMass <- log(massIn * amu)

  # compute depth-independent Doppler width, Delta_lambda_D
  logHelp <- ln2 + logK + logTeff - logMass # M-B dist, square of v_mode
  help <- exp(logHelp) + xiT * xiT # quadratic sum of thermal v and turbulent v
  logHelp <- 0.5 * log(help)
  logDopp <- logHelp + logLam0 - logC
  doppler <- exp(logDopp)

  for (i in 1:numDeps) {
      # gaussian ONLY at line centre Lorentzian will diverge
      delta <- 1.0
      # convert from H(a,v) in dimensionless Voigt units to physical ph(Delta Lambda) profile
      logDelta <- log(delta) + 2.0 * logLam0 - lnSqRtPi - logDopp - logC
      lineProf[id][1] <- exp(logDelta0
  }

lineProf
}

gauss <- function(linePoints, lam0In, numDeps, teff, tauRos, temp, tempSun) {
  doppler <- linePoints[2][1] / linePoints[2][2]
  logDopp <- log(doppler)
  tiny <- 10E-19

  # set up a half-profile Delta_lambda grid in Doppler width units
  numPoints <- length(linePoints[1])

  # return a 2D numPoints x numDeps array of normalized line profile points (phi)
  lineProf <- matrix(0, numDeps, numPoints)
  v <- vector("numeric", numPoints)

  gauss <- tiny # default initialization

  for (id in 1:numDeps) {
      for (il in 1:numPoints) {
      	  v[il] <- linePoints[il][2]

	  if (v[il] <= 3.5 && v[il] >= -3.5) {
	     # gaussian ONLY - at line centre Lorentzian will diverge
	     core <- exp(-1.0 * (v[il] * v[il]))
	     gauss <- core 
	     }
	  # convert from H(a,v) in dimensionless Voigt units to physical phi(Delta Lambda) profile
	  logGauss <- log(gauss) + 2.0 * logLam0 - lnSqRtPi - logDopp - logC
	  linProf[id][il] <- exp(logGauss)
      	  }
      }

lineProf

}

voigt <- function(linePoints, lam0In, logAij, logGammaCol, numDeps, teff, tauRos, temp, pGas, tempSun, pGasSun, hjertComp, dbgHandle) {
  doppler <- linePoints[2][1] / linePoints[2][2]
  logDopp <- log(doppler)

  logGammaSun <- 9.0 * ln10 # convert to base e
  tau1 <- tauPoint(numDeps, tauRos, 1.0)
  numPoints <- length(linePoints[1])
  # return a 2D numPoints x numDeps array of normalized line profile points (phi)
  lineProf <- matrix(0, numDeps, numPoints)
  # line profile points in Doppler widths - needed for Voigt function, H(a,v)
  v <- vector("numeric", numPoints)
  Aij <- 10^logAij
  il0 <- 36

  for (id in 1:numDeps) {
    # formula from p. 56 of Radiative Transfer in Stellar Atmospheres (Rutten)
    # logarithmically with respect to solar value
    logGamma <- pGas[id][2] - pGasSun[tau1][2] + 0.7 * (tempSun[tau1][2] - temp[id][2]) + logGammaSun
    logGamma <- logGamma + logGammaCol
    gamma <- exp(logGamma) + Aij
    logGamma <- log(gamma)

    # Voigt "a" parameter with line centre wavelength
      lagA <- 2.0 * logLam0 + logGamma - ln4pi - logC - logDopp
      a <- exp(logA)
      
  }
}
increasechief/chromastar documentation built on May 14, 2019, 5:14 a.m.