1# 1 "/home/runner/work/MFC/MFC/src/pre_process/m_perturbation.fpp"
13 use m_mpi_proxy !< message passing interface (mpi) module proxy
40 type(
scalar_field),
dimension(sys_size),
intent(inout) :: q_prim_vf
43 real(wp) :: perturb_alpha
51 call random_number(rand_real)
57 if ((.not. f_approx_equal(perturb_alpha, 0._wp)) .and. (.not. f_approx_equal(perturb_alpha, 1._wp)))
then
73 type(
scalar_field),
dimension(sys_size),
intent(inout) :: q_prim_vf
76 real(wp) :: perturb_alpha
85 call random_number(rand_real)
87 q_prim_vf(
mom_idx%beg)%sf(i,
j,
k) = (1._wp + rand_real)*q_prim_vf(
mom_idx%beg)%sf(i,
j,
k)
100 type(
scalar_field),
dimension(sys_size),
intent(inout) :: q_prim_vf
101 type(
integer_field),
dimension(1:num_dims, 1:2),
intent(in) :: bc_type
102 integer :: i,
j,
k,
l, q
114 (q_prim_vf(i)%sf(
j + 1, 0, 0) + q_prim_vf(i)%sf(
j - 1, 0, 0) + &
115 2._wp*q_prim_vf(i)%sf(
j, 0, 0))
118 else if (
p == 0)
then
123 (q_prim_vf(i)%sf(
j + 1,
k, 0) + q_prim_vf(i)%sf(
j - 1,
k, 0) + &
124 q_prim_vf(i)%sf(
j,
k + 1, 0) + q_prim_vf(i)%sf(
j,
k - 1, 0) + &
125 4._wp*q_prim_vf(i)%sf(
j,
k, 0))
135 (q_prim_vf(i)%sf(
j + 1,
k,
l) + q_prim_vf(i)%sf(
j - 1,
k,
l) + &
136 q_prim_vf(i)%sf(
j,
k + 1,
l) + q_prim_vf(i)%sf(
j,
k - 1,
l) + &
137 q_prim_vf(i)%sf(
j,
k,
l + 1) + q_prim_vf(i)%sf(
j,
k,
l - 1) + &
138 6._wp*q_prim_vf(i)%sf(
j,
k,
l))
162 type(
scalar_field),
dimension(sys_size),
intent(inout) :: q_prim_vf
163 real(wp) :: mag, freq, scale, vel_rsm
164 real(wp),
dimension(:, :),
allocatable :: ofs
166 real(wp) :: xl, yl, zl
168 integer :: i, j, k, l, q
189 xl = freq*(
x_cc(j) + ofs(i, 1))
190 yl = freq*(
y_cc(k) + ofs(i, 2))
194 zl = freq*(
z_cc(l) + ofs(i, 3))
200 vel_rsm = vel_rsm + q_prim_vf(
momxb + q - 1)%sf(j, k, l)**2._wp
202 vel_rsm = sqrt(vel_rsm)
204 q_prim_vf(
momxb + i - 1)%sf(j, k, l) = q_prim_vf(
momxb + i - 1)%sf(j, k, l) + &
227 xl = freq*(
x_cc(j) + ofs(i, 1))
228 yl = freq*(
y_cc(k) + ofs(i, 2))
232 zl = freq*(
z_cc(l) + ofs(i, 3))
235 q_prim_vf(
contxb + i - 1)%sf(j, k, l) = q_prim_vf(
contxb + i - 1)%sf(j, k, l) + &
236 q_prim_vf(
contxb + i - 1)%sf(j, k, l)*scale*mag
253 type(
scalar_field),
dimension(sys_size),
intent(inout) :: q_prim_vf
254 real(wp),
dimension(mixlayer_perturb_nk) :: k, Ek
255 real(wp),
dimension(3, 3) :: Rij, Lmat
256 real(wp),
dimension(3) :: velfluc, sig_tmp, sig, khat, xi
257 real(wp) :: dk, alpha, Eksum, q, uu0, phi
258 integer :: i, j, l, r, ierr
268 eksum = eksum + ek(i)
278 rij(1, 1) = 0.05_wp*uu0
279 rij(2, 2) = 0.03_wp*uu0
280 rij(3, 3) = 0.03_wp*uu0
281 rij(1, 2) = -0.02_wp*uu0
282 rij(2, 1) = rij(1, 2)
286 lmat(1, 1) = sqrt(rij(1, 1))
287 if (abs(lmat(1, 1)) < sgm_eps) lmat(1, 1) = sgm_eps
288 lmat(2, 1) = rij(2, 1)/lmat(1, 1)
289 lmat(2, 2) = sqrt(rij(2, 2) - lmat(2, 1)**2._wp)
290 if (abs(lmat(2, 2)) < sgm_eps) lmat(2, 2) = sgm_eps
291 lmat(3, 1) = rij(3, 1)/lmat(1, 1)
292 lmat(3, 2) = (rij(3, 2) - lmat(3, 1)*lmat(2, 1))/lmat(2, 2)
293 lmat(3, 3) = sqrt(rij(3, 3) - lmat(3, 1)**2._wp - lmat(3, 2)**2._wp)
304 call mpi_bcast(khat, 3, mpi_p, 0, mpi_comm_world, ierr)
305 call mpi_bcast(xi, 3, mpi_p, 0, mpi_comm_world, ierr)
306 call mpi_bcast(phi, 1, mpi_p, 0, mpi_comm_world, ierr)
311 sig_tmp = sig_tmp/sqrt(sum(sig_tmp**2._wp))
317 q = sqrt(ek(i)/eksum)
318 alpha = k(i)*(khat(1)*
x_cc(j) + khat(2)*
y_cc(r) + khat(3)*
z_cc(l)) + 2._wp*pi*phi
319 velfluc = 2._wp*q*sig*cos(alpha)
320 velfluc = matmul(lmat, velfluc)
321 q_prim_vf(
momxb)%sf(j, r, l) = q_prim_vf(
momxb)%sf(j, r, l) + velfluc(1)
322 q_prim_vf(
momxb + 1)%sf(j, r, l) = q_prim_vf(
momxb + 1)%sf(j, r, l) + velfluc(2)
323 q_prim_vf(
momxb + 2)%sf(j, r, l) = q_prim_vf(
momxb + 2)%sf(j, r, l) + velfluc(3)
333 integer,
intent(in) :: ik
334 real(wp),
intent(in) :: yloc
335 real(wp),
dimension(3),
intent(out) :: khat, xi
336 real(wp),
intent(out) :: phi
337 real(wp) :: theta, eta
338 integer :: seed, kfac, yfac
341 yfac = nint((sin(yloc) + 1._wp)*amplifier)
358 real(wp),
intent(in) :: theta, eta
360 real(wp),
dimension(3) :: vec
363 zeta = acos(2._wp*eta - 1._wp)
364 vec(1) = sin(zeta)*cos(xi)
365 vec(2) = sin(zeta)*sin(xi)
373 integer,
intent(inout) :: seed
374 real(wp),
intent(out) :: var
377 seed = mod(
modmul(seed), modulus)
378 var = seed/real(modulus, wp)
384 integer,
intent(in) :: a
388 x = (multiplier/real(modulus, wp))*a + (increment/real(modulus, wp))
389 y = nint((x - floor(x))*decimal_trim)/decimal_trim
390 val = nint(y*modulus)
Noncharacteristic and processor boundary condition application for ghost cells and buffer regions.
impure subroutine, public s_populate_variables_buffers(bc_type, q_prim_vf, pb_in, mv_in)
The purpose of this procedure is to populate the buffers of the primitive variables,...
Shared derived types for field data, patch geometry, bubble dynamics, and MPI I/O structures.
Defines global parameters for the computational domain, simulation algorithm, and initial conditions.
real(wp) perturb_flow_mag
Magnitude of perturbation with perturb_flow flag.
real(wp) mixlayer_perturb_k0
Peak wavenumber of prescribed energy spectra with mixlayer_perturb flag Default value (k0 = 0....
integer perturb_flow_fluid
Fluid to be perturbed with perturb_flow flag.
logical elliptic_smoothing
type(int_bounds_info) mom_idx
Indexes of first & last momentum eqns.
integer num_fluids
Number of different fluids present in the flow.
integer elliptic_smoothing_iters
real(wp), dimension(:), allocatable y_cc
integer proc_rank
Rank of the local processor.
integer sys_size
Number of unknowns in the system of equations.
type(simplex_noise_params) simplex_params
integer num_dims
Number of spatial dimensions.
real(wp), dimension(:), allocatable x_cc
integer mixlayer_perturb_nk
Number of Fourier modes for perturbation with mixlayer_perturb flag.
integer perturb_sph_fluid
Fluid to be perturbed with perturb_sph flag.
real(wp), dimension(num_fluids_max) fluid_rho
real(wp), dimension(:), allocatable z_cc
Locations of cell-centers (cc) in x-, y- and z-directions, respectively.
type(ic_patch_parameters), dimension(num_patches_max) patch_icpp
Database of the initial condition patch parameters (icpp) for each of the patches employed in the con...
integer e_idx
Index of total energy equation.
real(wp) mixlayer_vel_coef
Coefficient for the hyperbolic tangent streamwise velocity profile.
integer alf_idx
Index of void fraction.
Utility routines for bubble model setup, coordinate transforms, array sampling, and special functions...
pure real(wp) function, dimension(3), public f_cross(a, b)
This procedure computes the cross product of two vectors.
Broadcasts user inputs and decomposes the domain across MPI ranks for pre-processing.
Perturbs initial mean flow fields with random noise, mixing-layer instabilities, or simplex noise.
impure subroutine s_elliptic_smoothing(q_prim_vf, bc_type)
Iteratively smooths all primitive variable fields using a discrete elliptic (Laplacian) filter.
integer function modmul(a)
Computes a modular multiplication step for the linear congruential pseudo-random number generator.
impure subroutine s_perturb_sphere(q_prim_vf)
Randomly perturbs partial density fields at the interface of a spherical volume fraction region.
impure subroutine s_perturb_surrounding_flow(q_prim_vf)
Adds random noise to the velocity and void fraction of the surrounding flow field.
real(wp) function, dimension(3) f_unit_vector(theta, eta)
Generates a unit vector uniformly distributed on the sphere from two random parameters.
subroutine s_generate_random_perturbation(khat, xi, phi, ik, yloc)
Generates deterministic pseudo-random wave vector, polarization, and phase for a perturbation mode.
subroutine s_prng(var, seed)
This function generates a pseudo-random number between 0 and 1 based on linear congruential generator...
real(wp), dimension(:, :, :, :), allocatable q_prim_temp
impure subroutine s_finalize_perturbation_module()
Deallocates the temporary primitive variable array used by elliptic smoothing.
impure subroutine s_initialize_perturbation_module()
Allocates the temporary primitive variable array used by elliptic smoothing.
subroutine s_perturb_simplex(q_prim_vf)
Perturbs velocity and volume fraction fields using multi-octave simplex noise.
subroutine s_perturb_mixlayer(q_prim_vf)
This subroutine computes velocity perturbations for a temporal mixing layer with a hyperbolic tangent...
2D and 3D simplex noise generation for procedural initial condition perturbations
real(wp) function, public f_simplex2d(xin, yin)
Evaluates 2D simplex noise at the given coordinates and returns a value in [-1, 1].
real(wp) function, public f_simplex3d(xin, yin, zin)
Evaluates 3D simplex noise at the given coordinates and returns a value in [-1, 1].
Derived type annexing an integer scalar field (SF).
Derived type annexing a scalar field (SF).