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=20) :: fields(3)
127 call json%add(
"fields", fields)
129 call this%init_base(json,
case)
130 call this%writer%init(json,
case)
140 type(
coef_t),
intent(in) :: coef
141 integer :: il, jl, aa
142 character(len=NEKO_FNAME_LEN) :: fname_speri
155 allocate(this%eind_u(coef%msh%nelv))
156 allocate(this%eind_v(coef%msh%nelv))
157 allocate(this%eind_w(coef%msh%nelv))
158 allocate(this%sig_u(coef%msh%nelv))
159 allocate(this%sig_v(coef%msh%nelv))
160 allocate(this%sig_w(coef%msh%nelv))
163 associate(lx1 => coef%Xh%lx, ly1 => coef%Xh%ly, &
165 seri_small => this%SERI_SMALL, &
166 seri_smallr => this%SERI_SMALLR, &
167 seri_smallg => this%SERI_SMALLG, &
168 seri_smalls => this%SERI_SMALLS, &
169 seri_np => this%SERI_NP, &
170 seri_np_max => this%SERI_NP_MAX, &
171 seri_elr => this%SERI_ELR &
174 if (seri_np.gt.seri_np_max)
then
175 call neko_log%message(
'SETI_NP greater than SERI_NP_MAX')
177 il = seri_np+seri_elr
181 call neko_log%message(
'SERI_NP+SERI_ELR greater than L?1')
191 if(
allocated(this%eind_u))
then
192 deallocate(this%eind_u)
195 if(
allocated(this%eind_v))
then
196 deallocate(this%eind_v)
199 if(
allocated(this%eind_w))
then
200 deallocate(this%eind_w)
203 if(
allocated(this%sig_u))
then
204 deallocate(this%sig_u)
207 if(
allocated(this%sig_v))
then
208 deallocate(this%sig_v)
211 if(
allocated(this%sig_w))
then
212 deallocate(this%sig_w)
216 call this%speri_l%free()
225 call this%writer%free()
226 call this%free_base()
233 type(time_state_t),
intent(in) :: time
235 integer :: e, i, lx, ly, lz, nelv, n
238 call this%get_indicators(this%case%fluid%c_Xh)
240 lx = this%u_hat%Xh%lx
241 ly = this%u_hat%Xh%ly
242 lz = this%u_hat%Xh%lz
243 nelv = this%u_hat%msh%nelv
248 this%u_hat%x(i,1,1,e) = this%eind_u(e)
249 this%v_hat%x(i,1,1,e) = this%eind_v(e)
250 this%w_hat%x(i,1,1,e) = this%eind_w(e)
257 if (neko_bcknd_device .eq. 1)
then
258 call device_memcpy(this%u_hat%x, this%u_hat%x_d, lx*ly*lz*nelv, &
259 host_to_device, sync = .true.)
260 call device_memcpy(this%v_hat%x, this%v_hat%x_d, lx*ly*lz*nelv, &
261 host_to_device, sync = .true.)
262 call device_memcpy(this%w_hat%x, this%w_hat%x_d, lx*ly*lz*nelv, &
263 host_to_device, sync = .true.)
276 type(field_t),
intent(inout) :: u_hat
277 type(field_t),
intent(inout) :: u
278 type(field_t),
intent(inout) :: wk
279 type(coef_t),
intent(inout) :: coef
280 character(len=4),
intent(in) :: space
281 integer :: i, j, k, e, nxyz, nelv, n
284 nxyz = coef%Xh%lx*coef%Xh%lx*coef%Xh%lx
289 if ((neko_bcknd_hip .eq. 1) .or. (neko_bcknd_cuda .eq. 1) .or. &
290 (neko_bcknd_opencl .eq. 1))
then
291 call device_copy(wk%x_d, u%x_d, n)
293 call copy(wk%x,u%x,n)
298 call tnsr3d(u_hat%x, coef%Xh%lx, wk%x, &
299 coef%Xh%lx,coef%Xh%vinv, &
300 coef%Xh%vinvt, coef%Xh%vinvt, nelv)
302 call tnsr3d(u_hat%x, coef%Xh%lx, wk%x, &
303 coef%Xh%lx,coef%Xh%v, &
304 coef%Xh%vt, coef%Xh%vt, nelv)
308 if ((neko_bcknd_hip .eq. 1) .or. (neko_bcknd_cuda .eq. 1) .or. &
309 (neko_bcknd_opencl .eq. 1))
then
311 call device_memcpy(u_hat%x,u_hat%x_d, n, &
312 device_to_host, sync=.true.)
321 type(coef_t),
intent(inout) :: coef
331 coef%msh%nelv, coef%Xh%lx, coef%Xh%ly, coef%Xh%lz, &
334 coef%msh%nelv, coef%Xh%lx, coef%Xh%ly, coef%Xh%lz, &
337 coef%msh%nelv, coef%Xh%lx, coef%Xh%ly, coef%Xh%lz, &
346 real(kind=rp),
intent(in) :: t
349 integer lx, ly, lz, nelv
354 call this%mf_speri%write(this%speri_l,t)
369 type(coef_t),
intent(in) :: coef
374 real(kind=rp) :: eind(lnelt)
375 real(kind=rp) :: sig(lnelt)
376 real(kind=rp) :: var(lx1,ly1,lz1,lnelt)
378 real(kind=rp) :: xa(coef%Xh%lx,coef%Xh%ly,coef%Xh%lz)
379 real(kind=rp) :: xb(coef%Xh%lx,coef%Xh%ly,coef%Xh%lz)
383 call rzero(eind,lnelt)
384 call rzero(sig,lnelt)
387 call speri_var(this, eind,sig,var,lnelt,xa,xb, lx1, ly1, lz1)
402 subroutine speri_var(this, est,sig,var,nell,xa,xb,LX1,LY1,LZ1)
408 real(kind=rp) :: est(nell)
409 real(kind=rp) :: sig(nell)
410 real(kind=rp) :: var(lx1,ly1,lz1,nell)
411 real(kind=rp) :: xa(lx1,ly1,lz1)
412 real(kind=rp) :: xb(lx1,ly1,lz1)
415 integer :: il, jl, kl, ll, j_st, j_en, ii
417 real(kind=rp) :: coeff(lx1,ly1,lz1)
419 real(kind=rp) :: coef11
421 real(kind=rp) :: coefx(this%SERI_NP_MAX,ly1,lz1), &
422 coefy(this%SERI_NP_MAX,lx1,lz1), &
423 coefz(this%SERI_NP_MAX,lx1,ly1)
425 real(kind=rp) :: estx, esty, estz
427 real(kind=rp) :: sigx, sigy, sigz
428 real(kind=rp) :: third
429 parameter(third = 1.0/3.0)
435 do ii = 1, lx1*ly1*lz1
436 coeff(ii,1,1) = var(ii,1,1,il) * var(ii,1,1,il)
440 coef11 = coeff(1,1,1)
443 if (coef11.ge.this%SERI_SMALL)
then
448 j_st =
max(1,lx1-this%SERI_NP+1-this%SERI_ELR)
449 j_en =
max(1,lx1-this%SERI_ELR)
453 coefx(j_en-jl+1,kl,ll) = coeff(jl,kl,ll)
464 j_st =
max(1,ly1-this%SERI_NP+1-this%SERI_ELR)
465 j_en =
max(1,ly1-this%SERI_ELR)
469 coefy(j_en-kl+1,jl,ll) = coeff(jl,kl,ll)
480 j_st =
max(1,lz1-this%SERI_NP+1-this%SERI_ELR)
481 j_en =
max(1,lz1-this%SERI_ELR)
485 coefz(j_en-ll+1,jl,kl) = coeff(jl,kl,ll)
494 est(il) = sqrt(estx + esty + estz)
495 sig(il) = third*(sigx + sigy + sigz)
529 integer :: ix_st,ix_en,nyl,nzl
531 real(kind=rp) :: coef(this%SERI_NP_MAX,nyl,nzl)
533 real(kind=rp) :: coef11
535 real(kind=rp) :: estx, sigx
538 integer :: il, jl, kl, ll
539 integer :: nsigt, pnr, nzlt
540 real(kind=rp) :: sigt, smallr, cmin, cmax, cnm, rtmp, rtmp2, rtmp3
541 real(kind=rp) :: sumtmp(4), cffl(this%SERI_NP_MAX)
542 real(kind=rp) :: stmp, estt, clog, ctmp, cave, erlog
543 logical :: cuse(this%seri_np_max)
545 associate(seri_small => this%SERI_SMALL, &
546 seri_smallr => this%SERI_SMALLR, &
547 seri_smallg => this%SERI_SMALLG, &
548 seri_smalls => this%SERI_SMALLS, &
549 seri_np => this%SERI_NP, &
550 seri_np_max => this%SERI_NP_MAX, &
551 seri_elr => this%SERI_ELR &
558 smallr = coef11*seri_smallr
561 pnr = ix_en - ix_st +1
571 nzlt =
max(1,nzl - seri_elr)
574 rtmp3 = 1.0/(2.0*(il-1)+1.0)
575 do jl=1,nyl - seri_elr
578 cffl(1) = coef(1,jl,il)
582 cffl(kl) = coef(kl,jl,il)
583 cmin = min(cmin,cffl(kl))
584 cmax =
max(cmax,cffl(kl))
588 if((cmin.gt.0.0).and.(cmax.gt.smallr))
then
601 if ((cffl(1).lt.smallr).and. &
602 (cffl(2).lt.smallr))
then
603 if (cffl(3).lt.smallr)
then
613 if ((cffl(1)/cffl(2).lt.seri_smallg).and. &
614 (cffl(3)/cffl(4).lt.seri_smallg))
then
618 elseif ((cffl(2)/cffl(1).lt.seri_smallg).and. &
619 (cffl(4)/cffl(3).lt.seri_smallg))
then
635 rtmp =
real(ix_en-kl)
636 rtmp2 = log(cffl(kl))
637 sumtmp(1) = sumtmp(1) +rtmp2
638 sumtmp(2) = sumtmp(2) +rtmp
639 sumtmp(3) = sumtmp(3) +rtmp*rtmp
640 sumtmp(4) = sumtmp(4) +rtmp2*rtmp
642 cmin = min(cffl(kl),cmin)
647 stmp = (sumtmp(1)*sumtmp(2) - sumtmp(4)*cmax)/ &
648 (sumtmp(3)*cmax - sumtmp(2)*sumtmp(2))
655 if (stmp.lt.seri_smalls)
then
659 clog = (sumtmp(1)+stmp*sumtmp(2))/cmax
662 cave = sumtmp(1)/cmax
669 erlog = clog - stmp*
real(ix_en-kl)
670 sumtmp(1) = sumtmp(1)+ &
671 (erlog-log(cffl(kl)))**2
672 sumtmp(2) = sumtmp(2)+ &
676 rtmp = 1.0 - sumtmp(1)/sumtmp(2)
677 if (rtmp.lt.seri_smalls)
then
681 estt = ctmp/stmp*exp(-stmp*cnm)
685 estx = estx + estt/(2.0*(jl-1)+1.0)*rtmp3
694 estx = estx/(2.0*(ix_en-1)+1.0)
699 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, 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.