|
[Sponsors] |
November 17, 2015, 23:43 |
Using a calculated variable in another UDF
|
#1 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
Hi
How can I use a quantity calculated in one DPM UDF in another different type of DPM UDF? For example if I calculate the particle's kinetic energy in a DEFINE_DPM_BC UDF, I then want to use this in a DEFINE_DPM_OUTPUT UDF to report. If I use F_UDMI, does it not only store one value, whereas I have the kinetic energy value calculated for every particle that comes in contact with the wall. Thanks |
|
November 18, 2015, 04:33 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
You can add extra particle user defined memories. And then you can access them by P_USER_REAL(p,i) (where p is the particle, and i is the index of the particle user defined memory, starting at zero.)
|
|
November 19, 2015, 03:29 |
Re
|
#3 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
Does specifying the i value in P_USER_REAL(p,i) the same as the i value in F_UDMI mean that the values will be taken from the memory? Or do I need to do something else as well.
I am trying to take help from the manual through 2 examples the DEFINE_DPM_EROSION one and the DEFINE_DPM_SCALAR_UPDATE, each of which does one part of the solution you proposed but I cant fit them together. Heres my code, it compiles OK but when the particle actually reaches the wall where the DEFINE_DPM_BC UDF comes in, Fluent reports an error and aborts. The BC UDF works OK otherwise if the code shown below is not added to it. 'ke' is calculated in BC UDF. I have tried both with looping the faces and not, but get the same error. I am compiling the following in the same .c file as the BC UDF ofcourse. Code:
begin_f_loop(f,t) { ke=F_UDMI(f,t,0); } end_f_loop(f,t) } DEFINE_DPM_OUTPUT(discrete_phase_sampler,header,fp,p,t,plane) { if(header) { par_fprintf(fp,"abc [m]"); } { real d; if (NULLP(p)) return; /*d=P_DIAM(p);*/ par_fprintf(fp, "%d %" int64_fmt " %e\t\n", P_INJ_ID(P_INJECTION(p)), p->part_id, P_USER_REAL(p,0)); } } |
|
November 19, 2015, 04:44 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
No, P_USER_REAL and F_UDMI are different things.
P_USER_REAL is a memory address for each particle, you could use it for example to store the electric charge of a particle. F_UDMI is a memory address for each face, you coudl use it for example to store surface roughness of each face. But P_USER_REAL does not do anything other than storing a number. If you want that number to have any effect on your calculation, you should do something with that number. But your question was:"For example if I calculate the particle's kinetic energy in a DEFINE_DPM_BC UDF, I then want to use this in a DEFINE_DPM_OUTPUT UDF to report." If you want to do that, you have to do three things: 1. Add a user defined memory for a particle (somewhere in Fluent->models->DPM models) 2. In the DEFINE_DPM_BC UDF, store the particle's kinetic energy in that memory. Code:
P_USER_REAL(p,0)=(code for kinetic energy) Code:
par_fprintf(fp,"%e\n",P_USER_REAL(p,0)); |
|
November 19, 2015, 06:12 |
re
|
#5 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
Gave up on trying to find the user defined memory location for a particle. Dont think it is documented either?
Its not the same as the number of scalars is it, i think not. Also there are a lot of particles, not one, hope that is not going to be an issue? |
|
November 19, 2015, 06:21 |
|
#6 | ||
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Quote:
Quote:
|
|||
November 19, 2015, 06:26 |
|
#7 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Or perhaps you mean that you don't know where to say how many memory locations should be allocated for particles? In that case it is indeed "Number of scalars".
My Help says (Version 16.1, Fluent User's guide, 24.2.6. User-Defined Functions) "In addition, you can specify a Number of Scalars which are allocated to each particle and can be used to store information when implementing your own particle models." So if you want to add one memory address per particle to store kinetic energy, you set the number of scalars to one. And you can use P_USER_REAL(p,0) in your udfs to access that memory location. |
|
November 19, 2015, 08:08 |
Re
|
#8 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
Yup, i was actually confused with the 'number of scalars' part. Thanks, that answers my question and is what I had actually done as well.
The error is the same though (F1 process could not be restarted) and Fluent crashed , when i press the 'start' button after hooking the DEFINE_DPM_OUTPUT in the results section. Will try to find the reason and post it here if i do, or else if I give in again, ask more questions! Thanks |
|
November 20, 2015, 02:15 |
|
#9 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
Hi
Got this working was just a problem in my print statement. Other problems though: Editing the earlier post. There is actually something wrong with the BC UDF. If i use it the particle diameters are reported in vague values -9m or 15m for example in CFD post. Wondering if it is a bug in the 16.1 version. 2) While some particle's kinetic energy reported is correct, other's kinectic energy reported is 0. I was expecting this UDF to only report the kinetic energy of the particles which come in contact with the wall. Is it that it also somehow ends up reporting the kinetic energy of the particles which dont come in contact with the wall and hence their KE is not calculated since I am using a DEFINE_DPM_BC macro? 3) Printing the values on screen of the kinectic energy on sigma, not one value matches with the P_USER_REAL values printed out in a file. Copying the actualy UDF below: Last edited by hwet; November 22, 2015 at 23:29. Reason: updating |
|
November 22, 2015, 23:29 |
|
#10 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
Code:
#include "udf.h" DEFINE_DPM_BC(dust_collection_on_wall, p, thread_face, f_index, f_normal, dim) { real vsqr=0; /*Initializing the variables*/ real vmag=0; real vn=0; real normal[3]; real kinetic_energy_on_sigma; real criticalarea; int i, idim=dim; real diameter; real mass; diameter=P_DIAM(p); mass=P_MASS(p); for (i=0; i<idim;i++) { vsqr += P_VEL(p)[i]*P_VEL(p)[i]; /*Taking all dimensions into consideration*/ vmag += sqrt(vsqr); /*have tried with both vmag+ and vmag*/ Message0("The velocity magnitude is: %e\n", vmag); /*From specified node only*/ kinetic_energy_on_sigma= (((mass * vmag * vmag)/ 2) /0.072); /*Weber number calculation*/ Message0("The particle kinetic energy/water's surface tension is: %e\n", kinetic_energy_on_sigma); P_USER_REAL(p,0)=kinetic_energy_on_sigma; criticalarea= M_PI * diameter*diameter / 2; } for(i=0; i<idim; i++) normal[i]= f_normal[i]; Message0("The fnormal vector components are: %e %e %e %e\n", f_normal[0],f_normal[1],f_normal[2],diameter); if (kinetic_energy_on_sigma >= criticalarea) /*Critical weber number values from experiments/literature*/ {return PATH_END; } else /*Compute normal velocity*/ { for(i=0; i<idim; i++) vn +=P_VEL(p)[i]*normal[i]; /*printf("The face normal vector is: %d %d %d\n", normal[i]); */ Message0("The normal velocity is: %e\n", vn); /* Subtract off normal velocity*/ for(i=0; i<idim; i++); P_VEL(p)[i] -= vn*normal[i]; /*Add reflected normal velocity*/ for(i=0;i<idim; i++) P_VEL(p)[i] -=vn*normal[i]; /*Store new velocity in P_VEL0 of particle*/ for(i=0;i<idim; i++) P_VEL0(p)[i]= P_VEL(p)[i]; Message0("New velocity components are: %e %e %e %e\n", P_VEL(p)[0],P_VEL(p)[1],P_VEL(p)[2],diameter); return PATH_ACTIVE; } } DEFINE_DPM_OUTPUT(discrete_phase_sampler,header,fp,p,t,plane) { if(header) { par_fprintf_head(fp,"kinectic_energy_on_sigma"); } { if (NULLP(p)) return; par_fprintf(fp, "%d %" int64_fmt " %e\n", P_INJ_ID(P_INJECTION(p)), p->part_id, P_USER_REAL(p,0)); } } Last edited by hwet; November 23, 2015 at 01:51. |
|
November 23, 2015, 05:28 |
|
#11 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Your loop of i is wrong... Consider the following part:
Code:
for (i=0; i<idim;i++) { vsqr += P_VEL(p)[i]*P_VEL(p)[i]; /*Taking all dimensions into consideration*/ vmag += sqrt(vsqr); Message0("The velocity magnitude is: %e\n", vmag); ... } First, i=0 is calculated: vsqr = 3*3 = 9; vmag = sqrt(9) = 3. So the message on the screen will be "The velocity magnitude is: 3." Then, i=1 is calulated: vsqr = 9 + 4*4 = 25; vmag = 3 + sqrt(25) = 8. So the message on the screen will be "The velocity magnitude is: 8." Then, i=2 is calculated: vsqr = 25 + 12*12 = 169; vmag = 8 + sqrt(169) = 21. So, the message on the screen will be "The velocity magnitude is: 21." However, the true velocity of that particle is 13. You should rethink the steps you want your program to take. |
|
November 24, 2015, 01:40 |
|
#12 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
Thanks i corrected that part now.
Also the particle diameters were still being reported wrong, so i tried running the simulation in Ansys 15.0 instead, turns out it works correctly in that version, same case same UDF! It is actually something wrong in Ansys 16.1 I think. Thanks again |
|
November 26, 2015, 04:36 |
|
#13 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
Hi
The particle data file which is written reports 0 velocity and kinetic energy for particles which get collected (PATH END). For particles which rebound it reports a non-zero value (which is correct as well). I am thinking, I need to report the Kinetic energy of particles as they enter the wall cell and not when they actually hit the wall to get non-zero values for these particles? I am just guessing this is the actual reason. Any ideas? Also, if that is the reason, how can I get the particle's data before it has aborted. thanks |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Setting cell variable values in a fluid zone using UDF | eromon84 | Fluent UDF and Scheme Programming | 6 | March 28, 2021 12:59 |
UDF Compilation Error - Loading Library - COMMON Problem! Help! | robtheslob | Fluent UDF and Scheme Programming | 8 | July 24, 2015 01:53 |
modify a intern variable of Fluent with scheme and UDF | fanch33 | Fluent UDF and Scheme Programming | 3 | March 2, 2015 12:01 |
variable Heat Source for Solid Region with UDF | Alex90 | Fluent UDF and Scheme Programming | 3 | February 24, 2015 12:24 |
UDF: check variable for error | icemesh | Fluent UDF and Scheme Programming | 0 | February 13, 2014 09:50 |