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

Passing variables between DEFINE_ON_DEMAND macros

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 3, 2023, 21:17
Default Passing variables between DEFINE_ON_DEMAND macros
  #1
Member
 
BM
Join Date: Sep 2021
Posts: 35
Rep Power: 5
blyatman is on a distinguished road
I have two define_on_demand macros called "run1" and "run2".

"run1" spits out an array x. "run2" uses x, as well as a parameter y obtained from Get_Input_Parameter, to spit out another output z, so z = z(x,y).

I am trying to build a workflow that does something like this:
1. Call "run1" to get x.
2. Set a value of y, call "run2" to get z, save results.
3. Repeat previous step for different values of y.

The reason I do not want to combine "run1" and "run2" into a single define_on_demand macro is because I only need to execute "run1" once. If I combine it into a single macro with "run2", then "run1" would execute every single time with "run2", which is unnecessary and potentially time-consuming.

Is there a way to do this? I have considered using scheme variables, but there is no option to define an array using a scheme variable.
blyatman is offline   Reply With Quote

Old   April 9, 2023, 10:33
Default
  #2
Member
 
Odisha
Join Date: Jan 2020
Posts: 59
Rep Power: 6
Siba11 is on a distinguished road
Hi. You say that you need to execute "run1" only once. This means that while the parameter 'y' will attain different values, the array will be treated as a constant. So why don't you add that array as an input variable in your second UDF (run2). And then execute only "run2" for as many times as you want.

This will save you from having to write any scheme scripts.
Siba11 is offline   Reply With Quote

Old   April 10, 2023, 01:21
Default
  #3
Member
 
BM
Join Date: Sep 2021
Posts: 35
Rep Power: 5
blyatman is on a distinguished road
Quote:
Originally Posted by Siba11 View Post
Hi. You say that you need to execute "run1" only once. This means that while the parameter 'y' will attain different values, the array will be treated as a constant. So why don't you add that array as an input variable in your second UDF (run2). And then execute only "run2" for as many times as you want.

This will save you from having to write any scheme scripts.
When you say to add that array into run2, do you mean hardcoding 'x' into run2? I would be using this workflow for different cases, so hardcoding 'x' would not be practical.
blyatman is offline   Reply With Quote

Old   April 10, 2023, 03:14
Default
  #4
Member
 
Odisha
Join Date: Jan 2020
Posts: 59
Rep Power: 6
Siba11 is on a distinguished road
Hi. Maybe I'm misunderstanding. What is this "x" array exactly? Like, is it an array storing the coordinates of all mesh cells or something like that?

As you might be knowing, DEFINE_ON_DEMAND doesn't execute every iteration as it is outside the solver loop. So whatever value this "run1" is spitting out, it must be independent of the iteration number. So, you can execute "run1" once, get the array "x", and hardcode it into "run2".

(UNLESS of course 'x' is something that's going to change on the fly.)
Siba11 is offline   Reply With Quote

Old   April 10, 2023, 05:25
Default
  #5
Member
 
BM
Join Date: Sep 2021
Posts: 35
Rep Power: 5
blyatman is on a distinguished road
Quote:
Originally Posted by Siba11 View Post
Hi. Maybe I'm misunderstanding. What is this "x" array exactly? Like, is it an array storing the coordinates of all mesh cells or something like that?

As you might be knowing, DEFINE_ON_DEMAND doesn't execute every iteration as it is outside the solver loop. So whatever value this "run1" is spitting out, it must be independent of the iteration number. So, you can execute "run1" once, get the array "x", and hardcode it into "run2".

(UNLESS of course 'x' is something that's going to change on the fly.)
'x' is going to be an array of arrays, and it will be a mesh-related quantity that is independent of the solution. This array could have a million elements, and for each element, there could be a few thousand elements. As a result, it is impractical to hardcode it, which is why I am trying to figure out a way to pass it into "run2" (not to mention that I will be running a script that does this for other meshes, so hardcoding 'x' would again be out of the question). Hope this clears up the confusion.
blyatman is offline   Reply With Quote

Reply

Tags
scheme, udf


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
Passing variables to a codedBC tladd OpenFOAM Programming & Development 2 May 30, 2021 15:51
[swak4Foam] How to define boundary condition variables by using previosly defined variables? pawlo OpenFOAM Community Contributions 8 September 13, 2020 12:37
Optimal tolerance and variables scaling settings 4513645ygq Main CFD Forum 0 July 28, 2020 09:56
Some variables not loading in Tecplot nick.l.thomas Tecplot 1 October 25, 2018 18:48
Passing fortran variables to C in mixed programmin Quarkz Main CFD Forum 1 January 9, 2008 07:17


All times are GMT -4. The time now is 12:02.