Compute Div (Vorticy X velocity)


UDF needed to compute div(vorticity x velocity)
/* UDF to compute div (vorticity x velocity)
or

Grad . ( Grad x u x u )

by

William Wangard, Ph.D.
Fluent, Inc.

FLUENT does not assume liability for this UDF
*/

#include "udf.h"
#include "sg.h"

void check_uds_udm(void);

enum
{ S_WXV_0,
S_WXV_1,
S_WXV_2,
N_REQUIRED_UDS
};

enum
{
DIV_WXV,
N_REQUIRED_UDM
};


# define VORI(c,t)(C_DWDY(c,t) - C_DVDZ(c,t))
# define VORJ(c,t)(C_DUDZ(c,t) - C_DWDX(c,t))
# define VORK(c,t)(C_DVDX(c,t) - C_DUDY(c,t))


DEFINE_ADJUST(compute_div_vort_vel,d)
{

Thread* t,*t0,*t1;
cell_t c,c0,c1;
face_t f;
real N3V_VEC(z), N3V_VEC(w), N3V_VEC(u);
int ns;



check_uds_udm();


/* Cell threads */
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
/* Velocity */
ND_D(u[0], u[1], u[2], =, C_U(c,t), C_V(c,t), C_W(c,t));

/* Vorticity */
ND_D(w[0], w[1], w[2], =, VORI(c,t), VORJ(c,t), VORK(c,t));

/* Vorticity x velocity */
ND_D(z[0], z[1], z[2], =, (w[1]*u[2] - u[1]*w[2]), (w[2]*u[0] - w[0]*u[2]), (w[0]*u[1] - w[1]*u[0]));


/* Put components into UDS */
ND_D(C_UDSI(c,t,S_WXV_0), C_UDSI(c,t,S_WXV_1), C_UDSI(c,t,S_WXV_2), =, z[0], z[1], z[2]);
}
end_c_loop(c,t);
}




/* Face threads */
thread_loop_f(t,d)
{
begin_f_loop(f,t)
{

NV_S(z, =, 0.0);

c0 = F_C0(f,t);
t0 = F_C0_THREAD(f,t);

if (FLUID_THREAD_P(t->t0))
{
switch (THREAD_TYPE(t))
{

case THREAD_F_WALL:
case THREAD_F_POUTLET:
case THREAD_F_VINLET:
case THREAD_F_SYMMETRIC:

/* Velocity */
ND_D(u[0], u[1], u[2], =, F_U(f,t), F_V(f,t), F_W(f,t));

/* Vorticity */
ND_D(w[0], w[1], w[2], =, VORI(c0,t0), VORJ(c0,t0), VORK(c0,t0));

/* Vorticity x velocity */
ND_D(z[0], z[1], z[2], =, (w[1]*u[2] - u[1]*w[2]), (w[2]*u[0] - w[0]*u[2]), (w[0]*u[1] - w[1]*u[0]));
/* Put components into UDS */
ND_D(F_UDSI(f,t,S_WXV_0), F_UDSI(f,t,S_WXV_1), F_UDSI(f,t,S_WXV_2), =, z[0], z[1], z[2]);

break;

default:
break;
}



}
}
end_f_loop(f,t);
}

/* Take derivatives of UDS */
if (sg_uds)
{
for (ns = S_WXV_0; ns < S_WXV_0+3; ++ns)
{
MD_Alloc_Storage_Vars(d, SV_UDSI_RG(ns),SV_UDSI_G(ns),SV_NULL);
Scalar_Reconstruction(d, SV_UDS_I(ns), -1, SV_UDSI_RG(ns), NULL);
Scalar_Derivatives(d, SV_UDS_I(ns), -1, SV_UDSI_G(ns), SV_UDSI_RG(ns), NULL);
}
}

/* Put component of derivatives into UDM to form divergence */
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,DIV_WXV) = C_UDSI_G(c,t,S_WXV_0)[0] + C_UDSI_G(c,t,S_WXV_1)[1] + C_UDSI_G(c,t,S_WXV_2)[2];
}
end_c_loop(c,t);
}


}




void check_uds_udm(void)
{

/* Check UDSs defined */
if (sg_uds)
{
if (n_uds < N_REQUIRED_UDS)
{
Message("nERROR: You must define at least %i User-Defined Species.n", N_REQUIRED_UDS);
Internal_Error("Not enough UDSs defined.n");
}
}
else
Internal_Error("nERROR: You must define at least %i User-Defined Species.n");



/* Check UDMs defined */
if (sg_udm < N_REQUIRED_UDM)
{
Message("nERROR: You must define at least %i User-Defined Memory Locations.n", N_REQUIRED_UDM);
Internal_Error("Not enough UDMs defined.n");
}

}





Show Form
No comments yet. Be the first to add a comment!