CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Accessing phase volm fraction in UDF for a source term in mixture model (https://www.cfd-online.com/Forums/fluent-udf/114874-accessing-phase-volm-fraction-udf-source-term-mixture-model.html)

aditya.pandare March 19, 2013 07:54

Accessing phase volm fraction in UDF for a source term in mixture model
 
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 March 19, 2013 08:53

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 (Post 414967)
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!


vasava March 19, 2013 09:16

Shouldn't you use 'zoneid' instead of 'zid' in the line 'Thread *mixture_thread = Lookup_Thread(domain,zid);' ??

aditya.pandare March 19, 2013 09:27

@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!

lihuang March 19, 2013 13:36

Quote:

Originally Posted by aditya.pandare (Post 414996)
@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

aditya.pandare March 19, 2013 23:10

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!

lihuang March 19, 2013 23:29

Quote:

Originally Posted by aditya.pandare (Post 415147)
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!

aditya.pandare March 19, 2013 23:47

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!

lihuang March 20, 2013 08:56

Quote:

Originally Posted by aditya.pandare (Post 415151)
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.

aditya.pandare March 20, 2013 23:38

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.


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