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

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

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

Like Tree2Likes
  • 1 Post By Yasser
  • 1 Post By Yasser

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 27, 2021, 23:52
Default UDF problem---setting an external force on surface in 6DOF
  #1
New Member
 
Join Date: Feb 2020
Posts: 20
Rep Power: 3
Silence is on a distinguished road
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 <iostream>
#include <fstream>
#include <iterator>
#include <vector>
#include "udf.h"
using namespace std;
static vector<pair<real, real>> 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<real> f( (istream_iterator<real>(Force_file)), istream_iterator<real>() );

/* separate time and force, and save them into container Fvec */
for (auto i = f.begin(); i != f.end(); i += 2)
{
Fvec.push_back(pair<real, real>(*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;

}
Silence is offline   Reply With Quote

Old   March 28, 2021, 11:56
Default
  #2
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 16
Yasser is on a distinguished road
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.
Yasser is offline   Reply With Quote

Old   March 29, 2021, 02:16
Default
  #3
New Member
 
Join Date: Feb 2020
Posts: 20
Rep Power: 3
Silence is on a distinguished road
Quote:
Originally Posted by Yasser View Post
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
Silence is offline   Reply With Quote

Old   March 29, 2021, 07:42
Default
  #4
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 16
Yasser is on a distinguished road
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.
Yasser is offline   Reply With Quote

Old   May 13, 2021, 04:06
Smile
  #5
New Member
 
Join Date: Feb 2020
Posts: 20
Rep Power: 3
Silence is on a distinguished road
Quote:
Originally Posted by Yasser View Post
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:
Sorry for such a late reply, since I was assigned to another program, I could not read your answer in time.
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
Silence is offline   Reply With Quote

Reply

Tags
6dof, dynamic mesh, force, udf code

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
Fluent Parallelization Problem After AC Power Dropped pawl Hardware 5 November 13, 2016 06:08
[Gmsh] Problem with Gmsh nishant_hull OpenFOAM Meshing & Mesh Conversion 23 August 5, 2015 02:09
[snappyHexMesh] determining displacement for added points CFDnewbie147 OpenFOAM Meshing & Mesh Conversion 1 October 22, 2013 09:53
Cells with t below lower limit Purushothama Siemens 2 May 31, 2010 21:58
gravitational force for free surface flow Jongtae Kim Main CFD Forum 1 July 2, 2000 11:57


All times are GMT -4. The time now is 13:56.