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

c_udmi returns zero when called in another udf

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By blackmask
  • 1 Post By blackmask
  • 1 Post By blackmask

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 29, 2018, 11:03
Default c_udmi returns zero when called in another udf
  #1
New Member
 
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 7
JannisSif is on a distinguished road
Hi!

I am trying to create a udf which finds the average temperature at the outlet of the domain and then applies it to the inlet (increased by 7.58). I wrote the following udf but in the DEFINE_PROFILE the c_udmi returns zero and thus the F_PROFILE(f,t,nv) gets equal to 7.58 constantly......can someone help please??



DEFINE_EXECUTE_AT_END(average_exit_temp)
{
face_t f;
cell_t c0;
Domain *d=Get_Domain(1);
Thread *t=Lookup_Thread(d,8), *t0;
real vol=0, tavg=0, temp=0, vol_tot=0;
t0=THREAD_T0(t);

begin_f_loop(f,t)
{
c0=F_C0(f,t);
vol=C_VOLUME(c0,t0);
vol_tot+=vol;
temp=C_T(c0,t0);
tavg+=temp*vol;
}
end_f_loop(f,t)

tavg/=vol_tot;

begin_f_loop(f,t)
{
c0=F_C0(f,t);
C_UDMI(c0,t,0)= tavg;
printf("\n Average temperature is: %g\n",C_UDMI(c0,t,0));
}
end_f_loop(f,t)
}




DEFINE_PROFILE(inlet_temperature, t, nv)
{
face_t f;
Thread *t0;
cell_t c0;
real tavg;
t0=THREAD_T0(t);

begin_f_loop(f,t)
{
c0=F_C0(f,t);
F_PROFILE(f,t,nv)= C_UDMI(c0,t0,0) + 7.58;

printf("\n Inlet temperature is: %g\n",F_PROFILE(f,t,nv));
}
end_f_loop(f,t)

}
JannisSif is offline   Reply With Quote

Old   August 29, 2018, 20:12
Default
  #2
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
You just need to store one value "tavg", what do you need a "UDM" for? You can simply declare "tavg" in the file scope.

The "c0" in "DEFINE_PROFILE" is the cell index adjacent to inlet boundary, which has no overlap with cell index adjacent to outlet boundary. Suppose there is a grid with 100*100 cells and is number from top left to bottom right. The inlet and outlet boundary are located at the left and right ends, respectively. Then in the "DEFINE_EXECUTE_AT_END" you assigned values for cells with index ranging 9900 to 9999, then in the "DEFINE_PROFILE" you obtain values from cells with index ranging 0 to 99.
blackmask is offline   Reply With Quote

Old   August 30, 2018, 03:38
Default
  #3
New Member
 
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 7
JannisSif is on a distinguished road
Quote:
Originally Posted by blackmask View Post
You just need to store one value "tavg", what do you need a "UDM" for? You can simply declare "tavg" in the file scope.
Hi blackmask and thank you very much for the reply. I am very new to udfs and so I am a little confused....


So as far as I understood from what you wrote, in my case, I could use the following code, wright?


#include "udf.h"

real tavg=280.;

DEFINE_EXECUTE_AT_END(average_exit_temp)
{
face_t f;
cell_t c0;
Domain *d=Get_Domain(1);
Thread *t=Lookup_Thread(d,8), *t0;
real vol=0, temp=0, vol_tot=0;
t0=THREAD_T0(t);

begin_f_loop(f,t)
{
c0=F_C0(f,t);
vol=C_VOLUME(c0,t0);
vol_tot+=vol;
temp=C_T(c0,t0);
tavg+=temp*vol;
}
end_f_loop(f,t)

tavg/=vol_tot;
}



DEFINE_PROFILE(inlet_temperature, t, nv)
{
face_t f;

begin_f_loop(f,t)
{
F_PROFILE(f,t,nv)= tavg + 7.58;
printf("\n Inlet temperature is: %g\n",F_PROFILE(f,t,nv));
}
end_f_loop(f,t)

}


The problem is though that although it is interpreted without a problem, when I start the calculation I get a "floating poitn axception error". Also the "printf" I used says that "Inlet temperature is: inf"......what could be the problem?

Thank you very much for your time!
JannisSif is offline   Reply With Quote

Old   August 30, 2018, 05:23
Default
  #4
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
You should check whether the thread is empty or the sum of volume is non-zero. What is the output of the code below?
Code:
#include "udf.h"

real tavg=280.0;

DEFINE_EXECUTE_AT_END(average_exit_temp)
{
    face_t f;
    cell_t c0;
    Domain *d=Get_Domain(1);
    Thread *t=Lookup_Thread(d,8), *t0;
    real vol=0, temp=0, vol_tot=0;
    t0=THREAD_T0(t);

    Message("number of faces: %d\n", THREAD_N_ELEMENTS(t));

    begin_f_loop(f,t)
    {
        c0 = F_C0(f,t);
        vol = C_VOLUME(c0,t0);
        vol_tot += vol;
        temp = C_T(c0,t0);
        tavg += temp*vol;
    }
    end_f_loop(f,t);

    Message("sum of volumes: %g\n", vol_tot);

    tavg /= vol_tot;
}



DEFINE_PROFILE(inlet_temperature1, t, nv)
{
    face_t f;

    begin_f_loop(f,t)
    {
        F_PROFILE(f,t,nv)= tavg + 7.58;
        printf("\n Inlet temperature is: %g\n",F_PROFILE(f,t,nv));
    }
    end_f_loop(f,t)

}
blackmask is offline   Reply With Quote

Old   August 30, 2018, 05:42
Default
  #5
New Member
 
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 7
JannisSif is on a distinguished road
So I run the code (actually changed the "message" with "printf" because I could not interpret it) and it printed this:

number of faces: 0
sum of volumes: 0
number of faces: 0
sum of volumes: 0
number of faces: 0
sum of volumes: 0
number of faces: 6
sum of volumes: 1.33696e-07
number of faces: 0
sum of volumes: 0
JannisSif is offline   Reply With Quote

Old   August 30, 2018, 05:46
Default
  #6
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
The thread id (8) could be wrong. Please check.
blackmask is offline   Reply With Quote

Old   August 30, 2018, 05:48
Default
  #7
New Member
 
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 7
JannisSif is on a distinguished road
I just checked, it is correct (8) for the outlet of the domain.....
JannisSif is offline   Reply With Quote

Old   August 30, 2018, 06:28
Default
  #8
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
You can use the following code (just paste them to the the fluent TUI, i.e., the console below the graphics window)
Code:
(rp-var-define 'jos-thread-id-list () 'list #f) 
(rpsetvar 'jos-thread-id-list ()) 
(for-each (lambda (t) (rpsetvar 'jos-thread-id-list (list-add 
(rpgetvar 'jos-thread-id-list) (thread-id t)))) 
(get-all-threads)) 
(rpgetvar 'jos-thread-id-list) 


(rp-var-define 'jos-thread-name-list () 'list #f) 
(rpsetvar 'jos-thread-name-list ()) 
(for-each (lambda (t) (rpsetvar 'jos-thread-name-list (list-add 
(rpgetvar 'jos-thread-name-list) (thread-name t)))) 
(get-all-threads)) 
(rpgetvar 'jos-thread-name-list)
to get the list of zone names and their ids. What is the output?
blackmask is offline   Reply With Quote

Old   August 30, 2018, 07:13
Default
  #9
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Quote:
Originally Posted by JannisSif View Post
So I run the code (actually changed the "message" with "printf" because I could not interpret it) and it printed this:

number of faces: 0
sum of volumes: 0
number of faces: 0
sum of volumes: 0
number of faces: 0
sum of volumes: 0
number of faces: 6
sum of volumes: 1.33696e-07
number of faces: 0
sum of volumes: 0
why do you have 5 output messages?
Are you using 5 cores?

best regards
AlexanderZ is offline   Reply With Quote

Old   August 30, 2018, 07:18
Default
  #10
New Member
 
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 7
JannisSif is on a distinguished road
Quote:
Originally Posted by blackmask View Post
to get the list of zone names and their ids. What is the output?
The output is:

jos-thread-id-list

> jos-thread-id-list

>
> (6 3 14 2 8 7 13 1 9 10 11 12 5)

> adapt/ file/ solve/
adjoint/ mesh/ surface/
close-fluent parallel/ views/
define/ plot/
display/ report/

> adapt/ file/ solve/
adjoint/ mesh/ surface/
close-fluent parallel/ views/
define/ plot/
display/ report/

> jos-thread-name-list

> jos-thread-name-list

>
> (zone_wall part_4-surface_body interior-zone_wall-shadow interior-zone_wall outlet inlet symmetry interior-part_4-surface_body wall_tank-part_4-surface_body-zone_wall wall_tank-zone_wall plates-part_4-surface_body plates-zone_wall wall_tank-part_4-surface_body-zone_wall-shadow)

>
JannisSif is offline   Reply With Quote

Old   August 30, 2018, 07:19
Default
  #11
New Member
 
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 7
JannisSif is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
why do you have 5 output messages?
Are you using 5 cores?

best regards
Hi Alexander,

I am running on 4 cores (not sure why I have 5 messages....)

thank you.
JannisSif is offline   Reply With Quote

Old   August 30, 2018, 08:42
Default
  #12
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
Did not see that coming. Please try the following code:
Code:
#include "udf.h"

real tavg=280.0;

DEFINE_EXECUTE_AT_END(average_exit_temp)
{
    face_t f;
    cell_t c0;
    Domain *d=Get_Domain(1);
    Thread *t=Lookup_Thread(d,8), *t0;
    real vol=0, temp=0, vol_tot=0;
    t0=THREAD_T0(t);

    tavg = 0.0;
#if RP_NODE || !PARALLEL
    begin_f_loop(f,t)
    {
        c0 = F_C0(f,t);
        vol = C_VOLUME(c0,t0);
        vol_tot += vol;
        temp = C_T(c0,t0);
        tavg += temp*vol;
    }
    end_f_loop(f,t);

    tavg = PRF_GRSUM1(tavg);
    vol_tot = PRF_GRSUM1(vol_tot);
    tavg /= vol_tot;

    Message("processor: %d,tavg: %g\n", myid, vol_tot);
#endif
}



DEFINE_PROFILE(inlet_temperature1, t, nv)
{
    face_t f;
#if RP_NODE || !PARALLEL
    begin_f_loop(f,t)
    {
        F_PROFILE(f,t,nv)= tavg + 7.58;
        printf("\n Inlet temperature is: %g\n",F_PROFILE(f,t,nv));
    }
    end_f_loop(f,t)
#endif
}
JannisSif likes this.
blackmask is offline   Reply With Quote

Old   August 30, 2018, 08:52
Default
  #13
New Member
 
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 7
JannisSif is on a distinguished road
Quote:
Originally Posted by blackmask View Post
Did not see that coming. Please try the following code:
Thank you so much for your help! I tried the code you sent me but I got an error "MPT_gssum1: no function prototype"
JannisSif is offline   Reply With Quote

Old   August 30, 2018, 09:59
Default
  #14
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
The error does not occur if you can use compiled UDF. Otherwise it might need a work-around.
JannisSif likes this.
blackmask is offline   Reply With Quote

Old   August 30, 2018, 10:09
Default
  #15
New Member
 
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 7
JannisSif is on a distinguished road
Quote:
Originally Posted by blackmask View Post
The error does not occur if you can use compiled UDF. Otherwise it might need a work-around.
Yes you are absolutely right! It worked fine!!! Thank you so much!

So just to understand exactly what happened, the problem was that each core was calculating a different value? Or something else?
JannisSif is offline   Reply With Quote

Old   August 30, 2018, 20:23
Default
  #16
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
The solver processes are composed of one host node plus n (n=4 in your case) computing nodes. The host process definitely have no data of your outlet thread, so it will always result in 0./0. (i.e., FPE error you have encountered). Depending on the mesh partition, the computing node may or may not have data of your outlet thread, so it may cause FPE. Besides, the (temperature*volume) and (volume) should be summed from all computing nodes and then compute the average value, which is done with PRF_GRSUM1.
JannisSif likes this.
blackmask is offline   Reply With Quote

Old   August 31, 2018, 03:05
Default
  #17
New Member
 
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 7
JannisSif is on a distinguished road
Quote:
Originally Posted by blackmask View Post
The solver processes are composed of one host node plus n (n=4 in your case) computing nodes. The host process definitely have no data of your outlet thread, so it will always result in 0./0. (i.e., FPE error you have encountered). Depending on the mesh partition, the computing node may or may not have data of your outlet thread, so it may cause FPE. Besides, the (temperature*volume) and (volume) should be summed from all computing nodes and then compute the average value, which is done with PRF_GRSUM1.
Thank you very much for your time and help!! Have a nice day!

Best regards,
Jannis
JannisSif is offline   Reply With Quote

Reply

Tags
c_udmi, fluent - udf, udf


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
UDF: How to load data from an external file into a vector EmiS Fluent UDF and Scheme Programming 17 January 14, 2019 01:55
dynamic contact angle udf returns no value to solver shiraz_man67 Fluent UDF and Scheme Programming 5 July 3, 2018 14:51
Help with unsteady calculation with source/sink UDF RobV Fluent UDF and Scheme Programming 3 March 10, 2016 03:45
Source Term UDF VS Porous Media Model pchoopanya Fluent UDF and Scheme Programming 1 August 28, 2013 06:12
Help me to check my UDF Liufeng_ustb Fluent UDF and Scheme Programming 2 May 7, 2013 10:25


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