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

second derivation of temperature

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 13, 2014, 00:11
Default second derivation of temperature
  #1
New Member
 
Join Date: Jun 2014
Posts: 16
Rep Power: 11
sunjian is on a distinguished road
Hi,everyone!
I want to define a source term including the second derivation of temperature. I use the macros DEFINE_SOURCE and DEFINF_ADJUST. Here is the code:
DEFINE_ADJUST(my_adjust,d)
{
Thread *t;
cell_t c;
if (! Data_Valid_P())
return;

thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDSI(c,t,1)=C_T_G(c,t)[0];
C_UDSI(c,t,2)=C_T_G(c,t)[1];
C_UDSI(c,t,3)=C_T_G(c,t)[2];
}
end_c_loop(c,t)
}
}

DEFINE_SOURCE(uds_source, c, t, dS, eqn)
{
real source;
source=-0.000143472*(C_UDSI_G(c,t,1)[0]+C_UDSI_G(c,t,2)[1]+C_UDSI_G(c,t,3)[2]);
dS[eqn]=0;
return source;
}
I use an interpreted udf. I've tried solve/set/expert temporary solver memory [yes], and iterated some steps before hooking DEFINE_ADJUST. After I hook DEFINE_ADJUST, it can calculate without any problems. But once I include the source term, I meet the error access_violation.
Can you help me with some advice on my problem. I am looking forward to your reply. Thank you in advance.
sunjian
sunjian is offline   Reply With Quote

Old   June 13, 2014, 04:43
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Do you get the same error if you replace the line
Code:
source=-0.000143472*(C_UDSI_G(c,t,1)[0]+C_UDSI_G(c,t,2)[1]+C_UDSI_G(c,t,3)[2]);
by the following line?
Code:
source=-0.000143472*(C_UDSI(c,t,1)[0]+C_UDSI(c,t,2)[1]+C_UDSI(c,t,3)[2]);
If you get the same problems without the gradient, the problem is that the UDS is not defined; if you do not get the same problems, the problem is related to the gradient.
Having this information might bring you one small step closer to the solution...
pakk is offline   Reply With Quote

Old   June 13, 2014, 09:27
Default
  #3
New Member
 
Join Date: Jun 2014
Posts: 16
Rep Power: 11
sunjian is on a distinguished road
Hi, pakk. Thank you for your reply. I replace the line
CODE: source=-0.000143472*(C_UDSI_G(c,t,1)[0]+C_UDSI_G(c,t,2)[1]+C_UDSI_G(c,t,3)[2]);
with the following line
CODE: source=-0.000143472*(C_UDSI(c,t,1)+C_UDSI(c,t,2)+C_UDSI(c, t,3));

Then I get the same error. You said maybe the uds is not defined. But what can I do to solve this problem? Is there something wrong in DEFINE_ADJUST?
sunjian is offline   Reply With Quote

Old   June 13, 2014, 10:52
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Try to plot the UDS. Is it zero on some parts of your domain? Then something is wrong in the adjust-part, maybe it did not hook to all cell zones.
Otherwise, I would have to think really hard.
pakk is offline   Reply With Quote

Old   June 15, 2014, 06:23
Default
  #5
New Member
 
Join Date: Jun 2014
Posts: 16
Rep Power: 11
sunjian is on a distinguished road
Hi, pakk. It's very nice of you to reply. Thank you again.
I tried to iterated with hooking the adjust-part and without including UDS transport equation 0 (I need to obtain User Scalar 0 in this equation) because as long as I include UDS transport equation 0, I will get the error access_violation. And I found that User Scalar 1, User Scalar 2 and User Scalar 3 were mostly not zero, though in some parts they might be zero (most of the values were near zero). On this occasion, is something wrong in the adjust-part?
sunjian is offline   Reply With Quote

Old   June 18, 2014, 03:50
Default
  #6
New Member
 
Join Date: Jun 2014
Posts: 16
Rep Power: 11
sunjian is on a distinguished road
Hi,pakk.
I read a UDF showgrad.c in section Gradient(G) and Reconstruction Gradient(RG) Vector Macros in UDF Manual. I include the code below in my code.
CODE:
DEFINE_ON_DEMAND(showgrad)
{
Domain *domain;
Thread *t;
domain=Get_Domain(1);
if (! Data_Valid_P())
return;
Message0(" >>> entering show-grad: \n ");
thread_loop_c(t, domain)
{
Message0("::::\n ");
Message0(":::: Gradients :::: \n ");
Message0("::::\n ");
if (NNULLP(THREAD_STORAGE(t, SV_T_G)))
{
Message0("Gradient of T is available \n ");
}
if (NNULLP(T_STORAGE_R_NV(t,SV_UDSI_G(1))))
{
Message0("Gradient of UDSI(1) is available \n ");
}
if (NNULLP(T_STORAGE_R_NV(t,SV_UDSI_G(2))))
{
Message0("Gradient of UDSI(2) is available \n ");
}
if (NNULLP(T_STORAGE_R_NV(t,SV_UDSI_G(3))))
{
Message0("Gradient of UDSI(3) is available \n ");
}
}
}
After the calculation with attaching the adjust-part and without attaching UDS transport equation 0, showgrad is executed and shows gradient of T, UDSI(1), UDSI(2) and UDSI(3) are available. So I think maybe the error happens in the source in UDS transport equation 0. Am I right?
The source term is Laplacian of temperature as follows:
source=a*(d2T/dX2+d2T/dY2+d2T/dZ2)
My code is:
DEFINE_SOURCE(uds_source, c, t, dS, eqn)
{
real source;
source=-0.000143472*(C_UDSI_G(c,t,1)[0]+C_UDSI_G(c,t,2)[1]+C_UDSI_G(c,t,3)[2]);
dS[eqn]=0;
return source;
}
But I can't find any problem here. Can you give some suggestions?
I'm looking forward to you reply. Thank you.
sunjian is offline   Reply With Quote

Old   June 18, 2014, 04:16
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Simplify your uds_source until it works. In that way you might identify in which step the problem occurs.

Some suggestions:

Code:
DEFINE_SOURCE(uds_source, c, t, dS, eqn)
{
real source;
source=-0.000143472*(C_UDSI_G(c,t,1)[0]);
dS[eqn]=0;
return source;
}
Code:
DEFINE_SOURCE(uds_source, c, t, dS, eqn)
{
real source;
source=-0.000143472*(C_UDSI(c,t,1)[0]);
dS[eqn]=0;
return source;
}
Code:
DEFINE_SOURCE(uds_source, c, t, dS, eqn)
{
real source;
source=-0.000143472;
dS[eqn]=0;
return source;
}
pakk is offline   Reply With Quote

Old   June 19, 2014, 05:06
Default
  #8
New Member
 
Join Date: Jun 2014
Posts: 16
Rep Power: 11
sunjian is on a distinguished road
Hi, pakk. Thank you for your help!
I've found where the error happens. In my UDF, I also define a UDS flux for UDS transport equation 0. I want to obtain the flux that equals the negative product of density and velocity. I use the code below firstly:
DEFINE_UDS_FLUX(A_flux, f, t, i)
{
real NV_VEC(vec), NV_VEC(A),dens,flux;
F_AREA(A, f, t);
dens=F_R(f,t);
NV_DS(vec,=,F_U(f,t),F_V(f,t),F_W(f,t),*,dens);
flux=NV_DOT(vec,A);
return - flux;
}
The error access_violation always occurs. Then I try the code below:
DEFINE_UDS_FLUX(A_flux, f, t, i)
{
return - F_FLUX(f,t);
}
It can iterate now. Both of the codes can be compiled without any error. Do you know what the mistake is in the first code?
Best regards.
sunjian is offline   Reply With Quote

Old   June 19, 2014, 06:04
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
You should look at the example in the manual for DEFINE_UDS_FLUX. It has a comment about the density not being available for all BCs, and how to solve it. I don't know if this is causing the problem, but you could try it.
pakk is offline   Reply With Quote

Old   June 23, 2014, 06:32
Default
  #10
New Member
 
Join Date: Jun 2014
Posts: 16
Rep Power: 11
sunjian is on a distinguished road
Hi, pakk. I have another question about the outlet boundary condition. I simulate the heat transfer in duct. For the inlet, I set the velocity-inlet condition and the user scalar 0 is set constant value 0. Here's no question. But for the fully-developed flow, I set the outflow condition and the BC should be (A*\nabla T)inlet = (A*\nabla T)outlet, where A is user scalar 0. For BC like this, how can I define it? I couldn't find a similar example in UDF manual. Could you help me with some clue? Thank you very much.
sunjian is offline   Reply With Quote

Old   June 23, 2014, 06:55
Default
  #11
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by sunjian View Post
Hi, pakk. I have another question about the outlet boundary condition. I simulate the heat transfer in duct. For the inlet, I set the velocity-inlet condition and the user scalar 0 is set constant value 0. Here's no question. But for the fully-developed flow, I set the outflow condition and the BC should be (A*\nabla T)inlet = (A*\nabla T)outlet, where A is user scalar 0. For BC like this, how can I define it? I couldn't find a similar example in UDF manual. Could you help me with some clue? Thank you very much.
If A at the inlet is set at the constant value 0, then (A*\nabla T)inlet=0, isn't it?
pakk is offline   Reply With Quote

Old   June 23, 2014, 11:25
Default
  #12
New Member
 
Join Date: Jun 2014
Posts: 16
Rep Power: 11
sunjian is on a distinguished road
Yes, you are right. So I just need to define (A*\nabla T)outlet = 0. Is it right? I'll have a try and see what I will get. Thank you very much.
sunjian is offline   Reply With Quote

Old   July 18, 2014, 09:53
Unhappy
  #13
New Member
 
Join Date: Jul 2014
Posts: 6
Rep Power: 11
stef_pasc is on a distinguished road
Hi everyone!!
I have a similar problem. I'm trying to calculate the laplacian of temperature field in order to introduce it into the source terme of energy equation. Here there is a simplification of my C code.

DEFINE_ADJUST(adjust_gradient, domain)
{
Thread *t;
cell_t c;

if (! Data_Valid_P())
return;

thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDSI(c,t,0)=C_T_RG(c,t)[0];
C_UDSI(c,t,1)=C_T_RG(c,t)[1];
C_UDSI(c,t,2)=C_T_RG(c,t)[2];
}
end_c_loop (c,t)
}

}

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

real source;

source=20*C_UDSI(c,t,0);

C_UDMI(c,t,0)=C_UDSI(c,t,0);
C_UDMI(c,t,1)=source;
C_UDMI(c,t,2)=C_UDSI_G(c,t,0)[0]; /*some calculus for testing the data*/
C_UDMI(c,t,3)=1/C_UDSI_G(c,t,0)[0];
C_UDMI(c,t,4)=100*C_UDSI_G(c,t,0)[0];

ds[eqn]=0;
return source;

}

The operations I make are:
  • Add User Scalars and memory
  • Inactivate UDS equations
  • Tape solver/set/expert---> yes for "keep temporary solver memory ...."
  • Launch the computation

SO I have 2 principal problems:
  1. Sometimes, I receive a "segmentation fault" error message: this is due to the lines
    C_UDSI(c,t,0)=C_T_G(c,t)[0];
    C_UDSI(c,t,1)=C_T_G(c,t)[1];
    C_UDSI(c,t,2)=C_T_G(c,t)[2];

    If I use C_T(c,t), there's no more problems...whyyy??;
  2. In this case, if I plot "Reconstruction dT/dx", Scalar 0 and Memory 0, they should coincide but there some little differences.

Is there someone who can help me, pleeease???

Thank you guys!!!
Stefano
stef_pasc is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
whats the cause of error? immortality OpenFOAM Running, Solving & CFD 13 March 24, 2021 08:15
Static Temperature / Opening Temperature JulianP CFX 12 April 10, 2019 19:00
Calculation of the Governing Equations Mihail CFX 7 September 7, 2014 07:27
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 02:27
Is wall ajacent temperature equal to conservative temperature of the wall? shenying0710 CFX 8 January 4, 2013 05:03


All times are GMT -4. The time now is 10:23.