SFEMaNS  version 5.3
Reference documentation for SFEMaNS
main.f90
Go to the documentation of this file.
1 PROGRAM mhd_prog
2  USE def_type_mesh
4  USE my_util
5  USE input_data
6  !USE arpack_mhd
8  USE user_data
10  USE verbose
11 #include "petsc/finclude/petsc.h"
12  USE petsc
13  IMPLICIT NONE
14  !===Navier-Stokes fields========================================================
15  TYPE(mesh_type), POINTER :: pp_mesh, vv_mesh
16  REAL(KIND=8), POINTER, DIMENSION(:,:,:) :: un, pn
17  TYPE(dyn_real_array_three), POINTER, DIMENSION(:):: der_un
18  !===Maxwell fields==============================================================
19  TYPE(mesh_type), POINTER :: H_mesh, phi_mesh
20  TYPE(interface_type), POINTER :: interface_H_mu, interface_H_phi
21  REAL(KIND=8), POINTER, DIMENSION(:,:,:) :: Hn, Bn, phin, vel
22  REAL(KIND=8), POINTER, DIMENSION(:) :: sigma_field, mu_H_field
23  !===Temperature field===========================================================
24  TYPE(mesh_type), POINTER :: temp_mesh
25  REAL(KIND=8), POINTER, DIMENSION(:,:,:) :: temperature
26  REAL(KIND=8), POINTER, DIMENSION(:) :: vol_heat_capacity_field
27  REAL(KIND=8), POINTER, DIMENSION(:) :: temperature_diffusivity_field
28  !===Level_set===================================================================
29  REAL(KIND=8), POINTER, DIMENSION(:,:,:,:) :: level_set
30  !===Density=====================================================================
31  REAL(KIND=8), POINTER, DIMENSION(:,:,:) :: density
32  !===Fourier modes===============================================================
33  INTEGER :: m_max_c
34  INTEGER, POINTER, DIMENSION(:) :: list_mode
35  !===Time iterations=============================================================
36  REAL(KIND=8) :: time
37  INTEGER :: it
38  !===Timing======================================================================
39  REAL(KIND=8) :: tps, tploc, tploc_max=0.d0
40  !===Declare PETSC===============================================================
41  petscerrorcode :: ierr
42  petscmpiint :: rank
43  mpi_comm, DIMENSION(:), POINTER :: comm_one_d, comm_one_d_ns, comm_one_d_temp
44 
45  !===Start PETSC and MPI (mandatory)=============================================
46  CALL petscinitialize(petsc_null_character,ierr)
47  CALL mpi_comm_rank(petsc_comm_world,rank,ierr)
48 
49  !===User reads his/her own data=================================================
50  CALL read_user_data('data')
51 
52  !===Initialize SFEMANS (mandatory)==============================================
53  CALL initial(vv_mesh, pp_mesh, h_mesh, phi_mesh, temp_mesh, &
54  interface_h_phi, interface_h_mu, list_mode, &
55  un, pn, hn, bn, phin, vel, &
56  vol_heat_capacity_field, temperature_diffusivity_field, mu_h_field, sigma_field, &
57  time, m_max_c, comm_one_d, comm_one_d_ns, comm_one_d_temp, temperature, &
58  level_set, density, der_un)
59 
60  !===============================================================================
61  ! VISUALIZATION WITHOUT COMPUTING !
62  !===============================================================================
63  IF (inputs%if_just_processing) THEN
64  inputs%freq_plot=1
65  CALL my_post_processing(1)
66  CALL error_petsc('End post_processing')
67  END IF
68 
69  !===============================================================================
70  ! EIGENVALUE PROBLEMS/ARPACK !
71  !===============================================================================
72  !IF (inputs%if_arpack) THEN
73  ! !ATTENTION: m_max_c should be equal to 1, meaning each processors is dealing with 1 Fourier mode
74  ! CALL solver_arpack_mhd(comm_one_d,H_mesh,phi_mesh,&
75  ! inputs%dt,list_mode,mu_H_field)
76  ! !===Postprocessing to check convergence
77  ! IF (inputs%test_de_convergence) THEN
78  ! CALL post_proc_test(vv_mesh, pp_mesh, temp_mesh, H_mesh, phi_mesh, list_mode, &
79  ! un, pn, Hn, Bn, phin, temperature, level_set, mu_H_field, &
80  ! time, m_max_c, comm_one_d, comm_one_d_ns, comm_one_d_temp) ! MODIFICATION: comm_one_d_temp added
81  ! CALL error_Petsc('End of convergence test')
82  ! !IF (rank==0) WRITE(*,*) 'End of convergence test'
83  ! !RETURN
84  ! END IF
85  ! !=== Put your postprocessing here
86  !
87  ! !===End of code for ARPACK problem
88  ! CALL error_Petsc('END OF ARPACK, EXITING PRGM')
89  !IF (rank==0) WRITE(*,*) 'END OF ARPACK, EXITING PRGM'
90  ! !RETURN
91  !END IF
92 
93  !===============================================================================
94  ! TIME INTEGRATION !
95  !===============================================================================
96  !===Start time loop
97  tps = user_time()
98  DO it = 1, inputs%nb_iteration
99  tploc = user_time()
100  time = time + inputs%dt
101 
102  CALL run_sfemans(time, it) ! MODIFICATION: used to compute the magnetic field only once in fhd with steady current case
103 
104  !===My postprocessing
105  IF (.NOT.inputs%test_de_convergence) THEN
106  CALL my_post_processing(it)
107  END IF
108 
109  !===Write restart file
110  IF (mod(it, inputs%freq_restart) == 0) THEN
111  CALL save_run(it,inputs%freq_restart)
112  ENDIF
113 
114  !===Timing
115  tploc = user_time() - tploc
116  IF (it>1) tploc_max = tploc_max + tploc
117  ENDDO
118 
119  !===Timing======================================================================
120  tps = user_time() - tps
121  CALL write_verbose(rank,opt_tps=tps,opt_tploc_max=tploc_max)
122 
123  !===Postprocessing to check convergence=========================================
124  IF (inputs%test_de_convergence) THEN
125  CALL post_proc_test(vv_mesh, pp_mesh, temp_mesh, h_mesh, phi_mesh, list_mode, &
126  un, pn, hn, bn, phin, temperature, level_set, mu_h_field, &
127  time, m_max_c, comm_one_d, comm_one_d_ns, comm_one_d_temp)
128  CALL error_petsc('End of convergence test')
129  END IF
130 
131  !===End of code=================================================================
132  CALL error_petsc('End of SFEMaNS')
133 CONTAINS
134 
135  SUBROUTINE my_post_processing(it)
137  USE chaine_caractere
138  USE tn_axi
139  USE boundary
140  USE sft_parallele
141  USE verbose
142  USE vtk_viz
143  IMPLICIT NONE
144  INTEGER, INTENT(IN) :: it
145  REAL(KIND=8) :: err, norm
146  INTEGER :: i, it_plot
147  CHARACTER(LEN=3) :: what
148  INTEGER :: rank_S, rank_F
149  INTEGER :: rank_ns_S, rank_ns_F
150  REAL(KIND=8), DIMENSION(vv_mesh%np, 2, SIZE(list_mode)) :: level_1_P2
151  REAL(KIND=8), DIMENSION(pp_mesh%np, 2, SIZE(list_mode)) :: level_1_P1
152  REAL(KIND=8), DIMENSION(vv_mesh%np,2,SIZE(list_mode)) :: chi, one_chi
153  INTEGER :: nb_procs, m_max_pad, bloc_size
154  !===VTU 2d======================================================================
155  CHARACTER(LEN=3) :: st_mode
156  CHARACTER(LEN=200) :: header
157  CHARACTER(LEN=3) :: name_of_field
158 
159  !===Check ranks
160  IF (vv_mesh%me /=0) THEN
161  CALL mpi_comm_rank(comm_one_d_ns(1), rank_ns_s, ierr)
162  CALL mpi_comm_rank(comm_one_d_ns(2), rank_ns_f, ierr)
163  ELSE
164  rank_ns_s = -1
165  rank_ns_f = -1
166  END IF
167  CALL mpi_comm_rank(comm_one_d(1), rank_s, ierr)
168  CALL mpi_comm_rank(comm_one_d(2), rank_f, ierr)
169 
170  !===Check divergence of fields
171  IF (inputs%check_numerical_stability) THEN
172  IF (inputs%type_pb=='nst' .OR. inputs%type_pb=='mhd' .OR. inputs%type_pb=='fhd') THEN
173  norm = norm_sf(comm_one_d_ns, 'L2', vv_mesh, list_mode, un)
174  ELSE
175  norm = norm_sf(comm_one_d, 'L2', h_mesh, list_mode, hn)
176  END IF
177  IF (norm>1.d2) THEN
178  CALL error_petsc('From my_post_processing: numerical unstability')
179  END IF
180  END IF
181 
182  !===Put your postprocessing stuff here
183  IF (mod(it,inputs%freq_en) == 0) THEN
184 
185  !===Verbose
186  CALL write_verbose(rank)
187 
188  IF (inputs%type_pb=='nst' .OR. inputs%type_pb=='mhd' .OR. inputs%type_pb=='fhd') THEN
189  IF (inputs%if_compute_momentum_pseudo_force) THEN
190  !===Compute the term -2/pi*integral((1-chi)*(u-u_solid).e_z/dt)
191  !===chi is the penalty function, u_solid the velocity of the solid, dt the time step
192  !==Output written in the file fort.12
193  CALL forces_and_moments(time,vv_mesh,comm_one_d_ns,list_mode,un)
194  END IF
195 
196  err = norm_sf(comm_one_d, 'div', vv_mesh, list_mode, un)
197  norm = norm_sf(comm_one_d, 'H1', vv_mesh, list_mode, un)
198  IF (rank == 0) THEN
199  !===Divergence of velocity field
200  WRITE(31,*) time, err/norm
201  END IF
202  DO i=1,SIZE(list_mode)
203  norm = norm_s(comm_one_d, 'L2', vv_mesh, list_mode(i:i), un(:,:,i:i))
204  IF (rank_ns_s == 0) THEN
205  !===L2 norm of Fourier mode list_mode(i) of velocity field un
206  WRITE(100+list_mode(i),*) time, norm
207  END IF
208  END DO
209 
210  err = norm_sf(comm_one_d, 'L2', vv_mesh, list_mode, un)
211  norm = norm_sf(comm_one_d, 'sH1', vv_mesh, list_mode, un)
212  IF (rank == 0) THEN
213  WRITE(98,*) time, err
214  WRITE(*,*) 'norm L2 of velocity', time, err
215  WRITE(*,*) 'semi norm H1 of velocity', time, norm
216  END IF
217 
218  err = norm_sf(comm_one_d, 'L2', pp_mesh, list_mode, pn)
219  IF (rank == 0) THEN
220  WRITE(*,*) 'norm L2 of pressure', time, err
221  END IF
222 
223  IF (inputs%if_level_set) THEN
224  !===Compute the term integral(level_set-level_set_t=0)/integral(level_set_t=0)
225  !===Output written in file fort.97
226  IF (inputs%if_level_set_P2) THEN
227  CALL compute_level_set_conservation(time,vv_mesh,comm_one_d_ns,list_mode,level_set)
228  ELSE
229  CALL compute_level_set_conservation(time,pp_mesh,comm_one_d_ns,list_mode,level_set)
230  END IF
231  END IF
232 
233  IF (inputs%if_temperature) THEN
234  norm = norm_sf(comm_one_d_temp, 'L2', temp_mesh, list_mode, temperature)
235  IF (rank == 0) THEN
236  WRITE(99,*) 'norm L2 of temperature', time, norm
237  WRITE(*,*) 'norm L2 of temperature', time, norm
238  END IF
239  END IF
240  END IF ! end nst or mhd or fhd
241 
242  IF (inputs%type_pb/='nst') THEN
243  err = norm_sf(comm_one_d, 'L2', h_mesh, list_mode, hn)
244  IF (rank == 0) THEN
245  !===L2 norm of magnetic field
246  WRITE(41,*) time, err
247  END IF
248  err = norm_sf(comm_one_d, 'div', h_mesh, list_mode, bn)
249  norm = norm_sf(comm_one_d, 'L2', h_mesh, list_mode, bn)
250  IF (rank == 0) THEN
251  !===L2 norm of div(Bn)
252  WRITE(51,*) time, err, err/norm
253  WRITE(52,*) time, err, norm
254  WRITE(*,*) 'norm L2 of magnetic field', time, norm
255  END IF
256  DO i=1,SIZE(list_mode)
257  norm = norm_s(comm_one_d, 'L2', h_mesh, list_mode(i:i), hn(:,:,i:i))
258  IF (rank_s == 0) THEN
259  !===L2 norm of Fourier mode list_mode(i) of magnetic field Hn
260  WRITE(200+list_mode(i),*) time, norm
261  END IF
262  END DO
263  END IF ! end /=nst
264  END IF ! end freq_en
265 
266  IF (mod(it,inputs%freq_plot) == 0) THEN
267  !===Plot whatever you want here
268  IF (it==inputs%freq_plot) THEN
269  what = 'new'
270  ELSE
271  what = 'old'
272  END IF
273  it_plot = it/inputs%freq_plot
274  !===Generation of 3D plots
275  IF (inputs%if_level_set) THEN
276  IF (inputs%if_level_set_P2) THEN
277  level_1_p2=level_set(1,:,:,:)
278  CALL vtu_3d(level_1_p2, 'vv_mesh', 'Level_1', 'level_1', what, opt_it=it_plot)
279  ELSE
280  level_1_p1=level_set(1,:,:,:)
281  CALL vtu_3d(level_1_p1, 'pp_mesh', 'Level_1', 'level_1', what, opt_it=it_plot)
282  END IF
283  !CALL vtu_3d(density, 'vv_mesh', 'Density', 'density', what, opt_it=it_plot)
284  END IF
285  IF (inputs%type_pb/='mxw' .AND. inputs%type_pb/='mxx') THEN
286  IF (inputs%type_fe_velocity==3) THEN
287  CALL vtu_3d(un, 'vv_mesh', 'Velocity', 'vel', what, opt_it=it_plot, opt_mesh_in=vv_mesh)
288  ELSE
289  CALL vtu_3d(un, 'vv_mesh', 'Velocity', 'vel', what, opt_it=it_plot)
290  ENDIF
291  CALL vtu_3d(pn, 'pp_mesh', 'Pressure', 'pre', what, opt_it=it_plot)
292  CALL vtu_3d(un, 'vv_mesh', 'Vorticity', 'vor', what, opt_it=it_plot, &
293  opt_grad_curl='curl_u', opt_mesh_in=vv_mesh)
294  !===Visualization of the penalty function
295  IF (inputs%if_ns_penalty) THEN
296  CALL mpi_comm_size(comm_one_d(2), nb_procs, ierr)
297  m_max_pad = 3*SIZE(list_mode)*nb_procs/2
298  bloc_size = SIZE(vv_mesh%rr,2)/nb_procs+1
299  DO i=1,SIZE(list_mode)
300  IF (list_mode(i)==0) THEN
301  one_chi(:,1,i)=1.d0
302  one_chi(:,2,i)=0.d0
303  ELSE
304  one_chi(:,:,i)=0.d0
305  END IF
306  END DO
307  CALL fft_par_var_eta_prod_gauss_dcl(comm_one_d(2), penal_in_real_space, vv_mesh, &
308  one_chi, chi, nb_procs, bloc_size, m_max_pad, vv_mesh%rr, time)
309  CALL vtu_3d(chi, 'vv_mesh', 'Chi', 'chi', what, opt_it=it_plot)
310  END IF
311  !===Visualization of the penalty function
312  !===2D plots for each mode of the velocity field and the pressure
313  DO i = 1, m_max_c
314  WRITE(st_mode,'(I3)') list_mode(i)
315  header = 'Vn_'//'mode_'//trim(adjustl(st_mode))
316  name_of_field = 'Vn'
317  CALL make_vtu_file_2d(comm_one_d_ns(1), vv_mesh, header, un(:,:,i), name_of_field, what, opt_it=it_plot)
318  WRITE(st_mode,'(I3)') list_mode(i)
319  header = 'Pn_'//'mode_'//trim(adjustl(st_mode))
320  name_of_field = 'Pn'
321  CALL make_vtu_file_2d(comm_one_d_ns(1), pp_mesh, header, pn(:,:,i), name_of_field, what, opt_it=it_plot)
322  END DO
323  END IF
324  IF (inputs%if_temperature) THEN
325  !CALL vtu_3d(temperature, 'temp_mesh', 'Temperature', 'temp', what, opt_it=it_plot)
326  END IF
327  IF (inputs%type_pb/='nst') THEN
328  !CALL vtu_3d(Hn, 'H_mesh', 'MagField', 'mag', what, opt_it=it_plot)
329  !CALL vtu_3d(Hn, 'H_mesh', 'Current', 'cur', what, opt_it=it_plot, &
330  ! opt_grad_curl='curl_h', opt_2D=.FALSE.)
331  !IF (inputs%nb_dom_phi>0) THEN
332  ! CALL vtu_3d(phin, 'phi_mesh', 'ScalPot', 'phi', what, opt_it=it_plot)
333  !END IF
334  END IF
335  !==End generation of 3D plots
336 
337  !===Generation of 2D plots for each Fourier mode (uncomment if wanted)
338  !===Proceed as follows to make 2D plots in the Fourier space (using Hn for instance)
339  !===what = 'new' if first image, what= 'old' for later images (CHARACTER(LEN=3) :: what)
340  !===WRITE(st_mode,'(I3)') list_mode(i) (CHARACTER(LEN=3) :: st_mode)
341  !===header = 'Hn_'//'_mode_'//trim(adjustl(st_mode)) (CHARACTER(LEN=200) :: header)
342  !===name_of_field = 'Hn' (for instance) (CHARACTER(LEN=3) :: name_of_field)
343  !===CALL make_vtu_file_2D(comm_one_(1), H_mesh, header, Hn(:,:,i), name_of_field, what, opt_it=1)
344 !!$ IF (inputs%if_level_set) THEN
345 !!$ !===2D plots for each mode of the first level set
346 !!$ DO i = 1, m_max_c
347 !!$ WRITE(st_mode,'(I3)') list_mode(i)
348 !!$ header = 'Ln_'//'mode_'//trim(adjustl(st_mode))
349 !!$ name_of_field = 'Ln'
350 !!$ IF (inputs%if_level_set_P2) THEN
351 !!$ level_1_P2(:,:,i)=level_set(1,:,:,i)
352 !!$ CALL make_vtu_file_2D(comm_one_d_ns(1), vv_mesh, header, level_1_P2(:,:,i), name_of_field, what, opt_it=it_plot)
353 !!$ ELSE
354 !!$ level_1_P1(:,:,i)=level_set(1,:,:,i)
355 !!$ CALL make_vtu_file_2D(comm_one_d_ns(1), pp_mesh, header, level_1_P1(:,:,i), name_of_field, what, opt_it=it_plot)
356 !!$ END IF
357 !!$ header = 'Dn_'//'mode_'//trim(adjustl(st_mode))
358 !!$ name_of_field = 'Dn'
359 !!$ CALL make_vtu_file_2D(comm_one_d_ns(1), vv_mesh, header, density(:,:,i), name_of_field, what, opt_it=it_plot)
360 !!$ END DO
361 !!$ END IF
362 !!$ IF (inputs%type_pb/='mxw' .AND. inputs%type_pb/='mxx') THEN
363 !!$ !===2D plots for each mode of the velocity field and the pressure
364 !!$ DO i = 1, m_max_c
365 !!$ WRITE(st_mode,'(I3)') list_mode(i)
366 !!$ header = 'Vn_'//'mode_'//trim(adjustl(st_mode))
367 !!$ name_of_field = 'Vn'
368 !!$ CALL make_vtu_file_2D(comm_one_d_ns(1), vv_mesh, header, un(:,:,i), name_of_field, what, opt_it=it_plot)
369 !!$ WRITE(st_mode,'(I3)') list_mode(i)
370 !!$ header = 'Pn_'//'mode_'//trim(adjustl(st_mode))
371 !!$ name_of_field = 'Pn'
372 !!$ CALL make_vtu_file_2D(comm_one_d_ns(1), pp_mesh, header, pn(:,:,i), name_of_field, what, opt_it=it_plot)
373 !!$ END DO
374 !!$ END IF
375 !!$ IF (inputs%if_temperature) THEN
376 !!$ !===2D plots for each mode of the temperature
377 !!$ DO i = 1, m_max_c
378 !!$ WRITE(st_mode,'(I3)') list_mode(i)
379 !!$ header = 'Tn_'//'_mode_'//trim(adjustl(st_mode))
380 !!$ name_of_field = 'Tn'
381 !!$ CALL make_vtu_file_2D(comm_one_d_temp(1), temp_mesh, header, temperature(:,:,i), name_of_field, what, opt_it=it_plot) ! MODIFICATION: comm_one_d_temp instead of comm_one_d
382 !!$ END DO
383 !!$ END IF
384 !!$ IF (inputs%type_pb/='nst') THEN
385 !!$ !===2D plots for each mode of the magnetic field and the scalar potential
386 !!$ DO i = 1, m_max_c
387 !!$ WRITE(st_mode,'(I3)') list_mode(i)
388 !!$ header = 'Hn_'//'_mode_'//trim(adjustl(st_mode))
389 !!$ name_of_field = 'Hn'
390 !!$ CALL make_vtu_file_2D(comm_one_d(1), H_mesh, header, Hn(:,:,i), name_of_field, what, opt_it=it_plot)
391 !!$ IF (inputs%nb_dom_phi>0) THEN
392 !!$ WRITE(st_mode,'(I3)') list_mode(i)
393 !!$ header = 'Phin_'//'_mode_'//trim(adjustl(st_mode))
394 !!$ name_of_field = 'Phin'
395 !!$ CALL make_vtu_file_2D(comm_one_d(1), phi_mesh, header, phin(:,:,i), name_of_field, what, opt_it=it_plot)
396 !!$ END IF
397 !!$ END DO
398 !!$ END IF
399  !===End Generation of 2D plots for each Fourier mode (uncomment if wanted)
400 
401  END IF ! end freq_plot
402 
403  END SUBROUTINE my_post_processing
404 
405  SUBROUTINE forces_and_moments(time,vv_mesh,communicator,list_mode,un)
407  USE input_data
408  USE boundary
409  USE sft_parallele
410 #include "petsc/finclude/petsc.h"
411  USE petsc
412  IMPLICIT NONE
413  TYPE(mesh_type), INTENT(IN) :: vv_mesh
414  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
415  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: un
416  REAL(KIND=8), INTENT(IN) :: time
417  REAL(KIND=8), DIMENSION(vv_mesh%gauss%l_G*vv_mesh%dom_me,6,SIZE(list_mode)) :: vel_gauss, vel_gauss_penal
418  REAL(KIND=8), DIMENSION(2,vv_mesh%gauss%l_G*vv_mesh%dom_me) :: rr_gauss
419  INTEGER, DIMENSION(vv_mesh%gauss%n_w) :: j_loc
420  REAL(KIND=8) :: vel_torque, vel_torque_tot
421  INTEGER :: m, l , i, mode, index, type, nb_procs, m_max_pad, bloc_size
422  petscerrorcode :: ierr
423  mpi_comm,DIMENSION(2) :: communicator
424 
425  index = 0
426  DO m = 1, vv_mesh%dom_me
427  j_loc = vv_mesh%jj(:,m)
428  DO l = 1, vv_mesh%gauss%l_G
429  index = index + 1
430  rr_gauss(1,index) = sum(vv_mesh%rr(1,j_loc)*vv_mesh%gauss%ww(:,l))
431  rr_gauss(2,index) = sum(vv_mesh%rr(2,j_loc)*vv_mesh%gauss%ww(:,l))
432  END DO
433  END DO
434 
435  DO i = 1, SIZE(list_mode)
436  mode = list_mode(i)
437  index = 0
438  DO m = 1, vv_mesh%dom_me
439  j_loc = vv_mesh%jj(:,m)
440  DO l = 1, vv_mesh%gauss%l_G
441  index = index + 1
442  DO type = 1, 6
443  vel_gauss(index,type,i) = sum(un(j_loc,type,i)*vv_mesh%gauss%ww(:,l))*(3/(2*inputs%dt))
444  END DO
445  END DO
446  END DO
447  IF(inputs%if_impose_vel_in_solids) THEN
448  IF (mode==0) THEN
449  vel_gauss(:,:,i) = vel_gauss(:,:,i) - imposed_velocity_by_penalty(rr_gauss(:,:),time)
450  ENDIF
451  END IF
452  END DO
453 
454  CALL mpi_comm_size(communicator(2), nb_procs, ierr)
455  m_max_pad = 3*SIZE(list_mode)*nb_procs/2
456  bloc_size = SIZE(vel_gauss,1)/nb_procs+1
457  CALL fft_par_var_eta_prod_gauss_dcl(communicator(2), penal_in_real_space, vv_mesh, &
458  vel_gauss, vel_gauss_penal, nb_procs, bloc_size, m_max_pad, rr_gauss, time)
459 
460  vel_torque = 0.d0
461  DO i = 1, SIZE(list_mode)
462  mode = list_mode(i)
463  IF (mode/=0) THEN
464  cycle
465  ELSE
466  index = 0
467  DO m = 1, vv_mesh%dom_me
468  j_loc = vv_mesh%jj(:,m)
469  DO l = 1, vv_mesh%gauss%l_G
470  index = index + 1
471  !===Force is int_domain ((1-chi)*(u-u_solid)/dt )dx
472  vel_torque = vel_torque + (vel_gauss_penal(index,5,i) - vel_gauss(index,5,i)) &
473  *rr_gauss(1,index)*vv_mesh%gauss%rj(l,m)
474  END DO
475  END DO
476  CALL mpi_allreduce(vel_torque, vel_torque_tot,1,mpi_double_precision, mpi_sum, communicator(1), ierr)
477  WRITE(*,*) ' FORCES_AND_MOMENTS ', time, 2*acos(-1.d0)*vel_torque_tot/(0.5d0*acos(-1.d0))
478  WRITE(12,*) time, 2*acos(-1.d0)*vel_torque_tot/(0.5d0*acos(-1.d0))
479  END IF
480  END DO
481  END SUBROUTINE forces_and_moments
482 
483  SUBROUTINE compute_level_set_conservation(time, mesh, communicator, list_mode, level_set)
485  USE input_data
486  USE boundary
487  USE sft_parallele
488 #include "petsc/finclude/petsc.h"
489  USE petsc
490  IMPLICIT NONE
491  TYPE(mesh_type), INTENT(IN) :: mesh
492  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
493  REAL(KIND=8), DIMENSION(:,:,:,:), INTENT(IN) :: level_set
494  REAL(KIND=8), INTENT(IN) :: time
495  LOGICAL, SAVE :: once_compute=.true.
496  REAL(KIND=8), ALLOCATABLE, DIMENSION(:), SAVE :: volum_init
497  REAL(KIND=8) :: volum_init_loc, volum_init_F
498  REAL(KIND=8) :: inte_fft_loc, inte_fft_tot_F
499  REAL(KIND=8), DIMENSION(inputs%nb_fluid-1) :: inte_fft_tot
500  REAL(KIND=8), DIMENSION(mesh%np, 2, SIZE(list_mode)) :: level_posi_fft
501  REAL(KIND=8) :: ray
502  INTEGER, DIMENSION(mesh%gauss%n_w) :: j_loc
503  INTEGER :: m, l , i, nb_inter
504  INTEGER :: my_petscworld_rank, code
505  mpi_comm,DIMENSION(2) :: communicator
506 
507  CALL mpi_comm_rank(petsc_comm_world,my_petscworld_rank,code)
508 
509 103 FORMAT(1500(e22.9,2x))
510 
511  !===Computation of initial integral of level set
512  IF (once_compute) THEN
513  once_compute = .false.
514 
515  ALLOCATE(volum_init(SIZE(level_set,1)))
516 
517  DO nb_inter=1, SIZE(level_set,1)
518  volum_init_loc = 0.d0
519  DO i = 1, SIZE(list_mode)
520  IF (list_mode(i)==0) THEN
521  DO m = 1, mesh%me
522  j_loc = mesh%jj(:,m)
523  DO l = 1, mesh%gauss%l_G
524  !===Compute radius of Gauss point
525  ray = sum(mesh%rr(1,j_loc)*mesh%gauss%ww(:,l))
526  volum_init_loc = volum_init_loc + sum(level_set_exact(nb_inter,1,mesh%rr(:,j_loc),list_mode(i),0.d0)* &
527  mesh%gauss%ww(:,l))*ray*mesh%gauss%rj(l,m)
528  END DO
529  END DO
530  END IF
531  END DO
532  volum_init_loc = volum_init_loc*2*acos(-1.d0)
533  CALL mpi_allreduce(volum_init_loc, volum_init_f, 1, mpi_double_precision, mpi_sum, &
534  communicator(2), code)
535  CALL mpi_allreduce(volum_init_f, volum_init(nb_inter), 1, mpi_double_precision, mpi_sum, &
536  communicator(1), code)
537  END DO
538  IF (my_petscworld_rank==0) THEN
539  WRITE(*,*) 'mass initial = ', time, volum_init
540  END IF
541  END IF !end once_compute
542 
543  !===Computation of level set conservation relative error
544  DO nb_inter=1, SIZE(level_set,1)
545  level_posi_fft = level_set(nb_inter,:,:,:)
546  inte_fft_loc = 0.d0
547  DO i = 1, SIZE(list_mode)
548  IF (list_mode(i)==0) THEN
549  DO m = 1, mesh%me
550  j_loc = mesh%jj(:,m)
551  DO l = 1, mesh%gauss%l_G
552  !===Compute radius of Gauss point
553  ray = sum(mesh%rr(1,j_loc)*mesh%gauss%ww(:,l))
554  inte_fft_loc = inte_fft_loc + sum(level_posi_fft(j_loc,1,i)*mesh%gauss%ww(:,l))* &
555  ray*mesh%gauss%rj(l,m)
556  END DO
557  END DO
558  END IF
559  END DO
560  inte_fft_loc = inte_fft_loc*2*acos(-1.d0)
561  CALL mpi_allreduce(inte_fft_loc, inte_fft_tot_f, 1, mpi_double_precision, mpi_sum, &
562  communicator(2), code)
563  CALL mpi_allreduce(inte_fft_tot_f, inte_fft_tot(nb_inter), 1, mpi_double_precision, mpi_sum, &
564  communicator(1), code)
565  END DO
566  IF (my_petscworld_rank==0) THEN
567  WRITE(*,*) 'relative mass error of level set at t = ', &
568  time, abs(1-inte_fft_tot/(volum_init+1.d-14))
569  WRITE(97,103) time, abs(1-inte_fft_tot/(volum_init+1.d-14))
570  END IF
571  END SUBROUTINE compute_level_set_conservation
572 
573 END PROGRAM mhd_prog
subroutine, public make_vtu_file_2d(communicator, mesh_in, header, field_in, field_name, what, opt_it)
subroutine, public fft_par_var_eta_prod_gauss_dcl(communicator, eta, H_mesh, c_in, c_out, nb_procs, bloc_size, m_max_pad, rr_gauss, time, temps)
subroutine error_petsc(string)
Definition: my_util.f90:16
type(my_data), public inputs
real(kind=8) function user_time()
Definition: my_util.f90:8
subroutine, public vtu_3d(field, name_of_mesh, header, name_of_field, what, opt_it, opt_grad_curl, opt_2D, opt_mesh_in)
subroutine, public save_run(it, freq_restart)
subroutine compute_level_set_conservation(time, mesh, communicator, list_mode, level_set)
Definition: main.f90:484
subroutine, public post_proc_test(vv_mesh, pp_mesh, temp_mesh, H_mesh, phi_mesh, list_mode, un, pn, Hn, Bn, phin, tempn, level_setn, mu_H_field, time, m_max_c, comm_one_d, comm_one_d_ns, comm_one_d_temp)
real(kind=8) function norm_s(communicator, norm_type, mesh, list_mode, v)
Definition: tn_axi.f90:88
subroutine, public write_verbose(rank, opt_tps, opt_tploc_max)
Definition: verbose.f90:32
subroutine, public initial(vv_mesh_out, pp_mesh_out, H_mesh_out, phi_mesh_out, temp_mesh_out, interface_H_phi_out, interface_H_mu_out, list_mode_out, un_out, pn_out, Hn_out, Bn_out, phin_out, v_to_Max_out, vol_heat_capacity_field_out, temperature_diffusivity_field_out, mu_H_field_out, sigma_field_out, time_out, m_max_c_out, comm_one_d_out, comm_one_d_ns_out, comm_one_d_temp_out, tempn_out, level_set_out, density_out, der_un_out)
program mhd_prog
Definition: main.f90:1
Definition: tn_axi.f90:5
real(kind=8) function norm_sf(communicator, norm_type, mesh, list_mode, v)
Definition: tn_axi.f90:40
subroutine my_post_processing(it)
Definition: main.f90:136
subroutine, public run_sfemans(time_in, it)
subroutine gauss(mesh)
real(kind=8), dimension(:,:), pointer ww
subroutine forces_and_moments(time, vv_mesh, communicator, list_mode, un)
Definition: main.f90:406
subroutine, public read_user_data(data_file)