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

UDF code problem about total value

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   January 9, 2012, 02:51
Default UDF code problem about total value
  #1
New Member
 
Yu-Pei Chen
Join Date: Jun 2011
Posts: 26
Rep Power: 6
ypchen is on a distinguished road
Hi, everybody, here is my code :

Code:
#include "udf.h"
#include "mem.h"
#include "math.h"
#include "stdio.h"
#define mass_alloy 0.295
 
DEFINE_ADJUST(adj_UDS,d)
{
 cell_t c ;
 Thread *t;
 real H_M,mass,sum ;
 thread_loop_c(t,d)
 {
  begin_c_loop(c,t)
  {
  mass= (C_UDSI(c,t,0)-8238)*C_VOLUME(c,t)*3.14159;
  H_M = (mass/mass_alloy)*432.4;
  C_UDMI(c,t,0) = H_M ;
  sum += sum C_UDMI(c,t,0) ;
  }
  end_c_loop(c,t)
 }
}
where C_UDSI(c,t,0) represent the value calculated by UDS, and I wanna get the total scalar for H_M in every cell. My case is transient and It can work, but the result seems the summation did not work. My question is if the summation can't be used in DEFINE_ADJUST macro or another method can be appied to calcuate summation.

Thanks.
ypchen is offline   Reply With Quote

Old   January 9, 2012, 04:36
Default
  #2
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 739
Blog Entries: 1
Rep Power: 14
Amir is on a distinguished road
Hi,

First of all the summation command is something like this:
Quote:
sum += C_UDMI(c,t,0);
Also you have to initialize the parameter "sum" in this macro:
Quote:
real sum =0.0;
Using this macro is reasonable but you can also use "custom field function" for your purpose without using any UDF.

Bests,
__________________
Amir
Amir is offline   Reply With Quote

Old   January 9, 2012, 08:42
Default
  #3
New Member
 
Yu-Pei Chen
Join Date: Jun 2011
Posts: 26
Rep Power: 6
ypchen is on a distinguished road
Hi, Amir,

the reason that I calculate "sum" is I should use the value to calculate "p_eq" as following :
Code:
#include "udf.h"
#include "mem.h"
#include "math.h"
#include "stdio.h"
#define A 18.3
#define B 3704.6
#define a 0.0819
#define b 330
 
DEFINE_ADJUST(adj_peq,d)
{
 cell_t c ;
 Thread *t
real tem ;
thread_loop_c(t,d)
 {
 
  begin_c_loop(c,t)
  {
  tem = C_T(c,t);
  if(sum<1.2972)
  {
  p_eq = 1000*exp((a*1.2972-(B/tem)+A)*(1-((sum-1.2972)*(sum-1.2972))/1.6827));
  }
  if(1.2972 <= sum <= 4.7564)
  {
  p_eq = 1000*exp((a*sum)-(B/tem)+A) ;
  }
  if(sum> 4.7564)
  {
  p_eq = 1000*exp(((a*4.7564)-(B/tem)+A)+b*((sum-4.7564)*(sum-4.7564))/tem) ;
  }
  C_UDMI(c,t,1) = p_eq ;
  }
  end_c_loop(c,t)
  
 }
 
}
where the "sum" is a global varible outside the two macros(or create a UDM to store).
can I import the "custom field function" by UDF ?
besides, I check the "UDF guide " and found that :
Quote:
"A function that is defined using DEFINE ADJUST executes at every iteration and is called at the beginning of every iteration before transport equations are solved."
My case is transient, and I calculate every time step for many iterations. so I have a new qusetion :

if I add the iteration number, the H_M will be added more time ? 


Thank you very much.
ypchen is offline   Reply With Quote

Old   January 9, 2012, 09:06
Default
  #4
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 739
Blog Entries: 1
Rep Power: 14
Amir is on a distinguished road
Quote:
Originally Posted by ypchen View Post
where the "sum" is a global varible outside the two macros(or create a UDM to store).
yes; global variable is a good option here and as you said it should be out of the macros unlike your first UDF. Performing another UDM is not proper for such purpose; although it works but just consumes memory.
Quote:
Originally Posted by ypchen View Post
can I import the "custom field function" by UDF ?
I'm not sure about this. it may be possible with schemes where I don't have any experiences with. You can search threads or open a new one.

Quote:
Originally Posted by ypchen View Post
if I add the iteration number, the H_M will be added more time ?
To avoid this feature you have 2 options:
1) use a simple if-clause in current UDF and use the commands when the time changes.
2) use DEFINE_EXECUTE_AT_THE_END macro which executes at the end of each time step automatically.

Bests,
__________________
Amir
Amir is offline   Reply With Quote

Old   January 10, 2012, 02:11
Default
  #5
New Member
 
Yu-Pei Chen
Join Date: Jun 2011
Posts: 26
Rep Power: 6
ypchen is on a distinguished road
Quote:
use a simple if-clause in current UDF and use the commands when the time changes.
Thank for your reply, Amir. But how to do this ? Can you show a simple example for me ? I have no ideal about this. Thank you .
ypchen is offline   Reply With Quote

Old   January 10, 2012, 04:28
Default
  #6
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 739
Blog Entries: 1
Rep Power: 14
Amir is on a distinguished road
Quote:
Originally Posted by ypchen View Post
But how to do this ? Can you show a simple example for me ? I have no ideal about this. Thank you .
Hi,

This is an example of manual:


Quote:
static int last_ts = -1; /* Global variable. Time step is never <0 */
DEFINE_ADJUST(first_iter_only, domain)
{
int curr_ts;
curr_ts = N_TIME;
if (last_ts != curr_ts)
{
last_ts = curr_ts;

/* things to be done only on first iteration of each time step
can be put here */

}
}
Bests,
__________________
Amir
Amir is offline   Reply With Quote

Old   January 10, 2012, 23:32
Default
  #7
New Member
 
Yu-Pei Chen
Join Date: Jun 2011
Posts: 26
Rep Power: 6
ypchen is on a distinguished road
You really help me. Thank you very much, Amir.
ypchen is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
solving a conduction problem in FLUENT using UDF Avin2407 Fluent UDF and Scheme Programming 1 March 13, 2015 03:02
Problem with zeroGradient wall BC for temperature - Total temperature loss cboss OpenFOAM 10 March 5, 2015 07:57
A problem about 'printf' and 'Message' in UDF. LICH Fluent UDF and Scheme Programming 2 May 2, 2013 02:45
Problem with my udf july Fluent UDF and Scheme Programming 3 June 20, 2010 06:56
UDF (write a data file) problem lichun Dong FLUENT 2 July 29, 2005 11:39


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