1# 1 "/home/runner/work/MFC/MFC/src/pre_process/m_perturbation.fpp"
35 type(
scalar_field),
dimension(sys_size),
intent(inout) :: q_prim_vf
37 real(wp) :: perturb_alpha
45 call random_number(rand_real)
51 if ((.not. f_approx_equal(perturb_alpha, 0._wp)) .and. (.not. f_approx_equal(perturb_alpha, 1._wp)))
then
65 type(
scalar_field),
dimension(sys_size),
intent(inout) :: q_prim_vf
67 real(wp) :: perturb_alpha
76 call random_number(rand_real)
79 q_prim_vf(
mom_idx%beg)%sf(i,
j,
k) = (1._wp + rand_real)*q_prim_vf(
mom_idx%beg)%sf(i,
j,
k)
92 type(
scalar_field),
dimension(sys_size),
intent(inout) :: q_prim_vf
93 type(
integer_field),
dimension(1:num_dims,1:2),
intent(in) :: bc_type
94 integer :: i,
j,
k,
l, q
104 q_prim_temp(
j, 0, 0, i) = (1._wp/4._wp)*(q_prim_vf(i)%sf(
j + 1, 0, 0) + q_prim_vf(i)%sf(
j - 1, 0, &
105 & 0) + 2._wp*q_prim_vf(i)%sf(
j, 0, 0))
108 else if (
p == 0)
then
112 q_prim_temp(
j,
k, 0, i) = (1._wp/8._wp)*(q_prim_vf(i)%sf(
j + 1,
k, 0) + q_prim_vf(i)%sf(
j - 1,
k, &
113 & 0) + q_prim_vf(i)%sf(
j,
k + 1, 0) + q_prim_vf(i)%sf(
j,
k - 1, &
114 & 0) + 4._wp*q_prim_vf(i)%sf(
j,
k, 0))
123 q_prim_temp(
j,
k,
l, i) = (1._wp/12._wp)*(q_prim_vf(i)%sf(
j + 1,
k,
l) + q_prim_vf(i)%sf(
j - 1, &
124 &
k,
l) + q_prim_vf(i)%sf(
j,
k + 1,
l) + q_prim_vf(i)%sf(
j,
k - 1, &
125 &
l) + q_prim_vf(i)%sf(
j,
k,
l + 1) + q_prim_vf(i)%sf(
j,
k, &
126 &
l - 1) + 6._wp*q_prim_vf(i)%sf(
j,
k,
l))
150 type(
scalar_field),
dimension(sys_size),
intent(inout) :: q_prim_vf
151 real(wp) :: mag, freq, scale, vel_rsm
152 real(wp),
dimension(:,:),
allocatable :: ofs
154 real(wp) :: xl, yl, zl
155 integer :: i, j, k, l, q
176 xl = freq*(
x_cc(j) + ofs(i, 1))
177 yl = freq*(
y_cc(k) + ofs(i, 2))
181 zl = freq*(
z_cc(l) + ofs(i, 3))
187 vel_rsm = vel_rsm + q_prim_vf(
momxb + q - 1)%sf(j, k, l)**2._wp
189 vel_rsm = sqrt(vel_rsm)
191 q_prim_vf(
momxb + i - 1)%sf(j, k, l) = q_prim_vf(
momxb + i - 1)%sf(j, k, l) + vel_rsm*scale*mag
213 xl = freq*(
x_cc(j) + ofs(i, 1))
214 yl = freq*(
y_cc(k) + ofs(i, 2))
218 zl = freq*(
z_cc(l) + ofs(i, 3))
221 q_prim_vf(
contxb + i - 1)%sf(j, k, l) = q_prim_vf(
contxb + i - 1)%sf(j, k, &
222 & l) + q_prim_vf(
contxb + i - 1)%sf(j, k, l)*scale*mag
237 type(
scalar_field),
dimension(sys_size),
intent(inout) :: q_prim_vf
238 real(wp),
dimension(mixlayer_perturb_nk) :: k, Ek
239 real(wp),
dimension(3, 3) :: Rij, Lmat
240 real(wp),
dimension(3) :: velfluc, sig_tmp, sig, khat, xi
241 real(wp) :: dk, alpha, Eksum, q, uu0, phi
242 integer :: i, j, l, r, ierr
251 eksum = eksum + ek(i)
259 rij(1, 1) = 0.05_wp*uu0
260 rij(2, 2) = 0.03_wp*uu0
261 rij(3, 3) = 0.03_wp*uu0
262 rij(1, 2) = -0.02_wp*uu0
263 rij(2, 1) = rij(1, 2)
267 lmat(1, 1) = sqrt(rij(1, 1))
268 if (abs(lmat(1, 1)) < sgm_eps) lmat(1, 1) = sgm_eps
269 lmat(2, 1) = rij(2, 1)/lmat(1, 1)
270 lmat(2, 2) = sqrt(rij(2, 2) - lmat(2, 1)**2._wp)
271 if (abs(lmat(2, 2)) < sgm_eps) lmat(2, 2) = sgm_eps
272 lmat(3, 1) = rij(3, 1)/lmat(1, 1)
273 lmat(3, 2) = (rij(3, 2) - lmat(3, 1)*lmat(2, 1))/lmat(2, 2)
274 lmat(3, 3) = sqrt(rij(3, 3) - lmat(3, 1)**2._wp - lmat(3, 2)**2._wp)
284 call mpi_bcast(khat, 3, mpi_p, 0, mpi_comm_world, ierr)
285 call mpi_bcast(xi, 3, mpi_p, 0, mpi_comm_world, ierr)
286 call mpi_bcast(phi, 1, mpi_p, 0, mpi_comm_world, ierr)
291 sig_tmp = sig_tmp/sqrt(sum(sig_tmp**2._wp))
297 q = sqrt(ek(i)/eksum)
298 alpha = k(i)*(khat(1)*
x_cc(j) + khat(2)*
y_cc(r) + khat(3)*
z_cc(l)) + 2._wp*pi*phi
299 velfluc = 2._wp*q*sig*cos(alpha)
300 velfluc = matmul(lmat, velfluc)
301 q_prim_vf(
momxb)%sf(j, r, l) = q_prim_vf(
momxb)%sf(j, r, l) + velfluc(1)
302 q_prim_vf(
momxb + 1)%sf(j, r, l) = q_prim_vf(
momxb + 1)%sf(j, r, l) + velfluc(2)
303 q_prim_vf(
momxb + 2)%sf(j, r, l) = q_prim_vf(
momxb + 2)%sf(j, r, l) + velfluc(3)
314 integer,
intent(in) :: ik
315 real(wp),
intent(in) :: yloc
316 real(wp),
dimension(3),
intent(out) :: khat, xi
317 real(wp),
intent(out) :: phi
318 real(wp) :: theta, eta
319 integer :: seed, kfac, yfac
322 yfac = nint((sin(yloc) + 1._wp)*amplifier)
340 real(wp),
intent(in) :: theta, eta
342 real(wp),
dimension(3) :: vec
345 zeta = acos(2._wp*eta - 1._wp)
346 vec(1) = sin(zeta)*cos(xi)
347 vec(2) = sin(zeta)*sin(xi)
355 integer,
intent(inout) :: seed
356 real(wp),
intent(out) :: var
359 seed = mod(
modmul(seed), modulus)
360 var = seed/real(modulus, wp)
367 integer,
intent(in) :: a
371 x = (multiplier/real(modulus, wp))*a + (increment/real(modulus, wp))
372 y = nint((x - floor(x))*decimal_trim)/decimal_trim
373 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)
Populate the buffers of the primitive variables based on the selected boundary conditions.
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 for mixlayer perturbation (default: most unstable mode).
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 Number of cells in the x-, y- and z-coordinate directions.
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
Locations of cell-centers (cc) in x-, y- and z-directions, respectively.
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
type(ic_patch_parameters), dimension(num_patches_max) patch_icpp
IC patch parameters (max: num_patches_max).
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)
Compute 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 smooth all primitive variable fields using a discrete elliptic (Laplacian) filter.
integer function modmul(a)
Compute a modular multiplication step for the linear congruential pseudo-random number generator.
impure subroutine s_perturb_sphere(q_prim_vf)
Randomly perturb partial density fields at the interface of a spherical volume fraction region.
impure subroutine s_perturb_surrounding_flow(q_prim_vf)
Add random noise to the velocity and void fraction of the surrounding flow field.
real(wp) function, dimension(3) f_unit_vector(theta, eta)
Generate a unit vector uniformly distributed on the sphere from two random parameters.
subroutine s_generate_random_perturbation(khat, xi, phi, ik, yloc)
Generate deterministic pseudo-random wave vector, polarization, and phase for a perturbation mode.
subroutine s_prng(var, seed)
Generate a pseudo-random number between 0 and 1 using a linear congruential generator.
real(wp), dimension(:,:,:,:), allocatable q_prim_temp
impure subroutine s_finalize_perturbation_module()
Deallocate the temporary primitive variable array used by elliptic smoothing.
impure subroutine s_initialize_perturbation_module()
Allocate the temporary primitive variable array used by elliptic smoothing.
subroutine s_perturb_simplex(q_prim_vf)
Perturb velocity and volume fraction fields using multi-octave simplex noise.
subroutine s_perturb_mixlayer(q_prim_vf)
Compute velocity perturbations for a temporal mixing layer with a hyperbolic tangent mean streamwise ...
2D and 3D simplex noise generation for procedural initial condition perturbations
real(wp) function, public f_simplex2d(xin, yin)
Evaluate 2D simplex noise at the given coordinates and return a value in [-1, 1].
real(wp) function, public f_simplex3d(xin, yin, zin)
Evaluate 3D simplex noise at the given coordinates and return a value in [-1, 1].
Derived type annexing an integer scalar field (SF).
Derived type annexing a scalar field (SF).