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

SEGMENTATION fault while using DEFINE_PROPERTY macro

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 24, 2018, 09:57
Post SEGMENTATION fault while using DEFINE_PROPERTY macro
  #1
New Member
 
Leonard
Join Date: Dec 2017
Posts: 4
Rep Power: 8
leo1993 is on a distinguished road
Dear all,

I am relatively new to programming in c, and completely new in writing UDF's for Fluent. Now, I want to write an UDF that defines the thermal conductivity for the primary phase and the secondary phase. I am using the DEFINE_PROPERTY macro to do this. I have tried this in the following way:
Code:
/*********************************************************************
   UDF that simulates the correlation for the conductivity proposed by Shen et al.                                    
**********************************************************************/
#include "udf.h"

DEFINE_PROPERTY(cell_conductivity,cell,thread)
{
	/* Variable fluid properties for water-vapor subcooling @353.15 K as defined by Mills */
        real T_SAT 						= 373.15;
	real k_v 						= 24.8e-3;
	real k_l						= 0.674;
	real ktc_;
	/* Enhancement factor n, as proposed by Shen. Enhances the energy transportation in the two-phase region. */
	real n 							= 1.;
	
	Domain *subdomain_gas;
	Domain *subdomain_liq;
	int phase_domain_index_gas; 		
	int phase_domain_index_liq;
	Thread *gas;
	Thread *liq;
	real temp;
	
	subdomain_gas 					= Get_Domain(2);										/* retrieve pointer to primary phase domain */
	subdomain_liq 					= Get_Domain(3);										/* retrieve pointer to secondary phase domain */
	phase_domain_index_gas 			        = PHASE_DOMAIN_INDEX(subdomain_gas);				
	phase_domain_index_liq 			        = PHASE_DOMAIN_INDEX(subdomain_liq);
        gas 						= THREAD_SUB_THREAD(thread, phase_domain_index_gas);
        liq 						= THREAD_SUB_THREAD(thread, phase_domain_index_liq); 
	temp 					        = C_T(cell,thread);


  
	if (temp >= T_SAT){
		ktc_ = C_VOF(cell,liq) * k_l + C_VOF(cell,gas) * k_v;
	}
	else {
		ktc_ = C_VOF(cell,liq) * k_l + n * C_VOF(cell,gas) * k_v;
	}
	return ktc_;
}
The problem is the following. I am able to compile the code and to load it, but when I specify the user defined conductivity in the material properties, I receive a segmentation fault.
I would be very happy if someone could help me. Also, feel free to give any tips on programming if you like.

Cheers!
leo1993 is offline   Reply With Quote

Old   January 25, 2018, 04:43
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
This UDF needs some data to work, specifically the temperature and the VOF.
If you attach this UDF before initializing data, and Fluent wants to calculate the conductivity, Fluent will try to get the temperature/VOF, and fail, and give an error.

The simplest solution: initialize your data first (with a constant conductivity), and attach the UDF after that.
pakk is offline   Reply With Quote

Old   January 25, 2018, 04:59
Default
  #3
New Member
 
Leonard
Join Date: Dec 2017
Posts: 4
Rep Power: 8
leo1993 is on a distinguished road
I tried this, but this didn't work. I still receive the segmentation error. Any other suggestions?
leo1993 is offline   Reply With Quote

Old   January 25, 2018, 06:51
Default
  #4
New Member
 
Leonard
Join Date: Dec 2017
Posts: 4
Rep Power: 8
leo1993 is on a distinguished road
After doing some tests, I found out that C_VOF(c,t), returns the volume fraction of the secondary phase (seems counter-intuitive). Then I could fix the problem in the following way.
Code:
/*********************************************************************
   UDF that simulates the correlation for the conductivity proposed by Shen et al.                                    
**********************************************************************/
#include "udf.h"

DEFINE_PROPERTY(cell_conductivity,cell,thread)
{
	/* Variable fluid properties for water-vapor subcooling @353.15 K as defined by Mills */
        real T_SAT 		     		                = 373.15;
	real k_v 						= 0.0248;
	real k_l						= 0.674;
	real ktc_;
	/* Enhancement factor n, as proposed by Shen. Enhances the energy transportation in the two-phase region. */
	real n 							= 1.;
	real temp;	
	temp 							= C_T(cell,thread);
	
    ktc_ = 0.;
	if (temp >= T_SAT)
	{
		ktc_ = C_VOF(cell,thread) * k_l + (1-C_VOF(cell,thread)) * k_v;
	}
	else 
	{
		ktc_ = C_VOF(cell,thread) * k_l + n * (1-C_VOF(cell,thread)) * k_v;
	}
	return ktc_;
}
I checked the solution with hand calculations, and it worked out! However, I am still wondering what went wrong in the first code.
leo1993 is offline   Reply With Quote

Old   January 25, 2018, 06:58
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Eliminate the possible problems...

Does it work if you remove temperature?
Code:
DEFINE_PROPERTY(cell_conductivity,cell,thread)
{
    /* Variable fluid properties for water-vapor subcooling @353.15 K as defined by Mills */
        real T_SAT                         = 373.15;
    real k_v                         = 24.8e-3;
    real k_l                        = 0.674;
    real ktc_;
    /* Enhancement factor n, as proposed by Shen. Enhances the energy transportation in the two-phase region. */
    real n                             = 1.;
    
    Domain *subdomain_gas;
    Domain *subdomain_liq;
    int phase_domain_index_gas;         
    int phase_domain_index_liq;
    Thread *gas;
    Thread *liq;
    real temp;
    
    subdomain_gas                     = Get_Domain(2);                                        /* retrieve pointer to primary phase domain */
    subdomain_liq                     = Get_Domain(3);                                        /* retrieve pointer to secondary phase domain */
    phase_domain_index_gas                     = PHASE_DOMAIN_INDEX(subdomain_gas);                
    phase_domain_index_liq                     = PHASE_DOMAIN_INDEX(subdomain_liq);
        gas                         = THREAD_SUB_THREAD(thread, phase_domain_index_gas);
        liq                         = THREAD_SUB_THREAD(thread, phase_domain_index_liq); 
    temp                             = 300.;    /* <-- change is here! */


  
    if (temp >= T_SAT){
        ktc_ = C_VOF(cell,liq) * k_l + C_VOF(cell,gas) * k_v;
    }
    else {
        ktc_ = C_VOF(cell,liq) * k_l + n * C_VOF(cell,gas) * k_v;
    }
    return ktc_;
}
If so, your problem is with temperature. If not, simplify it further. (Replace C_VOF by a constant value, and so on.)
Knowing which part of the code is really given problems, makes it much easier to find the solution.
pakk is offline   Reply With Quote

Old   January 26, 2018, 06:56
Default
  #6
New Member
 
Leonard
Join Date: Dec 2017
Posts: 4
Rep Power: 8
leo1993 is on a distinguished road
The problem lies in C_VOF(cell, liq) or C_VOF(cell, gas). Now I have tried to fix this the following way.
Code:
#include "udf.h"

DEFINE_PROPERTY(cell_conductivity,c,thread)

{
	/* Variable fluid properties for water-vapor subcooling @353.15 K as defined by Mills */
    real T_SAT 						= 373.1;
	real k_v 						= 0.0248;
	real k_l						= 0.674;
	real ktc_;
	
	/* Enhancement factor n, as proposed by Shen. Enhances the energy transportation in the two-phase region. */
	real n 							= 1.;
	
	real temp						= C_T(c,thread);
	Domain *mix_domain = Get_Domain(1);
	Thread *mix_thread;
	Thread **pt;

	mp_thread_loop_c(mix_thread, mix_domain, pt)
	{	
		ktc_ = 0.;
		if (temp >= T_SAT)
		{
			ktc_ = C_VOF(c,pt[1]) * k_l + C_VOF(c,pt[0]) * k_v;
		}
		else 
		{
			ktc_ = C_VOF(c,pt[1]) * k_l + n * C_VOF(c,pt[0]) * k_v;
		}
		Message(": %g\n", C_VOF(c,pt[0]));
	}
	
	return (ktc_);
}
However, the weird thing is that, when initializing, the message produces 1's, 0's and the density of the primary phase. While I think it should only produce 1's. FYI, when initialized, there is only the primary phase in the domain (vapor).
After doing some other tests, I found out that C_VOF(c,pt[1])) always returns '1', and C_VOF(c,pt[0]) always returns '0'. But why? It should return the volume fraction right?
Any other suggestions to obtain the volume fraction of a cell?
leo1993 is offline   Reply With Quote

Reply

Tags
define_property, segmentaion fault, udf


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 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


All times are GMT -4. The time now is 21:41.