diff --git a/17_Kelvin_Helmholtz/CASE/DATA/run.cfg b/17_Kelvin_Helmholtz/CASE/DATA/run.cfg new file mode 100644 index 0000000..89ecabe --- /dev/null +++ b/17_Kelvin_Helmholtz/CASE/DATA/run.cfg @@ -0,0 +1,5 @@ +[job_defaults] + +n_procs: 1 +n_threads: 1 + diff --git a/17_Kelvin_Helmholtz/CASE/DATA/setup.xml b/17_Kelvin_Helmholtz/CASE/DATA/setup.xml new file mode 100644 index 0000000..4cbbc69 --- /dev/null +++ b/17_Kelvin_Helmholtz/CASE/DATA/setup.xml @@ -0,0 +1,205 @@ + + + + + + + all[] + + + + + all[] + + + + 1 + + + + + + 0.1 + + + + + + + + 10 + + + 0 + 0.004 + + + + X0 + X1 + Y0 + Y1 + Z0 + Z1 + + + + + + + + + + + + + + + + + + + + + + + + + + 1.17862 + 1 + 2 + + + 0.01 + + + + + 1.83e-05 + 0.0001 + 0.0001 + + + 0 + + + + 101325 + 293.15 + + + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + + + + + + 0.1 + 25 + X0 or X1 + + 1 + 0 + 0 + + 1 + 1 + + + + + all[] + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + 1 + 0 + + + + velocity[0] = 0.; +velocity[1] = 0.; +velocity[2] = 0.; + + + + + + + + + + + + 2 + + + 1 + + + + + + + \ No newline at end of file diff --git a/17_Kelvin_Helmholtz/CASE/SRC/cs_user_initialization.cpp b/17_Kelvin_Helmholtz/CASE/SRC/cs_user_initialization.cpp new file mode 100644 index 0000000..9de0d56 --- /dev/null +++ b/17_Kelvin_Helmholtz/CASE/SRC/cs_user_initialization.cpp @@ -0,0 +1,158 @@ +/*============================================================================ + * User initialization for the Kelvin-Helmholtz instability (VOF). + * + * A shear layer between two fluid phases with a sinusoidal perturbation + * of the interface triggers the Kelvin-Helmholtz rolling vortex instability. + *============================================================================*/ + +/* code_saturne version 9.1 */ + +/* + This file is part of code_saturne, a general-purpose CFD tool. + + Copyright (C) 1998-2025 EDF S.A. + + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/*----------------------------------------------------------------------------*/ + +#include "cs_defs.h" + +/*---------------------------------------------------------------------------- + * Standard C library headers + *----------------------------------------------------------------------------*/ + +#include +#include + +#if defined(HAVE_MPI) +#include +#endif + +/*---------------------------------------------------------------------------- + * PLE library headers + *----------------------------------------------------------------------------*/ + +#include + +/*---------------------------------------------------------------------------- + * Local headers + *----------------------------------------------------------------------------*/ + +#include "cs_headers.h" + +/*----------------------------------------------------------------------------*/ + +BEGIN_C_DECLS + +/*----------------------------------------------------------------------------*/ +/*! + * \file cs_user_initialization.cpp + * + * \brief Kelvin-Helmholtz instability initialization (VOF). + */ +/*----------------------------------------------------------------------------*/ + +/*============================================================================ + * User function definitions + *============================================================================*/ + +/*----------------------------------------------------------------------------*/ +/*! + * \brief Define initial conditions for the Kelvin-Helmholtz problem. + * + * Sets a hyperbolic tangent shear velocity profile and a smoothed + * sinusoidal VOF interface between two fluid phases. + * + * \param[in, out] domain pointer to a cs_domain_t structure + */ +/*----------------------------------------------------------------------------*/ + +void +cs_user_initialization(cs_domain_t *domain) +{ + const cs_lnum_t n_cells = domain->mesh->n_cells; + + /* Do not reinitialize on restart */ + if (domain->time_step->nt_prev > 0) + return; + + /* ---- Parameters (adapt if needed) ---- */ + + const cs_real_t Lx = 1.0; /* domain length in x */ + const cs_real_t y0 = 0.5; /* mean interface position */ + const cs_real_t eps = 0.03; /* interface perturbation amplitude */ + const cs_real_t U0 = 0.5; /* shear velocity magnitude */ + const cs_real_t delta = 0.01; /* shear layer thickness */ + const cs_real_t thickness = 0.01; /* interface smoothing thickness */ + + /* ---- Get mesh coordinates (v9.x: array [n_cells][3]) ---- */ + + const cs_real_t (*cell_cen)[3] = + domain->mesh_quantities->cell_cen; + + /* ---- Get fields ---- */ + + /* Volume fraction field (VOF) */ + cs_field_t *vf = cs_field_by_name_try("void_fraction"); + if (vf == nullptr) + vf = cs_field_by_name_try("volume_fraction"); + if (vf == nullptr) + vf = cs_field_by_name_try("alpha"); + + if (vf == nullptr) + bft_error(__FILE__, __LINE__, 0, + "VOF fraction field not found (tried: void_fraction, volume_fraction, alpha)."); + + /* Velocity field */ + cs_real_t *vel = CS_F_(vel)->val; + + /* ---- Initialization loop ---- */ + + for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) { + + const cs_real_t x = cell_cen[c_id][0]; + const cs_real_t y = cell_cen[c_id][1]; + + /* 1) Wavy interface */ + const cs_real_t y_int = + y0 + eps * sin(4.0 * M_PI * x / Lx); + + /* 2) Smoothed VOF using tanh */ + const cs_real_t s = (y - y_int) / thickness; + + cs_real_t alpha = + 0.5 * (1.0 + tanh(s)); + + /* Clamp safety */ + if (alpha < 0.0) alpha = 0.0; + if (alpha > 1.0) alpha = 1.0; + + vf->val[c_id] = alpha; + + /* 3) Smooth shear velocity profile */ + const cs_real_t r = (y - y0) / delta; + + const cs_real_t u = + U0 * tanh(r); + + vel[3*c_id + 0] = u; /* u */ + vel[3*c_id + 1] = 0.0; /* v */ + vel[3*c_id + 2] = 0.0; /* w */ + } +} + +END_C_DECLS \ No newline at end of file diff --git a/17_Kelvin_Helmholtz/README.md b/17_Kelvin_Helmholtz/README.md new file mode 100644 index 0000000..73e0df1 --- /dev/null +++ b/17_Kelvin_Helmholtz/README.md @@ -0,0 +1,51 @@ +Kelvin-Helmholtz Instability +============================ + +2D Kelvin-Helmholtz instability simulated with the VOF (Volume of Fluid) +method in code_saturne. + +The instability develops at the interface between two fluid layers moving +in opposite directions. A sinusoidal perturbation of the interface grows +into the characteristic rolling vortex structures. + +Setup +----- + +- Multiphase model: VOF (Volume of Fluid) +- Turbulence: off (laminar) +- Mesh: 128 x 64 x 1 Cartesian (generated at runtime) +- Domain: [0, 1] x [0.25, 0.75] x [0, 1] +- Periodicity: x-direction +- Boundary conditions: + - x0, x1: periodic + - y0, y1: symmetry + - z0, z1: symmetry (2D) +- Time stepping: fixed dt = 0.004 s, t_final = 10 s + +Fluid properties: + +| Property | Phase 1 | Phase 2 | +|------------|---------|---------| +| Density | 1.0 | 2.0 | +| Viscosity | 1e-4 | 1e-4 | + +Initial conditions (set in `cs_user_initialization.cpp`): + +| Parameter | Value | +|------------------------------|-------------------| +| Shear velocity U0 | 0.5 m/s | +| Shear layer thickness delta | 0.01 m | +| Interface perturbation eps | 0.03 | +| Perturbation wavelength | Lx/2 (4 pi mode) | + +The velocity field is initialized with a hyperbolic tangent shear profile +and the VOF fraction with a smoothed sinusoidal interface. + +Reference +--------- + +Lord Kelvin (W. Thomson), "Hydrokinetic solutions and observations", +Phil. Mag., 42:362-377, 1871. + +H. von Helmholtz, "On discontinuous movements of fluids", +Phil. Mag., 36:337-346, 1868. diff --git a/17_Kelvin_Helmholtz/smgr.xml b/17_Kelvin_Helmholtz/smgr.xml new file mode 100644 index 0000000..c7ae855 --- /dev/null +++ b/17_Kelvin_Helmholtz/smgr.xml @@ -0,0 +1,7 @@ + + + + + + +