|
[Sponsors] |
April 27, 2022, 06:25 |
for loop outside udf functions
|
#1 |
Member
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5 |
Hey,
maybe a simple question but I didnīt find a answer yet. I would like to use some global variables for which I need to loop. What I basically wanna do is this (just an simple example): Code:
#include "udf.h" #include <math.h> #include <stdio.h> const int N = 5; real A[N] = {1,5,9,13,17}; real B[N]; for(int i = 0; i < N; i++) { B[i] = pow(A[i],2) + i * A[i]; } Code:
error: expected identifier or '(' Or do I need to define it with DEFINE_INIT(name,d)? If I do so (and use my initial solution for another simulation with another UDF), does Fluent keep my B[N] variables for the second simulation? Because as far as I know, the initialization is only called once for the first simulation (when klicking initialization button in GUI). Thanks in advance Pyro |
|
April 28, 2022, 03:10 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
code which you are going to execute should be inside fluent build in macros.
depends on when you want code to be executed you are choosing the macro: could be DEFINE_INIT in case you want code to be executed once when you click initialize button could be DEFINE_ADJUST in case you want code to be executed before each iteration(time step for transient) and so on list of macros you may find in table of contents of Fluent customization manual for your case B[i] will be updated each time you click initialize.
__________________
best regards ****************************** press LIKE if this message was helpful |
|
April 28, 2022, 09:38 |
|
#3 |
Member
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5 |
Thank you for the answer.
I have already tied out DEFINE_INIT in past but the problem I figured out was, that If I try to use it with UDM than the initialization destroys my program... I tried following: 1) DEFINE_INIT to set my C_UDMI(c,t,0) values 2) Using some DEFINE_PROFILE where I want to set C_PROFILE(c,t,i) = C_UDMI(c,t,0) Problem here is like mentioned above that the initialization (standard) sets my UDM values and resets them also meaning the input for 2) is 0 everywhere... Why Iīm trying to do this is because I would like to pre define a profile for my mesh and do not update it over time... If I just set the profile inside DEFINE_PROFILE, the program recalculates the same field again and again which is a waste of time. Any suggestions? Thanks in advance Pyro Last edited by Pyrokrates; May 2, 2022 at 04:20. |
|
April 28, 2022, 22:55 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
actually you did it correct with DEFINE_INIT
most likely you forgot to allocate the memory for udm in fluent GUI if that's not the case: show your code, explain settings, describe errors, compile code and show log
__________________
best regards ****************************** press LIKE if this message was helpful |
|
May 2, 2022, 05:26 |
|
#5 |
Member
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5 |
Hi and thanks for your answer.
It is working now... I didnīt see, that the DEFINE_INIT step is called after the DEFINE_PROFILE while initialization... So the init first set my UDM to zero and than at the end of init I get my values set. So the profile is zero until the first real simulation step starts. Thanks, Pyro |
|
Tags |
loop., udf error |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Save output of udf in another udf! | JuanJoMex | FLUENT | 0 | February 8, 2018 13:43 |
Replicating Scalable Wall Function with a UDF | yousefaz | FLUENT | 0 | August 4, 2017 03:30 |
Source Term UDF VS Porous Media Model | pchoopanya | Fluent UDF and Scheme Programming | 1 | August 28, 2013 07:12 |
functions in UDF | Lucy | FLUENT | 4 | April 14, 2011 17:41 |
UDF...UDF...UDF...UDF | Luc SEMINEL | FLUENT | 0 | November 25, 2002 05:03 |