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

udf source term

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 18, 2020, 07:15
Default udf source term
  #1
New Member
 
iyad
Join Date: Nov 2019
Posts: 21
Rep Power: 7
pitch is on a distinguished road
hello ;
i need help , i am simulating a rotating airfoil and i wrote a udf for the motion by define_zone_motion so i define psi (azimuth angle ) psi =omega*(time) and omega is the rotational speed.
but i want to activate the source term only in 90° to 120° azimuthal position

appreciate any help please
thanks

Last edited by pitch; February 26, 2020 at 12:03.
pitch is offline   Reply With Quote

Old   February 18, 2020, 08:51
Default Clarify
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Your description is little unclear. Is there issue with zone motion UDF or with source UDF?
__________________
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   February 18, 2020, 09:07
Default
  #3
New Member
 
iyad
Join Date: Nov 2019
Posts: 21
Rep Power: 7
pitch is on a distinguished road
Thank you
For the source term how to active with azimth position because to use in define_source the same angle defined in zone_motion it sows error that undeclared variable

Last edited by pitch; February 18, 2020 at 10:07.
pitch is offline   Reply With Quote

Old   February 18, 2020, 15:23
Default Azimuthal position
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
So, all you need is to know the azimuthal position within DEFINE_SOURCE. If the rotational displacement or speed is user parameter then you can do the same calculation in DEFINE_SOURCE and apply the source if the position is within the required bounds.
__________________
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   February 18, 2020, 16:01
Default
  #5
New Member
 
iyad
Join Date: Nov 2019
Posts: 21
Rep Power: 7
pitch is on a distinguished road
dear vinerm
i am using this
DEFINE_ZONE_MOTION(blade,omega,axis,origin,velocit y,time,dtime)
{

psi=omegac*(time);
return;

}
DEFINE_SOURCE(Source1, c, t, dS, eqn)
{
real Source;
real time = RP_Get_Real("flow-time");
real psi=omegac*(time);

if (psi>= 90*M_PI/180 && psi <= 100*M_PI/180 )
{
Source=C_UDMI(c,t,F); ****i saved C_UDMI(c,t,F)*****
dS[eqn]=0;
}
else
{
Source=0.0;
dS[eqn]=0;
}
return Sourcex;

}

Last edited by pitch; February 26, 2020 at 12:04.
pitch is offline   Reply With Quote

Old   February 18, 2020, 16:18
Default Time and Zone Motion
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Hi

If this is the complete UDF then I have doubts that it works. Your SOURCE UDF is alright. It should work perfectly, except for two issues. What is omegac? It is not defined anywhere. Furthermore, what is F, the last argument of UDM? The last argument should correspond to the number of the UDM. If you have only one UDM in your case, then it should be 0 and not F. Of course, you can call it F provided you declare int F = 0; in your code.

ZONE_MOTION is supposed to provide velocities and not position. If omega is fixed or changing with time, you do not need this UDF. For fixed omega, just provide the number in the cell zone conditions. If it is changing with time, then you can use this UDF or profile. But in that case, UDF requires modification. psi is not defined anywhere nor is omegac.

As far as time is concerned, it is not a property of any macro. This is available to all macros. You can directly use CURRENT_TIME instead of using RP macro. CURRENT_TIME is a C based variable defined in Fluent and is equal to the current simulation time.
__________________
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   February 18, 2020, 16:36
Default
  #7
New Member
 
iyad
Join Date: Nov 2019
Posts: 21
Rep Power: 7
pitch is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Hi

If this is the complete UDF then I have doubts that it works. Your SOURCE UDF is alright. It should work perfectly, except for two issues. What is omegac? It is not defined anywhere. Furthermore, what is F, the last argument of UDM? The last argument should correspond to the number of the UDM. If you have only one UDM in your case, then it should be 0 and not F. Of course, you can call it F provided you declare int F = 0; in your code.

ZONE_MOTION is supposed to provide velocities and not position. If omega is fixed or changing with time, you do not need this UDF. For fixed omega, just provide the number in the cell zone conditions. If it is changing with time, then you can use this UDF or profile. But in that case, UDF requires modification. psi is not defined anywhere nor is omegac.

As far as time is concerned, it is not a property of any macro. This is available to all macros. You can directly use CURRENT_TIME instead of using RP macro. CURRENT_TIME is a C based variable defined in Fluent and is equal to the current simulation time.
Can you give me your skype or email to contact you please
pitch is offline   Reply With Quote

Old   February 18, 2020, 18:18
Default
  #8
New Member
 
iyad
Join Date: Nov 2019
Posts: 21
Rep Power: 7
pitch is on a distinguished road
Psi is defined

Last edited by pitch; February 19, 2020 at 13:16.
pitch is offline   Reply With Quote

Old   February 18, 2020, 18:46
Default
  #9
Senior Member
 
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 416
Rep Power: 15
Svetlana is on a distinguished road
omegac is not defined in the code; can you please add it?
Svetlana is offline   Reply With Quote

Old   February 18, 2020, 18:58
Default
  #10
New Member
 
iyad
Join Date: Nov 2019
Posts: 21
Rep Power: 7
pitch is on a distinguished road
Quote:
Originally Posted by Светлана View Post
omegac is not defined in the code; can you please add it?
Thank you
Its defined befor define zone motion its just not shown
Real omegac =500rpm

Last edited by pitch; February 26, 2020 at 12:04.
pitch is offline   Reply With Quote

Old   February 18, 2020, 19:28
Default
  #11
Senior Member
 
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 416
Rep Power: 15
Svetlana is on a distinguished road
Can you please post the complete code?
Svetlana is offline   Reply With Quote

Old   February 19, 2020, 04:31
Default Issue
  #12
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
From any of your posts, it is not clear what the issue is. Did you try the code? In my view, if you make the changes recommended by Svetlana and me, it would work alright. Let us know if you face any issue and also post the issue that you face.
__________________
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   February 19, 2020, 11:06
Default
  #13
New Member
 
iyad
Join Date: Nov 2019
Posts: 21
Rep Power: 7
pitch is on a distinguished road
Quote:
Originally Posted by vinerm View Post
From any of your posts, it is not clear what the issue is. Did you try the code? In my view, if you make the changes recommended by Svetlana and me, it would work alright. Let us know if you face any issue and also post the issue that you face.
i change theif so it is as fonction of time not omegac

but stil the Sourcex=0 so it's not changing with time

Last edited by pitch; February 19, 2020 at 13:01.
pitch is offline   Reply With Quote

Old   February 19, 2020, 11:12
Default Error
  #14
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Are you able to run a simulation with this code? Fluent would give error as soon as you compile it or interpret it. It should be C_UDMI(c, t, 1), assuming you have at least 2 UDMs in your simulation. If there is only one UDM, then it should be C_UDMI(c, t, 0). You cannot use F as an argument. If you wish to multiply UDM value with F, it has to be C_UDMI(c,t,0) * F or C_UDMI(c,t,1) * F. And C_UDMI should have a value that is different from 0.
__________________
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   February 19, 2020, 11:21
Default
  #15
New Member
 
iyad
Join Date: Nov 2019
Posts: 21
Rep Power: 7
pitch is on a distinguished road
[QUOTE=vinerm;758737]Are you able to run a simulation with this code? Fluent would give error as soon as you compile it or interpret it. It should be C_UDMI(c, t, 1), assuming you have at least 2 UDMs in your simulation. If there is only one UDM, then it should be C_UDMI(c, t, 0). You cannot use F as an argument. If you wish to multiply UDM value with F, it has to be C_UDMI(c,t,0) * F or C_UDMI(c,t,1) * F. And C_UDMI should have a value that is different from 0.[/QUOTE

DEFINE_SOURCE(X_Source1, c, t, dS, eqn)
{
real Sourcex;
real time= CURRENT_TIME;

if (0.0 <= CURRENT_TIME < 0.02 )
{
Sourcex=C_UDMI(c,t,Fx1);

dS[eqn]=0;
}
else if (0.02<= CURRENT_TIME < 0.03 )
{
Sourcex=0.0;
dS[eqn]=0;
}
return Sourcex;

}
please for all variables are defined in the code just too lange to show so the problem is in time
and after i compile it no error

Last edited by pitch; February 19, 2020 at 16:22.
pitch is offline   Reply With Quote

Old   February 19, 2020, 11:44
Default Source
  #16
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Alright, I am assuming that the indices that you use for UDMs are defined, either as integers or enum. And they have to be, otherwise your code would not have worked. There are also a few commands that are not of any use, such as, extraction of Zone ID. First thing you can check is the time of your case. Use the following command in TUI to see whether the time is between 0 and 0.02 or not.

(rpgetvar 'flow-time)

Also, at least for the debugging, use a smaller time-step, such as, 0.002. If the time is within the bounds where source should have some value other than 0 then do the following

1. Write a profile file as follows, using any text editor.

((sourcex transient 3 0)
(time
0
0.02
0.03
)
(src
900.0
1000.0
0.0
))

2. Read this into Fluent and hook in place of Source UDF.
3. Run the case for one time-step and see if you observe the effects of 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   February 19, 2020, 12:04
Default
  #17
New Member
 
iyad
Join Date: Nov 2019
Posts: 21
Rep Power: 7
pitch is on a distinguished road
IT SHOWS > (rpgetvar 'flow-time)
invalid command [(rpgetvar]
**and i included the brackets *
pitch is offline   Reply With Quote

Old   February 19, 2020, 12:10
Default Copy-Paste
  #18
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Did you do a copy and paste from the post? Then it will give this error. Yes, you have to use parentheses but you need to type the command.
__________________
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   February 19, 2020, 12:17
Default
  #19
New Member
 
iyad
Join Date: Nov 2019
Posts: 21
Rep Power: 7
pitch is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Did you do a copy and paste from the post? Then it will give this error. Yes, you have to use parentheses but you need to type the command.
so i change it to
DEFINE_SOURCE(X_Source1, c, t, dS, eqn)
{
real Sourcex;
real time= CURRENT_TIME;

if (0.0 <= CURRENT_TIME < 0.001 )
{
Sourcex=C_UDMI(c,t,Fx1);
dS[eqn]=0;
}
else if (0.001 <= CURRENT_TIME < 0.003 )
{
Sourcex=0.0;
dS[eqn]=0;
}
return Sourcex;
}
i get this
> (rpgetvar 'flow-time)
0.001
pitch is offline   Reply With Quote

Old   February 19, 2020, 12:20
Default Time-step
  #20
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
What I meant is that you keep your code as it but use a smaller time-step in Run Simulation panel. As far as using profile is concerned, do not use the UDF. Use only the profile and check if it works.
__________________
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

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] swak4foam for OpenFOAM 4.0 mnikku OpenFOAM Community Contributions 80 May 17, 2022 09:06
[foam-extend.org] Problems installing foam-extend-4.0 on openSUSE 42.2 and Ubuntu 16.04 ordinary OpenFOAM Installation 19 September 3, 2019 19:13
using value of surface integral in source term UDF morihangi Fluent UDF and Scheme Programming 0 March 23, 2019 04:59
SparceImage v1.7.x Issue on MAC OS X rcarmi OpenFOAM Installation 4 August 14, 2014 07:42
Problem compiling a custom Lagrangian library brbbhatti OpenFOAM Programming & Development 2 July 7, 2014 12:32


All times are GMT -4. The time now is 20:49.