#include <stdlib.h> //使用exit所需的库文件
#include <conio.h> //使用clrscr,getch所需的库文件
#include <malloc.h> //使用malloc、free所需的库文件
#include <stdio.h> //使用标准输入输出所需的库文件
#include "beam.h" //自定义头文件
void init_beam(double *ptr) { int i,j; char c='0'; int fix_node; double *nodf_ptr;
nodf_ptr = (double *)malloc(n*sizeof(double)); if (nodf_ptr == NULL){ printf("Create nodf_mem Error!\n"); fprintf(fp,"Create nodf_mem Error!\n"); free(ptr); free(beam_ptr); fclose(fp); getch(); exit (1); } else { printf("Init nodal forces:\n"); fprintf(fp,"Init nodal forces:\n"); for(i=0;i<n;i++) { scanf("%lf", nodf_ptr+i); fprintf(fp,"%lf\n", *(nodf_ptr+i)); } }
printf("\nInit beams:\n"); fprintf(fp,"\nInit beams:\n"); for(i=0;i<n-1;i++) { printf("\n\nBeam %d\n",i+1); fprintf(fp,"\n\nBeam %d\n",i+1); printf("Input E:\n"); fprintf(fp,"Input E:\n"); scanf("%lf", &((beam_ptr+i)->E)); fprintf(fp,"%lf\n", (beam_ptr+i)->E); printf("Input I:\n"); fprintf(fp,"Input I:\n"); scanf("%lf", &((beam_ptr+i)->I)); fprintf(fp,"%lf\n", (beam_ptr+i)->I); printf("Input l:\n"); fprintf(fp,"Input l:\n"); scanf("%lf", &((beam_ptr+i)->l)); fprintf(fp,"%lf\n", (beam_ptr+i)->l); printf("Input F:\n"); fprintf(fp,"Input F:\n"); if (choose == 'c') { scanf("%lf", &((beam_ptr+i)->F)); if ((ACCURACY_LOWER > ((beam_ptr+i)->F)) || (((beam_ptr+i)->F) > ACCURACY_UPPER)) { printf("Input a:\n"); fprintf(fp,"Input a:\n"); scanf("%lf", &((beam_ptr+i)->a)); fprintf(fp,"%lf\n", (beam_ptr+i)->a); } printf("Input q:\n"); fprintf(fp,"Input q:\n"); scanf("%lf", &((beam_ptr+i)->q)); fprintf(fp,"%lf\n", (beam_ptr+i)->q); } }
for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { *(ptr+tab(i,j)) = 0; } } *(ptr+tab(1,1)) = 4 * STIFF(0); *(ptr+tab(n,n)) = 4 * STIFF(n-2); *(ptr+tab(n-1,n)) = 2 * STIFF(n-2); *(ptr+tab(n,n-1)) = 2 * STIFF(n-2); for(i=2;i<n;i++) { *(ptr+tab(i,i)) = 4 * (STIFF(i-1) + STIFF(i-2)); *(ptr+tab(i,i-1)) = 2 * STIFF(i-2); *(ptr+tab(i-1,i)) = *(ptr+tab(i,i-1)); } *(ptr+tab(1,n+1)) = *nodf_ptr + M_q_left(0) + M_F_left(0); *(ptr+tab(n,n+1)) = *(nodf_ptr+n-1) + M_q_right(n-2) + M_F_right(n-2); for(i=2;i<n;i++) { *(ptr+tab(i,n+1)) = *(nodf_ptr+i-1) + M_q_right(i-2) + M_F_right(i-2) + M_q_left(i-1) + M_F_left(i-1); }
printf("Init fixed crunode\n"); fprintf(fp,"Init fixed crunode\n"); while(c != 'q') { printf("Input fixed node num:\n"); fprintf(fp,"Input fixed node num:\n"); scanf("%d",&fix_node); fprintf(fp,"%d\n",fix_node); if((fix_node >= 1) && (fix_node <= n)) { for(i=1;i<=n;i++) { *(ptr+tab(i,fix_node)) = 0; } for(i=1;i<=n+1;i++) { *(ptr+tab(fix_node,i)) = 0; } *(ptr+tab(fix_node,fix_node)) = 1; } printf("Press 'q' if u wanto end input fixed node!\n"); fprintf(fp,"Press 'q' if u wanto end input fixed node!\n"); c = getch(); }
free(nodf_ptr); }
|