52 use json_module,
only : json_file
57 use,
intrinsic :: iso_c_binding
78 real(kind=
rp) :: seri_small = 1.e-14
80 real(kind=
rp) :: seri_smallr = 1.e-10
82 real(kind=
rp) :: seri_smallg = 1.e-5
84 real(kind=
rp) :: seri_smalls = 0.2
86 integer :: seri_np = 4
87 integer :: seri_np_max = 4
89 integer :: seri_elr = 0
91 real(kind=
rp),
allocatable :: eind_u(:), eind_v(:), eind_w(:)
93 real(kind=
rp),
allocatable :: sig_u(:), sig_v(:), sig_w(:)
117 type(json_file),
intent(inout) :: json
118 class(
case_t),
intent(inout),
target :: case
120 character(len=:),
allocatable :: name
121 character(len=20) :: fields(3)
130 call json%add(
"fields", fields)
132 call this%init_base(json,
case)
133 call this%writer%init(json,
case)
143 type(
coef_t),
intent(in) :: coef
144 integer :: il, jl, aa
145 character(len=NEKO_FNAME_LEN) :: fname_speri
158 allocate(this%eind_u(coef%msh%nelv))
159 allocate(this%eind_v(coef%msh%nelv))
160 allocate(this%eind_w(coef%msh%nelv))
161 allocate(this%sig_u(coef%msh%nelv))
162 allocate(this%sig_v(coef%msh%nelv))
163 allocate(this%sig_w(coef%msh%nelv))
166 associate(lx1 => coef%Xh%lx, ly1 => coef%Xh%ly, &
168 seri_small => this%SERI_SMALL, &
169 seri_smallr => this%SERI_SMALLR, &
170 seri_smallg => this%SERI_SMALLG, &
171 seri_smalls => this%SERI_SMALLS, &
172 seri_np => this%SERI_NP, &
173 seri_np_max => this%SERI_NP_MAX, &
174 seri_elr => this%SERI_ELR &
177 if (seri_np .gt. seri_np_max)
then
178 call neko_log%message(
'SETI_NP greater than SERI_NP_MAX')
180 il = seri_np + seri_elr
184 call neko_log%message(
'SERI_NP+SERI_ELR greater than L?1')
194 if (
allocated(this%eind_u))
then
195 deallocate(this%eind_u)
198 if (
allocated(this%eind_v))
then
199 deallocate(this%eind_v)
202 if (
allocated(this%eind_w))
then
203 deallocate(this%eind_w)
206 if (
allocated(this%sig_u))
then
207 deallocate(this%sig_u)
210 if (
allocated(this%sig_v))
then
211 deallocate(this%sig_v)
214 if (
allocated(this%sig_w))
then
215 deallocate(this%sig_w)
219 call this%speri_l%free()
228 call this%writer%free()
229 call this%free_base()
236 type(time_state_t),
intent(in) :: time
238 integer :: e, i, lx, ly, lz, nelv, n
241 call this%get_indicators(this%case%fluid%c_Xh)
243 lx = this%u_hat%Xh%lx
244 ly = this%u_hat%Xh%ly
245 lz = this%u_hat%Xh%lz
246 nelv = this%u_hat%msh%nelv
251 this%u_hat%x(i, 1, 1, e) = this%eind_u(e)
252 this%v_hat%x(i, 1, 1, e) = this%eind_v(e)
253 this%w_hat%x(i, 1, 1, e) = this%eind_w(e)
260 if (neko_bcknd_device .eq. 1)
then
261 call device_memcpy(this%u_hat%x, this%u_hat%x_d, lx*ly*lz*nelv, &
262 host_to_device, sync = .true.)
263 call device_memcpy(this%v_hat%x, this%v_hat%x_d, lx*ly*lz*nelv, &
264 host_to_device, sync = .true.)
265 call device_memcpy(this%w_hat%x, this%w_hat%x_d, lx*ly*lz*nelv, &
266 host_to_device, sync = .true.)
280 type(field_t),
intent(inout) :: u_hat
281 type(field_t),
intent(inout) :: u
282 type(field_t),
intent(inout) :: wk
283 type(coef_t),
intent(inout) :: coef
284 character(len=4),
intent(in) :: space
285 integer :: i, j, k, e, nxyz, nelv, n
288 nxyz = coef%Xh%lx * coef%Xh%lx * coef%Xh%lx
293 if ((neko_bcknd_hip .eq. 1) .or. (neko_bcknd_cuda .eq. 1) .or. &
294 (neko_bcknd_opencl .eq. 1))
then
295 call device_copy(wk%x_d, u%x_d, n)
297 call copy(wk%x, u%x, n)
302 call tnsr3d(u_hat%x, coef%Xh%lx, wk%x, &
303 coef%Xh%lx, coef%Xh%vinv, &
304 coef%Xh%vinvt, coef%Xh%vinvt, nelv)
306 call tnsr3d(u_hat%x, coef%Xh%lx, wk%x, &
307 coef%Xh%lx, coef%Xh%v, &
308 coef%Xh%vt, coef%Xh%vt, nelv)
312 if ((neko_bcknd_hip .eq. 1) .or. (neko_bcknd_cuda .eq. 1) .or. &
313 (neko_bcknd_opencl .eq. 1))
then
315 call device_memcpy(u_hat%x, u_hat%x_d, n, &
316 device_to_host, sync = .true.)
325 type(coef_t),
intent(inout) :: coef
335 coef%msh%nelv, coef%Xh%lx, coef%Xh%ly, coef%Xh%lz, &
338 coef%msh%nelv, coef%Xh%lx, coef%Xh%ly, coef%Xh%lz, &
341 coef%msh%nelv, coef%Xh%lx, coef%Xh%ly, coef%Xh%lz, &
350 real(kind=rp),
intent(in) :: t
353 integer lx, ly, lz, nelv
358 call this%mf_speri%write(this%speri_l, t)
374 type(coef_t),
intent(in) :: coef
379 real(kind=rp) :: eind(lnelt)
380 real(kind=rp) :: sig(lnelt)
381 real(kind=rp) :: var(lx1, ly1, lz1, lnelt)
383 real(kind=rp) :: xa(coef%Xh%lx, coef%Xh%ly, coef%Xh%lz)
384 real(kind=rp) :: xb(coef%Xh%lx, coef%Xh%ly, coef%Xh%lz)
388 call rzero(eind, lnelt)
389 call rzero(sig, lnelt)
392 call speri_var(this, eind, sig, var, lnelt, xa, xb, lx1, ly1, lz1)
407 subroutine speri_var(this, est, sig, var, nell, xa, xb, LX1, LY1, LZ1)
413 real(kind=rp) :: est(nell)
414 real(kind=rp) :: sig(nell)
415 real(kind=rp) :: var(lx1, ly1, lz1, nell)
416 real(kind=rp) :: xa(lx1, ly1, lz1)
417 real(kind=rp) :: xb(lx1, ly1, lz1)
420 integer :: il, jl, kl, ll, j_st, j_en, ii
422 real(kind=rp) :: coeff(lx1, ly1, lz1)
424 real(kind=rp) :: coef11
426 real(kind=rp) :: coefx(this%SERI_NP_MAX, ly1, lz1), &
427 coefy(this%SERI_NP_MAX, lx1, lz1), &
428 coefz(this%SERI_NP_MAX, lx1, ly1)
430 real(kind=rp) :: estx, esty, estz
432 real(kind=rp) :: sigx, sigy, sigz
433 real(kind=rp) :: third
434 parameter(third = 1.0/3.0)
440 do ii = 1, lx1*ly1*lz1
441 coeff(ii, 1, 1) = var(ii, 1, 1, il) * var(ii, 1, 1, il)
445 coef11 = coeff(1, 1, 1)
448 if (coef11 .ge. this%SERI_SMALL)
then
453 j_st =
max(1, lx1 - this%SERI_NP + 1 - this%SERI_ELR)
454 j_en =
max(1, lx1 - this%SERI_ELR)
458 coefx(j_en - jl + 1, kl, ll) = coeff(jl, kl, ll)
464 j_st, j_en, ly1, lz1)
469 j_st =
max(1, ly1 - this%SERI_NP + 1 - this%SERI_ELR)
470 j_en =
max(1, ly1 - this%SERI_ELR)
474 coefy(j_en - kl + 1, jl, ll) = coeff(jl, kl, ll)
480 j_st, j_en, lx1, lz1)
485 j_st =
max(1, lz1 - this%SERI_NP + 1 - this%SERI_ELR)
486 j_en =
max(1, lz1 - this%SERI_ELR)
490 coefz(j_en - ll + 1, jl, kl) = coeff(jl, kl, ll)
496 j_st, j_en, lx1, ly1)
499 est(il) = sqrt(estx + esty + estz)
500 sig(il) = third*(sigx + sigy + sigz)
530 ix_st, ix_en, nyl, nzl)
534 integer :: ix_st, ix_en, nyl, nzl
536 real(kind=rp) :: coef(this%SERI_NP_MAX, nyl, nzl)
538 real(kind=rp) :: coef11
540 real(kind=rp) :: estx, sigx
543 integer :: il, jl, kl, ll
544 integer :: nsigt, pnr, nzlt
545 real(kind=rp) :: sigt, smallr, cmin, cmax, cnm, rtmp, rtmp2, rtmp3
546 real(kind=rp) :: sumtmp(4), cffl(this%SERI_NP_MAX)
547 real(kind=rp) :: stmp, estt, clog, ctmp, cave, erlog
548 logical :: cuse(this%seri_np_max)
550 associate(seri_small => this%SERI_SMALL, &
551 seri_smallr => this%SERI_SMALLR, &
552 seri_smallg => this%SERI_SMALLG, &
553 seri_smalls => this%SERI_SMALLS, &
554 seri_np => this%SERI_NP, &
555 seri_np_max => this%SERI_NP_MAX, &
556 seri_elr => this%SERI_ELR &
563 smallr = coef11*seri_smallr
566 pnr = ix_en - ix_st + 1
576 nzlt =
max(1, nzl - seri_elr)
579 rtmp3 = 1.0/(2.0*(il - 1) + 1.0)
580 do jl = 1, nyl - seri_elr
583 cffl(1) = coef(1, jl, il)
587 cffl(kl) = coef(kl, jl, il)
588 cmin = min(cmin, cffl(kl))
589 cmax =
max(cmax, cffl(kl))
593 if ((cmin .gt. 0.0) .and. (cmax .gt. smallr))
then
606 if ((cffl(1) .lt. smallr) .and. &
607 (cffl(2) .lt. smallr))
then
608 if (cffl(3) .lt. smallr)
then
611 cnm =
real(ix_en - 2)
614 cnm =
real(ix_en - 1)
618 if ((cffl(1)/cffl(2) .lt. seri_smallg) .and. &
619 (cffl(3)/cffl(4) .lt. seri_smallg))
then
622 cnm =
real(ix_en - 1)
623 elseif ((cffl(2)/cffl(1) .lt. seri_smallg) .and. &
624 (cffl(4)/cffl(3) .lt. seri_smallg))
then
640 rtmp =
real(ix_en - kl)
641 rtmp2 = log(cffl(kl))
642 sumtmp(1) = sumtmp(1) + rtmp2
643 sumtmp(2) = sumtmp(2) + rtmp
644 sumtmp(3) = sumtmp(3) + rtmp*rtmp
645 sumtmp(4) = sumtmp(4) + rtmp2*rtmp
647 cmin = min(cffl(kl), cmin)
652 stmp = (sumtmp(1)*sumtmp(2) - sumtmp(4)*cmax)/ &
653 (sumtmp(3)*cmax - sumtmp(2)*sumtmp(2))
660 if (stmp .lt. seri_smalls)
then
664 clog = (sumtmp(1)+stmp*sumtmp(2))/cmax
667 cave = sumtmp(1)/cmax
675 erlog = clog - stmp*
real(ix_en - kl)
676 sumtmp(1) = sumtmp(1) + &
677 (erlog - log(cffl(kl)))**2
678 sumtmp(2) = sumtmp(2) + &
682 rtmp = 1.0 - sumtmp(1)/sumtmp(2)
683 if (rtmp .lt. seri_smalls)
then
687 estt = ctmp/stmp*exp(-stmp*cnm)
691 estx = estx + estt/(2.0*(jl - 1) + 1.0)*rtmp3
700 estx = estx/(2.0*(ix_en - 1) + 1.0)
704 if (nsigt .gt. 0)
then
705 sigx = 0.5*sigt/nsigt
Copy data between host and device (or device and device)
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
Defines a simulation case.
integer, public pe_rank
MPI rank.
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
Device abstraction, common interface for various accelerators.
integer, parameter, public host_to_device
integer, parameter, public device_to_host
Implements the field_writer_t type.
Module for file I/O operations.
subroutine file_free(this)
File operation destructor.
Utilities for retrieving parameters from the case files.
type(log_t), public neko_log
Global log stream.
subroutine, public copy(a, b, n)
Copy a vector .
subroutine, public rzero(a, n)
Zero a real vector.
integer, parameter neko_bcknd_hip
integer, parameter neko_bcknd_device
integer, parameter neko_bcknd_opencl
integer, parameter neko_bcknd_cuda
integer, parameter, public rp
Global precision used in computations.
Defines a registry for storing solution fields.
type(registry_t), target, public neko_registry
Global field registry.
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
subroutine compute_(this, time)
Dummy compute function.
Defines a function space.
Implements type spectral_error_t.
subroutine speri_extrap(this, estx, sigx, coef11, coef, ix_st, ix_en, nyl, nzl)
Extrapolate the Legendre spectrum from the last points.
subroutine spectral_error_write(this, t)
Write error indicators in a field file.
subroutine spectral_error_free(this)
Destructor.
subroutine spectral_error_get_indicators(this, coef)
Transform and get the spectral error indicators.
subroutine spectral_error_init_from_components(this, coef)
Actual constructor.
subroutine spectral_error_init(this, json, case)
Constructor.
subroutine spectral_error_compute(this, time)
Compute the spectral error indicator.
subroutine speri_var(this, est, sig, var, nell, xa, xb, lx1, ly1, lz1)
Calculate the indicator in a specified variable.
subroutine calculate_indicators(this, coef, eind, sig, lnelt, lx1, ly1, lz1, var)
Wrapper for old fortran 77 subroutines.
subroutine transform_to_spec_or_phys(u_hat, u, wk, coef, space)
Transform a field u to u_hat into physical or spectral space the result of the transformation is in u...
subroutine, public tnsr3d(v, nv, u, nu, a, bt, ct, nelv)
Tensor product performed on nelv elements.
Module with things related to the simulation time.
integer, parameter, public neko_fname_len
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
field_list_t, To be able to group fields together
A simulation component that writes a 3d field to a file.
A wrapper around a polymorphic generic_file_t that handles its init. This is essentially a factory fo...
Base abstract class for simulation components.
Provides tools to calculate the spectral error indicator.
A struct that contains all info about the time, expand as needed.