SlideShare a Scribd company logo
>> IN THE NAME OF GOD <
Geometric Nonlinearity Analysis of Springs with Rigid Element Displacement Control
Large Deformation Formulated in C programming
C program is written by Salar Delavar Ghashghaei – Publication Date: 18/November/2019
E-mail: salar.d.ghashghaei@gmail.com
-4.00E+03
-3.00E+03
-2.00E+03
-1.00E+03
0.00E+00
1.00E+03
2.00E+03
3.00E+03
4.00E+03
0.00E+00 2.00E+01 4.00E+01 6.00E+01 8.00E+01 1.00E+02 1.20E+02
BaseShear
Displacement
Geometric and Material Nonlinearity Analysis of Springs
C Code:#include <stdio.h>
#include <windows.h> // text color
#include <conio.h>
#define N 10000
#define S01 " >> IN THE NAME OF GOD << "
#define S02 " Geometric and Material Nonlinearity Analysis of Springs with Displacement Control "
#define S03 " UNIT: Free Unit "
#define S04 " This program is written by Salar Delavar Ghashghaei "
#define S05 " E-mail: salar.d.ghashghaei@gmail.com "
#define ShowText01 "ConnectionProblemDCStrain-inputDATA.csv"
#define ShowText02 "ConnectionProblemDCStrain-inputSPRING.csv"
#define ShowText03 "ConnectionProblemDCStrain-outputEXCEL.csv"
#define ShowText04 "ConnectionProblemDCStrain-outputMATLAB.m"
void IMPORT_DATA01(double Import_Data[]);
void IMPORT_DATA02(double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int &k);
void MessageNegative_IMPORT_DATA01(double Import_Data[]);
void MessageNegative_IMPORT_DATA02(double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int n);
void MessageInputDataTEXT();
void MessageAnalysisReportTEXT();
void MessageErrorReportTEXT();
void MessageInitialData(double Import_Data[],int n);
void MessageStrainStressTEXT(double STARIN01[],double STRESS01[],double STARIN02[],double STRESS02[],int n);
void textcolor(int ForgC);
void Distance(int i);
void Element_Slope(double A[],double B[],double C[],int n);
void Element_Stiffness(double A[],double B[],double C[],double D[],double E[],double F[],double K[],int n,int m);
void ANALYSIS(double Import_Data[],double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int n,int m);
void OUTPUT_excel(double A[],double B[],int n);
void OUTPUT_matlab(double A[],double B[],int n);
double ABS(double B);
double Horizental_Disp(double L,double &x,double y);
double SQRT2(double D);
int main(){
int k;
double Import_Data[10];
double STRAIN01[10];
double STRESS01[10];
double STRAIN02[10];
double STRESS02[10];
IMPORT_DATA01(Import_Data);
MessageNegative_IMPORT_DATA01(Import_Data);
IMPORT_DATA02(STRAIN01,STRESS01,STRAIN02,STRESS02,k);
MessageNegative_IMPORT_DATA02(STRAIN01,STRESS01,STRAIN02,STRESS02,k);
int m = 1 + ABS(Import_Data[9]/Import_Data[7]);
textcolor(10);
MessageInitialData(Import_Data,m);
MessageStrainStressTEXT(STRAIN01,STRESS01,STRAIN02,STRESS02,k);
textcolor(14);
ANALYSIS(Import_Data,STRAIN01,STRESS01,STRAIN02,STRESS02,k,m);
getch();
return 0;
}
void IMPORT_DATA01(double Import_Data[]){
int i=0;
FILE *InputFile;
InputFile = fopen(ShowText01, "r");
if (!InputFile){
MessageErrorReportTEXT();
printf(" File is not available! -> [%s] n",ShowText01);
Sleep(6000);
exit(1);
}
char line[100],a[100];
while(i < N && fgets(line,sizeof(line),InputFile) != NULL){
sscanf(line,"%s",a);
//printf("a[%d]: %sn",i,a);
Import_Data[i]= atof(a);
i++;
}
}
void IMPORT_DATA02(double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int &k){
int i = 0;
FILE *InputFile;
InputFile = fopen(ShowText02, "r");
if (!InputFile){
MessageErrorReportTEXT();
printf(" File is not available! -> [%s] n",ShowText02);
Sleep(6000);
exit(1);
}
char line[1000];
do{
fscanf(InputFile,"%lf,%lf,%lf,%lf",&STRAIN01[i],&STRESS01[i],&STRAIN02[i],&STRESS02[i]);
//printf("%d - STRAIN01[%d]: %lf - STRESS01[%d]: %lf- STRAIN02[%d]: %lf - STRESS02[%d]: %lfn",i,i,STRAIN01[i],i,STRESS01[i],i,STRAIN02[i],i,STRESS02[i]);
i++;
}
while(i < N && fgets(line,sizeof(line),InputFile) != NULL);
k = i-1;
//printf("%dn",k);
}
void MessageNegative_IMPORT_DATA01(double Import_Data[]){
if ( Import_Data[0] < 0 || Import_Data[1] < 0 || Import_Data[2] < 0 || Import_Data[3] < 0 || Import_Data[4] < 0 || Import_Data[9] < 0){
MessageErrorReportTEXT();
printf(" Please check this file! -> [%s]n",ShowText01);
printf(" *** Negative data input value is not acceptable ***n");
printf(" Length of rigid element: %fn",Import_Data[0]);
printf(" Spring length 1: %fn",Import_Data[1]);
printf(" Spring length 2: %fn",Import_Data[2]);
printf(" Spring area 1: %fn",Import_Data[3]);
printf(" Spring area 2: %fn",Import_Data[4]);
printf(" External applied load in spring 1: %fn",Import_Data[5]);
printf(" External applied load in spring 2: %fn",Import_Data[6]);
printf(" Initial applied displacement: %fn",Import_Data[7]);
printf(" Distance of spring 1 from rigid element: %fn",Import_Data[8]);
printf(" Ultimate absolute displacement: %fn",Import_Data[9]);
Sleep(40000);
exit(1);
}
}
void MessageNegative_IMPORT_DATA02(double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int n){
int i;
for (i=0;i<n+1;i++){
if ( STRAIN01[i] < 0 || STRESS01[i] < 0 || STRAIN02[i] < 0 || STRESS02[i] < 0 ){
MessageErrorReportTEXT();
printf(" Please check this file! -> [%s]n",ShowText02);
printf(" Row %d has a negative value.n",i);
printf(" *** Negative data input value is not acceptable ***n");
printf(" Strain of spring 1: %fn",STRAIN01[i]);
printf(" Stress of spring 1: %fn",STRESS01[i]);
printf(" Strian of spring 2: %fn",STRAIN02[i]);
printf(" Stress of spring 2: %fn",STRESS02[i]);
Sleep(40000);
exit(1);
}
}
}
void textcolor(int ForgC){
WORD wColor;
//This handle is needed to get the current background attribute
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
//csbi is used for wAttributes word
if(GetConsoleScreenBufferInfo(hStdOut, &csbi)){
//To mask out all but the background attribute, and to add the color
wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
SetConsoleTextAttribute(hStdOut, wColor);
}
return;
}
void MessageErrorReportTEXT(){
int i;
char Ql;
Ql=176;
textcolor(12);
printf("an ");
for (i=1;i<50;i++)
printf("%c",Ql);
printf(" Error Report ");
for (i=1;i<50;i++)
printf("%c",Ql);
printf("n");
}
void MessageInputDataTEXT(){
int i;
char Ql=176;
printf("n ");
for (i=1;i<50;i++)
printf("%c",Ql);
printf(" Input Data ");
for (i=1;i<50;i++)
printf("%c",Ql);
printf("n");
}
void MessageAnalysisReportTEXT(){
int i;
char Ql=176;
printf("n ");
for (i=1;i<47;i++)
printf("%c",Ql);
printf(" Analysis Report ");
for (i=1;i<47;i++)
printf("%c",Ql);
printf("n");
printf("nt ");
for (i=1;i<72;i++)
printf("-");
printf("n");
printf("t Increment Base Shear Incremental Displacement[DOF(1)] n");
printf("t ");
for (i=1;i<72;i++)
printf("-");
printf("n");
}
void Distance(int i){
if (i < 10)
printf("b");
if (i >= 10 && i <= 99)
printf("btb");
if (i >= 100 && i <= 999)
printf("btbb");
if (i >= 1000 && i <= 9999)
printf("btbbb");
if (i >= 10000 && i <= 20000)
printf("btbbbb");
}
double ABS(double B){
if (B < 0)
B = -B;//Absolute number
else
B = B;
return B;
}
void Element_Slope(double A[],double B[],double C[],int n){
int i;
C[0]=B[0]/A[0];
//printf("%d - Rk[%d]: %fn",0,0,C[0]);
for (i=1;i<n;i++){
//cout<<i<<" - TET["<<i<<"]:"<<A[i]<<" - MOM["<<i<<"]:"<<B[i]<<endl;
C[i]=(B[i]-B[i-1])/(A[i]-A[i-1]);
//printf("%d - Strain[%d]: %f - Stress[%d]: %f - Rk[%d]: %fn",i,i,A[i],i,B[i],i,C[i]);
}
}
void Element_Stiffness(double A[],double B[],double C[],double D[],double E[],double F[],double K[],int n,int m){
int i;
if (ABS(D[n])>= 0 && ABS(D[n])<= A[0])
K[n] = (C[n]*E[n])/F[n];
for (i=0;i<m;i++){
if (ABS(D[n])> A[i] && ABS(D[n])<= A[i+1])
K[n] = ((B[i]+C[i+1]*(ABS(D[n])-A[i]))/ABS(D[n]))*E[n]/F[n];
}
if (ABS(D[n]) > A[m-1])
K[n] = 0;
}
void ANALYSIS(double Import_Data[],double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int n,int m){
double L,Dx,a=0,Le[2],Area[2],Force[2],es[2],K[2],SLOPE01[10],SLOPE02[10],Dini,Dmax,Du,up;
int z,zMAX,well_done=0;
double output_u[N],output_base[N];
L = Import_Data[0];
Le[0] = Import_Data[1];
Le[1] = Import_Data[2];
Area[0] = Import_Data[3];
Area[1] = Import_Data[4];
Force[0] = Import_Data[5];
Force[1] = Import_Data[6];
Dini = Import_Data[7];
Du = Import_Data[8];
Dmax = Import_Data[9];
double F[2],Ay;
Element_Slope(STRAIN01,STRESS01,SLOPE01,n);
Element_Slope(STRAIN02,STRESS02,SLOPE02,n);
MessageAnalysisReportTEXT();
for (z=0;z<m;z++){
up = Dini*(z+1);// Define the applied Displacement
Horizental_Disp(L,Dx,up);
a = SQRT2(.5*up*.5*up + .5*Dx*.5*Dx);// spring strain 1 during analysis
es[0] = a/Le[0];
Element_Stiffness(STRAIN01,STRESS02,SLOPE01,es,Area,Le,K,0,n);
F[0] = (((L-Dx)/L)*((L-Dx)/L))*K[0]*0.5*up + Import_Data[5];
Ay = F[0];
//printf("t+ %f - %fn",es[0],F[0]);
if (ABS(up) >= Du){
es[1] = (Du-up)/Le[1];
Element_Stiffness(STRAIN02,STRESS02,SLOPE02,es,Area,Le,K,1,n);
F[1] = (((L-Dx)/L)*((L-Dx)/L))*K[1]*(Du-up) + Import_Data[6];
Ay = F[0] + F[1];
//printf("t= %f - %fn",es[1],F[1]);
}
//printf("t %f - %fn",up,Dx);
zMAX=z+1;
output_u[z]=up;
output_base[z]=Ay;
Distance(z);
printf("tt%dtt%ett%en",z+1,output_base[z],output_u[z]);
if (ABS(up) >= Dmax){
well_done = 1;
textcolor(13);
printf("ntt ## Increment displacement reach to ultimate displacement ##nn");
break;
}
}// for
if (well_done == 1){
OUTPUT_excel(output_u,output_base,zMAX);
OUTPUT_matlab(output_u,output_base,zMAX);
textcolor(15);
printf("na - Output data is written in Excel and Matlab file -");
}
}
void OUTPUT_matlab(double A[],double B[],int n){
// MATLAB OUTPUT
int i;
FILE *OutputFile;
OutputFile = fopen(ShowText04, "w");
fprintf(OutputFile," %% Geometric and Material Nonlinearity Analysis of Springs with Displacement Control %%n");
fprintf(OutputFile,"disp_Dof1=[0n");
for(i=0;i<=n;i++)
fprintf(OutputFile,"%en",A[i]);
fprintf(OutputFile,"];nn");
fprintf(OutputFile,"base_shear=[0n");
for(i=0;i<=n;i++)
fprintf(OutputFile,"%en",B[i]);
fprintf(OutputFile,"];nn");
fprintf(OutputFile,"figure(1)n");
fprintf(OutputFile,"plot(disp_Dof1,base_shear,'LineWidth',3);n");
fprintf(OutputFile,"title(['# BASE SHEAR - DISPLACEMENT DIAGRAM #'],'Color','b');n");
fprintf(OutputFile,"xlabel('DISPLACEMENT [DOF(1)]');ylabel('BASE SHEAR');grid on;n");
fclose(OutputFile);
}
void OUTPUT_excel(double A[],double B[],int n){
// EXCEL OUTPUT
int i;
FILE *OutputFile;
OutputFile = fopen(ShowText03, "w");
fprintf(OutputFile," ### Geometric and Material Nonlinearity Analysis of Springs with Displacement Control ###n");
fprintf(OutputFile,"Increment,Displacement [DOF(1)],Base Shear[DOF(1)]n");
for(i=0;i<n;i++)
fprintf(OutputFile,"%d,%e,%en",i+1,A[i],B[i]);
fclose(OutputFile);
}
void MessageInitialData(double Import_Data[],int n){
char Qa,Qb,Qc,Qd,Qe,Qf,Qg,Qk;
int i;
Qa=201;Qb=205;Qc=187;Qd=200;Qe=188,Qf=186,Qg=204,Qk=185;
printf("tttt%c",Qa);
for (i=1;i<84;i++)
printf("%c",Qb);
printf("%cn",Qc);
printf("tttt%c%s%cn",Qf,S01,Qf);
printf("tttt%c%s%cn",Qf,S02,Qf);
printf("tttt%c%s%cn",Qf,S03,Qf);
printf("tttt%c",Qg);
for (i=1;i<84;i++)
printf("%c",Qb);
printf("%cn",Qk);
printf("tttt%c%s%cn",Qf,S04,Qf);
printf("tttt%c%s%cn",Qf,S05,Qf);
printf("tttt%c",Qd);
for (i=1;i<84;i++)
printf("%c",Qb);
printf("%cn",Qe);
MessageInputDataTEXT();
printf("t Length of rigid element: %fn",Import_Data[0]);
printf("t Spring length 1: %fn",Import_Data[1]);
printf("t Spring length 2: %fn",Import_Data[2]);
printf("t Spring area 1: %fn",Import_Data[3]);
printf("t Spring area 2: %fn",Import_Data[4]);
printf("t External applied load in spring 1: %fn",Import_Data[5]);
printf("t External applied load in spring 2: %fn",Import_Data[6]);
printf("t Initial applied displacement: %fn",Import_Data[7]);
printf("t Distance of spring 1 from rigid element: %fn",Import_Data[8]);
printf("t Ultimate absolute displacement: %fn",Import_Data[9]);
printf("t Number of increments: %dn",n);
}
void MessageStrainStressTEXT(double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int n){
int i;
char Qa,Qb,Qc,Qd,Qe,Qf;
int BB=201,CC=205,DD=187,EE=200,FF=188,GG=186;
Qa=BB;Qb=CC;Qc=DD;Qd=EE;Qe=FF;Qf=GG;
printf(" %c",Qa);
for (i=1;i<77;i++)
printf("%c",Qb);
printf("%cn",Qc);
printf(" %c Spring 1 | Spring 2 %cn",Qf,Qf);
printf(" %c Strain Stress | Strain Stress %cn",Qf,Qf);
printf(" %c",Qd);
for (i=1;i<77;i++)
printf("%c",Qb);
printf("%cn",Qe);
for(i=0;i<n;i++)
printf(" %e %e %e %en",STRAIN01[i],STRESS01[i],STRAIN02[i],STRESS02[i]);
}
double Horizental_Disp(double L,double &x,double y){
int it,itermax;
double residual,tolerance,dx,dx_ABS,f,df;
it = 0; // initialize iteration count
itermax = 100000;
residual = 100; // initialize residual
tolerance = 1e-12;
x = 1;// initialize answer
while (residual > tolerance){
f = x*x + y*y - 2*L*x;
df = 2*x - 2*L;
dx = f/df;
x -= dx;
residual = ABS(dx); // abs residual
it = it + 1; // increment iteration count
//printf("f: %f -tdx: %f -tresidual: %fn",f,dx,residual);
if (it == itermax){
printf("tSQRT2(number,power) : SQRT2(%f) - iteration: %d -> ## The solution is not converged ##n",y,it);
break;
}
}
if (it < itermax){
//printf("tSQRT(number,power) - SQRT(%f,%f) : %f n",D,n, x);
return x;
}
}
double SQRT2(double D){
int it,itermax;
double residual,tolerance,x,dx,dx_ABS,f,df;
it = 0; // initialize iteration count
itermax = 100000;
residual = 100; // initialize residual
tolerance = 1e-8;
x = 1;// initialize answer
while (residual > tolerance){
f = x*x - D;
df = 2 * x;
dx = f/df;
x -= dx;
residual = ABS(dx); // abs residual
it += 1; // increment iteration count
//printf("f: %f -tdx: %f -tresidual: %fn",f,dx,residual);
if (it == itermax){
printf("tSQRT2(number,power) : SQRT2(%f) - iteration: %d -> ## The solution is not converged ##n",D,it);
break;
}
}
if (it < itermax){
//printf("tSQRT(number,power) - SQRT(%f,%f) : %f n",D,n, x);
return x;
}
}
Plot :
Figure(1) Analysis file
Figure(2) Input csv file
Figure(3) Input Strain-Stress properties csv file
Figure(4) Output csv file

More Related Content

What's hot (20)

DOCX
DAA Lab File C Programs
Kandarp Tiwari
 
PDF
design and analysis of algorithm Lab files
Nitesh Dubey
 
PDF
Cn os-lp lab manual k.roshan
riturajj
 
DOCX
Os lab file c programs
Kandarp Tiwari
 
PDF
c-programming-using-pointers
Sushil Mishra
 
PDF
Nonlinear analysis of frame with hinge by hinge method in c programming
Salar Delavar Qashqai
 
PDF
C programs
Vikram Nandini
 
PDF
C program
Komal Singh
 
DOCX
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
Anushka Rai
 
PDF
Cpd lecture im 207
Syed Tanveer
 
TXT
c++ program for Railway reservation
Swarup Kumar Boro
 
PDF
C programms
Mukund Gandrakota
 
PDF
C lab excellent
Srinivas Reddy Amedapu
 
DOCX
Cpds lab
praveennallavelly08
 
DOC
Basic c programs updated on 31.8.2020
vrgokila
 
PDF
programs
Vishnu V
 
DOCX
SaraPIC
Sara Sahu
 
PPTX
Arrays
mohamed sikander
 
DAA Lab File C Programs
Kandarp Tiwari
 
design and analysis of algorithm Lab files
Nitesh Dubey
 
Cn os-lp lab manual k.roshan
riturajj
 
Os lab file c programs
Kandarp Tiwari
 
c-programming-using-pointers
Sushil Mishra
 
Nonlinear analysis of frame with hinge by hinge method in c programming
Salar Delavar Qashqai
 
C programs
Vikram Nandini
 
C program
Komal Singh
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
Anushka Rai
 
Cpd lecture im 207
Syed Tanveer
 
c++ program for Railway reservation
Swarup Kumar Boro
 
C programms
Mukund Gandrakota
 
C lab excellent
Srinivas Reddy Amedapu
 
Basic c programs updated on 31.8.2020
vrgokila
 
programs
Vishnu V
 
SaraPIC
Sara Sahu
 

Similar to Geometric nonlinearity analysis of springs with rigid element displacement control large deformation formulated in c programming (20)

DOCX
Chapter 8 c solution
Azhar Javed
 
PDF
Data Structure in C Programming Language
Arkadeep Dey
 
DOCX
ADA FILE
Gaurav Singh
 
PPTX
Array matrix example programs - C language
Sk_Group
 
PPT
array.ppt
DeveshDewangan5
 
DOC
'C' language notes (a.p)
Ashishchinu
 
DOCX
C programs
Azaj Khan
 
DOCX
C Programming
Sumant Diwakar
 
PDF
Mcs 011 solved assignment 2015-16
Indira Gnadhi National Open University (IGNOU)
 
DOCX
C lab manaual
manoj11manu
 
PDF
C and Data Structures
Srinivas Reddy Amedapu
 
PDF
C and Data Structures Lab Solutions
Srinivas Reddy Amedapu
 
DOCX
Lab. Programs in C
Saket Pathak
 
PDF
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu
 
PDF
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu
 
PDF
2Darrays.pdf. data structure using c programming
maha280307
 
PDF
The solution manual of c by robin
Abdullah Al Naser
 
PDF
DSC program.pdf
Prof. Dr. K. Adisesha
 
PDF
C Programming lab
Vikram Nandini
 
DOC
C basics
MSc CST
 
Chapter 8 c solution
Azhar Javed
 
Data Structure in C Programming Language
Arkadeep Dey
 
ADA FILE
Gaurav Singh
 
Array matrix example programs - C language
Sk_Group
 
array.ppt
DeveshDewangan5
 
'C' language notes (a.p)
Ashishchinu
 
C programs
Azaj Khan
 
C Programming
Sumant Diwakar
 
Mcs 011 solved assignment 2015-16
Indira Gnadhi National Open University (IGNOU)
 
C lab manaual
manoj11manu
 
C and Data Structures
Srinivas Reddy Amedapu
 
C and Data Structures Lab Solutions
Srinivas Reddy Amedapu
 
Lab. Programs in C
Saket Pathak
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu
 
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu
 
2Darrays.pdf. data structure using c programming
maha280307
 
The solution manual of c by robin
Abdullah Al Naser
 
DSC program.pdf
Prof. Dr. K. Adisesha
 
C Programming lab
Vikram Nandini
 
C basics
MSc CST
 
Ad

More from Salar Delavar Qashqai (20)

PDF
Pushover 2order (p delta effect) analysis force analogy method with force con...
Salar Delavar Qashqai
 
PDF
Pushover analysis of frame by force analogy method with force control based o...
Salar Delavar Qashqai
 
PDF
Truss optimization with excel solver
Salar Delavar Qashqai
 
PDF
Pushover analysis of triangular steel membrane element subjected to lateral d...
Salar Delavar Qashqai
 
PDF
Pushover analysis of simply support steel section beam based on plastic hinge...
Salar Delavar Qashqai
 
PDF
Pushover analysis of steel section beam subjected to incremental vertical loa...
Salar Delavar Qashqai
 
PDF
Moment curvature analysis of unconfined concrete section with matlab and sap2000
Salar Delavar Qashqai
 
PDF
Large deformation analysis of cantilever beam subjected to concentrated const...
Salar Delavar Qashqai
 
PDF
Moment curvature analysis unconfined concrete section with different tension...
Salar Delavar Qashqai
 
PDF
Optimization of steel section based on moment and section ductility
Salar Delavar Qashqai
 
PDF
Nonlinear analysis of 2 d cantilever nonprismatic beam with plastic hinge con...
Salar Delavar Qashqai
 
PDF
Import data from csv excel file and export to xml excel file in c programming
Salar Delavar Qashqai
 
PDF
Elastic response pseudo spectrum in c programming
Salar Delavar Qashqai
 
PDF
Structural eigen value analysis in c programming
Salar Delavar Qashqai
 
PDF
Analysis of 1st order and 2nd order nonlinear semi rigid connection braced fr...
Salar Delavar Qashqai
 
PDF
Analysis of 1st order and 2nd order nonlinear semi rigid connection frame sub...
Salar Delavar Qashqai
 
PDF
Moment curvature analysis confined concrete section in matlab
Salar Delavar Qashqai
 
PDF
Moment curvature analysis of unconfined circular concrete pipe section with m...
Salar Delavar Qashqai
 
PDF
1st order pushover analysis of column subjected to compression and tension ax...
Salar Delavar Qashqai
 
PDF
Pushover analysis of steel section beam with semi rigid connection in matlab ...
Salar Delavar Qashqai
 
Pushover 2order (p delta effect) analysis force analogy method with force con...
Salar Delavar Qashqai
 
Pushover analysis of frame by force analogy method with force control based o...
Salar Delavar Qashqai
 
Truss optimization with excel solver
Salar Delavar Qashqai
 
Pushover analysis of triangular steel membrane element subjected to lateral d...
Salar Delavar Qashqai
 
Pushover analysis of simply support steel section beam based on plastic hinge...
Salar Delavar Qashqai
 
Pushover analysis of steel section beam subjected to incremental vertical loa...
Salar Delavar Qashqai
 
Moment curvature analysis of unconfined concrete section with matlab and sap2000
Salar Delavar Qashqai
 
Large deformation analysis of cantilever beam subjected to concentrated const...
Salar Delavar Qashqai
 
Moment curvature analysis unconfined concrete section with different tension...
Salar Delavar Qashqai
 
Optimization of steel section based on moment and section ductility
Salar Delavar Qashqai
 
Nonlinear analysis of 2 d cantilever nonprismatic beam with plastic hinge con...
Salar Delavar Qashqai
 
Import data from csv excel file and export to xml excel file in c programming
Salar Delavar Qashqai
 
Elastic response pseudo spectrum in c programming
Salar Delavar Qashqai
 
Structural eigen value analysis in c programming
Salar Delavar Qashqai
 
Analysis of 1st order and 2nd order nonlinear semi rigid connection braced fr...
Salar Delavar Qashqai
 
Analysis of 1st order and 2nd order nonlinear semi rigid connection frame sub...
Salar Delavar Qashqai
 
Moment curvature analysis confined concrete section in matlab
Salar Delavar Qashqai
 
Moment curvature analysis of unconfined circular concrete pipe section with m...
Salar Delavar Qashqai
 
1st order pushover analysis of column subjected to compression and tension ax...
Salar Delavar Qashqai
 
Pushover analysis of steel section beam with semi rigid connection in matlab ...
Salar Delavar Qashqai
 
Ad

Recently uploaded (20)

PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PDF
smart lot access control system with eye
rasabzahra
 
PPTX
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPT
Electrical Safety Presentation for Basics Learning
AliJaved79382
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
smart lot access control system with eye
rasabzahra
 
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
Thermal runway and thermal stability.pptx
godow93766
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Electrical Safety Presentation for Basics Learning
AliJaved79382
 

Geometric nonlinearity analysis of springs with rigid element displacement control large deformation formulated in c programming

  • 1. >> IN THE NAME OF GOD < Geometric Nonlinearity Analysis of Springs with Rigid Element Displacement Control Large Deformation Formulated in C programming C program is written by Salar Delavar Ghashghaei – Publication Date: 18/November/2019 E-mail: [email protected] -4.00E+03 -3.00E+03 -2.00E+03 -1.00E+03 0.00E+00 1.00E+03 2.00E+03 3.00E+03 4.00E+03 0.00E+00 2.00E+01 4.00E+01 6.00E+01 8.00E+01 1.00E+02 1.20E+02 BaseShear Displacement Geometric and Material Nonlinearity Analysis of Springs
  • 2. C Code:#include <stdio.h> #include <windows.h> // text color #include <conio.h> #define N 10000 #define S01 " >> IN THE NAME OF GOD << " #define S02 " Geometric and Material Nonlinearity Analysis of Springs with Displacement Control " #define S03 " UNIT: Free Unit " #define S04 " This program is written by Salar Delavar Ghashghaei " #define S05 " E-mail: [email protected] " #define ShowText01 "ConnectionProblemDCStrain-inputDATA.csv" #define ShowText02 "ConnectionProblemDCStrain-inputSPRING.csv" #define ShowText03 "ConnectionProblemDCStrain-outputEXCEL.csv" #define ShowText04 "ConnectionProblemDCStrain-outputMATLAB.m" void IMPORT_DATA01(double Import_Data[]); void IMPORT_DATA02(double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int &k); void MessageNegative_IMPORT_DATA01(double Import_Data[]); void MessageNegative_IMPORT_DATA02(double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int n); void MessageInputDataTEXT(); void MessageAnalysisReportTEXT(); void MessageErrorReportTEXT(); void MessageInitialData(double Import_Data[],int n); void MessageStrainStressTEXT(double STARIN01[],double STRESS01[],double STARIN02[],double STRESS02[],int n); void textcolor(int ForgC); void Distance(int i); void Element_Slope(double A[],double B[],double C[],int n); void Element_Stiffness(double A[],double B[],double C[],double D[],double E[],double F[],double K[],int n,int m); void ANALYSIS(double Import_Data[],double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int n,int m); void OUTPUT_excel(double A[],double B[],int n); void OUTPUT_matlab(double A[],double B[],int n); double ABS(double B); double Horizental_Disp(double L,double &x,double y); double SQRT2(double D); int main(){ int k; double Import_Data[10]; double STRAIN01[10]; double STRESS01[10]; double STRAIN02[10]; double STRESS02[10]; IMPORT_DATA01(Import_Data); MessageNegative_IMPORT_DATA01(Import_Data); IMPORT_DATA02(STRAIN01,STRESS01,STRAIN02,STRESS02,k); MessageNegative_IMPORT_DATA02(STRAIN01,STRESS01,STRAIN02,STRESS02,k); int m = 1 + ABS(Import_Data[9]/Import_Data[7]); textcolor(10); MessageInitialData(Import_Data,m); MessageStrainStressTEXT(STRAIN01,STRESS01,STRAIN02,STRESS02,k); textcolor(14); ANALYSIS(Import_Data,STRAIN01,STRESS01,STRAIN02,STRESS02,k,m); getch(); return 0; } void IMPORT_DATA01(double Import_Data[]){ int i=0; FILE *InputFile; InputFile = fopen(ShowText01, "r"); if (!InputFile){ MessageErrorReportTEXT(); printf(" File is not available! -> [%s] n",ShowText01); Sleep(6000); exit(1); } char line[100],a[100]; while(i < N && fgets(line,sizeof(line),InputFile) != NULL){ sscanf(line,"%s",a); //printf("a[%d]: %sn",i,a); Import_Data[i]= atof(a); i++; } } void IMPORT_DATA02(double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int &k){ int i = 0; FILE *InputFile; InputFile = fopen(ShowText02, "r"); if (!InputFile){ MessageErrorReportTEXT(); printf(" File is not available! -> [%s] n",ShowText02); Sleep(6000); exit(1); } char line[1000]; do{ fscanf(InputFile,"%lf,%lf,%lf,%lf",&STRAIN01[i],&STRESS01[i],&STRAIN02[i],&STRESS02[i]); //printf("%d - STRAIN01[%d]: %lf - STRESS01[%d]: %lf- STRAIN02[%d]: %lf - STRESS02[%d]: %lfn",i,i,STRAIN01[i],i,STRESS01[i],i,STRAIN02[i],i,STRESS02[i]); i++; } while(i < N && fgets(line,sizeof(line),InputFile) != NULL); k = i-1; //printf("%dn",k); } void MessageNegative_IMPORT_DATA01(double Import_Data[]){ if ( Import_Data[0] < 0 || Import_Data[1] < 0 || Import_Data[2] < 0 || Import_Data[3] < 0 || Import_Data[4] < 0 || Import_Data[9] < 0){ MessageErrorReportTEXT(); printf(" Please check this file! -> [%s]n",ShowText01); printf(" *** Negative data input value is not acceptable ***n"); printf(" Length of rigid element: %fn",Import_Data[0]); printf(" Spring length 1: %fn",Import_Data[1]); printf(" Spring length 2: %fn",Import_Data[2]); printf(" Spring area 1: %fn",Import_Data[3]); printf(" Spring area 2: %fn",Import_Data[4]); printf(" External applied load in spring 1: %fn",Import_Data[5]); printf(" External applied load in spring 2: %fn",Import_Data[6]); printf(" Initial applied displacement: %fn",Import_Data[7]); printf(" Distance of spring 1 from rigid element: %fn",Import_Data[8]); printf(" Ultimate absolute displacement: %fn",Import_Data[9]); Sleep(40000); exit(1); } } void MessageNegative_IMPORT_DATA02(double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int n){ int i; for (i=0;i<n+1;i++){ if ( STRAIN01[i] < 0 || STRESS01[i] < 0 || STRAIN02[i] < 0 || STRESS02[i] < 0 ){ MessageErrorReportTEXT(); printf(" Please check this file! -> [%s]n",ShowText02); printf(" Row %d has a negative value.n",i); printf(" *** Negative data input value is not acceptable ***n"); printf(" Strain of spring 1: %fn",STRAIN01[i]); printf(" Stress of spring 1: %fn",STRESS01[i]); printf(" Strian of spring 2: %fn",STRAIN02[i]); printf(" Stress of spring 2: %fn",STRESS02[i]); Sleep(40000); exit(1); } } } void textcolor(int ForgC){ WORD wColor; //This handle is needed to get the current background attribute HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbi; //csbi is used for wAttributes word if(GetConsoleScreenBufferInfo(hStdOut, &csbi)){ //To mask out all but the background attribute, and to add the color wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F); SetConsoleTextAttribute(hStdOut, wColor); } return; } void MessageErrorReportTEXT(){ int i; char Ql; Ql=176; textcolor(12); printf("an "); for (i=1;i<50;i++) printf("%c",Ql); printf(" Error Report "); for (i=1;i<50;i++) printf("%c",Ql); printf("n"); } void MessageInputDataTEXT(){ int i; char Ql=176; printf("n "); for (i=1;i<50;i++) printf("%c",Ql); printf(" Input Data "); for (i=1;i<50;i++) printf("%c",Ql); printf("n"); } void MessageAnalysisReportTEXT(){ int i; char Ql=176; printf("n "); for (i=1;i<47;i++) printf("%c",Ql); printf(" Analysis Report "); for (i=1;i<47;i++) printf("%c",Ql); printf("n"); printf("nt "); for (i=1;i<72;i++) printf("-"); printf("n"); printf("t Increment Base Shear Incremental Displacement[DOF(1)] n"); printf("t "); for (i=1;i<72;i++) printf("-"); printf("n"); } void Distance(int i){ if (i < 10) printf("b"); if (i >= 10 && i <= 99) printf("btb"); if (i >= 100 && i <= 999) printf("btbb"); if (i >= 1000 && i <= 9999) printf("btbbb"); if (i >= 10000 && i <= 20000) printf("btbbbb"); } double ABS(double B){ if (B < 0) B = -B;//Absolute number else B = B; return B; } void Element_Slope(double A[],double B[],double C[],int n){ int i; C[0]=B[0]/A[0]; //printf("%d - Rk[%d]: %fn",0,0,C[0]); for (i=1;i<n;i++){ //cout<<i<<" - TET["<<i<<"]:"<<A[i]<<" - MOM["<<i<<"]:"<<B[i]<<endl; C[i]=(B[i]-B[i-1])/(A[i]-A[i-1]); //printf("%d - Strain[%d]: %f - Stress[%d]: %f - Rk[%d]: %fn",i,i,A[i],i,B[i],i,C[i]); } } void Element_Stiffness(double A[],double B[],double C[],double D[],double E[],double F[],double K[],int n,int m){ int i; if (ABS(D[n])>= 0 && ABS(D[n])<= A[0]) K[n] = (C[n]*E[n])/F[n]; for (i=0;i<m;i++){ if (ABS(D[n])> A[i] && ABS(D[n])<= A[i+1]) K[n] = ((B[i]+C[i+1]*(ABS(D[n])-A[i]))/ABS(D[n]))*E[n]/F[n]; } if (ABS(D[n]) > A[m-1]) K[n] = 0; } void ANALYSIS(double Import_Data[],double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int n,int m){ double L,Dx,a=0,Le[2],Area[2],Force[2],es[2],K[2],SLOPE01[10],SLOPE02[10],Dini,Dmax,Du,up; int z,zMAX,well_done=0; double output_u[N],output_base[N]; L = Import_Data[0]; Le[0] = Import_Data[1]; Le[1] = Import_Data[2]; Area[0] = Import_Data[3]; Area[1] = Import_Data[4]; Force[0] = Import_Data[5]; Force[1] = Import_Data[6]; Dini = Import_Data[7]; Du = Import_Data[8]; Dmax = Import_Data[9]; double F[2],Ay; Element_Slope(STRAIN01,STRESS01,SLOPE01,n); Element_Slope(STRAIN02,STRESS02,SLOPE02,n); MessageAnalysisReportTEXT(); for (z=0;z<m;z++){ up = Dini*(z+1);// Define the applied Displacement Horizental_Disp(L,Dx,up); a = SQRT2(.5*up*.5*up + .5*Dx*.5*Dx);// spring strain 1 during analysis es[0] = a/Le[0]; Element_Stiffness(STRAIN01,STRESS02,SLOPE01,es,Area,Le,K,0,n); F[0] = (((L-Dx)/L)*((L-Dx)/L))*K[0]*0.5*up + Import_Data[5]; Ay = F[0]; //printf("t+ %f - %fn",es[0],F[0]); if (ABS(up) >= Du){ es[1] = (Du-up)/Le[1]; Element_Stiffness(STRAIN02,STRESS02,SLOPE02,es,Area,Le,K,1,n); F[1] = (((L-Dx)/L)*((L-Dx)/L))*K[1]*(Du-up) + Import_Data[6]; Ay = F[0] + F[1]; //printf("t= %f - %fn",es[1],F[1]); } //printf("t %f - %fn",up,Dx); zMAX=z+1; output_u[z]=up; output_base[z]=Ay; Distance(z); printf("tt%dtt%ett%en",z+1,output_base[z],output_u[z]); if (ABS(up) >= Dmax){ well_done = 1; textcolor(13); printf("ntt ## Increment displacement reach to ultimate displacement ##nn"); break; } }// for if (well_done == 1){ OUTPUT_excel(output_u,output_base,zMAX); OUTPUT_matlab(output_u,output_base,zMAX); textcolor(15); printf("na - Output data is written in Excel and Matlab file -"); } } void OUTPUT_matlab(double A[],double B[],int n){ // MATLAB OUTPUT int i; FILE *OutputFile; OutputFile = fopen(ShowText04, "w"); fprintf(OutputFile," %% Geometric and Material Nonlinearity Analysis of Springs with Displacement Control %%n"); fprintf(OutputFile,"disp_Dof1=[0n"); for(i=0;i<=n;i++) fprintf(OutputFile,"%en",A[i]); fprintf(OutputFile,"];nn"); fprintf(OutputFile,"base_shear=[0n"); for(i=0;i<=n;i++) fprintf(OutputFile,"%en",B[i]); fprintf(OutputFile,"];nn"); fprintf(OutputFile,"figure(1)n"); fprintf(OutputFile,"plot(disp_Dof1,base_shear,'LineWidth',3);n"); fprintf(OutputFile,"title(['# BASE SHEAR - DISPLACEMENT DIAGRAM #'],'Color','b');n"); fprintf(OutputFile,"xlabel('DISPLACEMENT [DOF(1)]');ylabel('BASE SHEAR');grid on;n"); fclose(OutputFile); } void OUTPUT_excel(double A[],double B[],int n){ // EXCEL OUTPUT int i; FILE *OutputFile; OutputFile = fopen(ShowText03, "w"); fprintf(OutputFile," ### Geometric and Material Nonlinearity Analysis of Springs with Displacement Control ###n"); fprintf(OutputFile,"Increment,Displacement [DOF(1)],Base Shear[DOF(1)]n"); for(i=0;i<n;i++) fprintf(OutputFile,"%d,%e,%en",i+1,A[i],B[i]); fclose(OutputFile); } void MessageInitialData(double Import_Data[],int n){ char Qa,Qb,Qc,Qd,Qe,Qf,Qg,Qk; int i; Qa=201;Qb=205;Qc=187;Qd=200;Qe=188,Qf=186,Qg=204,Qk=185; printf("tttt%c",Qa); for (i=1;i<84;i++) printf("%c",Qb); printf("%cn",Qc); printf("tttt%c%s%cn",Qf,S01,Qf); printf("tttt%c%s%cn",Qf,S02,Qf); printf("tttt%c%s%cn",Qf,S03,Qf); printf("tttt%c",Qg); for (i=1;i<84;i++) printf("%c",Qb); printf("%cn",Qk); printf("tttt%c%s%cn",Qf,S04,Qf); printf("tttt%c%s%cn",Qf,S05,Qf); printf("tttt%c",Qd); for (i=1;i<84;i++) printf("%c",Qb); printf("%cn",Qe); MessageInputDataTEXT(); printf("t Length of rigid element: %fn",Import_Data[0]); printf("t Spring length 1: %fn",Import_Data[1]); printf("t Spring length 2: %fn",Import_Data[2]); printf("t Spring area 1: %fn",Import_Data[3]); printf("t Spring area 2: %fn",Import_Data[4]); printf("t External applied load in spring 1: %fn",Import_Data[5]); printf("t External applied load in spring 2: %fn",Import_Data[6]); printf("t Initial applied displacement: %fn",Import_Data[7]); printf("t Distance of spring 1 from rigid element: %fn",Import_Data[8]); printf("t Ultimate absolute displacement: %fn",Import_Data[9]); printf("t Number of increments: %dn",n); } void MessageStrainStressTEXT(double STRAIN01[],double STRESS01[],double STRAIN02[],double STRESS02[],int n){ int i; char Qa,Qb,Qc,Qd,Qe,Qf; int BB=201,CC=205,DD=187,EE=200,FF=188,GG=186; Qa=BB;Qb=CC;Qc=DD;Qd=EE;Qe=FF;Qf=GG; printf(" %c",Qa); for (i=1;i<77;i++) printf("%c",Qb); printf("%cn",Qc); printf(" %c Spring 1 | Spring 2 %cn",Qf,Qf); printf(" %c Strain Stress | Strain Stress %cn",Qf,Qf); printf(" %c",Qd); for (i=1;i<77;i++) printf("%c",Qb); printf("%cn",Qe); for(i=0;i<n;i++) printf(" %e %e %e %en",STRAIN01[i],STRESS01[i],STRAIN02[i],STRESS02[i]); } double Horizental_Disp(double L,double &x,double y){ int it,itermax; double residual,tolerance,dx,dx_ABS,f,df; it = 0; // initialize iteration count itermax = 100000; residual = 100; // initialize residual tolerance = 1e-12; x = 1;// initialize answer while (residual > tolerance){ f = x*x + y*y - 2*L*x; df = 2*x - 2*L; dx = f/df; x -= dx; residual = ABS(dx); // abs residual it = it + 1; // increment iteration count //printf("f: %f -tdx: %f -tresidual: %fn",f,dx,residual);
  • 3. if (it == itermax){ printf("tSQRT2(number,power) : SQRT2(%f) - iteration: %d -> ## The solution is not converged ##n",y,it); break; } } if (it < itermax){ //printf("tSQRT(number,power) - SQRT(%f,%f) : %f n",D,n, x); return x; } } double SQRT2(double D){ int it,itermax; double residual,tolerance,x,dx,dx_ABS,f,df; it = 0; // initialize iteration count itermax = 100000; residual = 100; // initialize residual tolerance = 1e-8; x = 1;// initialize answer while (residual > tolerance){ f = x*x - D; df = 2 * x; dx = f/df; x -= dx; residual = ABS(dx); // abs residual it += 1; // increment iteration count //printf("f: %f -tdx: %f -tresidual: %fn",f,dx,residual); if (it == itermax){ printf("tSQRT2(number,power) : SQRT2(%f) - iteration: %d -> ## The solution is not converged ##n",D,it); break; } } if (it < itermax){ //printf("tSQRT(number,power) - SQRT(%f,%f) : %f n",D,n, x); return x; } } Plot : Figure(1) Analysis file
  • 5. Figure(3) Input Strain-Stress properties csv file