FE-Project
Loading...
Searching...
No Matches
scale_mesh_rectdom2d.F90
Go to the documentation of this file.
1!-------------------------------------------------------------------------------
2!> module FElib / Mesh / Rectangle 2D domain
3!!
4!! @par Description
5!! Manage mesh data of rectangle 2D domain for element-based methods
6!!
7!! @author Yuta Kawai, Team SCALE
8!<
9!-------------------------------------------------------------------------------
10#include "scaleFElib.h"
12
13 !-----------------------------------------------------------------------------
14 !
15 !++ used modules
16 !
17 use scale_precision
18
19 use scale_mesh_base2d, only: &
22
23 use scale_localmesh_2d, only: &
27
28 !-----------------------------------------------------------------------------
29 implicit none
30 private
31
32 !-----------------------------------------------------------------------------
33 !
34 !++ Public type & procedure
35 !
36 !> Derived type to manage a rectangular 2D computational domain
37 type, extends(meshbase2d), public :: meshrectdom2d
38 integer :: negx !< Number of elements in X direction (global)
39 integer :: negy !< Number of elements in Y direction (global)
40
41 integer :: nprcx !< Number of processes in X direction for domain decomposition
42 integer :: nprcy !< Number of processes in Y direction for domain decomposition
43
44 real(rp), public :: xmin_gl !< Minimum X coordinate of the global domain
45 real(rp), public :: xmax_gl !< Maximum X coordinate of the global domain
46 real(rp), public :: ymin_gl !< Minimum Y coordinate of the global domain
47 real(rp), public :: ymax_gl !< Maximum Y coordinate of the global domain
48
49 integer, allocatable :: rcdomij2lcmeshid(:,:)
50
51 logical :: isperiodicx !< Flag whether the domain is periodic in X direction
52 logical :: isperiodicy !< Flag whether the domain is periodic in Y direction
53 contains
54 procedure :: init => meshrectdom2d_init
55 procedure :: final => meshrectdom2d_final
56 procedure :: generate => meshrectdom2d_generate
57 procedure :: assigndomid => meshrectdom2d_assigndomid
58 end type meshrectdom2d
59
62
63 !-----------------------------------------------------------------------------
64 !
65 !++ Public parameters & variables
66 !
67
68 !-----------------------------------------------------------------------------
69 !
70 !++ Private procedure
71 !
72
73 !-----------------------------------------------------------------------------
74 !
75 !++ Private parameters & variables
76 !
77
78contains
79 !> Initialize an object to manage a 2D rectangular computational mesh
80!OCL SERIAL
81 subroutine meshrectdom2d_init(this, &
82 NeGX, NeGY, &
83 dom_xmin, dom_xmax, dom_ymin, dom_ymax, &
84 isPeriodicX, isPeriodicY, &
85 refElem, NLocalMeshPerPrc, &
86 NprcX, NprcY, &
87 nproc, myrank )
88
89 implicit none
90
91 class(meshrectdom2d), intent(inout) :: this
92 integer, intent(in) :: NeGX !< Number of elements in X direction (global)
93 integer, intent(in) :: NeGY !< Number of elements in Y direction (global)
94 real(RP), intent(in) :: dom_xmin !< Minimum X coordinate of the global domain
95 real(RP), intent(in) :: dom_xmax !< Maximum X coordinate of the global domain
96 real(RP), intent(in) :: dom_ymin !< Minimum Y coordinate of the global domain
97 real(RP), intent(in) :: dom_ymax !< Maximum Y coordinate of the global domain
98 logical, intent(in) :: isPeriodicX !< Flag whether the domain is periodic in X direction
99 logical, intent(in) :: isPeriodicY !< Flag whether the domain is periodic in Y direction
100 type(quadrilateralelement), intent(in), target :: refElem !< Reference element for the 2D mesh
101 integer, intent(in) :: NLocalMeshPerPrc !< Number of local meshes managed by each process
102 integer, intent(in) :: NprcX !< Number of processes in X direction for domain decomposition
103 integer, intent(in) :: NprcY !< Number of processes in Y direction for domain decomposition
104 integer, intent(in), optional :: nproc !< Total number of processes (if not provided, it will be determined from the parallel environment)
105 integer, intent(in), optional :: myrank !< Rank of the current process (if not provided, it will be determined from the parallel environment)
106
107 !-----------------------------------------------------------------------------
108
109 this%NeGX = negx
110 this%NeGY = negy
111
112 this%xmin_gl = dom_xmin
113 this%xmax_gl = dom_xmax
114 this%ymin_gl = dom_ymin
115 this%ymax_gl = dom_ymax
116 this%dom_vol = (this%xmax_gl - this%xmin_gl) * (this%ymax_gl - this%ymin_gl)
117
118 this%isPeriodicX = isperiodicx
119 this%isPeriodicY = isperiodicy
120
121 this%NprcX = nprcx
122 this%NprcY = nprcy
123
124 call meshbase2d_init( this, refelem, nlocalmeshperprc, &
125 nproc, myrank )
126
127 return
128 end subroutine meshrectdom2d_init
129
130 !> Finalize an object to manage a 2D rectangular computational mesh
131!OCL SERIAL
132 subroutine meshrectdom2d_final( this )
133 implicit none
134 class(meshrectdom2d), intent(inout) :: this
135
136 integer :: n
137 !-----------------------------------------------------------------------------
138
139 if (this%isGenerated) then
140 if ( allocated(this%rcdomIJ2LCMeshID) ) then
141 !$acc exit data delete(this%rcdomIJ2LCMeshID)
142 deallocate( this%rcdomIJ2LCMeshID )
143 end if
144 end if
145
146 call meshbase2d_final( this )
147
148 return
149 end subroutine meshrectdom2d_final
150
151 !> Generate meshes for the rectangular domain
152!OCL SERIAL
153 subroutine meshrectdom2d_generate( this )
154 implicit none
155 class(meshrectdom2d), intent(inout), target :: this
156
157 integer :: n
158 integer :: p
159 type(localmesh2d), pointer :: mesh
160
161 integer :: tileID_table(this%LOCAL_MESH_NUM, this%PRC_NUM)
162 integer :: panelID_table(this%LOCAL_MESH_NUM*this%PRC_NUM)
163 integer :: pi_table(this%LOCAL_MESH_NUM*this%PRC_NUM)
164 integer :: pj_table(this%LOCAL_MESH_NUM*this%PRC_NUM)
165
166 integer :: TILE_NUM_PER_PANEL
167 real(RP) :: delx, dely
168 integer :: tileID
169 !-----------------------------------------------------------------------------
170
171 tile_num_per_panel = this%LOCAL_MESH_NUM_global / 1
172
173
174 !--- Construct the connectivity of patches (only master node)
175
176 call this%AssignDomID( &
177 tileid_table, panelid_table, & ! (out)
178 pi_table, pj_table ) ! (out)
179
180 !--- Setup local meshes managed by my process
181
182 do n=1, this%LOCAL_MESH_NUM
183 mesh => this%lcmesh_list(n)
184 tileid = tileid_table(n, mesh%PRC_myrank+1)
185
186 call meshrectdom2d_setuplocaldom( mesh, &
187 tileid, panelid_table(tileid), &
188 pi_table(tileid), pj_table(tileid), this%NprcX, this%NprcY, &
189 this%xmin_gl, this%xmax_gl, this%ymin_gl, this%ymax_gl, &
190 this%NeGX/this%NprcX, this%NeGY/this%NprcY )
191
192 !---
193 ! write(*,*) "** my_rank=", mesh%PRC_myrank
194 ! write(*,*) " tileID:", mesh%tileID
195 ! write(*,*) " pnlID:", mesh%panelID, "-- i,j (within a panel)=", pi_table(tileID), pj_table(tileID)
196 ! write(*,*) " local mesh:", n, "( total", this%LOCAL_MESH_NUM, ")"
197 ! write(*,*) " panel_connect:", this%tilePanelID_globalMap(:,mesh%tileID)
198 ! write(*,*) " tile_connect:", this%tileID_globalMap(:,mesh%tileID)
199 ! write(*,*) " face_connect:", this%tileFaceID_globalMap(:,mesh%tileID)
200 ! write(*,*) " domain size"
201 ! write(*,*) " NeX, NeY:", mesh%NeX, mesh%NeY
202 ! write(*,*) " [X], [Y]:", mesh%xmin, mesh%xmax, ":", mesh%ymin, mesh%ymax
203 end do
204
205 this%isGenerated = .true.
206
207 return
208 end subroutine meshrectdom2d_generate
209
210 !- private ------------------------------------------------------
211
212 subroutine meshrectdom2d_setuplocaldom( lcmesh, &
213 tileID, panelID, &
214 i, j, NprcX, NprcY, &
215 dom_xmin, dom_xmax, dom_ymin, dom_ymax, &
216 NeX, NeY )
217
218 use scale_meshutil_2d, only: &
223
225 implicit none
226
227 type(localmesh2d), intent(inout) :: lcmesh
228 integer, intent(in) :: tileid
229 integer, intent(in) :: panelid
230 integer, intent(in) :: i, j
231 integer, intent(in) :: nprcx, nprcy
232 real(rp), intent(in) :: dom_xmin, dom_xmax
233 real(rp), intent(in) :: dom_ymin, dom_ymax
234 integer, intent(in) ::nex, ney
235
236 class(elementbase2d), pointer :: elem
237 real(rp) :: delx, dely
238
239 !-----------------------------------------------------------------------------
240
241 elem => lcmesh%refElem2D
242 lcmesh%tileID = tileid
243 lcmesh%panelID = panelid
244 !$acc update device(lcmesh%tileID, lcmesh%panelID)
245
246 !--
247
248 lcmesh%Ne = nex * ney
249 lcmesh%Nv = (nex + 1)*(ney + 1)
250 lcmesh%NeS = 1
251 lcmesh%NeE = lcmesh%Ne
252 lcmesh%NeA = lcmesh%Ne + 2*(nex + ney)
253 !$acc update device(lcmesh%Ne, lcmesh%Nv, lcmesh%NeS, lcmesh%NeE, lcmesh%NeA)
254
255 lcmesh%NeX = nex
256 lcmesh%NeY = ney
257 !$acc update device(lcmesh%NeX, lcmesh%NeY)
258
259 delx = (dom_xmax - dom_xmin)/dble(nprcx)
260 dely = (dom_ymax - dom_ymin)/dble(nprcy)
261
262 lcmesh%xmin = dom_xmin + (i-1)*delx
263 lcmesh%xmax = dom_xmin + i *delx
264 lcmesh%ymin = dom_ymin + (j-1)*dely
265 lcmesh%ymax = dom_ymin + j *dely
266 !$acc update device(lcmesh%xmin, lcmesh%xmax, lcmesh%ymin, lcmesh%ymax)
267
268 allocate( lcmesh%pos_ev(lcmesh%Nv,2) )
269 allocate( lcmesh%EToV(lcmesh%Ne,elem%Nv) )
270 allocate( lcmesh%EToE(lcmesh%Ne,elem%Nfaces) )
271 allocate( lcmesh%EToF(lcmesh%Ne,elem%Nfaces) )
272 allocate( lcmesh%BCType(lcmesh%refElem%Nfaces,lcmesh%Ne) )
273 allocate( lcmesh%VMapM(elem%NfpTot, lcmesh%Ne) )
274 allocate( lcmesh%VMapP(elem%NfpTot, lcmesh%Ne) )
275 allocate( lcmesh%MapM(elem%NfpTot, lcmesh%Ne) )
276 allocate( lcmesh%MapP(elem%NfpTot, lcmesh%Ne) )
277 !$acc enter data create(lcmesh%pos_ev, lcmesh%EToV, lcmesh%EToE, lcmesh%EToF, lcmesh%BCType, &
278 !$acc lcmesh%VMapM, lcmesh%VMapP, lcmesh%MapM, lcmesh%MapP)
279
280 lcmesh%BCType(:,:) = bctype_interior
281 !$acc update device(lcmesh%BCType)
282
283 !----
284
285 call meshutil2d_genrectdomain( lcmesh%pos_ev, lcmesh%EToV, & ! (out)
286 lcmesh%NeX, lcmesh%xmin, lcmesh%xmax, & ! (in)
287 lcmesh%NeY, lcmesh%ymin, lcmesh%ymax ) ! (in)
288 !$acc update device(lcmesh%pos_ev, lcmesh%EToV)
289
290 !---
291 call meshbase2d_setgeometricinfo( lcmesh, meshrectdom2d_coord_conv, meshrectdom2d_calc_normal )
292
293 !---
294
295 call meshutil2d_genconnectivity( lcmesh%EToE, lcmesh%EToF, & ! (out)
296 lcmesh%EToV, lcmesh%Ne, elem%Nfaces ) ! (in)
297 !$acc update device(lcmesh%EToE, lcmesh%EToF)
298
299 !---
300 call meshutil2d_buildinteriormap( lcmesh%VmapM, lcmesh%VMapP, lcmesh%MapM, lcmesh%MapP, &
301 lcmesh%pos_en, lcmesh%pos_ev, lcmesh%EToE, lcmesh%EtoF, lcmesh%EtoV, &
302 elem%Fmask, lcmesh%Ne, elem%Np, elem%Nfp, elem%Nfaces, lcmesh%Nv )
303
304 call meshutil2d_genpatchboundarymap( lcmesh%VMapB, lcmesh%MapB, lcmesh%VMapP, &
305 lcmesh%pos_en, lcmesh%xmin, lcmesh%xmax, lcmesh%ymin, lcmesh%ymax, &
306 elem%Fmask, lcmesh%Ne, elem%Np, elem%Nfp, elem%Nfaces, lcmesh%Nv)
307 !$acc update device(lcmesh%VMapM, lcmesh%VMapP, lcmesh%MapM, lcmesh%MapP)
308 !$acc enter data copyin(lcmesh%VMapB, lcmesh%MapB)
309
310 return
311 end subroutine meshrectdom2d_setuplocaldom
312
313 subroutine meshrectdom2d_assigndomid( this, &
314 tileID_table, panelID_table, &
315 pi_table, pj_table )
316
317 use scale_meshutil_2d, only: &
319 use scale_io
320 implicit none
321
322 class(meshrectdom2d), target, intent(inout) :: this
323 integer, intent(out) :: tileid_table(this%local_mesh_num, this%prc_num)
324 integer, intent(out) :: panelid_table(this%local_mesh_num*this%prc_num)
325 integer, intent(out) :: pi_table(this%local_mesh_num*this%prc_num)
326 integer, intent(out) :: pj_table(this%local_mesh_num*this%prc_num)
327
328 integer :: n
329 integer :: prc
330 integer :: tileid
331 integer :: is_lc, js_lc
332 integer :: ilc_count, jlc_count
333 integer :: ilc, jlc
334
335 type(localmesh2d), pointer :: lcmesh
336 !-----------------------------------------------------------------------------
337
339 panelid_table, pi_table, pj_table, & ! (out)
340 this%tileID_globalMap, this%tileFaceID_globalMap, this%tilePanelID_globalMap, & ! (out)
341 this%LOCAL_MESH_NUM_global, this%isPeriodicX, this%isPeriodicY, & ! (in)
342 this%NprcX, this%NprcY ) ! (in)
343 !$acc update device(this%tileID_globalMap, this%tileFaceID_globalMap, this%tilePanelID_globalMap)
344
345 !----
346
347 do prc=1, this%PRC_NUM
348 do n=1, this%LOCAL_MESH_NUM
349 tileid = n + (prc-1)*this%LOCAL_MESH_NUM
350 lcmesh => this%lcmesh_list(n)
351 !-
352 tileid_table(n,prc) = tileid
353 this%tileID_global2localMap(tileid) = n
354 this%PRCRank_globalMap(tileid) = prc - 1
355
356 !-
357 if ( this%PRCRank_globalMap(tileid) == lcmesh%PRC_myrank ) then
358 if (n==1) then
359 is_lc = pi_table(tileid); ilc_count = 1
360 js_lc = pj_table(tileid); jlc_count = 1
361 end if
362 if(is_lc < pi_table(tileid)) ilc_count = ilc_count + 1
363 if(js_lc < pj_table(tileid)) jlc_count = jlc_count + 1
364 end if
365 end do
366 end do
367 !$acc update device(this%tileID_global2localMap, this%PRCRank_globalMap)
368
369 allocate( this%rcdomIJ2LCMeshID(ilc_count,jlc_count) )
370 do jlc=1, jlc_count
371 do ilc=1, ilc_count
372 this%rcdomIJ2LCMeshID(ilc,jlc) = ilc + (jlc - 1)*ilc_count
373 end do
374 end do
375 !$acc enter data copyin(this%rcdomIJ2LCMeshID)
376
377 return
378 end subroutine meshrectdom2d_assigndomid
379
380 subroutine meshrectdom2d_coord_conv( x, y, xr, xs, yr, ys, &
381 vx, vy, elem )
382 implicit none
383
384 type(elementbase2d), intent(in) :: elem
385 real(rp), intent(out) :: x(elem%np), y(elem%np)
386 real(rp), intent(out) :: xr(elem%np), xs(elem%np), yr(elem%np), ys(elem%np)
387 real(rp), intent(in) :: vx(elem%nv), vy(elem%nv)
388
389 !-------------------------------------------------
390
391 x(:) = vx(1) + 0.5_rp*(elem%x1(:) + 1.0_rp)*(vx(2) - vx(1))
392 y(:) = vy(1) + 0.5_rp*(elem%x2(:) + 1.0_rp)*(vy(3) - vy(1))
393
394 xr(:) = 0.5_rp*(vx(2) - vx(1)) !matmul(refElem%Dx1,mesh%x1(:,n))
395 xs(:) = 0.0_rp !matmul(refElem%Dx2,mesh%x1(:,n))
396 yr(:) = 0.0_rp !matmul(refElem%Dx1,mesh%x2(:,n))
397 ys(:) = 0.5_rp*(vy(3) - vy(1)) !matmul(refElem%Dx2,mesh%x2(:,n))
398
399 return
400 end subroutine meshrectdom2d_coord_conv
401
402 subroutine meshrectdom2d_calc_normal( normal_fn, &
403 Escale_f, fid, elem )
404 implicit none
405
406 type(elementbase2d), intent(in) :: elem
407 real(rp), intent(out) :: normal_fn(elem%nfptot,2)
408 integer, intent(in) :: fid(elem%nfp,elem%nfaces)
409 real(rp), intent(in) :: escale_f(elem%nfptot,2,2)
410
411 integer :: d
412 !-------------------------------------------------
413
414 do d=1, 2
415 normal_fn(fid(:,1),d) = - escale_f(fid(:,1),2,d)
416 normal_fn(fid(:,2),d) = + escale_f(fid(:,2),1,d)
417 normal_fn(fid(:,3),d) = + escale_f(fid(:,3),2,d)
418 normal_fn(fid(:,4),d) = - escale_f(fid(:,4),1,d)
419 end do
420
421 return
422 end subroutine meshrectdom2d_calc_normal
423
424end module scale_mesh_rectdom2d
module FElib / Element / Base
module FElib / Element / Quadrilateral
module FElib / Mesh / Local 2D
module FElib / Mesh / Local, Base
integer, parameter, public bctype_interior
module FElib / Mesh / Base 2D
subroutine, public meshbase2d_final(this)
Finalize an object to manage a 2D computational mesh.
subroutine, public meshbase2d_init(this, refelem, nlocalmeshperprc, nprocs, myrank)
Initialize an object to manage a 2D computational mesh.
subroutine, public meshbase2d_setgeometricinfo(lcmesh, coord_conv, calc_normal)
module FElib / Mesh / Rectangle 2D domain
subroutine, public meshrectdom2d_setuplocaldom(lcmesh, tileid, panelid, i, j, nprcx, nprcy, dom_xmin, dom_xmax, dom_ymin, dom_ymax, nex, ney)
subroutine, public meshrectdom2d_coord_conv(x, y, xr, xs, yr, ys, vx, vy, elem)
subroutine meshrectdom2d_init(this, negx, negy, dom_xmin, dom_xmax, dom_ymin, dom_ymax, isperiodicx, isperiodicy, refelem, nlocalmeshperprc, nprcx, nprcy, nproc, myrank)
Initialize an object to manage a 2D rectangular computational mesh.
module FElib / Mesh / utility for 2D mesh
subroutine, public meshutil2d_buildinteriormap(vmapm, vmapp, mapm, mapp, pos_en, pos_ev, etoe, etof, etov, fmask, ne, np, nfp, nfaces, nv)
subroutine, public meshutil2d_genconnectivity(etoe, etof, etov, ne, nfaces)
subroutine, public meshutil2d_genrectdomain(pos_v, etov, ke_x, xmin, xmax, ke_y, ymin, ymax)
subroutine, public meshutil2d_buildglobalmap(panelid_table, pi_table, pj_table, tileid_map, tilefaceid_map, tilepanelid_map, ntile, isperiodicx, isperiodicy, ne_x, ne_y)
subroutine, public meshutil2d_genpatchboundarymap(vmapb, mapb, vmapp, pos_en, xmin, xmax, ymin, ymax, fmask, ne, np, nfp, nfaces, nv)
Derived type representing a 2D reference element.
Derived type representing a quadrilateral element.
Derived type representing a local mesh for 2D domain.
Derived type to manage a computational mesh (base type for 2D domain)
Derived type to manage a rectangular 2D computational domain.