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

converting instructions of a wall to instructions of a domain

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By pakk
  • 1 Post By pakk
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 29, 2018, 11:20
Default converting instructions of a wall to instructions of a domain
  #1
Member
 
youhane kha
Join Date: Sep 2017
Posts: 36
Rep Power: 9
youhane is on a distinguished road
hello everybody,

Can any one help me please. I'm working with an UDF that makes the velocity inlet in a pipe varies with respect to the average temperature of a wall (THREAD_ID(t)==2 in my UDF).

The UDF works perfectly when the thread_id concerned is a wall, but when I change the wall by a surface (2d domain) by changing the THREAD_ID(t) in the code, Fluent generate this error:

Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: ()

This is my udf code:

#include "udf.h"

DEFINE_PROFILE(unsteady_velocity_profile, th, position)
{
Domain *d; /* declare domain pointer since it is not passed as an
argument to the DEFINE macro */
face_t f;
real tavg = 0.;
Thread *t;
real tempe,volume,vol_tot,area;

real A[ND_ND];

d = Get_Domain(1); /* Get the domain using Fluent utility */

/* Loop over all cell threads in the domain */
thread_loop_f(t,d)
{
/* only use thread with id=2 */
if (THREAD_ID(t)==2) {
/* Loop over all cells */
begin_f_loop(f,t)
{

tempe = F_T(f,t);
area=NV_MAG(A);

vol_tot += area;
tavg += (tempe*area);

}
end_f_loop(f,t)
tavg /= vol_tot;

}
}

begin_f_loop(f, th)
{
if ( tavg <= 298. )
F_PROFILE(f, th, position) = 0.5;
if ( tavg > 301.4 )
F_PROFILE(f, th, position) = 0.;
}
end_f_loop(f, th)
}
youhane is offline   Reply With Quote

Old   March 30, 2018, 19:45
Unhappy
  #2
Member
 
youhane kha
Join Date: Sep 2017
Posts: 36
Rep Power: 9
youhane is on a distinguished road
Any helps please !!
youhane is offline   Reply With Quote

Old   March 31, 2018, 12:46
Default
  #3
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
This version is working, but what exactly do you change in the version where it not working?
youhane likes this.
pakk is offline   Reply With Quote

Old   April 2, 2018, 20:15
Default
  #4
Member
 
youhane kha
Join Date: Sep 2017
Posts: 36
Rep Power: 9
youhane is on a distinguished road
Quote:
Originally Posted by pakk View Post
This version is working, but what exactly do you change in the version where it not working?
Thanks for your reply Mr. pakk.

Yes exactly, when I use the THREAD_ID(t) of a wall, the code work perfectly, but when I want to use the THREAD_ID(t) of a domain ( interior_air in the pictures) either the code generate this error: FLUENT received fatal signal (ACCESS_VIOLATION) when the ID is got from the boundary conditions (ID=2 here) like in this picture:



Or the code does not generate errors when the ID is got from the cell zone conditions (ID=9 here) like in this picture:



But even if the code does not generate errors when the ID is got from the cell zone conditions, the velocity defined is always equal to 0.5 , that's mean that the T_average is not well calculated from the interior_air.

Can you help me please ?
youhane is offline   Reply With Quote

Old   April 3, 2018, 05:58
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
The problem is simple to explain: you wrote a UDF to calculate average temperature on a wall. But now you apply it on an interior. An interior is not a wall...

I can't give you a solution. I mean, I can give you many 'solutions' that will get rid of the error, but I can't guess which one is relevant for you, because I don't understand what you are trying to achieve.
youhane likes this.
pakk is offline   Reply With Quote

Old   April 3, 2018, 11:04
Default
  #6
Member
 
youhane kha
Join Date: Sep 2017
Posts: 36
Rep Power: 9
youhane is on a distinguished road
Quote:
Originally Posted by pakk View Post
The problem is simple to explain: you wrote a UDF to calculate average temperature on a wall. But now you apply it on an interior. An interior is not a wall...

I can't give you a solution. I mean, I can give you many 'solutions' that will get rid of the error, but I can't guess which one is relevant for you, because I don't understand what you are trying to achieve.
Thanks Mr. Pakk. So this is what I'm trying to achieve :



So could you help me please?
youhane is offline   Reply With Quote

Old   April 4, 2018, 02:55
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Part of your code is this:

Code:
/* Loop over all cells */
begin_f_loop(f,t)
The problem is that the comment and the code itself do not agree. As the comment says, you should loop over all cells, but the code below shows that you loop over all faces.

So rewrite your code to work with cells instead of faces.
pakk is offline   Reply With Quote

Old   April 4, 2018, 09:46
Default
  #8
Member
 
youhane kha
Join Date: Sep 2017
Posts: 36
Rep Power: 9
youhane is on a distinguished road
Quote:
Originally Posted by pakk View Post
Part of your code is this:

Code:
/* Loop over all cells */
begin_f_loop(f,t)
The problem is that the comment and the code itself do not agree. As the comment says, you should loop over all cells, but the code below shows that you loop over all faces.

So rewrite your code to work with cells instead of faces.
unfortunately, I tried the code with cells before I used it with faces. Neither of them have worked. This is the code with cells: ( I tried also thread_loop_c(t,d) instead of thread_loop_f(t,d) and there is no results )


#include "udf.h"

DEFINE_PROFILE(unsteady_velocity_profile, th, position)
{
Domain *d; /* declare domain pointer since it is not passed as an
argument to the DEFINE macro */
face_t f;
real tavg = 0.;
Thread *t;
real tempe,volume,vol_tot;
cell_t c;


d = Get_Domain(1); /* Get the domain using Fluent utility */

/* Loop over all cell threads in the domain */
thread_loop_f(t,d)
{
/* only use thread with id=11 */
if (THREAD_ID(t)==9) {
/* Loop over all cells */
begin_c_loop(c,t)
{
volume = C_VOLUME(c,t); /* get cell volume */
tempe = C_T(c,t); /* get cell temperature */

vol_tot += volume;
tavg += (tempe*volume);

}
end_c_loop(c,t)

tavg /= vol_tot;
}
}

begin_f_loop(f, th)
{
if ( tavg <= 298. )
F_PROFILE(f, th, position) = 0.5;
if ( tavg > 298. )
F_PROFILE(f, th, position) = 0.;
}
end_f_loop(f, th)
}
youhane is offline   Reply With Quote

Old   April 4, 2018, 09:49
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Code:
/* Loop over all cell threads in the domain */
   thread_loop_f(t,d)
Again, code and comment do not agree. Comment is correct, code is wrong.

But what do you mean with "no results"??? Program crashed, error warning, strange results, compilation error... What?
pakk is offline   Reply With Quote

Old   April 4, 2018, 10:05
Default
  #10
Member
 
youhane kha
Join Date: Sep 2017
Posts: 36
Rep Power: 9
youhane is on a distinguished road
Quote:
Originally Posted by pakk View Post
Code:
/* Loop over all cell threads in the domain */
   thread_loop_f(t,d)
Again, code and comment do not agree. Comment is correct, code is wrong.

But what do you mean with "no results"??? Program crashed, error warning, strange results, compilation error... What?
yes when I put that:

thread_loop_c(t,d)
{
/* only use thread with id=9 */
if (THREAD_ID(t)==9) {
/* Loop over all cells */
begin_c_loop(c,t)
{
volume = C_VOLUME(c,t); /* get cell volume */
tempe = C_T(c,t); /* get cell temperature */

vol_tot += volume;
tavg += (tempe*volume);

}
end_c_loop(c,t)

tavg /= vol_tot;


the velocity is always 0. that's mean that tavg is always above 298 k. and that's not true. I initialised with 291 k.
youhane is offline   Reply With Quote

Old   April 4, 2018, 10:07
Default
  #11
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
If you are running in serial mode (not parallel), then I can't see where the problem is.
pakk is offline   Reply With Quote

Old   April 4, 2018, 10:17
Default
  #12
Member
 
youhane kha
Join Date: Sep 2017
Posts: 36
Rep Power: 9
youhane is on a distinguished road
Quote:
Originally Posted by pakk View Post
If you are running in serial mode (not parallel), then I can't see where the problem is.
unfortunately, I run it in serial mode

But please Mr. Pakk, if you can tell me instructions to write the tavg in a separate file or either in the fluent window in every time step, then I can maybe recognize where the problem is.
youhane is offline   Reply With Quote

Old   April 4, 2018, 10:19
Default
  #13
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Message("tavg=%f\n",tavg);
pakk is offline   Reply With Quote

Old   April 4, 2018, 10:30
Default
  #14
Member
 
youhane kha
Join Date: Sep 2017
Posts: 36
Rep Power: 9
youhane is on a distinguished road
Quote:
Originally Posted by pakk View Post
Message("tavg=%f\n",tavg);
Excuse me but that gives this error in the fluent window:

unsteady_velocity_profile.c: line 59: function "CX_Message" not found (pc=140).

that what I puted in the code:


begin_c_loop(c,t)
{
volume = C_VOLUME(c,t); /* get cell volume */
tempe = C_T(c,t); /* get cell temperature */

vol_tot += volume;
tavg += (tempe*volume);

}
end_c_loop(c,t)

tavg /= vol_tot;
Message("tavg=%f\n",tavg);
}
youhane is offline   Reply With Quote

Old   April 4, 2018, 10:32
Default
  #15
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You should (as always) be compiling, not interpreting.
youhane likes this.
pakk is offline   Reply With Quote

Old   April 4, 2018, 10:40
Default
  #16
Member
 
youhane kha
Join Date: Sep 2017
Posts: 36
Rep Power: 9
youhane is on a distinguished road
Quote:
Originally Posted by pakk View Post
You should (as always) be compiling, not interpreting.
okey thank you very much, I will refrer to the udf manuel to learn the difference between them, that may be my whole problem
youhane 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
Centrifugal fan j0hnny CFX 13 October 1, 2019 14:55
Periodic Pressure drop cfd_begin CFX 10 May 25, 2017 08:09
Centrifugal fan-reverse flow in outlet lesds to a mass in flow field xiexing CFX 3 March 29, 2017 11:00
Difficulty In Setting Boundary Conditions Moinul Haque CFX 4 November 25, 2014 18:30
Error finding variable "THERMX" sunilpatil CFX 8 April 26, 2013 08:00


All times are GMT -4. The time now is 19:13.