CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF code for water absorption in Polymer (https://www.cfd-online.com/Forums/fluent-udf/221005-udf-code-water-absorption-polymer.html)

qkhanh189 September 30, 2019 12:04

UDF code for water absorption in Polymer
 
Hello everybody,

I am simulating the process of water absorption of polymers in water. Polymer was soaked in water for 25h, 100h, 225h, 400h, 625h, 900h, 1225h, 1600h, then polymer was removed to observe their water permeability phenomenon. Water is a stationary mass, without applied pressure, at a temperature of 65 ° C.

The mathematical model consists of the diffusion equation in three dimensions: dM/dt = D*d2M/dx2 + D*d2M/dy2 + D*d2M/dz2 where D: diffusion coefficient ( I already know this value), M: water content.

I'm try to write UDF code, but I don't know that it's correct or no?. In particular, the time steps to observe water content (25h, 100h....)?.

Thank in advance for your help!

******************************
#include "udf.h"

/* USER INPUTS */

/********************************************/

#define temp 338 /* at 65C, Initial Temperature Unit:K*/

/********************************************/
/* Defined constants */


#define g 9.81
#define M(c,t) C_UDSI(c,t,0) /* water content (concentration) */
#define D 1.72e-12 /* diffusion coefficient Unit: m^2/s */

/* Solid density (EP resin density) in kg/m3 */
#define rhos 1150
/********************************************/
DEFINE_ADJUST(adjust_UDS,domain)
{
Thread *t;
cell_t c;
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDSI(c,t,0) = C_VOF(c,t);
}
end_c_loop (c,t)
}
}
/********************************************/
/* DIFFUSION */
/********************************************/

DEFINE_DIFFUSIVITY(UDS_diffusivity, c, t, i)
{
return C_R(c,t)*1.72e-12 + C_MU_TURB(c,t)/0.7;
}

/********************************************/
/* WATER CONCENTRATION */
/********************************************/
DEFINE_ON_DEMAND(M_concentration)
{
Domain *d; /* declare domain pointer since it is not passed as an
argument to the DEFINE macro */
real time, dtime;
real M_x, M_y, M_z, dM_x, dM_y, dM_z, M, dM;
real div_x, div_y, div_z;
Thread *t;
cell_t c;
d = Get_Domain(1); /* Get the domain using Fluent utility */

/* Loop over all cell threads in the domain */
thread_loop_c(t,d)
{
/* Loop over all cells */
begin_c_loop(c,t)
{
temp = C_T(c,t);
time = CURRENT_TIME;
dtime = CURRENT_TIMESTEP;
M_x = C_UDSI(c,t,1);
M_y = C_UDSI(c,t,2);
M_z = C_UDSI(c,t,3);
dM_x = C_UDSI_G(c,t,0)[0];
dM_y = C_UDSI_G(c,t,0)[1];
dM_z = C_UDSI_G(c,t,0)[2];
/* take gradient */
div_x = C_UDSI(c,t,1)[0];
div_y = C_UDSI(c,t,2)[1];
div_z = C_UDSI(c,t,3)[2];
/* take laplacian */
laplacian = div_x + div_y +div_z;

M = C_YI(c,t,0);
dM = C_YI_G(c,t,0);

C_YI_G(c,t,0)/dtime = D*laplacian(M);

return M;
end_c_loop(c,t)

}
}
}

/********************************************/
/* TIME STEPS */
/********************************************/

DEFINE_DELTAT(mydeltat,d)
{
real time_step;
real flow_time = CURRENT_TIME;
if (flow_time < 360000)
{time_step = 270000;}
else if (flow_time < 810000)
{time_step = 720000;}
else if (flow_time < 1440000)
{time_step = 1350000;}
else if (flow_time < 2250000)
{time_step = 2160000;}
else if (flow_time < 2250000)
{time_step = 3150000;}
else if (flow_time < 3240000)
{time_step = 4320000;}
else if (flow_time < 4410000)
{time_step = 5670000;}
else{time_step = 5670000}
return time_step;
}

/********************************************/
/* INITIAL VALUE */
/********************************************/
DEFINE_INIT(myinti,domain)
{
cell_t c;
Thread *t;
real xc[ND_ND]; real time;
real M_x, M_y, M_z;
Thread_loop_c(t,domain)
{
begin_c_loop_all(c,t)
{
C_CENTROID(xc,c,t);
C_T(c,t) = 338;
if (time = 0)
M_x = M_y = M_z = 0;
else
M_x = C_UDSI(c,t,1);
M_y = C_UDSI(c,t,2);
M_z = C_UDSI(c,t,3);
}
end_c_loop_all(cc,t)
}
}

AlexanderZ October 1, 2019 03:47

compile your code, you have type errors inside your code, read log and fix them

your DEFINE_DELTAT(mydeltat,d) is confusing
time_step = 270000 is it what you really want?
else if () construction in your case should go from MAX to MIN, but in your case it is opposite

in DEFINE_INIT(myinti,domain) variable time is not defined, add time = CURRENT_TIME;

does your equation have source? but there is no source in your code

in DEFINE_ON_DEMAND macro you have
Code:

return M;
which is not working the way you want, actually you dont need this line at all,
your scalar (M(c,t)) will be defined after you execute on_demand function

best regards

qkhanh189 October 1, 2019 18:55

3 Attachment(s)
Thanks so much AlexanderZ, Could you help me some points?

I rewrite UDF after compile with ANSYS as follow, the code work fine. But I think that I didn't do the code correct:

1. See attached figure1: with DEFINE_ON_DEMAND, I use C_UDMI(c, t, 0) = D * laplacian; for equation dM/dt = D*d2M/dx2 + D*d2M/dy2 + D*d2M/dz2. But I don't know how to write DM/dt???

2. See attached figure2: finally, I want to know water absorption in polymer with time 25h, 100h, 225h, 400h, 625h, 900h, 1225h, 1600h. I use DEFINE_DELTAT (25h = 90000s, 100h=360000, then deltat = 270000s....). But i confused, I don't know how to define this.

3. See attached figure3: How can i write the boundary conditions at the surface as the figure 3???

#include "udf.h"

/* USER INPUTS */

/********************************************/

#define temp 338 /* at 65C, Initial Temperature Unit:K*/

/********************************************/
/* Defined constants */


#define g 9.81
#define M(c,t) C_UDSI(c,t,0) /* water content (concentration) */
#define D 1.72e-12 /* diffusion coefficient Unit: m^2/s */

/* Solid density (EP resin density) in kg/m3 */
#define rhos 1150
/********************************************/
DEFINE_ADJUST(adjust_UDS,domain)
{
Thread *t;
cell_t c;
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDSI(c,t,0) = C_VOF(c,t);
}
end_c_loop (c,t)
}
}
/********************************************/
/* DIFFUSION */
/********************************************/

DEFINE_DIFFUSIVITY(UDS_diffusivity, c, t, i)
{
return C_R(c,t)*1.72e-12 + C_MU_T(c,t)/0.7;
}

/********************************************/
/* WATER CONCENTRATION */
/********************************************/
DEFINE_ON_DEMAND(M_concentration)
{
Domain *d; /* declare domain pointer since it is not passed as an
argument to the DEFINE macro */
real time, dtime;
real M, dM, laplacian;
real div_x, div_y, div_z;
Thread *t;
cell_t c;
d = Get_Domain(1); /* Get the domain using Fluent utility */

/* Loop over all cell threads in the domain */
thread_loop_c(t,d)
{
/* Loop over all cells */
begin_c_loop(c,t)
{
C_T(c,t)=338;
time = CURRENT_TIME;
dtime = CURRENT_TIMESTEP;
M = C_YI(c, t, 0);

C_UDSI(c, t, 1) = C_YI_G(c, t, 0)[0];
C_UDSI(c, t, 2) = C_YI_G(c, t, 0)[1];
C_UDSI(c, t, 3) = C_YI_G(c, t, 0)[2];
/* take gradient */
div_x = C_YI_G(c, t, 1)[0];
div_y = C_YI_G(c, t, 2)[1];
div_z = C_YI_G(c, t, 3)[2];
/* take laplacian */
laplacian = div_x + div_y +div_z;

C_UDMI(c, t, 0) = D * laplacian;

end_c_loop(c,t)

}
}
}

/********************************************/
/* TIME STEPS */
/********************************************/

DEFINE_DELTAT(mydeltat,d)
{
real time_step;
real flow_time = CURRENT_TIME;
if (flow_time < 90001)
{time_step = 90000;}
else if (flow_time < 360000)
{time_step = 270000;}
else if (flow_time < 810000)
{time_step = 720000;}
else if (flow_time < 1440000)
{time_step = 1350000;}
else if (flow_time < 2250000)
{time_step = 2160000;}
else if (flow_time < 3240000)
{time_step = 3150000;}
else if (flow_time < 4410000)
{time_step = 4320000;}
else { time_step = 5670000; }
return time_step;
}

/********************************************/
/* INITIAL VALUE */
/********************************************/
DEFINE_INIT(myinti,domain)
{
cell_t c;
Thread *t;
real xc[ND_ND]; real time;
real M_x, M_y, M_z, M;
thread_loop_c(t,domain)
{
begin_c_loop_all(c,t)
{
C_CENTROID(xc,c,t);
C_T(c,t) = 338;
time = 0;
M = 0;
}
end_c_loop_all(cc,t)
}
}

AlexanderZ October 15, 2019 00:25

update your progress

best regards

qkhanh189 November 22, 2019 22:02

I was still stuck, could anyone help me.


All times are GMT -4. The time now is 16:16.