CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   fluentError: received a fatal signal (Segmentation fault). (https://www.cfd-online.com/Forums/fluent-udf/140631-fluenterror-received-fatal-signal-segmentation-fault.html)

thomaszhangjing August 19, 2014 22:50

fluentError: received a fatal signal (Segmentation fault).
 
I‘m now simulating the gas-liquid two-phase flow in vertical pipe. I have written UDF including adjust function and diffusivity function. When i loaded the adjust function, the case can be calculated.However, once i added the diffusivity function, the error appeared as shown below:

Error: received a fatal signal (Segmentation fault).

Error: received a fatal signal (Segmentation fault).
Error Object: #f


The UDF is presented below, i couldn't find the reason for the error for a long time. Could anyone do me a favor? Thank you very much!!!


#include "udf.h"

/* Define which user-defined scalars to use. */
enum
{
MF=0,
N_REQUIRED_UDS
};

DEFINE_ADJUST(adjust_droplet_mass_fraction, mixture_domain)
{
cell_t c;
Thread **pt;
Thread *cell_threads;
/* Domain *mixture_domain; /* t is mixture_thread according to the definition of the ADJUST Macro */
mixture_domain = Get_Domain(1);

/* Make sure there are enough user defined-scalars. */
if (n_uds < N_REQUIRED_UDS)
Internal_Error("not enough user-defined scalars allocated");

/* Fill UDS with the variable. */
mp_thread_loop_c(cell_threads, mixture_domain, pt)
{
begin_c_loop (c,cell_threads)
{
C_UDSI(c,cell_threads,MF)= C_VOF(c,pt[1])*C_VOLUME(c,cell_threads)*C_R(c,pt[1])/(C_VOF(c,pt[1])*C_VOLUME(c,cell_threads)*C_R(c,pt[1])+C_VOF(c,pt[0])*C_VOLUME(c,cell_threads)*C_R(c,pt[0])); /*DEFINE the mass fraction of the droplet, the scalar*/
}
end_c_loop (c,cell_threads)
}
}



#include "udf.h"

DEFINE_DIFFUSIVITY(my_uds_diffusivity,c,t,i)
{
/*int phase_domain_index=0;*/
Thread **primary_t=THREAD_SUB_THREADS(t); /* primary phase pointer*/
return C_R(c,primary_t[0])*C_MU_EFF(c,primary_t[0])*C_R(c,primary_t[0])*C_K(c,t)*C_K(c,t)/C_D(c,t);
}

polaritus September 11, 2014 05:45

The segmentation fault means that you try to access a variable, which is not saved.

The problem might be with the C_D turbulent kinetic energy dissipation rate. Do you use the k-epsilon model? If you use anything different, like k-omega, then the epsilon is not saved, and when you call C_D, you will have a segmentation fault.

Try to use epsilon = 0.09*omega * k instead.

alinik November 3, 2016 12:12

Quote:

Originally Posted by polaritus (Post 509945)
The segmentation fault means that you try to access a variable, which is not saved.

The problem might be with the C_D turbulent kinetic energy dissipation rate. Do you use the k-epsilon model? If you use anything different, like k-omega, then the epsilon is not saved, and when you call C_D, you will have a segmentation fault.

Try to use epsilon = 0.09*omega * k instead.

Hi Rita,

Is there anyway to trace and find what variable is causing this error? Also what is the workaround to this problem?

alinik December 9, 2016 16:14

Thomas, did you solve this?

Quote:

Originally Posted by thomaszhangjing (Post 506728)
I‘m now simulating the gas-liquid two-phase flow in vertical pipe. I have written UDF including adjust function and diffusivity function. When i loaded the adjust function, the case can be calculated.However, once i added the diffusivity function, the error appeared as shown below:

Error: received a fatal signal (Segmentation fault).

Error: received a fatal signal (Segmentation fault).
Error Object: #f


The UDF is presented below, i couldn't find the reason for the error for a long time. Could anyone do me a favor? Thank you very much!!!


#include "udf.h"

/* Define which user-defined scalars to use. */
enum
{
MF=0,
N_REQUIRED_UDS
};

DEFINE_ADJUST(adjust_droplet_mass_fraction, mixture_domain)
{
cell_t c;
Thread **pt;
Thread *cell_threads;
/* Domain *mixture_domain; /* t is mixture_thread according to the definition of the ADJUST Macro */
mixture_domain = Get_Domain(1);

/* Make sure there are enough user defined-scalars. */
if (n_uds < N_REQUIRED_UDS)
Internal_Error("not enough user-defined scalars allocated");

/* Fill UDS with the variable. */
mp_thread_loop_c(cell_threads, mixture_domain, pt)
{
begin_c_loop (c,cell_threads)
{
C_UDSI(c,cell_threads,MF)= C_VOF(c,pt[1])*C_VOLUME(c,cell_threads)*C_R(c,pt[1])/(C_VOF(c,pt[1])*C_VOLUME(c,cell_threads)*C_R(c,pt[1])+C_VOF(c,pt[0])*C_VOLUME(c,cell_threads)*C_R(c,pt[0])); /*DEFINE the mass fraction of the droplet, the scalar*/
}
end_c_loop (c,cell_threads)
}
}



#include "udf.h"

DEFINE_DIFFUSIVITY(my_uds_diffusivity,c,t,i)
{
/*int phase_domain_index=0;*/
Thread **primary_t=THREAD_SUB_THREADS(t); /* primary phase pointer*/
return C_R(c,primary_t[0])*C_MU_EFF(c,primary_t[0])*C_R(c,primary_t[0])*C_K(c,t)*C_K(c,t)/C_D(c,t);
}


raviramesh10 June 3, 2017 06:27

Doubt regarding UDF
 
Hello everyone,

I am simulating the behaviour of the non-Newtonian fluid, Colgate on top of a vibrating membrane of a speaker. I have been working on a UDF to apply on a vibrating membrane, giving it a sinusoidal input velocity, i.e.,
v =v0* cos(pi*x/L)*sin(2*pi*f*t)

Where v0 is the maximum velocity achieved by the vibrating membrane and pi is already defined. f is the input frequency which I have obtained from previous experiments.

The code I have written is as follows, but it shows a segmentation error:

#include "udf.h"
#include "dynamesh_tools.h"
#define pi 22/7
DEFINE_GRID_MOTION(inlet_y_velocity,d,dt,time,dtim e)
{
Thread *t;
real y[ND_ND];
real x_c;
face_t f;
int n;
begin_f_loop(f,t,n)
{
x_c=y[0];
y[0]=.2*cos((pi*x_c)/.08)*sin(2*pi*120*time);
}
end_f_loop(f,t)
}

I would be highly grateful if somebody could help me on the same.

SPH_CFD June 4, 2017 03:02

Quote:

Originally Posted by raviramesh10 (Post 651453)
Hello everyone,

I am simulating the behaviour of the non-Newtonian fluid, Colgate on top of a vibrating membrane of a speaker. I have been working on a UDF to apply on a vibrating membrane, giving it a sinusoidal input velocity, i.e.,
v =v0* cos(pi*x/L)*sin(2*pi*f*t)

Where v0 is the maximum velocity achieved by the vibrating membrane and pi is already defined. f is the input frequency which I have obtained from previous experiments.

The code I have written is as follows, but it shows a segmentation error:

#include "udf.h"
#include "dynamesh_tools.h"
#define pi 22/7
DEFINE_GRID_MOTION(inlet_y_velocity,d,dt,time,dtim e)
{
Thread *t;
real y[ND_ND];
real x_c;
face_t f;
int n;
begin_f_loop(f,t,n)
{
x_c=y[0];
y[0]=.2*cos((pi*x_c)/.08)*sin(2*pi*120*time);
}
end_f_loop(f,t)
}

I would be highly grateful if somebody could help me on the same.

Firstly, I think definition of Pi should be
#define pi 3.1416

Secondly, what is your output? Because in your code, you write
x_c=y[0];
y[0]=.2*cos((pi*x_c)/.08)*sin(2*pi*120*time);

Don't have any initialization

y[0] don't have any value and after that you insert into x_c. And then use x_c to calculate y[0]. It means that you only calculate null ???

raviramesh10 June 4, 2017 05:42

Quote:

Originally Posted by SPH_CFD (Post 651551)
Firstly, I think definition of Pi should be
#define pi 3.1416

Secondly, what is your output? Because in your code, you write
x_c=y[0];
y[0]=.2*cos((pi*x_c)/.08)*sin(2*pi*120*time);

Don't have any initialization

y[0] don't have any value and after that you insert into x_c. And then use x_c to calculate y[0]. It means that you only calculate null ???

OK, sir, I will do the needful.
My output is supposed to be the vibrating membrane vibrating with a sinusoidal velocity input given. I understood the error there.
But doesn't y[0] imply that I am initializing the y-velocity component?

I have done some editing. Does the below code make more sense?

#include "udf.h"
#include "dynamesh_tools.h"
#define pi 3.1416
DEFINE_GEOM(plane,domain,dt,position)
{
position[1]=0.001;
}
DEFINE_GRID_MOTION(inlet_y_velocity,d,dt,time,dtim e)
{
Thread *t;
real y[ND_ND];
real x_c;
face_t f;
real v;
Node *w;
int n;
SET_DEFORMING_THREAD_FLAG(THREAD_TO(t));

begin_f_loop(f,t)
{
f_node_loop(f,t)
{
w = F_NODE(f,t,n);
if (NODE_X(v)>0 && NODE_X(v)<0.08 && NODE_Y(v)==0 && NODE_POS_NEED_UPDATE(v))
{
NODE_POS_UPDATED(v);
v=.2*cos((pi*x_c)/.08)*sin(2*pi*120*time);
}
end_f_loop(f,t)
}
}

Severus June 19, 2017 05:11

Hello,
Usually we get segmentation error in UDM when we have used it in a UDF but havent set the number of UDMs in fluent GUI.

When we compile a UDF in which we use a UDM, before compiling we should go to DEFINE->User Defined->Memory and Set the number as you wish

Hope this helps

Severus June 19, 2017 05:17

Quote:

Originally Posted by Severus (Post 653890)
Hello,
Usually we get segmentation error in UDM when we have used it in a UDF but havent set the number of UDMs in fluent GUI.

When we compile a UDF in which we use a UDM, before compiling we should go to DEFINE->User Defined->Memory and Set the number as you wish

Hope this helps

Sorry by mistake posted in this Forum, and unable to delete

furqanrk June 30, 2017 03:05

Received a fatal Signal ( Segmentation fault )
 
Hi everyone !

I hope you are fine. I am using UDF in VOF model in ANSYS FLUENT, although, my VOF model without UDF is running fine. The UDF is written by my friend used it successfully. He has graduated last year after getting the results from same UDF. The UDF was working well on his server. He was using Fluent 6.3 on Linux system. When I am using same case, date and UDF on my laptop the case is not running, although UDF compilation is very fine. I also check it on Linux system too. During or after initialization, Error occurred segmentation fault error. It is very strange that same case and UDF is not working on his office now. Main error occurred when I am hooking ADJUST and EXECUTE-AT-END UDFs. May be there is some problem of writing/calling style is different in Windows and Linux system with 32bit and 64bit. ( this is just my opinion).

I hope you can understand the situation and have a try to fix the problem. I would be highly thankful if you guide me that where is the problem. I can send UDF by email if needed..

Thanks in Advance,
Regards,
M. F. ALi

paoching September 6, 2018 18:57

Please have a look at my UDF and let me know what could be causing Segmentation error
 
Hi all, I'm writing a udf for galvanic corrosion damage. Below is my code. I was able to compile and load it, but ran into segmentation fault when I tried to run it. Please take a look and give me some ideas on how to fix it.
Code:

/**********************************************************
 node motion based on corrosion rate calculated from electric
 current density compiled UDF
 **********************************************************/
#include "udf.h"
#include "metric.h"
#include "mem.h"
#include "sg_udms.h"
#include "sg.h"
#include "models.h"
#include "dynamesh_tools.h"
DEFINE_GRID_MOTION(corrosion_rate,domain,dt,time,dtime)
{       
        Thread        *tf = DT_THREAD(dt);
        face_t        f;
        cell_t        c;
        Node        *v;
        real        y;
        int                n;
        real        F=96485.34;                //Faraday's constant C/mol or A*s/mol
        real        MWT=26.981539;        //molecular weight
        int                z=3;                        //al ion charge#
        real        RHO=2700000;        //Al density g/m^3
        real        sigma=5;
        real        k=(-sigma*MWT/(z*F*RHO));
        thread_loop_c (tf,domain)
        {
                begin_c_loop (c,tf)
                {
                        C_UDMI(c,tf,0) = k*C_PHI_1_G(c,tf)[1];
                }
                end_c_loop (c,tf)
        }
        /* set deforming flag on adjacent cell zone */
        SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf));
        Message ("time = %f, Cr = %f\n", time);
        begin_f_loop(f,tf)
                {
                        f_node_loop(f,tf,n)
                        {
                                v = F_NODE(f,tf,n);
                                if (NODE_POS_NEED_UPDATE (v))
                                {
                                        /* indicate that node position has been update
                                        so that it's not updated more than once */
                                        NODE_POS_UPDATED(v);
                                        NODE_Y(v) -= C_UDMI(c,tf,0)*dtime;        //new y position
                                }
                        }
                }
        end_f_loop(f,tf);
}

Here is the error message I get:
Quote:

Error: received a fatal signal (Segmentation fault).
Error Object: #f

luqz January 13, 2021 09:37

a little tips
 
Quote:

Originally Posted by thomaszhangjing (Post 506728)
I‘m now simulating the gas-liquid two-phase flow in vertical pipe. I have written UDF including adjust function and diffusivity function. When i loaded the adjust function, the case can be calculated.However, once i added the diffusivity function, the error appeared as shown below:

Error: received a fatal signal (Segmentation fault).

Error: received a fatal signal (Segmentation fault).
Error Object: #f


The UDF is presented below, i couldn't find the reason for the error for a long time. Could anyone do me a favor? Thank you very much!!!


#include "udf.h"

/* Define which user-defined scalars to use. */
enum
{
MF=0,
N_REQUIRED_UDS
};

DEFINE_ADJUST(adjust_droplet_mass_fraction, mixture_domain)
{
cell_t c;
Thread **pt;
Thread *cell_threads;
/* Domain *mixture_domain; /* t is mixture_thread according to the definition of the ADJUST Macro */
mixture_domain = Get_Domain(1);

/* Make sure there are enough user defined-scalars. */
if (n_uds < N_REQUIRED_UDS)
Internal_Error("not enough user-defined scalars allocated");

/* Fill UDS with the variable. */
mp_thread_loop_c(cell_threads, mixture_domain, pt)
{
begin_c_loop (c,cell_threads)
{
C_UDSI(c,cell_threads,MF)= C_VOF(c,pt[1])*C_VOLUME(c,cell_threads)*C_R(c,pt[1])/(C_VOF(c,pt[1])*C_VOLUME(c,cell_threads)*C_R(c,pt[1])+C_VOF(c,pt[0])*C_VOLUME(c,cell_threads)*C_R(c,pt[0])); /*DEFINE the mass fraction of the droplet, the scalar*/
}
end_c_loop (c,cell_threads)
}
}



#include "udf.h"

DEFINE_DIFFUSIVITY(my_uds_diffusivity,c,t,i)
{
/*int phase_domain_index=0;*/
Thread **primary_t=THREAD_SUB_THREADS(t); /* primary phase pointer*/
return C_R(c,primary_t[0])*C_MU_EFF(c,primary_t[0])*C_R(c,primary_t[0])*C_K(c,t)*C_K(c,t)/C_D(c,t);
}

I try a similar code as you did. when i delete the liquid gas, only kept the mixture of the gas then i worked. so i guess the thread of mixture_thread only points to mixture material rather than the liquid phase, so it makes the fluent confuse.


All times are GMT -4. The time now is 06:07.