SFEMaNS  version 5.3
Reference documentation for SFEMaNS
sub_ns_with_velocity.f90
Go to the documentation of this file.
1 !
2 !Authors Jean-Luc Guermond, Raphael Laguerre, Caroline Nore, Copyrights 2005
3 !Revised for PETSC, Jean-Luc Guermond, Franky Luddens, January 2011
4 !
6  USE my_util
7 #include "petsc/finclude/petsc.h"
8  USE petsc
9  USE subroutine_ns_with_m ! MODIFICATION: for smb_explicit_diffu_sym
10  PUBLIC :: moy, bdf2_ns_stress_bc_with_u
11  PRIVATE
12 CONTAINS
13 
14  SUBROUTINE bdf2_ns_stress_bc_with_u(comm_one_d, time, vv_3_LA, pp_1_LA, vvz_per, pp_per, dt, Re, list_mode, pp_mesh, &
15  vv_mesh, incpn_m1, incpn, pn_m1, pn, un_m1, un, &
16  chmp_mag, bn_p2, opt_tempn)
17  !==============================
18  USE def_type_mesh
19  USE fem_m_axi
20  USE fem_rhs_axi
21  USE fem_tn_axi
22  USE dir_nodes_petsc
23  USE periodic
24  USE st_matrix
25  USE solve_petsc
26  USE dyn_line
27  USE boundary
29  USE sub_plot
30  USE st_matrix
31  USE input_data
34  USE tn_axi
35  USE verbose
37  USE my_util
38  IMPLICIT NONE
39  REAL(KIND=8) :: time, dt, Re
40  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
41  TYPE(mesh_type), INTENT(IN) :: pp_mesh, vv_mesh
42  TYPE(petsc_csr_la) :: vv_3_LA, pp_1_LA
43  TYPE(periodic_type), INTENT(IN) :: vvz_per, pp_per
44  REAL(KIND=8), DIMENSION(:,:,:), INTENT(INOUT) :: incpn_m1, incpn
45  REAL(KIND=8), DIMENSION(:,:,:), INTENT(INOUT) :: pn_m1, pn
46  REAL(KIND=8), DIMENSION(:,:,:), INTENT(INOUT) :: un_m1, un
47  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN), OPTIONAL:: opt_tempn
48  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: chmp_mag, Bn_p2
49  REAL(KIND=8), DIMENSION(vv_mesh%np,6,SIZE(list_mode)):: chmp_mag_aux
50  !===Saved variables
51  INTEGER, SAVE :: m_max_c
52  !INTEGER, DIMENSION(:), POINTER, SAVE :: pp_js_D
53  !INTEGER, DIMENSION(:), POINTER, SAVE :: pp_js_axis_D
54  TYPE(dyn_real_line),DIMENSION(:), ALLOCATABLE, SAVE :: pp_global_D
55  TYPE(dyn_int_line), DIMENSION(:), POINTER, SAVE :: pp_mode_global_js_D
56  TYPE(dyn_int_line), DIMENSION(3), SAVE :: vv_js_D
57  !INTEGER, DIMENSION(:), POINTER, SAVE :: vv_js_axis_D
58  TYPE(dyn_int_line), DIMENSION(:), POINTER, SAVE :: vv_mode_global_js_D
59  TYPE(dyn_real_line),DIMENSION(:), ALLOCATABLE, SAVE :: vel_global_D
60  LOGICAL, SAVE :: once = .true.
61  INTEGER, SAVE :: my_petscworld_rank
62  REAL(KIND=8), DIMENSION(:,:,:,:),ALLOCATABLE, SAVE :: visco_entro_sym_grad_u
63  !===End saved variables
64 
65  !----------Declaration sans save-------------------------------------------------------
66  INTEGER, POINTER, DIMENSION(:) :: pp_1_ifrom, vv_3_ifrom
67 
68  INTEGER :: i, k, m, n, n1, n2, n3, n123
69  INTEGER :: nb_procs, code, nu_mat, mode
70  REAL(KIND=8) :: moyenne
71  !allocations des variables locales
72  REAL(KIND=8), DIMENSION(pp_mesh%np, 2, SIZE(list_mode)) :: div
73  REAL(KIND=8), DIMENSION(pp_mesh%np, 2) :: pn_p1, phi
74  REAL(KIND=8), DIMENSION(vv_mesh%np, 6) :: un_p1
75  REAL(KIND=8), DIMENSION(vv_mesh%np, 6, SIZE(list_mode)) :: un_m2
76  REAL(KIND=8), DIMENSION(vv_mesh%gauss%l_G*vv_mesh%dom_me,6,SIZE(list_mode)) :: rotv_v, rotb_b, rotb_b_aux
77  REAL(KIND=8), DIMENSION(vv_mesh%gauss%l_G*vv_mesh%dom_me,6,SIZE(list_mode)) :: mag_force
78  REAL(KIND=8), DIMENSION(vv_mesh%gauss%l_G*vv_mesh%dom_me,6,SIZE(list_mode)) :: rhs_gauss
79  REAL(KIND=8), DIMENSION(vv_mesh%np,6,SIZE(list_mode)) :: uext
80  REAL(KIND=8), DIMENSION(vv_mesh%np,2,SIZE(list_mode)) :: nu_tilde ! MODIFICATION: variable part of the kinematic viscosity
81  REAL(KIND=8), DIMENSION(3,vv_mesh%gauss%l_G*vv_mesh%dom_me,6,SIZE(list_mode)) :: two_nu_tilde_grads_u_ext ! MODIFICATION: 2 times variable part of nu times symmetric gradient of u
82  REAL(KIND=8), DIMENSION(vv_mesh%np) :: vel_loc, vel_tot
83  REAL(KIND=8) :: tps, tps_tot, tps_cumul, coeff, vloc, cfl, cfl_max, norm
84  !April 17th 2008, JLG
85  REAL(KIND=8) :: one, zero, three
86  DATA zero, one, three/0.d0,1.d0,3.d0/
87 
88  !Communicators for Petsc, in space and Fourier------------------------------
89  petscerrorcode :: ierr
90  mpi_comm, DIMENSION(:), POINTER :: comm_one_d
91  mat, DIMENSION(:), POINTER, SAVE :: vel_mat
92  mat, DIMENSION(:), POINTER, SAVE :: press_mat
93  mat, SAVE :: mass_mat, mass_mat0
94  vec, SAVE :: vb_3_145, vb_3_236, vx_3, vx_3_ghost
95  vec, SAVE :: pb_1, pb_2, px_1, px_1_ghost
96  ksp, DIMENSION(:), POINTER, SAVE :: vel_ksp, press_ksp
97  ksp, SAVE :: mass_ksp, mass_ksp0
98  !------------------------------END OF DECLARATION--------------------------------------
99 
100  IF (once) THEN
101  once = .false.
102  CALL mpi_comm_rank(petsc_comm_world,my_petscworld_rank,code)
103 
104  !===CREATE PETSC VECTORS AND GHOSTS
105  CALL create_my_ghost(vv_mesh,vv_3_la,vv_3_ifrom)
106  n = 3*vv_mesh%dom_np
107  CALL veccreateghost(comm_one_d(1), n, &
108  petsc_determine, SIZE(vv_3_ifrom), vv_3_ifrom, vx_3, ierr)
109  CALL vecghostgetlocalform(vx_3, vx_3_ghost, ierr)
110  CALL vecduplicate(vx_3, vb_3_145, ierr)
111  CALL vecduplicate(vx_3, vb_3_236, ierr)
112 
113  CALL create_my_ghost(pp_mesh,pp_1_la,pp_1_ifrom)
114  n = pp_mesh%dom_np
115  CALL veccreateghost(comm_one_d(1), n, &
116  petsc_determine, SIZE(pp_1_ifrom), pp_1_ifrom, px_1, ierr)
117  CALL vecghostgetlocalform(px_1, px_1_ghost, ierr)
118  CALL vecduplicate(px_1, pb_1, ierr)
119  CALL vecduplicate(px_1, pb_2, ierr)
120  !===End CREATE PETSC VECTORS AND GHOSTS
121 
122  !===Number of modes on proc
123  m_max_c = SIZE(list_mode)
124  !===End umber of modes on proc
125 
126  !===PREPARE pp_mode_global_js_D ARRAY FOR PRESSURE
127  !===ATTENTION pressure BCs are no longer implemented
128  !===JLG JUne 9 2017
129  !CALL scalar_glob_js_D(pp_mesh, list_mode, pp_1_LA, pp_mode_global_js_D)
130  CALL scalar_without_glob_js_d(pp_mesh, list_mode, pp_1_la, pp_mode_global_js_d)
131  ALLOCATE(pp_global_d(m_max_c))
132  DO i = 1, m_max_c
133  ALLOCATE(pp_global_d(i)%DRL(SIZE(pp_mode_global_js_d(i)%DIL)))
134  END DO
135  !===End PREPARE pp_mode_global_js_D ARRAY FOR PRESSURE
136 
137  !===PREPARE TYPE OF BOUNDARY CONDITIONS AND js_D ARRAY FOR VELOCITY
138  CALL vector_glob_js_d(vv_mesh, list_mode, vv_3_la, inputs%vv_list_dirichlet_sides, &
139  vv_js_d, vv_mode_global_js_d)
140 
141  ALLOCATE(vel_global_d(m_max_c))
142  DO i = 1, m_max_c
143  ALLOCATE(vel_global_d(i)%DRL(SIZE(vv_mode_global_js_d(i)%DIL)))
144  END DO
145  !===END PREPARE TYPE OF BOUNDARY CONDITIONS AND js_D ARRAY FOR VELOCITY
146 
147  !===ASSEMBLE MASS MATRIX
148  CALL create_local_petsc_matrix(comm_one_d(1), pp_1_la, mass_mat, clean=.false.)
149  CALL qs_diff_mass_scal_m (pp_mesh, pp_1_la, 0.d0, 1.d0, 0.d0, 0, mass_mat)
150  IF (inputs%my_periodic%nb_periodic_pairs/=0) THEN
151  CALL periodic_matrix_petsc(pp_per%n_bord, pp_per%list, pp_per%perlist, mass_mat, pp_1_la)
152  END IF
153  DO i = 1, m_max_c
154  IF (list_mode(i)==0) cycle
155  CALL dirichlet_m_parallel(mass_mat,pp_mode_global_js_d(i)%DIL)
156  END DO
157  CALL init_solver(inputs%my_par_mass,mass_ksp,mass_mat,comm_one_d(1),&
158  solver=inputs%my_par_mass%solver,precond=inputs%my_par_mass%precond)
159 
160  IF (minval(list_mode)==0) THEN
161  CALL create_local_petsc_matrix(comm_one_d(1), pp_1_la, mass_mat0, clean=.false.)
162  CALL qs_diff_mass_scal_m (pp_mesh, pp_1_la, 0.d0, 1.d0, 0.d0, 0, mass_mat0)
163  IF (inputs%my_periodic%nb_periodic_pairs/=0) THEN
164  CALL periodic_matrix_petsc(pp_per%n_bord, pp_per%list, pp_per%perlist, mass_mat0, pp_1_la)
165  END IF
166  DO i = 1, m_max_c
167  IF (list_mode(i).NE.0) cycle
168  CALL dirichlet_m_parallel(mass_mat0,pp_mode_global_js_d(i)%DIL)
169  CALL init_solver(inputs%my_par_mass,mass_ksp0,mass_mat0,comm_one_d(1),&
170  solver=inputs%my_par_mass%solver,precond=inputs%my_par_mass%precond)
171  END DO
172  END IF
173  !===END ASSEMBLE MASS MATRIX
174 
175  !===ASSEMBLING VELOCITY MATRICES
176  ALLOCATE(visco_entro_sym_grad_u(3,vv_mesh%gauss%l_G*vv_mesh%dom_me,6,SIZE(list_mode)))
177  visco_entro_sym_grad_u = 0.d0
178  ALLOCATE(vel_mat(2*m_max_c),vel_ksp(2*m_max_c))
179  ALLOCATE(press_mat(m_max_c),press_ksp(m_max_c))
180  DO i = 1, m_max_c
181  mode = list_mode(i)
182  !===VELOCITY
183  nu_mat = 2*i-1
184  CALL create_local_petsc_matrix(comm_one_d(1), vv_3_la, vel_mat(nu_mat), clean=.false.)
185  CALL qs_diff_mass_vect_3x3_divpenal (1, vv_3_la, vv_mesh, one/re, three/(2*dt), &
186  inputs%LES_coeff1, inputs%stab_bdy_ns, i, mode, vel_mat(nu_mat))
187  IF (inputs%my_periodic%nb_periodic_pairs/=0) THEN
188  CALL periodic_matrix_petsc(vvz_per%n_bord, vvz_per%list,vvz_per%perlist, &
189  vel_mat(nu_mat), vv_3_la)
190  END IF
191  CALL dirichlet_m_parallel(vel_mat(nu_mat),vv_mode_global_js_d(i)%DIL)
192  CALL init_solver(inputs%my_par_vv,vel_ksp(nu_mat),vel_mat(nu_mat),comm_one_d(1),&
193  solver=inputs%my_par_vv%solver,precond=inputs%my_par_vv%precond)
194  nu_mat = nu_mat+1
195  CALL create_local_petsc_matrix(comm_one_d(1), vv_3_la, vel_mat(nu_mat), clean=.false.)
196  CALL qs_diff_mass_vect_3x3_divpenal (2, vv_3_la, vv_mesh, one/re, three/(2*dt), &
197  inputs%LES_coeff1, inputs%stab_bdy_ns, i, mode, vel_mat(nu_mat))
198  IF (inputs%my_periodic%nb_periodic_pairs/=0) THEN
199  CALL periodic_matrix_petsc(vvz_per%n_bord, vvz_per%list,vvz_per%perlist, &
200  vel_mat(nu_mat), vv_3_la)
201  END IF
202  CALL dirichlet_m_parallel(vel_mat(nu_mat),vv_mode_global_js_d(i)%DIL)
203  CALL init_solver(inputs%my_par_vv,vel_ksp(nu_mat),vel_mat(nu_mat),comm_one_d(1),&
204  solver=inputs%my_par_vv%solver,precond=inputs%my_par_vv%precond)
205  !===End VELOCITY
206 
207  !===PRESSURE
208  CALL create_local_petsc_matrix(comm_one_d(1), pp_1_la, press_mat(i), clean=.false.)
209  !JLG Jan 2014 (regularize pressure matrix)
210  !CALL qs_diff_mass_scal_M(pp_mesh, pp_1_LA, one, zero, zero, mode, press_mat(i))
211  CALL qs_diff_mass_scal_m(pp_mesh, pp_1_la, one, 1.d-10, zero, mode, press_mat(i))
212  IF (inputs%my_periodic%nb_periodic_pairs/=0) THEN
213  CALL periodic_matrix_petsc(pp_per%n_bord, pp_per%list, pp_per%perlist, press_mat(i), pp_1_la)
214  END IF
215  CALL dirichlet_m_parallel(press_mat(i),pp_mode_global_js_d(i)%DIL)
216  CALL init_solver(inputs%my_par_pp,press_ksp(i),press_mat(i),comm_one_d(1),&
217  solver=inputs%my_par_pp%solver,precond=inputs%my_par_pp%precond)
218  !===End PRESSURE
219  ENDDO
220  !===End ASSEMBLING VELOCITY MATRICES
221  ENDIF !===End of once
222 
223  !===Compute NL by FFT at Gauss points
224  tps_tot = user_time()
225  tps_cumul = 0
226  tps = user_time()
227  uext = 2*un-un_m1
228  CALL smb_cross_prod_gauss_sft_par(comm_one_d(2),vv_mesh,list_mode,uext,rotv_v,inputs%precession)
229 
230  IF (inputs%type_pb=='mhd') THEN
231  !===Compute Lorentz force if mhd in quasi-static limit
232  IF (inputs%if_quasi_static_approx) THEN
233  DO i = 1, m_max_c
234  mode = list_mode(i)
235  chmp_mag_aux(:,:,i) = h_b_quasi_static('H', vv_mesh%rr, mode)
236  END DO
237  CALL smb_curlh_cross_b_gauss_sft_par(comm_one_d(2),vv_mesh,list_mode,chmp_mag_aux,bn_p2,rotb_b_aux)
238  DO i = 1, m_max_c
239  mode = list_mode(i)
240  chmp_mag_aux(:,:,i) = h_b_quasi_static('B', vv_mesh%rr, mode)
241  END DO
242  CALL smb_curlh_cross_b_gauss_sft_par(comm_one_d(2),vv_mesh,list_mode,chmp_mag,chmp_mag_aux,rotb_b)
243  rotb_b = rotb_b + rotb_b_aux
244  ELSE !===Compute Lorentz force if mhd
245  CALL smb_curlh_cross_b_gauss_sft_par(comm_one_d(2),vv_mesh,list_mode,chmp_mag,bn_p2,rotb_b)
246  END IF
247  rotv_v = rotv_v - rotb_b
248  END IF
249 
250  IF (inputs%type_pb=='fhd') THEN
251  !===Computate magnetic force if fhd
252  IF (inputs%if_helmholtz_force) THEN
253  CALL smb_helmholtz_force_gauss_fft_par(comm_one_d(2),vv_mesh,list_mode,opt_tempn,chmp_mag,mag_force)
254  ELSE
255  CALL smb_kelvin_force_gauss_fft_par(comm_one_d(2),vv_mesh,list_mode,opt_tempn,chmp_mag,mag_force)
256  END IF
257  rotv_v = rotv_v - mag_force
258  END IF
259 
260  tps = user_time() - tps; tps_cumul=tps_cumul+tps
261  !===End Compute NL by FFT at Gauss points
262 
263  !===Computation of CFL
264  IF (inputs%verbose_CFL) THEN
265  vel_loc = 0.d0
266  DO i = 1, m_max_c
267  IF (list_mode(i)==0) THEN
268  coeff = 1.d0
269  ELSE
270  coeff = .5d0
271  END IF
272  vel_loc = vel_loc + coeff*(un(:,1,i)**2+un(:,2,i)**2+un(:,3,i)**2 &
273  +un(:,4,i)**2+un(:,5,i)**2+un(:,6,i)**2)
274  END DO
275  CALL mpi_comm_size(comm_one_d(2),nb_procs,code)
276  CALL mpi_allreduce(vel_loc,vel_tot,vv_mesh%np,mpi_double_precision, mpi_sum, comm_one_d(2), code)
277  vel_tot = sqrt(vel_tot)
278  cfl = 0.d0
279  DO m = 1, vv_mesh%dom_me
280  vloc = maxval(vel_tot(vv_mesh%jj(:,m)))
281  !cfl = MAX(vloc*dt/MIN(vv_mesh%hloc(m),0.5d0/inputs%m_max),cfl)
282  cfl = max(vloc*dt/min(vv_mesh%hloc(m),maxval(vv_mesh%hm)),cfl) !(JLG April 7 2017)
283  END DO
284  CALL mpi_allreduce(cfl,cfl_max,1,mpi_double_precision, mpi_max, comm_one_d(1), code)
285  talk_to_me%CFL=cfl_max
286  talk_to_me%time=time
287  END IF
288  !===End Computation of CFL
289 
290  !===Computation of rhs at Gauss points for every mode
291  IF (PRESENT(opt_tempn)) THEN
292  CALL rhs_ns_gauss_3x3(vv_mesh, pp_mesh, comm_one_d(2), list_mode, time, &
293  (4*un-un_m1)/(2*inputs%dt), pn, (4.d0*incpn-incpn_m1)/3.d0, &
294  rotv_v, rhs_gauss, opt_tempn=opt_tempn)
295  ELSE
296  CALL rhs_ns_gauss_3x3(vv_mesh, pp_mesh, comm_one_d(2), list_mode, time, &
297  (4*un-un_m1)/(2*inputs%dt), pn, (4.d0*incpn-incpn_m1)/3.d0, &
298  rotv_v, rhs_gauss)
299  END IF
300  !===End Computation of rhs
301 
302  !===Computation of 2 * nu_tilde(T) * grad^s u
303  IF (inputs%if_variable_visco) THEN
304  nu_tilde = opt_tempn
305  CALL smb_nu_tilde_fft_par(comm_one_d(2), list_mode, nu_tilde)
306  IF (.NOT. (inputs%verbose_CFL)) THEN
307  CALL mpi_comm_size(comm_one_d(2), nb_procs, code)
308  END IF
309  CALL smb_explicit_diffu_sym(comm_one_d(2), vv_mesh, list_mode, nb_procs, &
310  nu_tilde, 2 * un - un_m1, two_nu_tilde_grads_u_ext)
311  END IF
312  !===End Computation of 2 * nu_tilde(T) * grad^s u
313 
314  DO i = 1, m_max_c
315  tps = user_time()
316  mode = list_mode(i)
317 
318  !===Compute phi
319  pn_p1(:,:) = pn(:,:,i)
320 
321  !===Assemble vb_3_145, vb_3_236 using rhs_gauss
322  IF (inputs%LES) THEN
323  CALL rhs_3x3(vv_mesh, vv_3_la, mode, rhs_gauss(:,:,i), vb_3_145, vb_3_236, &
324  opt_tensor=-visco_entro_sym_grad_u(:,:,:,i))
325  ELSE IF (inputs%if_variable_visco) THEN
326  CALL rhs_3x3(vv_mesh, vv_3_la, mode, rhs_gauss(:,:,i), vb_3_145, vb_3_236, &
327  opt_tensor=-two_nu_tilde_grads_u_ext(:,:,:,i)) ! MODIFICATION: variable part of nu term in the RHS, constant part of nu (in data) in the LHS
328  ELSE
329  CALL rhs_3x3(vv_mesh, vv_3_la, mode, rhs_gauss(:,:,i), vb_3_145, vb_3_236)
330  END IF
331  !===Periodic boundary conditions
332  IF (inputs%my_periodic%nb_periodic_pairs/=0) THEN
333  CALL periodic_rhs_petsc(vvz_per%n_bord, vvz_per%list, vvz_per%perlist, vb_3_236, vv_3_la)
334  CALL periodic_rhs_petsc(vvz_per%n_bord, vvz_per%list, vvz_per%perlist, vb_3_145, vv_3_la)
335  END IF
336  !===Axis boundary conditions
337  n1 = SIZE(vv_js_d(1)%DIL)
338  n2 = SIZE(vv_js_d(2)%DIL)
339  n3 = SIZE(vv_js_d(3)%DIL)
340  n123 = n1+n2+n3
341  vel_global_d(i)%DRL(1:n1) = vv_exact(1,vv_mesh%rr(:,vv_js_d(1)%DIL), mode, time)
342  vel_global_d(i)%DRL(n1+1:n1+n2) = vv_exact(4,vv_mesh%rr(:,vv_js_d(2)%DIL), mode, time)
343  vel_global_d(i)%DRL(n1+n2+1:n123)= vv_exact(5,vv_mesh%rr(:,vv_js_d(3)%DIL), mode, time)
344  vel_global_d(i)%DRL(n123+1:) = 0.d0
345  CALL dirichlet_rhs(vv_mode_global_js_d(i)%DIL-1,vel_global_d(i)%DRL,vb_3_145)
346  vel_global_d(i)%DRL(1:n1) = vv_exact(2,vv_mesh%rr(:,vv_js_d(1)%DIL), mode, time)
347  vel_global_d(i)%DRL(n1+1:n1+n2) = vv_exact(3,vv_mesh%rr(:,vv_js_d(2)%DIL), mode, time)
348  vel_global_d(i)%DRL(n1+n2+1:n123)= vv_exact(6,vv_mesh%rr(:,vv_js_d(3)%DIL), mode, time)
349  CALL dirichlet_rhs(vv_mode_global_js_d(i)%DIL-1,vel_global_d(i)%DRL,vb_3_236)
350  tps = user_time() - tps; tps_cumul=tps_cumul+tps
351  !===End Assemble vb_3_145, vb_3_236 using rhs_gauss
352 
353  !===Solve linear system for momentum equation
354  tps = user_time()
355  !===Solve system 1, ur_c, ut_s, uz_c
356  nu_mat =2*i-1
357  CALL solver(vel_ksp(nu_mat),vb_3_145,vx_3,reinit=.false.,verbose=inputs%my_par_vv%verbose)
358  CALL vecghostupdatebegin(vx_3,insert_values,scatter_forward,ierr)
359  CALL vecghostupdateend(vx_3,insert_values,scatter_forward,ierr)
360  CALL extract(vx_3_ghost,1,1,vv_3_la,un_p1(:,1))
361  CALL extract(vx_3_ghost,2,2,vv_3_la,un_p1(:,4))
362  CALL extract(vx_3_ghost,3,3,vv_3_la,un_p1(:,5))
363 
364  !===Solve system 2, ur_s, ut_c, uz_s
365  nu_mat = nu_mat + 1
366  CALL solver(vel_ksp(nu_mat),vb_3_236,vx_3,reinit=.false.,verbose=inputs%my_par_vv%verbose)
367  CALL vecghostupdatebegin(vx_3,insert_values,scatter_forward,ierr)
368  CALL vecghostupdateend(vx_3,insert_values,scatter_forward,ierr)
369  CALL extract(vx_3_ghost,1,1,vv_3_la,un_p1(:,2))
370  CALL extract(vx_3_ghost,2,2,vv_3_la,un_p1(:,3))
371  CALL extract(vx_3_ghost,3,3,vv_3_la,un_p1(:,6))
372 
373  tps = user_time() - tps; tps_cumul=tps_cumul+tps
374  !===End Solve linear system for momentum equation
375 
376  !===Assemble divergence of velocity in arrays pb_1, pb_2
377  tps = user_time()
378  CALL qs_01_div_hybrid_generic(inputs%type_fe_velocity,vv_mesh, pp_mesh, pp_1_la, mode, un_p1, pb_1, pb_2) !===JLG Dec 9 2019
379  !CALL qs_01_div_hybrid_2006(vv_mesh, pp_mesh, pp_1_LA, mode, un_p1, pb_1, pb_2)
380  !===End assembling; pb_1, and pb_2 are petsc vectors for the rhs divergence
381 
382  IF (inputs%my_periodic%nb_periodic_pairs/=0) THEN
383  CALL periodic_rhs_petsc(pp_per%n_bord, pp_per%list, pp_per%perlist, pb_1, pp_1_la)
384  CALL periodic_rhs_petsc(pp_per%n_bord, pp_per%list, pp_per%perlist, pb_2, pp_1_la)
385  END IF
386 
387  !===ATENTION BCs are no longer implemented for pressure
388  !===Boundary condition on axis for pressure
389  pp_global_d(i)%DRL = 0.d0
390  CALL dirichlet_rhs(pp_mode_global_js_d(i)%DIL-1,pp_global_d(i)%DRL,pb_1)
391  CALL dirichlet_rhs(pp_mode_global_js_d(i)%DIL-1,pp_global_d(i)%DRL,pb_2)
392  !===End boundary condition on axis for pressure
393 
394  !===Solve -LAP(PH3) = -3/(2*dt)*DIV(un_p1)
395  CALL solver(press_ksp(i),pb_1,px_1,reinit=.false.,verbose=inputs%my_par_pp%verbose)
396  CALL vecghostupdatebegin(px_1,insert_values,scatter_forward,ierr)
397  CALL vecghostupdateend(px_1,insert_values,scatter_forward,ierr)
398  CALL extract(px_1_ghost,1,1,pp_1_la,phi(:,1))
399 
400  CALL solver(press_ksp(i),pb_2,px_1,reinit=.false.,verbose=inputs%my_par_pp%verbose)
401  CALL vecghostupdatebegin(px_1,insert_values,scatter_forward,ierr)
402  CALL vecghostupdateend(px_1,insert_values,scatter_forward,ierr)
403  CALL extract(px_1_ghost,1,1,pp_1_la,phi(:,2))
404 
405  phi = -phi*(1.5d0/dt)
406  tps = user_time() - tps; tps_cumul=tps_cumul+tps
407  !===End Solve -LAP(PH3) = -3/(2*dt)*DIV(un_p1)
408 
409  !===Solve mass matrix for pressure correction
410  tps = user_time()
411  IF (mode==0) THEN
412  CALL solver(mass_ksp0,pb_1,px_1,reinit=.false.,verbose=inputs%my_par_mass%verbose)
413  ELSE
414  CALL solver(mass_ksp,pb_1,px_1,reinit=.false.,verbose=inputs%my_par_mass%verbose)
415  END IF
416  CALL vecghostupdatebegin(px_1,insert_values,scatter_forward,ierr)
417  CALL vecghostupdateend(px_1,insert_values,scatter_forward,ierr)
418  CALL extract(px_1_ghost,1,1,pp_1_la,div(:,1,i))
419  IF (mode==0) THEN
420  CALL solver(mass_ksp0,pb_2,px_1,reinit=.false.,verbose=inputs%my_par_mass%verbose)
421  ELSE
422  CALL solver(mass_ksp,pb_2,px_1,reinit=.false.,verbose=inputs%my_par_mass%verbose)
423  END IF
424  CALL vecghostupdatebegin(px_1,insert_values,scatter_forward,ierr)
425  CALL vecghostupdateend(px_1,insert_values,scatter_forward,ierr)
426  CALL extract(px_1_ghost,1,1,pp_1_la,div(:,2,i))
427  !===End solve mass matrix for pressure correction
428 
429  !===Pressure computation
430  DO k=1, 2
431  !pn_p1(:,k) = pn_p1(:,k) + phi(:,k) - div(:,k,i)/Re
432  !pn_p1(:,k) = pn_p1(:,k) + phi(:,k) !- 0.25*div(:,k,i)/Re - inputs%div_stab_in_ns*div(:,k,i)
433  !LC 2017/01/27
434  pn_p1(:,k) = pn_p1(:,k) + phi(:,k) - 2*div(:,k,i)/re - inputs%div_stab_in_ns/re*div(:,k,i)
435  END DO
436  tps = user_time() - tps; tps_cumul=tps_cumul+tps
437  !===End Pressure computation
438 
439  !===UPDATES
440  tps = user_time()
441  !===Handling of mean pressure
442  IF (mode == 0) THEN
443  CALL moy(comm_one_d(1),pp_mesh, pn_p1(:,1),moyenne)
444  pn_p1(:,1) = pn_p1(:,1)-moyenne
445  ENDIF
446  !===End of handling of mean pressure
447 
448  !===Correction of zero mode
449  IF (mode==0) THEN
450  un_p1(:,2) = 0.d0
451  un_p1(:,4) = 0.d0
452  un_p1(:,6) = 0.d0
453  pn_p1(:,2) = 0.d0
454  END IF
455  !===Correction of zero mode
456 
457  IF (inputs%LES) THEN
458  un_m2(:,:,i) = un_m1(:,:,i)
459  END IF
460  !===UPDATES
461  un_m1(:,:,i) = un(:,:,i)
462  un(:,:,i) = un_p1
463  pn_m1(:,:,i) = pn(:,:,i)
464  pn(:,:,i) = pn_p1
465  incpn_m1(:,:,i) = incpn(:,:,i)
466  incpn(:,:,i) = phi
467  tps = user_time() - tps; tps_cumul=tps_cumul+tps
468  !===End UPDATES
469 
470  ENDDO
471 
472  IF (inputs%verbose_divergence) THEN
473  norm = norm_sf(comm_one_d, 'H1', vv_mesh, list_mode, un)
474  talk_to_me%div_L2 = norm_sf(comm_one_d, 'div', vv_mesh, list_mode, un)/norm
475  talk_to_me%weak_div_L2 = norm_sf(comm_one_d, 'L2', pp_mesh, list_mode, div)/norm
476  END IF
477 
478  !===Compute entropy viscosity
479  IF (inputs%LES) THEN
480  IF (PRESENT(opt_tempn)) THEN
481  CALL compute_entropy_viscosity(comm_one_d, vv_3_la, vv_mesh, pp_mesh, time, list_mode, vvz_per, &
482  un, un_m1, un_m2, pn_m1, rotv_v, visco_entro_sym_grad_u, opt_tempn)
483  ELSE
484  CALL compute_entropy_viscosity(comm_one_d, vv_3_la, vv_mesh, pp_mesh, time, list_mode, vvz_per, &
485  un, un_m1, un_m2, pn_m1, rotv_v, visco_entro_sym_grad_u)
486  END IF
487  END IF
488  !===End Compute entropy viscosity
489 
490  tps_tot = user_time() - tps_tot
491 
492  END SUBROUTINE bdf2_ns_stress_bc_with_u
493  !============================================
494 
495  ! cas PRECESSION 28/07/09
496  SUBROUTINE smb_cross_prod_gauss_sft_par(communicator,mesh,list_mode,V_in,V_out,precession_in)
497  !=================================
498  USE sft_parallele
499  USE chaine_caractere
500  USE input_data
501  USE def_type_mesh
502  IMPLICIT NONE
503 
504  TYPE(mesh_type), INTENT(IN) :: mesh
505  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
506  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: V_in
507  REAL(KIND=8), DIMENSION(:,:,:), INTENT(OUT) :: V_out
508  LOGICAL, INTENT(IN) :: precession_in
509  REAL(KIND=8), DIMENSION(mesh%gauss%l_G*mesh%me,6,SIZE(list_mode)) :: RotV, W, Om
510  INTEGER, DIMENSION(mesh%gauss%n_w) :: j_loc
511  REAL(KIND=8), DIMENSION(mesh%gauss%k_d,mesh%gauss%n_w) :: dw_loc
512  INTEGER :: m, l , i, mode, index, k
513  REAL(KIND=8), DIMENSION(mesh%gauss%n_w,6) :: Vs, Omega_s
514  REAL(KIND=8) :: ray
515  REAL(KIND=8) :: tps, PI
516  REAL(KIND=8), DIMENSION(3) :: temps
517  REAL(KIND=8), DIMENSION(:,:,:), ALLOCATABLE, SAVE :: Omega
518  LOGICAL, SAVE :: once=.true.
519  !===FOR FFT_PAR_CROSS_PROD_DCL
520  INTEGER :: nb_procs, bloc_size, m_max_pad, code
521  mpi_comm :: communicator
522 
523  IF (once) THEN
524  once = .false.
525  ALLOCATE(omega(mesh%np,6,SIZE(list_mode)))
526  omega = 0.d0
527  pi = acos(-1.d0)
528  DO i=1, SIZE(list_mode)
529  IF (list_mode(i) == 1) THEN
530  !precession selon un axe penche d un angle angle_s_pi*PI
531  omega(:,1,i) = inputs%taux_precession * sin(inputs%angle_s_pi*pi)
532  omega(:,4,i) = -inputs%taux_precession * sin(inputs%angle_s_pi*pi)
533  ELSE IF (list_mode(i) == 0) THEN
534  !precession selon un axe penche d un angle angle_s_pi*PI
535  omega(:,5,i) = inputs%taux_precession * cos(inputs%angle_s_pi*pi)
536  ENDIF
537  ENDDO
538  ENDIF ! fin du once
539 
540  tps = user_time()
541  DO i = 1, SIZE(list_mode)
542  mode = list_mode(i)
543  index = 0
544  DO m = 1, mesh%me
545  j_loc = mesh%jj(:,m)
546  DO k = 1, 6
547  vs(:,k) = v_in(j_loc,k,i)
548  omega_s(:,k) = omega(mesh%jj(:,m),k,i)
549  END DO
550 
551  DO l = 1, mesh%gauss%l_G
552  index = index + 1
553  dw_loc = mesh%gauss%dw(:,:,l,m)
554 
555  !===Compute radius of Gauss point
556  ray = sum(mesh%rr(1,j_loc)*mesh%gauss%ww(:,l))
557 
558  !-----------------vitesse sur les points de Gauss---------------------------
559  w(index,1,i) = sum(vs(:,1)*mesh%gauss%ww(:,l))
560  w(index,3,i) = sum(vs(:,3)*mesh%gauss%ww(:,l))
561  w(index,5,i) = sum(vs(:,5)*mesh%gauss%ww(:,l))
562 
563  w(index,2,i) = sum(vs(:,2)*mesh%gauss%ww(:,l))
564  w(index,4,i) = sum(vs(:,4)*mesh%gauss%ww(:,l))
565  w(index,6,i) = sum(vs(:,6)*mesh%gauss%ww(:,l))
566  !-----------------vecteur rotation sur les points de Gauss---------------------------
567  om(index,1,i) = sum(omega_s(:,1)*mesh%gauss%ww(:,l))
568  om(index,3,i) = sum(omega_s(:,3)*mesh%gauss%ww(:,l))
569  om(index,5,i) = sum(omega_s(:,5)*mesh%gauss%ww(:,l))
570 
571  om(index,2,i) = sum(omega_s(:,2)*mesh%gauss%ww(:,l))
572  om(index,4,i) = sum(omega_s(:,4)*mesh%gauss%ww(:,l))
573  om(index,6,i) = sum(omega_s(:,6)*mesh%gauss%ww(:,l))
574  !-----------------rotational sur les points de Gauss---------------------------
575  !coeff sur les cosinus
576  rotv(index,1,i) = mode/ray*w(index,6,i) &
577  -sum(vs(:,3)*dw_loc(2,:))
578  rotv(index,4,i) = sum(vs(:,2)*dw_loc(2,:)) &
579  -sum(vs(:,6)*dw_loc(1,:))
580  rotv(index,5,i) = 1/ray*w(index,3,i) &
581  +sum(vs(:,3)*dw_loc(1,:)) &
582  -mode/ray*w(index,2,i)
583  !coeff sur les sinus
584  rotv(index,2,i) =-mode/ray*w(index,5,i) &
585  -sum(vs(:,4)*dw_loc(2,:))
586  rotv(index,3,i) = sum(vs(:,1)*dw_loc(2,:)) &
587  -sum(vs(:,5)*dw_loc(1,:))
588  rotv(index,6,i) = 1/ray*w(index,4,i) &
589  +sum(vs(:,4)*dw_loc(1,:))&
590  +mode/ray*w(index,1,i)
591  ENDDO
592  ENDDO
593  END DO
594 
595  !JLG, FL, July 23 2010, There was a Bug here
596  IF (.NOT.precession_in) THEN
597  om=0.d0
598  END IF
599  !
600  ! cas PRECESSION 28/07/09
601  !take care to the -F= 2 Om x U term in LHS
602  rotv = rotv + 2.d0 * om
603  temps = 0
604 
605 
606  CALL mpi_comm_size(communicator, nb_procs, code)
607  bloc_size = SIZE(rotv,1)/nb_procs+1
608  m_max_pad = 3*SIZE(list_mode)*nb_procs/2
609  CALL fft_par_cross_prod_dcl(communicator, rotv, w, v_out, nb_procs, bloc_size, m_max_pad, temps)
610  tps = user_time() - tps
611 
612  END SUBROUTINE smb_cross_prod_gauss_sft_par
613 
614  SUBROUTINE smb_curlh_cross_b_gauss_sft_par(communicator,mesh,list_mode,V_in,W_in,V_out)
615  !=================================
616  USE sft_parallele
617  USE chaine_caractere
618  USE input_data
619  USE def_type_mesh
620  IMPLICIT NONE
621  TYPE(mesh_type), INTENT(IN) :: mesh
622  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
623  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: V_in, W_in
624  REAL(KIND=8), DIMENSION(:,:,:) :: V_out
625  REAL(KIND=8), DIMENSION(mesh%gauss%l_G*mesh%me,6,SIZE(list_mode)) :: RotV, V, W
626  INTEGER, DIMENSION(mesh%gauss%n_w) :: j_loc
627  REAL(KIND=8), DIMENSION(mesh%gauss%k_d,mesh%gauss%n_w) :: dw_loc
628  INTEGER :: m, l , i, mode, index, k
629  REAL(KIND=8), DIMENSION(mesh%gauss%n_w,6) :: Vs, Ws
630  REAL(KIND=8) :: ray
631  REAL(KIND=8) :: tps
632  REAL(KIND=8), DIMENSION(3) :: temps
633  !===FOR FFT_PAR_CROSS_PROD_DCL
634  INTEGER :: nb_procs, bloc_size, m_max_pad, code
635  mpi_comm :: communicator
636 
637  tps = user_time()
638  DO i = 1, SIZE(list_mode)
639  mode = list_mode(i)
640  index = 0
641  DO m = 1, mesh%me
642  j_loc = mesh%jj(:,m)
643  DO k = 1, 6
644  vs(:,k) = v_in(j_loc,k,i)
645  ws(:,k) = w_in(j_loc,k,i)
646  END DO
647 
648  DO l = 1, mesh%gauss%l_G
649  index = index + 1
650  dw_loc = mesh%gauss%dw(:,:,l,m)
651 
652  !===Compute radius of Gauss point
653  ray = sum(mesh%rr(1,j_loc)*mesh%gauss%ww(:,l))
654 
655  !-----------------vitesse sur les points de Gauss---------------------------
656  w(index,1,i) = sum(ws(:,1)*mesh%gauss%ww(:,l))
657  w(index,3,i) = sum(ws(:,3)*mesh%gauss%ww(:,l))
658  w(index,5,i) = sum(ws(:,5)*mesh%gauss%ww(:,l))
659 
660  w(index,2,i) = sum(ws(:,2)*mesh%gauss%ww(:,l))
661  w(index,4,i) = sum(ws(:,4)*mesh%gauss%ww(:,l))
662  w(index,6,i) = sum(ws(:,6)*mesh%gauss%ww(:,l))
663  v(index,1,i) = sum(vs(:,1)*mesh%gauss%ww(:,l))
664  v(index,3,i) = sum(vs(:,3)*mesh%gauss%ww(:,l))
665  v(index,5,i) = sum(vs(:,5)*mesh%gauss%ww(:,l))
666 
667  v(index,2,i) = sum(vs(:,2)*mesh%gauss%ww(:,l))
668  v(index,4,i) = sum(vs(:,4)*mesh%gauss%ww(:,l))
669  v(index,6,i) = sum(vs(:,6)*mesh%gauss%ww(:,l))
670  !-----------------rotational sur les points de Gauss---------------------------
671  !coeff sur les cosinus
672  rotv(index,1,i) = mode/ray*v(index,6,i) &
673  -sum(vs(:,3)*dw_loc(2,:))
674  rotv(index,4,i) = sum(vs(:,2)*dw_loc(2,:)) &
675  -sum(vs(:,6)*dw_loc(1,:))
676  rotv(index,5,i) = 1/ray*v(index,3,i) &
677  +sum(vs(:,3)*dw_loc(1,:)) &
678  -mode/ray*v(index,2,i)
679  !coeff sur les sinus
680  rotv(index,2,i) =-mode/ray*v(index,5,i) &
681  -sum(vs(:,4)*dw_loc(2,:))
682  rotv(index,3,i) = sum(vs(:,1)*dw_loc(2,:)) &
683  -sum(vs(:,5)*dw_loc(1,:))
684  rotv(index,6,i) = 1/ray*v(index,4,i) &
685  +sum(vs(:,4)*dw_loc(1,:))&
686  +mode/ray*v(index,1,i)
687  ENDDO
688  ENDDO
689  END DO
690 
691  !tps = user_time() - tps
692  !WRITE(*,*) ' Tps dans la grande boucle', tps
693  !tps = user_time()
694  temps = 0
695 
696 
697  CALL mpi_comm_size(communicator, nb_procs, code)
698  bloc_size = SIZE(rotv,1)/nb_procs+1
699  m_max_pad = 3*SIZE(list_mode)*nb_procs/2
700 
701  CALL fft_par_cross_prod_dcl(communicator, rotv, w, v_out, nb_procs, bloc_size, m_max_pad, temps)
702  tps = user_time() - tps
703  !WRITE(*,*) ' Tps dans FFT_PAR_PROD_VECT', tps
704  !write(*,*) ' Temps de Comm ', temps(1)
705  !write(*,*) ' Temps de Calc ', temps(2)
706  !write(*,*) ' Temps de Chan ', temps(3)
707  !DEALLOCATE(Om, W, RotV)
708 
709  END SUBROUTINE smb_curlh_cross_b_gauss_sft_par
710 
711  SUBROUTINE smb_kelvin_force_gauss_fft_par(communicator,mesh,list_mode,scal_in,vect_in,vect_out)
713  USE sft_parallele
714  USE def_type_mesh
715  USE boundary
716  IMPLICIT NONE
717  TYPE(mesh_type), INTENT(IN) :: mesh
718  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
719  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: scal_in, vect_in
720  REAL(KIND=8), DIMENSION(:,:,:) :: vect_out
721  REAL(KIND=8), DIMENSION(mesh%np,2,SIZE(list_mode)) :: chi_coeff, vect_in_square
722  REAL(KIND=8), DIMENSION(mesh%gauss%l_G*mesh%me,2,SIZE(list_mode)) :: chi_coeff_gauss
723  REAL(KIND=8), DIMENSION(mesh%gauss%l_G*mesh%me,6,SIZE(list_mode)) :: grad_vect_in_square
724  INTEGER :: i, mode, index, m, k, l
725  INTEGER, DIMENSION(:,:), POINTER :: jj
726  REAL(KIND=8), DIMENSION(mesh%gauss%k_d,mesh%gauss%n_w) :: dw_loc
727  REAL(KIND=8) :: rad
728  !===FOR FFT
729  INTEGER :: nb_procs, bloc_size, m_max_pad, code
730  mpi_comm :: communicator
731 
732  ! We compute the Kelvin force: Kelvin force = chi_coeff(T) * grad(H**2/2)
733 
734  !===nb_procs and m_max_pad calculus for FFT
735  CALL mpi_comm_size(communicator, nb_procs, code)
736  m_max_pad = 3*SIZE(list_mode)*nb_procs/2
737 
738  !===chi_coeff(T) on nodes computation
739  chi_coeff = scal_in
740  bloc_size = SIZE(chi_coeff)/nb_procs+1
741  CALL fft_par_scal_funct(communicator, chi_coeff, chi_coeff_law, nb_procs, bloc_size, m_max_pad)
742 
743  !===chi_coeff(T) on Gauss nodes computation
744  CALL gauss(mesh)
745  jj => mesh%jj
746  DO i = 1, SIZE(list_mode)
747  index = 0 ! global index of Gauss node
748  DO m = 1, mesh%dom_me
749  DO l=1, l_g
750  index = index + 1
751  DO k = 1, 2
752  chi_coeff_gauss(index,k,i) = sum(chi_coeff(jj(:,m),k,i)*ww(:,l))
753  END DO
754  END DO
755  END DO
756  END DO
757 
758  !===H**2 on nodes computation
759  bloc_size = SIZE(vect_in,1)/nb_procs+1
760  CALL fft_par_dot_prod_dcl(communicator, vect_in, vect_in, vect_in_square, nb_procs, bloc_size, m_max_pad)
761 
762  !===grad(H**2) on Gauss nodes computation
763  DO i = 1, SIZE(list_mode)
764  mode = list_mode(i)
765  index = 0
766  DO m = 1, mesh%dom_me
767  DO l=1, l_g
768  index = index + 1
769  dw_loc = dw(:,:,l,m)
770  rad = sum(mesh%rr(1,jj(:,m))*ww(:,l)) ! radius of Gauss node
771  grad_vect_in_square(index,1,i) = sum(vect_in_square(jj(:,m),1,i)*dw_loc(1,:))
772  grad_vect_in_square(index,2,i) = sum(vect_in_square(jj(:,m),2,i)*dw_loc(1,:))
773  grad_vect_in_square(index,3,i) = mode/rad * sum(vect_in_square(jj(:,m),2,i)*ww(:,l))
774  grad_vect_in_square(index,4,i) = - mode/rad * sum(vect_in_square(jj(:,m),1,i)*ww(:,l))
775  grad_vect_in_square(index,5,i) = sum(vect_in_square(jj(:,m),1,i)*dw_loc(2,:))
776  grad_vect_in_square(index,6,i) = sum(vect_in_square(jj(:,m),2,i)*dw_loc(2,:))
777  END DO
778  END DO
779  END DO
780 
781  !===Kelvin force = chi_coeff(T) * grad(H**2/2) on Gauss nodes computation
782  bloc_size = SIZE(chi_coeff_gauss,1)/nb_procs+1
783  CALL fft_scalar_vect_dcl(communicator, 0.5*grad_vect_in_square, chi_coeff_gauss, vect_out, 1, nb_procs, bloc_size, m_max_pad)
784 
785  END SUBROUTINE smb_kelvin_force_gauss_fft_par
786 
787  SUBROUTINE smb_helmholtz_force_gauss_fft_par(communicator,mesh,list_mode,scal_in,vect_in,vect_out)
789  USE sft_parallele
790  USE def_type_mesh
791  USE boundary
792  IMPLICIT NONE
793  TYPE(mesh_type), INTENT(IN) :: mesh
794  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
795  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: scal_in, vect_in
796  REAL(KIND=8), DIMENSION(:,:,:) :: vect_out
797  REAL(KIND=8), DIMENSION(mesh%np,2,SIZE(list_mode)) :: vect_in_square, chi_coeff
798  REAL(KIND=8), DIMENSION(mesh%gauss%l_G*mesh%me,2,SIZE(list_mode)) :: vect_in_square_gauss
799  REAL(KIND=8), DIMENSION(mesh%gauss%l_G*mesh%me,6,SIZE(list_mode)) :: grad_chi_coeff
800  INTEGER :: i, mode, index, m, k, l
801  INTEGER, DIMENSION(:,:), POINTER :: jj
802  REAL(KIND=8), DIMENSION(mesh%gauss%k_d,mesh%gauss%n_w) :: dw_loc
803  REAL(KIND=8) :: rad
804  !===FOR FFT
805  INTEGER :: nb_procs, bloc_size, m_max_pad, code
806  mpi_comm :: communicator
807 
808  ! We compute the Helmholtz force: Helmholtz force = - H**2/2 * grad(chi_coeff(T))
809 
810  !===nb_procs and m_max_pad calculus for FFT
811  CALL mpi_comm_size(communicator, nb_procs, code)
812  m_max_pad = 3*SIZE(list_mode)*nb_procs/2
813 
814  !===H**2 on nodes computation
815  bloc_size = SIZE(vect_in,1)/nb_procs+1
816  CALL fft_par_dot_prod_dcl(communicator, vect_in, vect_in, vect_in_square, nb_procs, bloc_size, m_max_pad)
817 
818  !===H**2 on Gauss nodes computation
819  CALL gauss(mesh)
820  jj => mesh%jj
821  DO i = 1, SIZE(list_mode)
822  index = 0 ! global index of Gauss node
823  DO m = 1, mesh%dom_me
824  DO l=1, l_g
825  index = index + 1
826  DO k = 1, 2
827  vect_in_square_gauss(index,k,i) = sum(vect_in_square(jj(:,m),k,i)*ww(:,l))
828  END DO
829  END DO
830  END DO
831  END DO
832 
833  !===chi_coeff(T) on nodes computation
834  chi_coeff = scal_in
835  bloc_size = SIZE(chi_coeff)/nb_procs+1
836  CALL fft_par_scal_funct(communicator, chi_coeff, chi_coeff_law, nb_procs, bloc_size, m_max_pad)
837 
838  !===grad(chi_coeff(T)) on Gauss nodes computation
839  DO i = 1, SIZE(list_mode)
840  mode = list_mode(i)
841  index = 0
842  DO m = 1, mesh%dom_me
843  DO l=1, l_g
844  index = index + 1
845  dw_loc = dw(:,:,l,m)
846  rad = sum(mesh%rr(1,jj(:,m))*ww(:,l)) ! radius of Gauss node
847  grad_chi_coeff(index,1,i) = sum(chi_coeff(jj(:,m),1,i)*dw_loc(1,:))
848  grad_chi_coeff(index,2,i) = sum(chi_coeff(jj(:,m),2,i)*dw_loc(1,:))
849  grad_chi_coeff(index,3,i) = mode/rad * sum(chi_coeff(jj(:,m),2,i)*ww(:,l))
850  grad_chi_coeff(index,4,i) = - mode/rad * sum(chi_coeff(jj(:,m),1,i)*ww(:,l))
851  grad_chi_coeff(index,5,i) = sum(chi_coeff(jj(:,m),1,i)*dw_loc(2,:))
852  grad_chi_coeff(index,6,i) = sum(chi_coeff(jj(:,m),2,i)*dw_loc(2,:))
853  END DO
854  END DO
855  END DO
856 
857  !===Helmholtz force = - H**2/2 * grad(chi_coeff(T)) on Gauss nodes computation
858  bloc_size = SIZE(grad_chi_coeff,1)/nb_procs+1
859  CALL fft_scalar_vect_dcl(communicator, grad_chi_coeff, -0.5*vect_in_square_gauss, vect_out, 1, nb_procs, bloc_size, m_max_pad)
860 
861  END SUBROUTINE smb_helmholtz_force_gauss_fft_par
862 
863  SUBROUTINE smb_nu_tilde_fft_par(communicator,list_mode,scal_inout) ! MODIFICATION: computation of nu tilde function of temperature
865  USE sft_parallele
866  USE def_type_mesh
867  USE boundary
868  IMPLICIT NONE
869  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
870  REAL(KIND=8), DIMENSION(:,:,:), INTENT(INOUT) :: scal_inout
871  !===FOR FFT
872  INTEGER :: nb_procs, bloc_size, m_max_pad, code
873  mpi_comm :: communicator
874 
875  !===nb_procs and m_max_pad calculus for FFT
876  CALL mpi_comm_size(communicator, nb_procs, code)
877  m_max_pad = 3*SIZE(list_mode)*nb_procs/2
878 
879  bloc_size = SIZE(scal_inout)/nb_procs+1
880  CALL fft_par_scal_funct(communicator, scal_inout, nu_tilde_law, nb_procs, bloc_size, m_max_pad)
881 
882  END SUBROUTINE smb_nu_tilde_fft_par
883 
884  SUBROUTINE moy(communicator,mesh,p,RESLT)
885  !===========================
886  !moyenne
887  USE def_type_mesh
888  IMPLICIT NONE
889  TYPE(mesh_type) :: mesh
890  REAL(KIND=8), DIMENSION(:) , INTENT(IN) :: p
891  REAL(KIND=8) , INTENT(OUT) :: RESLT
892  REAL(KIND=8) :: vol_loc, vol_out, r_loc, r_out
893  INTEGER :: m, l , i , ni, code
894  INTEGER, DIMENSION(mesh%gauss%n_w) :: j_loc
895  REAL(KIND=8) :: ray
896  mpi_comm :: communicator
897  r_loc = 0.d0
898  vol_loc = 0.d0
899 
900  DO m = 1, mesh%dom_me
901  j_loc = mesh%jj(:,m)
902  DO l = 1, mesh%gauss%l_G
903  ray = 0
904  DO ni = 1, mesh%gauss%n_w; i = j_loc(ni)
905  ray = ray + mesh%rr(1,i)*mesh%gauss%ww(ni,l)
906  END DO
907 
908  r_loc = r_loc + sum(p(j_loc(:))*mesh%gauss%ww(:,l))*ray*mesh%gauss%rj(l,m)
909  vol_loc = vol_loc + ray*mesh%gauss%rj(l,m)
910 
911  ENDDO
912  ENDDO
913 
914  CALL mpi_allreduce(r_loc,r_out,1,mpi_double_precision, mpi_sum, communicator, code)
915  CALL mpi_allreduce(vol_loc,vol_out,1,mpi_double_precision, mpi_sum, communicator, code)
916  reslt = r_out / vol_out
917 
918  END SUBROUTINE moy
919 
920 END MODULE subroutine_ns_with_u
subroutine solver(my_ksp, b, x, reinit, verbose)
Definition: solver.f90:99
subroutine smb_cross_prod_gauss_sft_par(communicator, mesh, list_mode, V_in, V_out, precession_in)
subroutine smb_helmholtz_force_gauss_fft_par(communicator, mesh, list_mode, scal_in, vect_in, vect_out)
subroutine, public extract(xghost, ks, ke, LA, phi)
Definition: st_csr.f90:34
integer, public l_g
subroutine, public create_my_ghost(mesh, LA, ifrom)
Definition: st_csr.f90:15
subroutine smb_kelvin_force_gauss_fft_par(communicator, mesh, list_mode, scal_in, vect_in, vect_out)
subroutine, public fft_par_scal_funct(communicator, c1_inout, funct, nb_procs, bloc_size, m_max_pad, temps)
subroutine create_local_petsc_matrix(communicator, LA, matrix, clean)
Definition: solver.f90:147
type(my_data), public inputs
real(kind=8) function user_time()
Definition: my_util.f90:8
subroutine, public fft_par_cross_prod_dcl(communicator, V1_in, V2_in, V_out, nb_procs, bloc_size, m_max_pad, temps)
subroutine, public smb_explicit_diffu_sym(communicator, mesh, list_mode, nb_procs, visc_dyn, vel, V_out)
subroutine qs_diff_mass_scal_m(mesh, LA, visco, mass, stab, mode, matrix)
Definition: fem_M_axi.f90:130
subroutine qs_diff_mass_vect_3x3_divpenal(type_op, LA, mesh, visco, mass, stab, stab_bdy_ns, i_mode, mode, matrix)
Definition: fem_M_axi.f90:716
subroutine, public rhs_ns_gauss_3x3(vv_mesh, pp_mesh, communicator, list_mode, time, V1m, pn, pn_inc, rotv_v, rhs_gauss, opt_tempn)
subroutine qs_01_div_hybrid_generic(type_fe_velocity, vv_mesh, pp_mesh, pp_LA, mode, gg, pb_1, pb_2)
subroutine init_solver(my_par, my_ksp, matrix, communicator, solver, precond, opt_re_init)
Definition: solver.f90:12
subroutine dirichlet_rhs(js_D, bs_D, b)
subroutine vector_glob_js_d(vv_mesh, list_mode, vv_3_LA, vv_list_dirichlet_sides, vv_js_D, vv_mode_global_js_D)
subroutine, public periodic_matrix_petsc(n_bord, list, perlist, matrix, LA)
subroutine, public bdf2_ns_stress_bc_with_u(comm_one_d, time, vv_3_LA, pp_1_LA, vvz_per, pp_per, dt, Re, list_mode, pp_mesh, vv_mesh, incpn_m1, incpn, pn_m1, pn, un_m1, un, chmp_mag, Bn_p2, opt_tempn)
Definition: tn_axi.f90:5
subroutine dirichlet_m_parallel(matrix, glob_js_D)
type(my_verbose), public talk_to_me
Definition: verbose.f90:27
real(kind=8) function norm_sf(communicator, norm_type, mesh, list_mode, v)
Definition: tn_axi.f90:40
subroutine, public fft_scalar_vect_dcl(communicator, V1_in, V2_in, V_out, pb, nb_procs, bloc_size, m_max_pad, temps)
subroutine rhs_3x3(mesh, vv_3_LA, mode, rhs_in, vb_145, vb_236, opt_tensor, opt_tensor_scaln_bdy)
subroutine, public compute_entropy_viscosity(comm_one_d, vv_3_LA, vv_mesh, pp_mesh, time, list_mode, vvz_per, un, un_m1, un_m2, pn_m1, rotv_v_m1, visco_entro_grad_u, opt_tempn)
subroutine gauss(mesh)
subroutine moy(communicator, mesh, p, RESLT)
subroutine, public fft_par_dot_prod_dcl(communicator, V1_in, V2_in, c_out, nb_procs, bloc_size, m_max_pad, temps)
subroutine smb_nu_tilde_fft_par(communicator, list_mode, scal_inout)
real(kind=8), dimension(:,:,:,:), pointer dw
real(kind=8), dimension(:,:), pointer ww
subroutine, public periodic_rhs_petsc(n_bord, list, perlist, v_rhs, LA)
subroutine smb_curlh_cross_b_gauss_sft_par(communicator, mesh, list_mode, V_in, W_in, V_out)
subroutine scalar_without_glob_js_d(pp_mesh, list_mode, pp_1_LA, pp_mode_global_js_D)