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

Previous time step value

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 20, 2017, 06:12
Default Previous time step value
  #1
Member
 
sebastian bergman
Join Date: Mar 2017
Location: seattle
Posts: 52
Rep Power: 9
Tushar_Telmasre is on a distinguished road
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?
Tushar_Telmasre is offline   Reply With Quote

Old   March 21, 2017, 03:05
Default
  #2
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,676
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
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.
LuckyTran is offline   Reply With Quote

Old   March 22, 2017, 07:35
Default UDF and UDM
  #3
New Member
 
valerie
Join Date: Nov 2015
Posts: 20
Rep Power: 10
Tigrgrou is on a distinguished road
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)
}
}
Tigrgrou is offline   Reply With Quote

Old   March 23, 2017, 00:45
Default
  #4
Member
 
sebastian bergman
Join Date: Mar 2017
Location: seattle
Posts: 52
Rep Power: 9
Tushar_Telmasre is on a distinguished road
which header file to use if we just have to save the temperature in a udm?
My udf is giving parsing error.
Tushar_Telmasre is offline   Reply With Quote

Old   March 23, 2017, 01:49
Default
  #5
Member
 
sebastian bergman
Join Date: Mar 2017
Location: seattle
Posts: 52
Rep Power: 9
Tushar_Telmasre is on a distinguished road
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?
Tushar_Telmasre is offline   Reply With Quote

Old   March 23, 2017, 03:47
Default
  #6
New Member
 
valerie
Join Date: Nov 2015
Posts: 20
Rep Power: 10
Tigrgrou is on a distinguished road
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
Tigrgrou is offline   Reply With Quote

Old   March 23, 2017, 04:21
Default
  #7
Member
 
sebastian bergman
Join Date: Mar 2017
Location: seattle
Posts: 52
Rep Power: 9
Tushar_Telmasre is on a distinguished road
Thank you very much!!
Tushar_Telmasre is offline   Reply With Quote

Old   March 23, 2017, 06:18
Default
  #8
Member
 
sebastian bergman
Join Date: Mar 2017
Location: seattle
Posts: 52
Rep Power: 9
Tushar_Telmasre is on a distinguished road
Quote:
Originally Posted by Tigrgrou View Post
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.
Tushar_Telmasre is offline   Reply With Quote

Old   March 23, 2017, 06:25
Default
  #9
New Member
 
valerie
Join Date: Nov 2015
Posts: 20
Rep Power: 10
Tigrgrou is on a distinguished road
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
Tigrgrou is offline   Reply With Quote

Old   March 23, 2017, 09:44
Unhappy
  #10
Member
 
sebastian bergman
Join Date: Mar 2017
Location: seattle
Posts: 52
Rep Power: 9
Tushar_Telmasre is on a distinguished road
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.
Tushar_Telmasre is offline   Reply With Quote

Old   March 24, 2017, 02:39
Default
  #11
New Member
 
valerie
Join Date: Nov 2015
Posts: 20
Rep Power: 10
Tigrgrou is on a distinguished road
I tried your udf, it works well (interpreted or compiled). Just do the initialization then execute the udf, do you have the error?
Tigrgrou is offline   Reply With Quote

Old   May 11, 2017, 09:17
Default
  #12
Member
 
sebastian bergman
Join Date: Mar 2017
Location: seattle
Posts: 52
Rep Power: 9
Tushar_Telmasre is on a distinguished road
Quote:
Originally Posted by Tigrgrou View Post
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 is offline   Reply With Quote

Old   May 11, 2017, 14:07
Default
  #13
Member
 
sebastian bergman
Join Date: Mar 2017
Location: seattle
Posts: 52
Rep Power: 9
Tushar_Telmasre is on a distinguished road
Quote:
Originally Posted by Tigrgrou View Post
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.
Tushar_Telmasre is offline   Reply With Quote

Old   September 26, 2018, 09:51
Default
  #14
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
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 is offline   Reply With Quote

Old   September 26, 2018, 10:09
Default
  #15
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
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
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
Stuck in a Rut- interDyMFoam! xoitx OpenFOAM Running, Solving & CFD 14 March 25, 2016 07:09
simpleFoam error - "Floating point exception" mbcx4jc2 OpenFOAM Running, Solving & CFD 12 August 4, 2015 02:20
Star cd es-ice solver error ernarasimman STAR-CD 2 September 12, 2014 00:01
Help for the small implementation in turbulence model shipman OpenFOAM Programming & Development 25 March 19, 2014 10:08
mixerVesselAMI2D's mass is not balancing sharonyue OpenFOAM Running, Solving & CFD 6 June 10, 2013 09:34


All times are GMT -4. The time now is 05:38.