source: palm/trunk/SOURCE/data_output_3d.f90 @ 1359

Last change on this file since 1359 was 1359, checked in by hoffmann, 10 years ago

new Lagrangian particle structure integrated

  • Property svn:keywords set to Id
File size: 20.2 KB
Line 
1 SUBROUTINE data_output_3d( av )
2
3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2014 Leibniz Universitaet Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22! New particle structure integrated.
23!
24! Former revisions:
25! -----------------
26! $Id: data_output_3d.f90 1359 2014-04-11 17:15:14Z hoffmann $
27!
28! 1353 2014-04-08 15:21:23Z heinze
29! REAL constants provided with KIND-attribute
30!
31! 1327 2014-03-21 11:00:16Z raasch
32! parts concerning avs output removed,
33! -netcdf output queries
34!
35! 1320 2014-03-20 08:40:49Z raasch
36! ONLY-attribute added to USE-statements,
37! kind-parameters added to all INTEGER and REAL declaration statements,
38! kinds are defined in new module kinds,
39! old module precision_kind is removed,
40! revision history before 2012 removed,
41! comment fields (!:) to be used for variable explanations added to
42! all variable declaration statements
43!
44! 1318 2014-03-17 13:35:16Z raasch
45! barrier argument removed from cpu_log,
46! module interfaces removed
47!
48! 1308 2014-03-13 14:58:42Z fricke
49! Check, if the limit of the time dimension is exceeded for parallel output
50! To increase the performance for parallel output, the following is done:
51! - Update of time axis is only done by PE0
52!
53! 1244 2013-10-31 08:16:56Z raasch
54! Bugfix for index bounds in case of 3d-parallel output
55!
56! 1115 2013-03-26 18:16:16Z hoffmann
57! ql is calculated by calc_liquid_water_content
58!
59! 1106 2013-03-04 05:31:38Z raasch
60! array_kind renamed precision_kind
61!
62! 1076 2012-12-05 08:30:18Z hoffmann
63! Bugfix in output of ql
64!
65! 1053 2012-11-13 17:11:03Z hoffmann
66! +nr, qr, prr, qc and averaged quantities
67!
68! 1036 2012-10-22 13:43:42Z raasch
69! code put under GPL (PALM 3.9)
70!
71! 1031 2012-10-19 14:35:30Z raasch
72! netCDF4 without parallel file support implemented
73!
74! 1007 2012-09-19 14:30:36Z franke
75! Bugfix: missing calculation of ql_vp added
76!
77! Revision 1.1  1997/09/03 06:29:36  raasch
78! Initial revision
79!
80!
81! Description:
82! ------------
83! Output of the 3D-arrays in netCDF and/or AVS format.
84!------------------------------------------------------------------------------!
85
86    USE arrays_3d,                                                             &
87        ONLY:  e, nr, p, pt, q, qc, ql, ql_c, ql_v, qr, rho, sa, tend, u, v,   &
88               vpt, w
89       
90    USE averaging
91       
92    USE cloud_parameters,                                                      &
93        ONLY:  l_d_cp, prr, pt_d_t
94       
95    USE control_parameters,                                                    &
96        ONLY:  avs_data_file, cloud_physics, do3d, do3d_avs_n,                 &
97               do3d_no, do3d_time_count, io_blocks, io_group,                  &
98               message_string, netcdf_data_format, ntdim_3d,                   &
99               nz_do3d, plot_3d_precision, psolver, simulated_time,            &
100               simulated_time_chr, skip_do_avs, time_since_reference_point
101       
102    USE cpulog,                                                                &
103        ONLY:  log_point, cpu_log
104       
105    USE indices,                                                               &
106        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzt,  &
107               nzb
108       
109    USE kinds
110   
111    USE netcdf_control
112       
113    USE particle_attributes,                                                   &
114        ONLY:  grid_particles, number_of_particles, particles,                 &
115               particle_advection_start, prt_count
116       
117    USE pegrid
118
119    IMPLICIT NONE
120
121    CHARACTER (LEN=9) ::  simulated_time_mod  !:
122
123    INTEGER(iwp) ::  av        !:
124    INTEGER(iwp) ::  i         !:
125    INTEGER(iwp) ::  if        !:
126    INTEGER(iwp) ::  j         !:
127    INTEGER(iwp) ::  k         !:
128    INTEGER(iwp) ::  n         !:
129    INTEGER(iwp) ::  pos       !:
130    INTEGER(iwp) ::  prec      !:
131    INTEGER(iwp) ::  psi       !:
132
133    LOGICAL      ::  found     !:
134    LOGICAL      ::  resorted  !:
135
136    REAL(wp)     ::  mean_r    !:
137    REAL(wp)     ::  s_r2      !:
138    REAL(wp)     ::  s_r3      !:
139
140    REAL(sp), DIMENSION(:,:,:), ALLOCATABLE ::  local_pf  !:
141
142    REAL(wp), DIMENSION(:,:,:), POINTER ::  to_be_resorted  !:
143
144!
145!-- Return, if nothing to output
146    IF ( do3d_no(av) == 0 )  RETURN
147!
148!-- For parallel netcdf output the time axis must be limited. Return, if this
149!-- limit is exceeded. This could be the case, if the simulated time exceeds
150!-- the given end time by the length of the given output interval.
151    IF ( netcdf_data_format > 4 )  THEN
152       IF ( do3d_time_count(av) + 1 > ntdim_3d(av) )  THEN
153          WRITE ( message_string, * ) 'Output of 3d data is not given at t=',  &
154                                      simulated_time, '&because the maximum ', & 
155                                      'number of output time levels is ',      &
156                                      'exceeded.'
157          CALL message( 'data_output_3d', 'PA0387', 0, 1, 0, 6, 0 )         
158          RETURN
159       ENDIF
160    ENDIF
161
162    CALL cpu_log (log_point(14),'data_output_3d','start')
163
164!
165!-- Open output file.
166!-- Also creates coordinate and fld-file for AVS.
167!-- For classic or 64bit netCDF output or output of other (old) data formats,
168!-- for a run on more than one PE, each PE opens its own file and
169!-- writes the data of its subdomain in binary format (regardless of the format
170!-- the user has requested). After the run, these files are combined to one
171!-- file by combine_plot_fields in the format requested by the user (netcdf
172!-- and/or avs).
173!-- For netCDF4/HDF5 output, data is written in parallel into one file.
174    IF ( netcdf_data_format < 5 )  THEN
175       CALL check_open( 30 )
176       IF ( myid == 0 )  CALL check_open( 106+av*10 )
177    ELSE
178       CALL check_open( 106+av*10 )
179    ENDIF
180
181!
182!-- Allocate a temporary array with the desired output dimensions.
183    ALLOCATE( local_pf(nxlg:nxrg,nysg:nyng,nzb:nz_do3d) )
184
185!
186!-- Update the netCDF time axis
187!-- In case of parallel output, this is only done by PE0 to increase the
188!-- performance.
189#if defined( __netcdf )
190    do3d_time_count(av) = do3d_time_count(av) + 1
191    IF ( myid == 0 )  THEN
192       nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_time_3d(av),           &
193                               (/ time_since_reference_point /),            &
194                               start = (/ do3d_time_count(av) /),           &
195                               count = (/ 1 /) )
196       CALL handle_netcdf_error( 'data_output_3d', 376 )
197    ENDIF
198#endif
199
200!
201!-- Loop over all variables to be written.
202    if = 1
203
204    DO  WHILE ( do3d(av,if)(1:1) /= ' ' )
205!
206!--    Store the array chosen on the temporary array.
207       resorted = .FALSE.
208       SELECT CASE ( TRIM( do3d(av,if) ) )
209
210          CASE ( 'e' )
211             IF ( av == 0 )  THEN
212                to_be_resorted => e
213             ELSE
214                to_be_resorted => e_av
215             ENDIF
216
217          CASE ( 'lpt' )
218             IF ( av == 0 )  THEN
219                to_be_resorted => pt
220             ELSE
221                to_be_resorted => lpt_av
222             ENDIF
223
224          CASE ( 'nr' )
225             IF ( av == 0 )  THEN
226                to_be_resorted => nr
227             ELSE
228                to_be_resorted => nr_av
229             ENDIF
230
231          CASE ( 'p' )
232             IF ( av == 0 )  THEN
233                IF ( psolver /= 'sor' )  CALL exchange_horiz( p, nbgp )
234                to_be_resorted => p
235             ELSE
236                IF ( psolver /= 'sor' )  CALL exchange_horiz( p_av, nbgp )
237                to_be_resorted => p_av
238             ENDIF
239
240          CASE ( 'pc' )  ! particle concentration (requires ghostpoint exchange)
241             IF ( av == 0 )  THEN
242                IF ( simulated_time >= particle_advection_start )  THEN
243                   tend = prt_count
244                   CALL exchange_horiz( tend, nbgp )
245                ELSE
246                   tend = 0.0_wp
247                ENDIF
248                DO  i = nxlg, nxrg
249                   DO  j = nysg, nyng
250                      DO  k = nzb, nz_do3d
251                         local_pf(i,j,k) = tend(k,j,i)
252                      ENDDO
253                   ENDDO
254                ENDDO
255                resorted = .TRUE.
256             ELSE
257                CALL exchange_horiz( pc_av, nbgp )
258                to_be_resorted => pc_av
259             ENDIF
260
261          CASE ( 'pr' )  ! mean particle radius (effective radius)
262             IF ( av == 0 )  THEN
263                IF ( simulated_time >= particle_advection_start )  THEN
264                   DO  i = nxl, nxr
265                      DO  j = nys, nyn
266                         DO  k = nzb, nz_do3d
267                            number_of_particles = prt_count(k,j,i)
268                            IF (number_of_particles <= 0)  CYCLE
269                            particles => grid_particles(k,j,i)%particles(1:number_of_particles)
270                            s_r2 = 0.0_wp
271                            s_r3 = 0.0_wp
272                            DO  n = 1, number_of_particles
273                               IF ( particles(n)%particle_mask )  THEN
274                                  s_r2 = s_r2 + particles(n)%radius**2 * &
275                                         particles(n)%weight_factor
276                                  s_r3 = s_r3 + particles(n)%radius**3 * &
277                                         particles(n)%weight_factor
278                               ENDIF
279                            ENDDO
280                            IF ( s_r2 > 0.0_wp )  THEN
281                               mean_r = s_r3 / s_r2
282                            ELSE
283                               mean_r = 0.0_wp
284                            ENDIF
285                            tend(k,j,i) = mean_r
286                         ENDDO
287                      ENDDO
288                   ENDDO
289                   CALL exchange_horiz( tend, nbgp )
290                ELSE
291                   tend = 0.0_wp
292                ENDIF
293                DO  i = nxlg, nxrg
294                   DO  j = nysg, nyng
295                      DO  k = nzb, nz_do3d
296                         local_pf(i,j,k) = tend(k,j,i)
297                      ENDDO
298                   ENDDO
299                ENDDO
300                resorted = .TRUE.
301             ELSE
302                CALL exchange_horiz( pr_av, nbgp )
303                to_be_resorted => pr_av
304             ENDIF
305
306          CASE ( 'prr' )
307             IF ( av == 0 )  THEN
308                CALL exchange_horiz( prr, nbgp )
309                DO  i = nxlg, nxrg
310                   DO  j = nysg, nyng
311                      DO  k = nzb, nzt+1
312                         local_pf(i,j,k) = prr(k,j,i)
313                      ENDDO
314                   ENDDO
315                ENDDO
316             ELSE
317                CALL exchange_horiz( prr_av, nbgp )
318                DO  i = nxlg, nxrg
319                   DO  j = nysg, nyng
320                      DO  k = nzb, nzt+1
321                         local_pf(i,j,k) = prr_av(k,j,i)
322                      ENDDO
323                   ENDDO
324                ENDDO
325             ENDIF
326             resorted = .TRUE.
327
328          CASE ( 'pt' )
329             IF ( av == 0 )  THEN
330                IF ( .NOT. cloud_physics ) THEN
331                   to_be_resorted => pt
332                ELSE
333                   DO  i = nxlg, nxrg
334                      DO  j = nysg, nyng
335                         DO  k = nzb, nz_do3d
336                            local_pf(i,j,k) = pt(k,j,i) + l_d_cp *             &
337                                                          pt_d_t(k) *          &
338                                                          ql(k,j,i)
339                         ENDDO
340                      ENDDO
341                   ENDDO
342                   resorted = .TRUE.
343                ENDIF
344             ELSE
345                to_be_resorted => pt_av
346             ENDIF
347
348          CASE ( 'q' )
349             IF ( av == 0 )  THEN
350                to_be_resorted => q
351             ELSE
352                to_be_resorted => q_av
353             ENDIF
354
355          CASE ( 'qc' )
356             IF ( av == 0 )  THEN
357                to_be_resorted => qc
358             ELSE
359                to_be_resorted => qc_av
360             ENDIF
361
362          CASE ( 'ql' )
363             IF ( av == 0 )  THEN
364                to_be_resorted => ql
365             ELSE
366                to_be_resorted => ql_av
367             ENDIF
368
369          CASE ( 'ql_c' )
370             IF ( av == 0 )  THEN
371                to_be_resorted => ql_c
372             ELSE
373                to_be_resorted => ql_c_av
374             ENDIF
375
376          CASE ( 'ql_v' )
377             IF ( av == 0 )  THEN
378                to_be_resorted => ql_v
379             ELSE
380                to_be_resorted => ql_v_av
381             ENDIF
382
383          CASE ( 'ql_vp' )
384             IF ( av == 0 )  THEN
385                IF ( simulated_time >= particle_advection_start )  THEN
386                   DO  i = nxl, nxr
387                      DO  j = nys, nyn
388                         DO  k = nzb, nz_do3d
389                            number_of_particles = prt_count(k,j,i)
390                            IF (number_of_particles <= 0)  CYCLE
391                            particles => grid_particles(k,j,i)%particles(1:number_of_particles)
392                            DO  n = 1, number_of_particles
393                               IF ( particles(n)%particle_mask )  THEN
394                                  tend(k,j,i) =  tend(k,j,i) +                 &
395                                                 particles(n)%weight_factor /  &
396                                                 prt_count(k,j,i)
397                               ENDIF
398                            ENDDO
399                         ENDDO
400                      ENDDO
401                   ENDDO
402                   CALL exchange_horiz( tend, nbgp )
403                ELSE
404                   tend = 0.0_wp
405                ENDIF
406                DO  i = nxlg, nxrg
407                   DO  j = nysg, nyng
408                      DO  k = nzb, nz_do3d
409                         local_pf(i,j,k) = tend(k,j,i)
410                      ENDDO
411                   ENDDO
412                ENDDO
413                resorted = .TRUE.
414             ELSE
415                CALL exchange_horiz( ql_vp_av, nbgp )
416                to_be_resorted => ql_vp_av
417             ENDIF
418
419          CASE ( 'qr' )
420             IF ( av == 0 )  THEN
421                to_be_resorted => qr
422             ELSE
423                to_be_resorted => qr_av
424             ENDIF
425
426          CASE ( 'qv' )
427             IF ( av == 0 )  THEN
428                DO  i = nxlg, nxrg
429                   DO  j = nysg, nyng
430                      DO  k = nzb, nz_do3d
431                         local_pf(i,j,k) = q(k,j,i) - ql(k,j,i)
432                      ENDDO
433                   ENDDO
434                ENDDO
435                resorted = .TRUE.
436             ELSE
437                to_be_resorted => qv_av
438             ENDIF
439
440          CASE ( 'rho' )
441             IF ( av == 0 )  THEN
442                to_be_resorted => rho
443             ELSE
444                to_be_resorted => rho_av
445             ENDIF
446
447          CASE ( 's' )
448             IF ( av == 0 )  THEN
449                to_be_resorted => q
450             ELSE
451                to_be_resorted => s_av
452             ENDIF
453
454          CASE ( 'sa' )
455             IF ( av == 0 )  THEN
456                to_be_resorted => sa
457             ELSE
458                to_be_resorted => sa_av
459             ENDIF
460
461          CASE ( 'u' )
462             IF ( av == 0 )  THEN
463                to_be_resorted => u
464             ELSE
465                to_be_resorted => u_av
466             ENDIF
467
468          CASE ( 'v' )
469             IF ( av == 0 )  THEN
470                to_be_resorted => v
471             ELSE
472                to_be_resorted => v_av
473             ENDIF
474
475          CASE ( 'vpt' )
476             IF ( av == 0 )  THEN
477                to_be_resorted => vpt
478             ELSE
479                to_be_resorted => vpt_av
480             ENDIF
481
482          CASE ( 'w' )
483             IF ( av == 0 )  THEN
484                to_be_resorted => w
485             ELSE
486                to_be_resorted => w_av
487             ENDIF
488
489          CASE DEFAULT
490!
491!--          User defined quantity
492             CALL user_data_output_3d( av, do3d(av,if), found, local_pf,       &
493                                       nz_do3d )
494             resorted = .TRUE.
495
496             IF ( .NOT. found )  THEN
497                message_string =  'no output available for: ' //               &
498                                  TRIM( do3d(av,if) )
499                CALL message( 'data_output_3d', 'PA0182', 0, 0, 0, 6, 0 )
500             ENDIF
501
502       END SELECT
503
504!
505!--    Resort the array to be output, if not done above
506       IF ( .NOT. resorted )  THEN
507          DO  i = nxlg, nxrg
508             DO  j = nysg, nyng
509                DO  k = nzb, nz_do3d
510                   local_pf(i,j,k) = to_be_resorted(k,j,i)
511                ENDDO
512             ENDDO
513          ENDDO
514       ENDIF
515
516!
517!--    Output of the 3D-array
518#if defined( __parallel )
519       IF ( netcdf_data_format < 5 )  THEN
520!
521!--       Non-parallel netCDF output. Data is output in parallel in
522!--       FORTRAN binary format here, and later collected into one file by
523!--       combine_plot_fields
524          IF ( myid == 0 )  THEN
525             WRITE ( 30 )  time_since_reference_point,                   &
526                           do3d_time_count(av), av
527          ENDIF
528          DO  i = 0, io_blocks-1
529             IF ( i == io_group )  THEN
530                WRITE ( 30 )  nxlg, nxrg, nysg, nyng, nzb, nz_do3d
531                WRITE ( 30 )  local_pf
532             ENDIF
533#if defined( __parallel )
534             CALL MPI_BARRIER( comm2d, ierr )
535#endif
536          ENDDO
537
538       ELSE
539#if defined( __netcdf )
540!
541!--       Parallel output in netCDF4/HDF5 format.
542!--       Do not output redundant ghost point data except for the
543!--       boundaries of the total domain.
544          IF ( nxr == nx  .AND.  nyn /= ny )  THEN
545             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if),  &
546                               local_pf(nxl:nxr+1,nys:nyn,nzb:nz_do3d),  &
547                start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /),  &
548                count = (/ nxr-nxl+2, nyn-nys+1, nz_do3d-nzb+1, 1 /) )
549          ELSEIF ( nxr /= nx  .AND.  nyn == ny )  THEN
550             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if),  &
551                               local_pf(nxl:nxr,nys:nyn+1,nzb:nz_do3d),  &
552                start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /),  &
553                count = (/ nxr-nxl+1, nyn-nys+2, nz_do3d-nzb+1, 1 /) )
554          ELSEIF ( nxr == nx  .AND.  nyn == ny )  THEN
555             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if),  &
556                             local_pf(nxl:nxr+1,nys:nyn+1,nzb:nz_do3d),  &
557                start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /),  &
558                count = (/ nxr-nxl+2, nyn-nys+2, nz_do3d-nzb+1, 1 /) )
559          ELSE
560             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if),  &
561                                 local_pf(nxl:nxr,nys:nyn,nzb:nz_do3d),  &
562                start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /),  &
563                count = (/ nxr-nxl+1, nyn-nys+1, nz_do3d-nzb+1, 1 /) )
564          ENDIF
565          CALL handle_netcdf_error( 'data_output_3d', 386 )
566#endif
567       ENDIF
568#else
569#if defined( __netcdf )
570       nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if),        &
571                         local_pf(nxl:nxr+1,nys:nyn+1,nzb:nz_do3d),      &
572                         start = (/ 1, 1, 1, do3d_time_count(av) /),     &
573                         count = (/ nx+2, ny+2, nz_do3d-nzb+1, 1 /) )
574       CALL handle_netcdf_error( 'data_output_3d', 446 )
575#endif
576#endif
577
578       if = if + 1
579
580    ENDDO
581
582!
583!-- Deallocate temporary array.
584    DEALLOCATE( local_pf )
585
586
587    CALL cpu_log( log_point(14), 'data_output_3d', 'stop' )
588
589!
590!-- Formats.
5913300 FORMAT ('variable ',I4,'  file=',A,'  filetype=unformatted  skip=',I12/   &
592             'label = ',A,A)
593
594 END SUBROUTINE data_output_3d
Note: See TracBrowser for help on using the repository browser.