CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   dynamic meshing UDF motion coding issue! (https://www.cfd-online.com/Forums/fluent-udf/133198-dynamic-meshing-udf-motion-coding-issue.html)

lmarf88 April 11, 2014 12:42

dynamic meshing UDF motion coding issue!
 
Hello!

I am trying to simulate a 2D moving piston to analyse the pressure flow field in a closed system. I currently have a rectangular mesh and am trying to write a Define_GEOM macro to define the motion of one moving boundary to simulate the movement piston.

I do not have much experience with coding, but have been looking at various tutorials and examples and have so far come up with the following code:


#include "udf.h"

DEFINE_GEOM(moving_boundary,domain,dt,position)

int position;
for (int position=0; position<=230.5; position++)
{
nextposition = position+1;
if (position<230.5)
{
nextposition = - 138399*position*position + 2716.6*position - 0.7678;
}
position = nextposition;
}


The code contains a simple sin function: y = -138399x^2 + 2716.6x - 0.7678 which should allow the piston to accelerate and decelerate. The code is designed to move the piston wall from position 0mm to position 230.5mm and then stop. So I want the position to increment at 1mm every iteration from 0mm to 230.5mm at a rate of the sin function shown.
I am getting a lot of errors with this though and was hoping someone might be able to help!:confused:

Originally I used this code: { position[1] = - 138399*position[0]*position[0] + 2716.6*position[0] - 0.7678; }
and managed to hook it to my model, however as there is no loop function, the wall only moves slightly once.

Any help would be massively appreciated.

Thanks!

Lisa


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