Line data Source code
1 : ! ***********************************************************************
2 : !
3 : ! Copyright (C) 2021 The MESA Team
4 : !
5 : ! This program is free software: you can redistribute it and/or modify
6 : ! it under the terms of the GNU Lesser General Public License
7 : ! as published by the Free Software Foundation,
8 : ! either version 3 of the License, or (at your option) any later version.
9 : !
10 : ! This program is distributed in the hope that it will be useful,
11 : ! but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 : ! See the GNU Lesser General Public License for more details.
14 : !
15 : ! You should have received a copy of the GNU Lesser General Public License
16 : ! along with this program. If not, see <https://www.gnu.org/licenses/>.
17 : !
18 : ! ***********************************************************************
19 :
20 : module other_eos
21 :
22 : ! consult star/other/README for general usage instructions
23 : ! eos namelist option: use_other = .true.
24 : ! procedure pointers:
25 : ! s% eos_rq % other_eos_frac => my_other_eos_frac
26 : ! s% eos_rq % other_eos_component => my_other_eos_component
27 : ! s% eos_rq % other_eos_results => my_other_eos_results
28 :
29 : ! the subroutine other_eos_component allows you to provide an
30 : ! additional component eos. you must provide a complete set of
31 : ! eos results. this eos component has the highest priority in
32 : ! the blend.
33 :
34 : ! the subroutine other_eos_frac defines the region over which
35 : ! you want to use other_eos_component. you can use this to
36 : ! replace all or part of the MESA eos and control the location
37 : ! the eos blends associated with this component.
38 :
39 : ! the subroutine other_eos_results lets you modify the final
40 : ! results from the eos call right before they are returned.
41 : ! this allows you to make small modifications to the existing
42 : ! eos results without having to provide a full replacement eos.
43 :
44 : use const_def, only: dp
45 :
46 : implicit none
47 :
48 : contains
49 :
50 0 : subroutine null_other_eos_frac( &
51 : handle, &
52 : species, chem_id, net_iso, xa, &
53 : Rho, log10Rho, T, log10T, &
54 : frac, dfrac_dlogRho, dfrac_dlogT, ierr)
55 :
56 : ! INPUT
57 : use chem_def, only: num_chem_isos
58 :
59 : integer, intent(in) :: handle ! eos handle; from star, pass s% eos_handle
60 :
61 : integer, intent(in) :: species ! number of species
62 : integer, pointer :: chem_id(:) ! maps species to chem id
63 : ! index from 1 to species
64 : ! value is between 1 and num_chem_isos
65 : integer, pointer :: net_iso(:) ! maps chem id to species number
66 : ! index from 1 to num_chem_isos (defined in chem_def)
67 : ! value is 0 if the iso is not in the current net
68 : ! else is value between 1 and number of species in current net
69 : real(dp), intent(in) :: xa(:) ! mass fractions
70 :
71 : real(dp), intent(in) :: Rho, log10Rho ! the density
72 : real(dp), intent(in) :: T, log10T ! the temperature
73 :
74 : ! OUTPUT
75 : ! this routine must provide a fraction (in [0,1]) of the 'other' eos to use
76 : ! the remaining fraction (1-frac) will be provided by the standard MESA eos
77 : real(dp), intent(out) :: frac ! fraction of other_eos to use
78 : real(dp), intent(out) :: dfrac_dlogRho ! its partial derivative at constant T
79 : real(dp), intent(out) :: dfrac_dlogT ! its partial derivative at constant Rho
80 :
81 : integer, intent(out) :: ierr ! 0 means AOK.
82 :
83 : ! default implementation uses other_eos_component everywhere
84 0 : frac = 1d0
85 0 : dfrac_dlogRho = 0d0
86 0 : dfrac_dlogT = 0d0
87 :
88 0 : end subroutine null_other_eos_frac
89 :
90 :
91 0 : subroutine null_other_eos_component( &
92 : handle, &
93 : species, chem_id, net_iso, xa, &
94 : Rho, log10Rho, T, log10T, &
95 0 : res, d_dlnRho_const_T, d_dlnT_const_Rho, d_dxa_const_TRho, ierr)
96 :
97 : ! INPUT
98 0 : use chem_def, only: num_chem_isos
99 :
100 : integer, intent(in) :: handle ! eos handle; from star, pass s% eos_handle
101 :
102 : integer, intent(in) :: species ! number of species
103 : integer, pointer :: chem_id(:) ! maps species to chem id
104 : ! index from 1 to species
105 : ! value is between 1 and num_chem_isos
106 : integer, pointer :: net_iso(:) ! maps chem id to species number
107 : ! index from 1 to num_chem_isos (defined in chem_def)
108 : ! value is 0 if the iso is not in the current net
109 : ! else is value between 1 and number of species in current net
110 : real(dp), intent(in) :: xa(:) ! mass fractions
111 :
112 : real(dp), intent(in) :: Rho, log10Rho ! the density
113 : real(dp), intent(in) :: T, log10T ! the temperature
114 :
115 : ! OUTPUT
116 :
117 : real(dp), intent(inout) :: res(:) ! (num_eos_basic_results)
118 : ! partial derivatives of the basic results wrt lnd and lnT
119 : real(dp), intent(inout) :: d_dlnRho_const_T(:) ! (num_eos_basic_results)
120 : ! d_dlnRho(i) = d(res(i))/dlnd|T
121 : real(dp), intent(inout) :: d_dlnT_const_Rho(:) ! (num_eos_basic_results)
122 : ! d_dlnT(i) = d(res(i))/dlnT|Rho
123 : real(dp), intent(inout) :: d_dxa_const_TRho(:,:) ! (num_eos_basic_results, species)
124 : ! d_dxa(i,j) = d(res(i))/dxa(j)|T,Rho
125 :
126 : integer, intent(out) :: ierr ! 0 means AOK.
127 :
128 0 : res = 0
129 0 : d_dlnRho_const_T = 0
130 0 : d_dlnT_const_Rho = 0
131 0 : d_dxa_const_TRho = 0
132 :
133 0 : write(*,*) 'no implementation for other_eos'
134 0 : ierr = -1
135 :
136 0 : end subroutine null_other_eos_component
137 :
138 :
139 0 : subroutine null_other_eos_results( &
140 : handle, &
141 : species, chem_id, net_iso, xa, &
142 : Rho, log10Rho, T, log10T, &
143 : res, d_dlnRho_const_T, d_dlnT_const_Rho, d_dxa_const_TRho, ierr)
144 :
145 : ! INPUT
146 0 : use chem_def, only: num_chem_isos
147 :
148 : integer, intent(in) :: handle ! eos handle; from star, pass s% eos_handle
149 :
150 : integer, intent(in) :: species ! number of species
151 : integer, pointer :: chem_id(:) ! maps species to chem id
152 : ! index from 1 to species
153 : ! value is between 1 and num_chem_isos
154 : integer, pointer :: net_iso(:) ! maps chem id to species number
155 : ! index from 1 to num_chem_isos (defined in chem_def)
156 : ! value is 0 if the iso is not in the current net
157 : ! else is value between 1 and number of species in current net
158 : real(dp), intent(in) :: xa(:) ! mass fractions
159 :
160 : real(dp), intent(in) :: Rho, log10Rho ! the density
161 : real(dp), intent(in) :: T, log10T ! the temperature
162 :
163 : ! OUTPUT
164 :
165 : real(dp), intent(inout) :: res(:) ! (num_eos_basic_results)
166 : ! partial derivatives of the basic results wrt lnd and lnT
167 : real(dp), intent(inout) :: d_dlnRho_const_T(:) ! (num_eos_basic_results)
168 : ! d_dlnRho(i) = d(res(i))/dlnd|T
169 : real(dp), intent(inout) :: d_dlnT_const_Rho(:) ! (num_eos_basic_results)
170 : ! d_dlnT(i) = d(res(i))/dlnT|Rho
171 : real(dp), intent(inout) :: d_dxa_const_TRho(:,:) ! (num_eos_basic_results, species)
172 : ! d_dxa(i,j) = d(res(i))/dxa(j)|T,Rho
173 :
174 : integer, intent(out) :: ierr ! 0 means AOK.
175 :
176 : ! default implementation does not modify results
177 :
178 0 : end subroutine null_other_eos_results
179 :
180 :
181 : end module other_eos
|