/***********************************************************************/
/* vinlet_udf.c
*/
/* UDFs for specifying time dependant velocity profile boundary condition
*/ 
/***********************************************************************/
//Written by Chiyu Jiang
//Cornell University

#include "udf.h"//file that contains definitions for define functions and fluent operations
#define PI 3.141592654

DEFINE_PROFILE(inlet_velocity,th,i)
{
	face_t f;
	begin_f_loop(f,th)
		double t = (CURRENT_TIME*2-floor(CURRENT_TIME*2))/2; //t is the local time within each period

	{
		if(t <= 0.218)
			F_PROFILE(f,th,i) = 0.5*sin(4*PI*(t+0.0160236));
		else
			F_PROFILE(f,th,i) = 0.1;
	}
	end_f_loop(f,th);
}

/*********************************************************************
 UDF for applying the Casson Non-newtonian fluid model
 By Chiyu Jiang, Cornell University
 04-23-2015
 **********************************************************************/
 #include "udf.h"
 #define Hct 0.4
 #define mu_p 0.00145
 DEFINE_PROPERTY(casson_viscosity,c,t)
 {
 real mu_casson;
 real gamma = C_STRAIN_RATE_MAG(c,t);
 real N_inf = sqrt(mu_p*pow((1-Hct),-0.25));
 real mu_inf = sqrt(pow((0.625*Hct),3));
 if(gamma!=0){
 mu_casson = pow(mu_inf,2)/gamma+2*mu_inf*N_inf/sqrt(gamma)+pow(N_inf,2);}
 else{
 mu_casson = 0.0035;
 }
 return mu_casson;
 }