SFEMaNS  version 5.3
Reference documentation for SFEMaNS
tn_axi.f90
Go to the documentation of this file.
1 !
2 !Authors Jean-Luc Guermond, Raphael Laguerre, Copyrights 2005
3 !Revised: Jean-Luc Guermond Jan 2011
4 !
5 MODULE tn_axi
6 
7 CONTAINS
8 
9  FUNCTION dot_product_sf(communicator, mesh, list_mode, v, w) RESULT(norm)
12  USE fem_tn_ns_mhd
13 #include "petsc/finclude/petsc.h"
14  USE petsc
15  IMPLICIT NONE
16  TYPE(mesh_type), INTENT(IN) :: mesh !type de maillage
17  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
18  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: v, w
19  REAL(KIND=8) :: norm_loc, norm_tot, norm
20  INTEGER :: code
21  REAL(KIND=8) :: pi
22  mpi_comm, DIMENSION(2) :: communicator
23 
24  norm = 0.d0
25  norm_tot = 0.d0
26  IF (mesh%me==0) THEN
27  norm_loc = 0.d0
28  ELSE
29  norm_loc = dot_product_champ(mesh, list_mode, v, w)
30  END IF
31 
32  CALL mpi_allreduce(norm_loc,norm_tot,1,mpi_double_precision, mpi_sum, communicator(2), code)
33  CALL mpi_allreduce(norm_tot,norm,1,mpi_double_precision, mpi_sum, communicator(1), code)
34  pi = acos(-1.d0)
35  norm = norm*2*pi
36 
37  END FUNCTION dot_product_sf
38 
39  FUNCTION norm_sf(communicator, norm_type, mesh, list_mode, v) RESULT(norm)
42  USE fem_tn_ns_mhd
43 #include "petsc/finclude/petsc.h"
44  USE petsc
45  IMPLICIT NONE
46  TYPE(mesh_type), INTENT(IN) :: mesh !type de maillage
47  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
48  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: v
49  CHARACTER(*), INTENT(IN) :: norm_type
50  REAL(KIND=8) :: norm_loc, norm_tot, norm
51  INTEGER :: deb, fin, code
52  REAL(KIND=8) :: pi
53  mpi_comm, DIMENSION(2) :: communicator
54 
55  norm = 0.d0
56  norm_tot = 0.d0
57  IF (mesh%me==0) THEN
58  norm_loc = 0.d0
59  ELSE
60 
61  deb = start_of_string(norm_type)
62  fin = last_of_string(norm_type)
63  IF (norm_type(deb:fin)=='L2') THEN
64  norm_loc = norme_l2_champ(mesh, list_mode, v)
65  ELSE IF (norm_type(deb:fin)=='H1') THEN
66  norm_loc = sqrt(norme_l2_champ(mesh, list_mode, v)**2 &
67  + norme_h1_champ(mesh, list_mode, v)**2)
68  ELSE IF (norm_type(deb:fin)=='sH1') THEN
69  norm_loc = norme_h1_champ(mesh, list_mode, v)
70  ELSE IF (norm_type(deb:fin)=='div') THEN
71  norm_loc = norme_div(mesh, list_mode, v)
72  ELSE IF (norm_type(deb:fin)=='curl') THEN
73  norm_loc = norme_curl(mesh, list_mode, v)
74  ELSE
75  WRITE(*,*) ' BUG in norm, norm_type not programmed yet' , norm_type(deb:fin)
76  stop
77  END IF
78  END IF
79  CALL mpi_allreduce(norm_loc**2,norm_tot,1,mpi_double_precision, mpi_sum, communicator(2), code)
80  CALL mpi_allreduce(norm_tot,norm,1,mpi_double_precision, mpi_sum, communicator(1), code)
81  pi = acos(-1.d0)
82  norm = sqrt(norm*2*pi)
83 
84  END FUNCTION norm_sf
85 
86 
87  FUNCTION norm_s(communicator, norm_type, mesh, list_mode, v) RESULT(norm)
90  USE fem_tn_ns_mhd
91 #include "petsc/finclude/petsc.h"
92  USE petsc
93  IMPLICIT NONE
94  TYPE(mesh_type), INTENT(IN) :: mesh !type de maillage
95  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
96  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: v
97  CHARACTER(*), INTENT(IN) :: norm_type
98  REAL(KIND=8) :: norm_loc, norm_tot, norm
99  INTEGER :: deb, fin, code
100  REAL(KIND=8) :: pi
101  mpi_comm, DIMENSION(2) :: communicator
102 
103  norm = 0.d0
104  norm_tot = 0.d0
105  IF (mesh%me==0) THEN
106  norm_loc = 0.d0
107  ELSE
108 
109  deb = start_of_string(norm_type)
110  fin = last_of_string(norm_type)
111  IF (norm_type(deb:fin)=='L2') THEN
112  norm_loc = norme_l2_champ(mesh, list_mode, v)
113  ELSE IF (norm_type(deb:fin)=='H1') THEN
114  norm_loc = sqrt(norme_l2_champ(mesh, list_mode, v)**2 &
115  + norme_h1_champ(mesh, list_mode, v)**2)
116  ELSE IF (norm_type(deb:fin)=='sH1') THEN
117  norm_loc = norme_h1_champ(mesh, list_mode, v)
118  ELSE IF (norm_type(deb:fin)=='div') THEN
119  norm_loc = norme_div(mesh, list_mode, v)
120  ELSE IF (norm_type(deb:fin)=='curl') THEN
121  norm_loc = norme_curl(mesh, list_mode, v)
122  ELSE
123  WRITE(*,*) ' BUG in norm, norm_type not programmed yet' , norm_type(deb:fin)
124  stop
125  END IF
126  END IF
127  CALL mpi_allreduce(norm_loc**2,norm,1,mpi_double_precision, mpi_sum, communicator(1), code)
128  pi = acos(-1.d0)
129  norm = sqrt(norm*2*pi)
130 
131  END FUNCTION norm_s
132 
133  !DCQ, compute S_L1_norm using only the zero mode
134  FUNCTION norm_s_l1_zero_mode(communicator,mesh, list_mode, v) RESULT(norm)
136  USE chaine_caractere
137  USE fem_tn_ns_mhd
138 #include "petsc/finclude/petsc.h"
139  USE petsc
140  IMPLICIT NONE
141  TYPE(mesh_type), INTENT(IN) :: mesh !type de maillage
142  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
143  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: v
144  REAL(KIND=8) :: norm_loc, norm_tot, norm
145  INTEGER :: code
146  INTEGER, DIMENSION(1) :: zero_mode
147  REAL(KIND=8) :: pi
148  mpi_comm, DIMENSION(2) :: communicator
149 
150  norm = 0.d0
151  norm_tot = 0.d0
152  IF (mesh%me==0) THEN
153  norm_loc = 0.d0
154  ELSE
155  IF (minval(list_mode)==0) THEN !Just mode zero
156  zero_mode = minloc(list_mode)
157  norm_loc = norme_l1_one_mode(mesh, zero_mode(1), v)
158  ELSE
159  norm_loc=0;
160  END IF
161  END IF
162  CALL mpi_allreduce(norm_loc,norm,1,mpi_double_precision, mpi_sum, communicator(1), code)
163  pi = acos(-1.d0)
164  norm =(norm*2*pi)
165  END FUNCTION norm_s_l1_zero_mode
166 
167  SUBROUTINE integration_mode(communicator,norm_loc,norm_tot)
168 #include "petsc/finclude/petsc.h"
169  USE petsc
170  IMPLICIT NONE
171  REAL(KIND=8), INTENT(IN) :: norm_loc
172  REAL(KIND=8), INTENT(OUT) :: norm_tot
173  INTEGER :: code
174  REAL(KIND=8) :: pi
175  mpi_comm :: communicator
176 
177  pi = acos(-1.d0)
178  CALL mpi_allreduce(norm_loc,norm_tot,1,mpi_double_precision, mpi_sum, communicator, code)
179  !CN-AR Tue Jan 13 2009
180  norm_tot = norm_tot*(2*pi)
181  END SUBROUTINE integration_mode
182 
183 
184  FUNCTION norme_l2_champ_par(communicator, mesh, list_mode, v) RESULT(norm)
186  USE fem_tn_ns_mhd
187 #include "petsc/finclude/petsc.h"
188  USE petsc
189  IMPLICIT NONE
190  TYPE(mesh_type), INTENT(IN) :: mesh !type de maillage
191  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
192  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: v
193  REAL(KIND=8) :: norm_loc, norm
194  mpi_comm :: communicator
195 
196  IF (mesh%me==0) THEN
197  norm_loc = 0.d0
198  ELSE
199  norm_loc = norme_l2_champ(mesh, list_mode, v)
200  ENDIF
201  CALL integration_mode(communicator,norm_loc**2, norm)
202  norm = sqrt(norm)
203  END FUNCTION norme_l2_champ_par
204 
205  FUNCTION norme_h1_champ_par(communicator, mesh, list_mode, v) RESULT(norm)
207  USE fem_tn_ns_mhd
208 #include "petsc/finclude/petsc.h"
209  USE petsc
210  IMPLICIT NONE
211  TYPE(mesh_type), INTENT(IN) :: mesh !type de maillage
212  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
213  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: v
214  REAL(KIND=8) :: norm_loc, norm
215  mpi_comm :: communicator
216 
217  norm_loc = norme_h1_champ(mesh, list_mode, v)
218  CALL integration_mode(communicator,norm_loc**2, norm)
219  norm = sqrt(norm)
220  END FUNCTION norme_h1_champ_par
221 
222  FUNCTION norme_div_par(communicator, H_mesh, list_mode, v) RESULT(norm)
224  USE fem_tn_ns_mhd
225 #include "petsc/finclude/petsc.h"
226  USE petsc
227  IMPLICIT NONE
228  TYPE(mesh_type), INTENT(IN) :: H_mesh !type de maillage
229  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
230  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: v
231  REAL(KIND=8) :: norm_loc, norm
232  mpi_comm :: communicator
233 
234  norm_loc = norme_div(h_mesh, list_mode, v)
235  CALL integration_mode(communicator,norm_loc**2, norm)
236  norm = sqrt(norm)
237  END FUNCTION norme_div_par
238 
239  FUNCTION norme_curl_par(communicator, H_mesh, list_mode, v) RESULT(norm)
241  USE fem_tn_ns_mhd
242 #include "petsc/finclude/petsc.h"
243  USE petsc
244  IMPLICIT NONE
245  TYPE(mesh_type), INTENT(IN) :: H_mesh !type de maillage
246  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
247  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: v
248  REAL(KIND=8) :: norm_loc, norm
249  mpi_comm :: communicator
250 
251  norm_loc = norme_curl(h_mesh, list_mode, v)
252  CALL integration_mode(communicator,norm_loc**2, norm)
253  norm = sqrt(norm)
254  END FUNCTION norme_curl_par
255 
256  SUBROUTINE angular_momentum(mesh, list_mode, field, moments_out)
258 #include "petsc/finclude/petsc.h"
259  USE petsc
260  IMPLICIT NONE
261  TYPE(mesh_type), INTENT(IN) :: mesh
262  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
263  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: field
264  REAL(KIND=8), DIMENSION(3), INTENT(OUT) :: moments_out
265 
266  REAL(KIND=8), DIMENSION(3) :: moments_loc
267  REAL(KIND=8) :: m_x, m_y, ray, zed, urc, urs, utc, uts, uzc, uzs
268  INTEGER :: m, l, code, i
269 
270  moments_loc=0.d0
271  moments_out=0.d0
272  DO i = 1, SIZE(list_mode)
273  IF (list_mode(i)==0) THEN
274  DO m = 1, mesh%me
275  DO l = 1, mesh%gauss%l_G
276  ray = sum(mesh%rr(1,mesh%jj(:,m))*mesh%gauss%ww(:,l))
277  utc = sum(field(mesh%jj(:,m),3,i)*mesh%gauss%ww(:,l))
278 
279  moments_loc(3) = moments_loc(3) + ray**2*utc*mesh%gauss%rj(l,m)
280  END DO
281  END DO
282  ELSE IF (list_mode(i)==1) THEN
283  DO m = 1, mesh%me
284  DO l = 1, mesh%gauss%l_G
285  ray = sum(mesh%rr(1,mesh%jj(:,m))*mesh%gauss%ww(:,l))
286  zed = sum(mesh%rr(2,mesh%jj(:,m))*mesh%gauss%ww(:,l))
287 
288  urc = sum(field(mesh%jj(:,m),1,i)*mesh%gauss%ww(:,l))
289  urs = sum(field(mesh%jj(:,m),2,i)*mesh%gauss%ww(:,l))
290  utc = sum(field(mesh%jj(:,m),3,i)*mesh%gauss%ww(:,l))
291  uts = sum(field(mesh%jj(:,m),4,i)*mesh%gauss%ww(:,l))
292  uzc = sum(field(mesh%jj(:,m),5,i)*mesh%gauss%ww(:,l))
293  uzs = sum(field(mesh%jj(:,m),6,i)*mesh%gauss%ww(:,l))
294 
295  m_x = ray*(-zed*(urs+utc)+ray*uzs)
296  m_y = ray*(zed*(urc-uts)-ray*uzc)
297 
298  moments_loc(1) = moments_loc(1) + m_x*mesh%gauss%rj(l,m)
299  moments_loc(2) = moments_loc(2) + m_y*mesh%gauss%rj(l,m)
300  END DO
301  END DO
302  END IF
303  END DO
304 
305  CALL mpi_allreduce(moments_loc, moments_out, 3, mpi_double_precision, mpi_sum, petsc_comm_world, code)
306  moments_out(1) = acos(-1.d0)*moments_out(1)
307  moments_out(2) = acos(-1.d0)*moments_out(2)
308  moments_out(3) = 2*acos(-1.d0)*moments_out(3)
309 
310  END SUBROUTINE angular_momentum
311 
312  SUBROUTINE moments(communicator, H_mesh, list_mode, v, dipole_out, quadripole_out)
314 #include "petsc/finclude/petsc.h"
315  USE petsc
316  IMPLICIT NONE
317  TYPE(mesh_type), INTENT(IN) :: H_mesh
318  INTEGER, DIMENSION(:), INTENT(IN) :: list_mode
319  REAL(KIND=8), DIMENSION(:,:,:), INTENT(IN) :: v
320  REAL(KIND=8), DIMENSION(3), INTENT(OUT):: dipole_out
321  REAL(KIND=8), DIMENSION(3,3), INTENT(OUT):: quadripole_out
322  REAL(KIND=8), DIMENSION(3) :: dipole
323  REAL(KIND=8), DIMENSION(3,3) :: quadripole
324  REAL(KIND=8) :: jr, ray, zed, pi
325  INTEGER :: m_max_c, mode, k, m, l, ni, i
326  INTEGER :: code
327  REAL(KIND=8), DIMENSION(6) :: c
328 
329  mpi_comm :: communicator
330 
331  pi = acos(-1.d0)
332  m_max_c = SIZE(list_mode)
333  dipole = 0
334  quadripole = 0
335 
336  IF (SIZE(v,1)/=h_mesh%np .OR. SIZE(v,2)/=6 .OR. SIZE(v,3)/=m_max_c ) THEN
337  WRITE(*,*) ' BUG in MOMENTS', SIZE(v,1), h_mesh%np
338  stop
339  END IF
340  DO m = 1, h_mesh%me
341  DO l = 1, h_mesh%gauss%l_G
342 
343  !--------On calcule le rayon et z du point gauss
344  ray = 0
345  zed = 0
346  DO ni = 1, h_mesh%gauss%n_w; i = h_mesh%jj(ni,m)
347  ray = ray + h_mesh%rr(1,i)*h_mesh%gauss%ww(ni,l)
348  zed = zed + h_mesh%rr(2,i)*h_mesh%gauss%ww(ni,l)
349  END DO
350  jr = ray * h_mesh%gauss%rj(l,m)
351 
352  DO k=1, m_max_c
353  mode = list_mode(k)
354  IF (mode /=0 .AND. mode /=1 .AND. mode /=2) cycle
355 
356  !--------Compute Curl------
357  c = 0
358  DO ni = 1,h_mesh%gauss%n_w; i = h_mesh%jj(ni,m)
359  !--------Composante r------
360  c(1) = c(1) + ( mode/ray*v(i,6,k)*h_mesh%gauss%ww(ni,l) &
361  - v(i,3,k)*h_mesh%gauss%dw(2,ni,l,m))
362  c(2) = c(2) + (-mode/ray*v(i,5,k)*h_mesh%gauss%ww(ni,l) &
363  - v(i,4,k)*h_mesh%gauss%dw(2,ni,l,m))
364  !--------Composante theta------
365  c(3) = c(3) + (v(i,1,k)*h_mesh%gauss%dw(2,ni,l,m) &
366  - v(i,5,k)*h_mesh%gauss%dw(1,ni,l,m))
367  c(4) = c(4) + (v(i,2,k)*h_mesh%gauss%dw(2,ni,l,m) &
368  - v(i,6,k)*h_mesh%gauss%dw(1,ni,l,m))
369  !--------Composante z------
370  c(5) = c(5) + (v(i,3,k)*h_mesh%gauss%dw(1,ni,l,m) &
371  + v(i,3,k)*h_mesh%gauss%ww(ni,l)/ray &
372  - mode/ray*v(i,2,k)*h_mesh%gauss%ww(ni,l))
373  c(6) = c(6) + (v(i,4,k)*h_mesh%gauss%dw(1,ni,l,m) &
374  + v(i,4,k)*h_mesh%gauss%ww(ni,l)/ray &
375  + mode/ray*v(i,1,k)*h_mesh%gauss%ww(ni,l))
376  ENDDO
377 
378  !--------Compute dipole and quadripole------
379  IF (mode == 0) THEN
380  dipole(3) = dipole(3) + 2*pi*ray*c(3)*jr
381  quadripole(1,1) = quadripole(1,1) + pi*(-zed*ray*c(3))*jr
382  quadripole(1,2) = quadripole(1,2) + pi*(-zed*ray*c(1)+ray*ray*c(5))*jr
383  quadripole(2,1) = quadripole(2,1) + pi*( zed*ray*c(1)-ray*ray*c(5))*jr
384  quadripole(2,2) = quadripole(2,2) + pi*(-zed*ray*c(3))*jr
385  quadripole(3,3) = quadripole(3,3)+2*pi*( zed*ray*c(3))*jr
386  ELSE IF (mode == 1) THEN
387  dipole(1) = dipole(1) + pi*(-zed*c(3) -zed*c(2) +ray*c(6))*jr
388  dipole(2) = dipole(2) + pi*(-zed*c(4) +zed*c(1) -ray*c(5))*jr
389  quadripole(1,3) = quadripole(1,3) + pi*(-zed*c(3)-zed*c(2)+ray*c(6))*zed*jr
390  quadripole(2,3) = quadripole(2,3) + pi*(-zed*c(4)+zed*c(1)-ray*c(5))*zed*jr
391  quadripole(3,1) = quadripole(3,1) + pi*(ray*ray*c(3))*jr
392  quadripole(3,2) = quadripole(3,2) + pi*(ray*ray*c(4))*jr
393  ELSE IF (mode == 2) THEN
394  quadripole(1,1) = quadripole(1,1) + pi*(-zed*c(3)-zed*c(2)+ray*c(6))*ray*jr/2
395  quadripole(1,2) = quadripole(1,2) + pi*(-zed*c(4)+zed*c(1)-ray*c(5))*ray*jr/2
396  quadripole(2,1) = quadripole(2,1) + pi*(-zed*c(4)+zed*c(1)-ray*c(5))*ray*jr/2
397  quadripole(2,2) = quadripole(2,2) + pi*( zed*c(3)+zed*c(2)-ray*c(6))*ray*jr/2
398  END IF
399 
400  END DO
401  END DO
402  END DO
403 
404  !--------Collect from everybody------
405  CALL mpi_allreduce(dipole, dipole_out, 3,mpi_double_precision, &
406  mpi_sum, communicator, code)
407  CALL mpi_allreduce(quadripole,quadripole_out,9,mpi_double_precision, &
408  mpi_sum, communicator, code)
409  RETURN
410  END SUBROUTINE moments
411 
412  END MODULE tn_axi
integer function, public last_of_string(string)
subroutine moments(communicator, H_mesh, list_mode, v, dipole_out, quadripole_out)
Definition: tn_axi.f90:313
real(kind=8) function dot_product_champ(mesh, list_mode, v, w)
real(kind=8) function norme_l2_champ(mesh, list_mode, v)
real(kind=8) function norme_l1_one_mode(mesh, mode_idx, v)
real(kind=8) function norme_h1_champ(mesh, list_mode, v)
real(kind=8) function norme_div(H_mesh, list_mode, v)
real(kind=8) function norme_curl(H_mesh, list_mode, v)
subroutine integration_mode(communicator, norm_loc, norm_tot)
Definition: tn_axi.f90:168
real(kind=8) function norm_s(communicator, norm_type, mesh, list_mode, v)
Definition: tn_axi.f90:88
integer function, public start_of_string(string)
subroutine angular_momentum(mesh, list_mode, field, moments_out)
Definition: tn_axi.f90:257
real(kind=8) function norme_h1_champ_par(communicator, mesh, list_mode, v)
Definition: tn_axi.f90:206
real(kind=8) function norme_div_par(communicator, H_mesh, list_mode, v)
Definition: tn_axi.f90:223
real(kind=8) function norme_l2_champ_par(communicator, mesh, list_mode, v)
Definition: tn_axi.f90:185
Definition: tn_axi.f90:5
real(kind=8) function norme_curl_par(communicator, H_mesh, list_mode, v)
Definition: tn_axi.f90:240
real(kind=8) function norm_sf(communicator, norm_type, mesh, list_mode, v)
Definition: tn_axi.f90:40
real(kind=8) function dot_product_sf(communicator, mesh, list_mode, v, w)
Definition: tn_axi.f90:10
real(kind=8) function norm_s_l1_zero_mode(communicator, mesh, list_mode, v)
Definition: tn_axi.f90:135