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

for loop outside udf functions

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 27, 2022, 05:25
Default for loop outside udf functions
  #1
Member
 
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5
Pyrokrates is on a distinguished road
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];

}
Using the line with the for loop results in following error;
Code:
error: expected identifier or '('
Question is: How can I use loops outside any function of my UDF?
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
Pyrokrates is offline   Reply With Quote

Old   April 28, 2022, 02:10
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Old   April 28, 2022, 08:38
Default
  #3
Member
 
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5
Pyrokrates is on a distinguished road
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 03:20.
Pyrokrates is offline   Reply With Quote

Old   April 28, 2022, 21:55
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
Pyrokrates likes this.
__________________
best regards


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

Old   May 2, 2022, 04:26
Default
  #5
Member
 
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5
Pyrokrates is on a distinguished road
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
Pyrokrates is offline   Reply With Quote

Reply

Tags
loop., udf error


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
Save output of udf in another udf! JuanJoMex FLUENT 0 February 8, 2018 12:43
Replicating Scalable Wall Function with a UDF yousefaz FLUENT 0 August 4, 2017 02:30
Source Term UDF VS Porous Media Model pchoopanya Fluent UDF and Scheme Programming 1 August 28, 2013 06:12
functions in UDF Lucy FLUENT 4 April 14, 2011 16:41
UDF...UDF...UDF...UDF Luc SEMINEL FLUENT 0 November 25, 2002 04:03


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