8 character(len=NEKO_FNAME_LEN) :: inputchar, fname =
'box.nmsh'
9 real(kind=dp) :: x0, x1
10 real(kind=dp) :: y0, y1
11 real(kind=dp) :: z0, z1
12 real(kind=dp) :: coord(3)
13 integer :: nelx, nely, nelz, nel
16 type(htable_pt_t) :: htable_pts
17 logical :: period_x, period_y, period_z
18 type(point_t) :: p(2,2,2)
19 type(tuple4_i4_t) :: facet_ord
20 integer :: argc, gdim = 3
21 integer :: el_idx, p_el_idx, pt_idx
22 integer :: i, zone_id, e_x, e_y, e_z, ix, iy, iz, e_id
23 real(kind=dp),
allocatable :: el_len_x(:), el_len_y(:), el_len_z(:)
24 real(kind=dp),
allocatable :: cumm_x(:), cumm_y(:), cumm_z(:)
25 type(vector_t) :: dist_x, dist_y, dist_z
26 type(file_t) :: dist_x_file, dist_y_file, dist_z_file
27 character(len = 80) :: dist_x_fname, dist_y_fname, dist_z_fname
28 character(len=80) :: log_fname =
"genmeshbox.log"
29 logical :: file_exists
31 argc = command_argument_count()
33 if ((argc .lt. 9) .or. (argc .gt. 15))
then
34 write(*,*)
'Usage: ./genmeshbox x0 x1 y0 y1 z0 z1 nel_x nel_y nel_z'
35 write(*,*)
'**optional** periodic in x? (.true./.false.) y? ', &
36 '(.true./.false.) z? (.true./.false.)'
37 write(*,*)
'**optional** Point distribution in x? (fname/uniform) y? ', &
38 '(fname/uniform) z? (fname/uniform)'
40 write(*,*)
'Example command: ./genmeshbox 0 1 0 1 0 1 8 8 8 ', &
41 '.true. .true. .false.'
42 write(*,*)
'This examples generates a cube (box.nmsh) with side length ', &
43 '1 and with 8 elements in each spatial direction and periodic ', &
45 write(*,*)
'BCs for face 5,6 (z zones) can then be set by setting ', &
46 'bc_labels(5), bc_labels(6) in the parameter file'
47 write(*,*)
'If you want a specific distribution of vertices in the ', &
48 'directions, give the filename where it is stored'
49 write(*,*)
'Example command: ./genmeshbox 0 1 0 1 0 1 8 8 8 ', &
50 '.false. .false. .false. uniform uniform dist.csv'
51 write(*,*)
'This example uses the vertex distribution in the z ', &
52 'direction given in dist.csv and keep the other'
53 write(*,*)
'directions uniform'
62 dist_x_fname =
'uniform'
63 dist_y_fname =
'uniform'
64 dist_z_fname =
'uniform'
66 call get_command_argument(1, inputchar)
68 call get_command_argument(2, inputchar)
70 call get_command_argument(3, inputchar)
72 call get_command_argument(4, inputchar)
74 call get_command_argument(5, inputchar)
76 call get_command_argument(6, inputchar)
78 call get_command_argument(7, inputchar)
79 read(inputchar, *) nelx
80 call get_command_argument(8, inputchar)
81 read(inputchar, *) nely
82 call get_command_argument(9, inputchar)
83 read(inputchar, *) nelz
85 call get_command_argument(10, inputchar)
86 read(inputchar, *) period_x
87 call get_command_argument(11, inputchar)
88 read(inputchar, *) period_y
89 call get_command_argument(12, inputchar)
90 read(inputchar, *) period_z
92 if (argc .gt. 12)
then
93 call get_command_argument(13, inputchar)
94 read(inputchar, *) dist_x_fname
95 call get_command_argument(14, inputchar)
96 read(inputchar, *) dist_y_fname
97 call get_command_argument(15, inputchar)
98 read(inputchar, *) dist_z_fname
102 if (pe_rank .eq. 0)
then
106 inquire(
file = trim(log_fname), exist = file_exists)
107 if (.not. file_exists)
then
109 open(unit=10,
file=trim(log_fname), status =
'new', action =
'write')
110 write (10,
'(A,2(F10.6," "),I4,L2)')
"xmin, xmax, Nel, periodic:", &
111 x0, x1, nelx, period_x
112 write (10,
'(A,2(F10.6," "),I4,L2)')
"ymin, ymax, Nel, periodic:", &
113 y0, y1, nely, period_y
114 write (10,
'(A,2(F10.6," "),I4,L2)')
"zmin, zmax, Nel, periodic:", &
115 z0, z1, nelz, period_z
124 write(log_fname,
'(A,I1,A)')
"genmeshbox_", i,
".log"
125 else if (i .lt. 100)
then
126 write(log_fname,
'(A,I2,A)')
"genmeshbox_", i,
".log"
127 else if (i .lt. 1000)
then
128 write(log_fname,
'(A,I3,A)')
"genmeshbox_", i,
".log"
130 write(log_fname,
'(A,I4,A)')
"genmeshbox_", i,
".log"
137 call msh%init(gdim, nel)
138 call htable_pts%init( nel, gdim)
140 allocate(el_len_x(nelx), el_len_y(nely), el_len_z(nelz))
141 allocate(cumm_x(nelx+1), cumm_y(nely+1), cumm_z(nelz+1))
143 if (trim(dist_x_fname) .eq.
'uniform')
then
144 el_len_x(:) = (x1 - x0)/nelx
146 dist_x_file = file_t(trim(dist_x_fname))
147 call dist_x%init(nelx+1)
148 call dist_x_file%read(dist_x)
150 el_len_x(i) = dist_x%x(i+1) - dist_x%x(i)
152 call file_free(dist_x_file)
156 if (trim(dist_y_fname) .eq.
'uniform')
then
157 el_len_y(:) = (y1 - y0)/nely
159 dist_y_file = file_t(trim(dist_y_fname))
160 call dist_y%init(nely+1)
161 call dist_y_file%read(dist_y)
163 el_len_y(i) = dist_y%x(i+1) - dist_y%x(i)
165 call file_free(dist_y_file)
169 if (trim(dist_z_fname) .eq.
'uniform')
then
170 el_len_z(:) = (z1 - z0)/nelz
172 dist_z_file = file_t(trim(dist_z_fname))
173 call dist_z%init(nelz+1)
174 call dist_z_file%read(dist_z)
176 el_len_z(i) = dist_z%x(i+1) - dist_z%x(i)
178 call file_free(dist_z_file)
184 cumm_x(i+1) = cumm_x(i) + el_len_x(i)
189 cumm_y(i+1) = cumm_y(i) + el_len_y(i)
194 cumm_z(i+1) = cumm_z(i) + el_len_z(i)
204 coord(1) = cumm_x(e_x + 1 + ix)
205 coord(2) = cumm_y(e_y + 1 + iy)
206 coord(3) = cumm_z(e_z + 1 + iz)
207 pt_idx = 1 + (ix + e_x) + (iy + e_y)*(nelx + 1) + &
208 (iz + e_z)*(nelx + 1)*(nely + 1)
209 p(ix+1, iy+1, iz+1) = point_t(coord, pt_idx)
213 call msh%add_element(i, p(1,1,1), p(2,1,1),p(1,2,1),p(2,2,1),&
214 p(1,1,2), p(2,1,2), p(1,2,2), p(2,2,2))
224 e_id = 1+e_y*nelx+e_z*nely*nelx
225 if (zone_id .eq. 1)
then
226 el_idx = 1+e_y*nelx+e_z*nely*nelx
227 p_el_idx = 1+(nelx-1)+e_y*nelx+e_z*nely*nelx
229 p_el_idx = 1+e_y*nelx+e_z*nely*nelx
230 el_idx = 1+(nelx-1)+e_y*nelx+e_z*nely*nelx
233 call msh%elements(e_id)%e%facet_order(facet_ord, zone_id)
234 call msh%mark_periodic_facet(zone_id, el_idx, &
235 1+mod(zone_id,2), p_el_idx, facet_ord%x)
237 call msh%mark_labeled_facet(zone_id, el_idx, zone_id)
247 e_id = 1+e_x+e_z*nely*nelx
248 if (zone_id .eq. 3)
then
249 el_idx = 1+e_x+e_z*nely*nelx
250 p_el_idx = 1+e_x+(nely-1)*nelx+e_z*nely*nelx
252 el_idx = 1+e_x+(nely-1)*nelx+e_z*nely*nelx
253 p_el_idx = 1+e_x+e_z*nely*nelx
256 call msh%elements(e_id)%e%facet_order(facet_ord,3)
257 call msh%mark_periodic_facet(zone_id, el_idx, &
258 3+mod(zone_id,2), p_el_idx, facet_ord%x)
260 call msh%mark_labeled_facet(zone_id, el_idx, zone_id)
270 e_id = 1+e_x+e_y*nelx
271 if (zone_id .eq. 5)
then
272 el_idx = 1+e_x+e_y*nelx
273 p_el_idx = 1+e_x+e_y*nelx+(nelz-1)*nely*nelx
275 p_el_idx = 1+e_x+e_y*nelx
276 el_idx = 1+e_x+e_y*nelx+(nelz-1)*nely*nelx
279 call msh%elements(e_id)%e%facet_order(facet_ord,5)
280 call msh%mark_periodic_facet(zone_id, el_idx, &
281 5+mod(zone_id,2), p_el_idx, facet_ord%x)
283 call msh%mark_labeled_facet(zone_id, el_idx, zone_id)
294 e_id = 1+e_y*nelx+e_z*nely*nelx
295 if (zone_id .eq. 1)
then
296 el_idx = 1 + e_y*nelx + e_z*nely*nelx
297 p_el_idx = 1 + (nelx-1) + e_y*nelx + e_z*nely*nelx
299 p_el_idx = 1 + e_y*nelx + e_z*nely*nelx
300 el_idx = 1 + (nelx-1) + e_y*nelx + e_z*nely*nelx
302 call msh%create_periodic_ids(zone_id, el_idx, &
303 1+mod(zone_id,2), p_el_idx)
314 e_id = 1+e_x+e_z*nely*nelx
315 if (zone_id .eq. 3)
then
316 el_idx = 1+e_x+e_z*nely*nelx
317 p_el_idx = 1+e_x+(nely-1)*nelx+e_z*nely*nelx
319 el_idx = 1+e_x+(nely-1)*nelx+e_z*nely*nelx
320 p_el_idx = 1+e_x+e_z*nely*nelx
322 call msh%create_periodic_ids(zone_id, el_idx, &
323 3+mod(zone_id,2), p_el_idx)
333 e_id = 1+e_x+e_y*nelx
334 if (zone_id .eq. 5)
then
335 el_idx = 1+e_x+e_y*nelx
336 p_el_idx = 1+e_x+e_y*nelx+(nelz-1)*nely*nelx
338 p_el_idx = 1+e_x+e_y*nelx
339 el_idx = 1+e_x+e_y*nelx+(nelz-1)*nely*nelx
341 call msh%create_periodic_ids(zone_id, el_idx, &
342 5+mod(zone_id,2), p_el_idx)
program genmeshbox
Simple program to generate a mesh for a box Gives some insight into how one can use built in function...
Module for file I/O operations.
subroutine neko_finalize(c)