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

Modifying Contact Detection UDF for 3D

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 1 Post By wcj1n18
  • 2 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 11, 2021, 05:46
Default Modifying Contact Detection UDF for 3D
  #1
New Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 25
Rep Power: 2
wcj1n18 is on a distinguished road
Hi,

Does anyone have experience of modifying the 2D Contact Detection UDF example in the UDF manual to 3D. This is what I would like to do currently, however there is little information available (as far as I know) on the definitions of the macros involved so it is very difficult to do so. If anyone could point me in the correct direction or has experience with modifying the UDF then please let me know.

Any help you can give would be great!

Thank you!

PS. 2D example is here:

/************************************************** ***\
*2-degree of freedom equation of motion compiled UDF *
\************************************************* ****/

#include "udf.h"

DEFINE_CONTACT(contact_props, dt, contacts)
{
Objp *o;
face_t face;
Thread *thread;
Domain *domain = NULL;
Dynamic_Thread *ndt = NULL;

int tid, nid, n_faces;

real v0dotn1, v1dotn0;
real nc_mag, norm0_mag, norm1_mag;

real N3V_VEC (vel_rel);
real N3V_VEC (nc), N3V_VEC (nctmp);
real N3V_VEC (xc), N3V_VEC (xctmp);
real N3V_VEC (vel0), N3V_VEC (omega0), N3V_VEC (theta0), N3V_VEC (norm0);
real N3V_VEC (vel1), N3V_VEC (omega1), N3V_VEC (theta1), N3V_VEC (norm1);

if (!Data_Valid_P())
{
return;
}

/* Define a common contact point / plane */
N3V_S (nc, =, 0.0);
N3V_S (xc, =, 0.0);

/* Fetch current thread ID */
tid = THREAD_ID (DT_THREAD (dt));

nid = -1;
n_faces = 0;

loop (o, contacts)
{
face = O_F (o);
thread = O_F_THREAD (o);

/*Skip faces on current thread */
if (THREAD_ID (thread) == tid)
{
continue;
}

/*NOTE ID of the other thread for posterity */
if (nid == -1)
{
nid = THREAD_ID (thread);
}

/* Initialise to zero */
N3V_S (nctmp, =, 0.0);
N3V_S (xctmp, =, 0.0);

F_AREA (nctmp, face, thread);
F_CENTROID (xctmp, face, thread);

/**
* Negative sum because wall normals
* point out of the fluid domain
*/
N3V_V (nc, -=, nctmp);
N3V_V (xc, +=, xctmp);

n_faces++;

}

# if RP_NODE
{
/* Reduce in parallel */
nid = PRF_GIHIGH1 (nid);
n_faces = PRF_GISUM1 (n_faces);

PRF_GRSUM3 (nc[0], nc[1], nc[2]);
PRF_GRSUM3 (xc[0], xc[1], xc[2]);
}
# endif

/* Propogate to host */
node_to_host_int_2 (nid, n_faces);
node_to_host_real_3 (nc[0], nc[1], nc[2]);
node_to_host_real_3 (xc[0], xc[1], xc[2]);

if (n_faces > 0)
{
nc_mag = N3V_MAG (nc) + REAL_MIN;

N3V_S (nc, /=, nc_mag);
N3V_S (xc, /=, n_faces);
}
else
{
return;
}

Message
(
"\nContact:: tid: %d nid: %d n_faces: %d "
"Point: (%f %f %f) Normal: (%f %f %f)",
tid, nid, n_faces,
xc[0], xc[1], xc[2],
nc[0], nc[1], nc[2]
);

/* Fetch thread for opposite body */
domain = THREAD_DOMAIN (DT_THREAD (dt));
thread = Lookup_Thread (domain, nid);

if (NULLP (thread))
{
Message("\nWarning: No thread for nid %d ", nid);

return;
}
else
{
ndt = THREAD_DT (thread);
}

/* Fetch body parameters */
SDOF_Get_Motion (dt, vel0, omega0, theta0);

/* Compute difference vectors and normalise */
N3V_VV (norm0, =, xc, -, DT_CG (dt));
norm0_mag = N3V_MAG (norm0) + REAL_MIN;
N3V_S (norm0, /=, norm0_mag);

if (NULLP (ndt))
{
/*Stationary body/ wall. Use contact normal */
N3V_V (norm1, =, nc);

/* Compute relative velocity */
N3V_S (vel1, =, 0.0);
N3V_V (vel_rel, =, vel0);
}
else
{
/* Fetch body parameters */
SDOF_Get_Motion (ndt, vel1, omega1, theta1);

/* Compute relative velocity */
N3V_VV (vel_rel, =, vel0, -, vel1);

/* Compute difference vectors and normalise */
N3V_VV (norm1, =, xc, -, DT_CG (ndt));
norm1_mag = N3V_MAG (norm1) + REAL_MIN;
N3V_S (norm1, /=, norm1_mag);

/* Check if velocity needs to be reversed */
if (N3V_DOT (vel_rel, nc) < 0.0)
{
/* Reflect velocity across the normal */
v1dotn0 = 2.0 * N3V_DOT (vel1, norm0);

N3V_S (norm0, *=, v1dotn0);
N3V_V (vel1, -=, norm0);

/* Override body velocity */
SDOF_Overwrite_Motion (ndt, vel1, omega1, theta1);
}
}

/* Check if velocity needs to be reversed */
if (N3V_DOT (vel_rel, nc) < 0.0)
{
/* Reflect velocity across the normal */
v0dotn1 = 2.0 * N3V_DOT (vel0, norm1);

N3V_S (norm1, *=, v0dotn1);
N3V_V (vel0, -=, norm1);

/* Override body vectors */
SDOF_Overwrite_Motion (dt, vel0, omega0, theta0);
}

Message
(
"\ncontact_props: Updated :: vel0 = (%f %f %f) vel1 = (%f %f %f)",
vel0[0], vel0[1], vel0[2], vel1[0], vel1[1], vel1[2]
);
}
wcj1n18 is offline   Reply With Quote

Old   February 11, 2021, 06:33
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,921
Rep Power: 23
pakk will become famous soon enough
Have you already tried to just use this code in 3D? If so, what went wrong?
pakk is offline   Reply With Quote

Old   February 11, 2021, 09:24
Default
  #3
New Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 25
Rep Power: 2
wcj1n18 is on a distinguished road
Hi Pakk,

Thanks for the response. You're correct, maybe it should still work in 3D and I get an error for another reason, however, the error I get is this:



999999: mpt_accept: error: accept failed: No such file or directory
.
. (lots of repeats)
.
999999: mpt_accept: error: accept failed: No such file or directory

Node 2: Process 7064: Received signal SIGSEGV.

999999: mpt_accept: error: accept failed: No such file or directory

999999: mpt_accept: error: accept failed

Node 7: Process 21496: Received signal SIGSEGV.: No such file or directory

999999: mpt_accept: error: accept failed: No such file or directory
.
. (lots of repeats)
.
999999: mpt_accept: error: accept failed: No such file or directory

999999: mpt_accept: error: accept failed: No such file or directoryMPI Application rank 5 exited before MPI_Finalize() with status 2
The fl process could not be started.


The part where it says "The fl process could not be started" I have noticed before in other parts of the forum, but not in this situation:

MPI Application rank 0 exited before MPI_Finalize() with status 2 The fl process cou

Personally, I think it's to do with the UDF not being compatible for 3D, but I may be wrong.

Thank you
wcj1n18 is offline   Reply With Quote

Old   February 11, 2021, 09:44
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,921
Rep Power: 23
pakk will become famous soon enough
Do you also get an error in serial mode?
pakk is offline   Reply With Quote

Old   February 11, 2021, 11:44
Default
  #5
New Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 25
Rep Power: 2
wcj1n18 is on a distinguished road
Running in serial mode seems to make the UDF work in 3D and I don't get the error, thanks for that! However, why is it that the UDF works in parallel for 2D but not 3D? Also, is it possible for me to edit the UDF such that it works in parallel for 3D?
wcj1n18 is offline   Reply With Quote

Old   February 11, 2021, 12:38
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,921
Rep Power: 23
pakk will become famous soon enough
I don't know that... Making a UDF parallel is not something I am good in, and the error messages are never helpful.
pakk is offline   Reply With Quote

Old   February 12, 2021, 04:05
Default
  #7
New Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 25
Rep Power: 2
wcj1n18 is on a distinguished road
OK, but as far as you know it is possible to do so? This is what I would have to do in order to make it work in parallel processing I guess.
Thanks
wcj1n18 is offline   Reply With Quote

Old   March 15, 2021, 13:27
Default
  #8
FJW
New Member
 
Join Date: Dec 2020
Posts: 1
Rep Power: 0
FJW is on a distinguished road
Hi wcj1n18,

Did you manage to modify the 2D Contact Detection UDF to work in 3D? If so, could you please provide me with some pointers on how to do it?

Thank you!
FJW is offline   Reply With Quote

Old   March 16, 2021, 06:35
Default
  #9
New Member
 
Will Crawford-Jones
Join Date: Jan 2021
Posts: 25
Rep Power: 2
wcj1n18 is on a distinguished road
Hey,

I actually was over-complicating it. It seems to work in 3D anyway. That code just simply reflects the velocity in the same way that a ball would bounce of a wall. But yeah, it should work in 3D.
FJW likes this.
wcj1n18 is offline   Reply With Quote

Old   March 17, 2021, 23:33
Default
  #10
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,778
Rep Power: 28
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
there is no reason to make this code parallel
remove
Code:
# if RP_NODE
{
/* Reduce in parallel */
nid = PRF_GIHIGH1 (nid);
n_faces = PRF_GISUM1 (n_faces);

PRF_GRSUM3 (nc[0], nc[1], nc[2]);
PRF_GRSUM3 (xc[0], xc[1], xc[2]);
}
# endif

/* Propogate to host */
node_to_host_int_2 (nid, n_faces);
node_to_host_real_3 (nc[0], nc[1], nc[2]);
node_to_host_real_3 (xc[0], xc[1], xc[2]);
FJW and wcj1n18 like this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply

Tags
3 dimensions, contact detection, udf and programming, udf manual

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
UDF for dynamic Contact Angle Wolfgang.Black FLOW-3D 0 May 26, 2020 15:20
Replicating Scalable Wall Function with a UDF yousefaz FLUENT 0 August 4, 2017 02:30
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 22:14
Contact angle UDF shephali shrimali FLUENT 0 May 10, 2007 07:52
UDF for dynamic contact angle Aireen FLUENT 0 August 11, 2006 11:08


All times are GMT -4. The time now is 08:58.