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"
30 logical :: file_exists
32 argc = command_argument_count()
34 if ((argc .lt. 9) .or. (argc .gt. 15))
then
35 write(*,*)
'Usage: ./genmeshbox x0 x1 y0 y1 z0 z1 nel_x nel_y nel_z'
36 write(*,*)
'**optional** periodic in x? (.true./.false.) y? ', &
37 '(.true./.false.) z? (.true./.false.)'
38 write(*,*)
'**optional** Point distribution in x? (fname/uniform) y? ', &
39 '(fname/uniform) z? (fname/uniform)'
41 write(*,*)
'Example command: ./genmeshbox 0 1 0 1 0 1 8 8 8 ', &
42 '.true. .true. .false.'
43 write(*,*)
'This examples generates a cube (box.nmsh) with side length ', &
44 '1 and with 8 elements in each spatial direction and periodic ', &
46 write(*,*)
'BCs for face 5,6 (z zones) can then be set by setting ', &
47 'boundary_conditions in the parameter file'
48 write(*,*)
'If you want a specific distribution of vertices in the ', &
49 'directions, give the filename where it is stored'
50 write(*,*)
'Example command: ./genmeshbox 0 1 0 1 0 1 8 8 8 ', &
51 '.false. .false. .false. uniform uniform dist.csv'
52 write(*,*)
'This example uses the vertex distribution in the z ', &
53 'direction given in dist.csv and keep the other'
54 write(*,*)
'directions uniform'
63 dist_x_fname =
'uniform'
64 dist_y_fname =
'uniform'
65 dist_z_fname =
'uniform'
67 call get_command_argument(1, inputchar)
69 call get_command_argument(2, inputchar)
71 call get_command_argument(3, inputchar)
73 call get_command_argument(4, inputchar)
75 call get_command_argument(5, inputchar)
77 call get_command_argument(6, inputchar)
79 call get_command_argument(7, inputchar)
80 read(inputchar, *) nelx
81 call get_command_argument(8, inputchar)
82 read(inputchar, *) nely
83 call get_command_argument(9, inputchar)
84 read(inputchar, *) nelz
86 call get_command_argument(10, inputchar)
87 read(inputchar, *) period_x
88 call get_command_argument(11, inputchar)
89 read(inputchar, *) period_y
90 call get_command_argument(12, inputchar)
91 read(inputchar, *) period_z
93 if (argc .gt. 12)
then
94 call get_command_argument(13, inputchar)
95 read(inputchar, *) dist_x_fname
96 call get_command_argument(14, inputchar)
97 read(inputchar, *) dist_y_fname
98 call get_command_argument(15, inputchar)
99 read(inputchar, *) dist_z_fname
103 if (pe_rank .eq. 0)
then
107 inquire(
file = trim(log_fname), exist = file_exists)
108 if (.not. file_exists)
then
110 open(newunit = log_unit,
file = trim(log_fname), status =
'new', &
112 write (log_unit,
'(A,2(F12.6," "),I4,L2)') &
113 "xmin, xmax, Nel, periodic:", x0, x1, nelx, period_x
114 write (log_unit,
'(A,2(F12.6," "),I4,L2)') &
115 "ymin, ymax, Nel, periodic:", y0, y1, nely, period_y
116 write (log_unit,
'(A,2(F12.6," "),I4,L2)') &
117 "zmin, zmax, Nel, periodic:", z0, z1, nelz, period_z
126 write(log_fname,
'(A,I1,A)')
"genmeshbox_", i,
".log"
127 else if (i .lt. 100)
then
128 write(log_fname,
'(A,I2,A)')
"genmeshbox_", i,
".log"
129 else if (i .lt. 1000)
then
130 write(log_fname,
'(A,I3,A)')
"genmeshbox_", i,
".log"
132 write(log_fname,
'(A,I4,A)')
"genmeshbox_", i,
".log"
139 call msh%init(gdim, nel)
140 call htable_pts%init( nel, gdim)
142 allocate(el_len_x(nelx), el_len_y(nely), el_len_z(nelz))
143 allocate(cumm_x(nelx+1), cumm_y(nely+1), cumm_z(nelz+1))
145 if (trim(dist_x_fname) .eq.
'uniform')
then
146 el_len_x(:) = (x1 - x0)/nelx
148 call dist_x_file%init(trim(dist_x_fname))
149 call dist_x%init(nelx+1)
150 call dist_x_file%read(dist_x)
152 el_len_x(i) = dist_x%x(i+1) - dist_x%x(i)
154 call file_free(dist_x_file)
158 if (trim(dist_y_fname) .eq.
'uniform')
then
159 el_len_y(:) = (y1 - y0)/nely
161 call dist_y_file%init(trim(dist_y_fname))
162 call dist_y%init(nely+1)
163 call dist_y_file%read(dist_y)
165 el_len_y(i) = dist_y%x(i+1) - dist_y%x(i)
167 call file_free(dist_y_file)
171 if (trim(dist_z_fname) .eq.
'uniform')
then
172 el_len_z(:) = (z1 - z0)/nelz
174 call dist_z_file%init(trim(dist_z_fname))
175 call dist_z%init(nelz+1)
176 call dist_z_file%read(dist_z)
178 el_len_z(i) = dist_z%x(i+1) - dist_z%x(i)
180 call file_free(dist_z_file)
186 cumm_x(i+1) = cumm_x(i) + el_len_x(i)
191 cumm_y(i+1) = cumm_y(i) + el_len_y(i)
196 cumm_z(i+1) = cumm_z(i) + el_len_z(i)
206 coord(1) = cumm_x(e_x + 1 + ix)
207 coord(2) = cumm_y(e_y + 1 + iy)
208 coord(3) = cumm_z(e_z + 1 + iz)
209 pt_idx = 1 + (ix + e_x) + (iy + e_y)*(nelx + 1) + &
210 (iz + e_z)*(nelx + 1)*(nely + 1)
211 call p(ix+1, iy+1, iz+1)%init(coord, pt_idx)
215 call msh%add_element(i, i, p(1,1,1), p(2,1,1),p(1,2,1),p(2,2,1),&
216 p(1,1,2), p(2,1,2), p(1,2,2), p(2,2,2))
226 e_id = 1+e_y*nelx+e_z*nely*nelx
227 if (zone_id .eq. 1)
then
228 el_idx = 1+e_y*nelx+e_z*nely*nelx
229 p_el_idx = 1+(nelx-1)+e_y*nelx+e_z*nely*nelx
231 p_el_idx = 1+e_y*nelx+e_z*nely*nelx
232 el_idx = 1+(nelx-1)+e_y*nelx+e_z*nely*nelx
235 call msh%elements(e_id)%e%facet_order(facet_ord, zone_id)
236 call msh%mark_periodic_facet(zone_id, el_idx, &
237 1+mod(zone_id,2), p_el_idx, facet_ord%x)
239 call msh%mark_labeled_facet(zone_id, el_idx, zone_id)
249 e_id = 1+e_x+e_z*nely*nelx
250 if (zone_id .eq. 3)
then
251 el_idx = 1+e_x+e_z*nely*nelx
252 p_el_idx = 1+e_x+(nely-1)*nelx+e_z*nely*nelx
254 el_idx = 1+e_x+(nely-1)*nelx+e_z*nely*nelx
255 p_el_idx = 1+e_x+e_z*nely*nelx
258 call msh%elements(e_id)%e%facet_order(facet_ord,3)
259 call msh%mark_periodic_facet(zone_id, el_idx, &
260 3+mod(zone_id,2), p_el_idx, facet_ord%x)
262 call msh%mark_labeled_facet(zone_id, el_idx, zone_id)
272 e_id = 1+e_x+e_y*nelx
273 if (zone_id .eq. 5)
then
274 el_idx = 1+e_x+e_y*nelx
275 p_el_idx = 1+e_x+e_y*nelx+(nelz-1)*nely*nelx
277 p_el_idx = 1+e_x+e_y*nelx
278 el_idx = 1+e_x+e_y*nelx+(nelz-1)*nely*nelx
281 call msh%elements(e_id)%e%facet_order(facet_ord,5)
282 call msh%mark_periodic_facet(zone_id, el_idx, &
283 5+mod(zone_id,2), p_el_idx, facet_ord%x)
285 call msh%mark_labeled_facet(zone_id, el_idx, zone_id)
296 e_id = 1+e_y*nelx+e_z*nely*nelx
297 if (zone_id .eq. 1)
then
298 el_idx = 1 + e_y*nelx + e_z*nely*nelx
299 p_el_idx = 1 + (nelx-1) + e_y*nelx + e_z*nely*nelx
301 p_el_idx = 1 + e_y*nelx + e_z*nely*nelx
302 el_idx = 1 + (nelx-1) + e_y*nelx + e_z*nely*nelx
304 call msh%create_periodic_ids(zone_id, el_idx, &
305 1+mod(zone_id,2), p_el_idx)
316 e_id = 1+e_x+e_z*nely*nelx
317 if (zone_id .eq. 3)
then
318 el_idx = 1+e_x+e_z*nely*nelx
319 p_el_idx = 1+e_x+(nely-1)*nelx+e_z*nely*nelx
321 el_idx = 1+e_x+(nely-1)*nelx+e_z*nely*nelx
322 p_el_idx = 1+e_x+e_z*nely*nelx
324 call msh%create_periodic_ids(zone_id, el_idx, &
325 3+mod(zone_id,2), p_el_idx)
335 e_id = 1+e_x+e_y*nelx
336 if (zone_id .eq. 5)
then
337 el_idx = 1+e_x+e_y*nelx
338 p_el_idx = 1+e_x+e_y*nelx+(nelz-1)*nely*nelx
340 p_el_idx = 1+e_x+e_y*nelx
341 el_idx = 1+e_x+e_y*nelx+(nelz-1)*nely*nelx
343 call msh%create_periodic_ids(zone_id, el_idx, &
344 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.