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/)
-   -   UDF temperature gradient (https://www.cfd-online.com/Forums/fluent-udf/150785-udf-temperature-gradient.html)

perun333 March 29, 2015 15:44

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

`e` March 29, 2015 16:45

Fluent already has a macro for the temperature gradient: C_T_G(c,t). Read the UDF manual for details.

perun333 March 29, 2015 17:07

Quote:

Originally Posted by `e` (Post 538869)
Fluent already has a macro for the temperature gradient: C_T_G(c,t). Read the UDF manual for details.


Could you be more specific?

`e` March 29, 2015 17:21

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

perun333 March 29, 2015 18:03

Quote:

Originally Posted by `e` (Post 538873)
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).

is it correct?

#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)
}

}

`e` March 29, 2015 18:25

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?

perun333 March 29, 2015 18:38

Quote:

Originally Posted by `e` (Post 538885)
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?


thank you. Do you know how it looks with macro DEFINE_ADJUST?

Thanks

`e` March 29, 2015 18:51

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.

perun333 March 31, 2015 05:27

Quote:

Originally Posted by `e` (Post 538887)
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.

I tried to use ADJUST, but didnt work. Any Idea?

# 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)
}
}

`e` March 31, 2015 06:04

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?

perun333 March 31, 2015 06:27

1 Attachment(s)
Quote:

Originally Posted by `e` (Post 539179)
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?

It said receive fatal signal. My steps are:

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

`e` March 31, 2015 07:12

I'll be specific, remove the following line of code:

Code:

domain = Get_Domain(domain_ID);
If you're still getting fatal errors crashing Fluent, ensure you have enabled the user defined memory.

perun333 March 31, 2015 07:25

1 Attachment(s)
Quote:

Originally Posted by `e` (Post 539202)
I'll be specific, remove the following line of code:

Code:

domain = Get_Domain(domain_ID);
If you're still getting fatal errors crashing Fluent, ensure you have enabled the user defined memory.

I removed line of code and define memory 1 but still fatal error. :(

pakk March 31, 2015 07:33

Quote:

Originally Posted by perun333 (Post 539207)
I removed line of code and define memory 1 but still fatal error. :(

Yes, you define 1 memory (so location 0) and try to store things in memory location 1! That does not work.

perun333 March 31, 2015 07:36

Quote:

Originally Posted by pakk (Post 539209)
Yes, you define 1 memory (so location 0) and try to store things in memory location 1! That does not work.

So what you recomend?

pakk March 31, 2015 07:39

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.

perun333 March 31, 2015 07:53

Quote:

Originally Posted by pakk (Post 539214)
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.

Sorry I dont have much experiencies with programing in C and really dont know why I have to set this memory:(. I computing heat transfer in 2D axisymetric model with conditions:
- 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)
}
}

pakk March 31, 2015 08:04

Quote:

Originally Posted by perun333 (Post 539219)
Sorry I dont have much experiencies with programing in C and really dont know why I have to set this memory:(. I computing heat transfer in 2D axisymetric model with conditions:
- 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)
}
}

My question has nothing to do with programming in c. It has to do with reading skills and basic logic.

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.

perun333 March 31, 2015 09:16

Quote:

Originally Posted by pakk (Post 539223)
My question has nothing to do with programming in c. It has to do with reading skills and basic logic.

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.

Sorry, I thought that this forum helps to sort out problems. But I just only see cynic approach, sorry :/

pakk March 31, 2015 09:24

Quote:

Originally Posted by perun333 (Post 539243)
Sorry, I thought that this forum helps to sort out problems. But I just only see cynic approach, sorry :/

It is bad that you see it that way. The way I see it, I am trying to help you understand the problem, and help you get to a solution.

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.


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