Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
average_field_in_space.f90
Go to the documentation of this file.
1
4 use neko
5 implicit none
6
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
13 type(coef_t) :: coef
14 type(dofmap_t), target :: dof
15 type(space_t) :: xh
16 type(mesh_t) :: msh
17 type(gs_t) :: gs_h
18 type(map_1d_t) :: map_1d
19 type(map_2d_t) :: map_2d
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
29
30 argc = command_argument_count()
31
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)'
35 write(*,*) '----'
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'
38 write(*,*) '----'
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'
41 write(*,*) '----'
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'
45 end if
46 stop
47 end if
48
49 call neko_init
50
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
61
62 call mesh_file%read(msh)
63
64 call field_data%init(msh%nelv,msh%offset_el)
65 call field_file%read(field_data)
66
67 lx = field_data%lx
68 !To make sure any deformation made in the user file is passed onto here as well
69 do i = 1,msh%nelv
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))
78
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))
87
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))
96 end do
97
98 call xh%init(gll, field_data%lx, field_data%ly, field_data%lz)
99
100 call dof%init(msh, xh)
101 call gs_h%init(dof)
102 call coef%init(gs_h)
103
104 ! 1 corresponds to x, 2 to y, 3 to z
105 if (trim(hom_dir) .eq. 'x') then
106 dir = 1
107 avg_to_1d = .false.
108 else if (trim(hom_dir) .eq. 'y') then
109 dir = 2
110 avg_to_1d = .false.
111 else if (trim(hom_dir) .eq. 'z') then
112 dir = 3
113 avg_to_1d = .false.
114 else if (trim(hom_dir) .eq. 'yz') then
115 dir = 1
116 avg_to_1d = .true.
117 else if (trim(hom_dir) .eq. 'xz') then
118 dir = 2
119 avg_to_1d = .true.
120 else if (trim(hom_dir) .eq. 'xy') then
121 dir = 3
122 avg_to_1d = .true.
123 else
124 call neko_error('homogenous direction not supported')
125 end if
126 if (avg_to_1d) then
127 call map_1d%init(coef, dir, 1e-7_rp)
128 else
129 call map_2d%init(coef, dir, 1e-7_rp)
130 end if
131
132 !allocate array with pointers to all vectors in the file
133
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)
138 if (avg_to_1d) then
139 call map_1d%average_planes(avg_matrix, fields)
140 call output_file%write(avg_matrix,field_data%time)
141 ! Compute averages in 1 direction and store in a 3d field (lots of redundant data, sorry)
142 ! Should output a 2d field in principle
143 else
144 call map_2d%average(output_data,field_data)
145 call output_file%write(output_data,field_data%time)
146 end if
147 end do
148 if (pe_rank .eq. 0) write(*,*) 'Done'
149 call neko_finalize
150
151end program average_field_in_space
152
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.
Definition map_1d.f90:3
Maps a 3D dofmap to a 2D spectral element grid.
Definition map_2d.f90:3
Master module.
Definition neko.f90:34
subroutine neko_finalize(c)
Definition neko.f90:303
subroutine neko_init(c)
Definition neko.f90:130