|
[Sponsors] |
Stop simulation after given conditions (UDF) |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 23, 2020, 11:47 |
Stop simulation after given conditions (UDF)
|
#1 |
Member
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6 |
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! |
|
April 23, 2020, 15:42 |
Stopping Fluent
|
#2 |
Senior Member
|
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.
__________________
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. |
|
April 24, 2020, 05:18 |
|
#3 |
Member
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6 |
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) |
|
April 24, 2020, 05:31 |
Energy
|
#4 |
Senior Member
|
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. |
|
April 24, 2020, 05:33 |
|
#5 |
Member
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6 |
The accumulated one
|
|
April 24, 2020, 05:43 |
Accumulated Energy
|
#6 |
Senior Member
|
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.
__________________
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. |
|
April 24, 2020, 05:57 |
|
#7 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you may try to test this function to stop calculation, this is core, if it works go further:
Code:
CX_Interpret_String("(cx-interrupt)"); 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) }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
April 24, 2020, 11:23 |
|
#8 |
Member
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6 |
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? |
|
April 24, 2020, 12:00 |
Stop Criterion
|
#9 |
Senior Member
|
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.
__________________
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. |
|
April 24, 2020, 12:32 |
|
#10 |
Member
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6 |
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. |
|
April 24, 2020, 12:52 |
Stop Criterion
|
#11 |
Senior Member
|
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.
__________________
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. |
|
April 24, 2020, 13:56 |
|
#12 |
Member
Francesco
Join Date: Apr 2020
Posts: 56
Rep Power: 6 |
Thank you very much Vinerm
|
|
April 24, 2020, 14:33 |
|
#13 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,761
Rep Power: 66 |
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.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF for Wall Boundary moving Left and right to create wave Simulation in a Flume | buerskin | Fluent UDF and Scheme Programming | 3 | September 30, 2024 01:05 |
Problem in parallel simulation with UDF and Rotational domain | Joao Bomfim | Fluent UDF and Scheme Programming | 7 | July 16, 2019 18:10 |
Doubts in injection mould simulation (inlet conditions, temperature...) | jpina | FLUENT | 7 | October 3, 2016 09:14 |
Problem with DPM simulation with particles injection and EXECUTE_AT_THE_END UDF. | Ari | Fluent UDF and Scheme Programming | 4 | May 31, 2016 09:51 |
initial conditions with transient UDF | Antoine Pages | FLUENT | 4 | September 19, 2004 12:51 |