forked from lanl/SuperNu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
groupmod.f
298 lines (298 loc) · 8.85 KB
/
groupmod.f
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
* © 2023. Triad National Security, LLC. All rights reserved.
* This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos National
* Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S. Department of
* Energy/National Nuclear Security Administration. All rights in the program are reserved by Triad
* National Security, LLC, and the U.S. Department of Energy/National Nuclear Security Administration.
* The Government is granted for itself and others acting on its behalf a nonexclusive, paid-up,
* irrevocable worldwide license in this material to reproduce, prepare. derivative works, distribute
* copies to the public, perform publicly and display publicly, and to permit others to do so.
*This file is part of SuperNu. SuperNu is released under the terms of the GNU GPLv3, see COPYING.
*Copyright (c) 2013-2022 Ryan T. Wollaeger and Daniel R. van Rossum. All rights reserved.
module groupmod
implicit none
c
c-- wavelength grid (gridmod has a copy as well)
integer,target :: grp_ng,grp_ngs
real*8 :: grp_wlmin,grp_wlmax
real*8,allocatable :: grp_wl(:) !(grp_ng) wavelength grid
real*8,allocatable :: grp_wlinv(:) !(grp_ng) wavelength grid
c
type grp_t_cache
integer :: ic=0
integer :: nlump !number of groups in the lump
real*8 :: capgreyinv
real*8 :: speclump,emitlump,caplump,doplump
real*8,pointer :: specarr(:) !(grp_ng)
integer :: istat
integer*2,pointer :: glumps(:) !(grp_ng)
logical*2,pointer :: llumps(:) !(grp_ng) this group belongs to the lump
end type grp_t_cache
c
save
c
contains
c
c
subroutine groupmod_init(wldex)
c -------------------------------!{{{
implicit none
integer,intent(in) :: wldex
************************************************************************
* setup wavelength grid
************************************************************************
integer :: ig
c
c-- verify data range
if(grp_ng>2**15-1) stop 'groupmod_init: grp_ng > 2^15. '//
& 'Increase glumps int*2 data range'
c
c-- read wavelength grid from file
if(grp_ng==0) then
call read_wlgrid(wldex,grp_ng)
else
allocate(grp_wl(grp_ng+1))
forall(ig=1:grp_ng+1) grp_wl(ig) =
& grp_wlmin*(grp_wlmax/dble(grp_wlmin))**((ig-1d0)/grp_ng)
endif
c
allocate(grp_wlinv(grp_ng+1))
grp_wlinv = 1d0/grp_wl
c
contains
c
subroutine read_wlgrid(wldex,ng)
c --------------------------------!{{{
implicit none
integer,intent(in) :: wldex
integer,intent(out) :: ng
************************************************************************
* read wavelength grid from file
*
* EXAMPLE FILE LAYOUT:
* --------------------
* #wavelength bin boundaries. units: [cm]
* #ncell ngroupmax
* #icell ngroup wlbound
* 10 5
* 1 1 1e-5 32e-5
* 2 5 1e-5 2e-5 4e-5 8e-5 16e-5 32e-5
*
************************************************************************
real*8 :: help
real*8,allocatable :: wlstore(:)
integer :: ngm,nrm,irr,l,ig
c
open(4,file='input.wlgrid',status='old')
c
c-- strip header
do l=1,3
read(4,*)
enddo
c-- read dimensions
read(4,*) nrm,ngm !not used
c
do l=1,wldex-1
read(4,*)
enddo
read(4,*) irr, ng
c
allocate(grp_wl(ng+1))
allocate(wlstore(ng+3))
rewind(4)
do l=1,wldex+3
read(4,*)
enddo
read(4,*) wlstore(:)
close(4)
grp_wl = wlstore(3:)
deallocate(wlstore)
c
c-- check monotonicity
help = 0d0
do ig=1,ng+1
if(grp_wl(ig)<=help) stop 'read_wlgrid: wlgrid not increasing'
help = grp_wl(ig)
enddo
c
write(6,*)
write(6,*) 'read_wlgrid: ng=',ng
! write(6,*) 'wavelength grid in [cm]'
! write(6,*) grp_wl
c!}}}
end subroutine read_wlgrid
c!}}}
end subroutine groupmod_init
c
c
elemental function specint0(tempinv,ig)
c ---------------------------------------!{{{
use physconstmod
implicit none
real*8 :: specint0
real*8,intent(in) :: tempinv
integer,intent(in) :: ig
************************************************************************
* Calculate x**3/(exp(x) - 1), where x = h*c/(wl*k*T)
************************************************************************
real*8,parameter :: ftpi4=15d0/pc_pi**4
real*8,parameter :: hck=pc_h*pc_c/pc_kb
real*8 :: x,dx
c
x = hck*tempinv
dx = x*abs(grp_wlinv(ig+1) - grp_wlinv(ig))
x = x*.5d0*(grp_wlinv(ig+1) + grp_wlinv(ig))
c
specint0 = ftpi4 * dx * x**3/(exp(x) - 1d0)
c!}}}
end function specint0
c
c
elemental function dopspeccalc(tempinv,ig)
c ---------------------------------------!{{{
use physconstmod
implicit none
real*8 :: dopspeccalc
real*8,intent(in) :: tempinv
integer,intent(in) :: ig
************************************************************************
* Calculate x**3/(exp(x) - 1), where x = h*c/(wl*k*T)
************************************************************************
real*8,parameter :: ftpi4=15d0/pc_pi**4
real*8,parameter :: hck=pc_h*pc_c/pc_kb
real*8 :: x
c
x = hck*tempinv
x = x*grp_wlinv(ig+1)
c
dopspeccalc = ftpi4 * x**4/(exp(x) - 1d0)
c!}}}
end function dopspeccalc
c
c
pure subroutine specintv(tempinv,n,ss,offset,mode,mask,maskval)
c -----------------------------------------------!{{{
use physconstmod
implicit none
real*8,intent(in) :: tempinv
integer,intent(in) :: n
real*8,intent(out) :: ss(n)
integer,intent(in),optional :: offset
integer,intent(in),optional :: mode
logical*2,intent(in),optional :: mask(n)
logical,intent(in),optional :: maskval
************************************************************************
* Integrate normalized Planck spectrum using Newton-Cotes formulae of
* different degrees.
************************************************************************
real*8,parameter :: ftpi4=15d0/pc_pi**4
real*8,parameter :: hck=pc_h*pc_c/pc_kb
real*8,parameter :: one6th=ftpi4/6d0
real*8,parameter :: one90th=ftpi4/90d0
real*8,parameter :: onehalf=ftpi4/2d0
real*8,parameter :: one=ftpi4
real*8 :: xarr(n+1)
real*8 :: farr(n+1)
real*8 :: f2arr(n)
integer :: imode,ioff
c
c-- defaults
ioff = 1
if(present(offset)) ioff = offset
imode = 0
if(present(mode)) imode = mode
c
c-- sanity check
if(ioff+n>grp_ng+1 .or. present(mask).neqv.present(maskval)) then
ss = -1d0
return
endif
c
c-- x
xarr = hck*tempinv*grp_wlinv(ioff:ioff+n)
c
select case(imode)
c-- constant
case(0)
if(present(mask)) then
where(mask.eqv.maskval)
ss = one*abs(xarr(2:)-xarr(:n)) *
& f(.5d0*(xarr(2:)+xarr(:n)))
endwhere
else
ss = one*abs(xarr(2:)-xarr(:n)) *
& f(.5d0*(xarr(2:)+xarr(:n)))
endif
c
c-- linear
case(1)
if(present(mask)) then
where(mask.eqv.maskval)
farr = f(xarr) !edge values
ss = onehalf*abs(xarr(2:)-xarr(:n)) *
& (farr(2:)+farr(:n))
endwhere
else
farr = f(xarr) !edge values
ss = onehalf*abs(xarr(2:)-xarr(:n)) *
& (farr(2:)+farr(:n))
endif
c
c-- quadratic
case(2)
if(present(mask)) then
where(mask.eqv.maskval)
farr = f(xarr) !edge values
f2arr = f(.5d0*(xarr(2:) + xarr(:n))) !midpoints
c-- simpson's rule
ss = one6th*abs(xarr(2:)-xarr(:n)) *
& (farr(2:) + farr(:n) + 4d0*f2arr)
endwhere
else
farr = f(xarr) !edge values
f2arr = f(.5d0*(xarr(2:) + xarr(:n))) !midpoints
c-- simpson's rule
ss = one6th*abs(xarr(2:)-xarr(:n)) *
& (farr(2:) + farr(:n) + 4d0*f2arr)
endif
c
c-- cubic
case(11)
if(present(mask)) then
where(mask.eqv.maskval)
farr = f(xarr) !edge values
c-- quarter points
f2arr = 12d0*f(.5d0*(xarr(2:) + xarr(:n))) + 32d0*(
& f(.25d0*xarr(2:) + .75d0*xarr(:n)) +
& f(.75d0*xarr(2:) + .25d0*xarr(:n)))
c-- Boole's rule
ss = one90th*abs(xarr(2:)-xarr(:n)) *
& (7d0*(farr(2:) + farr(:n)) + f2arr)
endwhere
else
farr = f(xarr) !edge values
c-- quarter points
f2arr = 12d0*f(.5d0*(xarr(2:) + xarr(:n))) + 32d0*(
& f(.25d0*xarr(2:) + .75d0*xarr(:n)) +
& f(.75d0*xarr(2:) + .25d0*xarr(:n)))
c-- Boole's rule
ss = one90th*abs(xarr(2:)-xarr(:n)) *
& (7d0*(farr(2:) + farr(:n)) + f2arr)
endif
c
c-- invalid
case default
ss = -1d0
endselect
c
contains
c
elemental real*8 function f(x)
real*8,intent(in) :: x
f = x**3/(exp(x) - 1d0)
end function
c!}}}
end subroutine specintv
c
c
end module groupmod
c vim: fdm=marker