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

DEFINE_PROFILE how to transfer variable for another macro?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 30, 2015, 04:24
Default DEFINE_PROFILE how to transfer variable for another macro?
  #1
New Member
 
Pawel
Join Date: Oct 2013
Posts: 9
Rep Power: 13
pawel123 is on a distinguished road
Hello,

I would like to use variable computed in one boundary condition (DEFINE_PROFILE) in another boundary condition (DEFINE_PROFILE).

Part of the UDF:

#include "udf.h"

real temp1=400;
real m_wody = 1;
real cp_wody = 4190;
real depth = 10.1;
real variable_for_another_macro;

DEFINE_PROFILE(temp_prof, t, i)
{
face_t f;
real NV_VEC(farea);
real area;
real heat;

begin_f_loop(f, t)
{
F_PROFILE(f, t, i) = temp1;
F_AREA(farea, f, t);
area += NV_MAG(farea);
heat += BOUNDARY_HEAT_FLUX(f, t);
Message("message1= %f\n", area*depth*heat*depth);
}
end_f_loop(f, t)

variable_for_another_macro = area*depth*heat*depth;
Message("message2= %f\n", variable_for_another_macro);

}

I am caluclating value og "variable_for_another_macro" and I want to use it in another DEFINE_PROFILE but I obtaind value equal to 0.

Boundary have 8 faces and messages report:
message1= -453.149002
message1= -1807.908318
message1= -3622.132761
message1= -5866.225999
message1= -8420.704222
message1= -12881.145991
message1= -17280.047513
message1= -23394.525392 (till this moment everything is OK - I have sum from 8 faces)
message2= -23394.525392 (Sum from loop is transfered to my "variable_for_another_macro" - OK - I would like to use this value in another DEFINE_PROFILE)
message2= 0.000000 ("variable_for_another_macro" changes to 0 and message is shown 8 times - 8 boundary faces)
message2= 0.000000
message2= 0.000000
message2= 0.000000
message2= 0.000000
message2= 0.000000
message2= 0.000000
message2= 0.000000

Why my variable changes to 0? I need value -23394.525392 and i do not understand why Fluent shows message2 8 times when i do not have loop there.
pawel123 is offline   Reply With Quote

Old   April 30, 2015, 08:27
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
You have only shown one DEFINE_PROFILE code block, is there supposed to be a second which prints "message2=..." as well?

Are you intentionally accumulating the area for each face such that (perhaps in an arbitrary order) most faces include more than its own area? Could you change your logic so that you don't need this shared variable, "variable_for_another_macro"?

Are you running in serial or parallel mode? If you're running in parallel, have a read of the parallelisation section in the UDF manual (perhaps your sum is not shared among the nodes).
`e` is offline   Reply With Quote

Old   April 30, 2015, 14:38
Default
  #3
New Member
 
Pawel
Join Date: Oct 2013
Posts: 9
Rep Power: 13
pawel123 is on a distinguished road
Yes there will be another DEFINE_PROFILE block.

I want to transfer "Total surface heat flux" from boundary to another DEFINE_PROFILE.
BOUNDARY_HEAT_FLUX returns value in W/m2 and I need to multiply it by area to obtain W.
Then in another DEFINE_PROFILE I want to increase temperature on boundary based on Total surface heat flux.

area += NV_MAG(farea); returns total area of boundary (sum from 8 faces area) and value is correct.

When I delete sum (just for checking) message2 also reset value to 0.

I am using parallel mode.
pawel123 is offline   Reply With Quote

Old   April 30, 2015, 18:48
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
OK, I understand now that your "area" and "heat" variables are calculated independent of your F_PROFILE but is used within the same loop (which works fine).

Are your values for the heat flux what you expected? This macro returns the heat flux in units of [W] according to this thread. Your UDF multiplies this flux by the area and depth twice giving units of [W.m^4].

I still don't understand why your code is printing "message2= 0.0..." eight times because there's nothing in your UDF that you've posted which instructs Fluent to print these messages. If there's another DEFINE_PROFILE block you're using, could you post this code as well?

If you can't manage to use this global variable then evaluate this heat flux on your other boundary condition and call the first boundary using the respective thread with:

Code:
Thread *t0 = LookupThread(d,boundary_ID);
`e` is offline   Reply With Quote

Old   May 1, 2015, 08:07
Default
  #5
New Member
 
Pawel
Join Date: Oct 2013
Posts: 9
Rep Power: 13
pawel123 is on a distinguished road
Thank you for your help.

I use heat flux to calculate temperature and I get what I expect. I wrote more about it on picture.
I am attaching whole UDF and I also show and explain it on picture.

Pictue: http://i.imgur.com/U97xbBT.png

I used both ways:
1) with global variables
2) with local variables
unfortunately both does not work.

I also do not understand why my values are reset to 0 multiple times. In my opinion this UDF is quite simple and results are really strange.

Best regards,
Paweł
Attached Files
File Type: c test_case.c (1.5 KB, 91 views)
pawel123 is offline   Reply With Quote

Old   May 1, 2015, 09:05
Default
  #6
New Member
 
Pawel
Join Date: Oct 2013
Posts: 9
Rep Power: 13
pawel123 is on a distinguished road
Ok my UDF is working in serial mode. Everything works fine and values are not reset to 0.


I also find that in parallel mode, command PRF_GRSUM1 set correct value in each node and correct value is passed to "variable_for_another_macro".

#if RP_NODE
variable_for_another_macro = PRF_GRSUM1(temp);
#endif


I do not know if this is efficient way of doing this because still a lot of values are printed with Message function but all values are correct.

Last edited by pawel123; May 1, 2015 at 11:57.
pawel123 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
Radiation interface hinca CFX 15 January 26, 2014 18:11
Tecplot Macro - conditional - array variable pchidamb Tecplot 2 July 29, 2009 10:48
How to pass a variable from a define macro... Padian FLUENT 2 May 30, 2008 06:22
Why doesnbt the macro forall work for the volVectorField variable siwen OpenFOAM Running, Solving & CFD 2 February 24, 2006 16:27
field variable macro of the mean-x-velocity? zt xie FLUENT 2 November 15, 2005 06:48


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