-
-
November 30, 2022 at 12:26 pm
ehsan.sadeghi
SubscriberHello
I have the following UDF structure for calculating gradients of UDS0 (potential). I start with calculation the UDS0 gradients in ADJUST macro, then I want to pass the calculated Ex, Ey and Ez to a SOURCE macro. My problem is that I am not sure if in my code structure Ex, Ey and Ez pass to Source function or not? how can I do that?
```
#include "udf.h"
DEFINE_EXECUTE_ON_LOADING(uds_names, uds_libnames)
{
void Set_User_Scalar_Name(int i,char *name);
Set_User_Scalar_Name(0,"potential");
Set_User_Scalar_Name(1,"E_x");
Set_User_Scalar_Name(2,"E_y");
Set_User_Scalar_Name(3,"E_z");
Set_User_Scalar_Name(4,"E");
Set_User_Scalar_Name(5,"n");
}enum
{
potential,
E_x,
E_y,
E_z,
E,
n,
N_REQUIRED_UDS
};DEFINE_ADJUST(grad_calc, domain)
{
/* calculate E_x, E_y, E_z; */
}
DEFINE_SOURCE(potential_source, cell, thread, dS, eqn)
{
real source;
source = 2.0*E_x;
return source;
}```
-
December 1, 2022 at 11:53 am
Rob
Ansys EmployeeI tend to calculate the values for the source terms directly, so E_x etc would be in the DEFINE_SOURCE part of the code.
-
December 1, 2022 at 12:33 pm
ehsan.sadeghi
Subscriberso you mean I implment another DEFINE_ADJUST inside the DEFINE_SOURCE? or only the thread loop and face loop?
In DEFINE_ADJUST I calculate E_x, etc... then I need that parameter in source.
-
December 1, 2022 at 1:49 pm
Rob
Ansys EmployeeDo you need the DEFINE_ADJUST bit?
-
December 2, 2022 at 8:36 am
ehsan.sadeghi
SubscriberI don´t understand what you mean?
-
-
December 2, 2022 at 9:49 am
Rob
Ansys EmployeeWhat does the DEFINE_ADJUST do that can't be done in the DEFINE_SOURCE routine?
-
December 2, 2022 at 10:24 am
ehsan.sadeghi
SubscriberThat´s what I was asking. I didn´t know that it already loops over domain and executes per iteration. Thanks for being so nice!!
-
-
December 2, 2022 at 11:51 am
ehsan.sadeghi
SubscriberI did as you said, but for some reason I get error:
999999: mpt_accept: error: accept failed: No such file or directory
===================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= RANK 0 PID 1228 RUNNING AT PC-ANSYS-157
= EXIT STATUS: -1 (ffffffff)
My code is:
#include”udf.h”
#define e 1.6e-19
#define epsilon0 8.854e-12
#define mu_p 1.35e-4
#define Dp 3.5e-6
DEFINE_EXECUTE_ON_LOADING(on_loading, libname)
{
Set_User_Memory_Name(0,”Potential Source”);
Set_User_Memory_Name(1,”Potential”);
Set_User_Memory_Name(2,”Ex”);
Set_User_Memory_Name(3,”Ey”);
Set_User_Memory_Name(4,”Ez”);
Set_User_Memory_Name(5,”Electric Field”);
Set_User_Memory_Name(7,”x-Momentum Source”);
Set_User_Memory_Name(8,”y-Momentum Source”);
Set_User_Memory_Name(9,”z-Momentum Source”);
Set_User_Scalar_Name(0,”Potential”);
Set_User_Scalar_Name(1,”ion concentration”);
}DEFINE_ADJUST(E_xyz,d)
{
Thread *t;
cell_t c;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,1) = C_UDSI(c,t,0) ;
C_UDMI(c,t,2) = -C_UDSI_G(c,t,0)[0] ;
C_UDMI(c,t,3) = -C_UDSI_G(c,t,0)[1] ;
C_UDMI(c,t,4) = -C_UDSI_G(c,t,0)[2] ;
C_UDMI(c,t,5) = NV_MAG(C_UDSI_G(c,t,0)) ;
C_UDMI(c,t,6) = C_UDSI(c,t,1) ;
}
end_c_loop(c,t)
}
}/* Sets the gradient of phi (UDS-0) to equal E_x (UDS-1) and E_y (UDS-2), and sets face values */
DEFINE_SOURCE(phi_source,c,t,dS,eqn)
{
real phi_source;
dS[eqn] = 0.0;
phi_source = -(e/epsilon0)*C_UDSI(c,t,1);
C_UDMI(c,t,0) = phi_source;
return phi_source;
}DEFINE_SOURCE(momentum_x, c, t, dS, eqn)
{
real source;
dS[eqn] = 0.0;
source = e*C_UDMI(c,t,2)*C_UDSI(c,t,1);
C_UDMI(c,t,7) = source;
return source;
}DEFINE_SOURCE(momentum_y, c, t, dS, eqn)
{
real source;
dS[eqn] = 0.0;
source = e*C_UDMI(c,t,3)*C_UDSI(c,t,1);
C_UDMI(c,t,8) = source;
return source;
}DEFINE_SOURCE(momentum_z, c, t, dS, eqn)
{
real source;
dS[eqn] = 0.0;
source = e*C_UDMI(c,t,4)*C_UDSI(c,t,1);
C_UDMI(c,t,9) = source;
return source;
}
DEFINE_UDS_FLUX(flux_ions,f,t,i)
{
cell_t c;
cell_t c0, c1= -1;
Thread *t0, *t1 = NULL;
real NV_VEC(A), NV_VEC(E_vec), E_flux = 0.;
real rho = C_R(c0,t0)+C_R(c1,t1);
c0 = F_C0(f,t);
t0 = F_C0_THREAD(f,t);
F_AREA(A,f,t);
if (BOUNDARY_FACE_THREAD_P(t))
{
E_flux = 0.0;
}
else
{
begin_c_loop(c,t)
{
F_UDMI(c,t,2) = C_UDMI(c,t,2) ;
F_UDMI(c,t,3) = C_UDMI(c,t,2) ;
F_UDMI(c,t,4) = C_UDMI(c,t,2) ;
}
end_c_loop(c,t)
c1 = F_C1(f,t);
t1 = F_C1_THREAD(f,t);
NV_DS(E_vec, =, F_UDMI(c0, t0, 2), F_UDMI(c0, t0, 3), F_UDMI(c0, t0, 4), *, Dp);
NV_DS(E_vec, +=, F_UDMI(c1, t1, 2), F_UDMI(c1, t1, 3), F_UDMI(c1, t1, 4), *, Dp);
E_flux = NV_DOT(E_vec,A)/2.0;
}if (i==1)
{
return (F_FLUX(f,t)/rho+E_flux);
}
else
return (0.);
}
-
- You must be logged in to reply to this topic.

Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.

Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
- Suppress Fluent to open with GUI while performing in journal file
- Floating point exception in Fluent
- What are the differences between CFX and Fluent?
- Heat transfer coefficient
- Getting graph and tabular data from result in workbench mechanical
- The solver failed with a non-zero exit code of : 2
- Difference between K-epsilon and K-omega Turbulence Model
- Time Step Size and Courant Number
- Mesh Interfaces in ANSYS FLUENT
- error in cfd post
-
2524
-
2066
-
1279
-
1096
-
457
© 2023 Copyright ANSYS, Inc. All rights reserved.