/***********************************************************************/
/* MAE523code.c
*/
/* UDFs for specifying time dependant velocity profile boundary condition,
	calculating coefficient of lift on a surface of an arbitrary geometry, and initializing a good start for an unsteady case
*/ 
/***********************************************************************/
//Written by Drew Eisenberg
//Modified by Rajesh Bhaskaran
//Cornell University

#include "udf.h"//file that contains definitions for define functions and fluent operations
#define PI 3.141592654

//note that arrays/vectors start with an index of 0 rather than 1 as it is in MATLAB
//liftFunc is the name of UDF which appears in GUI
// thread contains boundary zone no. (assigned via GUI)
// nu sets which variable is being modified (user defined scalar //      in our case ... also assigned via GUI) 

DEFINE_PROFILE(liftFunc, thread, nu)
{
	real pressure;
	real area[ND_ND];//defines an empty array (similar to a vector in MATLAB)
	real liftF;
    real a_x=0;
    real a_y=0;
    real j_normal=0;
	face_t face;
	begin_f_loop(face,thread)//loops through all faces in the given thread
	{
		pressure = F_P(face,thread);//F_P returns the static pressure at this face
        
        F_AREA(area,face,thread);
        a_x = area[0];
        a_y = area[1];
        j_normal = a_y/sqrt(pow(a_x,2)+pow(a_y,2));
        liftF = pressure*j_normal;
        
		F_PROFILE(face,thread,nu) = liftF;//returns the value of liftF into the face for this profile (a UDS from Fluent)
	}
	end_f_loop(face,thread)
}


