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

DEFINE_CG_MOTION and Message(...) issue

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 3, 2021, 11:12
Default DEFINE_CG_MOTION and Message(...) issue
  #1
Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 43
Rep Power: 5
wcj1n18 is on a distinguished road
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 is offline   Reply With Quote

Old   March 4, 2021, 05:12
Default DEFINE_CG_MOTION and Message(...) issue
  #2
Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 43
Rep Power: 5
wcj1n18 is on a distinguished road
Hi, it would be really appreciated if anyone could give any suggestions at all here? Thanks
wcj1n18 is offline   Reply With Quote

Old   March 4, 2021, 06:01
Default
  #3
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
if (!Data_Valid_P()) {
Message("For some reason, the data was invalid.") ;
return;
}

Try this, see if you get this message on your screen.
pakk is offline   Reply With Quote

Old   March 4, 2021, 08:11
Default
  #4
Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 43
Rep Power: 5
wcj1n18 is on a distinguished road
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?
wcj1n18 is offline   Reply With Quote

Old   March 4, 2021, 09:17
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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.
pakk is offline   Reply With Quote

Old   March 4, 2021, 09:48
Default
  #6
Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 43
Rep Power: 5
wcj1n18 is on a distinguished road
OK, I put it at the start of the code now and tested. Still no Message! So, it's not being used?
wcj1n18 is offline   Reply With Quote

Old   March 4, 2021, 10:26
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
It looks like that...

Delete the libudf folder, compile again, and try. Will not solve the problem, but might show useful warnings.
pakk is offline   Reply With Quote

Old   March 4, 2021, 11:09
Default
  #8
Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 43
Rep Power: 5
wcj1n18 is on a distinguished road
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.
wcj1n18 is offline   Reply With Quote

Old   March 4, 2021, 11:27
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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?
pakk is offline   Reply With Quote

Old   March 4, 2021, 12:04
Default
  #10
Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 43
Rep Power: 5
wcj1n18 is on a distinguished road
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.

wcj1n18 is offline   Reply With Quote

Old   March 4, 2021, 12:43
Default
  #11
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Oh, I misunderstood, that error is logical then. I'm clueless now.
pakk is offline   Reply With Quote

Old   March 5, 2021, 08:02
Smile
  #12
Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 43
Rep Power: 5
wcj1n18 is on a distinguished road
OK, I've looked into this further and I think I have solved the problem. A has been noted here incorrect cg motion UDF sdof_properties (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!
wcj1n18 is offline   Reply With Quote

Reply

Tags
6dof, define_cg_motion, message log, udf


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
Error Message during transient run on a cluster balrog_f CFX 0 June 17, 2017 04:18
Guide: Getting Started with the CFD Online Discussion Forums pete Site Help, Feedback & Discussions 8 July 29, 2016 06:00
error message susan Siemens 0 August 17, 2007 01:27
how to avoid reverse flow message Amit Mahulkar FLUENT 0 April 20, 2006 01:45
Error Message on es-ice [BUG] Wendy Tjia Siemens 0 February 10, 2005 09:40


All times are GMT -4. The time now is 15:48.