|
[Sponsors] |
November 15, 2016, 15:25 |
Using Cell gradient Variables in UDF
|
#1 |
New Member
Join Date: May 2015
Posts: 29
Rep Power: 11 |
Hi all,
I'm trying to simulate diffusion of a species through a boundary wall in my system. I'm trying to set a user defined species mass fraction at the walls with a UDF using the DEFINE_PROFILE function. The specified mass fraction is actually a function of the concentration gradient at the wall. Hence I need to use the cell variable macro C_YI_G, which stores the gradient at the cell wall. The usage of this variable with pressure based solver involves using 2 seperate commands Code:
set/solve/expert Code:
(rpsetvar 'species/save-gradients? #t) I'm using a parallel system and a moving mesh and have included provisions for that in the UDF as well. The UDF is as follows Code:
#include "unsteady.h" DEFINE_ON_DEMAND(save2) { #if !RP_HOST save2(); Message0("\n\n Done! \n You can check this through plotting the contours of user defined node memory (e.g. print on walls)\n"); #endif /*!RP_HOST */ } void save2() { Domain *domain; cell_t c; Thread *t; Node *v; int n; domain=Get_Domain(1); /*Store the mesh node coordinates in user-defined node memory, this data is used in the dynamic mesh*/ thread_loop_c (t,domain) { begin_c_loop (c,t) { c_node_loop (c,t,n) { v = C_NODE(c,t,n); N_UDMI(v,0) = NODE_X(v); N_UDMI(v,1) = NODE_Y(v); N_UDMI(v,2) = NODE_Z(v); } } end_c_loop (c,t) } } DEFINE_PROFILE(conc_sink,t,i) { cell_t c; face_t f; real cx; begin_c_loop(c,t) { cx = C_YI_G(c,t,i)[0]; begin_f_loop(f,t) { F_PROFILE(f,t,i) = cx*0.003; } end_f_loop(f,t) } end_c_loop(c,t) } |
|
November 18, 2016, 09:07 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 |
There is the clean but complicated solution, and the easy dirty solution.
Easy dirty: make sure that conc_sink is not called when you initialize. So unload the library before you initialize, or change the relevant boundary condition into something else, and change it back after you initialize. Clean but complicated: Add a check in your code such that the gradient is only read if you have already initialized your data. Based on the Fluent manual, I would guess one of these three formats would work: Code:
if (NNULLP(THREAD_STORAGE(t,C_YI_G))) {... } Code:
if (DATA_VALID_P(C_YI_G)) { ... } Code:
if (DATA_VALID_P()) { .... } |
|
March 9, 2020, 17:22 |
|
#3 | |
Senior Member
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6 |
Quote:
DEFINE_ADJUST(gradient, domain) { Thread *t; Thread **pt; cell_t c; Domain *pDomain = DOMAIN_SUB_DOMAIN(domain,P_PHASE); real voidx, voidy, voidz=0.0; mp_thread_loop_c (t,domain,pt) { if (FLUID_THREAD_P(t) && n_udm > 0) { Thread *tp = pt[P_PHASE]; begin_c_loop (c,t) { C_UDMI(c,t,0) = C_YI_G(c,tp,0)[0]; } end_c_loop (c,t) } } } this code compile and initialize correctly without any error but in calculating in 1st iteration appear the message "the f1 process could not be started" and fluent crashes. Where do you think the problem is? |
||
March 9, 2020, 17:35 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
what is it?
Code:
Domain *pDomain = DOMAIN_SUB_DOMAIN(domain,P_PHASE); try DEFINE_EXECUTE_AT_END instead of DEFINE_ADJUST
__________________
best regards ****************************** press LIKE if this message was helpful |
|
March 10, 2020, 03:11 |
Code
|
#5 |
Senior Member
|
The code works fine. I wrote it and tested it at my end before sharing it. The issue is with the case not with the code.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
March 10, 2020, 08:08 |
|
#6 |
Senior Member
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6 |
||
March 10, 2020, 08:09 |
|
#7 |
Senior Member
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6 |
||
March 12, 2020, 19:13 |
|
#8 | |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Quote:
ansys fluent customization manual
__________________
best regards ****************************** press LIKE if this message was helpful |
||
March 14, 2020, 06:26 |
|
#9 | |
Senior Member
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6 |
Quote:
i type this command but not work solve>set>expert reply yes to question keep memory from being freed? and (rpsetvar 'species/save-gradients? #t) how to store the species mass fraction gradients in fluent? what is the its another command? |
||
Tags |
define macro, fluent, fluent - udf |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Using UDF in fuel cell addon module | qwe2077 | FLUENT | 5 | February 12, 2015 03:25 |
UDF to record FLUENT solver variables... | mariachi | FLUENT | 1 | February 3, 2010 22:18 |
accessing upstream cell - UDF | bohis | FLUENT | 0 | April 7, 2008 05:12 |
UDF: Density Cell Gradient Vector Macros | matteo | FLUENT | 0 | December 1, 2007 12:14 |
UDF variables F1, y / problem with UDF | Fabian | FLUENT | 6 | June 2, 2003 10:22 |