CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

UDF code for water absorption in Polymer

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 30, 2019, 13:04
Exclamation UDF code for water absorption in Polymer
  #1
New Member
 
david
Join Date: Sep 2019
Posts: 9
Rep Power: 7
qkhanh189 is on a distinguished road
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)
}
}

Last edited by qkhanh189; October 1, 2019 at 19:39.
qkhanh189 is offline   Reply With Quote

Old   October 1, 2019, 04:47
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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.
AlexanderZ is offline   Reply With Quote

Old   October 1, 2019, 19:55
Default
  #3
New Member
 
david
Join Date: Sep 2019
Posts: 9
Rep Power: 7
qkhanh189 is on a distinguished road
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)
}
}
Attached Images
File Type: png 1-.PNG (5.5 KB, 22 views)
File Type: png 2-.PNG (25.3 KB, 17 views)
File Type: png 3.PNG (15.4 KB, 16 views)
qkhanh189 is offline   Reply With Quote

Old   October 15, 2019, 01:25
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
update your progress

best regards
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   November 22, 2019, 23:02
Default
  #5
New Member
 
david
Join Date: Sep 2019
Posts: 9
Rep Power: 7
qkhanh189 is on a distinguished road
I was still stuck, could anyone help me.
qkhanh189 is offline   Reply With Quote

Reply


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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling the customized UDF code for PEMFC dmfo Fluent UDF and Scheme Programming 2 October 1, 2017 19:30
UDF code help solve reaction rate equation palm oil zirkov Fluent UDF and Scheme Programming 0 February 13, 2017 11:34
write code UDF Fluent solve kinetic reaction rate equation palm oil zirkov FLUENT 0 February 13, 2017 11:16
UDF Compilation Error - Loading Library - COMMON Problem! Help! robtheslob Fluent UDF and Scheme Programming 8 July 24, 2015 01:53
error in conditional UDF code Bollonga Fluent UDF and Scheme Programming 3 October 7, 2013 13:01


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