|
[Sponsors] |
May 14, 2018, 19:04 |
Segmentation error with DEFINE_SOURCE
|
#1 |
New Member
Masoud Mo
Join Date: May 2018
Posts: 6
Rep Power: 8 |
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; } |
|
May 15, 2018, 06:43 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Your problem is in the line
Code:
thsec = THREAD_SUB_THREAD(thmix,3); 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. |
|
May 15, 2018, 08:40 |
|
#3 |
Member
annan
Join Date: Nov 2016
Posts: 72
Rep Power: 10 |
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 |
|
May 15, 2018, 11:57 |
|
#4 |
New Member
Masoud Mo
Join Date: May 2018
Posts: 6
Rep Power: 8 |
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] |
|
May 15, 2018, 12:04 |
|
#5 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
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 |
|
May 15, 2018, 12:08 |
|
#6 |
New Member
Masoud Mo
Join Date: May 2018
Posts: 6
Rep Power: 8 |
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, |
|
May 15, 2018, 12:22 |
|
#7 | |
New Member
Masoud Mo
Join Date: May 2018
Posts: 6
Rep Power: 8 |
Quote:
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. |
||
|
|
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 22:59 |
Segmentation fault in SU2 V5.0 | ygd | SU2 | 2 | March 1, 2017 05:38 |
Segmentation fault when running in parallel | Pj. | OpenFOAM Running, Solving & CFD | 3 | April 8, 2015 09:12 |
Segmentation Fault w/ compiled OF 2.2.0 - motorBike example | sudo | OpenFOAM Running, Solving & CFD | 3 | April 2, 2013 18:27 |
segmentation fault when installing OF-2.1.1 on a cluster | Rebecca513 | OpenFOAM Installation | 9 | July 31, 2012 16:06 |