-
Notifications
You must be signed in to change notification settings - Fork 0
/
moddump_collision_radialvelocity.f90
786 lines (680 loc) · 22.1 KB
/
moddump_collision_radialvelocity.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
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
!--------------------------------------------------------------------------!
! The Phantom Smoothed Particle Hydrodynamics code, by Daniel Price et al. !
! Copyright (c) 2007-2022 The Authors (see AUTHORS) !
! See LICENCE file for usage and distribution conditions !
! http://phantomsph.bitbucket.io/ !
!--------------------------------------------------------------------------!
module moddump
!
! Input is a relaxed star, output is two relaxed stars in binary orbit
!
! :References: None
!
! :Owner: Terrence Tricco
!
! :Runtime parameters: None
!
! :Dependencies: centreofmass, checkconserved, dim, extern_gwinspiral,
! externalforces, io, options, part, physcon, prompting, readwrite_dumps,
! timestep, units
!
implicit none
contains
subroutine modify_dump(npart,npartoftype,massoftype,xyzh,vxyzu)
use part, only:nptmass,xyzmh_ptmass,vxyz_ptmass,igas,set_particle_type,igas,mhd
use prompting, only:prompt
use centreofmass, only:reset_centreofmass,get_centreofmass
use physcon, only:c
use units, only:unit_velocity
use timestep, only:tmax,dtmax
use checkconserved, only:get_conserv
use options, only:iexternalforce
use externalforces, only:iext_gwinspiral
integer, intent(inout) :: npart
integer, intent(inout) :: npartoftype(:)
real, intent(inout) :: massoftype(:)
real, intent(inout) :: xyzh(:,:),vxyzu(:,:)
integer :: opt, synchro, Nstar1, Nstar2, nx
real :: sep,mtot,angvel,vel1,vel2,vcoll
real :: xcom(3), vcom(3), x1com(3), v1com(3), x2com(3), v2com(3)
real :: pmassi,m1,m2,rad1,rad2
real :: tmax0,fac,omega_inner,omega_outer
logical :: add_gw,add_v
!
! Option selection
!
print *, 'Running moddump_binarystar:'
print *, ''
print *, 'This utility sets two stars in binary orbit around each other, or modifies an existing binary.'
print *, ''
print *, 'Options:'
print *, ' 1) Duplicate a relaxed star'
print *, ' 2) Add a star from another dumpfile'
! print *, ' 3) Adjust separation of existing binary'
! print *, ' 4) Add magnetic field'
! print *, ' 5) Add gravitational waves'
! print *, ' 6) Add radial pulsation'
! print *, ' 7) Add rotational velocity pulsation'
vcoll = 1.
opt = 1
synchro = 0
add_gw = .false.
add_v = .false.
call prompt('Choice',opt, 1, 7)
!
! Add gravitational waves
!
if (opt == 5) then
add_gw = .true.
iexternalforce = iext_gwinspiral
print*, 'This option requires creating a binary system. How would you like to create the second star?'
print*, 'Pick option 1 or 2 from above'
opt = 1
! Then create binary
call prompt('Choice',opt, 1, 2)
endif
!
! Add radial or rotational velocity pulsations
!
if (opt == 6 .or. opt == 7) then
add_v = .true.
call reset_velocity(npart,vxyzu)
if (opt == 6) then
fac = 0.2
call prompt('Enter fac, where v_r = fac*r:',fac,0.)
call add_vradial(npart,xyzh,vxyzu,fac)
endif
if (opt == 7) then
omega_inner = 0.025
omega_outer = 0.014
call prompt('Enter angular velocity at center: ',omega_inner)
call prompt('Enter angular velocity at surface:',omega_outer)
call add_vrotational(npart,xyzh,vxyzu,omega_inner,omega_outer)
endif
print*, 'Would you like to create the second star?'
print*, 'Pick option 1 or 2 from above, or 0 for no additional star'
opt = 0
! Then create binary
call prompt('Choice',opt, 0, 2)
endif
if (opt == 1 .or. opt == 2 .or. opt == 3) then
sep = 1.0
if (add_gw) sep = 50.0
print *, ''
call prompt('Enter radial separation between stars (code unit)', sep, 0.)
endif
!
! Create binary
!
if (opt == 1) then
call duplicate_star(npart, npartoftype, xyzh, vxyzu, Nstar1, Nstar2)
endif
if (opt == 2) then
call add_star(npart, npartoftype, xyzh, vxyzu, Nstar1, Nstar2)
endif
if (opt == 3) then
call determine_Nstar(npart,xyzh,Nstar1,Nstar2)
endif
if (opt == 4) then
print *, ''
if (mhd) then
print *, 'Adding/resetting magnetic fields'
else
print *, 'ERROR: To add magnetic field, compile with MHD=yes.'
endif
print *, ''
endif
! This is turned off.
! To get a sufficiently low resolution background requires ~10^9 particles in each star. Not realistic.
if (.false.) then
nx = 128
call prompt('Specify number of particles in x-direction for low-density background',nx,0)
print *, ''
call determine_Nstar(npart,xyzh,Nstar1,Nstar2)
call get_centreofmass(xcom, vcom, npart, xyzh, vxyzu)
call get_centreofmass(x1com, v1com, Nstar1, xyzh(:,1:Nstar1), vxyzu(:,1:Nstar1))
call get_centreofmass(x2com, v2com, Nstar2, xyzh(:,Nstar1+1:npart), vxyzu(:,Nstar1+1:npart))
! call add_background(npart,npartoftype,massoftype,xyzh,vxyzu,Nstar1,Nstar2,x1com,x2com,nx)
endif
! Only if duplicating, adding, or adjusting separation
if (opt == 1 .or. opt == 2 .or. opt == 3) then
call prompt('Enter collision velocity in units of earth escape velocity', vcoll, 0.)
! get com of each star
call get_centreofmass(xcom, vcom, npart, xyzh, vxyzu)
call get_centreofmass(x1com, v1com, Nstar1, xyzh(:,1:Nstar1), vxyzu(:,1:Nstar1))
call get_centreofmass(x2com, v2com, Nstar2, xyzh(:,Nstar1+1:npart), vxyzu(:,Nstar1+1:npart))
! calculate radii of each star
call get_radii(npart,xyzh,Nstar1,Nstar2,x1com,x2com,rad1,rad2)
pmassi = massoftype(igas)
mtot = npart * pmassi
m1 = Nstar1 * pmassi
m2 = Nstar2 * pmassi
print *, ' Mass of first star: ', m1
print *, ' Mass of second star: ', m2
print *, ''
print *, ' Radius of first star: ', rad1
print *, ' Radius of second star: ', rad2
print *, ''
! adjust the separation of the binary
call adjust_sep(npart,xyzh,vxyzu,Nstar1,Nstar2,sep,x1com,v1com,x2com,v2com)
angvel = sqrt(1.0 * mtot / sep**3) ! angular velocity
vel1 = m1 * sep / mtot * angvel
vel2 = m2 * sep / mtot * angvel
! find new com's
call get_centreofmass(x1com, v1com, Nstar1, xyzh(:,1:Nstar1), vxyzu(:,1:Nstar1))
call get_centreofmass(x2com, v2com, Nstar2, xyzh(:,Nstar1+1:npart), vxyzu(:,Nstar1+1:npart))
! set orbital velocity of the binary
if (.not. add_v) call reset_velocity(npart,vxyzu)
print *, ' Collision velocity in Earth escape velocity units: ', vcoll
call set_velocity_coll(npart,vxyzu,Nstar1,Nstar2,angvel,vcoll)
!call set_corotate_velocity(angvel)
! synchronise rotation
! reset centre of mass to origin
call reset_centreofmass(npart,xyzh,vxyzu,nptmass,xyzmh_ptmass,vxyz_ptmass)
! reset tracked conservation properties
get_conserv = 1.
endif
! These are additional variables required for the gravitational wave study
if (add_gw) then
tmax0 = 5./256.*(c/unit_velocity)**5*sep**4/(m1*m2*(m1+m2))
dtmax = tmax0/tmax*dtmax
tmax = 2.0*tmax0
call save_nstar(Nstar1,Nstar2)
endif
end subroutine modify_dump
!
! Take the star from the input file and duplicate it some distance apart.
! This assumes the dump file only has one star.
!
subroutine duplicate_star(npart,npartoftype,xyzh,vxyzu,Nstar1,Nstar2)
use part, only: igas,set_particle_type,copy_particle
integer, intent(inout) :: npart
integer, intent(inout) :: npartoftype(:)
real, intent(inout) :: xyzh(:,:),vxyzu(:,:)
integer, intent(out) :: Nstar1, Nstar2
integer :: i
real :: sep
print *, 'Duplicating star'
print *, ''
npart = npartoftype(igas)
sep = 10.0
! duplicate relaxed star
do i = npart+1, 2*npart
! copy all particle properties
call copy_particle(i-npart,i,.true.)
! place star a distance rad away
xyzh(1,i) = xyzh(1,i-npart) + sep
xyzh(2,i) = xyzh(2,i-npart)
xyzh(3,i) = xyzh(3,i-npart)
xyzh(4,i) = xyzh(4,i-npart)
vxyzu(1,i) = vxyzu(1,i-npart)
vxyzu(2,i) = vxyzu(2,i-npart)
vxyzu(3,i) = vxyzu(3,i-npart)
vxyzu(4,i) = vxyzu(4,i-npart)
enddo
Nstar1 = npart
Nstar2 = npart
npart = 2 * npart
npartoftype(igas) = npart
end subroutine duplicate_star
!
! Place a star that is read from another dumpfile
!
subroutine add_star(npart,npartoftype,xyzh,vxyzu,Nstar1,Nstar2)
use part, only: igas,set_particle_type,eos_vars,alphaind,maxeosvars
use prompting, only: prompt
use dim, only: maxp,maxvxyzu,nalpha,maxalpha
use readwrite_dumps, only: read_dump
use io, only: idisk1,iprint
integer, intent(inout) :: npart
integer, intent(inout) :: npartoftype(:)
real, intent(inout) :: xyzh(:,:),vxyzu(:,:)
integer, intent(out) :: Nstar1, Nstar2
character(len=120) :: fn
real, allocatable :: xyzh2(:,:)
real, allocatable :: vxyzu2(:,:)
real, allocatable :: eos_vars2(:,:)
real, allocatable :: alphaind2(:,:)
integer :: i,ierr
real :: time2,hfact2,sep
print *, 'Adding a new star read from another dumpfile'
print *, 'WARNING: This subroutine is DANGEROUS and may not save all particle properties'
print *,' It needs a re-write...'
! DJP: the problem with this routine is that it saves only some of the arrays
! To save all particle properties the only way is to use the "copy_particles" routine
! to copy particles into a temporary buffer
fn = ''
call prompt('Name of second dumpfile',fn)
! read_dump will overwrite the current particles, so store them in a temporary array
allocate(xyzh2(4,maxp),stat=ierr) ! positions + smoothing length
if (ierr /= 0) stop ' error allocating memory to store positions'
allocate(vxyzu2(maxvxyzu,maxp),stat=ierr) ! velocity + thermal energy
if (ierr /= 0) stop ' error allocating memory to store velocity'
allocate(eos_vars2(maxeosvars,maxp),stat=ierr) ! temperature
if (ierr /= 0) stop ' error allocating memory to store temperature'
if (maxalpha == maxp) then ! artificial viscosity alpha
allocate(alphaind2(nalpha,maxp),stat=ierr)
if (ierr /= 0) stop ' error allocating memory to store alphaind'
endif
Nstar2 = npart
xyzh2 = xyzh
vxyzu2 = vxyzu
eos_vars2 = eos_vars
if (maxalpha == maxp) then
alphaind2 = alphaind
endif
! read second dump file
call read_dump(trim(fn),time2,hfact2,idisk1+1,iprint,0,1,ierr)
if (ierr /= 0) stop 'error reading second dumpfile'
Nstar1 = npart
sep = 10.0
! insert saved star (from original dump file)
do i = npart+1, npart+Nstar2
! place star a distance rad away
xyzh(1,i) = xyzh2(1,i-npart) + sep
xyzh(2,i) = xyzh2(2,i-npart)
xyzh(3,i) = xyzh2(3,i-npart)
xyzh(4,i) = xyzh2(4,i-npart)
vxyzu(1,i) = vxyzu2(1,i-npart)
vxyzu(2,i) = vxyzu2(2,i-npart)
vxyzu(3,i) = vxyzu2(3,i-npart)
vxyzu(4,i) = vxyzu2(4,i-npart)
eos_vars(:,i) = eos_vars2(:,i-npart)
if (maxalpha == maxp) then
alphaind(1,i) = real(alphaind2(1,i-npart),kind=4)
alphaind(2,i) = real(alphaind2(2,i-npart),kind=4)
endif
call set_particle_type(i,igas)
enddo
npart = npart + Nstar2
npartoftype(igas) = npart
end subroutine add_star
!
! If editing an existing binary, determine number of particles in each star based on their position
!
subroutine determine_Nstar(npart,xyzh,Nstar1,Nstar2)
integer, intent(in) :: npart
real, intent(in) :: xyzh(:,:)
integer, intent(out) :: Nstar1, Nstar2
integer :: Nstar1xneg, Nstar1xpos, Nstar1yneg, Nstar1ypos
integer :: Nstar2xneg, Nstar2xpos, Nstar2yneg, Nstar2ypos
integer :: i
logical :: done
print *, 'Auto-Determining which particles belong in each star'
print *, ' (warning: assumes stars are separated, in x-y plane, and com is at x=y=0)'
print *, ' (and does not work if ambient background already present)'
print *, ''
!
! We do this in a brute force simple way.
!
! There exists a cut along x=0 or y=0 that separates the two stars.
! So try both and take the one that works.
!
! We also need to know which star is ordered first in memory.
! Means we try 4 cuts in total (left/right and right/left for x=0, etc)
!
! Strategy: Try looping from i=1 onwards for 4 cuts to find Nstar1
! then loop from i=npart downwards to find Nstar2
!
! Solution exists when Nstar1 + Nstar2 = npart
! (If they don't, then cut is going through the stars or is backwards.)
!
Nstar1xneg = 0
Nstar1xpos = 0
Nstar1yneg = 0
Nstar1ypos = 0
i = 1
done = .false.
do while (.not.done)
if (xyzh(1,i) < 0.0) then
Nstar1xneg = NStar1xneg + 1
else
done = .true.
endif
i = i + 1
enddo
i = 1
done = .false.
do while (.not.done)
if (xyzh(1,i) > 0.0) then
Nstar1xpos = NStar1xpos + 1
else
done = .true.
endif
i = i + 1
enddo
i = 1
done = .false.
do while (.not.done)
if (xyzh(2,i) < 0.0) then
Nstar1yneg = NStar1yneg + 1
else
done = .true.
endif
i = i + 1
enddo
i = 1
done = .false.
do while (.not.done)
if (xyzh(2,i) > 0.0) then
Nstar1ypos = NStar1ypos + 1
else
done = .true.
endif
i = i + 1
enddo
Nstar2xneg = 0
Nstar2xpos = 0
Nstar2yneg = 0
Nstar2ypos = 0
i = npart
done = .false.
do while (.not.done)
if (xyzh(1,i) < 0.0) then
Nstar2xneg = NStar2xneg + 1
else
done = .true.
endif
i = i - 1
enddo
i = npart
done = .false.
do while (.not.done)
if (xyzh(1,i) > 0.0) then
Nstar2xpos = NStar2xpos + 1
else
done = .true.
endif
i = i - 1
enddo
i = npart
done = .false.
do while (.not.done)
if (xyzh(2,i) < 0.0) then
Nstar2yneg = NStar2yneg + 1
else
done = .true.
endif
i = i - 1
enddo
i = npart
done = .false.
do while (.not.done)
if (xyzh(2,i) > 0.0) then
Nstar2ypos = NStar2ypos + 1
else
done = .true.
endif
i = i - 1
enddo
if (Nstar1xneg + Nstar2xpos == npart) then
Nstar1 = Nstar1xneg
Nstar2 = Nstar2xpos
elseif (Nstar1xpos + Nstar2xneg == npart) then
Nstar1 = Nstar1xpos
Nstar2 = Nstar2xneg
elseif (Nstar1yneg + Nstar2ypos == npart) then
Nstar1 = Nstar1yneg
Nstar2 = Nstar2ypos
elseif (Nstar1ypos + Nstar2yneg == npart) then
Nstar1 = Nstar1ypos
Nstar2 = Nstar2yneg
else
Nstar1 = npart
Nstar2 = 0
print *, 'ERROR: could not determine number of particles in each star'
print *, ' either this is not a binary, the stars are not separated, or there is extra material outside the stars'
print *, ''
endif
print *, ' Nstar1 = ', Nstar1
print *, ' Nstar2 = ', Nstar2
print *, ''
end subroutine determine_Nstar
!
! Determine radius of each star based on particles
!
subroutine get_radii(npart,xyzh,Nstar1,Nstar2,x1com,x2com,rad1,rad2)
integer, intent(in) :: npart
real, intent(inout) :: xyzh(:,:)
integer, intent(in) :: Nstar1, Nstar2
real, intent(in) :: x1com(:),x2com(:)
real, intent(out) :: rad1, rad2
integer :: i
real :: dx, dy, dz, dr
rad1 = 0.0
do i = 1, Nstar1
dx = xyzh(1,i) - x1com(1)
dy = xyzh(2,i) - x1com(2)
dz = xyzh(3,i) - x1com(3)
dr = sqrt(dx*dx + dy*dy + dz*dz)
rad1 = max(dr, rad1)
enddo
rad2 = 0.0
do i = Nstar1+1, npart
dx = xyzh(1,i) - x2com(1)
dy = xyzh(2,i) - x2com(2)
dz = xyzh(3,i) - x2com(3)
dr = sqrt(dx*dx + dy*dy + dz*dz)
rad2 = max(dr, rad2)
enddo
end subroutine get_radii
!
! Add an ambient background fluid
!
!subroutine add_background(npart,npartoftype,massoftype,xyzh,vxyzu,Nstar1,Nstar2,x1com,x2com,rad1,rad2,nx)
! use part, only: hfact,igas,set_particle_type
! use unifdis, only: set_unifdis
! use io, only: master
! use boundary, only: set_boundary,xmin,xmax,ymin,ymax,zmin,zmax,totvol
! use units, only: unit_density
! integer, intent(inout) :: npart
! integer, intent(inout) :: npartoftype(:)
! real, intent(in) :: massoftype(:)
! real, intent(inout) :: xyzh(:,:),vxyzu(:,:)
! integer, intent(in) :: Nstar1, Nstar2
! real, intent(in) :: x1com(:),x2com(:)
! real, intent(in) :: rad1, rad2
! integer, intent(in) :: nx
! integer :: id
! integer :: i
! real :: xlen, deltax, bgdens
! integer(kind=8) :: npart_total
!
! print *, 'Adding uniform low-density background fluid'
! print *, ''
!
! xlen = 0.437 * 0.5 ! 10^10 cm
! call set_boundary(-xlen,xlen,-xlen,xlen,-xlen,xlen)
!
! deltax = (2.0 * xlen) / nx
!
! if (deltax > rad1 .or. deltax > rad2) then
! print *, 'WARNING: particle separation greater than star radius'
! print *, ' suggest using nx=', int(2.0 * xlen / rad1)
! print *, ''
! endif
!
! id = 1
! npart_total = int(npart,kind=4)
! call set_unifdis('cubic',id,master,xmin,xmax,ymin,ymax,zmin,zmax,deltax,hfact,npart,xyzh,nptot=npart_total)
!
! npart = npart_total
! do i = Nstar1 + Nstar2 + 1, npart
! call set_particle_type(i,igas)
! enddo
!
! npartoftype(igas) = npart
!
! bgdens = (npart-Nstar1-Nstar2) * massoftype(igas) / totvol
! print *, ' Added background fluid of density: ', (bgdens*unit_density), ' g/cm^3'
! print *, ''
!
!end subroutine add_background
!
! Adjust the separation of the two stars.
! First star is placed at the origin, second star is placed sep away in x
!
subroutine adjust_sep(npart,xyzh,vxyzu,Nstar1,Nstar2,sep,x1com,v1com,x2com,v2com)
integer, intent(in) :: npart
real, intent(inout) :: xyzh(:,:),vxyzu(:,:)
integer, intent(in) :: Nstar1, Nstar2
real, intent(in) :: x1com(:),v1com(:),x2com(:),v2com(:)
real, intent(in) :: sep
integer :: i
print *, 'Placing stars apart at a distance: ', sep
print *, ''
do i = 1, Nstar1
xyzh(1,i) = xyzh(1,i) - x1com(1)
xyzh(2,i) = xyzh(2,i) - x1com(2)
xyzh(3,i) = xyzh(3,i) - x1com(3)
vxyzu(1,i) = vxyzu(1,i) - v1com(1)
vxyzu(2,i) = vxyzu(2,i) - v1com(2)
vxyzu(3,i) = vxyzu(3,i) - v1com(3)
enddo
do i = Nstar1+1, npart
xyzh(1,i) = xyzh(1,i) - x2com(1) + sep
xyzh(2,i) = xyzh(2,i) - x2com(2)
xyzh(3,i) = xyzh(3,i) - x2com(3)
vxyzu(1,i) = vxyzu(1,i) - v2com(1)
vxyzu(2,i) = vxyzu(2,i) - v2com(2)
vxyzu(3,i) = vxyzu(3,i) - v2com(3)
enddo
end subroutine adjust_sep
!
! reset velocities
!
subroutine reset_velocity(npart,vxyzu)
integer, intent(in) :: npart
real, intent(inout) :: vxyzu(:,:)
vxyzu(1:3,:) = 0.0
end subroutine reset_velocity
!
! Set corotation external force on using angular velocity
!
subroutine set_corotate_velocity(angvel)
use options, only:iexternalforce
use externalforces, only: omega_corotate,iext_corotate
real, intent(in) :: angvel
print "(/,a,es18.10,/)", ' The angular velocity in the corotating frame is: ', angvel
! Turns on corotation
iexternalforce = iext_corotate
omega_corotate = angvel
end subroutine set_corotate_velocity
!
! Set orbital velocity in normal space
!
subroutine set_velocity(npart,vxyzu,Nstar1,Nstar2,angvel,vel1,vel2)
integer, intent(in) :: npart
real, intent(inout) :: vxyzu(:,:)
integer, intent(in) :: Nstar1, Nstar2
real, intent(in) :: angvel
real, intent(in) :: vel1,vel2
integer :: i
print *, "Setting stars in mutual orbit with angular velocity: ", angvel
print *, " Adding bulk velocity |v| = ", vel1, " to first star"
print *, " |v| = ", vel2, " to second star"
print *, ""
! Adjust bulk velocity of relaxed star towards second star
do i = 1, Nstar1
vxyzu(2,i) = vxyzu(2,i) + vel1
enddo
do i = Nstar1+1, npart
vxyzu(2,i) = vxyzu(2,i) - vel2
enddo
end subroutine set_velocity
!
! Set binaries in synchronised orbit
!
subroutine synchronise(npart,xyzh,vxyzu,Nstar1,Nstar2,angvel,x1com,x2com)
integer, intent(in) :: npart
real, intent(in) :: xyzh(:,:)
real, intent(inout) :: vxyzu(:,:)
integer, intent(in) :: Nstar1, Nstar2
real, intent(in) :: angvel
real, intent(in) :: x1com(:), x2com(:)
integer :: i
print *, "Synchronising rotation to orbital period"
print *, ""
do i = 1, Nstar1
vxyzu(1,i) = vxyzu(1,i) + angvel * (xyzh(2,i) - x1com(2))
vxyzu(2,i) = vxyzu(2,i) - angvel * (xyzh(1,i) - x1com(1))
enddo
do i = Nstar1+1, npart
vxyzu(1,i) = vxyzu(1,i) + angvel * (xyzh(2,i) - x2com(2))
vxyzu(2,i) = vxyzu(2,i) - angvel * (xyzh(1,i) - x2com(1))
enddo
end subroutine synchronise
!
! Add radial pulsation velocity to a single star
!
subroutine add_vradial(npart,xyzh,vxyzu,fac)
use physcon, only: pi
integer, intent(in) :: npart
real, intent(in) :: xyzh(:,:)
real, intent(inout) :: vxyzu(:,:)
real, intent(in) :: fac
integer :: i
real :: rad,theta,phi,vr
do i = 1,npart
rad = sqrt( dot_product(xyzh(1:3,i),xyzh(1:3,i)) )
theta = atan(xyzh(2,i)/xyzh(1,i))
if (xyzh(1,i) < 0.0) theta = theta + pi
phi = acos(xyzh(3,i)/rad)
vr = fac*rad
vxyzu(1,i) = vr*cos(theta)*sin(phi)
vxyzu(2,i) = vr*sin(theta)*sin(phi)
vxyzu(3,i) = vr*cos(phi)
enddo
end subroutine add_vradial
!
! Add rotational velocity to a single star
! Author: Bernard Field under supervision of James Wurster
! (Note: The output may not be in hydrostatic equilibrium, thus may be unstable)
subroutine add_vrotational(npart,xyzh,vxyzu,omega_inner,omega_outer)
integer, intent(in) :: npart
real, intent(in) :: xyzh(:,:)
real, intent(inout) :: vxyzu(:,:)
real, intent(in) :: omega_inner,omega_outer
integer :: i
real :: domega,rad,rad2,rad2i,rstar1
domega = omega_outer - omega_inner
!--calculate stellar radius
rad2 = 0.
do i = 1,npart
rad2i = xyzh(1,i)*xyzh(1,i) + xyzh(2,i)*xyzh(2,i)
rad2 = max(rad2,rad2i)
enddo
rstar1 = 1.0/sqrt(rad2)
!
!--Add rotational profile
do i=1,npart
rad = sqrt( xyzh(1,i)*xyzh(1,i) + xyzh(2,i)*xyzh(2,i) )
vxyzu(1,i) = -xyzh(2,i) * (domega*rad*rstar1 + omega_inner)
vxyzu(2,i) = xyzh(1,i) * (domega*rad*rstar1 + omega_inner)
enddo
end subroutine add_vrotational
!
! Save nstar so it can be properly written to the header
!
subroutine save_nstar(Nstar1,Nstar2)
use extern_gwinspiral, only: Nstar
integer, intent(in) :: Nstar1,Nstar2
Nstar(1) = Nstar1
Nstar(2) = Nstar2
end subroutine save_nstar
subroutine set_velocity_coll(npart,vxyzu,Nstar1,Nstar2,angvel,vcoll)
integer, intent(in) :: npart
real, intent(inout) :: vxyzu(:,:)
integer, intent(in) :: Nstar1, Nstar2
real, intent(in) :: angvel
real, intent(in) :: vcoll
integer :: i
do i = 1, Nstar1
vxyzu(1,i) = vxyzu(1,i) + vcoll *(2.)**0.5 / 2
enddo
do i = Nstar1+1, npart
vxyzu(1,i) = vxyzu(1,i) - vcoll *(2.)**0.5 / 2
enddo
end subroutine set_velocity_coll
!-----------------------------------------------------------------------
end module moddump