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

Using Cell gradient Variables in UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 15, 2016, 16:25
Default Using Cell gradient Variables in UDF
  #1
New Member
 
Join Date: May 2015
Posts: 29
Rep Power: 11
avd28 is on a distinguished road
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
and
Code:
(rpsetvar 'species/save-gradients? #t)
which I have already done.

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)
}
This code compiles and loads correctly, but when I try to initialize the problem, it crashes. I realize of course that an initizlializing a gradient variable at the beginning of a solution may pose some problems. Does anyone know how to deal with this, and also how to use such variables in a solution?
avd28 is offline   Reply With Quote

Old   November 18, 2016, 10:07
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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()) { .... }
But I never tested this myself, so if you do, please tell me if which one (if any) worked.
pakk is offline   Reply With Quote

Old   March 9, 2020, 18:22
Default
  #3
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by pakk View Post
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()) { .... }
But I never tested this myself, so if you do, please tell me if which one (if any) worked.
hi i wrote a udf for getting the species mass fraction gradients by define_adjust and using the storing commands as follow:


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?
mahdi-united is offline   Reply With Quote

Old   March 9, 2020, 18:35
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
what is it?
Code:
Domain *pDomain = DOMAIN_SUB_DOMAIN(domain,P_PHASE);
you dont use pDomain in your code

try DEFINE_EXECUTE_AT_END instead of DEFINE_ADJUST
__________________
best regards


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

Old   March 10, 2020, 04:11
Default Code
  #5
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   March 10, 2020, 09:08
Default
  #6
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
what is it?
Code:
Domain *pDomain = DOMAIN_SUB_DOMAIN(domain,P_PHASE);
you dont use pDomain in your code

try DEFINE_EXECUTE_AT_END instead of DEFINE_ADJUST
hi
why do i use the DEFINE_EXECUTE_AT_END??
i want to store species mass fraction gradients.
mahdi-united is offline   Reply With Quote

Old   March 10, 2020, 09:09
Default
  #7
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
how to send my case to you?
mahdi-united is offline   Reply With Quote

Old   March 12, 2020, 20:13
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Quote:
Originally Posted by mahdi-united View Post
hi
why do i use the DEFINE_EXECUTE_AT_END??
i want to store species mass fraction gradients.
read manual first. stop wasting our time
ansys fluent customization manual
__________________
best regards


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

Old   March 14, 2020, 07:26
Default
  #9
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
hi


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?
mahdi-united is offline   Reply With Quote

Reply

Tags
define macro, fluent, fluent - udf


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
Using UDF in fuel cell addon module qwe2077 FLUENT 5 February 12, 2015 04:25
UDF to record FLUENT solver variables... mariachi FLUENT 1 February 3, 2010 23:18
accessing upstream cell - UDF bohis FLUENT 0 April 7, 2008 06:12
UDF: Density Cell Gradient Vector Macros matteo FLUENT 0 December 1, 2007 13:14
UDF variables F1, y / problem with UDF Fabian FLUENT 6 June 2, 2003 11:22


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