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/)
-   -   Cannot access pressure macro !!!! (https://www.cfd-online.com/Forums/fluent-udf/203654-cannot-access-pressure-macro.html)

mataus July 3, 2018 08:52

Cannot access pressure macro !!!!
 
Hai
I am currently experiencing a very strange problem. I would be very thankful if some could help me.
I am dealing with a simple concetric cylinder problem with simple udf.
Geometry consists of three cylindrical bodies:
1.inner cylinder with velocity in and pressure out condition
2.solid middle cylinder
3.outer cylinder with pressure inlet condition.
During modelling, I have made these 3 bodies into a multibody part by using 'form single body' option.
currently, I am getting a segmentation error ( i believe the issue is related to accessing the cell pressure value). the UDF works fine when I access temperature macro instead of pressure.
Moreover this same udf works with other 2d goemetries.
preesue=5bar and a value of udmi_0=0.01 is patched after intialization.
#include "udf.h"
DEFINE_EXECUTE_AT_END(source_calculation)
{
Domain *d=Get_Domain(1);
int zone_id=9;
Thread *t = Lookup_Thread(d,zone_id);
cell_t c;
real dt=CURRENT_TIMESTEP;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,1)=pow(10,5);
if (((C_P(c,t)>C_UDMI(c,t,1))) && (C_UDMI(c,t,0)<0.99))
{
C_UDMI(c,t,2)=0.001;
}
else
{
C_UDMI(c,t,2)=10;
}
C_UDMI(c,t,0)=C_UDMI(c,t,0)+(C_UDMI(c,t,2)*dt);
}
end_c_loop(c,t)
}
}
Intersingly,this udf works well when multibody option is disabled.But i have to use multibody option to mesh my complex geomtry

obscureed July 3, 2018 10:32

Hi Mataus,

One issue is that pressure is not stored in solid zones (because it has no meaning there). So C_P(c,t) causes a segmentation error there -- not really so strange.

So, inside the "thread_loop_c(t,d)", you should really check which thread you have reached. In this instance, you could check "if(SOLID_THREAD_P(t))". A better, more general test is

Code:

if(NULLP( THREAD_STORAGE(t, SV_P) )) {
  continue; /* or some other way to not use the thread */
}

This kind of test is useful for other variables if you know or can guess the variable index: SV_P, SV_T, SV_UDM_I. You can use it on face threads, too. (A useful example: the list of face threads that do not have UDM assigned to them is slightly larger than you might expect.)

For vector quantities, you might find that you need something different:
Code:

if(NULLP( T_STORAGE_R_NV(t, SV_T_G) )) {
  continue; /* or some other way to not use the gradient */
}

Good luck!
Ed

mataus July 4, 2018 04:23

2 Attachment(s)
Dear Ed,
thanks for your valuable comments.
you are correct .the segmentation error is happening because of accessing pressure value in the solid region.
But here the problem bit different. when I apply UDF in a particular id zone(outer cylinder region) it automatically applies to inner and middle cylinders. (it could be because of the multibody part option enabled.)
then I have changed UDF slightly by adding
"if (NNULLP( THREAD_STORAGE(t, SV_P)))" I think now it prevents accessing the pressure value from the solid region, and the UDF runs without segmentation error.
but still, the UDF applies to both inner outer fluid domain.


the volume monitors of UDMI 0,2 on both inner and outer regions are given below.
the updated udf


#include "udf.h"

DEFINE_EXECUTE_AT_END(source_calculation)
{
Domain *d=Get_Domain(1);
int zone_id=11;
Thread *t = Lookup_Thread(d,zone_id);
cell_t c;
real dt=CURRENT_TIMESTEP;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,1)=pow(10,5);

if(NNULLP( THREAD_STORAGE(t, SV_P)))

{
if (C_P(c,t)>C_UDMI(c,t,1))
{
C_UDMI(c,t,2)=1;
}
else
{
C_UDMI(c,t,2)=100;
}
C_UDMI(c,t,0)=C_UDMI(c,t,0)+(C_UDMI(c,t,2)*dt);
}
end_c_loop(c,t)
}
}
}

obscureed July 5, 2018 08:34

Hi Mataus,
An important point: in your latest code, you need end_c_loop to go after its associated curly-bracket, not before.

Some efficiency points: the test on the thread applies to the whole thread, so it is better to do it once, outside the cell loop, rather than for every cell. Also, "pow(10,5)" is a slow way to get "1.e5". (You mentioned 5 bar in your original post -- but this is 1 bar. Also, whenever you think about pressure, you should stop and think about whether you mean absolute or gauge pressure, and whether you need to pay attention to the operating pressure in the model setup. Fluent stores (and supplies in C_P) pressure values relative to this operating pressure.)

The command "thread_loop_c(t,d)" is a loop over all cell threads: each visit gets a new value in t. So, the first visit overwrites the value you got from "Lookup_Thread". I have not tried to interpret your images or work out all the details of your code, but I suspect that the code is doing what it has been told to do.

Good luck!
Ed


All times are GMT -4. The time now is 20:50.