|
动网格 UDF,支持多个运动,支持并行,支持信息自动保存
- /* ******************************************* */
- /* ******************************************* */
- 可以根据需要,添加更多的运动
- 支持多个运动,支持并行,支持信息自动保存
- /* ******************************************* */
- /* ******************************************* */
- # include "udf.h"
- /* ******************************************* */
- static real G = 9.80; /* gravity */
- static real valve_M = 0.1; /* mass of moving object*/
- static real valve_S = 0.0; /* replacement of moving object*/
- static real valve_V = 0.0; /* velocity of moving object */
- static real valve_F = 0.0; /* fluid force of one component */
- static int is_valve = 0; /* is the object still moving */
- static real ball_M = 0.19; /* mass of moving object*/
- static real ball_S = 0.0; /* replacement of moving object*/
- static real ball_V = 0.0; /* velocity of moving object */
- static real ball_F = 0.0; /* fluid force of one component */
- static int is_ball = 0; /* is the object still moving */
- /* ******************************************* */
- DEFINE_CG_MOTION(valve, dt, vel, omega, time, dtime)
- {
- #if !RP_HOST
- Thread *t;
- Domain *d;
- real dv, CG[ND_ND], force[3], moment[3];
- /* Check to see if there is data */
- if (!Data_Valid_P ())
- {
- Message0("\n\nNo data->No mesh motion!!!\n\n");
- return;
- }
-
- /* Reset velocities */
- NV_S (vel, =, 0.0);
- NV_S (omega, =, 0.0);
-
- /* Calculate force*/
- d = THREAD_DOMAIN (DT_THREAD ((Dynamic_Thread *)dt));
- t = DT_THREAD(dt);
- NV_S (CG, =, 0.0);
- Compute_Force_And_Moment (d, t, CG, force, moment, FALSE);
- /* Compute change in velocity, i.e., dv=F*dt/M velocity update using explicit Euler formula */
- dv = dtime * (force[0] - G * valve_M) / valve_M;
- if(is_valve == 0 && dv >= 0.0)
- {
- is_valve = 1;
- Message0("\n\n============================== BEGIN VALVE MOTION INFO ==============================\n");
- Message0("\n VALVE BEGIN MOVE! \n");
- Message0("\n============================== END VALVE MOTION INFO ==============================\n");
- }
- if(is_valve == 0 && dv < 0.0) {
- dv = 0.0;
- }
- valve_V += dv;
- if(valve_S >= 0.010)
- {
- valve_V = 0.0;
- }
- valve_S += valve_V * dtime;
- /* Set x-component of velocity */
- vel[0] = valve_V;
- valve_F = force[0];
- Message0("\n\n============================== BEGIN VALVE MOTION INFO ==============================\n");
- Message0("\ntime=%.5e F(x)=%.4e S(x)=%.6e V(x)=%.6e move?=%d\n", time, force[0], valve_S, valve_V, is_valve);
- Message0("\n============================== END VALVE MOTION INFO ==============================\n");
- #endif
- node_to_host_real_1(valve_S);
- node_to_host_real_1(valve_V);
- node_to_host_real_1(valve_F);
- node_to_host_int_1(is_valve);
- node_to_host_real(vel, ND_ND);
- node_to_host_real(omega, ND_ND);
- }
- DEFINE_CG_MOTION(ball, dt, vel, omega, time, dtime)
- {
- #if !RP_HOST
- Thread *t;
- Domain *d;
- real dv, CG[ND_ND], force[3], moment[3];
- /* Check to see if there is data */
- if (!Data_Valid_P ())
- {
- Message0("\n\nNo data->No mesh motion!!!\n\n");
- return;
- }
-
- /* Reset velocities */
- NV_S (vel, =, 0.0);
- NV_S (omega, =, 0.0);
-
- /* Calculate force*/
- d = THREAD_DOMAIN (DT_THREAD ((Dynamic_Thread *)dt));
- t = DT_THREAD(dt);
- NV_S (CG, =, 0.0);
- Compute_Force_And_Moment (d, t, CG, force, moment, FALSE);
- /* Compute change in velocity, i.e., dv=F*dt/M velocity update using explicit Euler formula */
- dv = dtime * (force[0] - G * ball_M) / ball_M;
- if(is_ball == 0 && dv >= 0.0)
- {
- is_ball = 1;
- Message0("\n\n============================== BEGIN BALL MOTION INFO ==============================\n");
- Message0("\n BALL BEGIN MOVE! \n");
- Message0("\n============================== END BALL MOTION INFO ==============================\n");
- }
- if(is_ball == 0 && dv < 0.0) {
- dv = 0.0;
- }
- ball_V += dv;
- ball_S += ball_V * dtime;
-
- /* Set x-component of velocity */
- vel[0] = ball_V;
- ball_F = force[0];
- Message0("\n\n============================== BEGIN BALL MOTION INFO ==============================\n");
- Message0("\ntime=%.5e F(x)=%.4e S(x)=%.6e V(x)=%.6e move?=%d\n", time, force[0], ball_S, ball_V, is_ball);
- Message0("\n============================== END BALL MOTION INFO ==============================\n\n");
- #endif
- node_to_host_real_1(ball_S);
- node_to_host_real_1(ball_V);
- node_to_host_real_1(ball_F);
- node_to_host_int_1(is_ball);
- node_to_host_real(vel, ND_ND);
- node_to_host_real(omega, ND_ND);
- }
- static void write_data(FILE *fp)
- {
- fprintf(fp, "%e ", valve_V);
- fprintf(fp, "\n");
- fprintf(fp, "%e ", valve_S);
- fprintf(fp, "\n");
- fprintf(fp, "%e ", valve_F);
- fprintf(fp, "\n");
- fprintf(fp, "%d ", is_valve);
- fprintf(fp, "\n");
- fprintf(fp, "%e ", ball_V);
- fprintf(fp, "\n");
- fprintf(fp, "%e ", ball_S);
- fprintf(fp, "\n");
- fprintf(fp, "%e ", ball_F);
- fprintf(fp, "\n");
- fprintf(fp, "%d ", is_ball);
- }
- static void read_data(FILE * fp)
- {
- fscanf(fp, "%e", [$valve_V)]
- fscanf(fp, "%e", [$valve_S)]
- fscanf(fp, "%e", [$valve_F)]
- fscanf(fp, "%d", [$is_valve)]
- fscanf(fp, "%e", [$ball_V)]
- fscanf(fp, "%e", [$ball_S)]
- fscanf(fp, "%e", [$ball_F)]
- fscanf(fp, "%d", [$is_ball)]
- }
- DEFINE_RW_FILE(reader, fp)
- {
- Message0("\n\n============================== BEGIN UDF INFOMATION ==============================\n");
- Message0("\nReading UDF data from data file...\n");
- #if PARALLEL
- #if RP_HOST
- read_data(fp);
- #endif
- #else
- read_data(fp);
- #endif
- host_to_node_real_1(valve_V);
- host_to_node_real_1(valve_S);
- host_to_node_real_1(valve_F);
- host_to_node_int_1(is_valve);
-
- host_to_node_real_1(ball_V);
- host_to_node_real_1(ball_S);
- host_to_node_real_1(ball_F);
- host_to_node_int_1(is_ball);
- Message0("\n------------------------------ BEGIN VALVE MOTION INFO ------------------------------\n");
- Message0("\nS(x)=%.6e V(x)=%.6e F(x)=%.4e move?=%d\n", valve_S, valve_V, valve_F, is_valve);
- Message0("\n------------------------------ END VALVE MOTION INFO ------------------------------\n");
-
- Message0("\n------------------------------ BEGIN BALL MOTION INFO ------------------------------\n");
- Message0("\nS(x)=%.6e V(x)=%.6e F(x)=%.4e move?=%d\n", ball_S, ball_V, ball_F, is_ball);
- Message0("\n------------------------------- END BALL MOTION INFO -------------------------------\n");
- Message0("\n================================ END UDF INFOMATION ================================\n\n");
- }
- DEFINE_RW_FILE(writer, fp)
- {
- Message0("\n\n============================== BEGIN UDF INFOMATION ==============================\n");
- Message0("\n\nWriting UDF data to data file...\n");
- #if PARALLEL
- #if RP_HOST
- write_data(fp);
- #endif
- #else
- write_data(fp);
- #endif
- Message0("\n================================ END UDF INFOMATION ================================\n\n");
- }
复制代码
来自傲雪 |
|