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

Thread has not been initialized

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 20, 2015, 09:16
Default Thread has not been initialized
  #1
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 11
edu_aero is on a distinguished road
I would really appreciate that someone would be able to help me facing the following problem.

I am creating a (compiled) code in order to calculate the Mass flow in different sections.
A part of that code is located here. I compile it, however Fluent tells me that 't' has not been initialized. Nevertheless I don't understand why when I have written
Code:
 Thread *t;
So that, Error: received a fatal signal (Segmentation fault). is producced in the line when I try to get the possition of the Centroid of the face.

Attached the code can be found

Code:
#include "udf.h"
//#include <math.h>
#define Num_div 5

DEFINE_ADJUST(GetMassFlow,d)
{
    Thread *t;
    face_t f;

    int n=0;                 
    real Area;
    real SUMflow=0;
    real x[ND_ND];
    real N[ND_ND];

/////////////////////////////////////////////////////////////////////////////    
        begin_f_loop(f,t)//thread_loop_c(t, d)                                            // Variable that stores the SUM of Mass Flow is initialized to zero
        {
            Message("1 ");
            F_CENTROID(x,f,t);
            Message("2 ");
                F_AREA(N,f,t);
                Message("3 ");
                Area=  sqrt(N[0]*N[0]+N[1]*N[1]+N[2]*N[2]);
                Message("4 ");
                N[2]=N[2]/(Area);
                SUMflow+=F_FLUX(f,t)*N[2];
        }
        end_f_loop(f,t)
    Message ("%f\t",SUMflow);
    Message ("\n");
}
I don't understand why is happening it.
Thank you very much
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 21, 2015, 06:08
Default
  #2
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
you can add this in your code:
Code:
int Zone_ID = (ID OF THE THREAD YOU WANT);
Thread *t=Lookup_Thread(d,Zone_ID);
This should work.
Bruno Machado is offline   Reply With Quote

Old   September 21, 2015, 21:30
Default
  #3
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 11
edu_aero is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
you can add this in your code:
Code:
int Zone_ID = (ID OF THE THREAD YOU WANT);
Thread *t=Lookup_Thread(d,Zone_ID);
This should work.
Thank you very much!! =)
With your advise that I solved part of the problem, because now I am facing a segmentation error when I am getting the information of density and velocity.
Code:
      Density=F_R(f,thread_fluid);
      VelocityZ=F_W(f,thread_fluid);
I think, that it can be because the thread is not corrected, am I right?
However, I haven't managed to fix it
Code:
#include "udf.h"

#define Lz 0.006 //[m^2]
DEFINE_ADJUST(cells_faces,domain)
{
  //Thread *t;                /* this will hold the position vector */
  face_t f;
  int i=0;
  int j=0;
  real x[ND_ND];
  real N[ND_ND];
  real SumMassFlow=0;
  real SumArea=0;
  real AverageMassFlow=0;
  real Density=0;
  real VelocityZ=0;

  int zone_ID = 20048;
  Thread *thread_fluid;
  thread_fluid = Lookup_Thread(domain,zone_ID);

//thread_loop_f(thread_fluid, domain)
//{
  j=j+1;
  begin_f_loop(f,thread_fluid)
    {
      SumArea=0;
      SumMassFlow=0;
      F_AREA(N,f,thread_fluid);
      F_CENTROID(x,f,thread_fluid);
      i=i+1;
      Message("Until here works properly =)");
      Density=F_R(f,thread_fluid);
      VelocityZ=F_W(f,thread_fluid);
      SumMassFlow=Density*N[2]*VelocityZ+SumMassFlow;
      SumArea=SumArea+N[2];
    }
  end_f_loop(f,thread_fluid)
      AverageMassFlow=SumMassFlow*Lz/SumArea;
  Message("\n%d\t%d",i,j);
  Message("\nSUM_FLOW : %f\n",SumMassFlow);
  Message("Cont_max: %d, Cont_min: %d", AverageMassFlow);
//}
}
Thank you beforehand if someone is able to help me =)

Edu
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 22, 2015, 05:38
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Compile it.
Make sure your computer can compile (explanation is elsewhere on this forum), and from then on use "compile", not "interpret". It is worth the effort.

I am not sure if it will solve your current problem, but it might, and otherwise it will help you a lot in the future.
pakk is offline   Reply With Quote

Old   September 22, 2015, 19:47
Default
  #5
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 11
edu_aero is on a distinguished road
Quote:
Originally Posted by pakk View Post
Compile it.
Make sure your computer can compile (explanation is elsewhere on this forum), and from then on use "compile", not "interpret". It is worth the effort.

I am not sure if it will solve your current problem, but it might, and otherwise it will help you a lot in the future.
Hello, firstly thank you for answering to my question
I have already faced the problems of using interpreted codes, so I am having that error compiling the code.
I am using the compiler that Fluent recommends, Visual Studio. I am using the 2012 version of this programme

I am continue trying to solve that problem...

Thank you very much for your comment
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 24, 2015, 07:51
Default
  #6
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 11
edu_aero is on a distinguished road
Does someone know why I am having that error?
I have been searching on the Internet but without success...
I can't understand why when I initialize the density macro does not work, but it works perfectly with the previous functions just before

Thank you very much, I would really appreciate any kind of help
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 24, 2015, 08:05
Default
  #7
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by edu_aero View Post
Does someone know why I am having that error?
I have been searching on the Internet but without success...
I can't understand why when I initialize the density macro does not work, but it works perfectly with the previous functions just before

Thank you very much, I would really appreciate any kind of help
Some thoughts that came to my mind now. Don't you have to loop it through the cells as well? If the loop through the cells does not work, cant you save the values from a different code (write another DEFINE_ADJUST perhaps) in an UDMI and use inside your loop?
Bruno Machado is offline   Reply With Quote

Old   September 24, 2015, 10:24
Default
  #8
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 11
edu_aero is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
Some thoughts that came to my mind now. Don't you have to loop it through the cells as well? If the loop through the cells does not work, cant you save the values from a different code (write another DEFINE_ADJUST perhaps) in an UDMI and use inside your loop?
Thank you very much for response Bruno!!

I think that there is not mistake on the looping because according to Fluent http://jullio.pe.kr/fluent6.1/help/html/udf/node114.htm

You can use begin_f_loop and end_f_loop when you want to loop over all faces f in a given face thread f_thread.
I am able to run that code without the following lines:

Code:
Density=F_R(f,f_thread);
VelocityZ=F_W(f,f_thread);
It is defined 'i', to count the number of times that the loop is done, this number is equal to the number of faces on fluid, 1197980.



Whereas you comment opened my eyes, that may be the problem would be on the definition of the thread.
I have two different matterials on my simulation, one fluid and one solid.+
I am defining the thread in the following way:
Code:
int zone_ID = 20048;
/* Being zone 20048 the zone corresponding to the fluid,
it is a volumen/*

Thread *f_thread;
f_thread = Lookup_Thread(domain,zone_ID);



When I change the Zone ID from a volumen to a surface, like it is the inlet or the outlet surfaces works well.
So that, I want to pop up the question if the function Lookup_Thread(domain,zone_ID), work properly with volumen.

And about the second solution that you proposed, I didn't really understand you. You mean to create another code to get the value of the variables and store e.g in a '.txt' file and access to that file just after it?
But for that, wouldn't I need the ID face? Because I think that the problem to get the ID of the face would be the same

I am really really grateful for you trying to help me Bruno, seriously

Thank you very much!!
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 28, 2015, 15:01
Default
  #9
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 11
edu_aero is on a distinguished road
Doesn't someone know why I am facing that error?
Becuase I am trying more and more solutions but I am not able to find the problem...

Thank you to one that will just pop up an idea why it is not working.

Thank you beforehand
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 29, 2015, 04:32
Default
  #10
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You are trying to go through all internal faces of a volume to calculate something... In a volume, Fluent typically uses the cell values, not the face values, so you cannot access them directly.

And it doesn't make much sense what you are doing... If you want to get the massflow, you should calculate this over the outside boundaries of the volume, not the volume itself!
pakk is offline   Reply With Quote

Old   September 29, 2015, 09:54
Smile
  #11
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 11
edu_aero is on a distinguished road
Quote:
Originally Posted by pakk View Post
You are trying to go through all internal faces of a volume to calculate something... In a volume, Fluent typically uses the cell values, not the face values, so you cannot access them directly.

And it doesn't make much sense what you are doing... If you want to get the massflow, you should calculate this over the outside boundaries of the volume, not the volume itself!
Thank you very much for your answer Pakk!!

Firstly, I want to explain the puropose of the code, I have't done it yet and I want to apologize for it.

We are using the DPM model in order to modelize evaporization. In order to validate the results, the continuty of mass flow (droplets + gas) should be costant throughout the geometry.
Taking that into account, a code has successfully been created able to calculate the mass flow of the droplets in a defined region. Now, A new code focused on calculating the mass flow of gas in different sections want to be develope. The sum of both mass flow for different sections should be constant because of the continuity equation.

As u pakk said, it is true that Fluent can easily calculate the mass flow on the boundaries. Nevertheless, the mass flow want to be calculate in different sections on the middle of the volume, (sections according to the ones defined for calculating the mass flow with droplets)

For calculating it, I thought that a good aproximation it would be to define a possition in the axis Z (Direction of the flow), giving it a little increment, bigger than a cell (what has not been programmed yet in the code that is uploaded), and ponderate it by the number Area, which it is is known. This is done by the following coefficient.
Code:
Lz/SumArea
I don't know if I have explained myself properly, you would be more than welcome to ask me to clarify some explanation or for deeper details. Everything in order to solve the code programming .

Onces, an overview of the simulation has been seen. I am really interesing in something that you said:

Quote:
Originally Posted by pakk View Post
And it doesn't make much sense what you are doing... If you want to get the massflow, you should calculate this over the outside boundaries of the volume, not the volume itself!
So that, u suggest that I should loop through all the cells and then looping through the boundaries? am I right?

'Were someone find this post interesting in the future, the information of looping through the faces of a cell is here
http://www.cfd-online.com/Forums/flu...-cell-udf.html

So, if I am understand you properly, the loop 'begin_f_loop(f,thread_fluid)', goes to the cells of the thread_fluid and after it goes to the faces of the cells itself, am I right?

I really appreciate your answer, it has been really helpful and I would love if you can answer to this message anytime that you can.

Thank you very much pakk,

Edu
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 30, 2015, 05:57
Default
  #12
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
I can not follow everything what you say, but I get the feeling that you want to know mass flows internally. So, a simplified drawing:

Code:
+---------------------+----------------------
->  volume A          |     volume B       ->
+---------------------+----------------------
Here, A and B represent what you call "different sections on the middle of the volume". I know it is very simplified.

You know that droplets evaporate in volume A and B, and you know that (for example) 1 kg/s gas flow goes into volume A, and that 1.5 kg/s gas flow goes out of volume B, which means that 0.5 kg/s evaporated, but you want to check where it evaporated, to validate your code. And what would help is to know the amount of gas flow that goes from volume A to B.

If the boundary between A and B exists in your geometry as an interface, you can immediately calculate the mass flux through that boundary. You don't need a UDF for this.

If the boundary between A and B does not yet exist in your geometry, I would say the best way to go forward is to create it. Make a bounded plane at the right location, and calculate the mass flux through that plane. You don't need a UDF for this.

So, if I understand you problem correctly, it looks like you can do completely without UDFs, and can be ready in a few minutes.
pakk is offline   Reply With Quote

Old   October 1, 2015, 09:06
Default
  #13
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 11
edu_aero is on a distinguished road
Quote:
Originally Posted by pakk View Post
I can not follow everything what you say, but I get the feeling that you want to know mass flows internally. So, a simplified drawing:

Code:
+---------------------+----------------------
->  volume A          |     volume B       ->
+---------------------+----------------------
Here, A and B represent what you call "different sections on the middle of the volume". I know it is very simplified.

You know that droplets evaporate in volume A and B, and you know that (for example) 1 kg/s gas flow goes into volume A, and that 1.5 kg/s gas flow goes out of volume B, which means that 0.5 kg/s evaporated, but you want to check where it evaporated, to validate your code. And what would help is to know the amount of gas flow that goes from volume A to B.

If the boundary between A and B exists in your geometry as an interface, you can immediately calculate the mass flux through that boundary. You don't need a UDF for this.

If the boundary between A and B does not yet exist in your geometry, I would say the best way to go forward is to create it. Make a bounded plane at the right location, and calculate the mass flux through that plane. You don't need a UDF for this.

So, if I understand you problem correctly, it looks like you can do completely without UDFs, and can be ready in a few minutes.
Thank you very much for your answer again

What we are trying to do it is a little trickier. Having this volume>
+---------------------+----------------------------------------------
-> volume A|volume B|volume C|volume D|volume E|volume F ->
+---------------------+----------------------------------------------
A lot of different volumes want to be created. The interface, won't need to be definided (here the purpose of the macro).
The mass flow of the droplets vs the direction of the flow should be a graph similirar to this one
-----------------------------------------------------------------
.
..
...
.....
.......
..........
...............
..........................
.................................................. ...
.................................................. ........................................
-------------------------------------------------------------------------
The mass flow of liquid, should be the opposite. So that, as I tell before the sum should be constant.
This want to be used as a convergence criteria. So that, it is neccesary that a macro is created to calculate the mass flow of liquid for a lot of different sections in order to asure that convergence has been achieved.

For this I need to create a macro and I am struggling with the coding. The problem itself it is perfectly defined.

So for that, I would appreciate help with the problem that I am facing to create the macro.
Just now I am going to try to loop through all the faces of a determined cell and cross my fingers in order that it works

Thank you again,

Edu
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   October 3, 2015, 21:46
Default
  #14
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 11
edu_aero is on a distinguished road
Finally, after having been thinking and thinking, I have encloused the problem!!
I have two different materials on the simulation. I have steel (in order to simulate the interchange of heat) and the fluid.
Finally after trying a lot of different things, I am looping through all the faces of a zone_ID.

But there is a problem with the boundary faces between the fluid and the steel.
I can properly get the possition and the area. However, and only sometimes I get problems getting data as the density of the boundary face.
This makes sense, because Fluent doesn't know which density should use.
Nevertheless, I cannot undersant why it only happen sometimes and other times it give me back the density of the fluid.

This problem can be solved with an if=NULL. But I cannot do it that to the thread because it is pointing to the face and it has information, less information but the result wouldn't be NULL.

Because, it happens sometimes. I cannot use neither the index of the boundary, because I already tried and it didn't work

So, does someone has any idea of how to do it?
__________________
Having fun with CFD =)
edu_aero 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
Divergence detected in AMG solver: k when udf loaded google9002 Fluent UDF and Scheme Programming 3 November 8, 2019 00:34
udf problem jane Fluent UDF and Scheme Programming 37 February 20, 2018 05:17
Error messages atg enGrid 7 August 30, 2013 12:16
Installing OpenFOAM 1.6-ext on Ubuntu 11.10 immortality OpenFOAM Installation 17 May 6, 2013 18:43
Phase locked average in run time panara OpenFOAM 2 February 20, 2008 15:37


All times are GMT -4. The time now is 18:51.