gebt.h 8.61 KB
Newer Older
François Trigaux's avatar
François Trigaux committed
1

2

3
4
#ifndef _GEBT_H_
#define _GEBT_H_
5
6


François Trigaux's avatar
François Trigaux committed
7
8
9
10
11
12
13
14
15
16
17
18
#define NSTRN 6
#define NDIM 3
#define MEMB_CONST 7
#define NDOF_ND 12

#define CHKINP(r) if (r==-1){ printf("Error reading input file (line %d)\n",__LINE__); exit(EXIT_FAILURE);}
#define CHKFRMT(r,val) if (r!=val){ printf("Error formatting input file (line: %d)\n",__LINE__); exit(EXIT_FAILURE);}

#define ALLOCATE1(ptr,type,n1) ptr = (type*)malloc((n1)*sizeof(type)) 
#define ALLOCATE2(ptr,type,n1,n2) ptr = (type **)malloc((n1) * sizeof(type *)); \
                                  for (i_=0; i_<(n1); i_++){\
                                    ptr[i_] = (type *)malloc((n2) * sizeof(type));}
19
#define ALLOCATE3(ptr,type,n1,n2,n3) ptr = (type ***)malloc((n1) * sizeof(type **)); \
François Trigaux's avatar
François Trigaux committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
                                  for (i_=0; i_<(n1); i_++){\
                                    ptr[i_] = (type **)malloc((n2) * sizeof(type *));\
                                    for (j_=0; j_<(n2); j_++){\
                                        ptr[i_][j_] = (type *)malloc((n3) * sizeof(type));}}

#define DEALLOCATE1(ptr) free(ptr);

#define DEALLOCATE2(ptr,n1) for (i_=0; i_<(n1); i_++){\
                               free(ptr[i_]);}\
                            free(ptr);

#define DEALLOCATE3(ptr,n1,n2) for (i_=0; i_<(n1); i_++){\
                        for (j_=0; j_<(n2); j_++){\
                           free(ptr[i_][j_]);}\
                           free(ptr[i_]);}\
                           free(ptr);


#define READL(line,len,file) read = getline(&line,&len,file); CHKINP(read);\
                                    if(line==NULL){printf("Reached end of the file\n");return;}\
                                    while (line[0]=='\n' || line[0]=='\r' || line[0]=='#'){\
                                        read = getline(&line,&len,file); CHKINP(read);\
                                        if(line==NULL){printf("Reached end of the file\n");return;}\
                                    }

#define READ1(file,val,tag) READL(line,len,file)\
                        sscanf(line,#tag,&(val))

#define READ3(file,vec,tag) READL(line,len,file)\
                        sscanf(line,#tag #tag #tag,&vec[0],&vec[1],&vec[2])

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

#define RAVEL2(obj,VEC,nx,ny,type) type*  rav_##VEC = (type*) malloc(sizeof(type)*(nx)*(ny)); \
for (i_=0;i_<(nx);i_++){\
for (j_=0;j_<(ny);j_++){\
rav_##VEC[j_*(nx)+i_] = obj->VEC[i_][j_];\
}}

#define RAVEL3(obj,VEC,nx,ny,nz,type) type*  rav_##VEC = (type*) malloc(sizeof(type)*(nx)*(ny)*(nz)); \
for (i_=0;i_<(nx);i_++){\
for (j_=0;j_<(ny);j_++){\
for (k_=0;k_<(nz);k_++){\
rav_##VEC[k_*(nx)*(ny)+j_*(nx)+i_] = obj->VEC[i_][j_][k_];\
}}}

#define UNRAVEL2(obj,VEC,nx,ny,type)for (i_=0;i_<(nx);i_++){\
for (j_=0;j_<(ny);j_++){\
obj->VEC[i_][j_] = rav_##VEC[j_*(nx)+i_];\
}}\
free(rav_##VEC)

#define UNRAVEL3(obj,VEC,nx,ny,nz,type) for (i_=0;i_<(nx);i_++){\
for (j_=0;j_<(ny);j_++){\
for (k_=0;k_<(nz);k_++){\
obj->VEC[i_][j_][k_] = rav_##VEC[k_*(nx)*(ny)+j_*(nx)+i_];\
}}}\
free(rav_##VEC) 

78
extern int i_,j_,k_;
François Trigaux's avatar
François Trigaux committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142


struct PrescriInf{
	 int   id;                               // where it is applied, could be a node number or member number
	 int   dof[NSTRN];                       // maximum 6 degrees of freedom can be prescribed, 	                         
	                                         // for distributed loads, it is used to denote the distribution function no
     double value[NSTRN];                    // the magnitude of the prescribed values
	 int    time_fun_no[NSTRN];              // which time function is used
	 int follower[NSTRN];                    // whether the prescribed quantity is a follower or not: 1 is a follower; 0 is not
	 double value_current[NSTRN];            // indicate the current functional value updated by time steps, calculated internally
};

struct TimeFunction{
	 int fun_type;                           //unction type: 0, user defined; 1, harmonic
	 double ts, te;                          // starting and ending time
	 int entries;                            // number of entries
	 double *time_val;                       // the ith time, in increasing order; the amplitude of the harmonic
	 double *fun_val ;                       // the ith functional value; the period of the harmonic
	 double *phase_val;                      // the phase value of the harmonic
};





typedef struct
{
    // Declare all the variables required for the analysis
    int                nkp;
    int                nelem;             // number of elements
    int                ndof_el;           // number of unknowns for each element
    int                nmemb;             // number of beam members
    int                ncond_pt;          // number of point conditions
    int                nmate;             // number of different cross-sections
    int                nframe;            // number of different cross-sectional frames
    int                ndistrfun;         // number of distribution functions
    int                ncurv;             // number of sets of initial curvature/twists
    double             **coord;           // coordinates for key points
    int                **member;          // member desriptions
    struct PrescriInf  *pt_condition;     // prescribed concentrated infromation at points
    double             ***material;       // cross-sectional properties

    int                ntimefun;          // number of time functions 
    int                niter;             // maximum number of iterations
    int                nstep;             // number of time steps
    double             ***sol_pt;         // solutions for points
    double             ***sol_mb;         // solutions for members
    char               error[32];            // error message

    int                ncond_mb;         // number of prescribed distribution               			                		
    double             ***frame;          // the direction cosine matrix for each frame. The default frame is the global frame 
    struct PrescriInf  *mb_condition;     // distributed load information
    double             **distr_fun;       // distributed functions 
    double             **curvature;       // curvature information
    double             omega_a0[NDIM];    // angular velocity of frame a
    double             v_root_a0[NDIM];   // linear velocity of starting point of the first member
    int                omega_a_tf[NDIM];  // time function for angular velocity of frame a
    int                v_root_a_tf[NDIM]; // time function for linear velocity of starting point of the first member

    double               simu_time[2];    // start and end time
    struct TimeFunction  *time_function;  // time functions
    double               **init_cond;
    int                  analysis_flag;
    int                  nev;             // upon return, nev is the number of converged eigen values might be the original nev given by the user in the inputs or nev+1 due to complex conjugate pair 
143
144
145
146

    // Personal add
    double              L;                // Beam Length
    int                 initFromFile;
147
148
    double              dt;
    int                 initialize;       // flag indicating if an initialisation step is required to find the compatible state variables
149
} Gebt;
François Trigaux's avatar
François Trigaux committed
150
151
152



153
void initGebt(Gebt *bm);
154

155
156
void gebt_setTwist(Gebt *bm, double *twist);
void gebt_setTwistFromFile(Gebt *bm, char *fname);
François Trigaux's avatar
François Trigaux committed
157

158
159
void gebt_setLoads(Gebt *bm, double *loads, int load_no);
void gebt_setEndLoad(Gebt *bm, double loads, int load_no);
160

161
void gebt_analysis(Gebt *bm);
162

163
164
void gebt_getNodeVelocities(double **vel, Gebt *bm);
void gebt_getMemberVelocities(double **vel, Gebt *bm);
165

166
167
void gebt_getNodeDisplacement(double **disp, Gebt *bm);
void gebt_getMemberDisplacement(double **disp, Gebt *bm);
168

169
170
void gebt_writeGebtToFile(Gebt *bm,char *fname);
void gebt_writeSolToFile(Gebt *bm, char *fileName);
171

172
void freeGebt(Gebt *bm);
173
174


175
// Private functions
François Trigaux's avatar
François Trigaux committed
176
static void gebt_interpolateMatrix(double **out, double x, double *xp, double ***matrix, int np, int nx, int ny, int ixStart, int iyStart);
177

178
static void gebt_setMaterial(Gebt *bm);
179

180
181
182
183
void fortran_analysis(int nkp,int nelem,int ndof_el,int nmemb,int ncond_pt,int nmate,int nframe,int ndistrfun,int ncurv, double **coord,
                int **member,struct PrescriInf **pt_condition, double **material, int niter, int nstep, double **sol_pt, double **sol_mb,char *error, int ncond_mb,
                int ntimefun,double **frame, struct PrescriInf **mb_condition,double **distr_fun, double **curvature, double omega_a0[], int omega_a_tf[],
                double v_root_a0[], int v_root_a_tf[], double simu_time[], struct TimeFunction **time_function, int analysis_flag, double **init_cond,
184
                int *nev, double **eigen_val, double **eigen_vec_pt,double **eigen_vec_mb, int initialize);
185
186
187



188
#endif