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

Accessing phase volm fraction in UDF for a source term in mixture model

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   March 19, 2013, 08:54
Default Accessing phase volm fraction in UDF for a source term in mixture model
  #1
New Member
 
Aditya Pandare
Join Date: Aug 2012
Location: Pune, India
Posts: 20
Rep Power: 4
aditya.pandare is on a distinguished road
Hello
I am trying to simulate cavitation using a UDF for the source term of vapor phase in the mixture model.
I am having trouble accessing the volume fraction of the secondary phase. this is the UDF I wrote. I am new to UDFs, so please help me.

#include "udf.h"

DEFINE_SOURCE(re,c,t,dS,eqn)
{
real source, prsr, alpha, pv, zoneid;
zoneid = 11;
Thread *mixture_thread = Lookup_Thread(domain,zid);
Thread **pt;
pt = THREAD_SUB_THREADS(mixture_thread);
prsr = C_P(c,t);
alpha = C_VOF(c,pt[3]);
pv = -97000;
source = 0.02 * (sqrt((2/3)*(pv - prsr)/998.2)) * (1-alpha) * 998.2 * 0.5542 / 0.0717;
dS[eqn] = - 0.02 * (sqrt((2/3)*(pv - prsr)/998.2)) * 998.2 * 0.5542 / 0.0717;
return source;
}

It gives a parse error for the 2 lines beginning with "Thread"
Any help in understanding the working of the THREAD syntaxes!
aditya.pandare is offline   Reply With Quote

Old   March 19, 2013, 09:53
Default
  #2
Member
 
Li Huang
Join Date: Jan 2011
Posts: 30
Rep Power: 5
lihuang is on a distinguished road
What are the error messages exactly?

I had a quick look at your code. It seems to me that you have "domain" undefined, which normally is 1.

What operating system are you using? To my experience, if you are under windows, most likely you have to declare all you local variables at top, for example, before the line "zoneid = 11;" in your code. If you are under Linux, this does not matter.

Good luck

Quote:
Originally Posted by aditya.pandare View Post
Hello
I am trying to simulate cavitation using a UDF for the source term of vapor phase in the mixture model.
I am having trouble accessing the volume fraction of the secondary phase. this is the UDF I wrote. I am new to UDFs, so please help me.

#include "udf.h"

DEFINE_SOURCE(re,c,t,dS,eqn)
{
real source, prsr, alpha, pv, zoneid;
zoneid = 11;
Thread *mixture_thread = Lookup_Thread(domain,zid);
Thread **pt;
pt = THREAD_SUB_THREADS(mixture_thread);
prsr = C_P(c,t);
alpha = C_VOF(c,pt[3]);
pv = -97000;
source = 0.02 * (sqrt((2/3)*(pv - prsr)/998.2)) * (1-alpha) * 998.2 * 0.5542 / 0.0717;
dS[eqn] = - 0.02 * (sqrt((2/3)*(pv - prsr)/998.2)) * 998.2 * 0.5542 / 0.0717;
return source;
}

It gives a parse error for the 2 lines beginning with "Thread"
Any help in understanding the working of the THREAD syntaxes!
lihuang is offline   Reply With Quote

Old   March 19, 2013, 10:16
Default
  #3
Senior Member
 
Paritosh Vasava
Join Date: Oct 2012
Location: Lappeenranta, Finland
Posts: 425
Rep Power: 12
vasava will become famous soon enough
Shouldn't you use 'zoneid' instead of 'zid' in the line 'Thread *mixture_thread = Lookup_Thread(domain,zid);' ??
vasava is offline   Reply With Quote

Old   March 19, 2013, 10:27
Default
  #4
New Member
 
Aditya Pandare
Join Date: Aug 2012
Location: Pune, India
Posts: 20
Rep Power: 4
aditya.pandare is on a distinguished road
@lihuang: The messages are: "error: line no.: parse error."
I am using 32bit windows 7.
But I have declared those in the "real......" line, right?
Actually since I am new to UDFs, I do not know how to define the domain.
Could you help me do that? How is the domain defined? what is the syntax?

@vasava: yes I should. I have made that change.

Thank you both for your quick replies!
aditya.pandare is offline   Reply With Quote

Old   March 19, 2013, 14:36
Default
  #5
Member
 
Li Huang
Join Date: Jan 2011
Posts: 30
Rep Power: 5
lihuang is on a distinguished road
Quote:
Originally Posted by aditya.pandare View Post
@lihuang: The messages are: "error: line no.: parse error."
I am using 32bit windows 7.
But I have declared those in the "real......" line, right?
Actually since I am new to UDFs, I do not know how to define the domain.
Could you help me do that? How is the domain defined? what is the syntax?

@vasava: yes I should. I have made that change.

Thank you both for your quick replies!
The "real ..." line looks ok to me. It's just the "Thread *mixture_thread = .." and "Thread **pt;" needs to be moved up before "zoneid=11;".

While using Lookup_Thread, you need to know what kind of "domain" you are looking at. There are three kinds: Mixture domain, sub-domain (phase domains), and interaction domain. For mixture domain, domainID=1; for phase domains, domainID can be found in the Phase Panel in Fluent.


Good luck
lihuang is offline   Reply With Quote

Old   March 20, 2013, 00:10
Default
  #6
New Member
 
Aditya Pandare
Join Date: Aug 2012
Location: Pune, India
Posts: 20
Rep Power: 4
aditya.pandare is on a distinguished road
Thank you for your help! But i am still facing problems in that UDF.
I moved the two lines up before the "zoneid=11" line; but it still gives me a "parse error" in the "Thread *mixture_thread;" line.

Also, If i move the "Thread *mixture_thread = Lookup_Thread(domain,zoneid);" line before the "zoneid = 11;" line, how will it know the zoneid to use in the Lookup thread command?

Another question: i am "interpreting" this udf file; does that make any difference?

yes I have looked up the zone-ID in the phases dialog box. but here; the "lookup_thread"is used to define the mixture thread; so I am using the zone-ID from the BC dialog box. Is this correct? I am using this mixture-thread to define the "pt" with the "thread_sub_threads".

This is how I used the UDF with the corrections you told me:

#include "udf.h"

DEFINE_SOURCE(re,c,t,dS,eqn)
{
real source, prsr, alpha, pv, zoneid;
Thread *mixture_thread;
Thread **pt;
zoneid = 11;
Thread *mixture_thread = Lookup_Thread(domain,zoneid);
pt = THREAD_SUB_THREADS(mixture_thread);
prsr = C_P(c,t);
alpha = C_VOF(c,pt[3]);
pv = -97000;
source = 0.02 * (sqrt((2/3)*(pv - prsr)/998.2)) * (1-alpha) * 998.2 * 0.5542 / 0.0717;
dS[eqn] = - 0.02 * (sqrt((2/3)*(pv - prsr)/998.2)) * 998.2 * 0.5542 / 0.0717;
return source;
}
Please help!
aditya.pandare is offline   Reply With Quote

Old   March 20, 2013, 00:29
Default
  #7
Member
 
Li Huang
Join Date: Jan 2011
Posts: 30
Rep Power: 5
lihuang is on a distinguished road
Quote:
Originally Posted by aditya.pandare View Post
Thank you for your help! But i am still facing problems in that UDF.
I moved the two lines up before the "zoneid=11" line; but it still gives me a "parse error" in the "Thread *mixture_thread;" line.

Also, If i move the "Thread *mixture_thread = Lookup_Thread(domain,zoneid);" line before the "zoneid = 11;" line, how will it know the zoneid to use in the Lookup thread command?

Another question: i am "interpreting" this udf file; does that make any difference?

yes I have looked up the zone-ID in the phases dialog box. but here; the "lookup_thread"is used to define the mixture thread; so I am using the zone-ID from the BC dialog box. Is this correct? I am using this mixture-thread to define the "pt" with the "thread_sub_threads".

This is how I used the UDF with the corrections you told me:

#include "udf.h"

DEFINE_SOURCE(re,c,t,dS,eqn)
{
real source, prsr, alpha, pv, zoneid;
Thread *mixture_thread;
Thread **pt;
zoneid = 11;
Thread *mixture_thread = Lookup_Thread(domain,zoneid);
pt = THREAD_SUB_THREADS(mixture_thread);
prsr = C_P(c,t);
alpha = C_VOF(c,pt[3]);
pv = -97000;
source = 0.02 * (sqrt((2/3)*(pv - prsr)/998.2)) * (1-alpha) * 998.2 * 0.5542 / 0.0717;
dS[eqn] = - 0.02 * (sqrt((2/3)*(pv - prsr)/998.2)) * 998.2 * 0.5542 / 0.0717;
return source;
}
Please help!

#include "udf.h"

DEFINE_SOURCE(re,c,t,dS,eqn)
{
real source, prsr, alpha, pv;
Thread *mixture_thread;
Thread **pt;
Domain *domain; /* domain is declared as a variable */
int zoneid = 11;
domain = Get_Domain(1); /* returns fluid domain pointer */
mixture_thread = Lookup_Thread(domain,zoneid);
pt = THREAD_SUB_THREADS(mixture_thread);
prsr = C_P(c,t);
alpha = C_VOF(c,pt[3]);
pv = -97000;
source = 0.02 * (sqrt((2/3)*(pv - prsr)/998.2)) * (1-alpha) * 998.2 * 0.5542 / 0.0717;
dS[eqn] = - 0.02 * (sqrt((2/3)*(pv - prsr)/998.2)) * 998.2 * 0.5542 / 0.0717;
return source;
}

Try this. It compiles fine under windows 7. I don't think the interpreting approach plays a role here. It should be the same.
Good luck!
lihuang is offline   Reply With Quote

Old   March 20, 2013, 00:47
Default
  #8
New Member
 
Aditya Pandare
Join Date: Aug 2012
Location: Pune, India
Posts: 20
Rep Power: 4
aditya.pandare is on a distinguished road
Although the UDF interpretation showed no errors (like "parse error in lines" which were showing in my UDF!); Fluent shows "FATAL_ERROR: access violation" when i run the case after loading the UDF.

Im probably stating this again; but for the sake of clarity:
1. 11 is the ID of the internal fluid in the BC dialog box (used as zone-id in Lookup_thread)
2. 3 is the ID of the secondary phase in the phase dialog box (used in C_VOF)
(my case has 2 phases, primary and secondary)

is this correct?
I also call your attention to the "alpha = C_VOF(c,pt[3]);" line. is this correct?

Thank you!
aditya.pandare is offline   Reply With Quote

Old   March 20, 2013, 09:56
Default
  #9
Member
 
Li Huang
Join Date: Jan 2011
Posts: 30
Rep Power: 5
lihuang is on a distinguished road
Quote:
Originally Posted by aditya.pandare View Post
Although the UDF interpretation showed no errors (like "parse error in lines" which were showing in my UDF!); Fluent shows "FATAL_ERROR: access violation" when i run the case after loading the UDF.

Im probably stating this again; but for the sake of clarity:
1. 11 is the ID of the internal fluid in the BC dialog box (used as zone-id in Lookup_thread)
2. 3 is the ID of the secondary phase in the phase dialog box (used in C_VOF)
(my case has 2 phases, primary and secondary)

is this correct?
I also call your attention to the "alpha = C_VOF(c,pt[3]);" line. is this correct?

Thank you!
Sorry for the late reply, but I only have my notes handy at work.
I think you are doing right on No. 1. But for No. 2, primary phase thread index=0, first secondary phase thread index=1, second secondary phase thread index=2, and so on. So in your case, you should try "alpha = C_VOF(c,pt[1]);". Let me know how it goes. If it does not solve your problem, you probably need to explain more about what you want to do with your case and the UDF.
lihuang is offline   Reply With Quote

Old   March 21, 2013, 00:38
Default
  #10
New Member
 
Aditya Pandare
Join Date: Aug 2012
Location: Pune, India
Posts: 20
Rep Power: 4
aditya.pandare is on a distinguished road
Yes, that is okay. Thats why I replied late as well.

I realised that since I was hooking my source term to the vapor equation, the thread "t" corresponded to the vapor phase itself. So I did not need to create a separate pointer for that. so C_VOF(c,t) worked okay.

What I needed to do was create a pointer for the mixture phase; which I did following your instructions:

Domain *domain;
int zoneid = 11;
domain = Get_Domain(1);
mixture_thread = Lookup_Thread(domain,zoneid);
prsr = C_P(c,mixture_thread);

this worked well.

Thank you very much for your help!!
I am grateful.
aditya.pandare is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please Help.....Insufficient Catalogue Size Paresh Jain CFX 17 March 11, 2014 12:40
UDF source term jerome_ FLUENT 2 July 11, 2011 11:55
A question about UDF utility in mixture and multiphase model aleisia Fluent UDF and Scheme Programming 0 June 7, 2011 16:32
gradient source term UDF ak6g08 Fluent UDF and Scheme Programming 0 July 9, 2009 06:37
UDF Source Term Units? Brian FLUENT 1 October 24, 2005 09:15


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