level 1
#include "udf.h"
#include "sg_mphase.h"
#ifndef C_VOF
#define C_VOF(c,t) C_STORAGE_R(c,t,SV_VOF_N)
#endif
DEFINE_INIT(set_phase_by_coordinates, domain)
{
cell_t c;
int cell_count = 0;
real x_min = 0.0, x_max = 1.0;
real y_min = 0.0, y_max = 1.0;
real z_min = 0.0, z_max = 1.0;
Message("Starting domain-based initialization...\n");
// 获取混合物域(通常是domain 1)
Domain *mix_domain = DOMAIN_SUPER_DOMAIN(domain);
if (mix_domain == NULL)
{
mix_domain = domain; // 如果已经是顶级域,使用当前域
}
Message("Using domain ID: %d\n", DOMAIN_ID(mix_domain));
// 遍历混合物域中的所有混合物线程
Thread *mix_thread;
thread_loop_c(mix_thread, mix_domain)
{
if (!FLUID_THREAD_P(mix_thread)) continue;
Message("Processing mixture thread ID: %d\n", THREAD_ID(mix_thread));
// 尝试获取相线程
Thread *pri_phase = THREAD_SUB_THREAD(mix_thread, 0);
Thread *sec_phase = THREAD_SUB_THREAD(mix_thread, 1);
if (pri_phase == NULL || sec_phase == NULL)
{
Message(" Cannot get phase threads - may not be multiphase\n");
continue;
}
Message(" Successfully got phase threads\n");
// 初始化区域内的单元格
int thread_cell_count = 0;
begin_c_loop(c, mix_thread)
{
real xc[ND_ND];
C_CENTROID(xc, c, mix_thread);
if (xc[0] >= x_min && xc[0] <= x_max &&
xc[1] >= y_min && xc[1] <= y_max &&
(ND_ND == 2 || (xc[2] >= z_min && xc[2] <= z_max)))
{
C_VOF(c, sec_phase) = 1.0;
C_VOF(c, pri_phase) = 0.0;
thread_cell_count++;
}
}
end_c_loop(c, mix_thread)
cell_count += thread_cell_count;
Message(" Initialized %d cells\n", thread_cell_count);
}
Message("Completed: %d cells initialized\n", cell_count);
}
2025年11月24日 10点11分

