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/)
-   -   non-integer subscript expression: float (https://www.cfd-online.com/Forums/fluent-udf/122450-non-integer-subscript-expression-float.html)

vExus August 20, 2013 06:59

non-integer subscript expression: float
 
Hi,
Being a total rookie at programming I am trying to set free steam temperature as a function of flow time. While interpreting UDF i get this error:
Code:

non-integer subscript expression: float
This is how the error line looks like:
Code:

F_PROFILE(f, thread, index) = tab[s];
Whole code:
Code:

#include "udf.h"       
DEFINE_PROFILE (T_ot, thread, index)
{
        real s;
        double tab[8547]={}; //There are 8547 temperature values set in the correct order (as they change with every time step). I had to cut them off to make the code shorter
        face_t f;
       
        s=RP_Get_Real("flow-time");
       
        begin_f_loop(f, thread)
        {
                F_PROFILE(f, thread, index) = tab[s];
        }
        end_f_loop(f, thread);
}

While changing "tab[s]" to "tab[2]" UDF interprets fine so "s" must be the problem.
How else can I specify array index? Does code look ok?

EDIT
I have changed "real s" to "int s" and now fluent do interpret UDF.
Does the rest looks fine?

blackmask August 20, 2013 09:16

You might need to change the code if the index of tab corresponds to time step rather than flow time. Also you need to avoid index out of range.

Code:

#include "udf.h"   
DEFINE_PROFILE (T_ot, thread, index)
{
        int s;
        real tval;
        double tab[8547]={}; //There are 8547 temperature values set in the correct order (as they change with every time step). I had to cut them off to make the code shorter
        face_t f;
           
        s = N_TIME;
        tval = s < 8547 ? tab[s] : tab[8546];
           
        begin_f_loop(f, thread)
        { 
                F_PROFILE(f, thread, index) = tval;
        }   
        end_f_loop(f, thread);
}


vExus August 21, 2013 18:41

Thanks a lot!


All times are GMT -4. The time now is 15:02.