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

Segmentation error with DEFINE_SOURCE

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 2 Post By pakk
  • 2 Post By annan
  • 2 Post By obscureed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 14, 2018, 18:04
Default Segmentation error with DEFINE_SOURCE
  #1
New Member
 
Masoud Mo
Join Date: May 2018
Posts: 6
Rep Power: 7
eng.masoud is on a distinguished road
Hi fellows,
I am simulating a 2phase problem (liquid and air) that liquid phase comes from inlet and depositing on wall substrate. I am using heat source to apply and make it molten.
I defined the code as below, to select only second phase cells and apply on them but after starting Ive got the segmentation error. Would you please guide me on this regard.

Thanks


#include "udf.h"
DEFINE_SOURCE(heatsource, c, thsec, dS, eqn)
{
real x[ND_ND], source, current_time;
real xc; /* xc - x coordinate */
real yc; /* yc - y coordinate */

Thread *thmix;
thsec = THREAD_SUB_THREAD(thmix,3);

C_CENTROID(x,c,thsec);
xc=x[0]; /* the x coordinate of the cell - 0th component of vector x */
yc=x[1]; /* the y coordinate of the cell - 1st component of vector x */

if (xc>=0.0045 & xc<=0.0077 & yc>=-0.001 & yc<=0.0029)

{
source=10e11;}

else {
source=0;}

dS[eqn] = 0.0; /* the source does not depend on temperature so dS = 0 */

return source;

}
eng.masoud is offline   Reply With Quote

Old   May 15, 2018, 05:43
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Your problem is in the line
Code:
thsec = THREAD_SUB_THREAD(thmix,3);
Up until that point, Fluent tells you that it wants to know the source corresponding to thread 'thsec' as input for this function, and you told the compiler to reserve memory for the thread 'thmix'.
And in this line of code, you tell Fluent to change 'thsec' (which makes no sense), and that it should be changed into something that depends on 'thmix', but you did not tell Fluent yet what 'thmix' is.

I have no idea what you try to accomplish with this line of code. It looks like your code becomes error-free if you simply remove this line, but then it might not do what you want it to do.
annan and eng.masoud like this.
pakk is offline   Reply With Quote

Old   May 15, 2018, 11:08
Default
  #3
New Member
 
Masoud Mo
Join Date: May 2018
Posts: 6
Rep Power: 7
eng.masoud is on a distinguished road
Hi Pakk
thanks for your response. For better elaboration plz have a look at attached picture and let me know your opinion on this regard.

cheers,
eng.masoud is offline   Reply With Quote

Old   May 15, 2018, 07:40
Default
  #4
Member
 
annan
Join Date: Nov 2016
Posts: 72
Rep Power: 9
annan is on a distinguished road
Hey eng.masoud,

I guess you're adding the source term to an equation defined for the mixture thread, so the thread *thmix that appears here : DEFINE_SOURCE(heatsource, c, thmix, dS, eqn) is actually your mixture thread.
If you want to work on the secondary phase only, you need to change the following code lines :
"Thread *thmix;
thsec = THREAD_SUB_THREAD(thmix,3);"
with :
"Thread *thsec;
thsec = THREAD_SUB_THREAD(thmix,1);"
index 1 corresponds to the secondary phase while index 0 corresponds to the primary phase.
I think those are the lines that cause segmentation fault, because you were trying to redefine the mixture thread which Fluent already knows with a phase thread.

Hope this will help.
Good luck
Annan
zobekenobe and eng.masoud like this.
annan is offline   Reply With Quote

Old   May 15, 2018, 10:57
Default
  #5
New Member
 
Masoud Mo
Join Date: May 2018
Posts: 6
Rep Power: 7
eng.masoud is on a distinguished road
Hi Annan
Thanks for your response.
Ive applied yr mentioned modifications but still doesn't work (segmentation error was solved). As you can see from attached picture, I want to apply the heat only on 2nd phase cells coming from inlet. On this regard, I defined a rectangular area as judgment to apply the heat on the 2nd phase cells inside of this area. But instead of heating up the specific phase, heat was applied on the whole rectangular area.


#include "udf.h"
DEFINE_SOURCE(heatsource, c, thmix, dS, eqn)
{
real x[ND_ND], source, current_time;
real xc; /* xc - x coordinate */
real yc; /* yc - y coordinate */

Thread *thsec;
thsec = THREAD_SUB_THREAD(thmix,1);

C_CENTROID(x,c,thsec);
xc=x[0]; /* the x coordinate of the cell - 0th component of vector x */
yc=x[1]; /* the y coordinate of the cell - 1st component of vector x */


if (xc>=0.0045 & xc<=0.0077 & yc>=-0.001 & yc<=0.0029)

{
source=10e11;}

else {
source=0;}

dS[eqn] = 0.0; /* the source does not depend on temperature so dS = 0 */

return source;
}

https://drive.google.com/file/d/1Ol3PFxu2RA_WnJqSP_ASaXvt3JGNStq4/view?usp=sharing[/URL]
eng.masoud is offline   Reply With Quote

Old   May 15, 2018, 11:04
Default
  #6
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
Hi eng.masoud,

I agree with annan's comments. (And, currently, you don't need to delve into sub-threads, because centroid information will be in thmix, the supplied superthread or mixture thread.)

Looking ahead, though, a few more comments:
(1) The standard C way to combine logical tests using AND is "&&" not "&". You might find that "&" works because of some integer bit-related machinery, but "&&" is the correct way.
(2) Your constant source rate of 10e11 seems very high for typical applications. It has units W/m3. For example, if the material has density 1000 kg/m3 and specific heat capacity 2000 J/(kg.K), then it would take a fraction of a millisecond to increase temperature by 100K. Maybe this is correct for your application, but please can you check this? You might find that convergence is easier if you drop the constant by several orders of magnitude, even if only for debugging.
(3) You have a real variable called "current_time". Perhaps you know that there is a built-in macro "CURRENT_TIME", which you might be able to use instead. It is always a double. I used to believe that it was always present on all compute-nodes, and could be used repeatedly without the expense of an RP_Get_Double every time, but now I am not so sure.

Good luck,
Ed
zobekenobe and annan like this.
obscureed is offline   Reply With Quote

Old   May 15, 2018, 11:22
Default
  #7
New Member
 
Masoud Mo
Join Date: May 2018
Posts: 6
Rep Power: 7
eng.masoud is on a distinguished road
Quote:
Originally Posted by obscureed View Post
Hi eng.masoud,

I agree with annan's comments. (And, currently, you don't need to delve into sub-threads, because centroid information will be in thmix, the supplied superthread or mixture thread.)

Looking ahead, though, a few more comments:
(1) The standard C way to combine logical tests using AND is "&&" not "&". You might find that "&" works because of some integer bit-related machinery, but "&&" is the correct way.
(2) Your constant source rate of 10e11 seems very high for typical applications. It has units W/m3. For example, if the material has density 1000 kg/m3 and specific heat capacity 2000 J/(kg.K), then it would take a fraction of a millisecond to increase temperature by 100K. Maybe this is correct for your application, but please can you check this? You might find that convergence is easier if you drop the constant by several orders of magnitude, even if only for debugging.
(3) You have a real variable called "current_time". Perhaps you know that there is a built-in macro "CURRENT_TIME", which you might be able to use instead. It is always a double. I used to believe that it was always present on all compute-nodes, and could be used repeatedly without the expense of an RP_Get_Double every time, but now I am not so sure.

Good luck,
Ed
Hi Ed
Thanks for your prompt response,
later on I will apply the heat source equation but this time for simplicity I just used constant value to make sure the correctness of my code.
eng.masoud 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
Segmentation fault when running dieselFoam or dieselEngineFoam in parallel francesco OpenFOAM Bugs 4 May 2, 2017 21:59
Segmentation fault in SU2 V5.0 ygd SU2 2 March 1, 2017 04:38
Segmentation fault when running in parallel Pj. OpenFOAM Running, Solving & CFD 3 April 8, 2015 08:12
Segmentation Fault w/ compiled OF 2.2.0 - motorBike example sudo OpenFOAM Running, Solving & CFD 3 April 2, 2013 17:27
segmentation fault when installing OF-2.1.1 on a cluster Rebecca513 OpenFOAM Installation 9 July 31, 2012 15:06


All times are GMT -4. The time now is 09:27.