-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolver.f90
More file actions
2790 lines (2581 loc) · 110 KB
/
Copy pathsolver.f90
File metadata and controls
2790 lines (2581 loc) · 110 KB
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
!------------------------------------------------------------------------------
!
! MODULE: solver
!
!! DESCRIPTION:
!> This module implements the NS solver for scalars and velocities.
!> @author
!> Guillaume Balarac et Patrick BEGOU, LEGI
!>
!> @details
!! This solver implements the numerical schemes to solve diffusion, advection and NS equations.
!> @author
!> Guillaume Balarac et Patrick BEGOU, LEGI
!------------------------------------------------------------------------------
MODULE solver
use differential_tools
USE precision_tools
USE datalayout
!USE real_4D_datalayout
USE param
USE plasticflow
USE wavenumber_tools
USE parallel_tools
USE data
USE rediscretization_tools
USE forcing
USE forcing_scalar
!USE subgridmodels
IMPLICIT NONE
!> Storage for L.E.S. models for scalars
INTEGER, DIMENSION(:), POINTER, PRIVATE :: ilessc
!> Storage for the L.E.S. model for velocities
INTEGER, PRIVATE :: iles
INTEGER, PRIVATE :: time_integration
!> Storage of setup about forcing term on scalar i- scalars advected with pseudo-spectral solver
integer, dimension(:), allocatable, private :: sc_spec_forc
!> Viscosity, Default to 1E-02
REAL(WP), PRIVATE :: mu
! XXX TODO - Delete when new RK is validate --
! ===== Storage of the spectral values of field at the RK intermediate step =====
!> Storage for the Spectral values of U at step i-1 for RK2
TYPE(COMPLEX_DATA_LAYOUT), PRIVATE, SAVE :: UkOld,sigmakOld
!> Storage for the Spectral values of V at step i-1 for RK2
TYPE(COMPLEX_DATA_LAYOUT), PRIVATE, SAVE :: VkOld
!> Storage for the Spectral values of W at step i-1 for RK2
TYPE(COMPLEX_DATA_LAYOUT), PRIVATE, SAVE :: WkOld
!> Storage for the spectral values of each scalar at step i-1 for RK2
TYPE(COMPLEX_DATA_LAYOUT),ALLOCATABLE, DIMENSION(:), PRIVATE :: ScalArraykOld
!> Storage of setup about forcing term on scalar i- scalars advected with particles method
integer, dimension(:), allocatable, private :: sc_part_forc
! MHD variables
!> Magnetic Prandl number, Default to 0E+00
REAL(WP), PRIVATE :: Prm
!> Storage for the Spectral values of B at step i-1 for RK2
TYPE(COMPLEX_DATA_LAYOUT), ALLOCATABLE, DIMENSION(:), PRIVATE :: BkOld
! External imposed magnetic field
!> External imposed Bx
REAL(WP), PRIVATE :: Bxext
!> External imposed By
REAL(WP), PRIVATE :: Byext
!> External imposed Bz
REAL(WP), PRIVATE :: Bzext
!> G (propagator) and sigmak complex layout for the Fourier transform
!TYPE(COMPLEX_DATA_LAYOUT) :: sigmak,G
!> Velocity used to advect scalar field solved with particle/spectral method
!! (as velocity is computed separatly from the velocity - a "trapeze" method is used)
TYPE(REAL_DATA_LAYOUT) , PRIVATE, SAVE :: U_mean
TYPE(REAL_DATA_LAYOUT) , PRIVATE, SAVE :: V_mean
TYPE(REAL_DATA_LAYOUT) , PRIVATE, SAVE :: W_mean
TYPE(COMPLEX_DATA_LAYOUT), PRIVATE, SAVE :: Uk_mean
TYPE(COMPLEX_DATA_LAYOUT), PRIVATE, SAVE :: Vk_mean
TYPE(COMPLEX_DATA_LAYOUT), PRIVATE, SAVE :: Wk_mean
!> To choose the right time integration
!LUCA: I made public the solve_Euler_luca
private ::solve_spec_Euler, solve_spec_RK2, solve_spec_RK4, solve_spec_AB2, solve_spec_AB3
!procedure(solve_spec_Euler), pointer, private :: solve_spec_basic => solve_spec_RK2
procedure(solve_spec_Euler), pointer, private :: solve_spec_basic => NULL()
!> Storage for intermadiate point, save and reconstruction of non-linear
!term in RK and Adam-Smith time schemes
TYPE(COMPLEX_DATA_LAYOUT), ALLOCATABLE, DIMENSION(:),PRIVATE, SAVE :: Uk_sav,Vk_sav,Wk_sav
TYPE(COMPLEX_DATA_LAYOUT), ALLOCATABLE, DIMENSION(:,:),PRIVATE, SAVE :: Bk_sav, Scalk_sav
TYPE(COMPLEX_DATA_LAYOUT), DIMENSION(3),PRIVATE, SAVE :: Fk_sav
!> Number of field to save
INTEGER :: save_size, dt_save
LOGICAL :: forcing_save
!> Save of previous time step for AB schemes
real(WP), allocatable, dimension(:), private, save :: dt_prev
!> total simulation time
REAL(WP), PROTECTED :: sim_time
!>timestep
REAL(WP), PROTECTED ::step_time
!>timestep
REAL(WP), PROTECTED ::dtn0,dtn22
!> number of scalars fields requested
INTEGER, PRIVATE :: nbscal=0
!> number of scalars fields requested
INTEGER, PRIVATE :: nbscal_part=0
!> forcing requested
INTEGER, PRIVATE :: iforce=0
!> forcing amplitude for scalar forcing
REAL(WP), DIMENSION(:), POINTER, PRIVATE :: amplitude_sf
!> lower bound of wavenumber shell of scalar forcing
REAL(WP), DIMENSION(:), POINTER, PRIVATE :: kmin_sf
!> upper bound of wavenumber shell of scalar forcing
REAL(WP), DIMENSION(:), POINTER, PRIVATE :: kmax_sf
!> forcing amplitude for scalar forcing
REAL(WP), DIMENSION(:), POINTER, PRIVATE :: amplitude_part_sf
!> lower bound of wavenumber shell of scalar forcing
REAL(WP), DIMENSION(:), POINTER, PRIVATE :: kmin_part_sf
!> upper bound of wavenumber shell of scalar forcing
REAL(WP), DIMENSION(:), POINTER, PRIVATE :: kmax_part_sf
!> coefficient for stability condition in the particle solver
REAL(WP), PRIVATE :: part_stab_coeff=0
type(COMPLEX_DATA_LAYOUT), allocatable, dimension(:), public:: divTub
PRIVATE wavesNumber_init
PRIVATE deleteWavesNumber
!PRIVATE firstTerm
!PRIVATE secondTerm
!PRIVATE non_linear_vel
!PRIVATE non_linear_scal
!PRIVATE non_linear_mhd
!PRIVATE mhd_velocity_coupling
! PRIVATE part_spec_step
! PRIVATE part_spec_step_fullPart
!procedure(part_spec_step), pointer, private :: part_solver_step => part_spec_step
! procedure(part_spec_step), pointer, private :: part_solver_step => NULL()
! PRIVATE solve_velo_ScalSpec_basic
! PRIVATE solve_velo_ScalSpec_subcycle
LOGICAL, PRIVATE :: initialized=.FALSE.
COMPLEX(WP), PRIVATE, PARAMETER :: ii=(0.0_WP,1.0_WP)
!> Solve Navier-Stokes equation for velocity and advection-diffusion equation
!! for scalar (solved with full pseudo-spectral solver).
CONTAINS
!------------------------------------------------------------------------------
!> @author
!> Luca Marradi
!
!> @details
!> This function initialize the solver module
!> @param [in,out] G the propagator
!> @param [in,out] sigma longitudinal velocity
!> @param [in] nbcpus the total amount of processes (or cpus)
!> @param [in] spec_rank my MPI processe rank in the range [0:nbcpus-1]
!> @param [out] current_time = simulation time
!> @return .TRUE. if initialization is successfull.
!------------------------------------------------------------------------------
FUNCTION initSolver_luca (convol,n_activ,sigmak,G,sigma,sigma_old,Esigma,Lsigma,gammadot_min,current_time, nbcpus,spec_rank)
USE cart_topology
USE differential_tools
IMPLICIT NONE
!=== INPUT/OUTPUT ===
INTEGER, INTENT(IN) :: nbcpus,spec_rank
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: sigma,sigma_old
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: Esigma,Lsigma,n_activ,convol
TYPE(COMPLEX_DATA_LAYOUT), INTENT(INOUT) :: G,sigmak
TYPE(WaveNumbers) :: kWN
REAL(WP), INTENT(IN) :: gammadot_min
REAL(WP), INTENT(OUT) :: current_time
!=== LOCAL DATA ===
LOGICAL initSolver_luca
REAL(WP) :: delt
INTEGER :: i,j,k,ierr,start
CHARACTER(len=str_long) :: request
CHARACTER(len=4) :: advec_solver ! choose advection solver (p_ON = particle method at order N, N = 2 or 4)
CHARACTER(len=4) :: advec_interp! choose advection solver (p_ON = particle method at order N, N = 2 or 4)
INTEGER :: ishowdiv
CHARACTER(LEN=str_long) :: sim_name
CHARACTER(LEN=str_long) :: les_name
CHARACTER(LEN=str_long) :: TimeMethod_name
CHARACTER(LEN=str_long) :: null_firstWN
LOGICAL :: res ! result return by the function
integer :: disc_init ! to init scalars to a disc shape.
! For particles method and assoicated scalar
LOGICAL :: advanced ! to know if group size is set manually or not.
INTEGER :: gp_size ! particle solver gather line by group. It allow to choose group size
INTEGER,DIMENSION(3) :: gp_size_array ! particle solver gather line by group. It allow to choose group size
initSolver_luca=.FALSE.
! Initial time
if (parser_is_defined('Initial time')) then
call parser_read('Initial time', sim_time)
else
sim_time = 0.0_WP
end if
current_time = sim_time
!=== INITIALIZES THE WAVENUMBER FOR SIGMA ===
IF(.NOT.wavesNumber_init(kWN,spec_rank,sigma%Lx,sigma%Ly,sigma%Lz,sigma%nx,sigma%ny,sigma%nz)) THEN
WRITE(6,'(a,i0,a)')'[ERROR] init solver on process ',spec_rank,': wave-number for velocity field not initialize'
RETURN
ENDIF
!=== GET INTEGRATION SCHEME ===
CALL parser_read('Integration Method',TimeMethod_name)
forcing_save = .false.
time_integration = 1
if (trim(TimeMethod_name)=='RK4') then
solve_spec_basic => solve_spec_RK4
save_size = 2
dt_save = 0
else if (trim(TimeMethod_name)=='RK2') then
solve_spec_basic => solve_spec_RK2
save_size = 1
dt_save = 0
else if (trim(TimeMethod_name)=='AB2') then
solve_spec_basic => solve_spec_AB2_init
save_size = 1
dt_save = 1
else if (trim(TimeMethod_name)=='AB3') then
solve_spec_basic => solve_spec_AB3_init
save_size = 2
dt_save = 2
else if (trim(TimeMethod_name)=='EULER') then
solve_spec_basic => solve_spec_Euler
save_size = 0
dt_save = 0
else
solve_spec_basic => solve_spec_RK2
time_integration = 1
save_size = 1
dt_save = 0
end if
! Ask for the name of particular initial condition
CALL parser_read('Simulation name', sim_name)
!INITIAL CONDITION
IF (trim(sim_name).EQ.'plasticflow') THEN
IF(.NOT.initplasticflow(convol,n_activ,sigmak,G,sigma,sigma_old,Esigma,Lsigma &
& ,gammadot_min,kWN,nbcpus,spec_rank)) THEN
RETURN
ENDIF
ELSEIF(trim(sim_name).EQ.'Zero') THEN
sigma%values = 0.0_WP
ELSE
IF(spec_rank.EQ.0) WRITE(6,'(a)') '[ERROR] initSolver: unknown Simulation Name['// &
& TRIM(sim_name)//']'
RETURN
ENDIF
!== INITIALIZATION OF SIGMA YIELD ==
IF(.NOT.probabilityL(Lsigma,spec_rank)) THEN
CALL MPI_FINALIZE(ierr)
STOP 'FAILED to compute probability from elastic to plastic'
ENDIF
! I should define delt just once in the code
!delt=1./2.0_WP*acos(-1.0_WP)
! INITIALIZATION OF THE PROPAGATOR G
! DO k=G%zmin,G%zmax
! DO j=G%ymin,G%ymax
! DO i=G%xmin,G%xmax
! delt = (kWN%ky(j)**2_WP + kWN%kx(i)**2_WP)**2_WP
! IF (delt.LT.1.E-20) THEN
! delt = 10000_WP
! ENDIF
! delt=1_WP/delt
! !TESTED
! !!G%values(i,j,k) = spec_rank!delt * exp(-0.5*( (0.5)**2.) )
! !TESTED FOR NX=2500, NY=10, NZ=10
! !!G%values(i,j,k) = delt * exp(-0.5*( (kWN%kx(i) - kWN%kx(500))**2.)/100. )
! !TESTED
! !!G%values(i,j,k) = kWN%kx(i)**2_WP !* delt
! G%values(i,j,k) = -4_WP * (kWN%kx(i)**2_WP * kWN%ky(j)**2_WP) * delt
! !IF(spec_rank.EQ.0) print*, "G(",i,",",j,",",k,"):",REALPART(G%values(i,j,k))
! ENDDO
! ENDDO
! ENDDO
!TESTED
!! WAVENUMBER VALUES
!! IF(spec_rank.eq.0) THEN
!! OPEN(400,file='G-propagator.dat',form='formatted')
!! DO k=1,sigma%nz
!! DO j=1,sigma%ny
!! DO i=1,((sigma%nx)/2)+1
!! write(400,'(g15.8,1x)') kWN%kx(i), kWN%ky(j), kWN%kz(k)
!! ENDDO
!! ENDDO
!! ENDDO
!! CLOSE(400)
!!ENDIF
!! call btran(G,sigma,res)
!! DO k=1,sigma%nz
!! DO j=1,sigma%ny
!! DO i=1,(sigma%nx)/2 + 1
!!G_full(i,j,k) = delt * exp(-0.5*( (kWN%kx(i) - kWN%kx(500))**2.)/100.)
!G_full(i,j,k) = REALPART(G%values(i,j,k))
!! ENDDO
!! ENDDO
!! ENDDO
! Now check if we want to overide initialization with existing datafiles
!! IF (.NOT. data_read(sigma, spec_rank)) then
!! WRITE(6,'(a,i0)')'[ERROR] init solver - failed to read data on process',spec_rank
!! RETURN
!! end if
! CALL ftran(sigma,sigmaK,res)
! IF (.NOT. res) THEN
! WRITE(6,'(a)')'[ERROR] initSolver_luca: cannot initialize sigma in fourier space'
! RETURN
! ENDIF
!!if(.not. init_save(sigmak,save_size)) then
!! write(6,'(a,i0)') '[ERROR] iinit_solver: init_save failed'
!! return
!!end if
initialized=.TRUE.
initSolver_luca=.TRUE.
RETURN
END FUNCTION initSolver_luca
!------------------------------------------------------------------------------
!> @author
!> Patrick BEGOU, LEGI
!
!>
!> @details
!> This function free the memory used by solver module
!------------------------------------------------------------------------------
!SUBROUTINE deleteSolver (imhd, me)
!
! use differential_tools
!
! logical, INTENT(IN) :: imhd
! INTEGER, INTENT(IN), OPTIONAL ::me
! INTEGER :: i
!
! IF (.NOT. initialized) RETURN
!
! IF (PRESENT(me)) THEN
! IF(me .EQ. 0) WRITE(6,'(a,g15.8)') '[PROGRESSION] Simulation time reached: ',sim_time
! ENDIF
!
! if(.not. delete_save(save_size, imhd)) then
! write(6,'(a,i0)') '[ERROR] delete_solver: delete_save failed'
! return
! end if
!
! ! free velocities wave numbers
! CALL deleteWavesNumber(VelWN)
!
! ! free scalars wave numbers
! IF (ASSOCIATED(ScalWN)) THEN
! DO I=1, SIZE(ScalWN)
! CALL deleteWavesNumber(ScalWN(i))
! ENDDO
! DEALLOCATE(ScalWN)
! ENDIF
!
! IF (ASSOCIATED(Scal_partWN)) THEN
! DO I=1, SIZE(Scal_partWN)
! CALL deleteWavesNumber(Scal_partWN(i))
! ENDDO
! DEALLOCATE(Scal_partWN)
! ENDIF
!
! IF (ALLOCATED(ScalArrayK)) THEN
! DO I=1, SIZE(ScalArrayK)
! CALL deleteDataLayout(ScalArrayK(i))
! ENDDO
! DEALLOCATE(ScalArrayK)
! ENDIF
!
! IF (ALLOCATED(Scal_partArrayK)) THEN
! DO I=1, SIZE(Scal_partArrayK)
! CALL deleteDataLayout(Scal_partArrayK(i))
! ENDDO
! DEALLOCATE(Scal_partArrayK)
! ENDIF
!
!!!! CALL delete_LES(SIZE(ScalArrayK))
! CALL delete_LES()
!
! IF (ASSOCIATED(schmidt)) DEALLOCATE(schmidt)
! IF (ASSOCIATED(ilessc)) DEALLOCATE(ilessc)
! IF (ASSOCIATED(schmidt_part)) DEALLOCATE(schmidt_part)
! IF (ALLOCATED(res_t)) DEALLOCATE(res_t)
! CALL deleteDataLayout(Uk)
! CALL deleteDataLayout(Vk)
! CALL deleteDataLayout(Wk)
!
! if(imhd) then
! CALL deleteDataLayout(Bk(1))
! CALL deleteDataLayout(Bk(2))
! CALL deleteDataLayout(Bk(3))
! deallocate(Bk)
! end if
!
!
! call diff_tool_deleteBuff(imhd)
! !CALL deleteDataLayout(phybuff)
!
! CALL deleteDataLayout(U_mean)
! CALL deleteDataLayout(V_mean)
! CALL deleteDataLayout(W_mean)
! CALL deleteDataLayout(Uk_mean)
! CALL deleteDataLayout(Vk_mean)
! CALL deleteDataLayout(Wk_mean)
!
!END SUBROUTINE deleteSolver
!------------------------------------------------------------------------------
!> @author
!> Luca MARRADI, LIPhy 2014
!
!> This function execute one time step
!> @param [in,out] sigma stress (physical space)
!> @param [in,out] L_sigma probability
!> @param [in] G the propagator
!> @param [in] nbcpus the total amount of processes (or cpus)
!> @param [in] spec_rank my MPI processe rank in the range [0:nbcpus-1]
!> @param [out] time = reached time
!> @return .TRUE. if the time-step is successfull and U,V,W,ScalArray after this
!new timestep.
!> @details
!! This function solve equation for one time step. It updates the field in both
!! real and spectral space. Be aware that, for optimisation reason, scalar
!! advected with particle method are up to date in Fourrier space but not in real
!! space (to avoid a inverse FFT transform, as computations start and end in
!! Fourrier space). This does not affect solver precision, but only the
!output.
!------------------------------------------------------------------------------
FUNCTION solver_step_luca(convol,n_activ,sigma,sigma_old,Esigma,Lsigma,G,sigmak,nbcpus,spec_rank,t_step,T) result(res)
USE avs
USE mpi
!=== INPUT/OUTPUT DATA
INTEGER, INTENT(IN) :: nbcpus,spec_rank
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: sigma,sigma_old,n_activ,convol
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: Esigma,Lsigma
TYPE(COMPLEX_DATA_LAYOUT), INTENT(INOUT) :: G,sigmak
REAL(WP), INTENT(IN) :: t_step,T
LOGICAL res
res=.FALSE.
IF (.NOT.initialized) THEN
IF(spec_rank.EQ.0) WRITE(6,'(a,f14.6,a)') '[ERROR] solver_step called before initialization!'
RETURN
ENDIF
END FUNCTION solver_step_luca
!------------------------------------------------------------------------------
!> @author
!> Luca MARRADI, LIPhy 2014
!
!> Evolve the equations by EULER methods
!> @param [in,out] sigma (physical space)
!> @param [in,out] sigma_old
!> @param [in] G the propagator
!> @param [in] nbcpus the total amount of processes (or cpus)
!> @param [in] spec_rank my MPI process rank in the range [0:nbcpus-1]
!> @param [out] time = reached time
!> @param [in] T temperature
!> @return .TRUE. if the time-step is successfull
!> @details
!! This function solve equation for one time step. It update the field in both
!! real and spectral space. Be aware that, for optimisation reason, scalar
!! advected with particle method are up to date in Fourrier space but not in real
!! space (to avoid a inverse FFT transform, as computations start and end in
!! Fourrier space). This does not affect solver precision, but only the
!output.
!------------------------------------------------------------------------------
FUNCTION solve_Euler_luca(convol,n_activ,n_old,mult,sigma,sigma_old,Esigma,Lsigma,gammadot_min,sigmak,G,t_step,T,nbcpus,spec_rank,ite,Nw,freq_sigma_corr) RESULT(res)
!USE avs
USE mpi
USE plasticflow
USE transforms_tools
!USE random_tools
IMPLICIT NONE
!== INPUT/OUTPUT DATA ==
INTEGER, INTENT(IN) :: nbcpus,spec_rank,ite,Nw,freq_sigma_corr
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: sigma,sigma_old,n_activ
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: mult,convol,n_old
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: Esigma,Lsigma
TYPE(COMPLEX_DATA_LAYOUT),INTENT(INOUT) :: sigmak,G
REAL(WP), INTENT(IN) :: t_step,T,gammadot_min
!== LOCAL DATA ==
INTEGER :: i,j,k,ierr
INTEGER :: seed,freq,l
REAL(WP) :: psr,gamma_c
LOGICAL :: success
LOGICAL :: res
res=.FALSE.
freq = 10
seed = spec_rank
!=== INITIALIZE THRESHOLD STRAIN ===
gamma_c = 0.09_WP
!=== COMPUTE SIGMA YIELD DISTRIBUTION ===
!IF(.NOT.probabilityL(sigma,Lsigma,T,t_step,spec_rank)) THEN
! CALL MPI_FINALIZE(ierr)
! STOP 'FAILED to compute probability from elastic to plastic'
!ENDIF
!IF(.NOT.probabilityE(sigma,Esigma,T,t_step,spec_rank)) THEN
! CALL MPI_FINALIZE(ierr)
! STOP 'FAILED to compute probability from plastic to elastic'
!ENDIF
!== CHECK FOR ELASTICITY PLASTICITY EVENTS ==
DO k=sigma%zmin,sigma%zmax
DO j=sigma%ymin,sigma%ymax
DO i=sigma%xmin,sigma%xmax
convol%values(i,j,k) = n_activ%values(i,j,k)*sigma%values(i,j,k)
n_old%values(i,j,k) = n_activ%values(i,j,k)
IF ( (n_activ%values(i,j,k).EQ.0_WP) .AND. (sigma%values(i,j,k) .GT. (Lsigma%values(i,j,k))*11.11_WP) ) THEN
n_activ%values(i,j,k) = 1_WP
!=== RECOMPUTE SIGMA YIELD DISTRIBUTION ===
IF(.NOT.probabilityL(Lsigma,spec_rank)) THEN
CALL MPI_FINALIZE(ierr)
STOP 'FAILED to compute probability from elastic to plastic'
ENDIF
ELSE IF( n_old%values(i,j,k).EQ.1_WP .AND. (1_WP.LE.Esigma%values(i,j,k)) ) THEN
n_activ%values(i,j,k) = 0_WP
ENDIF
IF ( (n_old%values(i,j,k).EQ.1_WP) ) THEN
Esigma%values(i,j,k) = 2_WP*( Esigma%values(i,j,k) + t_step*(gammadot_min + n_old%values(i,j,k)*sigma%values(i,j,k) ) )
ELSE
Esigma%values(i,j,k) = 0_WP
ENDIF
ENDDO
ENDDO
ENDDO
!== FROM REAL TO FOURIER SPACE ==
CALL ftran(convol,sigmak,success)
!== CONVOLUTION ==
CALL convolution(sigmak,sigmak,G,success)
!== FROM FOURIER TO REAL SPACE ==
CALL btran(sigmak,convol,res)
!== UPDATE SIGMA ==
DO k=sigma%zmin,sigma%zmax
DO j=sigma%ymin,sigma%ymax
DO i=sigma%xmin,sigma%xmax
sigma%values(i,j,k) = sigma%values(i,j,k) + t_step*(convol%values(i,j,k) + gammadot_min)
ENDDO
ENDDO
ENDDO
!=== COMPUTE SIGMA AT WAITING TIME ===
IF(Nw.EQ.ite) THEN
do k=sigma%zmin,sigma%zmax
do j=sigma%ymin,sigma%ymax
do i=sigma%xmin,sigma%xmax
sigma_old%values(i,j,k) = sigma%values(i,j,k)
enddo
enddo
enddo
ENDIF
IF (freq_sigma_corr>0 .AND. (mod((ite-Nw), freq_sigma_corr)== 0).AND.(ite>Nw)) THEN
do k=sigma%zmin,sigma%zmax
do j=sigma%ymin,sigma%ymax
do i=sigma%xmin,sigma%xmax
mult%values(i,j,k)= sigma_old%values(i,j,k) * sigma%values(i,j,k)
enddo
enddo
enddo
ENDIF
res=.TRUE.
END FUNCTION solve_Euler_luca
!------------------------------------------------------------------------------
!> @author
!> Luca MARRADI, LIPhy 2014
!
!> Evolve the equations by RK2 methods
!> @param [in,out] sigma (physical space)
!> @param [in,out] sigma_old
!> @param [in] G the propagator
!> @param [in] nbcpus the total amount of processes (or cpus)
!> @param [in] spec_rank my MPI process rank in the range [0:nbcpus-1]
!> @param [out] time = reached time
!> @param [in] T temperature
!> @return .TRUE. if the time-step is successfull
!> @details
!! This function solve equation for one time step. It update the field in both
!! real and spectral space. Be aware that, for optimisation reason, scalar
!! advected with particle method are up to date in Fourrier space but not in real
!! space (to avoid a inverse FFT transform, as computations start and end in
!! Fourrier space). This does not affect solver precision, but only the
!output.
!------------------------------------------------------------------------------
FUNCTION solve_RK2_luca(convol,n_activ,n_old,mult,sigma,sigma_old,Esigma,Lsigma,gammadot_min,sigmak,G,t_step,T,nbcpus,spec_rank,ite,Nw,freq_sigma_corr) RESULT(res)
USE mpi
USE plasticflow
USE transforms_tools
IMPLICIT NONE
!== INPUT/OUTPUT DATA ==
INTEGER, INTENT(IN) :: nbcpus,spec_rank,ite,Nw,freq_sigma_corr
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: sigma,sigma_old,n_activ
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: mult,convol,n_old
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: Esigma,Lsigma
TYPE(COMPLEX_DATA_LAYOUT),INTENT(INOUT) :: sigmak,G
REAL(WP), INTENT(IN) :: t_step,T,gammadot_min
!== LOCAL DATA ==
INTEGER :: i,j,k,ierr
INTEGER :: seed,freq,l
REAL(WP) :: psr,gamma_c
LOGICAL :: success
LOGICAL :: res
res=.FALSE.
freq = 10
seed = spec_rank
!=== INITIALIZE THRESHOLD STRAIN ===
gamma_c = 0.09_WP
!=== COMPUTE SIGMA YIELD DISTRIBUTION ===
IF(.NOT.probabilityL(Lsigma,spec_rank)) THEN
CALL MPI_FINALIZE(ierr)
STOP 'FAILED to compute probability from elastic to plastic'
ENDIF
!== CHECK FOR ELASTICITY PLASTICITY EVENTS ==
DO k=sigma%zmin,sigma%zmax
DO j=sigma%ymin,sigma%ymax
DO i=sigma%xmin,sigma%xmax
convol%values(i,j,k) = n_activ%values(i,j,k)*sigma%values(i,j,k)
n_old%values(i,j,k) = n_activ%values(i,j,k)
IF ( (n_activ%values(i,j,k).EQ.0_WP) .AND. (sigma%values(i,j,k) .GT. (Lsigma%values(i,j,k))*11.11_WP) ) THEN
n_activ%values(i,j,k) = 1_WP
ELSE IF( n_old%values(i,j,k).EQ.1_WP .AND. (1_WP.LE.Esigma%values(i,j,k)) ) THEN
n_activ%values(i,j,k) = 0_WP
ENDIF
IF ( (n_old%values(i,j,k).EQ.1_WP) ) THEN
Esigma%values(i,j,k) = 2_WP*( Esigma%values(i,j,k) + t_step*(gammadot_min + n_old%values(i,j,k)*sigma%values(i,j,k) ) )
ELSE
Esigma%values(i,j,k) = 0_WP
ENDIF
ENDDO
ENDDO
ENDDO
!== FROM REAL TO FOURIER SPACE ==
CALL ftran(convol,sigmak,success)
!== CONVOLUTION ==
CALL convolution(sigmak,sigmak,G,success)
!== FROM FOURIER TO REAL SPACE ==
CALL btran(sigmak,convol,res)
!== FIRST SIGMA UPDATE ==
DO k=sigma%zmin,sigma%zmax
DO j=sigma%ymin,sigma%ymax
DO i=sigma%xmin,sigma%xmax
!K1
sigma_old%values(i,j,k) = t_step*(convol%values(i,j,k) + gammadot_min)
ENDDO
ENDDO
ENDDO
!== SECOND SIGMA UPDATE ==
DO k=sigma%zmin,sigma%zmax
DO j=sigma%ymin,sigma%ymax
DO i=sigma%xmin,sigma%xmax
convol%values(i,j,k) = n_activ%values(i,j,k)*( sigma%values(i,j,k) + sigma_old%values(i,j,k)*0.5 )
ENDDO
ENDDO
ENDDO
!== FROM REAL TO FOURIER SPACE ==
CALL ftran(convol,sigmak,success)
!== CONVOLUTION ==
CALL convolution(sigmak,sigmak,G,success)
!== FROM FOURIER TO REAL SPACE ==
CALL btran(sigmak,convol,res)
!== SECOND SIGMA UPDATE ==
DO k=sigma%zmin,sigma%zmax
DO j=sigma%ymin,sigma%ymax
DO i=sigma%xmin,sigma%xmax
!K2
sigma_old%values(i,j,k) = t_step*( convol%values(i,j,k) + gammadot_min )
ENDDO
ENDDO
ENDDO
!== SIGMA UPDATE ==
DO k=sigma%zmin,sigma%zmax
DO j=sigma%ymin,sigma%ymax
DO i=sigma%xmin,sigma%xmax
sigma%values(i,j,k) = sigma%values(i,j,k) + sigma_old%values(i,j,k)
ENDDO
ENDDO
ENDDO
! IF (freq_sigma_corr>0 .AND. (mod((ite-Nw), freq_sigma_corr)== 0).AND.(ite>Nw)) THEN
! do k=sigma%zmin,sigma%zmax
! do j=sigma%ymin,sigma%ymax
! do i=sigma%xmin,sigma%xmax
! mult%values(i,j,k)= sigma_old%values(i,j,k) * sigma%values(i,j,k)
! enddo
! enddo
! enddo
! ENDIF
res=.TRUE.
END FUNCTION solve_RK2_luca
!> Explicit Euler Solve Navier-Stokes equation for velocity and advection-diffusion equation
!! for scalar (solved with full pseudo-spectral solver).
!! @author
!! Mouloud Kessar and Jean-Baptiste Lagaert, LEGI
!! @param[in,out] U = longitudinal velocity (physical space)
!! @param[in,out] V = vertical velocity (physical space)
!! @param[in,out] W = spanwise velocity (physical space)
!! @param[in,out] Uk = longitudinal velocity (spectral space)
!! @param[in,out] Vk = vertical velocity (spectral space)
!! @param[in,out] Wk = spanwise velocity (spectral space)
!! @param[in,out] nlx = nonlinear terms for U (fourier space), initialy set by firstTerm
!! @param[in,out] nly = nonlinear terms for V (fourier space), initialy set by firstTerm
!! @param[in,out] nlz = nonlinear terms for W (fourier space), initialy set by firstTerm
!! @param[in] spec_rank = my MPI processe rank in the range [0:nbcpus-1]
!! @param[in] imhd = 1 if MHD is active, 0 else
!! @param[out] time = reached time
!! @param[in, out] B = magnetic field
!! @param[out] res = true if no error occurs
!! @details
!! Velocity follows and Navier-Stokes equation and the scalar fields follow a
!! diffusion-advection equation. This subroutine solve it for a time intervall of
!! [T ; T+dt]. This function update these fields (by solving the equations)
!! both spectral and real space.
!! This function provide a first order intergrator: explicit Euler Scheme.
!! If the velocity field in real space is already on the good mesh
!! (considering the scalar resolution), then solver used it. Else, it compute
!! this vector on the right resolution directly from the Fourrier space
!! (and thus perform Fourrier interpolation).
subroutine solve_spec_Euler(U, V, W, Uk, Vk, Wk, nlx, nly, nlz, &
& B, nlB, ScalS, ScalP, ScalNL, &
& dt, imhd, Srank, res)
use differential_tools
! Input/Output
INTEGER, INTENT(IN) :: Srank
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: U,V,W
TYPE(REAL_DATA_LAYOUT) :: sigma
type(COMPLEX_DATA_LAYOUT) :: sigmak
type(COMPLEX_DATA_LAYOUT), intent(inout) :: Uk,Vk,Wk
TYPE(COMPLEX_DATA_LAYOUT),INTENT(INOUT) :: nlx, nly, nlz
TYPE(REAL_DATA_LAYOUT), POINTER, INTENT(INOUT) :: B(:)
TYPE(COMPLEX_DATA_LAYOUT), DIMENSION(:), INTENT(INOUT) :: nlB
TYPE(REAL_DATA_LAYOUT), POINTER, INTENT(INOUT) :: ScalS(:)
TYPE(REAL_DATA_LAYOUT), POINTER, INTENT(IN) :: ScalP(:)
TYPE(COMPLEX_DATA_LAYOUT), DIMENSION(:), INTENT(INOUT) :: ScalNL
LOGICAL, INTENT(IN) :: imhd
real(WP) :: dt
LOGICAL :: res
!
! ! Initialisation
! res = .false.
!
! ! == Compute non-linear term, forcing and projection (div(U,V,W)=0) ==
! call spectral_source_term(U,V,W,Uk,Vk,Wk, &
! & nlx, nly, nlz, &
! & imhd, B, nlB, &
! & ScalS,ScalNL, &
! & ScalP, dt, &
! & Srank, res)
! if(.not.res) then
! write(6,'(a)') '[ERROR] solve_spec_Euler : fail to compute source_term'
! return
! end if
!
! ! == compute diffusion and update complex fields ==
! call spectral_update_fields(Uk,Vk,Wk, Uk, &
! & Vk, Wk, nlx, nly, nlz, &
! & imhd,Bk,Bk,nlB, &
! & ScalArrayk, ScalArrayk, ScalNL, &
! & dt, res)
! if(.not.res) then
! write(6,'(a)') '[ERROR] solve_spec_Euler : fail to update complex fields'
! return
! end if
!
! ! == Update real fields ==
! call spectral_update_real_fields(U,V,W,Uk,Vk,Wk, &
! & imhd, B, Bk, &
! & ScalS,ScalArrayk, &
! & res)
! if(.not.res) then
! write(6,'(a)') '[ERROR] solve_spec_Euler : fail to update real fields'
! return
! end if
!
! ! == Update time ==
! sim_time = sim_time + dt
!
end subroutine solve_spec_Euler
!-------------------------------------------------------------------------------
!> Explicit Euler solves plasticity equations for sigma stress tensor
!! for scalar (solved with full pseudo-spectral solver).
!! @author
!! Luca MARRADI LIPhy, 2014
!! @param[in,out] sigma = stress tensor
!! @param[in] G = propagator
!! @param[in] mu = elasticity tensor
!! @param[in] sigmak = stress tensor (spectral space)
!! @param[in] spec_rank = my MPI processe rank in the range [0:nbcpus-1]
!! @param[out] time = reached time
!! @param[out] res = true if no error occurs
!! @details
!! This subroutine solve it for a time intervall of [T ; T+dt]. This function
!! update these fields (by solving the equations) both spectral and real space.
!! This function provide a first order intergrator: explicit Euler Scheme.
!!SUBROUTINE solve_spec_Euler_luca(sigma,sigma_old,sigmak,G_prop,step,T,Srank,res)
!! USE transforms_tools
!! USE plasticflow
! Input/Output
!! INTEGER :: i,j,k
!! INTEGER, INTENT(IN) :: Srank
!! TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: sigma,sigma_old
!! TYPE(COMPLEX_DATA_LAYOUT), INTENT(INOUT) :: G_prop,sigmak
!! REAL(WP),DIMENSION(:,:,:), ALLOCATABLE :: Lsigma
!! REAL(WP) :: step,T,psr
!! LOGICAL :: res
!! ALLOCATE(Lsigma(sigma%xmin:sigma%xmax,sigma%ymin:sigma%ymax,sigma%zmin:sigma%zmax))
! INITIALIZATION
!! res = .FALSE.
!== STOCHASTIC PART ==
!! CALL probability(sigma,Lsigma,T,step)
!== TEST OF PLASTICITY EVENT ==
!! psr=REAL(Srank)
!! DO k=sigma%zmin,sigma%zmax
!! DO j=sigma%ymin,sigma%ymax
!! DO i=sigma%xmin,sigma%xmax
!! CALL random_number(psr)
!! IF(Lsigma(i,j,k).LT.psr) sigma%values(i,j,k) = 0_WP
!! ENDDO
!! ENDDO
!! ENDDO
!== FROM REAL TO FOURIER SPACE ==
!! CALL ftran(sigma,sigmak,res)
!== CONVOLUTION ==
!! CALL convolution(sigmak,sigmak,G_prop,res)
!== FROM FOURIER TO REAL SPACE ==
!! CALL btran(sigmak,sigma,res)
!== UPDATE FIELD SIGMA ==
!! DO k = sigma%zmin,sigma%zmax
!! DO j = sigma%ymin,sigma%ymax
!! DO i = sigma%xmin,sigma%xmax
!! sigma%values(i,j,k) = sigma_old%values(i,j,k) + step*sigma%values(i,j,k) !+ mu%values(i,j,k) )
!! ENDDO
!! ENDDO
!! ENDDO
!== STORE SIGMA IN SIGMA_OLD FOR NEXT STEP ==
!! DO k = sigma%zmin,sigma%zmax
!! DO j = sigma%ymin,sigma%ymax
!! DO i = sigma%xmin,sigma%xmax
!! sigma_old%values(i,j,k) = sigma%values(i,j,k)
!! ENDDO
!! ENDDO
!! ENDDO
!DEALLOCATE MEMORY
!! DEALLOCATE(Lsigma)
!! res=.TRUE.
!!END SUBROUTINE solve_spec_Euler_luca
!-------------------------------------------------------------------------------
!> Runge-Kutta 2 for spectral sovler (Navier-Stokes equation for velocity and advection-diffusion equation
!! for scalar).
!! @author
!! Patrick Begou, Jean-Baptiste Lagaert, Guillaume Balarac, LEGI
!! Mouloud Kessar and Jean-Baptiste Lagaert, LEGI
!! @param[in,out] U = longitudinal velocity (physical space)
!! @param[in,out] V = vertical velocity (physical space)
!! @param[in,out] W = spanwise velocity (physical space)
!! @param[in,out] Uk = longitudinal velocity (spectral space)
!! @param[in,out] Vk = vertical velocity (spectral space)
!! @param[in,out] Wk = spanwise velocity (spectral space)
!! @param[in,out] nlx = nonlinear terms for U (fourier space), initialy set by firstTerm
!! @param[in,out] nly = nonlinear terms for V (fourier space), initialy set by firstTerm
!! @param[in,out] nlz = nonlinear terms for W (fourier space), initialy set by firstTerm
!! @param[in] spec_rank = my MPI processe rank in the range [0:nbcpus-1]
!! @param[in] imhd = 1 if MHD is active, 0 else
!! @param[out] time = reached time
!! @param[in, out] B = magnetic field
!! @param[out] res = true if no error occurs
!! @details
!! Velocity follows and Navier-Stokes equation and the scalar fields follow a
!! diffusion-advection equation. This subroutine solve it for a time intervall of
!! [T ; T+dt]. This function update these fields (by solving the equations)
!! both spectral and real space.
!! This is a second order in timer integrator.
!! If the velocity field in real space is already on the good mesh
!! (considering the scalar resolution), then solver used it. Else, it compute
!! this vector on the right resolution directly from the Fourrier space
!! (and thus perform Fourrier interpolation).
subroutine solve_spec_RK2(U, V, W, Uk, Vk, Wk, nlx, nly, nlz, &
& B, nlB, ScalS, ScalP, ScalNL, &
& dt, imhd, Srank, res)
use differential_tools
! Input/Output
INTEGER, INTENT(IN) :: Srank
TYPE(REAL_DATA_LAYOUT), INTENT(INOUT) :: U,V,W
type(COMPLEX_DATA_LAYOUT), intent(inout) :: Uk,Vk,Wk
TYPE(REAL_DATA_LAYOUT) :: sigma
type(COMPLEX_DATA_LAYOUT) :: sigmak
TYPE(COMPLEX_DATA_LAYOUT),INTENT(INOUT) :: nlx, nly, nlz
TYPE(REAL_DATA_LAYOUT), POINTER, INTENT(INOUT) :: B(:)
TYPE(COMPLEX_DATA_LAYOUT), DIMENSION(:), INTENT(INOUT) :: nlB
TYPE(REAL_DATA_LAYOUT), POINTER, INTENT(INOUT) :: ScalS(:)
TYPE(REAL_DATA_LAYOUT), POINTER, INTENT(IN) :: ScalP(:)
TYPE(COMPLEX_DATA_LAYOUT), DIMENSION(:), INTENT(INOUT) :: ScalNL
LOGICAL, INTENT(IN) :: imhd
real(WP) :: dt
LOGICAL :: res
! Local
!> Loop indices
INTEGER :: i
REAL(WP) :: step
! == Initialisation ==
! res = .false.