# UDF problem---setting an external force on surface in 6DOF

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

 March 28, 2021, 00:52 UDF problem---setting an external force on surface in 6DOF #1 New Member   Join Date: Feb 2020 Posts: 20 Rep Power: 5 Background: Hello everyone: I want to simulate compression of oil film, in my case, I assigned a force to push the moving wall move along y axis, details have been shown in Figure 1. The force consists of lots of points shown in Figure 2, which cannot be expressed by a function, thus, I need to read them and then set them as input, in this case, I used UDF(UDF code has been presented below) to solve this problem. The question is: UDF can be successfully compiled and the txt data can be successfully read(shown in Figure 3), but either in preview mesh motion or calculation, the expected moving wall fails to move, I guess there must be something wrong with my UDF code, but I cannot figure it out, can someone help me out? cause this problem puzzles me for a long time. Thanks for your time and attention. Regards, Figure 1 Figure 2 Figure 3 My UDF code #include #include #include #include #include "udf.h" using namespace std; static vector> Fvec; /* creating a container for time-force points */ /* UDF macro for reading time-force points in txt file */ DEFINE_EXECUTE_ON_LOADING(External_force_import, libname) { cout << "The contents of the file are as follows: " << endl; ifstream Force_file("force_sin.txt"); /* read time-force points */ /* save the file("force_sin.txt") data into container 'v' */ vector f( (istream_iterator(Force_file)), istream_iterator() ); /* separate time and force, and save them into container Fvec */ for (auto i = f.begin(); i != f.end(); i += 2) { Fvec.push_back(pair(*i, *(i + 1))); } for (const auto &i : Fvec) { cout << i.first << "\t" << i.second << endl; } } /* UDF macro for six DOF solver */ DEFINE_SDOF_PROPERTIES(Piston_force, prop, dt, time, dtime) { real Force_value; /* assign force value to variable Force_value */ for (auto i = Fvec.begin(); i != Fvec.end() - 1; ++i) { if ( (i->first <= CURRENT_TIME) && ((i+1)->first > CURRENT_TIME) ) { Force_value = i->second; break; } } /* Basic properties */ prop[SDOF_MASS] = 0.1; /* mass */ prop[SDOF_LOAD_F_Y] = Force_value; /* external force assigned on moving wall */; /* Translation constraint */ prop[SDOF_ZERO_TRANS_X] = TRUE; prop[SDOF_ZERO_TRANS_Z] = TRUE; /* Rotation constraint */ prop[SDOF_ZERO_ROT_X] = TRUE; prop[SDOF_ZERO_ROT_Y] = TRUE; prop[SDOF_ZERO_ROT_Z] = TRUE; }

 March 28, 2021, 12:56 #2 Member   Yasser Selima Join Date: Mar 2009 Location: Canada Posts: 52 Rep Power: 18 May be you need to change the force direction! Also print a Message showing the force to make sure you are reading the correct value Silence likes this.

March 29, 2021, 03:16
#3
New Member

Join Date: Feb 2020
Posts: 20
Rep Power: 5
Quote:
 Originally Posted by Yasser May be you need to change the force direction! Also print a Message showing the force to make sure you are reading the correct value
Hi, Yasser,
Thanks for your suggestion! The problem has now been solved!
I found that it is one syntax in my UDF that prevent me realizing the wall motion.
One more question, either after loading UDF or previewing mesh motion, there popped out many same messages, for example, in previewing mesh motion, in every step, the message “force value: xxx” will be displayed on console 82 times(I know this comes from my syntax “ cout << “Force_value: Force_value” ”), which is shown in Figure 4. For this problem, I guess there must be a 82 times loop when running the UDF, but I do not know how to control the displaying times?(I just one to see this message for only one time)
Regards

Figure 4

 March 29, 2021, 08:42 #4 Member   Yasser Selima Join Date: Mar 2009 Location: Canada Posts: 52 Rep Power: 18 This is because every node displays one message ... but I doubt having 82 nodes. Try this and see what happens #if RP_HOST Message(" .... ", ...); #end if Silence likes this.

May 13, 2021, 05:06
#5
New Member

Join Date: Feb 2020
Posts: 20
Rep Power: 5
Quote:
 Originally Posted by Yasser This is because every node displays one message ... but I doubt having 82 nodes. Try this and see what happens #if RP_HOST Message(" .... ", ...); #end if
Hello, Yasser:
Today, I am free from that, and I looked up the directives you gave in UDF manual and wrote it in UDF, then, I found that there still exists two lines of message. For this, in my opinion, it is because my computer has two hosts？(My computer has 24 cores-48threads, maybe 1host contain 12 cores.)
And for why there were 82 lines before, I don’t figure it out yet, the situation was: at that time, I set 40 solver processes, which displayed 82lines, and today, I tried different number of processes, such as 4, 10, and the corresponding message lines is: 10 lines for 4 processes, 22 lines for 10 processes, I found number of lines follows the function: lines = 2*processes + 2(Is this the number of host?), but I don’t know why...
Above is my guess, I do not know if it is right of wrong, please correct me if I am wrong, thanks!

Regards,
Silence

 Tags 6dof, dynamic mesh, force, udf code