-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.f90
More file actions
354 lines (288 loc) · 11.1 KB
/
Copy pathmain.f90
File metadata and controls
354 lines (288 loc) · 11.1 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
!===============================================================================
PROGRAM main
!==============================================================================
USE options
USE param
USE mpilayout_tools
USE communicators_tools
USE random_tools
USE data
USE datalayout
USE precision_tools
USE avs
USE mpi
USE solver
USE post_lib
USE post_in_simu
USE post_out_simu
USE stat_tools
!USE subgridmodels
USE wavenumber_tools
USE io_interface
IMPLICIT NONE
INTEGER :: nbcpus=1
!> the number of MPI processes
INTEGER :: ncpus1=1
!> the number of MPI processes in the first distributed array dimension
INTEGER :: ncpus2=1
!> the number of MPI processes in the second distributed array dimension
INTEGER :: spec_rank
!> my id in the pool of MPI processes inside the "spectral" communicator
INTEGER :: world_rank
!> my id in the pool of MPI processes inside the default "MPI_COMM_WOLRD" communicator
INTEGER :: ierr
!> Dimension of the mpi-topology used (if 0 the none)
INTEGER :: topo_dim
!> an integer to store error codes returned by subroutines
LOGICAL :: res
!> To determine postprocessing to perform (none => computation)
CHARACTER(LEN=32):: postprocess
!> Reached time (by the simulation)
REAL(WP) :: current_time=0.0_WP
! Time step
REAL(WP) :: dt, med
!LUCA
REAL(WP) :: ps,T,gammadot_min,corrXYw
INTEGER :: Nw,freq_sigma_corr
!VAR DEFINED FOR TESTING
TYPE(REAL_DATA_LAYOUT) :: sigma, sigma_old,mult
TYPE(REAL_DATA_LAYOUT) :: Esigma,Lsigma,n_activ,n_old,convol
TYPE(COMPLEX_DATA_LAYOUT) :: G,sigmak
LOGICAL :: success
!> number of solver iterations requested
INTEGER::n_iter
!> perform post-process ipost timestep
INTEGER:: ipost
INTEGER:: ite, sca
REAL(WP) :: coeff, final_time
REAL:: time1, time2,times=0.0,timesPost=0.0,tx
! LUCA
INTEGER:: i,j,k
!== INITIALIZE MPI ENVIRONMENT ==
CALL MPI_INIT(ierr)
CALL MPI_COMM_RANK(MPI_COMM_WORLD,world_rank,ierr)
CALL MPI_COMM_SIZE(MPI_COMM_WORLD,nbcpus,ierr)
! Gets the command line options.
IF (.NOT. get_options(world_rank)) THEN
CALL MPI_FINALIZE(ierr)
STOP 'FAILED'
ENDIF
CALL computeProcsMatrix(nbcpus,ncpus1,ncpus2,world_rank,res)
IF (.NOT. res) THEN
CALL MPI_FINALIZE(ierr)
STOP 'computeProcsMatrix FAILED'
ELSE
IF (world_rank.EQ.0) WRITE(6,'(2(a,i3),a)') &
& '[INFO] Cpus distribution is [',ncpus1,'] x [',ncpus2,']'
ENDIF
!== READS THE INPUT FILE CALLED "input" AND INITIALIZE PARSER ==
IF (.NOT. param_init(GetInputFile())) THEN
CALL MPI_FINALIZE(ierr)
STOP 'param_init FAILED'
ENDIF
IF (world_rank.EQ.0) CALL parser_show()
!== INITIALIZE PARALLEL CONTEXT ==
!ATTENTION TO THE TOPOLOGY
! Read input to initialize mpi topology:
CALL parser_read('Default topology', topo_dim)
! topo_dim = 3
! Initialize the mpi topology and the communicators
CALL initCommunicators(ncpus1, ncpus2, topo_dim, spec_rank)
! Send new rank to mpilayout_tools
CALL init_spec_rank(spec_rank)
!== INITIALIZE THE COMPUTATION PART OF THE APPLICATION ==
! Check if we have asked for the debug option with GetDebugRandom()
!------------------------------------------------
CALL random_init(spec_rank,GetDebugRandom())
!== INITIALIZE THE DATA STRUCTRE
IF(.NOT.data_init_luca(nbcpus,spec_rank,mult,sigma,sigma_old,Esigma&
& ,Lsigma,G,sigmak,n_activ,n_old,convol)) &
& STOP 'FAILED to initialize the data structure'
!------------------------------------------------
! Perform post out simu OR run a simulation
!------------------------------------------------
CALL parser_read('Post-process out simulation',postprocess)
IF ( postprocess.eq.'yes' ) THEN
!------------------------------------------------
! Post out simu part
!------------------------------------------------
IF(spec_rank.EQ.0) WRITE(6,'(a)')'[INFO] Post-process out of simulation'
CALL cpu_time(time1)
! IF (.NOT. post_out_simu_init_luca(spec_rank,sigma)) THEN
! CALL MPI_FINALIZE(ierr)
! STOP 'Error in initialization of post-processing'
! ENDIF
! IF (.NOT. post_out(nbcpus ,spec_rank, nbscal, scalArray, nbscal_part,scal_partArray, U, V ,W,B,imhd)) THEN
! CALL MPI_FINALIZE(ierr)
! STOP 'Error in post-processing'
! ENDIF
CALL cpu_time(time2)
IF(spec_rank.EQ.0) WRITE(6,'(a,x,g16.6,a)')'[INFO] Postprocess requires ',time2-time1,' s'
! IF (.NOT. post_out_simu_del(nbscal,nbscal_part) ) THEN
! CALL MPI_FINALIZE(ierr)
! STOP 'Error in delete of post-processing'
! ENDIF
ELSE ! ( postprocess.eq.'no' )
!=== COMPUTATIONAL PART ===
!=== INITIALIZATION OF THE SOLVER ===
IF(spec_rank.EQ.0) PRINT*,'-----------------------------------------------------------------'
!== INITIALIZE GAMMA DOT ==
CALL parser_read('Gamma dot',gammadot_min)
!== ALL THE FIELDS ARE INITIALIZED ==
IF (.NOT. initSolver_luca(convol,n_activ,sigmak,G,sigma,sigma_old,Esigma,Lsigma&
& ,gammadot_min,current_time,nbcpus,spec_rank)) THEN
CALL MPI_FINALIZE(ierr)
STOP 'FAILED to init solver luca'
ENDIF
IF(spec_rank.EQ.0) PRINT*,'-----------------------------------------------------------------'
!== INITIALIZE TIME STEP dt AND FINAL TIME ==
CALL parser_read('Simulation iterations',n_iter)
CALL parser_read('Fixed time step',dt)
IF (parser_is_defined('Final time')) then
CALL parser_Read('Final time', final_time)
coeff = 1._WP
ELSE
coeff = -1._WP
final_time = 1._WP
END IF
!== READS TEMPERATURE ELASTIC AND PLASTIC TAU ==
CALL parser_read('Temperature',T)
CALL parser_read('Sigma correlation XY iter',freq_sigma_corr)
CALL parser_read('Waiting time iter',Nw)
!== INITIALIZE POST-PROCESS AND GETS THE OUTPUTS FIELDS FREQUENCY
IF(.NOT.post_in_simu_init_luca(sigma,spec_rank,ipost)) THEN
CALL MPI_FINALIZE(ierr)
STOP 'unable to init post-process'
ENDIF
! IF(.not. post_simu_luca(0,current_time, 0.0_WP,nbcpus ,spec_rank,mult,sigma,sigma_old&
! & ,n_activ,n_iter,corrXYw)) write(*,'(a)') &
! & '[Warning] Unable to perform post-process and to show info'
! IF(.not. post_simu_deltaT_luca(current_time,nbcpus,spec_rank,sigma,n_iter)) write(*,'(a)') &
! & '[Warning] Unable to perform post-process and to show info -delta T'
! ===== INITIALIZE RANDON NUM GEN AND ITER =====
ite = 1
!LUCA
!n_iter=5_WP/(dt*gammadot_min)
times=0_WP
! ===== TIME LOOP =====
DO WHILE ((ite<=n_iter).and.(coeff*current_time<final_time))
!== SOLVE EQUATION ==
CALL cpu_time(time1)
IF (.NOT. solve_Euler_luca(convol,n_activ,n_old,mult,sigma,sigma_old,Esigma,Lsigma,gammadot_min,sigmak&
!IF (.NOT. solve_RK2_luca(convol,n_activ,n_old,mult,sigma,sigma_old,Esigma,Lsigma,gammadot_min,sigmak&
&,G,dt,T, nbcpus,spec_rank,ite,Nw,freq_sigma_corr)) THEN
CALL MPI_FINALIZE(ierr)
STOP 'Solver Error'
ENDIF
!CALL cpu_time(time2)
IF(spec_rank.EQ.0) WRITE(6,'(a,x,i0,x,a,f8.4,a, f12.4)') &
&'[PROGRESSION] Iteration', ite, 'requires ',time2-time1,' s, and t = ', current_time
!times=times+(time2-time1)
!== OUTPUT INSIDE THE TIME LOOP ==
!CALL cpu_time(time1)
!=== COMPUTE SIGMA WAITING AVERAGE ===
IF(Nw.EQ.ite) THEN
corrXYw = computeFieldAvg(sigma_old,spec_rank)
ENDIF
!=== PERFORMS POST-PROCESS ===
IF(.not. post_simu_luca(ite,current_time,dt,nbcpus,spec_rank,mult,sigma,sigma_old,&
&n_activ,n_iter,corrXYw)) WRITE(*,'(a)') &
& '[Warning] Unable to perform post-process and to show info'
!== PERFEROMANCE OUTPUT ==
!CALL cpu_time(time2)
IF(spec_rank.EQ.0) WRITE(6,'(a,x,i0,x,a,f8.4,a)') &
& '[INFO] PostSimu at Iteration', ite,'requires ',time2-time1,' s'
timesPost=timesPost+(time2-time1)
IF(.not. post_simu_deltaT_luca(current_time,nbcpus,spec_rank,sigma,n_iter)) write(*,'(a)') &
& '[Warning] Unable to perform post-process and to show info'
ite = ite + 1
!LUCA: the time advection step put outside the fucntion solver_step_luca
current_time=current_time + dt
CALL cpu_time(time2)
times=times+(time2-time1)
ENDDO
!== TIME PROFILING FOR THE OUTPUT PART ==
!tx=timesPost/(timesPost+times)*100.0_WP
IF(spec_rank.EQ.0) WRITE(6,'(a,g16.6,a)')'[INFO] Total run requires ',times,'s'
!IF(spec_rank.EQ.0) WRITE(6,'(a,g16.6,a,f5.2,a)')'[INFO] Total post-processing requires ',timesPost,'s soit ',tx,'%'
IF(spec_rank.EQ.0) WRITE(6,'(a,f16.6,a)')'[INFO] Average timestep is ',times/max(1,(ite-1)),'s'
END IF ! ( postprocess.eq.'no' )
!== DEALLOCATE MEMORY ==
CALL parser_reset()
CALL deleteDataLayout(sigma)
CALL deleteDataLayout(sigma_old)
CALL deleteDataLayout(G)
CALL deleteDataLayout(sigmak)
CALL deleteDataLayout(n_activ)
CALL deleteDataLayout(convol)
CALL deleteDataLayout(mult)
!=== TEMINATE ALL MPI PROCESS ===
CALL MPI_FINALIZE(ierr)
END PROGRAM main
!************************ TEST PART **********************************
!SIGMA INITIALIZATION
! IF (.NOT. initSolver_luca(sigma,sigma_old,current_time,nbcpus,spec_rank)) THEN
! CALL MPI_FINALIZE(ierr)
! STOP 'FAILED to init solver luca'
! ENDIF
!! AVERAGE TESTED and it works by pay attention read todo file
! med = computeFieldAvg(sigma,spec_rank)
!!TESTED
! print*,"sigma average:", med
!FFT TEST
!! CALL ftran(sigma, G,success)
!TESTED
!MPI PRINTS THE G INITIAL CONDITION
! IF(.NOT.cmplx_WriteToFile(spec_rank,trim(G%name),G)) THEN
! WRITE(*,*) "does not work!!!"
! ENDIF
! CALL btran(G,sigma_old,res)
!MPI PRINTS THE SIGMA INITIAL CONDITION
! IF(.NOT.real_WriteToFile(spec_rank,trim(sigma_old%name),sigma_old)) THEN
! WRITE(*,*) "does not work!!!"
! ENDIF
!TEST RANDOM_NUMBER
!! IF(spec_rank.eq.0) THEN
!! OPEN(400,file='random.dat',form='formatted')
!! DO k=1,sigma%nz
!! DO j=1,sigma%ny
!! DO i=1,((sigma%nx)/2)+1
!! CALL random_number(psr)
!! write(400,'(g15.8,1x)') psr
!! ENDDO
!! ENDDO
!! ENDDO
!! ENDIF
!TESTED
!!CALL convolution(risu,G,sigmak,res)
!MPI PRINTS THE CONVOLUTION
!!IF(.NOT.cmplx_WriteToFile(spec_rank,trim(risu%name),risu)) THEN
!! WRITE(*,*) "does not work!!!"
!!ENDIF
!HDF5 PRINT OF SIGMA INITIAL CONDITION
!! IF(.not.write_datalayout_scalar(sigma,ite,spec_rank,"hdf5") ) THEN
!! WRITE (6,'(a)') 'FAILED to write output for velocity field'
!! RETURN
! ! ENDIF
!HDF5 PRINT OF SIGMA INITIAL CONDITION
!! IF(.not.write_datalayout_scalar(sigma_old,ite,spec_rank) ) THEN
!! WRITE (6,'(a)') 'FAILED to write output for velocity field'
!! RETURN
!! ENDIF
!PRINT OF G PROPAGATOR INITIAL CONDITION
!! 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
!! IF(G_full(i,j,k).lt.1.E-20) THEN
!! G_full(i,j,k) = 0.d0
!! write(400,'(g15.8,1x)') G_full(i,j,k)
!! ELSE
!! write(400,'(g15.8,1x)') G_full(i,j,k)
!! ENDIF
!! ENDDO
!! ENDDO
!! ENDDO
!! CLOSE(400)
!! ENDIF