CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   DEFINE_CG_MOTION and Message(...) issue (https://www.cfd-online.com/Forums/fluent-udf/234348-define_cg_motion-message-issue.html)

wcj1n18 March 3, 2021 10:12

DEFINE_CG_MOTION and Message(...) issue
 
Hi,

I'm trying to give my 6DOF object a given velocity which is a function of the pressures and viscous forces on its surface, but want to override its motion in the Z-direction. Hence, i'm using DEFINE_CG_MOTION. My object should move in X and Y direction as usual, but not move in the Z-direction. However, when I run my simulation, it doesn't move at all; I check the cg velocity and position in the Dynamic Mesh Zone tab and they are all equal to 0. Additionally, I have a Message macro at the end of my UDF, but I cannot see anything in the console- nothing appears whatsoever.

The UDF compiles without error, I load it successfully, I hook it into the Dynamic Mesh Zones tab for the rigid body, so seems like it would work fine, but it is like it just doesn't respond to my UDF whatsoever- not that Fluent crashes or anything, and everything else runs fine (e.g. fluid data seems fine).

I have tried renaming the UDF file and re-compiling etc and have tried it on both Fluent 20 R1 and R2. Neither of these made a difference.

Any ideas what's happening here? Perhaps I am misunderstanding the effects of DEFINE_CG_MOTION.

My code is given below, which is basically a copy of what is given in the UDF Manual, except for 3D translation.

Thank you.

#include "udf.h"
#include <math.h>

#define Mass 0.0013875
#define g -9.81
static real NV_VEC(v_prev) = {0.0, 0.0, 0.0};

DEFINE_CG_MOTION(TEST_UDF2, dt, vel, omega, time, dtime)
{
Thread *t; /* pointer to thread */
face_t f; /* face thread */


real FZ; /*Total drag and weight */
real FZ1; /* Form drag */
real FZ2; /* Shear drag */
real FZ3; /* Weight */
real FC; /* Cancel force in Z direction*/
real FX; /* Total drag */
real FX1; /* Form drag */
real FX2; /* Shear drag */
real FY; /* Total drag */
real FY1; /* Form drag */
real FY2; /* Shear drag */
real NV_VEC(A); /* Area vector */
real NV_VEC(dv); /* Change in velocity */

/* reset velocities */
NV_S(vel, =, 0.0);


if (!Data_Valid_P())
return;

t = DT_THREAD(dt); /* get the thread pointer for which this motion is defined */

FZ1 = 0.0; /* initialise */
FZ2 = 0.0; /* initialise */
FX1 = 0.0; /* initialise */
FX2 = 0.0; /* initialise */
FY1 = 0.0; /* initialise */
FY2 = 0.0; /* initialise */

begin_f_loop(f, t)
{
F_AREA(A, f, t); /* Face area vector, points out of domain by convention */

FX1 += F_P(f,t) * A[0]; /* Form Drag, x */

FX2 += F_STORAGE_R_N3V(f, t, SV_WALL_SHEAR)[0]; /* shear force at current face added; only force in x-direction */

FY1 += F_P(f,t) * A[1]; /* Form Drag, y */

FY2 += F_STORAGE_R_N3V(f, t, SV_WALL_SHEAR)[1]; /* shear force at current face added; only force in y-direction */

FZ1 += F_P(f,t) * A[2]; /* Form Drag, z */

FZ2 += F_STORAGE_R_N3V(f, t, SV_WALL_SHEAR)[2]; /* shear force at current face added; only force in z-direction */
}
end_f_loop(f, t)

FZ3 = Mass * g; /* Weight */

FZ = FZ1 + FZ2 + FZ3;

FX = FX1 + FX2;

FY = FY1 + FY2;

FC = 0.0 - FZ1 - FZ2 - FZ3;

/* compute change in velocity, that is, dv = F * dt / mass
velocity update using explicit Euler formula */

dv[0] = ( FX / Mass ) * dtime;
dv[1] = ( FY / Mass) * dtime;
dv[2] = ( ( FZ + FC ) / Mass ) * dtime;

v_prev[0] += dv[0];
v_prev[1] += dv[1];
v_prev[2] += dv[2];

/* set components of velocity */

NV_V(vel, =, v_prev);

Message ("Resultant force, FZ= %g. \n Form drag force, FZ1= %g. \n Shear drag force, FZ2= %g. \n Weight, FZ3= %g. \n Cancel force, FC= %g. \n", FZ, FZ1, FZ2, FZ3, FC);
Message ("v_prev = (%g %g %g)\n", v_prev[0], v_prev[1], v_prev[2]);

}

wcj1n18 March 4, 2021 04:12

DEFINE_CG_MOTION and Message(...) issue
 
Hi, it would be really appreciated if anyone could give any suggestions at all here? Thanks :) :):)

pakk March 4, 2021 05:01

if (!Data_Valid_P()) {
Message("For some reason, the data was invalid.") ;
return;
}

Try this, see if you get this message on your screen.

wcj1n18 March 4, 2021 07:11

Thanks. I 've tried putting your suggested if function in a number of different locations within the code to identify an error, but I don't get any messages. I tried running the model with no UDF and it runs fine, so it seems like it's something to do with the UDF, but it compiles fine. I'm baffled about what's happening here. Surely even if the rest of the code wasn't working my messages at the bottom should show in the console?

pakk March 4, 2021 08:17

No, your messages at the bottom would only be shown if that part of the code is reached. You had a return above that, that's why I suggested to add a message there to see if that return was used.

To be sure your UDF is used: put a message at the start of your UDF.

wcj1n18 March 4, 2021 08:48

OK, I put it at the start of the code now and tested. Still no Message! So, it's not being used?

pakk March 4, 2021 09:26

It looks like that...

Delete the libudf folder, compile again, and try. Will not solve the problem, but might show useful warnings.

wcj1n18 March 4, 2021 10:09

OK, I tried that and as you suspected it didnt work. Compilation works fine...

Creating library libudf.lib and object libudf.exp
Creating user_nt.udf file for 3ddp_node ...
(system "copy "C:\PROGRA~1\ANSYSI~1\v201\fluent"\fluent20.1.0\sr c\udf\makefile_nt.udf "libudf\win64\3ddp_node\makefile" ")
1 file(s) copied.
(chdir "libudf")(chdir "win64\3ddp_node")# Generating ud_io1.h
TEST_UDF2.c
# Generating udf_names.c because of makefile TEST_UDF2.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj TEST_UDF2.obj
Microsoft (R) Incremental Linker Version 14.28.29335.0
Copyright (C) Microsoft Corporation. All rights reserved.


The only error I noted was when I loaded case file "Error: chip-exec: function "TEST_UDF2::libudf" not found". Thing is, I encountered this error earlier and assume it's just because the Dynamic Mesh Zones looks for the UDF which I have already deleted. So, I assumed (perhaps wrongly) that this is nothing significant.

pakk March 4, 2021 10:27

That error is very significant, it tells you that fluent can not find your UDF. But I have no idea why not...

Is this the first udf you use, or have you successfully compiled and used other UDFs in the past?

wcj1n18 March 4, 2021 11:04

Thanks a lot for continuing to help.

Note that it only gives this error when I first open the case file. So, I think that it only gives this error because I had just deleted libudf from Windows File Explorer as you suggested (the libudf is still hooked into the Dynamic Mesh Zone at this point, so I think this is why it shows this error.) I then recompile to recreate libudf and there is no such error.

Yes, I've used other UDFs. And since encountering this problem I've tried another UDF with this exact same case file and it worked fine.

:confused:

pakk March 4, 2021 11:43

Oh, I misunderstood, that error is logical then. I'm clueless now.

wcj1n18 March 5, 2021 07:02

OK, I've looked into this further and I think I have solved the problem. A has been noted here https://www.cfd-online.com/Forums/fl...roperties.html (and in other forum threads), if I go to Dynamic Mesh - Dynamic Mesh Zones - Rigid Body - and untick Six DOF, then the UDF seems to work. The slight worry was that the body wouldn't actually move, but having set up a 'scene' in the GUI I can see that the sphere does indeed move with Six DOF unticked and I can also see the messages showing in Console, which is great.

So yeah, think it's working now. Thanks for trying to help out earlier!


All times are GMT -4. The time now is 00:33.