changing scheme variable with UDF?
Hi All,
Is it possible to change or set a scheme variable through an UDF? Currently, I use rpsetvar after I get the value from the UDF by printf. Is there a way to do this directly in the UDF? Thanks |
Re: changing scheme variable with UDF?
yes. section 3.6 in the udf manual.
|
Re: changing scheme variable with UDF?
Thanks joe for the rapid respons,
I can access a scheme variable by rpgetvar in an UDF, and I'd like to change that variable within this UDF, not trhough the text interface by using rpsetvar. Is there a command similar to rpsetvar that can be used in the UDF? I read the UDf manual 3.6, but I don't seem to find it. Am I overlooking something? With regards, R. Wagemakers |
Hi Wagemakers,
I'm facing the same problem. Did you find any answer or workaround? Regards, Alessandro |
UDF Manual, section 3.6.4, has what you're looking for.
|
Hi Kokemoor,
Thanks for your reply. Looking at the UDF Manual (section 3.6.4), however, it seems that it's possible to define a scheme variable or get and use its value within the UDF. It is also possible to change the scheme-variable value, from the text interface. What I am looking for is a way to change the scheme-variable value from the UDF (instead of the text interface). Any suggestion? Thanks. |
Sure enough, I guess it doesn't show those. Can't imagine why not. I should've looked more closely at what I suggested myself :p
There are matching functions for all the RP_Get_* functions: RP_Set_Real("variable-name",real) RP_Set_Integer("variable-name",int) etc... |
Good call!
Thank you Kokemoor. |
Hi,
I am trying to update my 'temperature' boundary condition according to the total heat flux (radiation+convection) at the boundary during previous time step in an unsteady simulation. In order to do so, I am calling 'heat flux' in my UDF. Initially, I used heatflux=BOUNDARY_HEAT_FLUX(f,t); for this purpose. But I am not getting correct value of heat flux using this. So, now I want to use following command to obtain heat flux at each time step: heatflux=RP_Get_Real("myheatflux"); where 'myheatflux' is to be defined using TUI. I have used following TUI command: > (rp-var-define'myheatflux0.0'real#f) But there is a problem and it says Error: eval: unbound variable Error Object: t Can you please guide me what could be the reason for this error? or where I am wrong. As, I want to call this 'myheatflux' in my udf to update the boundary condition with time. Please let me know if I can do it by any other possible way. Thanks Udayraj Quote:
|
Hi Udayraj,
actually your procedure seems correct. 1- In the TUI you have to define your variable (rp-var-define 'myheatflux 0.0 'real #f) 2- try to check in the TUI the variable just created and its value with (rpgetvar 'myheatflux) this should return the variable velue (0 in this case) 3- in the UDF you shoud be able to get the variable value with heatflux=RP_Get_Real("myheatflux"); This should work... Let me know if everything is ok! Alsessandro |
Hi Dr. Aliosha,
Thanks you very much. As I said earlier also that fluent showing error as soon as I am typing first command. Please check below: > (rp-var-define'myheatflux0.0'real#f) Error: eval: unbound variable Error Object: t I am not able to define 'myheatflux'. Therefore, when I am giving second command as suggested by you it shows > (rpgetvar'myheatflux) Error: rp-var-value: undefined variable Error Object: myheatflux Can you suggest why I am not able to define 'myheatflux' using TUI command. Thanks Udayraj Quote:
|
If this (rp-var-define'myheatflux0.0'real#f) is the actual string that you wrote in the TUI, probably you miss the spaces...
try this (rp-var-define 'myheatflux 0.0 'real #f) and check with this (rpgetvar 'myheatflux) Let me know if it works, Alessandro |
Thanks Dr. Aliosha,
Thank you very much. It worked but I am facing a new problem now. I am able to define variable 'myheatflux' now using the command you suggested. > (rp-var-define 'myheatflux 0.0 'real #f) myheatflux Then I checked it > (rpgetvar 'myheatflux) 0 Now, I want to write report value into this variable. I used following command for that: > (rpsetvar 'myheatflux (pick-a-real " /report/fluxes sensor () heat-transfer no")) myheatflux Here, I want to assign total (convection+radiation) heat transfer 'heat-transfer' to this variable 'myheatflux'. where 'sensor' is the wall whose total heat flux I want in my udf. This is a transient problem and 'myheatflux' will be different at various time steps. Using this 'myheatflux' I want to update temperature assigned as boundary condition at the 'sensor' wall. My problem is that the 'myheatflux' remains zero at all time steps. It is not updating with time. Can you help in this? Am I missing something? Thanks Udayraj Quote:
|
If I have understood the problem, I think you could define an execute command to be executed each time step, with the string
(rpsetvar 'myheatflux (pick-a-real " /report/fluxes sensor () heat-transfer no")) Than, you can change the heat flux through the udf where the command heatflux=RP_Get_Real("myheatflux"); Did I get the problem correctly? Does it work? Alessandro |
Do I need to copy following line in execute command option of FLUENT?
(rpsetvar 'myheatflux (pick-a-real " /report/fluxes sensor () heat-transfer no")) I was writing this command in TUI. Please let me know whether you mean that I should write this command as execute command. Thanks Quote:
|
Yes, activate an execute command and copy the string inside!
|
Thanks...I will try it and let you know if I am able to do it. Thanks once again for prompt response.
Quote:
|
2 Attachment(s)
Hi Dr. Alessandro,
I tried to execute the command shown below (rpsetvar 'myheatflux (pick-a-real " /report/fluxes sensor () heat-transfer no")) My udf looks like #include "udf.h" real heatflux; FILE *fid; FILE *fid1; FILE *fid2; /* ------- Boundary Temperature Update -------------*/ DEFINE_PROFILE(boundary_temp,t,i) { face_t f; real Tnew; real Tp; int zoneid=THREAD_ID(t); heatflux=RP_Get_Real("myheatflux"); /* Write the property and thread id values for the flux condition to file */ fid=fopen("flux-ids","w"); fprintf(fid,"%d,%d\n",zoneid,i); fclose(fid); // Write total (Conduction+Radiation) heat flux value at the sensor /* Read in the heat flux value at the sensor */ fid1=fopen("sensor_heatflux_report","w"); fprintf(fid1,"%f\n",heatflux); fclose(fid1); /* Set profile values */ begin_f_loop(f,t) { if (CURRENT_TIME<=0.1) { //Tnew=300.0; F_PROFILE(f,t,i)=300.0; } else { /* Read the previous time step temp data */ Tp=C_T_M1(f,t); //Tp=300.0; /* Then calculate the new flux values */ Tnew=Tp+((-heatflux*4/(3.1416*0.04*0.04))*0.1*3.1416*0.04*0.04/(4.0*0.018*385.0)); // heatflux is actually heat-transfer-rate in watt (W) /* Write the updated temperature to file */ fid2=fopen("Temperature","w"); fprintf(fid2,"%f,%d,%f,%f,%f\n",CURRENT_TIME,i,Tp, heatflux,Tnew); fclose(fid2); /* Then set the new flux values */ F_PROFILE(f,t,i)=Tnew; } } end_f_loop(f,t) } I am getting a fatal error after first time step as shown below: Updating solution at time level N... done. Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: #f Then I changed Tp in the UDF to a constant value 300.0 just to check whether this is a problem due to the defined previous time temperature Tp or not. In that case there is no fatal error but still there is some problem. 'myheatflux' is not updating with time and it remains zero. Please check the two snapshots taken at the first and second time step. Please check attachment. Your expert comments may help me to identify and rectify the error. Please let me know if there are some mistakes in my UDF. Thanks Udayraj Quote:
|
All times are GMT -4. The time now is 12:44. |