Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mathematical formulation

Status
Not open for further replies.

Lesh108

Programmer
Jul 30, 2011
3
0
0
GB
Hi

I need to write the following 'logic' in C.

If the temperature (T) at time (t) is greater than the temperature at time (t-1), then cp = 2000.

i.e. in mathematics T(t) > T(t-1) , cp =2000.

My problem is I don't know how to write temperature as a function of time. Can somebody help ?

Lesh108
 
What characteristic does the temperature follow? Is it data from an experiment, a lookup table or some mathematical equation?
 
Temperature follows a lookup table, with reference to time.
 
There are quite a few ways of using lookup tables. The problem arises when the time is in between two items in the lookup table. The strategies are to use

1) previous value
2) Next value
3) Interpolated values

Say the table looks like this
Code:
struct LUTType
{
   float m_time;
   float m_temp;
};

struct LUTType lut[] =
{
   {  0.0, 40.0 },
   {  5.0, 41.0 },
   { 10.0, 43.0 },
   { 15.0, 47.0 },
   { 20.0, 45.0 },
   { 25.0, 42.0 }
};
Say the time is 7.0. The temp will be

1) 41.0 (previous time is 5.0)
2) 43.0 (next time is 10.0)
3) 41.0 + (43.0 - 41.0) * (7.0 - 5.0) / (10.0 - 5.0)

That is the basic theory. Which part are you having problems with.
 
Thanks for your help.

I'm writing a code for a FLUENT (cfd) UDF. FLUENT readily sends the temperature value at time (t), using global macros. My problem is that I cannot access the temperature at (t-1).

So I thought of storing the temperature values (at time t) for every timesteps, so that I can access it as (t-1) at a later time. I thought that maybe lookup tables can do that, but it seems that I need to put the temperature & time values myself at the beginning, which will not work.

I will need the code to store the values for each timestep, so that it can later use them. Would you know how to do that ?

Thanks
 
If you need the difference T(current) - T(previous) only, declare three variables:
Code:
double tprev, tcurr;
int more = 0; /* have previous measurement flag */
Now:
Code:
...
tcurr = get_it_somewhere;
if (more) {
   if (tprev < tcurr)
      cp = 2000;
   else
      do_unknown_action(no_specs_in_the_OP);
   tprev = tcurr; /* for the next step */
} else more = 1;
...
That's all.
How to save (accumulate) input data trace - it's the other story...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top