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

How can I get a variable as output parameter from A UDF for post processing in fluent

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By blackmask
  • 1 Post By blackmask

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 5, 2018, 11:42
Default How can I get a variable as output parameter from A UDF for post processing in fluent
  #1
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
Hi everyone

I'm modelling a process of a furnace. The heating process in this furnace occurs gradually, i.e. the thermal profile is changing with time. I have managed to write a UDF for this transient temperature for the furnace wall. Now I want to monitor the temperature profile of the product inside the furnace, which would be also changing with time as the heating process is running.

Now I want to capture the product's transient temperature at every time step and use it in post processing to make a temp. vs time graph?

What MACRO or SCHEME MACRO can I use to get this temp. variable from the UDF in such a way that I can use it in post processing. Also Can I save the output parameters in a file that can be opened in excel or Matlab?

Please see below code which is I believe not so correct as I build it using different tutorials. Please have a look and advice me how to modify it. I also want the values of the temperature to be saved in a file that can be opened in excel, if possible.

/* Compute face average temperature and store in user-defined memory */

#include "udf.h"
#define ID 8
DEFINE_ADJUST(wall_temp,domain)
{
face_t f;
Thread *t = Lookup_Thread(domain, ID);
begin_f_loop(f,t)
{
temp = F_T(f,t);

F_UDMI(f,t,0) = (temp - tmin) / (tmax-tmin);

}
end_f_loop(f,t)
}

Any help is much appreciated
Oula

Last edited by Oula; October 5, 2018 at 12:49.
Oula is offline   Reply With Quote

Old   October 6, 2018, 23:49
Default
  #2
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
The following is for your reference.

Code:
#include "udf.h"
#define ID 8

/* Solution a: store value in UDMI */
/* Both the face thread and their adjacent cells */
/* of the UDMI are set for proper visulazation in FLUENT */
DEFINE_EXECUTE_AT_END(wall_temp)
{
#if !RP_HOST
    face_t f;
    real temp, tmax, tmin;
    real value;
    Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
    Thread *t = Lookup_Thread(domain, ID);
    begin_f_loop(f,t)
    {
        temp = F_T(f,t);
        value = (temp - tmin) / (tmax-tmin);
        F_UDMI(f,t,0) = value;
        F_UDMI(F_C0(f, t), t->t0, 0) = value;
    }
    end_f_loop(f,t);
#endif
}

/* Solution b: write data to file */
FILE* fptemp = NULL;
DEFINE_EXECUTE_AT_END(write_temp_to_file)
{
#if !RP_HOST
    face_t f;
    real temp, tmax, tmin;
    real value;
    real time;
    Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
    Thread *t = Lookup_Thread(domain, ID);
    int cnt;
    char header[16];
    if (!fptemp)
    {
        fptemp = fopen("temp-vs-time.txt", "w");
        fprintf(fptemp, "%16s", "time");
        for (cnt = 0; cnt < t->nelements; ++cnt)
        {
            sprintf(header, "face%03d", cnt);
            fprintf(fptemp, "%16s", header);
        }
        fprintf(fptemp, "\n");
    }
    time = CURRENT_TIME;
    fprintf(fptemp, "%16.5e", time);

    begin_f_loop(f,t)
    {
        temp = F_T(f,t);
        value = (temp - tmin) / (tmax-tmin);
        fprintf(fptemp, "%16.5e", value);
    }
    end_f_loop(f,t);

    fprintf(fptemp, "\n");
    fflush(fptemp);
#endif
}
Oula likes this.
blackmask is offline   Reply With Quote

Old   October 8, 2018, 06:53
Default
  #3
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
Dear Blackmask,

Thank you so much for your reply and for the code you have provided. I really can't find words to thank you enough. Now, I can use this code to monitor the product temperature. May I ask you how to get this function work in Fluent?. I did my search and found the following instruction:
In Fluent go to define menu, select User-defined then select memory from the pop up list. then a box appear to set number of UDM locations and number of UDM node location, if this is right, How many locations do I need to set?
One last question can I write this code in one source file with other UDFs?

Many thanks again.
Oula
Oula is offline   Reply With Quote

Old   October 8, 2018, 08:00
Default
  #4
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
You need at least one UDM location for the above code to work. Check http://https://www.sharcnet.ca/Softw...df/node138.htm for Hooking DEFINE_EXECUTE_AT_END UDFs.
Oula likes this.
blackmask is offline   Reply With Quote

Old   October 11, 2018, 12:47
Default
  #5
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
Quote:
Originally Posted by blackmask View Post
The following is for your reference.

Code:
#include "udf.h"
#define ID 8

/* Solution a: store value in UDMI */
/* Both the face thread and their adjacent cells */
/* of the UDMI are set for proper visulazation in FLUENT */
DEFINE_EXECUTE_AT_END(wall_temp)
{
#if !RP_HOST
    face_t f;
    real temp, tmax, tmin;
    real value;
    Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
    Thread *t = Lookup_Thread(domain, ID);
    begin_f_loop(f,t)
    {
        temp = F_T(f,t);
        value = (temp - tmin) / (tmax-tmin);
        F_UDMI(f,t,0) = value;
        F_UDMI(F_C0(f, t), t->t0, 0) = value;
    }
    end_f_loop(f,t);
#endif
}

/* Solution b: write data to file */
FILE* fptemp = NULL;
DEFINE_EXECUTE_AT_END(write_temp_to_file)
{
#if !RP_HOST
    face_t f;
    real temp, tmax, tmin;
    real value;
    real time;
    Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
    Thread *t = Lookup_Thread(domain, ID);
    int cnt;
    char header[16];
    if (!fptemp)
    {
        fptemp = fopen("temp-vs-time.txt", "w");
        fprintf(fptemp, "%16s", "time");
        for (cnt = 0; cnt < t->nelements; ++cnt)
        {
            sprintf(header, "face%03d", cnt);
            fprintf(fptemp, "%16s", header);
        }
        fprintf(fptemp, "\n");
    }
    time = CURRENT_TIME;
    fprintf(fptemp, "%16.5e", time);

    begin_f_loop(f,t)
    {
        temp = F_T(f,t);
        value = (temp - tmin) / (tmax-tmin);
        fprintf(fptemp, "%16.5e", value);
    }
    end_f_loop(f,t);

    fprintf(fptemp, "\n");
    fflush(fptemp);
#endif
}
Hi Blackmask

I have tried to interpret the code that you have kindly provided, but I got some errors (parse error) in lines 11,12,13 & 14
real temp, tmax, tmin;
real value;
real time;
Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
Thread *t = Lookup_Thread(domain, ID);

and another says "temp undeclared variable" in line 17
temp = F_T(f,t);

why do you think that?

Thank you
Regards
Oula

Last edited by Oula; October 11, 2018 at 13:54.
Oula is offline   Reply With Quote

Old   October 31, 2018, 14:21
Default
  #6
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
Dear Blackmask

I have used the code that you have kindly provided, but the text file "temp-vs-time" has loads data, columns and faces counting, see attached file. I expected to get only temperature and time data are written and saved. Why do you think that?

Your help is much appreciated
Oula
Oula is offline   Reply With Quote

Old   October 31, 2018, 22:16
Default
  #7
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
I do not see the attached. The file should look like


time face000 face001 face002 ...
0.1 300.0 301.0 302.0 ...
0.2 300.2 300.8 301.5 ...
blackmask is offline   Reply With Quote

Old   November 1, 2018, 05:07
Default
  #8
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
Hi blackmask
I had problem yesterday with uploading the file due to its size. I have copied and past some of the data, see below, this is how it looks like. as you can see the time data has not been recorded, only the faces counting exists. I would like to ask you what does the faces counting represent? Regards

time face000 face001 face002 face003 face004 face005 face006 face007 face008 face009 face010 face011 face012 face013 face014 face015 face016 face017 face018 face019 face020 face021 face022 face023 face024 face025 face026 face027 face028 face029 face030 face031 face032 face033 face034 face035 face036 face037 face038 face039 face040 face041 face042 face043 face044 face045 face046 face047 face048 face049 face050 face051 face052 face053 face054 face055 face056 face057 face058 face059 face060 face061 face062 face063 face064 face065 face066 face067 face068 face069 face070 face071 face072 face073 face074 face075 face076 face077 face078 face079 face080 face081 face082 face083 face084 face085 face086 face087 face088 face089 face090 face091 face092 face093 face094 face095 face096


ce10751 face10752 face10753 face10754 face10755 face10756 face10757 face10758 face10759 face10760 face10761 face10762 face10763 face10764 face10765 face10766 face10767 face10768 face10769 face10770 face10771 face10772 face10773 face10774 face10775 face10776 face10777 face10778 face10779 face10780 face10781 face10782 face10783 face10784 face10785 face10786 face10787 face10788 face10789 face10790 face10791 face10792 face10793 face10794 face10795 face10796 face10797 face10798 face10799 face10800 face10801 face10802 face10803 face10804 face10805 face10806 face10807 face10808 face10809 face10810 face10811 face10812 face10813 face10814 face10815 face10816 face10817 face10818 face10819 face10820 face10821 face10822 face10823 face10824 face10825 face10826 face10827 face10828 face10829 face10830 face10831 face10832 face10833 face10834 face10835 face10836 face10837 face10838 face10839 face10840 face10841 face10842 face10843 face10844 face10845 face10846 face10847 face10848 face10849 face10850 face10851 face10852 face10853 face10854 face10855 face10856 face10857 face10858 face10859 face10860 face10861 face10862 face10863 face10864 face10865 face10866 face10867 face10868 face10869 face10870 face10871 face10872 face10873 face10874 face10875 face10876 face10877 face10878 face10879 face10880 face10881 face10882 face10883 face10884 face10885 face10886 face10887 face10888 face10889 face10890 face10891 face10892 face10893 face10894 face10895 face10896 face10897 face10898 face10899 face10900 face10901 face10902 face10903 face10904 face10905 face10906 face10907 face10908 face10909 face10910 face10911 face10912 face10913 face10914 face10915 face10916 face10917 face10918 face10919 face10920 face10921 face10922 face10923 face10924 face10925 face10926 face10927 face10928 face10929 face10930 face10931 face10932 face10933 face10934 face10935 face10936 face10937 face10938 face10939 face10940 face10941 face10942 face10943 face10944 face10945 face10946 face10947 face10948 face10949 face10950 face10951 face10952 face10953 face10954 face10955 face10956 face10957 face10958 face10959 face10960 face10961 face10962 face10963 face10964 face10965 face10966 face10967 face10968 face10969 face10970 face10971 face10972 face10973 face10974 face10975 face10976 face10977 face10978 face10979 face10980 face10981 face10982 face10983 face10984 face10985 face10986 face10987 face10988 face10989 face10990 face10991 face10992 face10993 face10994 face10995 face10996 face10997 face10998 face10999 face11000 face11001 face11002 face11003 face11004 face11005 face11006 face11007 face11008 face11009 face11010 face11011 face11012 face11013 face11014 face11015 face11016 face11017 face11018 face11019 face11020 face11021 face11022 face11023 face11024 face11025 face11026 face11027 face11028 face11029 face11030 face11031 face11032 face11033 face11034 face11035 face11036 face11037 face11038 face11039 face11040 face11041 face11042 face11043 face11044 face11045 face11046 face11047 face11048 face11049 face11050 face11051 face11052 face11053 face11054 face11055 face11056 face11057 face11058 face11059 face11060 face11061 face11062 face11063 face11064 face11065 face11066 face11067 face11068 face11069 face11070 face11071 face11072 face11073 face11074 face11075 face11076 face11077 face11078 face11079 face11080 face11081 face11082 face11083 face11084 face11085 face11086 face11087 face11088
0.00000e+00 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02
Oula is offline   Reply With Quote

Old   November 1, 2018, 07:37
Default
  #9
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
The furnace wall(or whatever the ID=8 corresponds to, is a face threads) consist of 11088 faces, and the UDF print out the temperature for each face. If you are interested in some statistics, say the average temperature, then you can do an average.
blackmask is offline   Reply With Quote

Old   November 2, 2018, 06:35
Default
  #10
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
Quote:
Originally Posted by blackmask View Post
I do not see the attached. The file should look like


time face000 face001 face002 ...
0.1 300.0 301.0 302.0 ...
0.2 300.2 300.8 301.5 ...
blackmask,

I was wondering why the data has not been saved in the format that you have mentioned?. Also I have noticed that the time data has not been saved at all, why do you think? see below how the data was actually saved. Your help is much appreciated.

time face000 face001 face002 face003 face004 face005 face006 face007 face008 face009 face010 face011 face012 face013 face014 face015 face016 face017 face018 face019 face020 face021 face022 face023 face024 face025 face026 face027 face028 face029 face030 face031 face032 face033 face034 face035 face036 face037 face038 face039 face040 face041 face042 face043 face044 face045 face046 face047 face048 face049 face050 face051 face052 face053 face054 face055 face056 face057 face058 face059 face060 face061 face062 face063 face064 face065 face066 face067 face068 face069 face070 face071 face072 face073 face074 face075 face076 face077 face078 face079 face080 face081 face082 face083 face084 face085 face086 face087 face088 face089 face090 face091 face092 face093 face094 face095 face096 face097 face098 face099 face100 face101 face102 face103 face104 face105 face106 face107 face108 face109 face110 face111 face112 face113 face114 face115 face116 face117 face118 face119 face120 face121 face122 face123 face124 ...... etc
Oula 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
looking for a smart interface matlab fluent chary FLUENT 24 June 18, 2021 10:07
Can I change the variable in UDF via Fluent console or window without compiling? swtbkim FLUENT 0 July 12, 2017 23:15
write code UDF Fluent solve kinetic reaction rate equation palm oil zirkov FLUENT 0 February 13, 2017 11:16
The fluent stopped and errors with "Emergency: received SIGHUP signal" yuyuxuan FLUENT 0 December 3, 2013 23:56
emag beta feature: charge density charlotte CFX 4 March 22, 2011 10:14


All times are GMT -4. The time now is 00:55.