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

code for product of rho and velocity

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By aravind vashista

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 17, 2017, 14:50
Default code for product of rho and velocity
  #1
Member
 
ARAVIND SRIDHARA
Join Date: Jan 2017
Posts: 32
Rep Power: 9
aravind vashista is on a distinguished road
Hii all
I am simulation 3D compressible supersonic flow with hydrogen as fuel and air as oxidizer. I want to write a UDF for mixing efficiency which involves surface integral of (Y**u). where y is species mass fraction, ρ is density , u is velocity. and plot the same along axial length. Since i am learning to write Udf i started of with writing a simple code to find product of ρ*u and allocate these scalar to a memory. so thst i can use the in postprocessing. The code looks as follows. The code is able to interpret but getting fatal signal (segmentation error) while executing. Can u guys please help me in correcting my code.

#include "udf.h"
DEFINE_ON_DEMAND(density)
{
Thread *t;
cell_t c;
real rho, u;
domain= Get_Domain(1);
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{

rho = C_R(c,t);
u = C_U(c,t);
C_UDSI(c,t,0)= rho*u;
}
end_c_loop(c,t)

begin_c_loop(c,t)
{

C_UDMI(c,t,0)=rho*u;

}
end_c_loop(c,t)

}
}

Please help me in correcting my code
aravind vashista is offline   Reply With Quote

Old   September 17, 2017, 22:12
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 33
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Hello.

to get the value of rho*u you do not need scalar (UDSI), you need variable (UDMI) only.

UDSI is used to define User-Defined Scalar (UDS) Transport Equations, see
ANSYS Fluent Customization Manual:
2.7. User-Defined Scalar (UDS) Transport Equation DEFINE Macros
ANSYS Fluent Theory Guide:
1.3. User-Defined Scalar (UDS) Transport Equations

Code:
#include "udf.h"
DEFINE_ON_DEMAND(density)
{
Thread *t;
cell_t c;
real rho, u;
domain= Get_Domain(1);
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{

rho = C_R(c,t);
u = C_U(c,t); 
C_UDMI(c,t,0)=rho*u;
}
end_c_loop(c,t)
}
}
Do not forget to change User Defined Memory locations in Fluent GUI
Go to User-Defined -> Memory -> User Defined Memory locations -> 1 (was 0). This is number of udm variables that you use in UDF.

Now you can plot rho*u the same way, as you plot for example velocity, find User Defined Memory... in the drop down list

Best regards
AlexanderZ is offline   Reply With Quote

Old   September 18, 2017, 02:20
Default
  #3
Member
 
ARAVIND SRIDHARA
Join Date: Jan 2017
Posts: 32
Rep Power: 9
aravind vashista is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
Hello.

to get the value of rho*u you do not need scalar (UDSI), you need variable (UDMI) only.

UDSI is used to define User-Defined Scalar (UDS) Transport Equations, see
ANSYS Fluent Customization Manual:
2.7. User-Defined Scalar (UDS) Transport Equation DEFINE Macros
ANSYS Fluent Theory Guide:
1.3. User-Defined Scalar (UDS) Transport Equations

Code:
#include "udf.h"
DEFINE_ON_DEMAND(density)
{
Thread *t;
cell_t c;
real rho, u;
domain= Get_Domain(1);
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{

rho = C_R(c,t);
u = C_U(c,t); 
C_UDMI(c,t,0)=rho*u;
}
end_c_loop(c,t)
}
}
Do not forget to change User Defined Memory locations in Fluent GUI
Go to User-Defined -> Memory -> User Defined Memory locations -> 1 (was 0). This is number of udm variables that you use in UDF.

Now you can plot rho*u the same way, as you plot for example velocity, find User Defined Memory... in the drop down list

Best regards
hii Alexander,
i have allocated user defined memory location as 1, and implemented the code u had suggested (i.e the same code u wrote above). but still i am getting error as '' Received a fatal signal (Segmentation fault)''. Can u please help me in resolving this issue.
I am modelling 3D supersonic compressible flows using pressure based and k-e for turbulence. and i use species transport to define mixture properties for h2-air.
aravind vashista is offline   Reply With Quote

Old   September 19, 2017, 00:41
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 33
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Hello

Try this code
Code:
#include "udf.h"

DEFINE_ON_DEMAND(my_density)
{
Domain *domain;
Thread *t;
cell_t c;
real rho, u;
real x[ND_ND];
domain= Get_Domain(1);

thread_loop_c (t,domain)
	{
	begin_c_loop (c,t)
		{
		C_CENTROID(x,c,t);
		rho = C_R(c,t);
		u = C_U(c,t); 
		C_UDMI(c,t,0)=rho;
		C_UDMI(c,t,1)=u;
		C_UDMI(c,t,2)=rho*u;
		}
	end_c_loop(c,t)
	}
	Message0("\n On demand executed\n");
}
Best regards
AlexanderZ is offline   Reply With Quote

Old   September 19, 2017, 04:59
Default
  #5
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,150
Blog Entries: 29
Rep Power: 39
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
A segmentation fault inevitably means you are accessing some memory location you are not supposed to access.

My first shot would be that you either have not initialized the solution or that something related to the species transport has to be considered (just guessing, I expect the density to depend on the species concentration, so accessing it in a DEFINE_ON_DEMAND udf might be dangerous as you might try to access it when it is not yet available).

Usually, the best way to debug something is to make it more simple, not the opposite.

Start with just the cell centroid (useful for debug, because always present). Then try just with the velocity (no species effect should be present). Then the density (maybe some species effect is present for DEFINE_ON_DEMAND). According to where the problem comes out you take further steps.
sbaffini is offline   Reply With Quote

Old   September 21, 2017, 07:11
Default
  #6
Member
 
ARAVIND SRIDHARA
Join Date: Jan 2017
Posts: 32
Rep Power: 9
aravind vashista is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
Hello

Try this code
Code:
#include "udf.h"

DEFINE_ON_DEMAND(my_density)
{
Domain *domain;
Thread *t;
cell_t c;
real rho, u;
real x[ND_ND];
domain= Get_Domain(1);

thread_loop_c (t,domain)
	{
	begin_c_loop (c,t)
		{
		C_CENTROID(x,c,t);
		rho = C_R(c,t);
		u = C_U(c,t); 
		C_UDMI(c,t,0)=rho;
		C_UDMI(c,t,1)=u;
		C_UDMI(c,t,2)=rho*u;
		}
	end_c_loop(c,t)
	}
	Message0("\n On demand executed\n");
}
Best regards
Yes i will try and comeback to u
Thank you
aravind vashista is offline   Reply With Quote

Old   September 21, 2017, 07:17
Default
  #7
Member
 
ARAVIND SRIDHARA
Join Date: Jan 2017
Posts: 32
Rep Power: 9
aravind vashista is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
A segmentation fault inevitably means you are accessing some memory location you are not supposed to access.

My first shot would be that you either have not initialized the solution or that something related to the species transport has to be considered (just guessing, I expect the density to depend on the species concentration, so accessing it in a DEFINE_ON_DEMAND udf might be dangerous as you might try to access it when it is not yet available).

Usually, the best way to debug something is to make it more simple, not the opposite.

Start with just the cell centroid (useful for debug, because always present). Then try just with the velocity (no species effect should be present). Then the density (maybe some species effect is present for DEFINE_ON_DEMAND). According to where the problem comes out you take further steps.
yes this was a good way for debugging, i wrote a new code and it interpreted and executed sucessfully but while compiling i am able to sucessfully build library file but unable to load it. I will get the following error in doing so

Error: Error code: 193\n
Error Object: #f

can u tell me y i am getting this error?
I have installed microsoft visual studio v17.0.
aravind vashista is offline   Reply With Quote

Old   September 21, 2017, 07:23
Default
  #8
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,150
Blog Entries: 29
Rep Power: 39
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
So, interpreting works with all the variables?

I have no idea of what that error means. If interpreting works, I would first stick to that. Only later I would bother with compiling, as any troubles can then be related just to the compilation process and not the udf in itself.
sbaffini is offline   Reply With Quote

Old   September 22, 2017, 03:27
Default
  #9
Member
 
ARAVIND SRIDHARA
Join Date: Jan 2017
Posts: 32
Rep Power: 9
aravind vashista is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
So, interpreting works with all the variables?

I have no idea of what that error means. If interpreting works, I would first stick to that. Only later I would bother with compiling, as any troubles can then be related just to the compilation process and not the udf in itself.
I resolved it, it was a visual studio error. i installed visual studio 2012 instead of visual studio 2017 and it got compiled.
Thank you
sbaffini likes this.
aravind vashista is offline   Reply With Quote

Reply

Tags
segmentaion fault, udf code, udmi.uds, udsi

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Problem about Rotor simulation whit high rotating speed Thomas pan OpenFOAM Running, Solving & CFD 4 June 20, 2018 07:24
Problem with SIMPLEC-like finite volume channel flow boundary conditions ghobold Main CFD Forum 3 June 15, 2015 12:14
settlingFoam crash when velocity increase jimbean OpenFOAM Running, Solving & CFD 1 March 26, 2014 04:59
should Courant number always be kept below 1? wc34071209 OpenFOAM Running, Solving & CFD 16 March 9, 2014 20:31
Why RNGkepsilon model gives floating error shipman OpenFOAM Running, Solving & CFD 3 September 7, 2013 09:00


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