|
[Sponsors] |
September 7, 2020, 19:41 |
How to call a function in UDF?
|
#1 |
New Member
Juncheng
Join Date: Sep 2020
Posts: 1
Rep Power: 0 |
I use UDF to calculate the moment on a fan. The UDF is
#include "udf.h" #include "mem.h" #include "dynamesh_tools.h" #define INERTIA 1.7 static real alpha_z0=0.0, omega_z0=0.0, theta_z0=0.0; int damp_f( real theta, real alpha, real* vol, real* r_m ){ real x0=-300, y0=137.5, x1=-80, y1=-600; real x0r, y0r, dx, dy, d01, ddf; x0r = x0 * cos( theta ) - y0 * sin( theta ); y0r = x0 * sin( theta ) + y0 * cos( theta ); dx = x0r - x1; dy = y0r - y1; d01 = sqrt( pow(dx, 2) + pow(dy, 2) ); *vol = d01 * alpha; *r_m = fabs( (y1 * x0r - x1 * y0r) / d01 ); return 0; } DEFINE_CG_MOTION( piston_damp_sp0, dt, vel, omega, time, dtime ) { face_t f; cell_t c; real f_glob[3], m_glob[3], domega_z, x_cg[ND_ND], m_damp, v_damp; int i, status; NV_S(omega, =, 0.0); for(i=0;i<=3;i++) { f_glob=0; m_glob=0; } x_cg[0] = 0; x_cg[1] = 0; Domain *domain= Get_Domain (1); Thread *tf1 = Lookup_Thread (domain, 3); Compute_Force_And_Moment (domain, tf1, x_cg, f_glob, m_glob, TRUE); real* vol; real* r_m; status = damp_f( theta_z0, alpha_z0, vol, r_m ); v_damp = 4 * (*vol) * (*r_m) ; m_damp = 0; alpha_z0 = (m_glob[2] - m_damp - v_damp )/INERTIA; domega_z = dtime * alpha_z0; omega_z0 += domega_z; theta_z0 = DT_THETA(dt)[2]; Message ("ntime=%f, tz=%.10lf, oz1=%.10lf, oz2=%.10lf, force_x=%.1f ,force_y=%.1f, moment_z=%f, vol=%.1f, rm=%.1f ", \ time, DT_THETA(dt)[2], DT_OMEGA_CG(dt)[2], theta_z0, f_glob[0], f_glob[1], m_glob[2], *vol, *r_m ); omega[2]=omega_z0; } I run the calculation with 2 cores in parallel mode,and get the error the the fluent is auto-closed. Node 0: Process 5204: Received signal SIGSEGV. ================================================== ============================ ================================================== ============================ Node 1: Process 9392: Received signal SIGSEGV. ================================================== ============================ MPI Application rank 0 exited before MPI_Finalize() with status 2 I can solve this problem with putting the calculations those in function damp_f into DEFINE_CG_MOTION. However, I wonder if a function can be called in UDF and how to call a function? Thx |
|
September 16, 2020, 09:35 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you can call functions in UDF same way as in C language
actually, what you've done seems to be correct
__________________
best regards ****************************** press LIKE if this message was helpful |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Call udf some Iterations | edu_aero | FLUENT | 8 | September 14, 2017 13:48 |
Running UDF with Supercomputer | roi247 | FLUENT | 4 | October 15, 2015 14:41 |
[swak4Foam] installation problem with version 0.2.3 | Claudio87 | OpenFOAM Community Contributions | 9 | May 8, 2013 11:20 |
[blockMesh] non-orthogonal faces and incorrect orientation? | nennbs | OpenFOAM Meshing & Mesh Conversion | 7 | April 17, 2013 06:42 |
[blockMesh] error message with modeling a cube with a hold at the center | hsingtzu | OpenFOAM Meshing & Mesh Conversion | 2 | March 14, 2012 10:56 |