-
Notifications
You must be signed in to change notification settings - Fork 1
/
tped.f90
114 lines (76 loc) · 3.19 KB
/
tped.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
!>
!! \brief This module contains routines having to do with the calculation of
!! temperature and electron density.
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: 2010-Mar-08 (but older)
!!
!! \b Doxygen \b note: This module contains "elemental" functions (i.e.
!! functions without side effects working on scalars). Doxygen does not
!! recognize these as functions, and therefore does not list them.
!!
!! The elemental functions in this module are:
!! - temper2pressr (calculates pressure from temperature, density and electron density).
!! - pressr2temper (calculates temperature from pressure, density and electron density).
!! - rho2n (calculates number density from mass density)
!! - n2rho (calculates mass density from number density)
!!
module tped
! This file contains routines having to do with the calculation of
! temperature and electron density.
! - temper2pressr : find temperature from pressure
! - pressr2temper : find pressure from temperature
! - electrondens: find electron density
use precision, only: dp
use cgsconstants, only: kb, m_p
use abundances, only: abu_c, mu
implicit none
contains
!=======================================================================
!> find temperature from pressure
elemental function temper2pressr (temper,ndens,eldens) result(pressr)
real(kind=dp),intent(in) :: ndens !< number density
real(kind=dp),intent(in) :: temper !< temperature
real(kind=dp),intent(in) :: eldens !< electron density
real(kind=dp) :: pressr !< pressure
pressr=(ndens+eldens)*kb*temper
!temper2pressr=pressr
end function temper2pressr
! =======================================================================
!> find pressure from temperature
elemental function pressr2temper (pressr,ndens,eldens) result(temper)
real(kind=dp),intent(in) :: pressr !< pressure
real(kind=dp),intent(in) :: ndens !< number density
real(kind=dp),intent(in) :: eldens !< electron density
real(kind=dp) :: temper !< temperature
temper=pressr/(kb*(ndens+eldens))
!pressr2temper=temper
end function pressr2temper
! =======================================================================
!> find electron density
function electrondens(ndens,xh)
real(kind=dp) :: electrondens
real(kind=dp),intent(in) :: ndens !< number density
real(kind=dp),intent(in) :: xh(0:1) !< H ionization fractions
electrondens=ndens*(xh(1)+abu_c)
end function electrondens
! =======================================================================
!> Find number density from mass density
elemental function rho2n(rho)
! Calculates number density from mass density
real(kind=dp) :: rho2n
real(kind=dp),intent(in) :: rho !< mass density
rho2n=rho/(mu*m_p)
end function rho2n
! =======================================================================
!> Find mass density from number density
elemental function n2rho(ndens)
! Calculates number density from mass density
real(kind=dp) :: n2rho
real(kind=dp),intent(in) :: ndens !< number density
n2rho=ndens*m_p*mu
end function n2rho
end module tped