# UDF code for water absorption in Polymer

 Register Blogs Members List Search Today's Posts Mark Forums Read September 30, 2019, 12:04 UDF code for water absorption in Polymer #1 New Member   david Join Date: Sep 2019 Posts: 9 Rep Power: 3 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); dM_y = C_UDSI_G(c,t,0); dM_z = C_UDSI_G(c,t,0); /* take gradient */ div_x = C_UDSI(c,t,1); div_y = C_UDSI(c,t,2); div_z = C_UDSI(c,t,3); /* 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) } } Last edited by qkhanh189; October 1, 2019 at 18:39.   October 1, 2019, 03:47 #2 Senior Member   Alexander Join Date: Apr 2013 Posts: 1,386 Rep Power: 20 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 likes this.   October 1, 2019, 18:55 #3
New Member

david
Join Date: Sep 2019
Posts: 9
Rep Power: 3 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
/********************************************/
{
cell_t c;
{
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;
cell_t c;
d = Get_Domain(1); /* Get the domain using Fluent utility */

/* Loop over all cell threads in the domain */
{
/* 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);
C_UDSI(c, t, 2) = C_YI_G(c, t, 0);
C_UDSI(c, t, 3) = C_YI_G(c, t, 0);
div_x = C_YI_G(c, t, 1);
div_y = C_YI_G(c, t, 2);
div_z = C_YI_G(c, t, 3);
/* 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;
real xc[ND_ND]; real time;
real M_x, M_y, M_z, M;
{
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)
}
}
Attached Images 1-.PNG (5.5 KB, 5 views) 2-.PNG (25.3 KB, 3 views) 3.PNG (15.4 KB, 5 views)   October 15, 2019, 00:25 #4 Senior Member   Alexander Join Date: Apr 2013 Posts: 1,386 Rep Power: 20 update your progress best regards __________________ best regards ****************************** press LIKE if this message helped you How to ask questions: https://www.cfd-online.com/Forums/si...tml#post612025   November 22, 2019, 22:02 #5 New Member   david Join Date: Sep 2019 Posts: 9 Rep Power: 3 I was still stuck, could anyone help me.  Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules Similar Threads Thread Thread Starter Forum Replies Last Post dmfo Fluent UDF and Scheme Programming 2 October 1, 2017 18:30 zirkov Fluent UDF and Scheme Programming 0 February 13, 2017 10:34 zirkov FLUENT 0 February 13, 2017 10:16 robtheslob Fluent UDF and Scheme Programming 8 July 24, 2015 00:53 Bollonga Fluent UDF and Scheme Programming 3 October 7, 2013 12:01

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