Cell Wall Distance in UDF: C_WALL_DIST, Fill_Cell_Wall_Distance, don't always work.


The cell wall distance is needed in a UDF for a laminar case.
Here, the default tools in FLUENT's UDF interface (like C_WALL_DIST(c,t)) don't work, because FLUENT doesn't calculated these values itself.
A solution is available by the attached on-demand UDF that calculates the values and stores them in a specified UDM.
This has been tested in on particular case only -- no guarantee is given for this to work!

There are two different routines for calculating the cell wall distance.
The "normal" one calculates the distance between the cell center and the nearest wall NODE, while the alternative one calculates the distance between the cell center and the nearest wall face centroid.


#define USE_UDM 0

#include "udf.h"
#include "prox.h"

void
cpySVartoUDM(Domain *domain, Svar sv, int udm)
{
size_t realsize = sizeof(real);
real *svpointr = NULL;
real *udmpoint = NULL;
Thread *thread = NULL;
Domain *supdom = DOMAIN_SUPER_DOMAIN(domain);
if (NULLP(supdom))
{
supdom = domain;
}

if (sg_udm <= udm)
{
Error("cpySVartoUDM(): too few User Defined Memory Locations.n"
"Location %d was requested, but there are only %d allocated.n",
udm, sg_udm);
}

thread_loop_c(thread, domain)
{
Thread *supthr = THREAD_SUPER_THREAD(thread);
if (NULLP(supthr))
{
supthr = thread;
}

if (NNULLP(svpointr = THREAD_STORAGE(thread, sv)) &&
(NNULLP(THREAD_STORAGE(supthr, SV_UDM_I)) ?
NNULLP(udmpoint = T_STORAGE_R_XV(supthr, SV_UDM_I, udm)) : FALSE))
{
int numbytes = realsize * thread->nelements;
memcpy(udmpoint, svpointr, numbytes);
}
}
}


DEFINE_ON_DEMAND(ondmd_cwdtoudm0)
{
Domain *dom = Get_Domain(1);
Thread *thr = NULL;
Alloc_Storage_Vars(dom, SV_RTMP_0, SV_NULL);
Calc_Cell_Wall_Distance(dom, SV_RTMP_0);
cpySVartoUDM(dom, SV_RTMP_0, USE_UDM);
Free_Storage_Vars(dom, SV_RTMP_0, SV_NULL);
}


DEFINE_ON_DEMAND(ondmd_acwdtoudm0)
{
Domain *dom = Get_Domain(1);
Thread *thr = NULL;
Alloc_Storage_Vars(dom, SV_RTMP_0, SV_NULL);
Calc_Cell_Wall_Distance_Alternative(dom, SV_RTMP_0);
cpySVartoUDM(dom, SV_RTMP_0, USE_UDM);
Free_Storage_Vars(dom, SV_RTMP_0, SV_NULL);
}





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