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/)
-   -   UDF-DPM: Structure reference not implemented (https://www.cfd-online.com/Forums/fluent-udf/158884-udf-dpm-structure-reference-not-implemented.html)

edu_aero September 6, 2015 09:26

UDF-DPM: Structure reference not implemented
 
16-09-2015
Taking into account my experience related with udf and DPM. I strongly recommend to use 'compiled' functions, because structures as loop(p,I->p_init) or get Ilist = Get_dpm_injections() ONLY WORK WITH COMPILED CODES!!

---------------------------------------------------------------------------------------------------------------------------------------

Hello to everyone =)

I would like to ask you all a problem that I am facing with UDF.
It is likely that it is something quite easy. But it is the same time that I am using udf which I am struggling with it.

I am trying to implement a code in order to calculate the flow mass ratio of some droplets in the outlet. In order to do that, I want to develope a programme. However, while trying I have created some codes and all have a common same mistake, structure reference not implemented in the line where 'loop(p,I->p_init) ' is implemented.On the Internet, it seems like this loop is the way of looping through all the particles.

This is my code:

# include "udf.h"
# include "dpm.h" // However it is not neccesary, included in udf.h

DEFINE_ADJUST(TRY1, domain)
{
Particle *p;
Injection *I;
int i=0;
real sum=0;


loop(p,I->p_init)
{
i=i+1;
sum=sum+P_FLOW_RATE(p);
}

printf("P_FLOW_RATE(p)/i%s\n", sum/i);
}


I am not able even to loop through all the particles because the loop is not working.

Bruno Machado September 7, 2015 10:11

you are using a different language for the code than the UDF language used by Fluent. You should have a look at the macros in the fluent manual.

edu_aero September 7, 2015 10:42

Quote:

Originally Posted by Bruno Machado (Post 562760)
you are using a different language for the code than the UDF language used by Fluent. You should have a look at the macros in the fluent manual.

Firstly, I want to really grateful your colaboration because I am really struggling with this problem. :):):):)

I have checked the Fluent macro manual, and especially the chapter about DPM.

All specific DPM funtions are definided for all the particles, not just for some of them. So that, the manual doesn't describe how to do a loop through all the particles in order to get some data every iteration with a macro as DEFINE_ADJUST.

That was the reason that I started looking on the Internet, finding these loops that are not working for me.

May be, these functions are not working because I am creating an interpreted macro and in order to use these macros instead of a compiled macro.

I do not find the way to do a loop all over the particles :(

Bruno Machado September 7, 2015 10:53

Hi,

you can have a look at this link. All the loop macros are there. You need to define the cell and thread variables (cell_t c; Thread *t; for example) to loop all over the domain.

https://www.sharcnet.ca/Software/Flu...udf/node97.htm


To print a message in the screen you should use
Message("TEXT YOU WANT %f, TEXT %f\n", VARIABLE, VARIABLE1);

each %f shows one variable. \n is for new line.

I think this is a good start for you.

Good luck.

edu_aero September 7, 2015 11:42

Quote:

Originally Posted by Bruno Machado (Post 562772)
Hi,

you can have a look at this link. All the loop macros are there. You need to define the cell and thread variables (cell_t c; Thread *t; for example) to loop all over the domain.

https://www.sharcnet.ca/Software/Flu...udf/node97.htm


To print a message in the screen you should use
Message("TEXT YOU WANT %f, TEXT %f\n", VARIABLE, VARIABLE1);

each %f shows one variable. \n is for new line.

I think this is a good start for you.

Good luck.

Thank you very much again :):)
But on that website, it is describe all the loops through cell, faces...
However, there is nothing said on that website about looping through particles.
So I am on the same situation, I do not know who to get the information of all the particles.

Thank you very much, I appreciate it :D:D:D

Bruno Machado September 7, 2015 12:07

Quote:

Originally Posted by edu_aero (Post 562777)
Thank you very much again :):)
But on that website, it is describe all the loops through cell, faces...
However, there is nothing said on that website about looping through particles.
So I am on the same situation, I do not know who to get the information of all the particles.

Thank you very much, I appreciate it :D:D:D

Yes, there is no macro to loop over particles (at least I do not know any). Although I never used particles in my problems, I am sure particles are allocated in cells and threads. So for your particles, lets say p, you probably going to have something like p(c,t) (or p = variable(c,t)) and inside the loop through all cells and threads this information is going to be defined/calculated. I do not know if I make myself clear enough.

And if possible, compile it instead of interpreting. I have no trust at all in interpreted codes.

Good luck.

edu_aero September 7, 2015 14:49

Quote:

Originally Posted by Bruno Machado (Post 562780)
Yes, there is no macro to loop over particles (at least I do not know any). Although I never used particles in my problems, I am sure particles are allocated in cells and threads. So for your particles, lets say p, you probably going to have something like p(c,t) (or p = variable(c,t)) and inside the loop through all cells and threads this information is going to be defined/calculated. I do not know if I make myself clear enough.

And if possible, compile it instead of interpreting. I have no trust at all in interpreted codes.

Good luck.

Thank you again for your response =)

When I struggled doing a loop through all the particles . So that, I thought about doing it on the way that you are telling me now, looping through all the cells instead of particles. However, I will need a function that tell me 'TRUE' or 'FALSE' if a particle is inside a cell and the number of particles per ell, am I right? With that, it will be easy to create a macro to calculate anything related with the particles.

Nevertheless, the solution that you are telling me, it seems like the most likely to success.

Thank you again for your response, I really really appreciate it!! :):):):)

`e` September 7, 2015 17:15

You were correct in using "loop" (from your first post). However, "loop(p,I->p_init)" is only used for initialising unsteady particles; "loop(p,I->p)" is used otherwise. Have a read of this post for an example: http://www.cfd-online.com/Forums/flu...tml#post291187

edu_aero September 8, 2015 03:22

Quote:

Originally Posted by `e` (Post 562815)
You were correct in using "loop" (from your first post). However, "loop(p,I->p_init)" is only used for initialising unsteady particles; "loop(p,I->p)" is used otherwise. Have a read of this post for an example: http://www.cfd-online.com/Forums/flu...tml#post291187

Thank you very much 'e', your responses are always really useful for me.

I have to admit that you are right about it and I missunderstood, here it is the difference between both loops from this website:
http://www.eureka.im/357.html
loop(p, I->p)
{
}
In unsteady DPM calculations, if you want to initialize the transient particles, you will require the following loop
loop(p, I->p_init)
{
}

However, by changing in the intial code that I proposed the loop
loop(p, I->p_init), for the one that you told me (the corrected one)loop(p, I->p) I am facing the same mistake, 'structure reference not implemented'.

So, I want to ask to you. Are this loops definied for interpreted codes? Because, I have not been able to run a code using them yet.

`e` September 8, 2015 06:40

I recommend compiling all UDFs to avoid potentially creating extra errors (some functions require compiling the UDF instead of interpreting).

However, the injection stream 'I' in your UDF is not initialised. The macro you took this code snippet from must have already set an injection stream (for example with the DEFINE_DPM_INJECTION_INIT macro, 'I' is an argument).

First, declare an injection list variable:

Code:

Injection *Ilist = Get_dpm_injections();
Then, wrap your loop within another loop of injection streams:

Code:

loop(I, Ilist)
{
}


edu_aero September 8, 2015 09:04

Quote:

Originally Posted by `e` (Post 562940)
I recommend compiling all UDFs to avoid potentially creating extra errors (some functions require compiling the UDF instead of interpreting).

However, the injection stream 'I' in your UDF is not initialised. The macro you took this code snippet from must have already set an injection stream (for example with the DEFINE_DPM_INJECTION_INIT macro, 'I' is an argument).

First, declare an injection list variable:

Code:

Injection *Ilist = Get_dpm_injections();
Then, wrap your loop within another loop of injection streams:

Code:

loop(I, Ilist)
{
}



Thank you again for your fast response :)

1-. I have read on the Fluent macro tutorial guide that it is neccesary to have installed Visual Studio in order to run compiled code in a Windows computer, am I right?

For me, and taking into account my little knowledge about this part of Fluent, it seems that the errors that I am facing is because using interpreted instead of compiled codes.

2-a. At adding the following line in following code "Injection *Ilist = Get_dpm_injections();". The error is the same, structure reference not implemented.
Code:

# include "udf.h"
# include "dpm.h"

DEFINE_ADJUST(TRY1, domain)
{
Particle *p;
Injection *I;
Injection *Ilist = Get_dpm_injections();
int i=0;
real sum=0;


loop(p, I->p)
    {
    i=i+1+;//P_DIAM(p);
    }

printf("P_FLOW_RATE(p)/i%s\n", i);
}

2-b. And at changing the the loop I have in this code, I have this error "Get_dpm_injections" not found (pc=6)"
Code:

# include "udf.h"
# include "dpm.h"

DEFINE_ADJUST(TRY1, domain)
{
Particle *p;
Injection *I;
Injection *Ilist = Get_dpm_injections();
Thread *thread;
int i=0;
real sum=0;

thread_loop_c(thread, domain) /*loops over all cell threads in domain*/
  {
loop(I, Ilist)
    {   
    i=i+P_DIAM(p);
    }
  }

printf("P_FLOW_RATE(p)/i%s\n", i);
}



Thank you very much, I think I will try to compile the code instead of interpreting it, facing the problem that I don't have Visual Studio. After investigating I think that it can be because of that.
Has someone been able to do a loop through particles in an interpreted code?

`e` September 8, 2015 15:34

Quote:

Originally Posted by edu_aero (Post 562974)
1-. I have read on the Fluent macro tutorial guide that it is neccesary to have installed Visual Studio in order to run compiled code in a Windows computer, am I right?

For me, and taking into account my little knowledge about this part of Fluent, it seems that the errors that I am facing is because using interpreted instead of compiled codes.

Microsoft Visual Studio Express is free and works well for compiling UDFs for Fluent. Have a read of the FAQ here: http://www.cfd-online.com/Wiki/Fluen...at_is_wrong.3F

Quote:

Originally Posted by edu_aero (Post 562974)
2-a. At adding the following line in following code "Injection *Ilist = Get_dpm_injections();". The error is the same, structure reference not implemented.

The same error would be expected because you still haven't initialised the 'I' variable.

Quote:

Originally Posted by edu_aero (Post 562974)
2-b. And at changing the the loop I have in this code, I have this error "Get_dpm_injections" not found (pc=6)"

I suspect that the function Get_dpm_injections requires compiling the UDF.

pakk September 9, 2015 07:58

It might be needed to add
Code:

# include "dpm_mem.h"
when you interpret, to get access to Get_dpm_injections. But I am not sure of that, and compiling is the better option anyway.

edu_aero September 16, 2015 02:33

Thank you all for your help, the problem that I was facing it was that it is that for making a loop through every particle, compiled functions need to be used.

Now I can develope the code without struggling with computers programmes, just struggling with theoretical problems hehehe


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