#include #include"udf.h" #defineUDF_FILENAME"udf_loc_velo_acc" #defineTemp_File"mytemp" /*readcurrentlocation,velocityandacceleratorfromfile*/ staticvoid read_loc_vel_acc_file(real*loc1,real*vel1,real*acc1) { FILE*fp=fopen(Temp_File,"r"); if(fp!=NULL) { floatread_loc1,read_vel1,read_acc1; fscanf(fp,"%e%e%e",&read_loc1,&read_vel1,&read_acc1); fclose(fp); *loc1=(real)read_loc1; *vel1=(real)read_vel1; *acc1=(real)read_acc1; Message("\nUDFreadviv:y_vel=%f,acc=%f Message("\nUDFreadv iv:y_vel=%f,acc=%f,loc(m)=%f\n", ,loc(m)=%f\n", *vel1,*acc1,*loc1); } else { *loc1=0.0; *vel1=0.0; *acc1=0.0; Message("\nThefirstreadingofudf_loc_vel_acc_file\n"); } } /*writecurrentlocation,velocityandaccele /*writecurrentlocat ion,velocityandaccelerationintofile*/ rationintofile*/ staticvoid write_loc_vel_acc_file(realloc,realvel,realacc) { FILE*fp=fopen(UDF_FILENAME,"a"); if(fp!=NULL) { fprintf(fp,"%e%e%e\n",loc,vel,acc); fclose(fp); } else Message("\nWarning:cannotwrite%sfile",UDF_FILENAME); } /*writecurrentlocation,velocityandacceler /*writecurrentlocat ion,velocityandaccelerationintotemp_file*/ ationintotemp_file*/ staticvoid write_loc_vel_acc_file2(realloc,realvel,realacc) { FILE*fp=fopen(Temp_File,"w"); if(fp!=NULL) { fprintf(fp,"%e%e%e\n",loc,vel,acc); fclose(fp); } else Message("\nWarning:cannotwrite%sfile",Temp_File); } DEFINE_CG_MOTION(viv,dt,cg_vel,cg_omega,time,dtime) { #defineDELTA0.5 #defineBETA0.25 #defineK_SPRING22.406
#defineMASS4.864 #definexi0.0054 realwn=sqrt(K_SPRING/MASS); realCC=2*xi*wn*MASS; /*fn=2.92745*/ /*massratioequaul2.4*/ realloc,vel,acc,loc1,vel1,acc1; reala0,a1,a2,a3,a4,a5,a6,a7,keff,reff; staticintid1=5;/*FaceIDofthecylinder*/ staticrealf_glob[3];/*Totalforces(global)*/ staticrealm_glob[3];/*Moment(global)*/ staticrealx_cg[3];/*CGlocation*/ staticrealforce[3]; inti=0; Thread*tf1; Domain*domain=Get_Domain(1); tf1=Lookup_Thread(domain,id1); a0=1/(BETA*dtime*dtime); a1=DELTA/(BETA*dtime); a2=1/(BETA*dtime); a3=0.5/BETA-1; a4=DELTA/BETA-1; a5=0.5*dtime*(DELTA/BETA-2); a6=dtime*(1-DELTA); a7=DELTA*dtime; keff=a0*MASS+a1*CC+K_SPRING; /*resetvelocities*/ NV_S(cg_vel,=,0.0); NV_S(cg_omega,=,0.0); if(!Data_Valid_P()) return; /*GetCGposition*/ for(i=0;i