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/)
-   -   Segmentation fault while initialization of F_UDMI, why? (https://www.cfd-online.com/Forums/fluent-udf/173776-segmentation-fault-while-initialization-f_udmi-why.html)

Niels W. June 27, 2016 11:20

Segmentation fault while initialization of F_UDMI, why?
 
Hi everyone,

i dont understand why i get an segmentation fault in my code:

#include "udf.h"
#define NUM_UDM 1
static int udm_offset = UDM_UNRESERVED;

DEFINE_ON_DEMAND(on_loading)
{
if (udm_offset == UDM_UNRESERVED)
udm_offset = Reserve_User_Memory_Vars(NUM_UDM);

if (udm_offset == UDM_UNRESERVED)
Message("\nYou need to define up to %d extra UDMs in GUI and then reload
current library \n", NUM_UDM);
else
{
Message("%d UDMs have been reserved by the current library \n",NUM_UDM);
Set_User_Memory_Name(udm_offset,"Mass");
}
Message("\nUDM Offset for Current Loaded Library = %d \n",udm_offset);
}

DEFINE_ON_DEMAND(Mass_init)
{
Domain *d;
d=Get_Domain(1);
Thread *t;
face_t f;
if(udm_offset != UDM_UNRESERVED)
{
Message("\nSetting Mass. ");
thread_loop_f(t,d)
{
if(BOUNDARY_FACE_THREAD_P(t)){
begin_f_loop(f,t)
{
F_UDMI(f,t,udm_offset)=42;
}
end_f_loop(f,t)
}
}
Message("Done.\n");
}
else
Message("UDM: Mass have not yet been reserved for library\n");
}

When i execute on demand "on_loading" with 1 memory location:

"1 UDMs have been reserved by the current library

UDM Offset for Current Loaded Library = 0"

after that i execute "Mass_init":

"Setting Mass.
Error: received a fatal signal (Segmentation fault).


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

Where is my fault? Thank you very much!

br,
Niels

Bruno Machado June 28, 2016 04:57

Quote:

Originally Posted by Niels W. (Post 606796)
Hi everyone,

i dont understand why i get an segmentation fault in my code:

#include "udf.h"
#define NUM_UDM 1
static int udm_offset = UDM_UNRESERVED;

DEFINE_ON_DEMAND(on_loading)
{
if (udm_offset == UDM_UNRESERVED)
udm_offset = Reserve_User_Memory_Vars(NUM_UDM);

if (udm_offset == UDM_UNRESERVED)
Message("\nYou need to define up to %d extra UDMs in GUI and then reload
current library \n", NUM_UDM);
else
{
Message("%d UDMs have been reserved by the current library \n",NUM_UDM);
Set_User_Memory_Name(udm_offset,"Mass");
}
Message("\nUDM Offset for Current Loaded Library = %d \n",udm_offset);
}

DEFINE_ON_DEMAND(Mass_init)
{
Domain *d;
d=Get_Domain(1);
Thread *t;
face_t f;
if(udm_offset != UDM_UNRESERVED)
{
Message("\nSetting Mass. ");
thread_loop_f(t,d)
{
if(BOUNDARY_FACE_THREAD_P(t)){
begin_f_loop(f,t)
{
F_UDMI(f,t,udm_offset)=42;
}
end_f_loop(f,t)
}
}
Message("Done.\n");
}
else
Message("UDM: Mass have not yet been reserved for library\n");
}

When i execute on demand "on_loading" with 1 memory location:

"1 UDMs have been reserved by the current library

UDM Offset for Current Loaded Library = 0"

after that i execute "Mass_init":

"Setting Mass.
Error: received a fatal signal (Segmentation fault).


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

Where is my fault? Thank you very much!

br,
Niels

looks like udm_offset is not the name (or number) of your UDM but how many UDMs you have. I think you gotta define your UDM like this

enum /* UDMs */
{
mass, /*whatever the name you want*/
NUM_UDM
};

Then change the following line

F_UDMI(f,t,mass)=42;

And exclude this one
#define NUM_UDM 1


All times are GMT -4. The time now is 05:11.