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

Stop simulation after given conditions (UDF)

Register Blogs Community New Posts Updated Threads Search

Like Tree8Likes
  • 1 Post By vinerm
  • 1 Post By vinerm
  • 3 Post By AlexanderZ
  • 1 Post By vinerm
  • 1 Post By vinerm
  • 1 Post By LuckyTran

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 23, 2020, 10:47
Default Stop simulation after given conditions (UDF)
  #1
Member
 
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6
franc1 is on a distinguished road
Hi everybody,

How can i stop a transient simulation after a condition is fullfilled?
For instance: a thermal flux (W/m^2) is flowing into my domain and i want to stop the simulation at the time-step at which a given amount of energy (J) is reached. How can it be done?

Thank you in advance!
franc1 is offline   Reply With Quote

Old   April 23, 2020, 14:42
Default Stopping Fluent
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
You can use (cx-interrupt). This is a Scheme command and cannot be called from within UDF. However, this can be called with an if condition withing Calculation Activities > Execute Commands. Let the commands check for the heat flux and as soon as it reaches a certain value, (cx-interrupt) will stop Fluent. Other option is to use convergence conditions. Fluent has convergence conditions that can be used to stop Fluent if a certain value reaches below a threshold. Since it requires value to be reducing, you have to define either 1/heat flux or difference between your threshold and heat flux. This way, as soon as the value reaches below a threshold, Fluent will stop. This has to be done via Report Definitions and then using this Report Definition in Convergence Conditions.
franc1 likes this.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 24, 2020, 04:18
Default
  #3
Member
 
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6
franc1 is on a distinguished road
If i want to apply the second way you suggested there's a problem: since my check value is energy (J) and as BC i have heatflux (W/m^2) this means that during calculation i have to sum up all the values of the previous time-steps. In this way at each time-step i check the integration of the heat flux of all the time-steps passed.

So the problem is: how can i store values calculated at the previous time-steps?

(i tried to do with a scheme execute command, but i don't have scheme programming background and it's quite difficult for me)
franc1 is offline   Reply With Quote

Old   April 24, 2020, 04:31
Default Energy
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Do you want to check for the energy accumulated in the system? Or do you want to check for the energy supplied until a certain time?
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 24, 2020, 04:33
Default
  #5
Member
 
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6
franc1 is on a distinguished road
The accumulated one
franc1 is offline   Reply With Quote

Old   April 24, 2020, 04:43
Default Accumulated Energy
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
If it is accumulated energy, then you do not need to sum over last time-steps. Since it is accumulating, that would be the energy of the cell zone. So, you can just look at the integral of the energy in the cell zone. Depending upon the unit of the quantity you take integral of, it has to be either volume or mass integral.
franc1 likes this.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 24, 2020, 04:57
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you may try to test this function to stop calculation, this is core, if it works go further:
Code:
CX_Interpret_String("(cx-interrupt)");
if works, so you can do everything from UDF

make global variables my_flux, total_energy.
code scheme may look like this:
Code:
#include "udf.h"
real my_flux = 1.e6;
real total_energy = 0.0;

DEFINE_EXECUTE_AT_END(execute_at_end)
{
   total_energy += my_flux*CURRENT_TIMESTEP;
   if (total_energy > 999) // your value here
      {
          CX_Interpret_String("(cx-interrupt)");
      }
}

DEFINE_PROFILE(my_flux_bc,t,i)
{
   face_t f;
   begin_f_loop(f,t)
   {
      F_PROFILE(f,t,i) = my_flux;
   }
   end_f_loop(f,t)
}
franc1, schwaral and bhwcs like this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   April 24, 2020, 10:23
Default
  #8
Member
 
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6
franc1 is on a distinguished road
I tried to solve the problem with the convergence method. I defined a parameter as: parameter= (Energy_target - Energy_inlet)

Energy_target is the target i want to reach;
Energy inlet is the difference between the actual and the initial total energy of my sistem.

In this way the "parameter" goes to zero during the simulation, but after this it goes to negative values.

Now, to stop the simulation i have to set a convergence condition. So i set in "convergence condition" the parameter as "report definition", but now i don't find a suitable value of the "stop criterion" to put. I don't find the meaning of this "stop criterion" in the help. What does it mean?
franc1 is offline   Reply With Quote

Old   April 24, 2020, 11:00
Default Stop Criterion
  #9
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Stop criterion is used as the minimum value below within solution is considered converged. So, if you set it to 0.001, it should work for you.
franc1 likes this.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 24, 2020, 11:32
Default
  #10
Member
 
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6
franc1 is on a distinguished road
I think that there's some problem with the exact definition of stop criterion.

If i put 3000 as "stop criterion" the simulation only does 2 time-steps and then stops.

While if i put the value of 0.001 as "stop criterion" the simulation stops at the time-step i fixed in the "Run calculation" window.

I attached the plot of the parameter.
Attached Images
File Type: png pic.PNG (6.6 KB, 27 views)
franc1 is offline   Reply With Quote

Old   April 24, 2020, 11:52
Default Stop Criterion
  #11
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
The working of the stop criterion is not very straightforward. It determines residual values over N number of previous iterations or time-step, as per the user input in number of previous iterations to consider. Value is determined as change in report definition value of those N number of iterations or time-steps. E.g., if you use 5 for previous iterations, then Fluent will determine fractional change in value of, say, pressure at inlet, over five iterations. Fraction is based on the latest iteration or time-step. So, for the second iteration, Fluent determine difference between pressure value at second and first iteration and then divides it by pressure at second iteration. For third iteration, it takes difference between pressure value at third and first iteration and then divides by pressure at third iteration and so on. Once the value is below the stop criterion within 5 iterations or time-steps, it stops. If it is not, then it starts again. So, 3000 being a large number, it will stop almost immediately. 0.001 may be too small. Look at the change in value and then use an appropriate number as stop criterion.
franc1 likes this.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 24, 2020, 12:56
Default
  #12
Member
 
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6
franc1 is on a distinguished road
Thank you very much Vinerm
franc1 is offline   Reply With Quote

Old   April 24, 2020, 13:33
Default
  #13
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,675
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
Also keep in mind stop criterion is based on reaching asymptotic behavior (+/-). If you want your simulation to stop immediately as soon as the threshold is reached, you might need to take the absolute value of your parameter and/or set the number of iterations to 1.
franc1 likes this.
LuckyTran 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
Problem in parallel simulation with UDF and Rotational domain Joao Bomfim Fluent UDF and Scheme Programming 7 July 16, 2019 17:10
UDF for Wall Boundary moving Left and right to create wave Simulation in a Flume buerskin Fluent UDF and Scheme Programming 2 July 3, 2019 21:23
Doubts in injection mould simulation (inlet conditions, temperature...) jpina FLUENT 7 October 3, 2016 08:14
Problem with DPM simulation with particles injection and EXECUTE_AT_THE_END UDF. Ari Fluent UDF and Scheme Programming 4 May 31, 2016 08:51
initial conditions with transient UDF Antoine Pages FLUENT 4 September 19, 2004 11:51


All times are GMT -4. The time now is 21:51.