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

Last change on this file since 4180 was 4180, checked in by scharf, 5 years ago

removed comments in 'Former revisions' section that are older than 01.01.2019

  • Property svn:keywords set to Id
File size: 6.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-2019 Leibniz Universitaet Hannover
19!------------------------------------------------------------------------------!
20!
21! Current revisions:
22! ------------------
23!
24!
25! Former revisions:
26! -----------------
27! $Id: pmc_general_mod.f90 4180 2019-08-21 14:37:54Z scharf $
28!
29! 2019-04-24 17:31:34Z suehring
30! Increase character length so that also chemistry variable names fully fit
31!
32! 3655 2019-01-07 16:51:22Z knoop
33! Determine number of coupled arrays dynamically.
34!
35!
36! Description:
37! ------------
38!
39! Structure definition and utilities of Palm Model Coupler
40!------------------------------------------------------------------------------!
41
42#if defined( __parallel )
43    USE, INTRINSIC ::  ISO_C_BINDING
44
45    USE kinds
46
47#if !defined( __mpifh )
48    USE MPI
49#endif
50
51    IMPLICIT NONE
52
53#if defined( __mpifh )
54    INCLUDE "mpif.h"
55#endif
56
57    PRIVATE
58    SAVE
59
60    INTEGER(iwp), PUBLIC            :: pmc_max_array          !< max # of arrays which can be coupled - will be determined dynamically in pmc_interface
61   
62    INTEGER(iwp), PARAMETER, PUBLIC :: da_desclen       =  8  !<
63    INTEGER(iwp), PARAMETER, PUBLIC :: da_namelen       = 16  !<
64    INTEGER(iwp), PARAMETER, PUBLIC :: pmc_da_name_err  = 10  !<
65    INTEGER(iwp), PARAMETER, PUBLIC :: pmc_max_models   = 64  !<
66    INTEGER(iwp), PARAMETER, PUBLIC :: pmc_status_ok    =  0  !<
67    INTEGER(iwp), PARAMETER, PUBLIC :: pmc_status_error = -1  !<
68
69
70    TYPE, PUBLIC :: xy_ind  !< pair of indices in horizontal plane
71       INTEGER(iwp) ::  i
72       INTEGER(iwp) ::  j
73    END TYPE
74
75    TYPE, PUBLIC ::  arraydef
76       INTEGER(iwp)                   :: coupleindex  !<
77       INTEGER(iwp)                   :: nrdims       !< number of dimensions
78       INTEGER(iwp)                   :: dimkey       !< key for NR dimensions and array type
79       INTEGER(iwp), DIMENSION(4)     :: a_dim        !< size of dimensions
80       TYPE(C_PTR)               :: data         !< pointer of data in parent space
81       TYPE(C_PTR), DIMENSION(2) :: po_data      !< base pointers,
82                                                 !< pmc_s_set_active_data_array
83                                                 !< sets active pointer
84       INTEGER(idp)              :: SendIndex    !< index in send buffer
85       INTEGER(idp)              :: RecvIndex    !< index in receive buffer
86       INTEGER(iwp)              :: SendSize     !< size in send buffer
87       INTEGER(iwp)              :: RecvSize     !< size in receive buffer
88       TYPE(C_PTR)               :: SendBuf      !< data pointer in send buffer
89       TYPE(C_PTR)               :: RecvBuf      !< data pointer in receive buffer
90       CHARACTER(LEN=da_namelen) :: Name         !< name of array
91       TYPE(arraydef), POINTER   :: next
92    END TYPE arraydef
93
94    TYPE(arraydef), PUBLIC, POINTER  :: next
95
96    TYPE, PUBLIC ::  pedef
97       INTEGER(iwp) :: nr_arrays = 0  !< number of arrays which will be transfered
98       INTEGER(iwp) :: nrele          !< number of elements, same for all arrays
99       TYPE(xy_ind), POINTER, DIMENSION(:)   ::  locInd      !< xy index local array for remote PE
100       TYPE(arraydef), POINTER, DIMENSION(:) ::  array_list  !< list of data arrays to be transfered
101    END TYPE pedef
102
103    TYPE, PUBLIC ::  childdef
104       INTEGER(idp) ::  totalbuffersize    !<
105       INTEGER(iwp) ::  model_comm         !< communicator of this model
106       INTEGER(iwp) ::  inter_comm         !< inter communicator model and child
107       INTEGER(iwp) ::  intra_comm         !< intra communicator model and child
108       INTEGER(iwp) ::  model_rank         !< rank of this model
109       INTEGER(iwp) ::  model_npes         !< number of PEs this model
110       INTEGER(iwp) ::  inter_npes         !< number of PEs child model
111       INTEGER(iwp) ::  intra_rank         !< rank within intra_comm
112       INTEGER(iwp) ::  win_parent_child   !< MPI RMA for preparing data on parent AND child side
113       TYPE(pedef), DIMENSION(:), POINTER ::  pes  !< list of all child PEs
114    END TYPE childdef
115
116    TYPE, PUBLIC ::  da_namedef  !< data array name definition
117       INTEGER(iwp)              ::  couple_index  !< unique number of array
118       CHARACTER(LEN=da_desclen) ::  parentdesc    !< parent array description
119       CHARACTER(LEN=da_namelen) ::  nameonparent  !< name of array within parent
120       CHARACTER(LEN=da_desclen) ::  childdesc     !< child array description
121       CHARACTER(LEN=da_namelen) ::  nameonchild   !< name of array within child
122    END TYPE da_namedef
123
124    INTERFACE pmc_g_setname
125       MODULE PROCEDURE pmc_g_setname
126    END INTERFACE pmc_g_setname
127
128    INTERFACE pmc_sort
129       MODULE PROCEDURE sort_2d_i
130    END INTERFACE pmc_sort
131
132    PUBLIC pmc_g_setname, pmc_sort
133
134 CONTAINS
135
136
137   
138 SUBROUTINE pmc_g_setname( mychild, couple_index, aname )
139
140    IMPLICIT NONE
141
142    CHARACTER(LEN=*)              ::  aname         !<
143    INTEGER(iwp), INTENT(IN)      ::  couple_index  !<
144    TYPE(childdef), INTENT(INOUT) ::  mychild       !<
145
146    INTEGER(iwp) ::  i  !<
147
148    TYPE(pedef), POINTER    ::  ape  !<
149
150!
151!-- Assign array to next free index in array list.
152!-- Set name of array in arraydef structure
153    DO  i = 1, mychild%inter_npes
154       ape => mychild%pes(i)
155       ape%nr_arrays = ape%nr_arrays + 1
156       ape%array_list(ape%nr_arrays)%name        = aname
157       ape%array_list(ape%nr_arrays)%coupleindex = couple_index
158    ENDDO
159
160 END SUBROUTINE pmc_g_setname
161
162
163
164 SUBROUTINE sort_2d_i( array, sort_ind )
165
166    IMPLICIT NONE
167
168    INTEGER(iwp), INTENT(IN)                    ::  sort_ind
169    INTEGER(iwp), DIMENSION(:,:), INTENT(INOUT) ::  array
170
171    INTEGER(iwp) ::  i  !<
172    INTEGER(iwp) ::  j  !<
173    INTEGER(iwp) ::  n  !<
174
175    INTEGER(iwp), DIMENSION(SIZE(array,1)) ::  tmp  !<
176
177    n = SIZE(array,2)
178    DO  j = 1, n-1
179       DO  i = j+1, n
180          IF ( array(sort_ind,i) < array(sort_ind,j) )  THEN
181             tmp = array(:,i)
182             array(:,i) = array(:,j)
183             array(:,j) = tmp
184          ENDIF
185       ENDDO
186    ENDDO
187
188 END  SUBROUTINE sort_2d_i
189
190#endif
191 END MODULE pmc_general
Note: See TracBrowser for help on using the repository browser.