7 character(len=NEKO_FNAME_LEN) :: inputchar, mesh_fname, field_fname, hom_dir, output_fname
8 type(file_t) :: field_file, output_file, mesh_file
9 real(kind=rp) :: start_time, el_h, el_dim(3,3), domain_height
10 real(kind=rp),
allocatable :: temp_el(:,:,:)
11 type(fld_file_data_t) :: field_data
12 type(fld_file_data_t) :: output_data
14 type(dofmap_t),
target :: dof
20 type(vector_ptr_t),
allocatable :: fields(:), fields2d(:)
21 type(matrix_t) :: avg_matrix
22 type(vector_t) :: volume_per_gll_lvl
23 integer :: argc, i, n, lx, j, e, n_levels, dir, ierr, n_1d, tstep, k
24 logical :: avg_to_1d = .false.
25 integer :: nelv_2d, glb_nelv_2d, offset_el_2d, lxy, n_2d
26 integer,
allocatable :: idx_2d(:)
27 real(kind=rp),
pointer,
dimension(:,:,:,:) :: x_ptr, y_ptr
28 real(kind=rp) :: coord
30 argc = command_argument_count()
32 if ((argc .lt. 4) .or. (argc .gt. 4))
then
33 if (pe_rank .eq. 0)
then
34 write(*,*)
'Usage: ./average_field_in_space mesh.nmsh field.fld dir(x, y, z, xz, xy, yz) outfield.(fld,csv)'
36 write(*,*)
'Example command for avg in 1 direction: ./average_field_in_space mesh.nmsh fieldblabla.fld x outfield.fld'
37 write(*,*)
'Computes spatial average in 1 direction and saves it in outfield.fld'
39 write(*,*)
'Example command: ./average_field_in_space mesh.nmsh fieldblabla.fld xy out.csv'
40 write(*,*)
'Computes the spatial average in 2 directions directly of the field fieldblabla.nek5000 and stores in out.csv'
42 write(*,*)
'In out.csv the first col are the coords of the GLL points'
43 write(*,*)
'In columns 2-n_fields are the averages for all fields in fieldblabla.fld'
44 write(*,*)
'If averaging in 2 directions output must be .csv and for 1 direction .fld'
51 call get_command_argument(1, inputchar)
52 read(inputchar, *) mesh_fname
53 mesh_file = file_t(trim(mesh_fname))
54 call get_command_argument(2, inputchar)
55 read(inputchar, *) field_fname
56 field_file = file_t(trim(field_fname))
57 call get_command_argument(3, inputchar)
58 read(inputchar, *) hom_dir
59 call get_command_argument(4, inputchar)
60 read(inputchar, *) output_fname
62 call mesh_file%read(msh)
64 call field_data%init(msh%nelv,msh%offset_el)
65 call field_file%read(field_data)
70 msh%elements(i)%e%pts(1)%p%x(1) = field_data%x%x(linear_index(1,1,1,i,lx,lx,lx))
71 msh%elements(i)%e%pts(2)%p%x(1) = field_data%x%x(linear_index(lx,1,1,i,lx,lx,lx))
72 msh%elements(i)%e%pts(3)%p%x(1) = field_data%x%x(linear_index(1,lx,1,i,lx,lx,lx))
73 msh%elements(i)%e%pts(4)%p%x(1) = field_data%x%x(linear_index(lx,lx,1,i,lx,lx,lx))
74 msh%elements(i)%e%pts(5)%p%x(1) = field_data%x%x(linear_index(1,1,lx,i,lx,lx,lx))
75 msh%elements(i)%e%pts(6)%p%x(1) = field_data%x%x(linear_index(lx,1,lx,i,lx,lx,lx))
76 msh%elements(i)%e%pts(7)%p%x(1) = field_data%x%x(linear_index(1,lx,lx,i,lx,lx,lx))
77 msh%elements(i)%e%pts(8)%p%x(1) = field_data%x%x(linear_index(lx,lx,lx,i,lx,lx,lx))
79 msh%elements(i)%e%pts(1)%p%x(2) = field_data%y%x(linear_index(1,1,1,i,lx,lx,lx))
80 msh%elements(i)%e%pts(2)%p%x(2) = field_data%y%x(linear_index(lx,1,1,i,lx,lx,lx))
81 msh%elements(i)%e%pts(3)%p%x(2) = field_data%y%x(linear_index(1,lx,1,i,lx,lx,lx))
82 msh%elements(i)%e%pts(4)%p%x(2) = field_data%y%x(linear_index(lx,lx,1,i,lx,lx,lx))
83 msh%elements(i)%e%pts(5)%p%x(2) = field_data%y%x(linear_index(1,1,lx,i,lx,lx,lx))
84 msh%elements(i)%e%pts(6)%p%x(2) = field_data%y%x(linear_index(lx,1,lx,i,lx,lx,lx))
85 msh%elements(i)%e%pts(7)%p%x(2) = field_data%y%x(linear_index(1,lx,lx,i,lx,lx,lx))
86 msh%elements(i)%e%pts(8)%p%x(2) = field_data%y%x(linear_index(lx,lx,lx,i,lx,lx,lx))
88 msh%elements(i)%e%pts(1)%p%x(3) = field_data%z%x(linear_index(1,1,1,i,lx,lx,lx))
89 msh%elements(i)%e%pts(2)%p%x(3) = field_data%z%x(linear_index(lx,1,1,i,lx,lx,lx))
90 msh%elements(i)%e%pts(3)%p%x(3) = field_data%z%x(linear_index(1,lx,1,i,lx,lx,lx))
91 msh%elements(i)%e%pts(4)%p%x(3) = field_data%z%x(linear_index(lx,lx,1,i,lx,lx,lx))
92 msh%elements(i)%e%pts(5)%p%x(3) = field_data%z%x(linear_index(1,1,lx,i,lx,lx,lx))
93 msh%elements(i)%e%pts(6)%p%x(3) = field_data%z%x(linear_index(lx,1,lx,i,lx,lx,lx))
94 msh%elements(i)%e%pts(7)%p%x(3) = field_data%z%x(linear_index(1,lx,lx,i,lx,lx,lx))
95 msh%elements(i)%e%pts(8)%p%x(3) = field_data%z%x(linear_index(lx,lx,lx,i,lx,lx,lx))
98 call xh%init(gll, field_data%lx, field_data%ly, field_data%lz)
100 call dof%init(msh, xh)
105 if (trim(hom_dir) .eq.
'x')
then
108 else if (trim(hom_dir) .eq.
'y')
then
111 else if (trim(hom_dir) .eq.
'z')
then
114 else if (trim(hom_dir) .eq.
'yz')
then
117 else if (trim(hom_dir) .eq.
'xz')
then
120 else if (trim(hom_dir) .eq.
'xy')
then
124 call neko_error(
'homogenous direction not supported')
127 call map_1d%init(coef, dir, 1e-7_rp)
129 call map_2d%init(coef, dir, 1e-7_rp)
134 output_file = file_t(trim(output_fname))
135 do tstep = 0, field_data%meta_nsamples-1
136 if (pe_rank .eq. 0)
write(*,*)
'Averaging field:', tstep
137 if (tstep .gt. 0)
call field_file%read(field_data)
139 call map_1d%average_planes(avg_matrix, fields)
140 call output_file%write(avg_matrix,field_data%time)
144 call map_2d%average(output_data,field_data)
145 call output_file%write(output_data,field_data%time)
148 if (pe_rank .eq. 0)
write(*,*)
'Done'
program average_field_in_space
Program to sum up a field in space in a homogenous direction Martin Karp 17/02-23.
Creates a 1d GLL point map along a specified direction based on the connectivity in the mesh.
Maps a 3D dofmap to a 2D spectral element grid.
subroutine neko_finalize(c)