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

Cannot access pressure macro !!!!

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 3, 2018, 09:52
Default Cannot access pressure macro !!!!
  #1
New Member
 
Mat
Join Date: Jan 2017
Posts: 23
Rep Power: 9
mataus is on a distinguished road
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
mataus is offline   Reply With Quote

Old   July 3, 2018, 11:32
Default
  #2
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
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
obscureed is offline   Reply With Quote

Old   July 4, 2018, 05:23
Default
  #3
New Member
 
Mat
Join Date: Jan 2017
Posts: 23
Rep Power: 9
mataus is on a distinguished road
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)
}
}
}
Attached Images
File Type: jpg outer fluid.jpg (39.6 KB, 5 views)
File Type: jpg inner.jpg (33.6 KB, 3 views)
mataus is offline   Reply With Quote

Old   July 5, 2018, 09:34
Default
  #4
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
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
obscureed is offline   Reply With Quote

Reply

Tags
segmentation fault, udf code


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
Pressure Inlet VS velocity Inlet difference Mohsin FLUENT 9 January 4, 2021 11:34
interFoam (HELYX-OS) pressure boundary conditions SFr OpenFOAM Running, Solving & CFD 8 June 23, 2016 17:36
Pressure Outlet Guage pressure Mohsin FLUENT 36 April 29, 2016 18:16
Calculation of the Governing Equations Mihail CFX 7 September 7, 2014 07:27
UDF Data Access Macro Woo Meng Wai FLUENT 0 November 6, 2007 21:23


All times are GMT -4. The time now is 14:18.