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

UDF line 1 parse error

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 15, 2003, 08:39
Default UDF line 1 parse error
  #1
Dimitrios
Guest
 
Posts: n/a
Hi there fellow fluent users....this is the first time I've been using UDF's and I'm not a used user of Fluent. Anyway...I get an error message when trying to interpret the UDF in Fluent. The following message appears: line 1: parse error

My code is the following:

#include "udf.h" #include "dynamesh_tools.h"

DEFINE_CG_MOTION(rorlig_yttre, dt, cg_vel, cg_omega, time, dtime) { Thread *t = DT_THREAD ((Dynamic_Thread *)dt); face_t f; real force, dv, area, k_spring, s_force;

/* reset velocities */ NV_S (cg_vel, =, 0.0); NV_S (cg_omega, =, 0.0);

if (!Data_Valid_P ())

return;

/* compute force on rorlig_yttre wall */ force = 0.0; begin_f_loop (f, t)

force += F_P (f, t) * NV_MAG (F_AREA_CACHE (f, t)); end_f_loop (f, t)

#if RP_2D if (rp_axi)

force *= 2.0 * M_PI; #endif

/* compute change in velocity */ dv = dtime * force/ 1.2; v_prev += dv; loc += v_prev*dtime; Message ("time = %f, x_vel = %f, force = %f, loc(m)= %f \n", time, v_prev,

force,loc); Message ("time = %f, force = %f, spring = %f, loc(m)= %f \n", time, force,

s_force,loc);

cg_vel[0] = v_prev; }

Does anyone know why the error message pops up?
  Reply With Quote

Old   November 15, 2003, 13:28
Default Re: UDF line 1 parse error
  #2
Ajay Rao
Guest
 
Posts: n/a
Have your case file and UDF in c:\fluent.inc\ntbin\ntx86 folder ... It will run then ! -Ajay
  Reply With Quote

Old   November 16, 2003, 06:21
Default Re: UDF line 1 parse error
  #3
Dimitrios
Guest
 
Posts: n/a
You were right Ajay...it interpreted the file when .case and .c was in nt86 folder but now I get a new message: ***line 8: structure reference not implemented*** Can you perhaps see what can be wrong with my code?
  Reply With Quote

Old   November 16, 2003, 06:43
Default Re: UDF line 1 parse error
  #4
Dimitrios
Guest
 
Posts: n/a
By the way....line 8 is:

Thread *t = DT_THREAD ((Dynamic_Thread *)dt);
  Reply With Quote

Old   November 16, 2003, 14:43
Default Re: UDF line 1 parse error
  #5
Ajay
Guest
 
Posts: n/a
Hi, The error means that you cant use Interpreted UDF you have to use compiled UDF. compiled udf are bit more difficult to set up , you need to build the libraries and then load them. You should have an external compiler , VC++ compiler, thats the way i do it. Let me know if you need more help with it. -Ajay
  Reply With Quote

Old   November 17, 2003, 03:25
Default Re: UDF line 1 parse error
  #6
ccc
Guest
 
Posts: n/a
hi, Dimitrios:

Ajay is very right. there are some features of udf you can not use in the interpreted mode and Dynamic Mesh is one of them.

  Reply With Quote

Old   November 17, 2003, 03:30
Default Re: UDF line 1 parse error
  #7
Dimitrios
Guest
 
Posts: n/a
Dear Ajay

I would really appreciate if you could help me out with compiled UDF and the libraries setup.

Sincerely,

Dimitrios

  Reply With Quote

Old   November 17, 2003, 18:28
Default Re: UDF line 1 parse error
  #8
Ajay Rao
Guest
 
Posts: n/a
Hi, The New version of FLUENT has a GUI to help build and Load compiled UDF the older version have just the "Load" part. You would need Microsoft Visual Studio . Net for this ( I use it , dont know how to do with something else)

You need to follow the following steps

1) set up the environmental variable This is done by going to the start menu > Programs>Fluent> Set_environment clicking this would set the path and variable.

2) set up a directory structure as follows create a dir libudf in that create "src" and "ntx86". In ntx86 create "3d".( am asuming that ur simulation is 3d)

3) copy the udf (.C file) and the required header( u can get the header files frm c:\FLUENT.INC\fluent6.*.*\ntx86\src) files into the "src" folder.

4) go to c:\FLUENT.INC\fluent6.*.*\ntx86\3d copy the contents into the 3d folder which you created.

5) go to c:\FLUENT.INC\fluent6.*.*\ntx86\src copy makefile_nt.udf and user_nt.udf to your 3d folder

6) rename makefile_nt.edf to makefile and open user_nt.udf and read the instructions and do accordingly.

7) close FLUENT . Open command prompt ( start > accessories > command prompt ) type the following C:\ CD program Files \ microsoft visual studio .net\vc7\bin

8) type :- vcvars32

9)go to the libudf\ntx86\3d which u have created

10) type nmake

11) This will compile ur code and build a lib if u dont have any errors , if errors are present it will say so u need to debug it then.

12) once this is done u can open fluent again and load the lib u have just created , in this case it would be libudf.

I know its confusing ! Keep trying it took me a long time to get all things correct.

All the best Ajay
  Reply With Quote

Old   November 18, 2003, 03:17
Default Re: UDF line 1 parse error
  #9
Dimitrios
Guest
 
Posts: n/a
Once again Ajay....thanks for the help....now the code is working great....a small problem though...I have two reals that I want them to both have the value zero in the first iteration. If I define them as vel=0 and time=0 in the beginning of the code, where I define all my reals, they tend to get zero after each new iteration. How can I write the code so they have the value zero only in the first iteration?
  Reply With Quote

Old   November 18, 2003, 10:22
Default Re: UDF line 1 parse error
  #10
Ajay Rao
Guest
 
Posts: n/a
Hi Dimitrios , You could compare the time ,

real time;

time=RP_Get_Real("flow-time")

if (time ==0) { initialize

}

Hope this helps , -Ajay

  Reply With Quote

Old   April 6, 2011, 02:32
Default
  #11
New Member
 
Join Date: Mar 2011
Posts: 2
Rep Power: 0
17_freedom is on a distinguished road
Thank you,I also meet the same problem.Thank you!
17_freedom is offline   Reply With Quote

Old   January 23, 2012, 05:13
Unhappy parse error line62
  #12
New Member
 
theja
Join Date: Oct 2011
Posts: 17
Rep Power: 15
theja is on a distinguished road
Quote:
Originally Posted by Dimitrios
;109119
Dear Ajay

I would really appreciate if you could help me out with compiled UDF and the libraries setup.

Sincerely,

Dimitrios
can you please help me out of this, i am getting parse error at line 62 when i am interpreting this udf valve.c

# include "udf.h"
# include "dynamesh_tools.h"
# ifndef intloop
# define intloop(n,m)for(n=0;n<m;++n);
# endif
/********************** Input Explanation Starts ***************************
DEBUG: will print out debug information.
NO_OF_VALVES: Number of valves
NO_OF_ZONES: a large number which is larger than the max number of face
zones per valve
valveid[NO_OF_VALVES][NO_OF_ZONES]={{22, 23, -1}, {13, 14, -1}}: valve face
zone list, in this example, invalve consists of face zone 21 and 23,
exvalve consists of face zone 13 and 14. -1 is a flag and so keep it.
These face zones will be used to calculate the pressure force.
axis[NO_OF_VALVES][ND_ND]={{0, 0, 1}, {0, 0, -1}}: valve motion axis. It points
from the max lift to min lift. And it has to be normalized.
r_rp_closed[NO_OF_VALVES][ND_ND]={{-0.025, 0, 0}, {0.025, 0, 0.005}}: The
reference point coordinates when valves are closed. A reference point,
used to keep track of valve motion, is a point in the valve. The
loation in the valve is immaterial and you can conveniently choose
the location.
lift_min[NO_OF_VALVES]={0.0005, 0.0005}: minimum lift
lift_max[NO_OF_VALVES]={0.01, 0.006}: maximum lift
rest_conts[NO_OF_VALVES]={0.5, 0.5}: bouncing factor
mass[NO_OF_VALVES]={0.02, 0.02}: valve mass
stiffness[NO_OF_VALVES]={2000, 5000}: valve stiffness
stretch_at_closed[NO_OF_VALVES]={0.002, 0.004}: what is the valve stretching
length when the valves are closed
gravity_direction: Gravitational direction. Has to be normalized.
current_vel_mag[NO_OF_VALVES]: Initial velocity. Could be negative if opposite
to valve axis
cur_r_rp[NO_OF_VALVES][ND_ND]: Initial position
previous_time[NO_OF_VALVES]: Initial time. Normally just 0.
How to use the udf:
- Modify the user input part of the udf. If more than one valve,then one needs to add
more DEFINE_CG_MOTION. See below for more details.
- Build the lib and hook the reader writer udf
- Use the udf for the valve motion
Note that this UDF is only valid in single precision.
Written by : Xiao Hu (Fluent Inc)
Last updated : 11/30/2004
********************** Input Explanation Ends *****************************/
/*************************** User Input Starts *****************************/
# define DEBUG
# define NO_OF_VALVES 1
# define NO_OF_ZONES 3
static int valveid[NO_OF_VALVES][NO_OF_ZONES]={{10, -1}};
static real axis[NO_OF_VALVES][ND_ND]={{-1,0}}; /* normalized */
static real r_rp_closed[NO_OF_VALVES][ND_ND]={{-0.01016, 0}};
static real lift_min[NO_OF_VALVES]={0};
static real lift_max[NO_OF_VALVES]={1e5};
static real rest_conts[NO_OF_VALVES]={0};
static real mass[NO_OF_VALVES]={0.01};
static real stiffness[NO_OF_VALVES]={150000};
static real stretch_at_closed[NO_OF_VALVES]={0};
static real gravity_direction[ND_ND]={0, 1}; /* normalized */
static real current_vel_mag[NO_OF_VALVES]={0};
static real cur_r_rp[NO_OF_VALVES][ND_ND]={{0, 0}};
static real previous_time[NO_OF_VALVES]={0};
/*************************** User Input Ends *******************************/
static void f_valve(int valveNo, void *dt, real *cg_vel, real *cg_omega, real time, real dtime)
{
#if !RP_HOST
real tmp[ND_ND], dv, current_vel[ND_ND], CG[ND_ND], force[3], moment[3], stretch;
real aero_force[ND_ND], aero_force_axis, spring_force, net_force, r_rp_new[NO_OF_VALVES][ND_ND];
int i;
Thread * tf;
Domain * domain;
/************************************************** ****************/
static real cg_vel_saved[NO_OF_VALVES][ND_ND];
/************************************************** ****************/
/* Do the calculation if the new time step */
if(fabs(previous_time[valveNo]-time)>0.2*dtime)
{
/* reset velocities */
NV_S (cg_vel, =, 0.0);
NV_S (cg_omega, =, 0.0);
/* Check to see if there is data */
if (!Data_Valid_P ())
{
Message0("\n\nNo data->No mesh motion!!!\n\n");
return;
}
/*Calculate force*/
domain = THREAD_DOMAIN (DT_THREAD ((Dynamic_Thread *)dt));
i=0;
NV_S(aero_force,=,0);
while(valveid[valveNo][i]>=0)
{
tf=Lookup_Thread(domain, valveid[valveNo][i]);
NV_S (CG, =, 0.0);
Compute_Force_And_Moment (domain, tf, CG, force, moment, FALSE);
NV_V(aero_force,+=,force);
i++;
}
aero_force_axis=NV_DOT(aero_force, axis[valveNo]);
NV_VV(tmp,=,r_rp_closed[valveNo],-,cur_r_rp[valveNo]);
stretch = (stretch_at_closed[valveNo]+NV_DOT(tmp,axis[valveNo]));
spring_force=stiffness[valveNo]*stretch;
net_force=spring_force+aero_force_axis+9.81*mass[valveNo]*NV_DOT(gravity_direction, axis[valveNo]);
dv=net_force/mass[valveNo]*dtime;

/* Calculate the C.G location and velocity if it does not hit the boundary */
NV_VS(current_vel,=,axis[valveNo],*,current_vel_mag[valveNo]);
NV_VS(tmp,=,current_vel,*,dtime);
NV_VV(r_rp_new[valveNo],=,cur_r_rp[valveNo],+,tmp);
/* Update velocity */
current_vel_mag[valveNo]+=dv;
/* debug info */
#ifdef DEBUG
Message0("\n\n*********************** DEBUG INFO ***************************\n");
Message0("\nvalveNo=%3d\n", valveNo);
Message0("\ncur_r_rp[%d]=(%10.3e, %10.3e, %10.3e)\n",
valveNo, cur_r_rp[valveNo][0], cur_r_rp[valveNo][1], cur_r_rp[valveNo][ND_ND-1]);
Message0("\naero force=(%10.3e, %10.3e, %10.3e)\n",
aero_force[0], aero_force[1], aero_force[ND_ND-1]);
Message0("\n(stretching at closed, stretching, force)=(%10.3e, %10.3e, %10.3e)\n",
stretch_at_closed[valveNo], stretch, spring_force);
Message0("\n(net_force, spring force, aero force)=(%10.3e, %10.3e, %10.3e)\n",
net_force, spring_force, aero_force_axis);
Message0("\nvel(cur)=%11.3e vel(next wo limit)=%11.3e ",
current_vel_mag[valveNo]-dv, current_vel_mag[valveNo]);
#endif
/* if it hits the lift_min boundary then it stays at lift_min*/
NV_VV(tmp,=,r_rp_closed[valveNo],-,r_rp_new[valveNo]);
if(NV_DOT(tmp,axis[valveNo])<(lift_min[valveNo]))
{
NV_V_VS(r_rp_new[valveNo],=,r_rp_closed[valveNo],-,axis[valveNo],*,lift_min[valveNo]);
current_vel_mag[valveNo]=-rest_conts[valveNo]*fabs(current_vel_mag[valveNo]);
}
/* if it hits the lift_max boundary then it stays at lift_max*/
NV_VV(tmp,=,r_rp_closed[valveNo],-,r_rp_new[valveNo]);
if(NV_DOT(tmp,axis[valveNo])>(lift_max[valveNo]))
{
NV_V_VS(r_rp_new[valveNo],=,r_rp_closed[valveNo],-,axis[valveNo],*,lift_max[valveNo]);
current_vel_mag[valveNo]=rest_conts[valveNo]*fabs(current_vel_mag[valveNo]);
}
/* set valve velocity */
NV_VV(tmp,=,r_rp_new[valveNo],-,cur_r_rp[valveNo]);
NV_VS(cg_vel,=,tmp,/,dtime);
/* Update location and velocity */
NV_V(cur_r_rp[valveNo],=,r_rp_new[valveNo]);
NV_V(cg_vel_saved[valveNo],=,cg_vel);
previous_time[valveNo]=time;
/* debug info */
#ifdef DEBUG
Message0("vel(next w limit)=%11.3e\n", current_vel_mag[valveNo]);
Message0("\nvelocity(CG)=(%10.3e, %10.3e, %10.3e)\n",
cg_vel[0], cg_vel[1], cg_vel[ND_ND-1]);
Message0("\nr_rp_new[%d]=(%10.3e, %10.3e, %10.3e)\n",
valveNo, r_rp_new[valveNo][0], r_rp_new[valveNo][1], r_rp_new[valveNo][ND_ND-1]);
Message0("\n*********************** DEBUG INFO ***************************\n\n");
#endif
}
else
{
NV_V(cg_vel,=,cg_vel_saved[valveNo]);
}
#endif
node_to_host_real(current_vel_mag, NO_OF_VALVES);
node_to_host_real(cur_r_rp[0], NO_OF_VALVES*ND_ND);
node_to_host_real(previous_time, NO_OF_VALVES);
}
/* Add more valves if necessary. For instance, if two valves, then
{
f_valve(0, dt, cg_vel, cg_omega, time, dtime);
}
{
f_valve(1, dt, cg_vel, cg_omega, time, dtime);
}
*/
DEFINE_CG_MOTION(valve, dt, cg_vel, cg_omega, time, dtime)
{
f_valve(0, dt, cg_vel, cg_omega, time, dtime);
node_to_host_real(cg_vel,ND_ND);
node_to_host_real(cg_omega,ND_ND);
}
DEFINE_EXECUTE_AT_END(output_results)
{
#if !RP_HOST
int i;
FILE *fp_results;
#if PARALLEL
if(I_AM_NODE_ZERO_P)
#endif
{
if(!(fp_results=fopen("results.txt","a")))
{
Message0("\nCan not open file-aborting!!");
exit(0);
}
}
#if PARALLEL
if(I_AM_NODE_ZERO_P)
#endif
{
fprintf(fp_results, "%12.4e ", CURRENT_TIME);
for(i=0; i<NO_OF_VALVES; i++)
{
fprintf(fp_results, "%12.4e ", NV_DOT(cur_r_rp[i],axis[i]));
}
fprintf(fp_results, "\n");
fclose(fp_results);
}
#endif
}
static void write_data(FILE *fp)
{
int i, j;
for(i=0; i<NO_OF_VALVES; i++)
{
fprintf(fp, "%e ", current_vel_mag[i]);
}
fprintf(fp, "\n");
for(i=0; i<NO_OF_VALVES; i++)
{
for(j=0; j<ND_ND; j++)
{
fprintf(fp, "%e ", cur_r_rp[i][j]);
}
fprintf(fp, "\n");
}
fprintf(fp, "\n");
for(i=0; i<NO_OF_VALVES; i++)
{
fprintf(fp, "%e ", previous_time[i]);
}
}
DEFINE_RW_FILE(writer, fp)
{
Message0("Writing UDF data to data file...\n");
#if PARALLEL
#if RP_HOST
write_data(fp);
#endif
#else
write_data(fp);
#endif
}
static void read_data(FILE * fp)
{
int i, j;
for(i=0; i<NO_OF_VALVES; i++)
{
fscanf(fp, "%e", current_vel_mag+i);
}
for(i=0; i<NO_OF_VALVES; i++)
{
for(j=0; j<ND_ND; j++)
{
fscanf(fp, "%e", cur_r_rp[i]+j);
}
}
for(i=0; i<NO_OF_VALVES; i++)
{
fscanf(fp, "%e", previous_time+i);
}
}
DEFINE_RW_FILE(reader, fp)
{
Message0("Reading UDF data from data file...\n");
#if PARALLEL
#if RP_HOST
read_data(fp);
#endif
#else
read_data(fp);
#endif
host_to_node_real(current_vel_mag, NO_OF_VALVES);
host_to_node_real(cur_r_rp[0], NO_OF_VALVES*ND_ND);
host_to_node_real(previous_time, NO_OF_VALVES);
}

thanks in advance
theja is offline   Reply With Quote

Old   August 9, 2012, 20:44
Question
  #13
New Member
 
n7310889
Join Date: Aug 2012
Posts: 26
Rep Power: 14
n7310889 is on a distinguished road
Quote:
Originally Posted by Ajay Rao
;109092
Have your case file and UDF in c:\fluent.inc\ntbin\ntx86 folder ... It will run then ! -Ajay
Hi Ajoy, As a test case I have just copied a udf of inlet_x_velocity and modified it slightly to check with a fluent model. But strangely enough, it also shows the similar error message that of Dimitrios one. Obviously, I have followed your instruction and tried several times with different modifications. But the problem is persistent with a little change from line 1 to line 2 then finally line 3. Could you please check the code whats going wrong?
#include "udf.h"

DEFINE_PROFILE(inlet_x_velocity, thread, position)
{
real x[ND_ND];
real y, h;
face_t f;
h = 33.;
begin_f_loop(f,thread)
{
F_CENTROID(x, f, thread);
y = (2.*x[1]- h)/h;
F_PROFILE(f, thread, position) = 2.5*(1.0-y*y);
}
end_f_loop(f, thread)
}
n7310889 is offline   Reply With Quote

Old   September 28, 2012, 03:54
Default fluent codding error
  #14
New Member
 
endalke
Join Date: Sep 2012
Posts: 1
Rep Power: 0
endalke is on a distinguished road
dear fluent users, i am a new user of fluent. trying to solve a 2D cross flow turbine. i use a UDF for the 2D model. my code is

/*This code is written in "C"*/
/*UDF starts for the rotor*/
#inc1ude "udf.h"
#inc1ude "dynamesh_tools.h"
/*UDF starts for Rotational Speed of rotor*/
DEFINE_CG_MOTION(rotor,dt,vel,omega,time,dtime)
{
NY_S(vel,=,0.0);
NY_S(omega,=,0.0);
/*Linear Velocity for blade and pipe*/
vel[O]=0.0;
vel[l]=0.0;
vel[2]=0.0;
/*Angular Velocity for blade and pipe*/
omega[O]=0;
omega[l]=0;
omega[2]=12;
/*Messages for Display*/
Message("\nThis is the rotor\n");
Message("\nCG_Omega for rotor: %g, %g, %g\n",omega[O],omega[1],omega[2]);
Message("\nCG_Position for rotor: %g, %g, %g\n",NV_LIST(DT_CG(dt)));
Message("\nCG_Orientation for rotor: %g, %g, %g\n",NY_LIST(DT_THETA(dt)));
}
/*UDF ends for Rotational Speed of blade and pipe*/

but when i try to compile the UDF i found an error message follow below

1 file(s) copied.
(system "copy C:\Fluent.Inc\fluent6.3.26\src\makefile_nt.udf libudf\ntx86\2ddp\makefile")
1 file(s) copied.
(chdir "libudf")()
(chdir "ntx86\2ddp")()
'nmake' is not recognized as an internal or external command,
operable program or batch file.
'nmake' is not recognized as an internal or external command,
operable program or batch file.

Done.

"D:/model"

Opening library "libudf"...
Error: open_udf_library: The system cannot find the file specified.

Error Object: ()

is any one knows what it mean? and how to solve it, please help me.
endalke is offline   Reply With Quote

Old   October 8, 2012, 05:46
Default UDF parse error with DEFINE_PROFILE
  #15
Senior Member
 
Join Date: Nov 2009
Posts: 125
Rep Power: 17
mactech001 is on a distinguished road
Quote:
Originally Posted by Ajay Rao
;109092
Have your case file and UDF in c:\fluent.inc\ntbin\ntx86 folder ... It will run then ! -Ajay
Dear Ajay,

Thx to your comments here.

I met a similar problem while using DEFINE_PROFILE (My code attached below. it is actuall an example from Help). The error points to line #1, which is the comment line.


/* Wall Heat Generation Rate Profile UDF */
#include "udf.h"
DEFINE_PROFILE(wallheatgenerate,thread,i)
{
real source = 0.001;
face_t f;
begin_f_loop(f,thread)
F_PROFILE(f,thread,i) = source;
end_f_loop(f,thread)
}

i copied the Case file and the C-code shown above into the folder directory: C:\Program Files\ANSYS Inc\v130\fluent\ntbin\ntx86

But the same error occurs while interpreting.

What else could be incorrect please?

Hope to obtain your guidance/comments as soon as possible. Thx!

Regards,
Mactech001
Using: ANSYS WB v13
mactech001 is offline   Reply With Quote

Old   October 10, 2012, 07:22
Default
  #16
Member
 
Tamil Nadu
Join Date: Oct 2012
Posts: 44
Rep Power: 14
nkme2007 is on a distinguished road
Hello All,

I want to do analysis of heat transfer from water flowing through pipes submerged inside concrete. I am modelling in GAMBIT and wish to analyse it on Ansys FLUENT.

Can anybody help me out, how to model and simulate?

Does any tutorials exist?
nkme2007 is offline   Reply With Quote

Old   October 31, 2012, 12:50
Default
  #17
Member
 
payamfadaei
Join Date: Oct 2012
Location: Mashhad/Iran
Posts: 32
Rep Power: 14
Payam89 is on a distinguished road
Send a message via Skype™ to Payam89
#include "udf.h"

#define Q 1.0;
#define e 1.0;
#define er 3.0;
#define pi 3.1;
#define s 0.0187;

DEFINE_SOURCE(xmom_source,c,t,ds,eqn)
{
real source;
real x[ND_ND];
ds[eqn]=-(Q/2.*pi*e)*(1./x + 1./s-x);

return source;
}



Error: C:\Users\USER\Desktop\ss.c: line 13: parse error.
Error: C:\Users\USER\Desktop\ss.c: line 13: parse error.
Error: C:\Users\USER\Desktop\ss.c: line 13: invalid type for pointer dereference: float.


??????????

thanks
Payam89 is offline   Reply With Quote

Old   November 30, 2012, 23:18
Default
  #18
New Member
 
nguyentuan
Join Date: Sep 2012
Posts: 5
Rep Power: 14
vmtlv is on a distinguished road
static void f_valve(int valveNo, void *dt, real *cg_vel, real *cg_omega, real time, real dtime)
{
#if !RP_HOST
real tmp[ND_ND], dv, current_vel[ND_ND], CG[ND_ND], force[3], moment[3], stretch;
real aero_force[ND_ND], aero_force_axis, spring_force, net_force, r_rp_new[NO_OF_VALVES][ND_ND];
int i;
Thread * tf;
Domain * domain;
/************************************************** ****************/
static real cg_vel_saved[NO_OF_VALVES][ND_ND];
/************************************************** ****************/
/* Do the calculation if the new time step */
if(fabs(previous_time[valveNo]-time)>0.2*dtime)
{
/* reset velocities */
NV_S (cg_vel, =, 0.0);
NV_S (cg_omega, =, 0.0);
/* Check to see if there is data */
if (!Data_Valid_P ())
{
Message0("\n\nNo data->No mesh motion!!!\n\n");
return;
}
/*Calculate force*/
domain = THREAD_DOMAIN (DT_THREAD ((Dynamic_Thread *)dt));
i=0;
NV_S(aero_force,=,0);
while(valveid[valveNo][i]>=0)
{
tf=Lookup_Thread(domain, valveid[valveNo][i]);
NV_S (CG, =, 0.0);
Compute_Force_And_Moment (domain, tf, CG, force, moment, FALSE);
NV_V(aero_force,+=,force);
i++;
}
aero_force_axis=NV_DOT(aero_force, axis[valveNo]);
NV_VV(tmp,=,r_rp_closed[valveNo],-,cur_r_rp[valveNo]);
stretch = (stretch_at_closed[valveNo]+NV_DOT(tmp,axis[valveNo]));
spring_force=stiffness[valveNo]*stretch;
net_force=spring_force+aero_force_axis+9.81*mass[valveNo]*NV_DOT(gravity_direction, axis[valveNo]);
dv=net_force/mass[valveNo]*dtime;

/* Calculate the C.G location and velocity if it does not hit the boundary */
NV_VS(current_vel,=,axis[valveNo],*,current_vel_mag[valveNo]);
NV_VS(tmp,=,current_vel,*,dtime);
NV_VV(r_rp_new[valveNo],=,cur_r_rp[valveNo],+,tmp);
/* Update velocity */
current_vel_mag[valveNo]+=dv;
/* debug info */
#ifdef DEBUG
Message0("\n\n*********************** DEBUG INFO ***************************\n");
Message0("\nvalveNo=%3d\n", valveNo);
Message0("\ncur_r_rp[%d]=(%10.3e, %10.3e, %10.3e)\n",
valveNo, cur_r_rp[valveNo][0], cur_r_rp[valveNo][1], cur_r_rp[valveNo][ND_ND-1]);
Message0("\naero force=(%10.3e, %10.3e, %10.3e)\n",
aero_force[0], aero_force[1], aero_force[ND_ND-1]);
Message0("\n(stretching at closed, stretching, force)=(%10.3e, %10.3e, %10.3e)\n",
stretch_at_closed[valveNo], stretch, spring_force);
Message0("\n(net_force, spring force, aero force)=(%10.3e, %10.3e, %10.3e)\n",
net_force, spring_force, aero_force_axis);
Message0("\nvel(cur)=%11.3e vel(next wo limit)=%11.3e ",
current_vel_mag[valveNo]-dv, current_vel_mag[valveNo]);
#endif
/* if it hits the lift_min boundary then it stays at lift_min*/
NV_VV(tmp,=,r_rp_closed[valveNo],-,r_rp_new[valveNo]);
if(NV_DOT(tmp,axis[valveNo])<(lift_min[valveNo]))
{
NV_V_VS(r_rp_new[valveNo],=,r_rp_closed[valveNo],-,axis[valveNo],*,lift_min[valveNo]);
current_vel_mag[valveNo]=-rest_conts[valveNo]*fabs(current_vel_mag[valveNo]);
}
/* if it hits the lift_max boundary then it stays at lift_max*/
NV_VV(tmp,=,r_rp_closed[valveNo],-,r_rp_new[valveNo]);
if(NV_DOT(tmp,axis[valveNo])>(lift_max[valveNo]))
{
NV_V_VS(r_rp_new[valveNo],=,r_rp_closed[valveNo],-,axis[valveNo],*,lift_max[valveNo]);
current_vel_mag[valveNo]=rest_conts[valveNo]*fabs(current_vel_mag[valveNo]);
}
/* set valve velocity */
NV_VV(tmp,=,r_rp_new[valveNo],-,cur_r_rp[valveNo]);
NV_VS(cg_vel,=,tmp,/,dtime);
/* Update location and velocity */
NV_V(cur_r_rp[valveNo],=,r_rp_new[valveNo]);
NV_V(cg_vel_saved[valveNo],=,cg_vel);
previous_time[valveNo]=time;
/* debug info */
#ifdef DEBUG
Message0("vel(next w limit)=%11.3e\n", current_vel_mag[valveNo]);
Message0("\nvelocity(CG)=(%10.3e, %10.3e, %10.3e)\n",
cg_vel[0], cg_vel[1], cg_vel[ND_ND-1]);
Message0("\nr_rp_new[%d]=(%10.3e, %10.3e, %10.3e)\n",
valveNo, r_rp_new[valveNo][0], r_rp_new[valveNo][1], r_rp_new[valveNo][ND_ND-1]);
Message0("\n*********************** DEBUG INFO ***************************\n\n");
#endif
}
else
{
NV_V(cg_vel,=,cg_vel_saved[valveNo]);
}
#endif
node_to_host_real(current_vel_mag, NO_OF_VALVES);
node_to_host_real(cur_r_rp[0], NO_OF_VALVES*ND_ND);
node_to_host_real(previous_time, NO_OF_VALVES);
}
/* Add more valves if necessary. For instance, if two valves, then
{
f_valve(0, dt, cg_vel, cg_omega, time, dtime);
}
{
f_valve(1, dt, cg_vel, cg_omega, time, dtime);
}


Hi, I can't understand "valveNo" that was most used in "f_valve" , how value does it has ?

Thanks for reading !
vmtlv is offline   Reply With Quote

Old   December 2, 2012, 12:35
Default
  #19
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27
ghost82 will become famous soon enough
Quote:
Originally Posted by Payam89 View Post
#include "udf.h"

#define Q 1.0;
#define e 1.0;
#define er 3.0;
#define pi 3.1;
#define s 0.0187;

DEFINE_SOURCE(xmom_source,c,t,ds,eqn)
{
real source;
real x[ND_ND];
ds[eqn]=-(Q/2.*pi*e)*(1./x + 1./s-x);

return source;
}



Error: C:\Users\USER\Desktop\ss.c: line 13: parse error.
Error: C:\Users\USER\Desktop\ss.c: line 13: parse error.
Error: C:\Users\USER\Desktop\ss.c: line 13: invalid type for pointer dereference: float.


??????????

thanks
you need to specify x[0], which is the x coordinate, or x[1], which is the y coordinate, or x[2], the z coordinate.
Payam89 likes this.
ghost82 is offline   Reply With Quote

Old   January 11, 2013, 01:52
Default UDF code understanding
  #20
Senior Member
 
Join Date: Nov 2009
Posts: 125
Rep Power: 17
mactech001 is on a distinguished road
dear all,

does the code below applies a constant heat flux of 0.001W/m^2 to the wall please?

/* Wall Heat Generation Rate Profile UDF */#include "udf.h" DEFINE_PROFILE(wallheatgenerate,thread,i) { real source = 0.001; face_t f; begin_f_loop(f,thread) F_PROFILE(f,thread,i) = source; end_f_loop(f,thread) } Regards,mactech001
__________________
Thank you for your kind attention.

Kind regards,
mactech001
Currently using: ANSYS v13
mactech001 is offline   Reply With Quote

Reply


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
[swak4Foam] GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh gschaider OpenFOAM Community Contributions 300 October 29, 2014 19:00
How to install CGNS under windows xp? lzgwhy Main CFD Forum 1 January 11, 2011 19:44
CGNS lib and Fortran compiler manaliac Main CFD Forum 2 November 29, 2010 07:25
UDF parse error at profile function line Wiggy Fluent UDF and Scheme Programming 1 July 27, 2009 16:59
Problems of Duns Codes! Martin J Main CFD Forum 8 August 15, 2003 00:19


All times are GMT -4. The time now is 03:51.