FE-Project
Loading...
Searching...
No Matches
scale_mesh_base1d.F90
Go to the documentation of this file.
1!-------------------------------------------------------------------------------
2!> module FElib / Mesh / Base 1D
3!!
4!! @par Description
5!! Base module to manage 1D meshes for element-based methods
6!!
7!! @author Yuta Kawai, Team SCALE
8!<
9#include "scaleFElib.h"
11
12 !-----------------------------------------------------------------------------
13 !
14 !++ used modules
15 !
16 use scale_precision
17
18 use scale_localmesh_1d, only: &
20
21 use scale_mesh_base, only: meshbase, &
24
27
28 !-----------------------------------------------------------------------------
29 implicit none
30 private
31
32 !-----------------------------------------------------------------------------
33 !
34 !++ Public type & procedure
35 !
36 !> Derived type to manage a computational mesh (base type for 1D domain)
37 type, abstract, public, extends(meshbase) :: meshbase1d
38 type(localmesh1d), allocatable :: lcmesh_list(:) !< Array of local meshes in each MPI process
39 class(elementbase1d), pointer :: refelem1d !< Pointer to an object with a reference element for 1D
40
41 integer, public :: neg
42 integer, public :: nprc
43
44 real(rp), public :: xmin_gl !< Minimum x-coordinate of the global mesh
45 real(rp), public :: xmax_gl !< Maximum x-coordinate of the global mesh
46
47 real(rp), public, allocatable :: fx(:)
48 contains
49 procedure(meshbase1d_generate), deferred :: generate
50 procedure :: getlocalmesh => meshbase1d_get_localmesh
51 end type meshbase1d
52
53 interface
54 subroutine meshbase1d_generate(this)
55 import meshbase1d
56 class(meshbase1d), intent(inout), target :: this
57 end subroutine meshbase1d_generate
58 end interface
59
62
63 !-----------------------------------------------------------------------------
64 !
65 !++ Public parameters & variables
66 !
67 integer, public :: meshbase1d_dimtype_num = 2
68 integer, public :: meshbase1d_dimtypeid_x = 1
69 integer, public :: meshbase1d_dimtypeid_xt = 2
70
71 !-----------------------------------------------------------------------------
72 !
73 !++ Private procedure
74 !
75
76 !-----------------------------------------------------------------------------
77 !
78 !++ Private parameters & variables
79 !
80
81contains
82 !> Initialize an object to manage a 1D computational mesh
83!OCL SERIAL
84 subroutine meshbase1d_init( this, &
85 NeG, &
86 dom_xmin, dom_xmax, &
87 refElem, NLocalMeshPerPrc, &
88 nprocs, myrank, FX )
89
90 implicit none
91
92 class(meshbase1d), intent(inout) :: this
93 integer, intent(in) :: neg
94 real(rp), intent(in) :: dom_xmin
95 real(rp), intent(in) :: dom_xmax
96 class(elementbase1d), intent(in), target :: refelem
97 integer, intent(in) :: nlocalmeshperprc
98 integer, intent(in), optional :: nprocs
99 integer, intent(in), optional :: myrank
100 real(rp), intent(in), optional :: fx(neg+1)
101
102 integer :: n
103 integer :: k
104 real(rp) :: dx
105 !-----------------------------------------------------------------------------
106
107 this%NeG = neg
108
109 this%xmin_gl = dom_xmin
110 this%xmax_gl = dom_xmax
111
112 !- Fx
113 allocate( this%FX(neg+1) )
114 if ( present(fx) ) then
115 this%FX(:) = fx(:)
116 else
117 this%FX(1 ) = dom_xmin
118 this%FX(neg+1) = dom_xmax
119 dx = (dom_xmax - dom_xmin) / dble(neg)
120 do k=2, neg
121 this%FX(k) = this%FX(k-1) + dx
122 end do
123 end if
124 !$acc enter data create(this%FX)
125
126 this%refElem1D => refelem
127 call meshbase_init( this, &
128 meshbase1d_dimtype_num, refelem, &
129 nlocalmeshperprc, 2, &
130 nprocs )
131
132 this%Nprc = this%PRC_NUM
133
134 allocate( this%lcmesh_list(this%LOCAL_MESH_NUM) )
135 do n=1, this%LOCAL_MESH_NUM
136 call localmesh1d_init( this%lcmesh_list(n), n, refelem, myrank )
137 end do
138
139 call this%SetDimInfo( meshbase1d_dimtypeid_x, "x", "m", "X-coordinate" )
140 call this%SetDimInfo( meshbase1d_dimtypeid_xt, "xt", "m", "X-coordinate" )
141
142 return
143 end subroutine meshbase1d_init
144
145 !> Finalize an object to manage a 1D computational mesh
146!OCL SERIAL
147 subroutine meshbase1d_final( this )
148 implicit none
149 class(meshbase1d), intent(inout) :: this
150
151 integer :: n
152 !-----------------------------------------------------------------------------
153
154 if ( allocated ( this%lcmesh_list ) ) then
155 do n=1, this%LOCAL_MESH_NUM
156 call localmesh1d_final( this%lcmesh_list(n), this%isGenerated )
157 end do
158
159 deallocate( this%lcmesh_list )
160 end if
161
162 call meshbase_final(this)
163
164 return
165 end subroutine meshbase1d_final
166
167!OCL SERIAL
168 subroutine meshbase1d_get_localmesh( this, id, ptr_lcmesh )
170 implicit none
171
172 class(meshbase1d), target, intent(in) :: this
173 integer, intent(in) :: id
174 class(localmeshbase), pointer, intent(out) :: ptr_lcmesh
175 !-------------------------------------------------------------
176
177 ptr_lcmesh => this%lcmesh_list(id)
178 return
179 end subroutine meshbase1d_get_localmesh
180
181!OCL SERIAL
182 subroutine meshbase1d_setgeometricinfo( lcmesh )
183 implicit none
184
185 type(localmesh1d), intent(inout) :: lcmesh
186
187 class(elementbase1d), pointer :: refelem
188 integer :: ke
189 integer :: f
190 integer :: i
191
192 integer :: node_ids(lcmesh%refelem%nv)
193 real(rp) :: vx(lcmesh%refelem%nv)
194 real(rp) :: xr(lcmesh%refelem%np)
195 real(dp) :: escale(1,1,lcmesh%refelem%np)
196 integer :: fmask(lcmesh%refelem%nfptot)
197 integer :: fid(lcmesh%refelem1d%nfp,lcmesh%refelem1d%nfaces)
198
199 !-----------------------------------------------------------------------------
200
201 call meshbase_setgeometricinfo(lcmesh, 1)
202 refelem => lcmesh%refElem1D
203
204 fmask(:) = reshape(refelem%Fmask, shape(fmask))
205 do f=1, refelem%Nfaces
206 do i=1, refelem%Nfp
207 fid(i,f) = i + (f-1)*refelem%Nfp
208 end do
209 end do
210
211 do ke=1, lcmesh%Ne
212 node_ids(:) = lcmesh%EToV(ke,:)
213 vx(:) = lcmesh%pos_ev(node_ids(:),1)
214 lcmesh%pos_en(:,ke,1) = vx(1) + 0.5_rp*(refelem%x1(:) + 1.0_rp)*(vx(2) - vx(1))
215
216 xr(:) = 0.5_rp*(vx(2) - vx(1)) !matmul(refElem%Dr,mesh%x(:,n))
217
218 lcmesh%J(:,ke) = xr
219 lcmesh%Escale(:,ke,1,1) = 1.0_rp/lcmesh%J(:,ke)
220
221 !* Face
222
223 !
224 !mesh%fx(:,n) = mesh%x(fmask(:),n)
225 !mesh%fy(:,n) = mesh%y(fmask(:),n)
226
227 ! Calculate normal vectors
228 lcmesh%normal_fn(fid(:,1),ke,1) = - 1.0_rp
229 lcmesh%normal_fn(fid(:,2),ke,1) = + 1.0_rp
230 lcmesh%sJ(:,ke) = 1.0_rp
231 lcmesh%Fscale(:,ke) = lcmesh%sJ(:,ke)/lcmesh%J(fmask(:),ke)
232 lcmesh%Gsqrt(:,ke) = 1.0_rp
233 end do
234 !$acc update device(lcmesh%pos_en, lcmesh%normal_fn, lcmesh%sJ, lcmesh%J, lcmesh%Escale, lcmesh%Fscale, lcmesh%Gsqrt)
235
236 return
237 end subroutine meshbase1d_setgeometricinfo
238
239!OCL SERIAL
240 subroutine meshbase1d_assigndomid( this, &
241 tileID_table, panelID_table, &
242 pi_table )
243
244 use scale_meshutil_1d, only: &
246 implicit none
247
248 class(meshbase1d), intent(inout) :: this
249 integer, intent(out) :: tileid_table(this%local_mesh_num, this%prc_num)
250 integer, intent(out) :: panelid_table(this%local_mesh_num*this%prc_num)
251 integer, intent(out) :: pi_table(this%local_mesh_num*this%prc_num)
252
253 integer :: n
254 integer :: p
255 integer :: tileid
256 !-----------------------------------------------------------------------------
257
259 panelid_table, pi_table, & ! (out)
260 this%tileID_globalMap, this%tileFaceID_globalMap, this%tilePanelID_globalMap, & ! (out)
261 this%LOCAL_MESH_NUM_global ) ! (in)
262
263 do p=1, this%PRC_NUM
264 do n=1, this%LOCAL_MESH_NUM
265 tileid = n + (p-1)*this%LOCAL_MESH_NUM
266
267 tileid_table(n,p) = tileid
268 this%tileID_global2localMap(tileid) = n
269 this%PRCRank_globalMap(tileid) = p - 1
270 end do
271 end do
272 !$acc update device(this%tileID_globalMap, this%tileFaceID_globalMap, &
273 !$acc this%tilePanelID_globalMap, this%tileID_global2localMap, this%PRCRank_globalMap)
274
275 return
276 end subroutine meshbase1d_assigndomid
277
278!OCL SERIAL
279 subroutine meshbase1d_setuplocaldom( lcmesh, &
280 tileID, panelID, &
281 i, Nprc, &
282 dom_xmin, dom_xmax, &
283 Ne, FX )
284
285 use scale_meshutil_1d, only: &
290
292 implicit none
293
294 type(localmesh1d), intent(inout) :: lcmesh
295 integer, intent(in) :: tileid
296 integer, intent(in) :: panelid
297 integer, intent(in) :: i
298 integer, intent(in) :: nprc
299 real(rp) :: dom_xmin, dom_xmax
300 integer, intent(in) ::ne
301 real(rp), intent(in) :: fx(ne*nprc+1)
302
303 class(elementbase1d), pointer :: elem
304 real(rp) :: delx
305 real(rp) :: fx_lc(ne+1)
306 !-----------------------------------------------------------------------------
307
308 elem => lcmesh%refElem1D
309 lcmesh%tileID = tileid
310 lcmesh%panelID = panelid
311 !$acc update device(lcmesh%tileID, lcmesh%panelID)
312
313 !--
314
315 lcmesh%Ne = ne
316 lcmesh%Nv = ne + 1
317 lcmesh%NeS = 1
318 lcmesh%NeE = lcmesh%Ne
319 lcmesh%NeA = lcmesh%Ne + 2
320 !$acc update device(lcmesh%Ne, lcmesh%Nv, lcmesh%NeS, lcmesh%NeE, lcmesh%NeA)
321
322 !delx = (dom_xmax - dom_xmin)/dble(Nprc)
323 fx_lc(:) = fx((i-1)*ne+1:i*ne+1)
324 lcmesh%xmin = fx_lc(1)
325 lcmesh%xmax = fx_lc(ne+1)
326 !$acc update device(lcmesh%xmin, lcmesh%xmax)
327
328 allocate( lcmesh%pos_ev(lcmesh%Nv,1) )
329 allocate( lcmesh%EToV(lcmesh%Ne,2) )
330 allocate( lcmesh%EToE(lcmesh%Ne,elem%Nfaces) )
331 allocate( lcmesh%EToF(lcmesh%Ne,elem%Nfaces) )
332 allocate( lcmesh%BCType(lcmesh%refElem%Nfaces,lcmesh%Ne) )
333 allocate( lcmesh%VMapM(elem%NfpTot, lcmesh%Ne) )
334 allocate( lcmesh%VMapP(elem%NfpTot, lcmesh%Ne) )
335 allocate( lcmesh%MapM(elem%NfpTot, lcmesh%Ne) )
336 allocate( lcmesh%MapP(elem%NfpTot, lcmesh%Ne) )
337 !$acc enter data create(lcmesh%pos_ev, lcmesh%EToV, lcmesh%EToE, lcmesh%EToF, lcmesh%BCType, &
338 !$acc lcmesh%VMapM, lcmesh%VMapP, lcmesh%MapM, lcmesh%MapP)
339
340 lcmesh%BCType(:,:) = bctype_interior
341 !$acc update device(lcmesh%BCType)
342
343 !----
344
345 call meshutil1d_genlinedomain( lcmesh%pos_ev, lcmesh%EToV, & ! (out)
346 lcmesh%Ne, lcmesh%xmin, lcmesh%xmax, fx=fx_lc ) ! (in)
347 !$acc update device(lcmesh%pos_ev, lcmesh%EToV)
348
349 !---
350 call meshbase1d_setgeometricinfo( lcmesh )
351
352 !---
353
354 call meshutil1d_genconnectivity( lcmesh%EToE, lcmesh%EToF, & ! (out)
355 & lcmesh%EToV, lcmesh%Ne, elem%Nfaces ) ! (in)
356 !$acc update device(lcmesh%EToE, lcmesh%EToF)
357
358 !---
359 call meshutil1d_buildinteriormap( lcmesh%VmapM, lcmesh%VMapP, lcmesh%MapM, lcmesh%MapP, & ! (out)
360 & lcmesh%pos_en, lcmesh%pos_ev, lcmesh%EToE, lcmesh%EtoF, lcmesh%EtoV, & ! (in)
361 & elem%Fmask, lcmesh%Ne, elem%Np, elem%Nfp, elem%Nfaces, lcmesh%Nv ) ! (in)
362
363 call meshutil1d_genpatchboundarymap( lcmesh%VMapB, lcmesh%MapB, lcmesh%VMapP, & ! (inout)
364 & lcmesh%pos_en, lcmesh%xmin, lcmesh%xmax, & ! (in)
365 & elem%Fmask, lcmesh%Ne, elem%Np, elem%Nfp, elem%Nfaces, lcmesh%Nv ) ! (in)
366 !$acc update device(lcmesh%VMapM, lcmesh%VMapP, lcmesh%MapM, lcmesh%MapP)
367 !$acc enter data copyin(lcmesh%VMapB, lcmesh%MapB)
368
369 return
370 end subroutine meshbase1d_setuplocaldom
371
372end module scale_mesh_base1d
module FElib / Element / Base
module FElib / Element / line
module FElib / Mesh / Local 1D
subroutine, public localmesh1d_final(this, is_generated)
Finalize an object to manage a local mesh for 1D domain.
subroutine, public localmesh1d_init(this, lcdomid, refelem, myrank)
Initialize an object to manage a local mesh for 1D domain.
module FElib / Mesh / Local, Base
integer, parameter, public bctype_interior
module FElib / Mesh / Base 1D
integer, public meshbase1d_dimtype_num
subroutine, public meshbase1d_init(this, neg, dom_xmin, dom_xmax, refelem, nlocalmeshperprc, nprocs, myrank, fx)
Initialize an object to manage a 1D computational mesh.
subroutine, public meshbase1d_final(this)
Finalize an object to manage a 1D computational mesh.
integer, public meshbase1d_dimtypeid_x
subroutine, public meshbase1d_assigndomid(this, tileid_table, panelid_table, pi_table)
subroutine, public meshbase1d_setgeometricinfo(lcmesh)
integer, public meshbase1d_dimtypeid_xt
subroutine, public meshbase1d_setuplocaldom(lcmesh, tileid, panelid, i, nprc, dom_xmin, dom_xmax, ne, fx)
module FElib / Mesh / Base
subroutine, public meshbase_final(this)
Finalize an object to manage a computational mesh.
subroutine, public meshbase_setgeometricinfo(mesh, ndim)
subroutine, public meshbase_init(this, ndimtype, refelem, nlocalmeshperprc, nsidetile, nprocs)
Initialize an object to manage a computational mesh.
module FElib / Mesh / utility for 1D mesh
subroutine, public meshutil1d_buildinteriormap(vmapm, vmapp, mapm, mapp, pos_en, pos_ev, etoe, etof, etov, fmask, ne, np, nfp, nfaces, nv)
subroutine, public meshutil1d_genconnectivity(etoe, etof, etov, ne, nfaces)
subroutine, public meshutil1d_genpatchboundarymap(vmapb, mapb, vmapp, pos_en, xmin, xmax, fmask, ne, np, nfp, nfaces, nv)
subroutine, public meshutil1d_buildglobalmap(panelid_table, pi_table, tileid_map, tilefaceid_map, tilepanelid_map, ntile)
subroutine, public meshutil1d_genlinedomain(pos_v, etov, ke_x, xmin, xmax, fx)
Derived type representing a 1D reference element.
Derived type representing a line element.
Derived type representing a local mesh for 1D domain.
Derived type to manage a local computational domain (base type)
Derived type to manage a computational mesh (base type for 1D domain)
Base type to manage a computational mesh.