# Global node coordinates values FSI-UDF

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

 February 8, 2021, 05:58 Global node coordinates values FSI-UDF #1 New Member   Marcelo Ruiz Join Date: Feb 2021 Location: Italy Posts: 16 Rep Power: 3 Hello everybody, I am traying to reproduce the motion of a fish in 2D. I am using the Macro DEFINE_GRID_MOTION(). I want to extract the initial coordinates of the fish, so that I can use it over all simulation. I other words, motion is defined by the initial position f(x_0,y_0,t). I have tried to code it in the same macro. Nevertheless, I have not succeed. Could you please provide me any advice? Which macro I can use to extract the Initial values and store it in a global variable matrix/array? In the next code I try to extract the minimum and maximum coordinates before the deformation. However it did not work properly: Code: ```DEFINE_GRID_MOTION(motion, domain, dt, time, dtime) { Thread* tf = DT_THREAD(dt); face_t f; Node* v; double xprev, yprev, hprev, d, h; int n; double x_max, x_min; x_max = -0.99e38; x_min = 0.99e38; begin_f_loop(f, tf) // I used this loop to find the maximum and minimum and maximum but it did not work { f_node_loop(f, tf,n) { v = F_NODE(f,tf, n); x_max = MAX(x_max, NODE_X(v)); x_min = MIN(x_min, NODE_X(v)); } }end_f_loop(f, tf) #if RP_NODE x_max = PRF_GRHIGH1(x_max); x_min = PRF_GRHIGH1(x_min); #endif SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf)); begin_f_loop(f, tf) { f_node_loop(f, tf, n) { v = F_NODE(f, tf, n); if (NODE_POS_NEED_UPDATE(v)) { NODE_POS_UPDATED(v); if (CURRENT_TIME > 0.0) { xprev = NODE_X(v); yprev = NODE_Y(v); hprev = kinematics(xprev, PREVIOUS_TIME,x_max,x_min); //Function for the kinematics of fish d = yprev; h = kinematics(xprev, CURRENT_TIME, x_max, x_min); //Function for the kinematics of fish NODE_Y(v) = d+hprev-h; } } } } end_f_loop(f,tf) }``` Thank you for the advice,

February 27, 2021, 09:36
#2
Member

Join Date: Jan 2020
Posts: 31
Rep Power: 4
Quote:
 Originally Posted by CFDavatar Hello everybody, I am traying to reproduce the motion of a fish in 2D. I am using the Macro DEFINE_GRID_MOTION(). I want to extract the initial coordinates of the fish, so that I can use it over all simulation. I other words, motion is defined by the initial position f(x_0,y_0,t). I have tried to code it in the same macro. Nevertheless, I have not succeed. Could you please provide me any advice? Which macro I can use to extract the Initial values and store it in a global variable matrix/array? In the next code I try to extract the minimum and maximum coordinates before the deformation. However it did not work properly: Code: ```DEFINE_GRID_MOTION(motion, domain, dt, time, dtime) { Thread* tf = DT_THREAD(dt); face_t f; Node* v; double xprev, yprev, hprev, d, h; int n; double x_max, x_min; x_max = -0.99e38; x_min = 0.99e38; begin_f_loop(f, tf) // I used this loop to find the maximum and minimum and maximum but it did not work { f_node_loop(f, tf,n) { v = F_NODE(f,tf, n); x_max = MAX(x_max, NODE_X(v)); x_min = MIN(x_min, NODE_X(v)); } }end_f_loop(f, tf) #if RP_NODE x_max = PRF_GRHIGH1(x_max); x_min = PRF_GRHIGH1(x_min); #endif SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf)); begin_f_loop(f, tf) { f_node_loop(f, tf, n) { v = F_NODE(f, tf, n); if (NODE_POS_NEED_UPDATE(v)) { NODE_POS_UPDATED(v); if (CURRENT_TIME > 0.0) { xprev = NODE_X(v); yprev = NODE_Y(v); hprev = kinematics(xprev, PREVIOUS_TIME,x_max,x_min); //Function for the kinematics of fish d = yprev; h = kinematics(xprev, CURRENT_TIME, x_max, x_min); //Function for the kinematics of fish NODE_Y(v) = d+hprev-h; } } } } end_f_loop(f,tf) }``` Thank you for the advice,
after this code use N_UDMI(v,0) & N_UDMI(v,1) as the initial condition nodes for x and y. please search about DEFINE_ON_DEMAND macro. Don't forget that you must "Execute on Demand" it in fluent after Initialization.

DEFINE_ON_DEMAND(NODE_FIRST)
{
Domain *d= Get_Domain(1);
face_t f;
Node *v;
int n;
FILE *fout;
real time=CURRENT_TIME;
{
begin_f_loop(f,t)
{
f_node_loop(f,t,n)
{
v = F_NODE(f,t,n);
N_UDMI(v,0) = NODE_X(v);
N_UDMI(v,1) = NODE_Y(v);
}
}
}
end_f_loop (f,t)
}

 October 26, 2021, 23:49 #3 New Member   Thomas Sprengeler Join Date: Oct 2020 Posts: 3 Rep Power: 4 Were you able to store the initial coordinates and make this work?

October 27, 2021, 10:25
#4
New Member

Marcelo Ruiz
Join Date: Feb 2021
Location: Italy
Posts: 16
Rep Power: 3
Quote:
 Originally Posted by sprengeler Were you able to store the initial coordinates and make this work?
Hello, at the end I just kept the fish swiiming from a fixed reference coordinate system. You can try with etedalgara suggestion above

October 27, 2021, 12:27
#5
New Member

Thomas Sprengeler
Join Date: Oct 2020
Posts: 3
Rep Power: 4
Quote:
 Originally Posted by CFDavatar Hello, at the end I just kept the fish swiiming from a fixed reference coordinate system. You can try with etedalgara suggestion above
Is there a way to specify a fixed reference coordinate system in your UDF?

 Tags define_grid_motion(), fluid-solid, fsi, global variables