CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   DEFINE_PROFILE how to transfer variable for another macro? (https://www.cfd-online.com/Forums/fluent-udf/152381-define_profile-how-transfer-variable-another-macro.html)

pawel123 April 30, 2015 03:24

DEFINE_PROFILE how to transfer variable for another macro?
 
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.

`e` April 30, 2015 07:27

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).

pawel123 April 30, 2015 13:38

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.

`e` April 30, 2015 17:48

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);

pawel123 May 1, 2015 07:07

1 Attachment(s)
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ł

pawel123 May 1, 2015 08:05

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.


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