65 class(*),
target,
intent(inout) :: data
70 type(
mesh_t),
pointer :: msh
71 type(mpi_status) :: status
73 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, mpi_el_offset
74 integer :: i, j, ierr, element_offset
75 integer :: nmsh_quad_size, nmsh_hex_size, nmsh_zone_size
76 integer :: nelv, gdim, nzones, ncurves
80 character(len=LOG_SIZE) :: log_buf
82 call this%check_exists()
93 call neko_log%message(
'Reading a binary Neko file ' // this%fname)
99 call mpi_file_open(
neko_comm, trim(this%fname), &
100 mpi_mode_rdonly, mpi_info_null, fh, ierr)
103 call neko_error(
'Could not open the mesh file ' // this%fname // &
106 call mpi_file_read_all(fh, nelv, 1, mpi_integer, status, ierr)
107 call mpi_file_read_all(fh, gdim, 1, mpi_integer, status, ierr)
109 write(log_buf,1) gdim, nelv
110 1
format(
'gdim = ', i1,
', nelements =', i9)
113 if (gdim .eq. 2)
then
114 call mpi_file_close(fh, ierr)
119 nelv = dist%num_local()
120 element_offset = dist%start_idx()
122 call msh%init(gdim, nelv)
124 call neko_log%message(
'Reading elements')
126 if (msh%gdim .eq. 2)
then
127 allocate(nmsh_quad(msh%nelv))
128 mpi_offset = int(2 *
mpi_integer_size,i8) + int(element_offset,i8) * int(nmsh_quad_size,i8)
129 call mpi_file_read_at_all(fh, mpi_offset, &
133 p(j) =
point_t(nmsh_quad(i)%v(j)%v_xyz, nmsh_quad(i)%v(j)%v_idx)
136 call msh%add_element(i, p(1), p(2), p(4), p(3))
138 deallocate(nmsh_quad)
139 mpi_el_offset = int(2 *
mpi_integer_size,i8) + int(dist%num_global(),i8) * int(nmsh_quad_size,i8)
140 else if (msh%gdim .eq. 3)
then
141 allocate(nmsh_hex(msh%nelv))
142 mpi_offset = int(2 *
mpi_integer_size,i8) + int(element_offset,i8) * int(nmsh_hex_size,i8)
143 call mpi_file_read_at_all(fh, mpi_offset, &
147 p(j) =
point_t(nmsh_hex(i)%v(j)%v_xyz, nmsh_hex(i)%v(j)%v_idx)
150 call msh%add_element(i, &
151 p(1), p(2), p(4), p(3), p(5), p(6), p(8), p(7))
154 mpi_el_offset = int(2 *
mpi_integer_size,i8) + int(dist%num_global(),i8) * int(nmsh_hex_size,i8)
158 call neko_log%message(
'Reading BC/zone data')
160 mpi_offset = mpi_el_offset
161 call mpi_file_read_at_all(fh, mpi_offset, &
162 nzones, 1, mpi_integer, status, ierr)
163 if (nzones .gt. 0)
then
164 allocate(nmsh_zone(nzones))
172 call mpi_file_read_at_all(fh, mpi_offset, &
176 el_idx = nmsh_zone(i)%e
177 if (el_idx .gt. msh%offset_el .and. &
178 el_idx .le. msh%offset_el + msh%nelv)
then
179 el_idx = el_idx - msh%offset_el
180 select case(nmsh_zone(i)%type)
182 call msh%mark_wall_facet(nmsh_zone(i)%f, el_idx)
184 call msh%mark_inlet_facet(nmsh_zone(i)%f, el_idx)
186 call msh%mark_outlet_facet(nmsh_zone(i)%f, el_idx)
188 call msh%mark_sympln_facet(nmsh_zone(i)%f, el_idx)
190 call msh%mark_periodic_facet(nmsh_zone(i)%f, el_idx, &
191 nmsh_zone(i)%p_f, nmsh_zone(i)%p_e, nmsh_zone(i)%glb_pt_ids)
193 call msh%mark_outlet_normal_facet(nmsh_zone(i)%f, el_idx)
195 call msh%mark_labeled_facet(nmsh_zone(i)%f, el_idx,nmsh_zone(i)%p_f)
201 el_idx = nmsh_zone(i)%e
202 if (el_idx .gt. msh%offset_el .and. &
203 el_idx .le. msh%offset_el + msh%nelv)
then
204 el_idx = el_idx - msh%offset_el
205 select case(nmsh_zone(i)%type)
207 call msh%apply_periodic_facet(nmsh_zone(i)%f, el_idx, &
208 nmsh_zone(i)%p_f, nmsh_zone(i)%p_e, nmsh_zone(i)%glb_pt_ids)
213 deallocate(nmsh_zone)
215 call neko_log%message(
'Reading deformation data')
217 mpi_offset = mpi_el_offset + int(
mpi_integer_size,i8) + int(nzones,i8)*int(nmsh_zone_size,i8)
218 call mpi_file_read_at_all(fh, mpi_offset, &
219 ncurves, 1, mpi_integer, status, ierr)
221 if (ncurves .gt. 0)
then
223 allocate(nmsh_curve(ncurves))
224 mpi_offset = mpi_el_offset + int(2 *
mpi_integer_size,i8) + int(nzones,i8)*int(nmsh_zone_size,i8)
225 call mpi_file_read_at_all(fh, mpi_offset, &
229 el_idx = nmsh_curve(i)%e - msh%offset_el
230 if (el_idx .gt. 0 .and. &
231 el_idx .le. msh%nelv)
then
232 call msh%mark_curve_element(el_idx, &
233 nmsh_curve(i)%curve_data, nmsh_curve(i)%type)
238 deallocate(nmsh_curve)
241 call mpi_file_close(fh, ierr)
242 call neko_log%message(
'Mesh read, setting up connectivity')
245 call neko_log%message(
'Done setting up mesh and connectivity')
255 type(
mesh_t),
pointer,
intent(inout) :: msh
260 type(mpi_status) :: status
262 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, mpi_el_offset
263 integer :: i, j, ierr, element_offset, id
264 integer :: nmsh_quad_size, nmsh_hex_size, nmsh_zone_size
265 integer :: nelv, gdim, nzones, ncurves, ids(4)
269 character(len=LOG_SIZE) :: log_buf
270 real(kind=rp) :: depth = 1d0
271 real(kind=dp) :: coord(3)
279 call mpi_file_open(
neko_comm, trim(this%fname), &
280 mpi_mode_rdonly, mpi_info_null, fh, ierr)
281 call mpi_file_read_all(fh, nelv, 1, mpi_integer, status, ierr)
282 call mpi_file_read_all(fh, gdim, 1, mpi_integer, status, ierr)
284 write(log_buf,2) gdim
285 2
format(
'gdim = ', i1,
', no full 2d support, creating thin slab')
290 nelv = dist%num_local()
291 element_offset = dist%start_idx()
293 call msh%init(gdim, nelv)
295 allocate(nmsh_quad(msh%nelv))
296 mpi_offset = int(2 *
mpi_integer_size,i8) + int(element_offset,i8) * int(nmsh_quad_size,i8)
297 call mpi_file_read_at_all(fh, mpi_offset, &
301 coord = nmsh_quad(i)%v(j)%v_xyz
303 p(j) =
point_t(coord, nmsh_quad(i)%v(j)%v_idx)
306 coord = nmsh_quad(i)%v(j)%v_xyz
308 id = nmsh_quad(i)%v(j)%v_idx+msh%glb_nelv*8
312 call msh%add_element(i, &
313 p(1), p(2), p(4), p(3), p(5), p(6), p(8), p(7))
315 deallocate(nmsh_quad)
316 mpi_el_offset = int(2 *
mpi_integer_size,i8) + int(dist%num_global(),i8) * int(nmsh_quad_size,i8)
318 mpi_offset = mpi_el_offset
319 call mpi_file_read_at_all(fh, mpi_offset, &
320 nzones, 1, mpi_integer, status, ierr)
321 if (nzones .gt. 0)
then
322 allocate(nmsh_zone(nzones))
330 call mpi_file_read_at_all(fh, mpi_offset, &
334 el_idx = nmsh_zone(i)%e
335 if (el_idx .gt. msh%offset_el .and. &
336 el_idx .le. msh%offset_el + msh%nelv)
then
337 el_idx = el_idx - msh%offset_el
338 select case(nmsh_zone(i)%type)
340 call msh%mark_wall_facet(nmsh_zone(i)%f, el_idx)
342 call msh%mark_inlet_facet(nmsh_zone(i)%f, el_idx)
344 call msh%mark_outlet_facet(nmsh_zone(i)%f, el_idx)
346 call msh%mark_sympln_facet(nmsh_zone(i)%f, el_idx)
348 nmsh_zone(i)%glb_pt_ids(3) = nmsh_zone(i)%glb_pt_ids(1)+msh%glb_nelv*8
349 nmsh_zone(i)%glb_pt_ids(4) = nmsh_zone(i)%glb_pt_ids(2)+msh%glb_nelv*8
350 if (nmsh_zone(i)%f .eq. 1 .or. nmsh_zone(i)%f .eq. 2)
then
351 ids(1) = nmsh_zone(i)%glb_pt_ids(1)
352 ids(2) = nmsh_zone(i)%glb_pt_ids(3)
353 ids(3) = nmsh_zone(i)%glb_pt_ids(4)
354 ids(4) = nmsh_zone(i)%glb_pt_ids(2)
356 ids(1) = nmsh_zone(i)%glb_pt_ids(1)
357 ids(2) = nmsh_zone(i)%glb_pt_ids(2)
358 ids(3) = nmsh_zone(i)%glb_pt_ids(4)
359 ids(4) = nmsh_zone(i)%glb_pt_ids(3)
361 nmsh_zone(i)%glb_pt_ids = ids
362 call msh%mark_periodic_facet(nmsh_zone(i)%f, el_idx, &
363 nmsh_zone(i)%p_f, nmsh_zone(i)%p_e, ids)
365 call msh%mark_outlet_normal_facet(nmsh_zone(i)%f, el_idx)
367 call msh%mark_labeled_facet(nmsh_zone(i)%f, el_idx,nmsh_zone(i)%p_f)
373 el_idx = nmsh_zone(i)%e
374 if (el_idx .gt. msh%offset_el .and. &
375 el_idx .le. msh%offset_el + msh%nelv)
then
376 el_idx = el_idx - msh%offset_el
377 select case(nmsh_zone(i)%type)
379 call msh%apply_periodic_facet(nmsh_zone(i)%f, el_idx, &
380 nmsh_zone(i)%p_f, nmsh_zone(i)%p_e, nmsh_zone(i)%glb_pt_ids)
386 call msh%elements(el_idx)%e%facet_order(glb_pt_ids,5)
387 call msh%mark_periodic_facet(6, el_idx, &
388 5, el_idx, glb_pt_ids%x)
389 call msh%elements(el_idx)%e%facet_order(glb_pt_ids,5)
390 call msh%mark_periodic_facet(5, el_idx, &
391 6, el_idx, glb_pt_ids%x)
394 call msh%elements(el_idx)%e%facet_order(glb_pt_ids,5)
395 call msh%apply_periodic_facet(6, el_idx, &
396 5, el_idx, glb_pt_ids%x)
397 call msh%elements(el_idx)%e%facet_order(glb_pt_ids,5)
398 call msh%apply_periodic_facet(5, el_idx, &
399 6, el_idx, glb_pt_ids%x)
402 deallocate(nmsh_zone)
405 mpi_offset = mpi_el_offset + &
407 call mpi_file_read_at_all(fh, mpi_offset, &
408 ncurves, 1, mpi_integer, status, ierr)
410 if (ncurves .gt. 0)
then
412 allocate(nmsh_curve(ncurves))
413 mpi_offset = mpi_el_offset + &
415 call mpi_file_read_at_all(fh, mpi_offset, &
419 el_idx = nmsh_curve(i)%e - msh%offset_el
420 if (el_idx .gt. 0 .and. &
421 el_idx .le. msh%nelv)
then
422 call msh%mark_curve_element(el_idx, &
423 nmsh_curve(i)%curve_data, nmsh_curve(i)%type)
428 deallocate(nmsh_curve)
431 call mpi_file_close(fh, ierr)
443 class(*),
target,
intent(in) :: data
444 real(kind=rp),
intent(in),
optional :: t
449 type(
mesh_t),
pointer :: msh
450 type(mpi_status) :: status
452 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, mpi_el_offset
453 integer :: i, j, ierr, nelgv, element_offset, k
454 integer :: nmsh_quad_size, nmsh_hex_size, nmsh_zone_size, nmsh_curve_size
455 integer :: nzones, ncurves
457 integer(i4),
dimension(8),
parameter :: vcyc_to_sym = (/1, 2, 4, 3, 5, &
472 call mpi_reduce(msh%nelv, nelgv, 1, mpi_integer, &
475 call mpi_exscan(msh%nelv, element_offset, 1, &
478 call neko_log%message(
'Writing data as a binary Neko file ' // this%fname)
480 call mpi_file_open(
neko_comm, trim(this%fname), &
481 mpi_mode_wronly + mpi_mode_create, mpi_info_null, fh, ierr)
483 call mpi_file_write_all(fh, nelgv, 1, mpi_integer, status, ierr)
484 call mpi_file_write_all(fh, msh%gdim, 1, mpi_integer, status, ierr)
486 call msh%reset_periodic_ids()
488 if (msh%gdim .eq. 2)
then
489 allocate(nmsh_quad(msh%nelv))
491 ep => msh%elements(i)%e
492 nmsh_quad(i)%el_idx = ep%id()
494 nmsh_quad(i)%v(j)%v_idx = ep%pts(vcyc_to_sym(j))%p%id()
495 nmsh_quad(i)%v(j)%v_xyz = ep%pts(vcyc_to_sym(j))%p%x
498 mpi_offset = int(2 *
mpi_integer_size,i8) + int(element_offset,i8) * int(nmsh_quad_size,i8)
499 call mpi_file_write_at_all(fh, mpi_offset, &
501 deallocate(nmsh_quad)
502 mpi_el_offset = int(2 *
mpi_integer_size,i8) + int(nelgv,i8) * int(nmsh_quad_size,i8)
503 else if (msh%gdim .eq. 3)
then
504 allocate(nmsh_hex(msh%nelv))
506 ep => msh%elements(i)%e
507 nmsh_hex(i)%el_idx = ep%id()
509 nmsh_hex(i)%v(j)%v_idx = ep%pts(vcyc_to_sym(j))%p%id()
510 nmsh_hex(i)%v(j)%v_xyz = ep%pts(vcyc_to_sym(j))%p%x
513 mpi_offset = int(2 *
mpi_integer_size,i8) + int(element_offset,i8) * int(nmsh_hex_size,i8)
514 call mpi_file_write_at_all(fh, mpi_offset, &
518 call mpi_file_write_at_all(fh, mpi_offset, &
522 mpi_el_offset = int(2 *
mpi_integer_size,i8) + int(nelgv,i8) * int(nmsh_hex_size,i8)
527 nzones = msh%wall%size + msh%inlet%size + msh%outlet%size + &
528 msh%sympln%size + msh%periodic%size + msh%outlet_normal%size
531 nzones = nzones + msh%labeled_zones(i)%size
533 mpi_offset = mpi_el_offset
534 call mpi_file_write_at_all(fh, mpi_offset, &
535 nzones, 1, mpi_integer, status, ierr)
537 if (nzones .gt. 0)
then
538 allocate(nmsh_zone(nzones))
540 nmsh_zone(:)%type = 0
543 do i = 1, msh%wall%size
544 nmsh_zone(j)%e = msh%wall%facet_el(i)%x(2) + msh%offset_el
545 nmsh_zone(j)%f = msh%wall%facet_el(i)%x(1)
546 nmsh_zone(j)%type = 1
550 do i = 1, msh%inlet%size
551 nmsh_zone(j)%e = msh%inlet%facet_el(i)%x(2) + msh%offset_el
552 nmsh_zone(j)%f = msh%inlet%facet_el(i)%x(1)
553 nmsh_zone(j)%type = 2
557 do i = 1, msh%outlet%size
558 nmsh_zone(j)%e = msh%outlet%facet_el(i)%x(2) + msh%offset_el
559 nmsh_zone(j)%f = msh%outlet%facet_el(i)%x(1)
560 nmsh_zone(j)%type = 3
564 do i = 1, msh%sympln%size
565 nmsh_zone(j)%e = msh%sympln%facet_el(i)%x(2) + msh%offset_el
566 nmsh_zone(j)%f = msh%sympln%facet_el(i)%x(1)
567 nmsh_zone(j)%type = 4
571 do i = 1, msh%periodic%size
572 nmsh_zone(j)%e = msh%periodic%facet_el(i)%x(2) + msh%offset_el
573 nmsh_zone(j)%f = msh%periodic%facet_el(i)%x(1)
574 nmsh_zone(j)%p_e = msh%periodic%p_facet_el(i)%x(2)
575 nmsh_zone(j)%p_f = msh%periodic%p_facet_el(i)%x(1)
576 nmsh_zone(j)%glb_pt_ids = msh%periodic%p_ids(i)%x
577 nmsh_zone(j)%type = 5
580 do i = 1, msh%outlet_normal%size
581 nmsh_zone(j)%e = msh%outlet_normal%facet_el(i)%x(2) + msh%offset_el
582 nmsh_zone(j)%f = msh%outlet_normal%facet_el(i)%x(1)
583 nmsh_zone(j)%type = 6
587 do i = 1, msh%labeled_zones(k)%size
588 nmsh_zone(j)%e = msh%labeled_zones(k)%facet_el(i)%x(2) + msh%offset_el
589 nmsh_zone(j)%f = msh%labeled_zones(k)%facet_el(i)%x(1)
591 nmsh_zone(j)%type = 7
598 call mpi_file_write_at_all(fh, mpi_offset, &
601 deallocate(nmsh_zone)
604 ncurves = msh%curve%size
605 mpi_offset = mpi_el_offset + int(
mpi_integer_size,i8) + int(nzones,i8)*int(nmsh_zone_size,i8)
607 call mpi_file_write_at_all(fh, mpi_offset, &
608 ncurves, 1, mpi_integer, status, ierr)
610 if (ncurves .gt. 0)
then
611 allocate(nmsh_curve(ncurves))
613 nmsh_curve(i)%type = 0
617 nmsh_curve(i)%e = msh%curve%curve_el(i)%el_idx + msh%offset_el
618 nmsh_curve(i)%curve_data = msh%curve%curve_el(i)%curve_data
619 nmsh_curve(i)%type = msh%curve%curve_el(i)%curve_type
621 mpi_offset = mpi_el_offset + int(2*
mpi_integer_size,i8) + int(nzones,i8)*int(nmsh_zone_size,i8)
622 call mpi_file_write_at_all(fh, mpi_offset, &
625 deallocate(nmsh_curve)
628 call mpi_file_sync(fh, ierr)
629 call mpi_file_close(fh, ierr)
type(mpi_comm) neko_comm
MPI communicator.
integer pe_size
MPI size of communicator.
Defines practical data distributions.
type(log_t), public neko_log
Global log stream.
integer, parameter, public neko_msh_max_zlbls
Max num. zone labels.
type(mpi_datatype), public mpi_nmsh_hex
MPI derived type for 3D Neko nmsh data.
type(mpi_datatype), public mpi_nmsh_quad
MPI derived type for 2D Neko nmsh data.
type(mpi_datatype), public mpi_nmsh_curve
MPI derived type for Neko nmsh curved elements.
integer, public mpi_integer_size
Size of MPI type integer.
type(mpi_datatype), public mpi_nmsh_zone
MPI derived type for Neko nmsh zone data.
subroutine nmsh_file_write(this, data, t)
Write a mesh from to a binary Neko nmsh file.
subroutine nmsh_file_read(this, data)
Load a mesh from a binary Neko nmsh file.
integer, parameter max_write_nel
Specifices the maximum number of elements any rank is allowed to write (for nmsh)....
subroutine nmsh_file_read_2d(this, msh)
Load a mesh from a binary Neko nmsh file.
Load-balanced linear distribution .
Base type for an element.
Interface for Neko nmsh files.
A point in with coordinates .