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

[UDF] Can you help to figure out the error?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 17, 2020, 08:26
Default [UDF] error C2106: '=': left operand ...
  #1
Member
 
mCiFlDk's Avatar
 
mCiFlDk
Join Date: Feb 2020
Posts: 56
Rep Power: 6
mCiFlDk is on a distinguished road
Hi everyone,


I have a simple rectangular domain, where I'm adding a force in X direction using a UDF. The UDF depends on X and Y but is straight forward in the rest of elements (Fig. 1). The code is just below and everything is calculated inside a DEFINE_SOURCE macros, where f_b is the body force exerted in the X component and what I'm trying to do is running it inside the limits (that's why I included an if-else).

I've been a couple of hours solving several errors that appeared in the UDF, but I'm not able to figure out what is this one. When I compile it in Fluent I obtain the following errors:

Code:
..\..\src\UDF_Yoon.c(23): error C2106: '=': left operand must be l-value
..\..\src\UDF_Yoon.c(24): error C2106: '=': left operand must be l-value
..\..\src\UDF_Yoon.c(26): error C2065: 'f': undeclared identifier
..\..\src\UDF_Yoon.c(28): error C2109: subscript requires array or pointer type
..\..\src\UDF_Yoon.c(31): error C2181: illegal else without matching if
..\..\src\UDF_Yoon.c(33): error C2109: subscript requires array or pointer type
..\..\src\UDF_Yoon.c(33): error C2065: 'f': undeclared identifier
..\..\src\UDF_Yoon.c(34): error C2109: subscript requires array or pointer type
..\..\src\UDF_Yoon.c(34): error C2198: 'sin': too few arguments for call
..\..\src\UDF_Yoon.c(34): error C2198: 'cos': too few arguments for call
I think I commited an error (or a couple of them) that are affecting the whole UDF, but I can't find them.


I'd appreciate a lot your help.

Regards
Attached Images
File Type: jpg IMG_20200517_141927.jpg (45.6 KB, 27 views)

Last edited by mCiFlDk; June 6, 2020 at 07:19. Reason: Copyright in my own work
mCiFlDk is offline   Reply With Quote

Old   May 17, 2020, 13:30
Default Bugs
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
The code is riddled with syntactical as well as logical bugs.

1. You are trying to save output of an equation that will return a real value to an enumeration variable. That's not doable. So, either remove l and h from enum and define those as real or define two new variable as real and assign values of first two equations to those variables.

2. DEFINE_SOURCE is automatically executed in a cell loop, i.e., function is executed at each cell. There could be a need to loop over faces of each cell to determine values of some function but apparently not in your case. So, remove face loop.

3. x is a real variable but it needs to have some value assigned before you can use it for comparison. So, you need to use C_CENTROID before comparing values of coordinates in conditional statement.

4. C_UDMI needs initialization but you can do that using Patch option as well. If you are not doing that, then you need to use a loop, NOT within DEFINE_SOURCE, to initialize UDMs. Also note that as per your code, you need 3 UDMs since value of Fx is 2. If this is the complete code, then you don't need 3 UDMs. So, use l in place of Fx or simply use 0 as third argument of C_UDMI.

5. dS[eqn] is supposed to be first-order derivative of source term with respect to the field variable to which source is being applied. Of course, this UDF can be hooked for any field, but most likely you want to apply this to one of the velocity component or may be to all of the components. That means, dS[eqn] should be derivative of the source term with respect to that component. But, if you look at the source term, it does not appear to be a function of any velocity. That means, dS[eqn] should be 0.

Lastly, not a bug but the usage of the UDF. You don't need this UDF. Since the source value is not changing from iteration to iteration or with time, you can pre-calculate the values and apply a profile for the source.
__________________
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.
vinerm is offline   Reply With Quote

Old   May 18, 2020, 07:38
Default
  #3
Member
 
mCiFlDk's Avatar
 
mCiFlDk
Join Date: Feb 2020
Posts: 56
Rep Power: 6
mCiFlDk is on a distinguished road
Quote:
Originally Posted by vinerm View Post
The code is riddled with syntactical as well as logical bugs.
You were completely right. However, thanks to your detailed explanation you made me understand every of the steps and I fixed it, so first of all: thank you SO much, I appreciate a lot your time.

I looked for every step you told me, changed other several tiny things and I'm starting to understand how ANSYS UDFs work thanks to explaining it, and not only saying: this is bad or that is wrong. You made one CFD lover very happy

Quote:
Originally Posted by vinerm View Post
4. C_UDMI needs initialization but you can do that using Patch option as well.
As regards to this quote I had a doubt, since I couldn't find what ANSYS does when you use the Patch option. What is it exactly?

Quote:
Originally Posted by vinerm View Post
Lastly, not a bug but the usage of the UDF. You don't need this UDF. Since the source value is not changing from iteration to iteration or with time, you can pre-calculate the values and apply a profile for the source.
Finally, regarding this quote, I decided to do it using a DEFINE_SOURCE because I have to use this function for 2D and 3D and from serial to parallel, simply to maintain the same structure. To do it, should I take into account any significant change?

Thank you so much again.

Regards

Code:
Eliminated because of copyright

Last edited by mCiFlDk; June 6, 2020 at 07:19.
mCiFlDk is offline   Reply With Quote

Old   May 18, 2020, 08:06
Default Patch and Version
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Patch is initialization but localized to a particular region or for a particular variable, in this case for UDM over whole domain.

If you want the code to work for 2D as well as 3D, you will have to modify it further since you can't compare z-coordinates in 2D. In any case, profile would be faster and you won't have to worry about serial or parallel.
__________________
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.
vinerm is offline   Reply With Quote

Old   May 18, 2020, 11:34
Default
  #5
Member
 
mCiFlDk's Avatar
 
mCiFlDk
Join Date: Feb 2020
Posts: 56
Rep Power: 6
mCiFlDk is on a distinguished road
Quote:
Originally Posted by vinerm View Post
In any case, profile would be faster and you won't have to worry about serial or parallel.
That intrigues me. Do you mean, creating a 2D profile and then "extending" it with a loop over Z direction? Because I haven't thought about this but looks simpler.

Regards
mCiFlDk is offline   Reply With Quote

Old   May 18, 2020, 11:40
Default Profile
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
It is a static, text file and has no loop or anything. Refer

https://www.afs.enea.it/project/nept...ug/node263.htm
__________________
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.
vinerm is offline   Reply With Quote

Old   May 18, 2020, 12:17
Default
  #7
Member
 
mCiFlDk's Avatar
 
mCiFlDk
Join Date: Feb 2020
Posts: 56
Rep Power: 6
mCiFlDk is on a distinguished road
Quote:
Originally Posted by vinerm View Post
It is a static, text file and has no loop or anything. Refer

https://www.afs.enea.it/project/nept...ug/node263.htm
I'll investigate it consciously. Thank you!
mCiFlDk is offline   Reply With Quote

Reply


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
[swak4Foam] GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh gschaider OpenFOAM Community Contributions 300 October 29, 2014 18:00
Undeclared Identifier Errof UDF SteveGoat Fluent UDF and Scheme Programming 7 October 15, 2014 07:11
checking the system setup and Qt version vivek070176 OpenFOAM Installation 22 June 1, 2010 12:34
[swak4Foam] groovyBC: problems compiling: "flex: not found" and "undefined reference to ..." sega OpenFOAM Community Contributions 12 February 17, 2010 09:30
error while compiling the USER Sub routine CFD user CFX 3 November 25, 2002 15:16


All times are GMT -4. The time now is 01:13.