CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Previous time step value (https://www.cfd-online.com/Forums/fluent/185150-previous-time-step-value.html)

Tushar_Telmasre March 20, 2017 06:12

Previous time step value
 
While defining field function, is there any way one can access the previous time step value while defining a custom field function?

For Example, if my field function is defined as

C_mix= (C_new-C_old)*Liquid fraction
where,
C_old is the concentration value at previous time step and C_new is the concentration value at present time step at a cell node.

the present time step value can be obtained from the drop down menu but I also need the previous time step value. Is there any way I can get it?

LuckyTran March 21, 2017 03:05

Mostly for moral support...Keep looking!

I don't actually know how to do it off the top of my head, but I feel like the answer is yes, you should be able to.

You should always have the values at the previous iteration, and possibly another time-step if you are using 2nd order Euler. You need to figure out the old variable names, you might have to do some tricks to get these variables to show up like temporary storage or something. Sorry I'm too lazy to actually test the solution for you.

Tigrgrou March 22, 2017 07:35

UDF and UDM
 
You use a UDF to store the valuein a UDM. You can use the value of the UDM in the custom field function.

Something like if you want to store the previous value of the y-velocity.

...
thread_loop_c(ct,domain)
{
if (FLUID_THREAD_P(ct))
{
begin_c_loop_all(c,ct)
{
C_UDMI(c,ct,0)= C_V_M1(c,ct);
}
end_c_loop_all(c,ct)
}
}

Tushar_Telmasre March 23, 2017 00:45

which header file to use if we just have to save the temperature in a udm?
My udf is giving parsing error.

Tushar_Telmasre March 23, 2017 01:49

I did write a simple code to save my temperature data in a udm.

real temp;
cell_t c;
Thread *t;
begin_c_loop(c,t)
{
temp = C_T(c,t);
F_UDMI(c,t,0) = temp;
}
end_c_loop(c,t)

it is not getting interpreted.
I want to know which macro I need to use to hook this function to fluent.
I want to further define a custom field function with value udm0 and plot it at the end of calculation. The contours of that should be same as the contours of temperature.

Can anyone please have a look and suggest any mistake? also how and where do I hook this UDF?

Tigrgrou March 23, 2017 03:47

For the header, you just need the usual one udf.h

You need to integrate the code in a macro. The choice of the macro depends on when you want to store the value.
DEFINE_ON_DEMAND for post-processing
F_UDMI is for face not cell

C_T_M1(c,t) is for the previous value of the temperature

Tushar_Telmasre March 23, 2017 04:21

Thank you very much!!

Tushar_Telmasre March 23, 2017 06:18

Quote:

Originally Posted by Tigrgrou (Post 641941)
For the header, you just need the usual one udf.h

You need to integrate the code in a macro. The choice of the macro depends on when you want to store the value.
DEFINE_ON_DEMAND for post-processing
F_UDMI is for face not cell

C_T_M1(c,t) is for the previous value of the temperature

I tried using the DEFINE_ON_DEMAND macro. it is giving a segmentation fault upon executing.

Tigrgrou March 23, 2017 06:25

You can add
Message0("TEST\n");
at different location of your code to debug the udf

You have an example of the macro DEFINE_ON_DEMAND on
https://www.sharcnet.ca/Software/Flu...udf/node27.htm

Tushar_Telmasre March 23, 2017 09:44

I read through the ansys help and tried to execute define_on_demand udf.

the code is
/************************************************** ********************
UDF to calculate temperature field function and store in
user-defined memory. Also print min, max, avg temperatures.
************************************************** *********************/
#include "udf.h"

DEFINE_ON_DEMAND(on_demand_calc)
{
Domain *d; /* declare domain pointer since it is not passed as an
argument to the DEFINE macro */
real tavg = 0.;
real tmax = 0.;
real tmin = 0.;
real temp,volume,vol_tot;
Thread *t;
cell_t c;
d = Get_Domain(1); /* Get the domain using ANSYS Fluent utility */

/* Loop over all cell threads in the domain */
thread_loop_c(t,d)
{

/* Compute max, min, volume-averaged temperature */

/* Loop over all cells */
begin_c_loop(c,t)
{
volume = C_VOLUME(c,t); /* get cell volume */
temp = C_T(c,t); /* get cell temperature */

if (temp < tmin || tmin == 0.) tmin = temp;
if (temp > tmax || tmax == 0.) tmax = temp;

vol_tot += volume;
tavg += temp*volume;

}
end_c_loop(c,t)

tavg /= vol_tot;

printf("\n Tmin = %g Tmax = %g Tavg = %g\n",tmin,tmax,tavg);

/* Compute temperature function and store in user-defined memory*/
/*(location index 0) */

begin_c_loop(c,t)
{
temp = C_T(c,t);
C_UDMI(c,t,0) = (temp-tmin)/(tmax-tmin);
}
end_c_loop(c,t)

}
}


This is the same as given in the ansys help.

further, i defined a memory location in fluent.

solved the following problem.
A Square aluminium block of length 1mm. properties as given in fluent.
left boundary: 600K temperature.
Right boundary: 100K temperature.
Initialized the problem with domain temperature 500K.
solved the problem with time step of 1e-5 for 100-time steps.

now when I am trying to execute the udf using execute_on_demand the function it is not getting executed. Instead, giving a segmentation fault. what is wrong here?

As far as I know segmentation fault occurs when code tries to access undefined memory location. I defined multiple user defined memory locations. still, it is not working.
what needs to be done?
Please help.

Tigrgrou March 24, 2017 02:39

I tried your udf, it works well (interpreted or compiled). Just do the initialization then execute the udf, do you have the error?

Tushar_Telmasre May 11, 2017 09:17

Quote:

Originally Posted by Tigrgrou (Post 642095)
I tried your udf, it works well (interpreted or compiled). Just do the initialization then execute the udf, do you have the error?

Thank you very much.

Tushar_Telmasre May 11, 2017 14:07

Quote:

Originally Posted by Tigrgrou (Post 642095)
I tried your udf, it works well (interpreted or compiled). Just do the initialization then execute the udf, do you have the error?

Experiencing a weird problem. solving for simple conduction based solidification.

#include "udf.h"

DEFINE_EXECUTE_AT_END(temp_gradient)
{
Domain *d;

Thread *t;

cell_t c;

d = Get_Domain(1);

thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,1) = C_T_M1(c,t);
}
end_c_loop(c,t)
}

}

in the above code I am getting segmentation fault. if I change C_T_M1(c,t) to C_T(c,t) I wont get any fault and solution will proceed.

any idea what might be the reason.

Oula September 26, 2018 09:51

Dear Tushar_Telmasre,

Do you know how to save temperature with respect to time using the UDM. I need to monitor the temperature on a surface with time in order to get a chart of temp. vs time. Your help is appreciated. Regards Oula

Oula September 26, 2018 10:09

Dear all

Thank you so much to all of you for sharing your experiences with the UDF and the UDM. I have question, do I need to write UDM and UDF for specific surface to save the output parameter of interest. I'm a little bit confuse now regarding these two terms. What I understood is that the udm could be like:

#include "udf.h"

DEFINE_ADJUST(wall_temp,domain)
{
face_t f;
Int ID;
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)
}

I.e. it can start exactly the same as the UDF with #include "udf.h" just the macro change. Therefore, it can be written in the same c++ source file with other UDFs for transient BCs, please correct me if I'm wrong.

Thank you
Regards
Oula


All times are GMT -4. The time now is 04:06.