-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubroutines.f90
3498 lines (2745 loc) · 83.5 KB
/
subroutines.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
!*************************************************!
! SIMMSUS !
!MODULE: subroutines !
!Last update: 16/07/2023 !
!*************************************************!
module subroutines
use variables
contains
!*************************************************!
! SIMMSUS !
!SUBROUTINE: allocatevariables !
!Last update: 16/07/2023 !
!*************************************************!
subroutine allocatevariables
if(bifshear) then
allocate(gpvetor(npast))
end if
allocate(trap(npast))
allocate(X(rea,N,3))
allocate(U(rea,N,3))
allocate(W(rea,N,3))
if(browniano)then
allocate(FORCAS(6,rea,N,3))
allocate(TORQUES(3,rea,N,3))
else
allocate(FORCAS(5,rea,N,3))
allocate(TORQUES(2,rea,N,3))
end if
allocate(FT(rea,N,3))
allocate(Tt(rea,N,3))
allocate(Di(rea,N,3))
allocate(aux1(rea,N))
allocate(aux2(rea,N))
allocate(aux3(rea,N))
allocate(aux4(rea,N))
allocate(nr(nnr))
allocate(hidrodinamica_aux1(N,3))
allocate(hidrodinamica_aux2(N,3))
allocate(contribuicao_self(rea,N))
allocate(contribuicao_fisico(rea,N))
allocate(contribuicao_reciproco(rea,N))
allocate(hidro1(nb,3))
allocate(hidro2(nbr,3))
if(tmagper)then
allocate(auxt(N,3))
allocate(torquereal(nb,3))
allocate(torquereciproco(nbr,3))
allocate(cof4(2,10000))
allocate(cof5(2,10000))
allocate(cof7(2,10000))
end if
if(fmagper) then
allocate(cof6(2,10000))
allocate(cof8(2,10000))
allocate(auxf(N,3))
allocate(forcareal(nb,3))
allocate(forcareciproca(nbr,3))
end if
allocate(ILF(nb,3))
allocate(ILR(nbr,3))
allocate(XI(nb,rea,N,3))
allocate(cof1(2,10000))
allocate(cof2(2,10000))
allocate(cof3(2,10000))
if(leito)then
allocate(usistema(rea,3))
end if
if(grafmag)then
allocate(magtempo(3,npast))
allocate(flutmag(N,rea))
end if
allocate(tempototal(npast))
if(agregado_inicial) then
allocate(centro_massa(rea,3))
end if
allocate(DIAM(rea,N))
allocate(beta(rea,N))
allocate(diarand(rea*N))
allocate(campo(npast))
allocate(y(npast))
end subroutine allocatevariables
!*************************************************!
! SIMMSUS !
!SUBROUTINE: particle_distribution !
!Last update: 16/07/2023 !
!*************************************************!
subroutine particle_distribution
if(polidispersidade)then
call randomica(1.5,2.5,diarand,(N*rea),8)
do j=1,rea
do i=1,N
DIAM(j,i)=diarand((j-1)*N + i)
end do
end do
else
do j=1,rea
do i=1,N
DIAM(j,i)=2.0
end do
end do
end if
do j=1,rea
do i=1,n
beta(j,i) = DIAM(j,i)/DIAM(j,1)
end do
end do
end subroutine particle_distribution
!*************************************************!
! SIMMSUS !
!SUBROUTINE: box_size !
!Last update: 16/07/2023 !
!*************************************************!
subroutine box_size
if(agregado_inicial) then
ragreg=(N/phi)**(1.0/3.0)
l=100.0*ragreg
h=l
else
l=((N/(razao*phi))*(4.0*3.1416)/(3.0))**(1.0/3.0)
razao2=razao
h=razao2*l
end if
end subroutine box_size
!*************************************************!
! SIMMSUS !
!SUBROUTINE: gera_arquivos !
!Last update: 16/07/2023 !
!*************************************************!
!*************************************************!
! Subroutine responsible for creating all the fi- !
! les used in the simulation !
!*************************************************!
subroutine gera_arquivos(a,b,c)
logical a,b
integer c,i
! Subtitle of the units used for file storage
! From 1 to rea -> posicao.plt
! From rea+1 to 2*rea -> velocidade.plt
! From 2*rea+1 to 3*rea -> dipolo.plt
! From 3*rea+1 to 4*rea -> dip_parcial.plt
! 5*rea -> mag_tempo.plt
! 100*rea-> particula_teste.plt
! 200*rea-> distribuicao_agregados.plt
! 300*rea -> duffing_field.plt
! 1093*j para j=1,rea -> phi_local.plt
! 2012*j para j=1,rea -> energia.plt
! From 400*rea +1 to 400*rea + nfreq
! Creating a file that will be used to plot the trajectory of an arbitrary test particle
open(100*c,file='test_particle.plt')
write(100*c,*) 'Variables="X","Y","Z","Dx","Dy","Dz","t"'
if(bifurcation.or.bifshear) then
do i=1,nfreq
write(rea_char, '(I3)') i
open (400*c+i,file='magnetization'//rea_char//'.plt')
write(400*c+i,*) 'Variables="H","dH/dt","Mx","My","Mz","dMx","dMy","dMz","t"'
end do
end if
if(duffing) then
open(300*c,file='duffing_field.plt')
write(300*c,*)'Variables="t","H(t)","dH/dt"'
end if
if(fator)then
open(6*rea,file='structure_factor.plt')
end if
! Creating the files for each realization
if(a)then
do i=1,c
write(rea_char, '(I3)') i
if(.not.ovito)then
open (i,file='position'//rea_char//'.plt')
else
open (i,file='position'//rea_char//'.xyz')
end if
if(.not.ovito)then
if(gravadipolo) then
write(i,*) 'Variables="X","Y","Z","Dx","Dy","Dz","D"'
else
write(i,*) 'Variables="X","Y","Z","D"'
end if
end if
end do
end if
if(b)then
do i=1,c
write(rea_char, '(I3)') i
open (c+i,file='velocity'//rea_char//'.plt')
write(c+i,*) 'Variables="U","V","W"'
end do
end if
if(grafmag) then
open(5*c,file='magnetization.plt')
write(5*c,*)'Variables="H","dH/dt","Mx","My","Mz","dMx","dMy","dMz","t"'
end if
if(printphi) then
do i=1,rea
write(rea_char, '(I3)') i
open (1093*i,file='local_phi'//rea_char//'.plt')
write(1093*i,*) 'Variables="X","Y","Z","Phi"'
end do
end if
! Right now all the necessary files for storaging the position,
! velocity, magnetization and other important physical variables
! have been created!
write(*,*) 'All output files have been created'
write(*,*) ''
end subroutine gera_arquivos
!*************************************************!
! SIMMSUS !
!SUBROUTINE: tabelagreen !
!Last update: 16/07/2023 !
!*************************************************!
!************************************************!
! Subroutine resposible for pre-calculating the !
! Green functions used in the calculation of pe- !
! riodic interactions, due to hydrodynamic for- !
! ces and magnetic forces and torques. !
! This procedure is done to decrease the compu- !
! tational cost, since theses functions are pre- !
! calculated only once and are simply called any-!
! time a force or torque on a particle is calcu- !
! lated through the code in future loops. !
!************************************************!
subroutine tabelagreen(a,e,f,g,y)
real a ! parameter "qsi" of the sum convergence
real RR1,RR2,RR3,RR4,SIG,SIG2,SIG3,SIG4,SIG5,SIG7 ! auxiliary parameters used to compute these functions
real b(2,10000), c(2,10000), d(2,10000), tb(2,10000), tc(2,10000),td(2,10000), tf(2,10000) ! periodic torques coefficient
integer f,g,i ! f = nb e g = nbr
real e,y ! e=l, y=h
real pi, RR7, RR5, te(2,10000)
pi=acos(-1.0)
! Making a table with all the coefficients
do i=1,10000
b(1,i)=2.0+(i-1)*(((3.0**0.5)*e*(f**(1.0/3.0)))/9999.0)
c(1,i)=b(1,i)
if(tmagper)then
tb(1,i)=b(1,i)
tc(1,i)=b(1,i)
end if
if(fmagper)then
td(1,i)=b(1,i)
end if
! Calculating the powers of all the possible distances between the particles
RR1=b(1,i)
RR2=b(1,i)**2.0
RR3=b(1,i)**3.0
RR4=b(1,i)**4.0
RR5=b(1,i)**5.0
RR7=b(1,i)**7.0
SIG=qsi
SIG2=qsi**2.0
SIG3=qsi**3.0
SIG4=qsi**4.0
SIG5=qsi**5.0
SIG7=qsi**7.0
! Computing the functions used to calculate hydrodynamic interactions (in real space)
if(ligaih) then
b(2,i) = (0.75/RR1 + 0.5/RR3)*ERFC(SIG*RR1) + (4.0*SIG7*RR4 + 3.0*SIG3*RR2 - &
& 20.0*SIG5*RR2 - 4.50*SIG + 14.0*SIG3 + SIG/RR2)*EXP(-SIG2*RR2)/SQRT(pi)
c(2,i) = (0.75/RR1 - 1.5/RR3)*ERFC(SIG*RR1) + (-4.0*SIG7*RR4 - 3.0*SIG3*RR2 + &
& 16.0*SIG5*RR2 + 1.50*SIG - 2.0*SIG3 - 3.0*SIG/RR2)*EXP(-SIG2*RR2)/SQRT(pi)
end if
! Computing the functions used to calculate periodic magnetic torques (in real space)
if(tmagper)then
tb(2,i)=(ERFC(SIG*RR1)+ ((2.0*SIG*RR1)/(SQRT(pi)))*EXP(-SIG2*RR2))/RR3
tc(2,i)=(3.0*ERFC(SIG*RR1) + (((2.0*SIG*RR1)/(SQRT(pi)))*(3.0+(2.0*SIG2*RR2))*EXP(-SIG2*RR2)))/RR5
end if
! Computing the functions used to calculate periodic magnetic forces (in real space)
if(fmagper)then
td(2,i)=(15.0*ERFC(SIG*RR1)+ ((2.0*SIG*RR1)/(SQRT(pi)))*(15.0+(10.0*SIG2*RR2+4.0*SIG4*RR4))*EXP(-SIG2*RR2))/RR7
end if
! Same procedure done now for the reciprocal space
! Calculating all possible wave numbers
if(g**(1.0/3.0).eq.5.0)then
d(1,i)= (2.0*pi/e)+ ((i-1)*(((4.0*(3.0**0.5)*pi/e)-(2.0*pi/e))/9999.0))
end if
if(g**(1.0/3.0).eq.3.0)then
d(1,i)= (2.0*pi/e)+ ((i-1)*(((2.0*(3.0**0.5)*pi/e)-(2.0*pi/e))/9999.0))
end if
! Determining the 2th and 4th powers of these possible wave numbers
RR2=d(1,i)**2.0
RR4=d(1,i)**4.0
! Computing the functions used to calculate hydrodynamic interactions (in reciprocal space)
if(ligaih) then
d(2,i)=(1.0/(e*e*y))*(1.0 - 1.0*RR2/3.0)*(1.0 + 0.25*RR2/SIG2 + 0.125*RR4/SIG4)*&
& 6.0*pi*EXP(-0.25*RR2/SIG2)/RR2
end if
! Computing the functions used to calculate periodic magnetic torques (in reciprocal space)
if(tmagper)then
te(1,i)=d(1,i)
te(2,i)=-(1.0/(e*e*y))*(4.0*pi*(EXP(-((pi/e)**2.0)*RR2/SIG2)))/1.0 !RR2
end if
! Computing the functions used to calculate periodic magnetic forces (in reciprocal space)
if(fmagper)then
tf(1,i)=d(1,i)
tf(2,i)=((8.0*(pi**2.0))/((e**4.0)*(RR2)))*EXP(-((pi**2.0)*RR2)/(SIG2*(e**2.0)))/RR2
end if
end do
cof1=b
cof2=c
cof3=d
if(tmagper)then
cof4=tb
cof5=tc
cof7=te
end if
if(fmagper) then
cof6=td
cof8=tf
end if
end subroutine tabelagreen
!*************************************************!
! SIMMSUS !
!SUBROUTINE: estrutura_periodica !
!Last update: 16/07/2023 !
!*************************************************!
!*************************************************!
! Suroutine responsible for creating a periodic !
! strucutre (lattice) containing copies of a phy- !
! sical cell with the interacting particles repli-!
! cated through the real and reciprocal spaces !
! using the Ewald summation technique (1921) des- !
! cribed in details in the works of Beenakker !
! (1986), Abade (2002), Gontijo (2013) !
!*************************************************!
subroutine estrutura_periodica
integer auxper(5), auxper2(5), auxper3(5)
pi=acos(-1.0)
! Creating the lattices indeces in the real space
auxper=0
if(nb**(1.0/3.0).eq.5.0)then
auxper(1)=1
auxper(2)=2
auxper(3)=3
auxper(4)=4
auxper(5)=5
auxper2(1)=0
auxper2(2)=5
auxper2(3)=10
auxper2(4)=15
auxper2(5)=20
auxper3(1)=0
auxper3(2)=25
auxper3(3)=50
auxper3(4)=75
auxper3(5)=100
end if
if(nb**(1.0/3.0).eq.3.0)then
auxper(1)=1
auxper(2)=2
auxper(3)=3
auxper2(1)=0
auxper2(2)=3
auxper2(3)=6
auxper3(1)=0
auxper3(2)=9
auxper3(3)=18
end if
do a=1,(nb**(1.0/3.0))
do b=1,(nb**(1.0/3.0))
do c=1,(nb**(1.0/3.0))
! Number of physical boxes
s=auxper3(a)+ auxper2(b) +auxper(c)
if(nb**(1.0/3.0).eq.5.0) then
ILF(s,1)=a-3
ILF(s,2)=b-3
ILF(s,3)=c-3
end if
if(nb**(1.0/3.0).eq.3.0) then
ILF(s,1)=a-2
ILF(s,2)=b-2
ILF(s,3)=c-2
end if
end do
end do
end do
! Creating the initial configuration of all the physical lattices
do a=1,nb
do b=1,rea
do i=1,N
XI(a,b,i,1)= X(b,i,1) + ILF(a,1)*l
XI(a,b,i,2)= X(b,i,2) + ILF(a,2)*l
XI(a,b,i,3)= X(b,i,3) + ILF(a,3)*h
end do
end do
end do
if(k.eq.1)then
open(872,file='condicao_inicial_periodica.plt')
write(872,*)'Variables= "X1","X2","X3"'
do a=1,nb
do b=1,N
write(872,*) XI(a,1,b,1),XI(a,1,b,2),XI(a,1,b,3)
end do
end do
end if
! Creating the lattice's indeces in the reciprocal space
if(nbr**(1.0/3.0).eq.5.0)then
auxper(1)=1
auxper(2)=2
auxper(3)=3
auxper(4)=4
auxper(5)=5
auxper2(1)=0
auxper2(2)=5
auxper2(3)=10
auxper2(4)=15
auxper2(5)=20
auxper3(1)=0
auxper3(2)=25
auxper3(3)=50
auxper3(4)=75
auxper3(5)=100
end if
if(nbr**(1.0/3.0).eq.3.0)then
auxper(1)=1
auxper(2)=2
auxper(3)=3
auxper2(1)=0
auxper2(2)=3
auxper2(3)=6
auxper3(1)=0
auxper3(2)=9
auxper3(3)=18
end if
do a=1,(nbr**(1.0/3.0))
do b=1,(nbr**(1.0/3.0))
do c=1,(nbr**(1.0/3.0))
! Number of reciprocal lattices
s=auxper3(a)+ auxper2(b) +auxper(c)
if(nbr**(1.0/3.0).eq.5.0) then
ILR(s,1)=a-3
ILR(s,2)=b-3
ILR(s,3)=c-3
end if
if(nbr**(1.0/3.0).eq.3.0) then
ILR(s,1)=a-2
ILR(s,2)=b-2
ILR(s,3)=c-2
end if
end do
end do
end do
end subroutine estrutura_periodica
!*************************************************!
! SIMMSUS !
!SUBROUTINE: distribui_dipolo !
!Last update: 16/07/2023 !
!*************************************************!
!*************************************************!
! Subroutine responsible for creating an initial !
! distribution of the dipole moments of all parti-!
! cles in all realizations !
!*************************************************!
subroutine distribui_dipolo(a,b,c)
integer b,c ! b= number of realizations, c= number of particles
real a(b,c,3) ! Dipoles
real d,e !
integer f
! If dipoles are distributed in an ordered way
if(dipolo_ordenado) then
do j=1,rea
do i=1,N
a(j,i,1)=0.0
a(j,i,2)=1.0
a(j,i,3)=0.0
end do
end do
else
! For a random dipole distribution
e=percentual*c
f=e
call randomica(-1.0,1.0,nr,(3*N*rea),3)
! If we are mixing magnetic particles with non magnetic ones...
if(mistura)then
!$OMP PARALLEL DO
do j=1,b
do i=1,f
a(j,i,1)= 0.0
a(j,i,2)= 0.0
a(j,i,3)= 0.0
end do
end do
!$OMP END PARALLEL DO
!$OMP PARALLEL DO
do j=1,b
do i=f+1,c
a(j,i,1)= nr((i*2+(i-2)+(c*3*(j-1))))
a(j,i,2)= nr((i*2+(i-1)+(c*3*(j-1))))
a(j,i,3)= nr((i*2+(i)+(c*3*(j-1))))
end do
end do
!$OMP END PARALLEL DO
! Normalizing the vectors
!$OMP PARALLEL DO
do j=1,b
do i=1,f
a(j,i,1)= 0.0
a(j,i,2)= 0.0
a(j,i,3)= 0.0
end do
end do
!$OMP END PARALLEL DO
!$OMP PARALLEL DO
do j=1,b
do i=f+1,N
d=((a(j,i,1)**2.0)+(a(j,i,2)**2.0)+(a(j,i,3)**2.0))**0.5
a(j,i,1)=a(j,i,1)/d
a(j,i,2)=a(j,i,2)/d
a(j,i,3)=a(j,i,3)/d
end do
end do
!$OMP END PARALLEL DO
Di=a
else
! If all the particles are magnetic particles, then...
!$OMP PARALLEL DO
do j=1,b
do i=1,c
a(j,i,1)= nr((i*2+(i-2)+(c*3*(j-1))))
a(j,i,2)= nr((i*2+(i-1)+(c*3*(j-1))))
a(j,i,3)= nr((i*2+(i)+(c*3*(j-1))))
end do
end do
!$OMP END PARALLEL DO
! Normalizing the vectors
!$OMP PARALLEL DO
do j=1,rea
do i=1,N
d=((a(j,i,1)**2.0)+(a(j,i,2)**2.0)+(a(j,i,3)**2.0))**0.5
a(j,i,1)=a(j,i,1)/d
a(j,i,2)=a(j,i,2)/d
a(j,i,3)=a(j,i,3)/d
end do
end do
!$OMP END PARALLEL DO
Di=a
end if
end if
end subroutine distribui_dipolo
!*************************************************!
! SIMMSUS !
!SUBROUTINE: condicao_inicial !
!Last update: 16/07/2023 !
!*************************************************!
!*************************************************!
! Subroutine responsible for creating the initial !
! particle distribution for all simultaneous !
! numerical experiments. !
! !
! Several possible initial configurations are im- !
! plemented here. These include: !
! !
! 1 - An initial random distribution !
! 2 - An ordered NxNxN array of particles !
! 3 - An initial spherical aggregate !
!*************************************************!
subroutine condicao_inicial
integer auxiliar1, loop, loop2
! If you have to continue a previous simulation, then get into this "if clause"
if(continua) then
! Opening the "particula_teste.plt" file in which we print the trajectory of an
! arbitrary test particle
open(100*rea,file='particula_teste.plt', STATUS='OLD')
! Defining important file's format
509 FORMAT(F30.4,F30.4,F30.4)
666 FORMAT(F30.4,F30.4,F30.4,F30.4,F30.4,F30.4,F30.4)
! Opening velocity files
do i=1,rea
write(rea_char, '(I3)') i
open (rea+i,file='velocidade'//rea_char//'.plt', STATUS='OLD')
end do
! Reading the velocities of all the particles in several files (one file per realization)
do j=1,rea
read (rea+j,'(A)') linha1
do k=1,(iter/n2)
read(rea+j,'(A)') linha2
do i=1,N
read(rea+j,509)U(j,i,1),U(j,i,2),U(j,i,3)
end do
end do
end do
! Opening position files
do i=1,rea
write(rea_char, '(I3)') i
open (i,file='posicao'//rea_char//'.plt', STATUS='OLD')
end do
! Reading the position and dipole moments of all the particles (in order to define a configuration from which the
! simulation must continue, we need to know not only the final position of the particles, but also their orientation
do j=1,rea
read (j,'(A)') linha1
do k=1,(iter/n2)
read(j,'(A)') linha2
do i=1,N
read(j,666)X(j,i,1),X(j,i,2),X(j,i,3),Di(j,i,1),Di(j,i,2),Di(j,i,3),DIAM(j,i)
end do
end do
end do
else
! If we are starting a new simulation, then we will check if the initial condition is a spherical aggregate
if(agregado_inicial) then
open(666,file='vel_tempo.plt')
write(666,*)'Variables="t","Ux","Uy","Uz"'
! Calculating the aggregate's radius
ragreg=(N/phi)**(1.0/3.0)
! Inserting the aggregate in a giant lattice to avoid periodicity condition
l=100.0*ragreg
h=l
call randomica(-1.0,1.0,nr,(3*N*rea),5)
! Defining the center of the aggregate
xcentro=l/2.0
ycentro=l/2.0
zcentro=h - 2.0*ragreg
do j=1,rea
do i=1,N
! Range of X position of the particles in the aggregate
xmin= l/2.0 - ragreg
xmax= xmin + 2.0*ragreg
X(j,i,1)= xcentro + (xmax-xmin)*0.5*nr((i*2+(i-2)+(N*3*(j-1))))
! Using the circle equation to distribute the particles in the y direction (sphere projection on a xy plane)
ymin=ycentro-(ragreg**2.0 -(X(j,i,1)-xcentro)**2.0)**0.5
ymax=ycentro+(ragreg**2.0 -(X(j,i,1)-xcentro)**2.0)**0.5
X(j,i,2)= ycentro +(ymax-ymin)*0.5*nr((i*2+(i-1)+(N*3*(j-1))))
! Using the circle equation to define the z positions considering now the sphere projection on planes zy and zx
zmin=zcentro-(ragreg**2.0 -(X(j,i,1)-xcentro)**2.0 -(X(j,i,2)-ycentro)**2.0)**0.5
zmax=zcentro+(ragreg**2.0 -(X(j,i,1)-xcentro)**2.0 -(X(j,i,2)-ycentro)**2.0)**0.5
X(j,i,3)= zcentro +(zmax-zmin)*0.5*nr((i*2+(i)+(N*3*(j-1))))
end do
end do
write(*,*) 'O raio do agregado e:',ragreg
write(*,*) 'A largura do box e:', l
write(*,*) 'A altura do box e:',h
! Checking for particle overlaping in the initial condition
118 call randomica(-1.0,1.0,nr,(3*N*rea),6)
! Calculating the center of mass of the aggregate
centro_massa(k,1)=sum(X(k,:,1))/N
centro_massa(k,2)=sum(X(k,:,2))/N
centro_massa(k,3)=sum(X(k,:,3))/N
else
! If you want to create an ordered distribution then...
if(ordenado) then
!$OMP PARALLEL DO
do j=1,rea
loop=0
loop2=0
do i=1,N
reale= (i-1.0)/(n**(1.0/3.0))
inteiro= (i-1)/(n**(1.0/3.0))
reale2= (loop+1.0)/(n**(1.0/3.0))
inteiro2= (loop+1)/(n**(1.0/3.0))
if(reale.ne.0.0)then
if(reale.eq.inteiro) then
loop=loop+1
end if
end if
if(reale2.ne.1.0) then
if(reale2.eq.inteiro2) then
loop2=loop2+1
end if
end if
auxiliar1=i/(N**(2.0/3.0))
a=i-loop*(N**(1.0/3.0))
b=1+loop-auxiliar1*(N**(1.0/3.0))
c=i/(N**(2.0/3.0))
X(j,i,1)= l/(2.0*(N**(1.0/3.0))) + (a)*(l-(l/(N**(1.0/3.0))))/((N**(1.0/3.0))-1.0)
X(j,i,2)= l/(2.0*(N**(1.0/3.0))) + (b)*(l-(l/(N**(1.0/3.0))))/((N**(1.0/3.0))-1.0)
X(j,i,3)= h/(2.0*(N**(1.0/3.0))) + (c)*(h-(h/(N**(1.0/3.0))))/((N**(1.0/3.0))-1.0)
end do
end do
!$OMP END PARALLEL DO
else
! If you want to generate a random initial distribution, then you must call the random number generation routine...
call randomica(0.0,1.0,nr,(3*N*rea),1)
!$OMP PARALLEL DO
do j=1,rea
do i=1,N
X(j,i,1)=0.0+(l-0.0)*nr((i*2+(i-2)+(N*3*(j-1))))
X(j,i,2)=0.0+(l-0.0)*nr((i*2+(i-1)+(N*3*(j-1))))
X(j,i,3)=0.0+(h-0.0)*nr((i*2+(i)+(N*3*(j-1))))
end do
end do
!$OMP END PARALLEL DO
! Now that we already created an initial random configuration, we must check for particle overlaps
! We call the random number generation subroutine
!$OMP PARALLEL DO
do k=1,rea
do i=1,N
do j=1,N
103 call randomica(-1.0,1.0,nr,3,2)
if(i.ne.j)then
! Calculate the distance between all the pair of particles in the suspension
r=((X(k,i,1)-X(k,j,1))**2.0+(X(k,i,2)-X(k,j,2))**2.0+(X(k,i,3)-X(k,j,3))**2.0)**0.5
! If at any point the distance is smaller then 0.01*a, then we give a Brownian kick in the overlaped particles
if(r.le.2.01)then
! Creating a small random vector used to "kick" one of the overlaped particles
nr1=nr(1)
nr2=nr(2)
nr3=nr(3)
modrand=((nr1**2.0)+(nr2**2.0)+(nr3**2.0))**0.5
! Normalizing this vector
nr1=nr1/modrand
nr2=nr2/modrand
nr3=nr3/modrand
nr1=nr1*0.25
nr2=nr2*0.25
nr3=nr3*0.25
! Changing the position of one of the overlaped particles with a Brownian "kick"
X(k,i,1)=X(k,i,1)+nr1
X(k,i,2)=X(k,i,2)+nr2
X(k,i,3)=X(k,i,3)+nr3
end if
! Calculate the new distance between the "problematic" particles
r=((X(k,i,1)-X(k,j,1))**2.0+(X(k,i,2)-X(k,j,2))**2.0+(X(k,i,3)-X(k,j,3))**2.0)**0.5
! If at any point the particles are still overlaped we give new
! Brownian kicks in the particles that present this problem until the
! situation is solved
if(r.le.2.01)then
go to 103
end if
! Imposing conditions to avoid particles outside the box
if(X(k,i,1).lt.0) then
X(k,i,1)=abs(X(k,i,1))
go to 103
end if
if(X(k,i,2).lt.0) then
X(k,i,2)=abs(X(k,i,2))
go to 103
end if
if(X(k,i,3).lt.0) then
X(k,i,3)=abs(X(k,i,3))
go to 103
end if
if(X(k,i,1).gt.(l)) then
X(k,i,1)=X(k,i,1) - l
go to 103
end if
if(X(k,i,2).gt.(l)) then
X(k,i,2)=X(k,i,2) - l
go to 103
end if
if(X(k,i,3).gt.(h)) then
X(k,i,3)=X(k,i,3) - h
go to 103
end if
end if
end do
end do
end do
!$OMP END PARALLEL DO
end if
! Lets define the initial velocity of the particles as the Stokes velocity (mobility problem)
!$OMP PARALLEL DO
do j=1,rea
do i=1,N
U(j,i,1)=0.0
U(j,i,2)=0.0
U(j,i,3)=-1.0
end do
end do
!$OMP END PARALLEL DO
end if
end if
end subroutine condicao_inicial
!*************************************************!
! SIMMSUS !
!SUBROUTINE: field_excitations !
!Last update: 16/07/2023 !
!*************************************************!
!*************************************************!
! Subroutine resonsible for pre-calculating the !
! magnetic field excitation and shear-rate ramp in!
! case the user wants to build a bifurcation dia- !
! gram of the magnetization response !
! !
! The following possibilities are considered for !
! the magnetic field H(t) !
! !
! 1 - H(t) as a solution of the Duffing oscilator !
! 2 - H(t) = cos(w1*t) + cos(w2*t) !
! 3 - H(t) = sin(w*t) [oscillatory field] !
! 4 - H(t) = sin(i*w*t) [i varying periodically] !
! 5 - H(t) = sin(w*t)ex + cos(w*t)ey [rotating] !
! !
! Field excitation number 4 implies that the field!
! frequency will periodically change as the simula!
! tion evolves. This is useful to build bifurca- !