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