CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   about unsteady uds term (

Frank March 26, 2002 06:25

about unsteady uds term
Hi everybody: I want to write a unsteady uds as a source term to add the mass balance equation. I am a fresh user. I meet many problem when I writting my program. I appreciate if anyboby can post some similar C program codes which can give some instructions.

Thank you very much


Greg Perkins March 26, 2002 22:25

Re: about unsteady uds term
have you read the Fluent 6 udf manual? If not start there.


Frank March 26, 2002 23:57

Re: about unsteady uds term
Hi: Thank you very much. Acutally I have read the udf mannual in fluent6. But only uds is introduced. I want to know more knowledge about how to write unsteady uds term. Do you have some samples about it?

By the way, my program can be compiled smoothly as a interpreted file. But when I execut it, "SEGMENTATION VIOLATION" is raised. what is the meaning of it? Do you have any advice to solve it?

need your reply promply.

Thank you again


Greg Perkins March 27, 2002 01:21

Re: about unsteady uds term
Segmentation fault is most likely caused by you accessing either a UDM or UDS that you haven't yet allocated memory for.

Actually, the udf manual for 6 has an example and a clear explanation of the uds unsteady term - or at least the electronic version I have does.

Have you tried the example....????


Frank March 27, 2002 01:25

Re: about unsteady uds term
Hi Greg

Do you think it is helpful for the problem if I compile my program as a compiled program?

Thank you for your reply


Frank March 27, 2002 03:46

Re: about unsteady uds term
Hi Greg:

The reason you mentioned may be true. But all uds in my program can be found in my fluent case file after compiling. Could you tell give me some introductions?

By the way, I read the sample of unsteady term in the mannual. The sample just define a derivative dv/dt. But in my case, I want to describe dv/dt=v-v*. How do I write program to describe the equation?

Thank you


Greg Perkins March 27, 2002 04:58

Re: about unsteady uds term
What is the exact meaning of dv/dt = v - v* what is v* ??

If this is your pde, then you don't need to write an unsteady uds function since you are using a standard form for the derivative, ie. dv/dt !

In this case, it looks to me like you'll be writing a source term for the v - v* term. Of course, I don't fully know what v* is so it may depend on your answer


Frank March 27, 2002 05:03

Re: about unsteady uds term
Hi: v is my uds v* is the function of concentration v*=f(c1,c2) I need the pde dvi/dt=v-v* to calculate v. Yes, you are right. I want to put dvi/dt add mass equation as a source term. Could you give me some advices?

Thank you


H.S.Fang April 16, 2002 22:29

Re: about unsteady uds term
I know how to do it. You must use C to write the d(v-v*)/dt,there are C codes I did .Maybe it will be helpful.for it is do d(cl-C_YI)/dt not d(v-v*)/dt. all the same.



thread_loop_c(t,domain) { begin_c_loop(c,t) { C_CENTROID(x,c,t);






else if(el>1.)




i1++; } end_c_loop(c,t); }

thread_loop_c(t,domain) {















else if(elo>1.)









if(fabs(detx)<=STEPX && fabs(dety)<=STEPY)









} undernum=totalx2*totaly2-totalxy*totalxy+0.000000000000001; fix=(totaly2*totalxf-totalxy*totalyf)/undernum; fiy=(totalx2*totalyf-totalxy*totalxf)/undernum; C_UDMI(c,t,0)=fix; C_UDMI(c,t,1)=fiy;


end_c_loop(c,t) }

fank April 16, 2002 23:32

Re: about unsteady uds term
Hi:Friend Thank you for you help. Can I ask you some question urgently by phone? Could you tell me your phone No. and convenient time? Thank you very much again

Greg Perkins April 18, 2002 00:18

Re: about unsteady uds term
I'm not convinced this is quite what is needed although the code is interesting.

How do you use such code? ie part of an adjust function?

It seems to me that a better way is actually to write the source term for v - v* which is quite easy.


Frank April 18, 2002 01:25

need help urgently
Dear Greg: Thank you for your reply. The following is the problem I want to solve: I want to add -Fdv/dt in the mass transfer equation as a source term. dv/dt=k(v*-v); v*=f(c1,c2) v1*=Kc1/(1+bc1+bc2)( here c1, c2 are concentration of one species.I have written a c code.But finally I find that the calculation results cannot be affected by the source term. The source term is zero in the rults. I feel so confused. Could you check my code and refer out the bug inside. Thank you very much!!!! Compilling is no problem.

#include "udf.h" #define F 0.96 #define c0 1000 define time_step 1.0 DEFINE_SOURCE(xmass_source,cell,thread,ds,eqn1) {float K[2]={2.354,3.675}; float b[2]={0.0529,0.0826}; float k[2]={0.9,1.2}; real flow_time, source1,phi1;phi_curr1,phi_old1,phi_balan1,time_di ff1;



phi_curr1=(1-time_step*k[0]*phi_old1+k[0]*time_step*phi_balan1; phi1=phi_curr1; time_diff1=(phi_curr1-phi_old1)/time_step; source1=-F*time_diff1; ds[eqn1]=0.0; return source; }

DEFINE_SOURCE(xmass_source2,cell,thread,ds,eqn2) {similar to the last part }

Frank April 18, 2002 01:33

Re: about unsteady uds term
I cannot put v-v* as a resouce term directly. Because I need the equation dv/dt=k(v-v*) to solve v. In my code, i use (v_curr-v_old)/time_step to represent dv/dt.

How to write time_step. Can I use RP_Get_Real to describe time step? The the program is a compiled program, right?

Do I need to write a user defined scalar?

need your help.

Thank you very very much

Greg Perkins April 18, 2002 03:14

Re: need help urgently
I still don't quite get what you want to do exactly. Are you trying to represent some sort of chemical reaction, or mass transfer???

For your udfs, to model mass transfer you need to add a mass source term that is the sum of the species source terms into the continuity eqn.

This seems to have caused some confusion, since I month or so ago I put a post about this - have a look at that.

Its likely, that if you've just added a source term to the species equations you won't see any effect on the total mass flow rate. As I said you need to add the source term to the continuity eqn.

Regarding the other questions, please post a complete description of this dv/dt = v - v*. is v* - a known function or is it some approximation your trying to use ??


Greg Perkins April 18, 2002 05:24

Re: about unsteady uds term
This is where we need to be clear on what you're trying to do.

If you want to solve for scalar transport of v in the domain, you will need to solve a scalar transport eqn. (though since its very simple, you may be able to get away with writing just a udf - like an execute on demand).

Assuming you solve a uds, you can set the unsteady term as the defualt, which will be dv/dt.

Then you need to set the flux function to none and the uds diffusivity to zero.

I assume the uds is no. zero and you've allocated memory for it.

Then write a udf source term for the v - v* term you have. I don't exactly undersatdn this term, but this is quite easy:

DEFINE_SOURCE(my_srce,c,t,ds,eqn) {

real srce;

real v_star;

srce = C_UDSI(c,t,0) - v_star;

ds[eqn] = 1.0; }

Now - I have some problem with your definition of the source term. If you use v - v* you are likely to have stability issues, since the derivative of this term wrt v is a positive value. You may need to linearize this term (see the book by Patankar).

Also if v* is a function of v then you'll need to add this to the derivative above. In this case the ds part will be

ds[eqn] = 1.0 + d(v_star)/dv;



Frank April 18, 2002 05:50

Re: about unsteady uds term
Hi: Thank you for your reply! My project is to describe adsorption separation of two specieses. Actually v is adsorption term. v* is balance adsorption term. Because there is no adsorption term dv/dt in the mass transfer equation. I need add this term in it.


v=f(c1,c2) c1, c2 is concentration of specieses. for example, v1=Kc1,v2=kc2

COuld you let me know how to write c code.I have already put my code in the last post. COuld you find problem inside. I need you help urgently.

Thank you very much

Frank April 18, 2002 06:04

Re: about unsteady uds term
Hi: I can not add v*-v as a source term directly, because v must be solved by the mass transfer equation and dv/dt=k(v*-v) and v*=f(c) (c is concentration)

thank you for your consideration

Frank April 18, 2002 06:08

Re: need help urgently
hi: which equation is continuity equation? I have already add it in the mass transfer equation as source term. In the source term panel, I select source term for different specieses.. COuld you reply to me?

Thank you very much

Greg Perkins April 18, 2002 07:06

Re: about unsteady uds term
Continuity equation is the one for overall conservation of mass.

I still don't quite understand this v equation. Perhaps somebody else knows this better than I.

At the species level, you have a conservation equation for each species (actuall N-1 equations, we don't solve for last species) and then you have the continuity equation for the conservation of the overall mass.Thus you have N equations for N species mass fractions, concentrations or apparent densities etc - depending on what you prefer you can use any of these.

So for your absorption process, I imagine that you have a source term for each species which models the rate at which the species is "absorbed" and/or desorbed etc. Here I'm using an analogy with chamical reactions since that's what I'm doing.

So have you got the full set of equations you want to solve and have you looked at the conservation of mass issue for the system and all the species?? Is you complete model consistent??

I would think you'll have to write a source term for each species at the very least.

Now back to v - what does it represent in terms of the conservation of mass etc???

If this represents some additional scalar then you'll need to solve it as such, but to be useful I would expect it must have an influence back on the conservation of mass for the species.


fank April 18, 2002 21:58

Re: about unsteady uds term
Hi: Thank you for you patient reply: the following is my model:

dc/dt+v*dc/dz=DL*dc^2/dz^2+F*dq/dt dq/dt=k(q*-q) q*=Kc

Where c is concentration of species.q is adsorption term Could you let me know how to write c code for this model?

Thank you very much

All times are GMT -4. The time now is 16:07.