-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_SIsimple.f90
1576 lines (1375 loc) · 47 KB
/
setup_SIsimple.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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!----------------------------------------------------------------
! Set up for the 2D cartesian Streaming Imstability MRI
! test problem described in Youdin and Johansen (2007) +
! the additional problems of Bai and Stone (2010)
! It is possible to add magnetic field
!
! Be careful to the dimensionless quantities:
! l(phys) = l(code)R = l(YJ)eta R
! t(phys) = t(code)/Omega = t(YJ)/Omega
! k(pkys) = k(code)/R = k(YJ)/(eta R)
! v(phys) = v(code) vk = v(YJ)(eta vk)
! rho(phys) = rho(code) Msol/R^3 = rho(code) Msol/(eta R)^3
!----------------------------------------------------------------
!--la soluce NSH86 est calculkee une precision plus faible que la perturbation.
!--tester la perturbation sans drag (linAwg): est ce qu'on a un increase de la slution ??
subroutine setup
!
!--include relevant global variables
!
use dimen_mhd
use debug
use loguns
use bound
use eos
use options
use part
use setup_params
use streaming
use uniform_distributions
use mem_allocation, only:alloc
!
!--define local variables
!
implicit none
integer :: i,ngas,npdust,jtype
real :: massp,masspdust,totmass,totmassdust
real :: denszero,uuzero,cs0,polyk0,denszeroc
real :: przero,Bzeroz,asize,betamhd,wavekmin,valfvenz
real :: denszerodust,dust_to_gas_ratio
real :: L,kx,kz,Bigkx,Bigkz,tausmode
real :: Rux,Iux,Ruy,Iuy,Ruz,Iuz,Rwx,Iwx,Rwy,Iwy,Rwz,Iwz
real :: Rrhog,Irhog,Rrhod,Irhod
real :: onepluseps,denomNSH,vgxNSH,vgyNSH,vdxNSH,vdyNSH
real :: xi,zi,cokx0,sikx0,cokz0,sikz0
real :: hL,eta_local
real :: x1,x2,x3,x4,z1,z2,z3,z4,pert,xstart,zstart
real :: kxfac, kzfac, combined_amp
real :: Rrhogc, Irhogc, ddens, gdens
real :: rhodonrho
real :: vgx,vgy,vgz,vdx,vdy,vdz
real :: cokx, sikx, cokz, sikz, tau_drag
logical :: iperturb, vparity
integer :: ntypes
integer, parameter :: itsmax = 20
real, parameter :: ampl = 1.d-3
real, parameter :: tol = 1.e-8
! real, parameter :: corr = 0.99975747 !--correction to handle the real SPH density
real, parameter :: corr = 0.99994416703041011
real, parameter :: vcorrg = 0.99930182
real, parameter :: vcorrd = 0.99930212
!character(len=20),parameter :: lin = 'kxkzgasIdRvz'
character(len=20),parameter :: lin = 'linA'
!--one fluid approach
if (idust.eq.1) then
ntypes = 1
else
ntypes = 2
endif
vparity = .false.
! eta_local = eta
print *, 'eta local ', eta_local, eta
eta_local = 0.005
if (trim(lin).eq.'shalloweta') eta_local = 0.001
!-------------------------------------------------------------
! set the external forces and the boundary conditions
!-------------------------------------------------------------
!--allow for tracing flow
if (trace) write(iprint,*) ' entering subroutine setup (SI)'
write(iprint,*) '2D streaming instability'
if (ndim.ne.2) stop 'error: this is a 2D problem and ndim.ne.2'
if (ndimV.ne.3) stop 'error: we need ndimV=3 for this problem'
!--set position of disc patch for coriolis & centrifugal forces
iexternal_force = 11 ! additional correction due to the background pressure gradient
! iexternal_force = 5
if (trim(lin).eq.'eigenNoShearNoPNoD') iexternal_force = 0
!-get the drag quantities and the SI perturbations
call getperturb(lin,Bigkx,Bigkz,tausmode,dust_to_gas_ratio,Rux,Iux, &
Ruy,Iuy,Ruz,Iuz,Rrhog,Irhog,Rwx,Iwx,Rwy,Iwy,Rwz,Iwz,iperturb, &
cs0,kxfac,kzfac,Rrhod,Irhod,ampl,eta_local)
!--set boundaries
ibound(:) = 3 ! periodic in y,z
ibound(1) = 5 ! shearing box in x (==R)
if (trim(lin).eq.'eigenNoShearNoPNoD') ibound(1) = 3
nbpts = 0 ! use ghosts not fixed
asize = 0.005/30. !0.3 !0.3 !1./3. !0.005/30. !0.01 !1.0!pi ! box size (corresponds to Bai/Stone 2010)
! xmin(:) = -asize*eta/Bigkx ! set position of boundaries
! xmax(:) = asize*eta/Bigkx
! psep = psep*eta/Bigkx
xmin(:) = -asize!_-*0.05
xmax(:) = asize!--*0.05
psep = psep*asize!--*0.05
if (abs(asize-1.).lt.tiny(0.)) print*,'WARNING: if asize .ne. 1, change cs'
!-------------------------------------------------------------
! set the particles and their masses
!-------------------------------------------------------------
!--setup uniform density grid of gas and dust particles
ngas = 0
npdust = 0
do jtype=1,ntypes
call set_uniform_cartesian(2,psep,xmin,xmax,adjustbound=.true.)
if (jtype.eq.1) then
ngas = npart
itype(1:ngas) = itypegas
print *, 'gas ', ngas
print *, x(1,1:10)
elseif (jtype.eq.2) then
npdust = npart - ngas
itype(ngas+1:ngas+npdust) = itypedust
print *, 'dust ', ngas, npdust
print *, x(1,ngas+1:ngas+10)
endif
enddo
ntotal = ngas + npdust
denszero = 1.0
denszerodust = denszero*dust_to_gas_ratio
select case(trim(lin))
case('nodrag','nodragpert','linAwg','kxepi','kxkzsimple','kxvd','kzvd', &
'kxkzdensgas','kxkzdens','eigenNoPNoDrag','BBeigenNoPNoDrag', &
'eigenNoShearNoPNoD')
Kdrag = 0.
tausmode = 0.
case('dpkz','simpledrag','kxsimpledrag','dpkx','kxkzdrag','dpkxkz', &
'kzvddrag','kxvddrag','kzvddragp','kxkzdensgasdrag','kxkzdensgasdragpr', &
'kxkzdenswdrag','prestest')
Kdrag = 1.
tausmode = denszerodust/Kdrag
case('strongdrag','kxstrongdrag','dpkxstrong','kxkzdragstrong', &
'kxkzdenssdrag','kxkzdensgasI','kxkzgasIdRvz','linAsimple', &
'kxkzdensgasIP','k10asym','damping','kxkzdustdens','kxkzvrgas', &
'kxkzdustdensp')
Kdrag = 10.
tausmode = denszerodust/Kdrag
case('dpkxkzstrong','kxkzdenssdragp','kxkzdustdensp30','kxkzdustdensp30_3')
Kdrag = 30.
tausmode = denszerodust/Kdrag
case('smallcontrast','eigen1','eigen2','eigen4','eigennopres','eigensettle', &
'mixedeigen2')
Kdrag = 0.01
tausmode = denszerodust/Kdrag
case default
Kdrag = (denszerodust*corr)*Omega0/tausmode
tausmode = denszerodust/Kdrag
tau_drag = denszerodust/Kdrag
end select
print *,'WARNING: Kdrag has been modified to correspond to the SI test. Kdrag=',Kdrag
print *, 'Tau_drag = ', tau_drag
print *, 'Pressure eta = ', eta, eta_local
!--determine particle mass
L = (xmax(1) - xmin(1))!*eta/Bigkx
hL = 0.5*L
totmass = denszero*L*L
totmassdust = denszerodust*L*L
massp = totmass/FLOAT(ngas)
if (idust.eq.1) then ! one fluid dust
massp = massp*(1. + dust_to_gas_ratio)
else
masspdust = totmassdust/FLOAT(npdust)
endif
print *, 'Particle mass ', massp, totmass, ngas, ntotal
!--kx,kz in code units (one wavelenght per box)
select case (trim(lin))
case ('kxkzdrag','kxkzsimple','kxkzdragstrong','dpkxkz','dpkxkzstrong',&
'kxkzdensgas','kxkzdensgasdrag','kxkzdensgasdragpr','kxkzdens', &
'kxkzdenswdrag','kxkzdenssdrag','kxkzdenssdragp','kxkzdensgasI', &
'kxkzgasIdRvz','linAsimple','linA','kxkzdensgasIP','damping', &
'kxkzdustdens','kxkzvrgas','kxkzdustdensp','kxkzdustdensp30', &
'kxkzdustdensp30_3','linAnew','shalloweta','smallcontrast','eigen1', &
'eigen2','eigen4','eigennopres','contrasttest','mixedeigen', &
'eigenNoPNoDrag','BBeigenNoPNoDrag','eigenNoShearNoPNoD','mixedeigen2')
kx = kxfac*2.*pi/L
case default
kx = 0.0 !kxfac*2.*pi/L
end select
kz = kzfac*2.*pi/L
if (trim(lin).eq.'k10asym') kz = 0.
select case (trim(lin))
case ('kxepi','kxsimpledrag','kxstrongdrag','dpkx','dpkxstrong', &
'kxvd','kxvddrag')
kx = kxfac*2.*pi/L
case default
end select
!-------------------------------------------------------------
! setup the gas quantities
!-------------------------------------------------------------
cs0 = 0.1 !--cfJY07
if (gamma > 1.) then
przero = denszero*cs0*cs0/gamma
uuzero = przero/(denszero*(gamma-1.))
polyk0 = przero/denszero**gamma
else
przero = denszero*cs0*cs0
uuzero = 1.5*cs0*cs0
polyk0 = cs0*cs0
endif
write(iprint,*) ' kx, kz = ', kx, kz
write(iprint,*) ' gamma = ', gamma
write(iprint,*) ' cs0 = ',cs0,' cs2 = ',cs0**2,' u = ',uuzero
write(iprint,*) ' Omega_c = ',Omega0, ' R_c = ',Rcentre
write(iprint,*) ' polyk = ',polyk,' setting to = ',polyk0
polyk = polyk0
write(iprint,*) ' orbital time = ',2.*pi/Omega0
write(iprint,*) ' c / (R omega) = ',cs0/(Rcentre*Omega0)
!-------------------------------------------------------------
! setup the parameters for the SI test
!-------------------------------------------------------------
onepluseps = 0.
denomNSH = 0.
select case(trim(lin))
case('nodrag','nodragpert')
vgxNSH = 0.
vgyNSH = 10.*eta
vdxNSH = 0.
vdyNSH = 0.
case('NSH','NSHpert','linA','linAwg','linB','dpkz','dpkx','dpkxstrong', &
'dpkxkz','dpkxkzstrong','kxkzdenssdragp','linAnew','mixedeigen') !--enforce the SPH solution for the background
!quantities calculated for eta=0.01
!--Older values (from original asymptotic approach)
! vgxNSH = 1.873813705237E-04
! vgyNSH = -2.50469218d-3*0.5
! vdxNSH = -6.246053793239E-05
! vdyNSH = -2.49843602d-3*0.5
! vgxNSH = 1.873813505437570E-04 ! 1.873813705237E-04 !3.75094634d-4*0.5*vcorrg ! 1.87381344594547123e-04
! vgyNSH = -1.252342266461199E-03 !-2.50469218d-3*0.5 !-1.25235010733846901d-3
! vdxNSH = -6.246055479643788E-05 !-6.246053793239E-05 !-1.25031547d-4*0.5*vcorrd !-6.24605585029068132e-05
! vdyNSH = -1.249219266205729E-03 !-2.49843602d-3*0.5 !-1.24921927251258388
vgxNSH = 1.87409978489950E-04 !1.873813505437570E-04 ! 1.873813705237E-04 !3.75094634d-4*0.5*vcorrg ! 1.87381344594547123e-04
vgyNSH = -1.25233666827186E-03 !-1.252342266461199E-03 !-2.50469218d-3*0.5 !-1.25235010733846901d-3
vdxNSH = -6.24699926597789E-05 !-6.246055479643788E-05 !-6.246053793239E-05 !-1.25031547d-4*0.5*vcorrd !-6.24605585029068132e-05
vdyNSH = -1.24922109681910E-03 !-1.249219266205729E-03 !-2.49843602d-3*0.5 !-1.24921927251258388
case('eigensettle','eigen2')
vgxNSH = 7.936174510944069E-05
vgyNSH = -4.979761466375418E-03
vdxNSH = -3.968087255472082E-03
vdyNSH = -1.011926681229109E-03
case('appB','appBsimple','simpledrag','strongdrag','kxkzdrag','kxepi', &
'kxsimpledrag','kxstrongdrag','kxkzsimple','kxkzdragstrong','kxvd', &
'kzvd','kzvddrag','kxvddrag','kxkzdensgas','kxkzdensgasdrag','kxkzdens',&
'kxkzdenswdrag','kxkzdenssdrag','kxkzdensgasI','kxkzgasIdRvz', &
'kxkzdustdens','kxkzvrgas','eigenNoPNoDrag','BBeigenNoPNoDrag',&
'eigenNoShearNoPNoD')
vgxNSH = 0.
vgyNSH = 0.
vdxNSH = 0.
vdyNSH = 0.
case default
onepluseps = 1. + dust_to_gas_ratio
denomNSH = onepluseps**2 + tausmode**2
vgxNSH = 2.*dust_to_gas_ratio*tausmode/denomNSH*eta_local
vgyNSH = -(1. + dust_to_gas_ratio*tausmode**2/denomNSH)*eta_local/onepluseps
vdxNSH = -2.*tausmode/denomNSH*eta_local
vdyNSH = -(1. - tausmode**2/denomNSH)*eta_local/onepluseps
! vgxNSH = 0.
! vgyNSH = 0.
! vdxNSH = 0.
! vdyNSH = 0.
! vgxNSH = 0. !2.49360859689E-04
! vgyNSH = 0. !-2.50623239911E-03
! vdxNSH = 0. !-2.49360859689E-04
! vdyNSH = 0. !-2.49376760089E-03
end select
write(iprint,*) ' vgxNSH = ',vgxNSH
write(iprint,*) ' vgyNSH = ',vgyNSH
write(iprint,*) ' vdxNSH = ',vdxNSH
write(iprint,*) ' vdyNSH = ',vdyNSH
!-------------------------------------------------------------
! setup the magnetic field (beta = pr/(0.5*B^2))
!-------------------------------------------------------------
if (imhd.ne.0) then
betamhd = 4000.
Bzeroz = sqrt(2.*przero/betamhd)
write(iprint,*) ' beta(MHD) = ',betamhd,' Bz = ',Bzeroz,' P = ',przero
valfvenz = sqrt(Bzeroz**2/denszero)
wavekmin = sqrt(15.)/4.*Omega0/valfvenz
write(iprint,*) 'most unstable wavelength = ',2.*pi/wavekmin
endif
!-------------------------------------------------------------
! assign particles properties
!-------------------------------------------------------------
combined_amp = ampl!*eta_local
Rrhog = Rrhog*denszero*ampl!*eta_local
Irhog = Irhog*denszero*ampl!*eta_local
Rrhod = Rrhod*denszero*combined_amp !ampl*eta_local
Irhod = 0.
!--convert the data YJ in code units (v(code) = eta v(YJ))
Rux = Rux*combined_amp
Iux = Iux*combined_amp
Ruy = Ruy*combined_amp
Iuy = Iuy*combined_amp
Ruz = Ruz*combined_amp
Iuz = Iuz*combined_amp
Rwx = Rwx*combined_amp
Iwx = Iwx*combined_amp
Rwy = Rwy*combined_amp
Iwy = Iwy*combined_amp
Rwz = Rwz*combined_amp
Iwz = Iwz*combined_amp
print *, 'V Coeffs ', Rux, Iux, Ruy, Iuy, Ruz, Iuz, Rwx, Iwx, Rwy, Iwy, Rwz, Iwz
print *, 'Dens coeffs ', Rrhog, Irhog, Rrhod, Irhod
print *, 'Dens amps ', sqrt(Rrhog**2 + Irhog**2), Rrhod
print *, 'ntotal ', ntotal
do i=1,ntotal
xi = x(1,i)
zi = x(2,i)
cokx0 = cos(kx*xi)
sikx0 = sin(kx*xi)
cokz0 = cos(kz*zi)
sikz0 = sin(kz*zi)
if (idust.eq.1) dustfrac(1,i) = dust_to_gas_ratio
!-------------------------------------------------------------
! start with the gas particles
!-------------------------------------------------------------
gdens = denszero
ddens = denszerodust
denszeroc = denszero
if (itype(i).eq.itypegas) then
if (iperturb.eqv. .true.) then
if (idust.eq.1) then
Rrhogc = Rrhog + Rrhod
Irhogc = Irhog + Irhod
denszeroc = denszero + denszerodust
else
Rrhogc = Rrhog
Irhogc = Irhog
endif
select case(trim(lin))
case('kxkzdensgas','kxkzdensgasdrag','kxkzdensgasdragpr','kxkzdens', &
'kxkzdenswdrag','kxkzdenssdrag','kxkzdenssdragp','kxkzdensgasI', &
'kxkzgasIdRvz','linAsimple','kxkzdensgasIP','prestest', &
'linAnew','shalloweta','linA','smallcontrast','eigen1', &
'eigen2','eigen4','eigennopres','contrasttest','mixedeigen', &
'eigenNoPNoDrag','BBeigenNoPNoDrag','eigenNoShearNoPNoD', &
'mixedeigen2')
!setup a density perturbation Rrhog*cos(kx*x + kz*z) - Irhog*sin(kx*x + kz*z)
xstart = xi
zstart = zi
!CAREFUL: keep 0.5 factor only for perturbations in 2D !
!--term 1 : Rrhog*cos(kx*x)*cos(kz*z)
pert = 0.5*Rrhogc*cokz0/denszeroc
call deltarho_cos(xi,pert,kx,-hL,hL) !--pert in x
x1 = xi - xstart
xi = xstart
pert = 0.5*Rrhogc*cokx0/denszeroc
call deltarho_cos(zi,pert,kz,-hL,hL) !--pert in z
z1 = zi - zstart
zi = zstart
if (.NOT.vparity) then
!--term 2 : -Rrhogc*sin(kx*x)*sin(kz*z)
pert = -0.5*Rrhogc*sikz0/denszeroc
call deltarho_sin(xi,pert,kx,-hL,hL) !--pert in x
x2 = xi - xstart
xi = xstart
pert = -0.5*Rrhogc*sikx0/denszeroc
call deltarho_sin(zi,pert,kz,-hL,hL) !--pert in z
z2 = zi - zstart
zi = zstart
else
x2 = 0.
z2 = 0.
endif
!--term 3 : -Irhog*sin(kx*x)*cos(kz*z)
pert = -0.5*Irhogc*cokz0/denszeroc
if (vparity) pert = -1.*pert
call deltarho_sin(xi,pert,kx,-hL,hL) !--pert in x
x3 = xi - xstart
xi = xstart
pert = -0.5*Irhogc*sikx0/denszeroc
if (vparity) pert = -1.*pert
call deltarho_cos(zi,pert,kz,-hL,hL) !--pert in z
z3 = zi - zstart
zi = zstart
if (.NOT.vparity) then
!--term 4 : -Irhog*cos(kx*x)*sin(kz*z)
pert = -0.5*Irhogc*sikz0/denszeroc
call deltarho_cos(xi,pert,kx,-hL,hL) !--pert in x
x4 = xi - xstart
xi = xstart
pert = -0.5*Irhogc*cokx0/denszeroc
call deltarho_sin(zi,pert,kz,-hL,hL) !--pert in z
z4 = zi - zstart
zi = zstart
else
x4 = 0.
z4 = 0.
endif
!--sum all the contributions
x(1,i) = xstart + x1 + x2 + x3 + x4
x(2,i) = zstart + z1 + z2 + z3 + z4
xi = x(1,i)
zi = x(2,i)
case default
end select
if (idust.eq.1) then
cokx = cos(kx*xi + kz*zi)
sikx = sin(kx*xi + kz*zi)
gdens = denszero + (Rrhog*cokx - Irhog*sikx)
ddens = denszerodust + (Rrhod*cokx - Irhod*sikx)
dustfrac(1,i) = ddens/gdens
endif
!----for adding a pert in kz only---------------------------
!pert = 1.d-7
!call deltarho_cos(zi,pert,kz,-hL,hL) !--pert in z
!x(2,i) = zi
!-----------------------------------------------------------------
endif
if (trim(lin).eq.'kxvd' .or. trim(lin).eq.'kxvddrag') then
!----for adding a pert in kz only---------------------------
pert = 1.d-7
xi = x(1,i)
call deltarho_cos(xi,pert,kx,-hL,hL) !--pert in x
x(1,i) = xi
!-----------------------------------------------------------------
endif
if (trim(lin).eq.'kzvd' .or. trim(lin).eq.'kzvddrag' .or. &
trim(lin).eq.'kzvddragp') then
!----for adding a pert in kz only---------------------------
pert = 1.d-7
zi = x(2,i)
call deltarho_cos(zi,pert,kz,-hL,hL) !--pert in z
x(2,i) = zi
!-----------------------------------------------------------------
endif
!--setup the kinematic quantities (v = vk + vNSH86 + vpert)
vel(:,i) = 0.
if (idust.eq.1) then
vgx = vgxNSH
vgy = 0.
vgz = -domegadr*Omega0*xi + vgyNSH
vdx = vdxNSH
vdy = 0.
vdz = -domegadr*Omega0*xi + vdyNSH
deltav(1,i) = vdx - vgx ! deltav = vdust - vgas
deltav(2,i) = vdy - vgy
deltav(3,i) = vdz - vgz
rhodonrho = dustfrac(1,i)/(1.+dustfrac(1,i))
vel(1,i) = vgx + rhodonrho*deltav(1,i) ! v = vg + rhod/rho*deltav
vel(2,i) = vgy + rhodonrho*deltav(2,i)
vel(3,i) = vgz + rhodonrho*deltav(3,i)
! print *, 'vels ', vel(1,i), (gdens*vgx + ddens*vdx)/(gdens+ddens)
!--equivalent to above
! vel(1,i) = (gdens*vgx + ddens*vdx)/(gdens+ddens)
! vel(2,i) = (gdens*vgy + ddens*vdy)/(gdens+ddens)
! vel(3,i) = (gdens*vgz + ddens*vdz)/(gdens+ddens)
else
vel(1,i) = vgxNSH
if (trim(lin).eq.'eigenNoShearNoPNoD') then
vel(3,i) = 0.
else
vel(3,i) = -domegadr*Omega0*xi + vgyNSH
endif
endif
select case(trim(lin))
case('kxkzdensgas','kxkzdensgasdrag','kxkzdensgasdragpr','kxkzdens', &
'kxkzdenswdrag','kxkzdenssdrag','kxkzdenssdragp','kxkzdensgasIP', &
'kxkzdensgasI')
if(i.eq.1) print *, 'No velocity perturbation'
case('kxepi','kxsimpledrag','kxstrongdrag','dpkx','dpkxstrong', &
'kxvd','kxvddrag')
!----for adding a pert in kx only--------------------------------
vel(1,i) = vel(1,i) + 1.d-7*cos(kx*xi)
vel(2,i) = vel(2,i) + 0.*cos(kx*xi)
vel(3,i) = vel(3,i) + 1.d-7*cos(kx*xi)
!-----------------------------------------------------------------
case('kxkzdrag','kxkzsimple','kxkzdragstrong','dpkxkz','dpkxkzstrong', &
'kxkzgasIdRvz','linAsimple','prestest','linAnew','shalloweta', &
'linA','smallcontrast','eigen1', &
'eigen2','eigen4','eigennopres','contrasttest','mixedeigen', &
'eigenNoPNoDrag','BBeigenNoPNoDrag','eigenNoShearNoPNoD', &
'mixedeigen2')
select case(trim(lin))
case('linAsimple','linA','linAnew','shalloweta','prestest', &
'smallcontrast','eigen1', &
'eigen2','eigen4','eigennopres','contrasttest','mixedeigen', &
'eigenNoPNoDrag','BBeigenNoPNoDrag','eigenNoShearNoPNoD', &
'mixedeigen2')
case default
Iux = 0.
Iuy = 0.
Iuz = 0.
Ruz = 0.
Rux = 1.d-7
Ruy = 1.d-7
print *, 'NOT HERE'
end select
if (trim(lin).eq.'kxkzgasIdRvz') then
Ruz = 1.0E-7
Iuz = 0.
! vel(2,i) = vel(2,i) + Ruz*cos(kx*xi + kz*zi) - Iuz*sin(kx*xi + kz*zi)
endif
! else
if (idust.eq.1) then
vel(:,i) = 0.
!--here x,y,z are just that.
vgx = vgxNSH
vgy = 0.
vgz = -domegadr*Omega0*xi + vgyNSH
vdx = vdxNSH
vdy = 0.
vdz = -domegadr*Omega0*xi + vdyNSH
if (iperturb.eqv. .true.) then
vgx = vgx + Rux*cos(kx*xi + kz*zi) - Iux*sin(kx*xi + kz*zi)
vdx = vdx + Rwx*cos(kx*xi + kz*zi) - Iwx*sin(kx*xi + kz*zi)
if (.NOT.vparity) then
vgy = vgy + Ruz*cos(kx*xi + kz*zi) - Iuz*sin(kx*xi + kz*zi)
vdy = vdy + Rwz*cos(kx*xi + kz*zi) - Iwz*sin(kx*xi + kz*zi)
else
vgy = vgy - (Ruz*cos(kx*xi + kz*zi) + Iuz*sin(kx*xi + kz*zi))
vdy = vdy - (Rwz*cos(kx*xi + kz*zi) + Iwz*sin(kx*xi + kz*zi))
endif
vgz = vgz + Ruy*cos(kx*xi + kz*zi) - Iuy*sin(kx*xi + kz*zi)
vdz = vdz + Rwy*cos(kx*xi + kz*zi) - Iwy*sin(kx*xi + kz*zi)
endif
deltav(1,i) = vdx - vgx ! deltav = vdust - vgas
deltav(2,i) = vdy - vgy
deltav(3,i) = vdz - vgz
rhodonrho = dustfrac(1,i)/(1.+dustfrac(1,i))
vel(1,i) = vgx + rhodonrho*deltav(1,i) ! v = vg + rhod/rho*deltav
vel(2,i) = vgy + rhodonrho*deltav(2,i)
vel(3,i) = vgz + rhodonrho*deltav(3,i)
print *, vel(3,i), deltav(3,i)
! print *, 'vels ', vel(1,i), (gdens*vgx + ddens*vdx)/(gdens+ddens)
else !--not one fluid
vel(1,i) = vel(1,i) + Rux*cos(kx*xi + kz*zi) - Iux*sin(kx*xi + kz*zi)
if (.NOT.vparity) then
vel(2,i) = vel(2,i) + Ruz*cos(kx*xi + kz*zi) - Iuz*sin(kx*xi + kz*zi)
else
vel(2,i) = vel(2,i) - (Ruz*cos(kx*xi + kz*zi) + Iuz*sin(kx*xi + kz*zi))
endif
vel(3,i) = vel(3,i) + Ruy*cos(kx*xi + kz*zi) - Iuy*sin(kx*xi + kz*zi)
endif
! endif
case('kxkzdustdens','kxkzdustdensp','kxkzdustdensp30_3', &
'kxkzdustdensp30')
!Do nothing
case default
if (iperturb .eqv. .true.) then
!----for adding a pert in kz only--------------------------------
vel(1,i) = vel(1,i) + 1.d-7*cos(kz*zi)
vel(2,i) = vel(2,i) + 0.*cos(kz*zi)
vel(3,i) = vel(3,i) + 1.d-7*cos(kz*zi)
!-----------------------------------------------------------------
endif
end select
! if (iperturb.eqv. .true.) then
! vel(1,i) = vel(1,i) + Rux*cos(kx*xi + kz*zi) - Iux*sin(kx*xi + kz*zi)
! vel(2,i) = vel(2,i) + Ruz*cos(kx*xi + kz*zi) - Iuz*sin(kx*xi + kz*zi)
! vel(3,i) = vel(3,i) + Ruy*cos(kx*xi + kz*zi) - Iuy*sin(kx*xi + kz*zi)
! endif
dens(i) = denszero
pmass(i) = massp
uu(i) = uuzero
!--if present, setup the magnetic field
if (imhd.gt.0) then
Bfield(:,i) = 0.
Bfield(2,i) = Bzeroz
Bfield(3,i) = 0.
elseif (imhd.lt.0) then
Bevol(:,i) = 0.
Bevol(3,i) = 0.
endif
!-------------------------------------------------------------
! now setup the dust particles
!-------------------------------------------------------------
elseif(itype(i).eq.itypedust) then
if (iperturb .eqv. .true.) then
select case(trim(lin))
case('kxkzdens','kxkzdenswdrag','kxkzdenssdrag','kxkzdenssdragp', &
'kxkzdensgasI','kxkzdensgasIP','linAsimple','prestest', &
'kxkzdustdens','kxkzdustdensp','kxkzdustdensp30', &
'kxkzdustdensp30_3','linAnew','shalloweta','linA', &
'smallcontrast','eigen1', &
'eigen2','eigen4','eigennopres','contrasttest','mixedeigen', &
'mixedeigen2')
!setup a density perturbation Rrhod*cos(kx*x + kz*z) - Irhod*sin(kx*x + kz*z)
xstart = xi
zstart = zi
!--term 1 : Rrhod*cos(kx*x)*cos(kz*z)
pert = 0.5*Rrhod*cokz0/denszerodust
call deltarho_cos(xi,pert,kx,-hL,hL) !--pert in x
x1 = xi - xstart
xi = xstart
pert = 0.5*Rrhod*cokx0/denszerodust
call deltarho_cos(zi,pert,kz,-hL,hL) !--pert in z
z1 = zi - zstart
zi = zstart
if (.NOT.vparity) then
!--term 2 : -Rrhod*sin(kx*x)*sin(kz*z)
pert = -0.5*Rrhod*sikz0/denszerodust
call deltarho_sin(xi,pert,kx,-hL,hL) !--pert in x
x2 = xi - xstart
xi = xstart
pert = -0.5*Rrhod*sikx0/denszerodust
call deltarho_sin(zi,pert,kz,-hL,hL) !--pert in z
z2 = zi - zstart
zi = zstart
else
x2 = 0.
z2 = 0.
endif
!--term 3 : -Irhod*sin(kx*x)*cos(kz*z)
pert = -0.5*Irhod*cokz0/denszerodust
if (vparity) pert = -1.*pert
call deltarho_sin(xi,pert,kx,-hL,hL) !--pert in x
x3 = xi - xstart
xi = xstart
pert = -0.5*Irhod*sikx0/denszerodust
if (vparity) pert = -1.*pert
call deltarho_cos(zi,pert,kz,-hL,hL) !--pert in z
z3 = zi - zstart
zi = zstart
if (.NOT.vparity) then
!--term 4 : -Irhod*cos(kx*x)*sin(kz*z)
pert = -0.5*Irhod*sikz0/denszerodust
call deltarho_cos(xi,pert,kx,-hL,hL) !--pert in x
x4 = xi - xstart
xi = xstart
pert = -0.5*Irhod*cokx0/denszerodust
call deltarho_sin(zi,pert,kz,-hL,hL) !--pert in z
z4 = zi - zstart
zi = zstart
else
x4 = 0.
z4 = 0.
endif
!--sum all the contributions
x(1,i) = xstart + x1 + x2 + x3 + x4
x(2,i) = zstart + z1 + z2 + z3 + z4
xi = x(1,i)
zi = x(2,i)
end select
endif
!----for adding a pert in kz only---------------------------
! pert = 1.d-7/denszerodust
! call deltarho_cos(zi,pert,kz,-hL,hL) !--pert in z
! x(2,i) = zi
!-----------------------------------------------------------------
!--setup the kinematic quantities (v = vk + vNSH86 + vpert)
vel(:,i) = 0.
vel(1,i) = vdxNSH
if (trim(lin).eq.'eigenNoShearNoPNoD') then
vel(3,i) = 0.
else
vel(3,i) = -domegadr*Omega0*xi + vdyNSH
endif
!----for adding a pert in kz only--------------------------------
! vel(1,i) = vel(1,i) + 1.d-7*cos(kz*zi)
! vel(2,i) = vel(2,i) + 0.*cos(kz*zi)
! vel(3,i) = vel(3,i) + 1.d-7*cos(kz*zi)
!-----------------------------------------------------------------
if (iperturb.eqv. .true.) then
select case(trim(lin))
case('linAsimple','linA','linAnew','shalloweta','prestest', &
'smallcontrast','eigen1', &
'eigen2','eigen4','eigennopres','contrasttest','mixedeigen', &
'mixedeigen2')
vel(1,i) = vel(1,i) + Rwx*cos(kx*xi + kz*zi) - Iwx*sin(kx*xi + kz*zi)
if (.NOT.vparity) then
vel(2,i) = vel(2,i) + Rwz*cos(kx*xi + kz*zi) - Iwz*sin(kx*xi + kz*zi)
else
vel(2,i) = vel(2,i) - (Rwz*cos(kx*xi + kz*zi) + Iwz*sin(kx*xi + kz*zi))
endif
vel(3,i) = vel(3,i) + Rwy*cos(kx*xi + kz*zi) - Iwy*sin(kx*xi + kz*zi)
end select
endif
dens(i) = denszerodust
pmass(i) = masspdust
uu(i) = 0.
endif
enddo
!--allow for tracing flow
if (trace) write(iprint,*) ' exiting subroutine setup'
return
end subroutine setup
!--------------------------------------------------------------------------------
!-initialise the different SI tests
!--------------------------------------------------------------------------------
subroutine getperturb(lin,Bigkx,Bigkz,tausmode,dust_to_gas_ratio,Rux,Iux, &
Ruy,Iuy,Ruz,Iuz,Rrhog,Irhog,Rwx,Iwx,Rwy,Iwy,Rwz,Iwz, &
iperturb,cs0,kxfac,kzfac,Rrhod,Irhod,ampl,eta_local)
use setup_params, only:pi
implicit none
character(len=20), intent(in) :: lin
real, intent(in) :: ampl,eta_local
real, intent(out) :: Bigkx,Bigkz,tausmode,dust_to_gas_ratio, cs0
real, intent(out) :: Rrhod,Irhod,kxfac,kzfac
real, intent(out) :: Rux,Iux,Ruy,Iuy,Ruz,Iuz,Rrhog,Irhog,Rwx,Iwx,Rwy,Iwy,Rwz,Iwz
logical, intent(out) :: iperturb
real :: Rurhog, Iurhog, Ruvrg, Iuvrg, Ruazig, Iuazig, Ruvzg, Iuvzg
real :: Rurhod, Ruvrd, Iuvrd, Ruazid, Iuazid, Ruvzd, Iuvzd
real :: Rsrhog, Isrhog, Rsvrg, Isvrg, Rsazig, Isazig, Rsvzg, Isvzg
real :: Rsrhod, Rsvrd, Isvrd, Rsazid, Isazid, Rsvzd, Isvzd
real :: sfac, ufac
cs0 = 0.1 !--cfJY07
kxfac = 1.0
kzfac = 1.0
Rrhod = 1.0
tausmode = 1.0
Bigkx = 1.
Bigkz = 1.
dust_to_gas_ratio = 1.
Rux = 0.
Iux = 0.
Ruy = 0.
Iuy = 0.
Ruz = 0.
Iuz = 0.
Rrhog = 0.
Irhog = 0.
Rwx = 0.
Iwx = 0.
Rwy = 0.
Iwy = 0.
Rwz = 0.
Iwz = 0.
iperturb = .true.
select case(trim(lin))
case('nodrag')
iperturb = .false.
Bigkx = 30.
Bigkz = 30.
dust_to_gas_ratio = 3.d0
case('nodragpert')
Bigkx = 30.
Bigkz = 30.
dust_to_gas_ratio = 3.d0
Rux = -0.1691398
Iux = 0.0361553
Ruy = 0.1336704
Iuy = 0.0591695
Ruz = 0.1691389
Iuz = -0.0361555
Rrhog = 0.0000224
Irhog = 0.0000212
Rwx = -0.1398623
Iwx = 0.0372951
Rwy = 0.1305628
Iwy = 0.0640574
Rwz = 0.1639549
Iwz = -0.0233277
case('NSH')
iperturb = .false.
tausmode = 0.1
Bigkx = 30.
Bigkz = 30.
dust_to_gas_ratio = 3.d0
case('damping')
iperturb = .false.
tausmode = 1.0
Bigkx = 30.
Bigkz = 30.
dust_to_gas_ratio = 1.d0
case('NSHpert')
iperturb = .true.
tausmode = 0.1
Bigkx = 30.
Bigkz = 30.
dust_to_gas_ratio = 3.d0
case('appB')
tausmode = 1.0
cs0 = 1.0
kxfac = -1.0
kzfac = 1.0
Rux = 1.0d-3
! Ruy = 1.0d-3
Rrhog = 0.0
Irhog = 0.0
Rrhod = 0.0
Bigkx = 1.0
Bigkz = 1.0
case('appBsimple')
iperturb = .true.
tausmode = 3.d0
Bigkx = 30.
Bigkz = 30.
dust_to_gas_ratio = 3.d0
case('simpledrag','kxsimpledrag','k10asym')
iperturb = .true.
tausmode = 1.d0
Bigkx = 1.
Bigkz = 1.
dust_to_gas_ratio = 1.d0
case('strongdrag','kxstrongdrag')
iperturb = .true.
tausmode = 3.d-1
Bigkx = 1.
Bigkz = 1.
dust_to_gas_ratio = 3.d0
case('kxkzdrag','kxkzsimple','kxkzdragstrong','kxkzdensgas','kxkzdensgasdrag', &
'kxkzdensgasdragpr','kxkzdens','kxkzdenswdrag','kxkzdenssdrag')
iperturb = .true.
tausmode = 1.d0
Bigkx = 1.
Bigkz = 1.
dust_to_gas_ratio = 1.d0
Irhog = 0.
Irhod = 0.
Rrhog = 1.0E-7/ampl
Rrhod = 1.0E-7/ampl
case('kxkzdenssdragp')
iperturb = .true.
tausmode = 1.d0
Bigkx = 1.
Bigkz = 1.
dust_to_gas_ratio = 3.d0
Irhog = 0.
Irhod = 0.
Rrhog = 1.0E-7/ampl
Rrhod = 1.0E-7/ampl
case('prestest')
iperturb = .true.
tausmode = 1.d0
Bigkx = 30.
Bigkz = 30.
dust_to_gas_ratio = 1.d0
Rux = 1.0E-7/(ampl*eta_local)
Iux = 0.
Ruy = 1.0E-7/(ampl*eta_local)
Iuy = 0.
Ruz = 1.0E-7/(ampl*eta_local)
Iuz = 0.
Rwx = 1.0E-7/(ampl*eta_local)
Iwx = 0.
Rwy = 0. !1.0E-7/(ampl*eta_local)
Iwy = 0.
Rwz = 1.0E-7/(ampl*eta_local)
Iwz = 0.
Rrhog = 1.0E-7/ampl
Rrhod = 1.0E-7/ampl
Irhog = 0.
Irhod = 0.
case('kxkzdensgasI','kxkzgasIdRvz','kxkzdensgasIP')
iperturb = .true.
tausmode = 1.d0
Bigkx = 1.
Bigkz = 1.
dust_to_gas_ratio = 1.d0
Irhog = 1.0E-7/ampl
Irhod = 0.
Rrhog = 0.
Rrhod = 0.
case('kxkzdustdens','kxkzdustdensp','kxkzdustdensp30')
iperturb = .true.
tausmode = 1.d0
Bigkx = 1.
Bigkz = 1.
dust_to_gas_ratio = 1.d0
Irhog = 0.0
Irhod = 0.
Rrhog = 0.
Rrhod = 1.0E-7/ampl
case('kxkzdustdensp30_3')
iperturb = .true.
tausmode = 1.d0
Bigkx = 1.
Bigkz = 1.
dust_to_gas_ratio = 3.d0
Irhog = 0.0