/* Description: Convert force-deflection or true-stress-strain curve to effective stress-strain curve Author: Suri Bala Date: May 2007 Usage: programe_name lsdyna_keyword_file -emod emod_value [-sigy sig_value -emod_strain avg_points -epse elastic_strain] Help: lsdyna_keyword_file would consist of DEFINE_CURVE which identifies the force-deflection curve Help: Parameters SFA and SFO are specimen length and specimen area Copyright: Livermore Software */ #include #include #include #include #include #define LINE_MAX 255 #define DIG_POINTS 100 #define CURVE_MAX 100 #define STRAIN_RATE_MAX 10 #define POINT_MAX 1000 #define OFFSET 0.002 char buffer[LINE_MAX]; typedef struct point { char *x; char *y; } Point; typedef struct line { struct point *p1; struct point *p2; } Line; typedef struct curve { char id[11]; int num_points; int type; char specimen_length[11]; char specimen_area[11]; char youngs_modulus[11]; struct point FD[POINT_MAX]; struct point TSS[POINT_MAX]; struct point EFFSS[POINT_MAX]; struct point ENGSS[POINT_MAX]; } Curve; typedef struct table { struct curve Curve[STRAIN_RATE_MAX]; } Table; char *getLine(FILE *fp); Point *getLineIntersection(Line *line1, Line *line2); float findYield(Point TSS[], int np, float emod, float offset); float getYoungsModulus(Point TSS[], int np, int emod_strain); int main(int argc, char *argv[]) { Curve Curves[CURVE_MAX]; FILE *fp = NULL, *fo=NULL; char *line = NULL; int i=0, j=0, num_curves=0, num_points=0, type=0; float offset=OFFSET, estress=0, emod_strain=0.0, estrain=0, omod=0, emod=0, sigy=0, epse=0, min_y=0; if( argc == 1 ) { fprintf(stderr, "Usage: fd_2_stress_strain fd_lsdyna_input_file_format.k", argv[0]); exit(-1); } // gather emod and sigy for(i=0; i= 0 && atof(Curves[i].EFFSS[j].y)>=sigy ) { fprintf(fo, "%20s%20s\n", Curves[i].EFFSS[j].x , Curves[i].EFFSS[j].y); } } } fprintf(fo, "*end"); fprintf(stdout," The converted stress-strain curve is stored in converted.k\n"); fclose(fp); fclose(fo); exit(-1); } float getYoungsModulus(Point TSS[], int np, int emod_strain) { int i=0; float emod = 0; // if no emod_strain, return the first slope if( emod_strain == 0 ) return ( atof(TSS[1].y) - atof(TSS[0].y) ) / ( atof(TSS[1].x) - atof(TSS[0].x) ); // if emod_strain > 0 , return the avg of slope from 0 to emod_strain if( emod_strain > 0 ) { for( i=0; i emod_strain ) break; } return emod; } // if emod_strain < 0 , return the slope from 0 to emod_strain if( emod_strain > 0 ) { for( i=0; i= abs(emod_strain) ) emod = ( atof(TSS[i].y) - atof(TSS[i-1].y) ) + ( atof(TSS[i].x) - atof(TSS[i-1].x) ); } return emod; } return 0.0; } char *getLine(FILE *fp) { fgets(buffer, LINE_MAX, fp); while( strncmp(buffer,"$",1) ==0 ) { fgets(buffer, LINE_MAX, fp); } buffer[strlen(buffer)-1] = '\0'; return buffer; } float findYield(Point TSS[], int np, float emod, float offset) { int i=0; Line *offset_line=NULL, *line_segment=NULL; Point *op1=NULL, *op2=NULL, *ipoint=NULL; op1 = (Point*)malloc(1*sizeof(Point)); op2 = (Point*)malloc(1*sizeof(Point)); op1->x = (char *)malloc(20*sizeof(char)); op1->y = (char *)malloc(20*sizeof(char)); op2->x = (char *)malloc(20*sizeof(char)); op2->y = (char *)malloc(20*sizeof(char)); sprintf(op1->x, "%20f", offset); sprintf(op1->y, "%20f", 0.0); sprintf(op2->x, "%20f", 1.0); sprintf(op2->y, "%20f", emod); offset_line = (Line *)malloc(1*sizeof(Line)); offset_line->p1 = op1; offset_line->p2 = op2; line_segment = (Line *)malloc(1*sizeof(Line)); line_segment->p1 = (Point *)malloc(1*sizeof(Point)); line_segment->p2 = (Point *)malloc(1*sizeof(Point)); line_segment->p1->x = (char *)malloc(20*sizeof(char)); line_segment->p1->y = (char *)malloc(20*sizeof(char)); line_segment->p2->x = (char *)malloc(20*sizeof(char)); line_segment->p2->y = (char *)malloc(20*sizeof(char)); for(i=0; ip1->x = TSS[i].x; line_segment->p1->y = TSS[i].y; line_segment->p2->x = TSS[i+1].x; line_segment->p2->y = TSS[i+1].y; ipoint = getLineIntersection(line_segment, offset_line); if( ipoint ) { fprintf(stderr," Yield is %f\n", atof(ipoint->y)); return atof(ipoint->y); } } return 0.0; } Point *getLineIntersection(Line *line1, Line *line2) { Point *ipoint = NULL; float denom=0.0, num1=0.0, num2=0.0; float x1=0, y1=0, x2=0, y2=0, x3=0, y3=0, x4=0, y4=0, ua=0, ub=0; x1 = atof(line1->p1->x); y1 = atof(line1->p1->y); x2 = atof(line1->p2->x); y2 = atof(line1->p2->y); x3 = atof(line2->p1->x); y3 = atof(line2->p1->y); x4 = atof(line2->p2->x); y4 = atof(line2->p2->y); denom = (float) (y4-y3)*(x2-x1)-(x4-x3)*(y2-y1); num1 = (float) (x4-x3)*(y1-y3)-(y4-y3)*(x1-x3); num2 = (float) (x2-x1)*(y1-y3)-(y2-y1)*(x1-x3); if( denom==0 ) return NULL; if( num1==0 || num2==0 ) return NULL; ua = num1/denom; ub = num2/denom; if( ua>0 && ua<1 && ub>0 && ub<1 ) { ipoint = (Point *)malloc(1*sizeof(Point)); ipoint->x = (char *)malloc(20*sizeof(char)); ipoint->y = (char *)malloc(20*sizeof(char)); sprintf(ipoint->x, "%20f", atof(line1->p1->x) + (num1/denom)*(atof(line1->p2->x)-atof(line1->p1->x))); sprintf(ipoint->y, "%20f", atof(line1->p1->y) + (num1/denom)*(atof(line1->p2->y)-atof(line1->p1->y))); } return ipoint; }