UDF temperature gradient
Hi guys
I would like to create UDF for computing temperature gradient (in time and space). I have 2D axysimmetric model. Some tips? I havent enough experiencies with c++. |
Fluent already has a macro for the temperature gradient: C_T_G(c,t). Read the UDF manual for details.
|
Quote:
Could you be more specific? |
Read section "3.2.3.7. Gradient (G) and Reconstruction Gradient (RG) Vector Macros" on page 221 of the ANSYS Fluent 15.0 UDF Manual (may have different page number and/or section for different versions of Fluent).
|
Quote:
#include "udf.h" DEFINE_ON_DEMAND(Temp_grad_ondemand) { Domain *d; cell_t c; Thread *t; d = Get_Domain(1); thread_loop_c(t,d) { begin_c_loop(c,t) { C_UDMI(c,t,1) = NV_MAG(C_T_G(c,t)); } end_c_loop(c,t) } } |
Your code appears correct if you want the magnitude of the temperature gradient. Have you tried compiling this UDF, and do you get expected results?
|
Quote:
thank you. Do you know how it looks with macro DEFINE_ADJUST? Thanks |
The code for determining the temperature gradient magnitude with a DEFINE_ADJUST macro would look very similar to your DEFINE_ON_DEMAND code. Again, have a read of the UDF manual and return if you have any precise questions.
|
Quote:
# include "udf.h" # define domain_ID 2 DEFINE_ADJUST(adjust_gradient, domain) { Thread *t; cell_t c; face_t f; domain = Get_Domain(domain_ID); /* Fill UDS with the variable. */ thread_loop_c (t,domain) { begin_c_loop (c,t) { C_UDMI(c,t,1) = NV_MAG(C_T_G(c,t)); } end_c_loop (c,t) } } |
What are the errors and when do they occur?
'domain' is a pointer to the domain that the adjust function is to be applied. Typically you only have one domain and use the macro Get_Domain(1) if you require the pointer for it (but it's provided with DEFINE_ADJUST). Do you have multiple domains or are you confusing domains with cell zones? |
1 Attachment(s)
Quote:
1.Star fluet 2. Sets bounday conditions 3. Interpred program 4. Set funkcions hook =>set it in adjust 5. Star calculation and then error Thx |
I'll be specific, remove the following line of code:
Code:
domain = Get_Domain(domain_ID); |
1 Attachment(s)
Quote:
|
Quote:
|
Quote:
|
I recommend that you think about how to solve the problem.
The current situation: you use a memory location that is not defined. The wanted situation: you use a memory location that is defined. How would you go from the current situation to the wanted situation? There are two strategies for that. |
Quote:
- max. time gradient 20°C/h during heating - max. time gradient 30°C/h during cooling - max. space temperature gradient 60°C/m I have found that I have to use type define_adjust and macro C_T_G. So I tried to use this after some upgrades: # include "udf.h" DEFINE_ADJUST(adjust_gradient, domain) { Thread *t; cell_t c; face_t f; /* Fill UDS with the variable. */ thread_loop_c (t,domain) { begin_c_loop (c,t) { C_UDMI(c,t,1) = NV_MAG(C_T_G(c,t)); } end_c_loop (c,t) } } |
Quote:
The current situation: you use a memory location that is not defined. The wanted situation: you use a memory location that is defined. How would you go from the current situation to the wanted situation? There are two strategies for that. This is really not a super-hard question. |
Quote:
|
Quote:
You give the impression that you don't want to understand anything, but that you just want to hear what you should do to get rid of your error. Is that what you want? In that case, you'll have to hire me, I don't do those jobs for free. |
We're both trying to help you out here Ondrej, and have both read your problem, understood it and given guidance. I agree with pakk that these forums are for learning and troubleshooting Fluent issues, not simply doing the work for you. It appears you ignored my comment on the domain pointer solution back in this post, and I had to repeat myself before you fixed that issue. For every solution we provide in threads, I'm sure there's a number of others who stumble across the same issue and find these threads through search engines.
That being said, I think the key issue you face is that computers like to start from zero; for example, you access the fourth element of an array with x[3] and not with x[4]. Applying this logic to your C_UDMI macro: try accessing C_UDMI(c,t,0). |
Quote:
Updating solution at time level N... done. iter energy delta_time time time/iter Error: received a fatal signal (Segmentation fault). Error: received a fatal signal (Segmentation fault). Error Object: #f This is my updated code: #include "udf.h" DEFINE_ADJUST(teste, domain) { Thread *t; cell_t c; thread_loop_c(t, domain) { begin_c_loop_all(c, t) { C_UDMI(c,t,0) = NV_MAG(C_T_G(c,t)); } end_c_loop_all(c, t) } } Then I tried it from another side, but with same resault: #include "udf.h" DEFINE_ADJUST(max_C_T_G, domain) { cell_t c; Thread *ct; real maxT; maxT = 0.0; thread_loop_c(ct,domain) { begin_c_loop(c,ct) { if (C_T_G(c,ct)[0] > maxT) { maxT = C_T_G(c,ct)[0]; } } end_c_loop(c,ct) } printf("Maximum temperature = %f \n", maxT); } Sorry for it. |
Try emptying your DEFINE_ADJUST UDF and only have a message, for example:
Code:
#include "udf.h" Lastly, use Message() instead of printf(). |
Quote:
|
Work through your code line by line (adding one by one from the working simple message UDF) until you determine which line is causing your error and then fix it, good luck!
|
Quote:
#include "udf.h" DEFINE_ADJUST(max_C_T_G, domain) { cell_t c; Thread *ct; real maxT; maxT = 0.0; thread_loop_c(ct,domain) { begin_c_loop(c,ct) { if (C_T_G(c,ct)[0] > maxT) { maxT = C_T_G(c,ct)[0]; } } end_c_loop(c,ct) } printf("Maximum temperature = %f \n", maxT); } But problem is maybe with axisymetric definition. |
The problem could be that your temperature gradient is not yet defined. Is this on the first iteration? If so, let your simulation run for a few time steps before you use this UDF.
And a minor detail: replace Code:
printf("Maximum temperature = %f \n", maxT); Code:
Message("Maximum temperature gradient = %f K/m.\n", maxT); |
Quote:
I tried your opinions: -change the line for message in udf -run transient calculate >>calculation converget -compiled upgraded udf -Adjust hook -calculate -error: Updating solution at time level N... done. iter energy delta_time time time/iter ! 45 solution is converged 45 5.6044e-07 1.0000e+01 1.3000e+02 0:00:02 20 Error: received a fatal signal (Segmentation fault). Error: received a fatal signal (Segmentation fault). Error Object: #f |
Hmm, then I don't know...
You could try to see if the gradient is the problem by replacing C_T_G(c,ct)[0] by C_T(c,ct). But if the gradient is really the problem, I would not know how to solve that. If C_T(c,ct) also does not work, the axisymmetry might be the problem. But then, I also would not know how to solve that. |
Quote:
|
Quote:
I try to compiled and adjusted udf (which have to work) from ansys forum. Here is code: #include "udf.h" DEFINE_ADJUST(total_dissipation, domain) { cell_t c; Thread *ct; real total_diss; total_diss = 0.0; /* Initialise total_diss before the loop */ thread_loop_c(ct,domain) { begin_c_loop(c,ct) { total_diss += C_D(c,ct) * C_VOLUME(c,ct); /* Use += to sum up values */ } end_c_loop(c,ct) } Message("Volume integral of turbulent dissipation = %f \n", total_diss); } And I have still same resault: fatal error (segmentation fault) I tried to compiled simple udf which contains only hello world and it works. Have you any idea where is problem? |
Hi!
I think that the solution to your problem is defining the thread value as equal to DT_THREAD(dt). The reason is in the fact that you are using the dynamic mesh. In that case normal thread definition does not work. Consequentially, your face looping macro aborts the simulation. Regards, Marko. |
@OP.
Actually what was being conveyed to you was that by default the first memory location is 0 in Ansys fluent. You defined one memory means you defined 0 serial number memory. It starts with 0. But you were storing the gradient in the user defined memory 1 which was not existing. |
All times are GMT -4. The time now is 13:59. |