source: palm/trunk/SOURCE/pmc_general_mod.f90 @ 2834

Last change on this file since 2834 was 2801, checked in by thiele, 7 years ago

Introduce particle transfer in nested models

  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
1 MODULE pmc_general
2
3!------------------------------------------------------------------------------!
4! This file is part of the PALM model system.
5!
6! PALM is free software: you can redistribute it and/or modify it under the
7! terms of the GNU General Public License as published by the Free Software
8! Foundation, either version 3 of the License, or (at your option) any later
9! version.
10!
11! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
12! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14!
15! You should have received a copy of the GNU General Public License along with
16! PALM. If not, see <http://www.gnu.org/licenses/>.
17!
18! Copyright 1997-2018 Leibniz Universitaet Hannover
19!------------------------------------------------------------------------------!
20!
21! Current revisions:
22! ------------------
23!
24!
25! Former revisions:
26! -----------------
27! $Id: pmc_general_mod.f90 2801 2018-02-14 16:01:55Z raasch $
28! Introduce particle transfer in nested models.
29!
30! 2718 2018-01-02 08:49:38Z maronga
31! Corrected "Former revisions" section
32!
33! 2696 2017-12-14 17:12:51Z kanani
34! Change in file header (GPL part)
35!
36! 2599 2017-11-01 13:18:45Z hellstea
37! Some cleanup and commenting improvements only.
38!
39! 2101 2017-01-05 16:42:31Z suehring
40!
41! 2000 2016-08-20 18:09:15Z knoop
42! Forced header and separation lines into 80 columns
43!
44! 1901 2016-05-04 15:39:38Z raasch
45! Code clean up. The words server/client changed to parent/child.
46!
47! 1900 2016-05-04 15:27:53Z raasch
48! re-formatted to match PALM style, file renamed again
49!
50! 1808 2016-04-05 19:44:00Z raasch
51! MPI module used by default on all machines
52!
53! 1786 2016-03-08 05:49:27Z raasch
54! change in child-parent data transfer: parent now gets data from child
55! instead of that child puts it to the parent
56!
57! 1779 2016-03-03 08:01:28Z raasch
58! PMC_MPI_REAL removed, dim_order removed from type arraydef,
59! array management changed from linked list to sequential loop
60!
61! 1766 2016-02-29 08:37:15Z raasch
62! +po_data in type arraydef
63!
64! 1764 2016-02-28 12:45:19Z raasch
65! cpp-statement added (nesting can only be used in parallel mode),
66! all kinds given in PALM style
67!
68! 1762 2016-02-25 12:31:13Z hellstea
69! Initial revision by K. Ketelsen
70!
71! Description:
72! ------------
73!
74! Structure definition and utilities of Palm Model Coupler
75!------------------------------------------------------------------------------!
76
77#if defined( __parallel )
78    USE, INTRINSIC ::  ISO_C_BINDING
79
80    USE kinds
81
82#if defined( __mpifh )
83    INCLUDE "mpif.h"
84#else
85    USE MPI
86#endif
87
88    IMPLICIT NONE
89
90    PRIVATE
91    SAVE
92
93    INTEGER(iwp), PARAMETER, PUBLIC :: da_desclen       =  8  !<
94    INTEGER(iwp), PARAMETER, PUBLIC :: da_namelen       = 16  !<
95    INTEGER(iwp), PARAMETER, PUBLIC :: pmc_da_name_err  = 10  !<
96    INTEGER(iwp), PARAMETER, PUBLIC :: pmc_max_array    = 32  !< max # of arrays which can be coupled
97    INTEGER(iwp), PARAMETER, PUBLIC :: pmc_max_models   = 64  !<
98    INTEGER(iwp), PARAMETER, PUBLIC :: pmc_status_ok    =  0  !<
99    INTEGER(iwp), PARAMETER, PUBLIC :: pmc_status_error = -1  !<
100
101
102    TYPE, PUBLIC :: xy_ind  !< pair of indices in horizontal plane
103       INTEGER(iwp) ::  i
104       INTEGER(iwp) ::  j
105    END TYPE
106
107    TYPE, PUBLIC ::  arraydef
108       INTEGER(iwp)                   :: coupleindex  !<
109       INTEGER(iwp)                   :: nrdims       !< number of dimensions
110       INTEGER(iwp)                   :: dimkey       !< key for NR dimensions and array type
111       INTEGER(iwp), DIMENSION(4)     :: a_dim        !< size of dimensions
112       TYPE(C_PTR)               :: data         !< pointer of data in parent space
113       TYPE(C_PTR), DIMENSION(2) :: po_data      !< base pointers,
114                                                 !< pmc_s_set_active_data_array
115                                                 !< sets active pointer
116       INTEGER(idp)              :: SendIndex    !< index in send buffer
117       INTEGER(idp)              :: RecvIndex    !< index in receive buffer
118       INTEGER(iwp)              :: SendSize     !< size in send buffer
119       INTEGER(iwp)              :: RecvSize     !< size in receive buffer
120       TYPE(C_PTR)               :: SendBuf      !< data pointer in send buffer
121       TYPE(C_PTR)               :: RecvBuf      !< data pointer in receive buffer
122       CHARACTER(LEN=8)          :: Name         !< name of array
123       TYPE(arraydef), POINTER   :: next
124    END TYPE arraydef
125
126    TYPE(arraydef), PUBLIC, POINTER  :: next
127
128    TYPE, PUBLIC ::  pedef
129       INTEGER(iwp) :: nr_arrays = 0  !< number of arrays which will be transfered
130       INTEGER(iwp) :: nrele          !< number of elements, same for all arrays
131       TYPE(xy_ind), POINTER, DIMENSION(:)   ::  locInd      !< xy index local array for remote PE
132       TYPE(arraydef), POINTER, DIMENSION(:) ::  array_list  !< list of data arrays to be transfered
133    END TYPE pedef
134
135    TYPE, PUBLIC ::  childdef
136       INTEGER(idp) ::  totalbuffersize    !<
137       INTEGER(iwp) ::  model_comm         !< communicator of this model
138       INTEGER(iwp) ::  inter_comm         !< inter communicator model and child
139       INTEGER(iwp) ::  intra_comm         !< intra communicator model and child
140       INTEGER(iwp) ::  model_rank         !< rank of this model
141       INTEGER(iwp) ::  model_npes         !< number of PEs this model
142       INTEGER(iwp) ::  inter_npes         !< number of PEs child model
143       INTEGER(iwp) ::  intra_rank         !< rank within intra_comm
144       INTEGER(iwp) ::  win_parent_child   !< MPI RMA for preparing data on parent AND child side
145       TYPE(pedef), DIMENSION(:), POINTER ::  pes  !< list of all child PEs
146    END TYPE childdef
147
148    TYPE, PUBLIC ::  da_namedef  !< data array name definition
149       INTEGER(iwp)              ::  couple_index  !< unique number of array
150       CHARACTER(LEN=da_desclen) ::  parentdesc    !< parent array description
151       CHARACTER(LEN=da_namelen) ::  nameonparent  !< name of array within parent
152       CHARACTER(LEN=da_desclen) ::  childdesc     !< child array description
153       CHARACTER(LEN=da_namelen) ::  nameonchild   !< name of array within child
154    END TYPE da_namedef
155
156    INTERFACE pmc_g_setname
157       MODULE PROCEDURE pmc_g_setname
158    END INTERFACE pmc_g_setname
159
160    INTERFACE pmc_sort
161       MODULE PROCEDURE sort_2d_i
162    END INTERFACE pmc_sort
163
164    PUBLIC pmc_g_setname, pmc_sort
165
166 CONTAINS
167
168
169   
170 SUBROUTINE pmc_g_setname( mychild, couple_index, aname )
171
172    IMPLICIT NONE
173
174    CHARACTER(LEN=*)              ::  aname         !<
175    INTEGER(iwp), INTENT(IN)      ::  couple_index  !<
176    TYPE(childdef), INTENT(INOUT) ::  mychild       !<
177
178    INTEGER(iwp) ::  i  !<
179
180    TYPE(arraydef), POINTER ::  ar   !<
181    TYPE(pedef), POINTER    ::  ape  !<
182
183!
184!-- Assign array to next free index in array list.
185!-- Set name of array in arraydef structure
186    DO  i = 1, mychild%inter_npes
187       ape => mychild%pes(i)
188       ape%nr_arrays = ape%nr_arrays + 1
189       ape%array_list(ape%nr_arrays)%name        = aname
190       ape%array_list(ape%nr_arrays)%coupleindex = couple_index
191    ENDDO
192
193 END SUBROUTINE pmc_g_setname
194
195
196
197 SUBROUTINE sort_2d_i( array, sort_ind )
198
199    IMPLICIT NONE
200
201    INTEGER(iwp), INTENT(IN)                    ::  sort_ind
202    INTEGER(iwp), DIMENSION(:,:), INTENT(INOUT) ::  array
203
204    INTEGER(iwp) ::  i  !<
205    INTEGER(iwp) ::  j  !<
206    INTEGER(iwp) ::  n  !<
207
208    INTEGER(iwp), DIMENSION(SIZE(array,1)) ::  tmp  !<
209
210    n = SIZE(array,2)
211    DO  j = 1, n-1
212       DO  i = j+1, n
213          IF ( array(sort_ind,i) < array(sort_ind,j) )  THEN
214             tmp = array(:,i)
215             array(:,i) = array(:,j)
216             array(:,j) = tmp
217          ENDIF
218       ENDDO
219    ENDDO
220
221 END  SUBROUTINE sort_2d_i
222
223#endif
224 END MODULE pmc_general
Note: See TracBrowser for help on using the repository browser.