-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadiativeTransfer.f
757 lines (654 loc) · 15.7 KB
/
RadiativeTransfer.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
subroutine RadiativeTransfer
use GlobalSetup
use Constants
IMPLICIT NONE
type(Photon),allocatable :: phot(:)
integer i,j,maxnopenmp,omp_get_max_threads,iopenmp,omp_get_thread_num
real*8 starttime,stoptime,starttime_w,omp_get_wtime,stoptime_w
maxnopenmp=omp_get_max_threads()+1
if(.not.use_multi) maxnopenmp=1
allocate(phot(maxnopenmp))
do i=1,maxnopenmp
allocate(phot(i)%i1(nzones))
allocate(phot(i)%i2(nzones))
allocate(phot(i)%i3(nzones))
allocate(phot(i)%inzone(nzones))
allocate(phot(i)%edgeNr(nzones))
allocate(phot(i)%KabsZ(nzones))
allocate(phot(i)%xzone(nzones))
allocate(phot(i)%yzone(nzones))
allocate(phot(i)%zzone(nzones))
allocate(phot(i)%vxzone(nzones))
allocate(phot(i)%vyzone(nzones))
allocate(phot(i)%vzzone(nzones))
enddo
call InitRadiativeTransfer
call output("==================================================================")
call output("Emitting " // trim(int2string(Nphot,'(i10)')) // " photon packages")
call cpu_time(starttime)
starttime_w=omp_get_wtime()
!$OMP PARALLEL IF(use_multi.and.rt_multi)
!$OMP& DEFAULT(NONE)
!$OMP& PRIVATE(i,iopenmp)
!$OMP& SHARED(Nphot,nzones,phot,starttime,starttime_w)
!$OMP DO SCHEDULE(STATIC,1)
do i=1,Nphot
c call tellertje(i,Nphot)
call tellertje_time(i,Nphot,starttime,starttime_w)
iopenmp=omp_get_thread_num()+1
phot(iopenmp)%nr=i
call EmitPhoton(phot(iopenmp))
call InWhichZones(phot(iopenmp))
call TravelPhoton(phot(iopenmp))
call MCoutput(phot(iopenmp))
enddo
!$OMP END DO
!$OMP FLUSH
!$OMP END PARALLEL
call cpu_time(stoptime)
stoptime_w=omp_get_wtime()
call output("Radiative transfer time: " // trim(dbl2string(stoptime-starttime,'(f10.3)')) // " s")
call output("Walltime: " // trim(dbl2string(stoptime_w-starttime_w,'(f10.3)')) // " s")
call DetermineTemperatures
return
end
subroutine InWhichZones(phot)
use GlobalSetup
IMPLICIT NONE
type(Photon) phot
real*8 r
integer i
do i=1,nzones
r=sqrt(phot%xzone(i)**2+phot%yzone(i)**2+phot%zzone(i)**2)
phot%inzone(i)=.false.
if(r.lt.Zone(i)%Rout.and.r.gt.Zone(i)%Rin) then
phot%inzone(i)=.true.
call determine_i1(phot,i)
if(Zone(i)%warped) call TranslatePhotonWarp(phot,i)
call determine_i2(phot,i)
call determine_i3(phot,i)
endif
enddo
return
end
subroutine TravelPhoton(phot)
use GlobalSetup
use Constants
IMPLICIT NONE
integer izone,imin,istar,status
logical leave,hitstar0
real*8 minv,tau0,tau,GetKext,random,GetKabs
type(Travel) Trac(nzones)
type(Travel) TracStar(nstars)
type(Cell),pointer :: C
type(Photon) phot
tau0=-log(random(idum))
if(rt_thin) tau0=1d200
do izone=1,nzones
Trac(izone)%recompute=.true.
enddo
do istar=1,nstars
TracStar(istar)%recompute=.true.
enddo
minv=0d0
1 continue
phot%Kext=0d0
phot%Kabs=0d0
do izone=1,nzones
phot%KabsZ(izone)=0d0
if(phot%inzone(izone)) then
C => Zone(izone)%C(phot%i1(izone),phot%i2(izone),phot%i3(izone))
phot%Kext=phot%Kext+GetKext(phot%ilam1,C)*phot%wl1+GetKext(phot%ilam2,C)*phot%wl2
phot%KabsZ(izone)=GetKabs(phot%ilam1,C)*phot%wl1+GetKabs(phot%ilam2,C)*phot%wl2
phot%Kabs=phot%Kabs+phot%KabsZ(izone)
endif
enddo
status=0
do izone=1,nzones
if(phot%inzone(izone)) then
select case(Zone(izone)%shape)
case("SPH")
c if(Trac(izone)%recompute) then
call TravelSph(phot,izone,Trac(izone),status)
c else
c Trac(izone)%v=Trac(izone)%v-minv
c endif
end select
Trac(izone)%recompute=.false.
else
select case(Zone(izone)%shape)
case("SPH")
c if(Trac(izone)%recompute) then
call HitSph(phot,izone,Trac(izone))
c else
c Trac(izone)%v=Trac(izone)%v-minv
c endif
end select
Trac(izone)%recompute=.false.
endif
enddo
do istar=1,nstars
c if(TracStar(istar)%recompute) then
call HitStar(phot,istar,TracStar(istar))
TracStar(istar)%recompute=.false.
c else
c TracStar(istar)%v=TracStar(istar)%v-minv
c endif
enddo
if(status.gt.0) then
call output("Something is wrong... Don't worry I'll try to fix it.")
nerrors=nerrors+1
if(nerrors.gt.100) stop
do izone=1,nzones
Trac(izone)%recompute=.true.
enddo
do istar=1,nstars
TracStar(istar)%recompute=.true.
enddo
minv=0d0
call InWhichZones(phot)
goto 1
endif
minv=20d0*maxR
leave=.true.
do izone=1,nzones
if(Trac(izone)%v.gt.0d0.and.Trac(izone)%v.lt.minv) then
minv=Trac(izone)%v
imin=izone
leave=.false.
endif
enddo
hitstar0=.false.
do istar=1,nstars
if(TracStar(istar)%v.gt.0d0.and.TracStar(istar)%v.lt.minv) then
minv=TracStar(istar)%v
imin=0
hitstar0=.true.
endif
enddo
if(leave) goto 3
if((tau0-phot%Kext*minv).lt.0d0) then
minv=tau0/phot%Kext
phot%edgeNr=0
call increaseColumn(phot,minv)
call TravelPhotonX(phot,minv)
call AddEtrace(phot,minv)
call Interact(phot)
do izone=1,nzones
Trac(izone)%recompute=.true.
enddo
do istar=1,nstars
TracStar(istar)%recompute=.true.
enddo
tau0=-log(random(idum))
if(random(idum).lt.fstop) then
phot%sI=0d0
phot%sQ=0d0
phot%sU=0d0
phot%sV=0d0
goto 3
endif
phot%sI=phot%sI/(1d0-fstop)
phot%sQ=phot%sQ/(1d0-fstop)
phot%sU=phot%sU/(1d0-fstop)
phot%sV=phot%sV/(1d0-fstop)
goto 1
endif
call increaseColumn(phot,minv)
call TravelPhotonX(phot,minv)
call AddEtrace(phot,minv)
tau0=tau0-phot%Kext*minv
if(hitstar0) then
phot%sI=0d0
phot%sQ=0d0
phot%sU=0d0
phot%sV=0d0
goto 3
endif
do izone=1,nzones
if(Trac(izone)%v.le.minv.or.izone.eq.imin) then
if(Zone(izone)%warped.and.phot%i1(izone).ne.Trac(izone)%i1next) then
phot%i1(izone)=Trac(izone)%i1next
call TranslatePhotonWarp(phot,izone)
phot%i2(izone)=-1
phot%i3(izone)=-1
else
phot%i1(izone)=Trac(izone)%i1next
phot%i2(izone)=Trac(izone)%i2next
phot%i3(izone)=Trac(izone)%i3next
endif
if(phot%i1(izone).eq.-1) call determine_i1(phot,izone)
if(phot%i2(izone).eq.-1) call determine_i2(phot,izone)
if(phot%i3(izone).eq.-1) call determine_i3(phot,izone)
phot%edgeNr(izone)=Trac(izone)%edgenext
phot%inzone(izone)=.true.
if(phot%i1(izone).gt.Zone(izone)%n1.or.
& phot%i2(izone).gt.Zone(izone)%n2.or.
& phot%i3(izone).gt.Zone(izone)%n3.or.
& phot%i1(izone).lt.1.or.
& phot%i2(izone).lt.1.or.
& phot%i3(izone).lt.1) then
phot%inzone(izone)=.false.
endif
Trac(izone)%recompute=.true.
else
phot%edgeNr(izone)=0
endif
enddo
goto 1
3 continue
return
end
subroutine increaseColumn(phot,v)
use GlobalSetup
IMPLICIT NONE
type(Photon) phot
real*8 v
integer izone,ipart,isize,iT
do izone=1,nzones
if(phot%inzone(izone)) then
do ipart=1,npart
do isize=1,Part(ipart)%nsize
do iT=1,Part(ipart)%nT
column(ipart,isize,iT)=column(ipart,isize,iT)
& +Zone(izone)%C(phot%i1(izone),phot%i2(izone),phot%i3(izone))%densP(ipart,isize,iT)*v
enddo
enddo
enddo
endif
enddo
return
end
subroutine AddEtrace(phot,v)
use GlobalSetup
IMPLICIT NONE
type(Photon) phot
integer izone
real*8 v,vI
do izone=1,nzones
if(phot%inzone(izone)) then
vI=v*phot%sI
Zone(izone)%C(phot%i1(izone),phot%i2(izone),phot%i3(izone))%Etrace=
& Zone(izone)%C(phot%i1(izone),phot%i2(izone),phot%i3(izone))%Etrace+
& vI*phot%KabsZ(izone)
endif
enddo
return
end
subroutine MCoutput(phot)
use GlobalSetup
use Constants
IMPLICIT NONE
real*8 inp,tot,x,y,z,ext(nlam),fact
integer i,j,ix,iy,ipart,isize,iT
logical doMCobs(nMCobs),doany
type(Photon) phot
doany=.false.
doMCobs=.false.
do i=1,nMCobs
inp=MCobs(i)%x*phot%vx+MCobs(i)%y*phot%vy+MCobs(i)%z*phot%vz
if(inp.gt.MCobs(i)%opening) then
doMCobs(i)=.true.
doany=.true.
endif
enddo
if(doany) then
ext=0d0
do ipart=1,npart
do isize=1,Part(ipart)%nsize
do iT=1,Part(ipart)%nT
do j=1,nlam
ext(j)=ext(j)+column(ipart,isize,iT)*Part(ipart)%Kext(isize,iT,j)
enddo
enddo
enddo
enddo
do j=1,nlam
if(ext(j).lt.1000d0) then
specemit(j)=specemit(j)*exp(-ext(j))
else
specemit(j)=0d0
endif
enddo
call integrate(specemit,tot)
if(tot.gt.1d-100) then
specemit=specemit/tot
else
doMCobs=.false.
endif
endif
!$OMP CRITICAL
do i=1,nMCobs
if(doMCobs(i)) then
fact=1d23*phot%sI/MCobs(i)%f
MCobs(i)%spec(1:nlam)=MCobs(i)%spec(1:nlam)+specemit(1:nlam)*fact
if(MCobs(i)%mcout) then
x=phot%x0
y=phot%y0
z=phot%z0
call rotateZ(x,y,z,MCobs(i)%cosp,-MCobs(i)%sinp)
call rotateY(x,y,z,MCobs(i)%cost,MCobs(i)%sint)
ix=real(MCobs(i)%npix)*(y+MCobs(i)%maxR)/(2d0*MCobs(i)%maxR)
iy=MCobs(i)%npix-real(MCobs(i)%npix)*(x+MCobs(i)%maxR)/(2d0*MCobs(i)%maxR)
if(ix.le.MCobs(i)%npix.and.iy.le.MCobs(i)%npix.and.ix.gt.0.and.iy.gt.0) then
MCobs(i)%image(ix,iy,1:nlam)=MCobs(i)%image(ix,iy,1:nlam)+specemit(1:nlam)*fact
endif
endif
endif
enddo
!$OMP END CRITICAL
return
end
subroutine EmitPhoton(phot)
use GlobalSetup
use Constants
IMPLICIT NONE
type(Photon) phot
integer i,izone
real*8 Ltot,r,random,x,y,z,theta,x0,y0,z0,fbeam,xn,yn,zn
fbeam=0.9d0
Ltot=0d0
do i=1,nstars
Ltot=Ltot+Star(i)%L*Star(i)%fL
enddo
r=Ltot*random(idum)
do i=1,nstars
r=r-Star(i)%L*Star(i)%fL
if(r.lt.0d0) exit
enddo
call randomdirection(phot%x,phot%y,phot%z)
phot%x=Star(i)%R*phot%x
phot%y=Star(i)%R*phot%y
phot%z=Star(i)%R*phot%z
call emit(phot,Star(i)%F,Star(i)%L)
phot%sI=Ltot/(real(Nphot)*Star(i)%fL)
phot%sQ=0d0
phot%sU=0d0
phot%sV=0d0
r=random(idum)
do izone=1,nzones
r=r-Zone(izone)%fbeamS(i)
if(r.lt.0d0) exit
enddo
if(izone.le.nzones) then
c beaming
x0=Zone(izone)%x0-Star(i)%x
y0=Zone(izone)%y0-Star(i)%y
z0=Zone(izone)%z0-Star(i)%z
r=sqrt(x0**2+y0**2+z0**2)
x0=x0/r
y0=y0/r
z0=z0/r
x=random(idum)
y=random(idum)
z=random(idum)
xn=y0*z-z0*y
yn=z0*x-x0*z
zn=x0*y-y0*x
r=sqrt(xn**2+yn**2+zn**2)
xn=xn/r
yn=yn/r
zn=zn/r
1 continue
if(random(idum).lt.fbeam) then
theta=acos(1d0-(1d0-Zone(izone)%ctbeamS(i))*random(idum))
phot%sI=phot%sI*Zone(izone)%EfbeamS(i)/fbeam
else
theta=acos(-1d0-(-1d0-Zone(izone)%ctbeamS(i))*random(idum))
phot%sI=phot%sI*(1d0-Zone(izone)%EfbeamS(i))/(1d0-fbeam)
endif
phot%vx=x0
phot%vy=y0
phot%vz=z0
call rotate(phot%vx,phot%vy,phot%vz,xn,yn,zn,theta)
theta=2d0*pi*random(idum)
call rotate(phot%vx,phot%vy,phot%vz,x0,y0,z0,theta)
if(phot%x*phot%vx+phot%y*phot%vy+phot%z*phot%vz.lt.0d0) then
call randomdirection(phot%x,phot%y,phot%z)
phot%x=Star(i)%R*phot%x
phot%y=Star(i)%R*phot%y
phot%z=Star(i)%R*phot%z
phot%sI=Ltot/real(Nphot)
goto 1
endif
else
if(phot%x*phot%vx+phot%y*phot%vy+phot%z*phot%vz.lt.0d0) then
phot%vx=-phot%vx
phot%vy=-phot%vy
phot%vz=-phot%vz
endif
endif
phot%x=phot%x+Star(i)%x
phot%y=phot%y+Star(i)%y
phot%z=phot%z+Star(i)%z
phot%edgeNr=0
phot%inzone=.false.
phot%x0=phot%x
phot%y0=phot%y
phot%z0=phot%z
call TranslatePhotonX(phot)
call TranslatePhotonV(phot)
return
end
subroutine InitRadiativetransfer
use GlobalSetup
IMPLICIT NONE
integer izone,i1,i2,i3,ilam,i
type(Cell),pointer :: C
real*8 GetKext
call output("Initializing radiative transfer")
nerrors=0
do izone=1,nzones
do i1=1,Zone(izone)%n1
do i2=1,Zone(izone)%n2
do i3=1,Zone(izone)%n3
C => Zone(izone)%C(i1,i2,i3)
C%E=0d0
C%Ni=0d0
C%T=0d0
C%Etrace=0d0
enddo
enddo
enddo
enddo
do i=1,nMCobs
MCobs(i)%spec=0d0
MCobs(i)%image=0d0
enddo
return
end
c This function gives the Planck mean opacity of the cell
real*8 function GetKp(iBB,C)
use GlobalSetup
IMPLICIT NONE
integer ipart,iT,isize,iBB
type(Cell) C
GetKp=0d0
do ipart=1,npart
do isize=1,Part(ipart)%nsize
do iT=1,Part(ipart)%nT
GetKp=GetKp+C%densP(ipart,isize,iT)*Part(ipart)%Kp(isize,iT,iBB)
enddo
enddo
enddo
return
end
c This function gives the absorption cross section per cm
real*8 function GetKabs(ilam,C)
use GlobalSetup
IMPLICIT NONE
integer ilam,ipart,iT,isize
type(Cell) C
GetKabs=0d0
do ipart=1,npart
do isize=1,Part(ipart)%nsize
do iT=1,Part(ipart)%nT
GetKabs=GetKabs+C%densP(ipart,isize,iT)*Part(ipart)%Kabs(isize,iT,ilam)
enddo
enddo
enddo
return
end
c This function gives the extinction cross section per cm
real*8 function GetKext(ilam,C)
use GlobalSetup
IMPLICIT NONE
integer ilam,ipart,iT,isize
type(Cell) C
GetKext=0d0
do ipart=1,npart
do isize=1,Part(ipart)%nsize
do iT=1,Part(ipart)%nT
GetKext=GetKext+C%densP(ipart,isize,iT)*Part(ipart)%Kext(isize,iT,ilam)
enddo
enddo
enddo
return
end
c This function gives the scattering cross section per cm
real*8 function GetKsca(ilam,C)
use GlobalSetup
IMPLICIT NONE
integer i1,i2,i3,ilam,ipart,iT,isize
type(Cell) C
GetKsca=0d0
do ipart=1,npart
do isize=1,Part(ipart)%nsize
do iT=1,Part(ipart)%nT
GetKsca=GetKsca+C%densP(ipart,isize,iT)*Part(ipart)%Ksca(isize,iT,ilam)
enddo
enddo
enddo
return
end
c This function gives the scattering cross section per cm in a certain angle
real*8 function GetF11(ilam,iscat,C)
use GlobalSetup
IMPLICIT NONE
integer i1,i2,i3,ilam,ipart,iT,isize,iscat
type(Mueller) F
type(Cell) C
GetF11=0d0
do ipart=1,npart
do isize=1,Part(ipart)%nsize
do iT=1,Part(ipart)%nT
GetF11=GetF11+C%densP(ipart,isize,iT)*
& Part(ipart)%Ksca(isize,iT,ilam)*Part(ipart)%F(isize,iT,ilam)%F11(iscat)
enddo
enddo
enddo
return
end
subroutine determine_i1(phot,izone)
use GlobalSetup
IMPLICIT NONE
integer i,izone
real*8 r2
type(Photon) phot
select case(Zone(izone)%shape)
case("SPH")
r2=phot%xzone(izone)**2+phot%yzone(izone)**2+phot%zzone(izone)**2
case("CYL")
r2=phot%xzone(izone)**2+phot%yzone(izone)**2
end select
do i=1,Zone(izone)%nr
if(r2.ge.Zone(izone)%R2(i).and.r2.le.Zone(izone)%R2(i+1)) exit
enddo
phot%i1(izone)=i
return
end
subroutine determine_i2(phot,izone)
use GlobalSetup
IMPLICIT NONE
integer i,izone
real*8 theta,r
type(Photon) phot
r=sqrt(phot%xzone(izone)**2+phot%yzone(izone)**2+phot%zzone(izone)**2)
theta=acos(phot%zzone(izone)/r)
do i=1,Zone(izone)%nt
if(theta.ge.Zone(izone)%theta(i).and.theta.le.Zone(izone)%theta(i+1)) exit
enddo
phot%i2(izone)=i
return
end
subroutine determine_i3(phot,izone)
use GlobalSetup
use Constants
IMPLICIT NONE
integer i,izone
real*8 phi,r
type(Photon) phot
r=sqrt(phot%xzone(izone)**2+phot%yzone(izone)**2)
phi=acos(phot%xzone(izone)/r)
if(phot%yzone(izone).lt.0d0) phi=2d0*pi-phi
do i=1,Zone(izone)%np
if(phi.ge.Zone(izone)%phi(i).and.phi.le.Zone(izone)%phi(i+1)) exit
enddo
if(i.gt.Zone(izone)%np) i=1
phot%i3(izone)=i
return
end
subroutine checkphot(phot)
use GlobalSetup
use Constants
IMPLICIT NONE
type(Photon) phot
integer i
real*8 r
logical oops
oops=.false.
do i=1,nzones
r=sqrt((phot%x-Zone(i)%x0)**2+(phot%y-Zone(i)%y0)**2+(phot%z-Zone(i)%z0)**2)
if(phot%inzone(i)) then
if(r.lt.Zone(i)%R(phot%i1(i))*0.99.or.
& r.gt.Zone(i)%R(phot%i1(i)+1)*1.01) then
print*,'zone',i,r/AU
print*,'oeps',phot%x/AU,phot%y/AU,phot%z/AU
print*,Zone(i)%R(phot%i1(i))/AU
print*,Zone(i)%R(phot%i1(i)+1)/AU
print*,phot%i1
print*,phot%inzone
oops=.true.
endif
else
if(r.gt.Zone(i)%R(1)*1.01.and.
& r.lt.Zone(i)%R(Zone(i)%nr+1)*0.99) then
print*,'zone',i,r/AU
c print*,'oeps',phot%x/AU,phot%y/AU,phot%z/AU
c print*,phot%i1
print*,phot%inzone
c oops=.true.
endif
endif
enddo
c if(oops) then
c stop
c endif
return
end
subroutine DetermineTemperatures
use GlobalSetup
IMPLICIT NONE
integer i1,i2,i3,izone
real*8 determineT
type(Cell),pointer :: C
do izone=1,nzones
!$OMP PARALLEL IF(use_multi)
!$OMP& DEFAULT(NONE)
!$OMP& PRIVATE(i1,i2,i3,C)
!$OMP& SHARED(Zone,izone)
!$OMP DO
do i1=1,Zone(izone)%n1
do i2=1,Zone(izone)%n2
do i3=1,Zone(izone)%n3
C=>Zone(izone)%C(i1,i2,i3)
C%T=determineT(C)
enddo
enddo
enddo
!$OMP END DO
!$OMP FLUSH
!$OMP END PARALLEL
enddo
return
end