gebt.c 36.2 KB
Newer Older
François Trigaux's avatar
François Trigaux committed
1
2
#include <stdlib.h>
#include <stdio.h>
François Trigaux's avatar
François Trigaux committed
3
#include <math.h>
François Trigaux's avatar
François Trigaux committed
4
5

#include "readINIFile.h"
6
#include "gebt.h"
7

François Trigaux's avatar
François Trigaux committed
8
9
10
11

int check;
int i_,j_,k_; // macro iterators

12
void initGebt(Gebt *bm)
13
14
15
{
    int i,j,k;
    char *section;
16
    dataINI fileGebt = readINIFile("Gebt.ini");
17

18
    char*   line = NULL; // don't forget to free! 
19
20
21
22
23
24
    ssize_t read;
    int     frmt;
    size_t  len = 0;

    /* Set the mesh parameters */ 
    /*section = "Beam";
25
26
27
28
29
30
    SET_OR_DEFAULT(&(bm->analysis_flag),%d,fileGebt,section,"analysis_flag",2);
    SET_OR_DEFAULT(&(bm->nkp),%d,fileGebt,section,"nkp",2);
    SET_OR_DEFAULT(&(bm->nframe),%d,fileGebt,section,"nframe",0);// number of different cross-sectional frames
    SET_OR_DEFAULT(&(bm->ncurv),%d,fileGebt,section,"ncurv",0);// number of sets of initial curvature/twists
    SET_OR_DEFAULT(&(bm->L),%lf,fileGebt,section,"L",1.0);// number of sets of initial curvature/twists
    SET_OR_DEFAULT(&(bm->initFromFile),%d,fileGebt,section,"initFromFile",0);// number of sets of initial curvature/twists
31
32
33

    */
    section = "Beam";
34
35
    SET_OR_DEFAULT(&(bm->analysis_flag),%d,fileGebt,section,"analysis_flag",2);
    SET_OR_DEFAULT(&(bm->nkp),%d,fileGebt,section,"nkp",2);
36

37
38
    SET_OR_DEFAULT(&(bm->L),%lf,fileGebt,section,"L",1.0);// number of sets of initial curvature/twists
    SET_OR_DEFAULT(&(bm->initFromFile),%d,fileGebt,section,"initFromFile",0);// number of sets of initial curvature/twists
39

40
41
    SET_OR_DEFAULT(&(bm->niter),%d,fileGebt,section,"niter",100);
    SET_OR_DEFAULT(&(bm->nstep),%d,fileGebt,section,"nstep",1);
42

43
    if(bm->analysis_flag>0){
44
        SET(&(bm->dt),%lf,fileGebt,section,"dt");
45
46
    }

47
48
49
    bm->t = 0.0;
    bm->lastStep = -1;

50
51
52
53
    bm->nmemb = bm->nkp-1; // specific for beams. 
    bm->nmate = bm->nkp;   // 1 material per point
    bm->ncond_mb  = bm->nmemb; // each member has one condition
    bm->ndistrfun = bm->nmemb; // each member will have its own distributed load.
François Trigaux's avatar
François Trigaux committed
54
55
    bm->nframe    = bm->nmemb; // each member will have its own frame.
    bm->ncurv     = bm->nmemb;
56
57
58
59
    bm->ncond_pt = 2; // condition for clamped-free beam

    bm->ntimefun = 0;

60
61
    bm->initialize = 1;

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    if(bm->analysis_flag==0){
    bm->ndof_el=NDOF_ND;
    for (i = 0; i < NDIM; i++) 
    {
      bm->omega_a0[i]    = 0.0;
      bm->omega_a_tf[i]  = 0;
      bm->v_root_a0[i]   = 0.0;
      bm->v_root_a_tf[i] = 0;
    }
    }
    else{
        bm->ndof_el=18;

        for (i = 0; i < NDIM; i++) 
        {
            bm->omega_a_tf[i]  = 0;
            bm->v_root_a_tf[i] = 0;
        }
80
81
82
83
84
85
        SET_OR_DEFAULT(&bm->omega_a0[0],%lf,fileGebt,section,"omegaX",0.0);
        SET_OR_DEFAULT(&bm->omega_a0[1],%lf,fileGebt,section,"omegaY",0.0);
        SET_OR_DEFAULT(&bm->omega_a0[2],%lf,fileGebt,section,"omegaZ",0.0);
        SET_OR_DEFAULT(&bm->v_root_a0[0],%lf,fileGebt,section,"vrootX",0.0);
        SET_OR_DEFAULT(&bm->v_root_a0[1],%lf,fileGebt,section,"vrootY",0.0);
        SET_OR_DEFAULT(&bm->v_root_a0[2],%lf,fileGebt,section,"vrootZ",0.0);
86
87
    }

88
    freeDataINI(fileGebt);
89
90
91
92
93
94
95
96
97
98
99
100
101
    bm->nev = 0;

    ALLOCATE2(bm->coord, double, bm->nkp, NDIM);
    ALLOCATE2(bm->member, int, bm->nmemb, MEMB_CONST);
    ALLOCATE1(bm->pt_condition, struct PrescriInf, bm->ncond_pt);
    ALLOCATE3(bm->material, double, bm->nmate, bm->ndof_el - NSTRN, NSTRN);
    ALLOCATE3(bm->frame, double, bm->nframe, NDIM, NDIM);
    ALLOCATE1(bm->mb_condition, struct PrescriInf, bm->ncond_mb);
    ALLOCATE2(bm->distr_fun, double, bm->ndistrfun, NSTRN);
    ALLOCATE2(bm->curvature, double, bm->ncurv, NDIM);
    //ALLOCATE1(bm->time_function, struct TimeFunction, bm-> ntimefun);

    for (i = 0; i < bm->nkp; i++) {
102
        bm->coord[i][0] = i * bm->L/((double)bm->nmemb); 
103
104
105
106
107
108
109
110
111
        bm->coord[i][1] = 0.0;
        bm->coord[i][2] = 0.0;
    }

    for (i=0;i<bm->nmemb;i++){ 
        bm->member[i][0] = i+1; // number of point 1
        bm->member[i][1] = i+2; // number of point 2
        bm->member[i][2] = i+1; // number of material 1
        bm->member[i][3] = i+2; // number of material 2
François Trigaux's avatar
François Trigaux committed
112
113
        bm->member[i][4] = i+1; // frame number
        bm->member[i][5] = 1;   // number of division per member
114
        bm->member[i][6] = 0;   // initial curvature number   -- NOTE: Default curvature must be changed to non-zero parameter only if twist is explicitely added!!
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
    }

    // Set the clamped-free conditions
    bm->pt_condition[0].id = 1;       // first point
    bm->pt_condition[1].id = bm->nkp; // last point
    for (i=0;i<6;i++){
        bm->pt_condition[0].dof[i] = i+1;
        bm->pt_condition[0].value[i] = 0.0;
        bm->pt_condition[0].time_fun_no[i] = 0;
        bm->pt_condition[0].follower[i] = 0;
        bm->pt_condition[0].value_current[i] = bm->pt_condition[0].value[i];

        bm->pt_condition[1].dof[i] = i+1+6;
        bm->pt_condition[1].value[i] = 0.0;
        bm->pt_condition[1].time_fun_no[i] = 0;
        bm->pt_condition[1].follower[i] = 0;
131
        bm->pt_condition[1].value_current[i] = bm->pt_condition[1].value[i];
132
133
134
    }

    // Initialize the materials
François Trigaux's avatar
François Trigaux committed
135
    gebt_setMaterial(bm);
136
137
138
139
140
141
    


    for(i=0;i<bm->nframe;i++){
        for(j=0;j<NDIM;j++){
            for(k=0;k<NDIM;k++){
François Trigaux's avatar
François Trigaux committed
142
                bm->frame[i][j][k]= (j==k) ? 1.0 : 0.0;
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
            }
        }
    }

    // Initialize the loads to zero. Use proper function later to set the distributed loads
    if(bm->ncond_mb>0){
        struct PrescriInf *tmp;
        for (i=0;i<bm->ncond_mb;i++)
        {
            tmp = &(bm->mb_condition[i]);
            tmp->id = i+1;
                
            for (j=0;j<NSTRN;j++)
            {
                tmp->dof[j] = i+1; // Set the number of the distributed function
                tmp->value[j] = 0.0; // Set the value to multiply the distributed function with
                tmp->time_fun_no[j] = 0;
                tmp->follower[j] = 0; 
                tmp->value_current[j] = tmp->value[j];
            }
        }
    }


    // Use the proper function later to set the distributed load functions
    if(bm->ndistrfun>0){
    	for(i=0;i<bm->ndistrfun;i++)
        {
            for (j=0;j<NSTRN;j++)
            {
                bm->distr_fun[i][j] = 0.0;
            }
        }
    }


    if(bm->ncurv>0)
    {    
        for(i=0;i<bm->ncurv;i++)
        {
François Trigaux's avatar
François Trigaux committed
183
184
185
186
            for(j=0;j<NDIM;j++)
            {
                bm->curvature[i][j] = 0.0;
            }
187
188
189
        }
    }

190
    // This is used to compute dt in Fortran. MUST BE UPDATED IF nstep OR dt ARE CHANGED!!! 
191
    bm->simu_time[0] = 0.0;
192
    bm->simu_time[1] = bm->nstep * bm->dt;
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

    ALLOCATE1(bm->time_function,struct TimeFunction,bm->ntimefun);
    if (bm->ntimefun>0)
    {
        printf("Unable to read timefunctions from C\n");
        exit(EXIT_FAILURE);
    }


    bm->nelem=0;
    for (i=0;i<bm->nmemb;i++)
    {
        bm->nelem += bm->member[i][5]; // total number of elements for the structure
    }

    // Initialize conditions from file
    ALLOCATE2(bm->init_cond    , double             , bm->nelem    , 12);
210
211
212
    for (i=0;i<bm->nelem;i++)
    {
        for (j=0;j<2*NSTRN;j++)
213
        {
214
            bm->init_cond[i][j] = 0.0;
215
        }
216
    }
217

218
219
220
    if((bm->analysis_flag==2) && (bm->initFromFile==1))
    {
        // READ INITIAL CONIDITIONS FROM THE FILE
221
        FILE *INIT = fopen("Gebt_initCond.ini","r"); 
222
223
        if (INIT==NULL)
        {
224
            printf("Cannot read %s\n","Gebt_initCond.ini");
225
            exit(EXIT_FAILURE);
226
227
        }

228
229
230
231
232
        for (i=0;i<bm->nelem;i++)
        {
            READL(line,len,INIT);
            frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->init_cond[i][0],&bm->init_cond[i][1],&bm->init_cond[i][2],&bm->init_cond[i][3],&bm->init_cond[i][4],&bm->init_cond[i][5]); CHKFRMT(frmt,6);
        }
233

234
235
236
237
238
239
        for (i=0;i<bm->nelem;i++)
        {
            READL(line,len,INIT);
            frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->init_cond[i][6],&bm->init_cond[i][7],&bm->init_cond[i][8],&bm->init_cond[i][9],&bm->init_cond[i][10],&bm->init_cond[i][11]); CHKFRMT(frmt,6);
        }
        fclose(INIT);
240
241
242
243
244
245
    }


    ALLOCATE3(bm->sol_pt       , double             , bm->nstep    , bm->nkp  , NDIM + NDOF_ND);    //for each point there are 12 variables
    ALLOCATE3(bm->sol_mb       , double             , bm->nstep    , bm->nelem, NDIM + bm->ndof_el);  // for each element, there are 18 variables

246
247
248
249


    free(line);

250
251
252
}


253
254


255
void initGebtFromGebtFile(Gebt *bm)
François Trigaux's avatar
François Trigaux committed
256
257
258
{
  int i,j;
  char *section, dataFileName[32];
259
  dataINI fileGebt = readINIFile("Gebt.ini");
François Trigaux's avatar
François Trigaux committed
260
261
262
263
264
265
266
267

  int tmp_no;
  char *  line = NULL;
  ssize_t read;
  int     frmt;
  size_t  len = 0;
  double  a, b, c;

268
  FILE *IN = fopen("Gebt_data.dat","r");
François Trigaux's avatar
François Trigaux committed
269
270
  if (IN==NULL)
  {
271
      printf("Unable to read file %s for beam data\n","Gebt_data.dat");
François Trigaux's avatar
François Trigaux committed
272
273
274
275
276
      exit(EXIT_FAILURE);
  }

  /* Set the mesh parameters */ 
  section = "Beam";
277
278
279
280
281
282
283
284
  SET_OR_DEFAULT(&(bm->analysis_flag),%d,fileGebt,section,"analysis_flag",2);
  SET_OR_DEFAULT(&(bm->nkp),%d,fileGebt,section,"nkp",2);
  SET_OR_DEFAULT(&(bm->nmemb),%d,fileGebt,section,"nmemb",1);// number of beam members
  SET_OR_DEFAULT(&(bm->ncond_pt),%d,fileGebt,section,"ncond_pt",2);// number of point conditions
  SET_OR_DEFAULT(&(bm->nmate),%d,fileGebt,section,"nmate",1);// number of different cross-sections
  SET_OR_DEFAULT(&(bm->nframe),%d,fileGebt,section,"nframe",0);// number of different cross-sectional frames
  SET_OR_DEFAULT(&(bm->ndistrfun),%d,fileGebt,section,"ndistrfun",0);// number of distribution functions
  SET_OR_DEFAULT(&(bm->ncurv),%d,fileGebt,section,"ncurv",0);// number of sets of initial curvature/twists
François Trigaux's avatar
François Trigaux committed
285

286
287
  SET_OR_DEFAULT(&(bm->niter),%d,fileGebt,section,"niter",100);
  SET_OR_DEFAULT(&(bm->nstep),%d,fileGebt,section,"nstep",0);
François Trigaux's avatar
François Trigaux committed
288

289
  SET_OR_DEFAULT(&(bm->ncond_mb),%d,fileGebt,section,"ncond_mb",2);
François Trigaux's avatar
François Trigaux committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478

  bm->ntimefun = 0; // impossible to pass time-functions to fortran

  if(bm->analysis_flag==0){
    bm->ndof_el=NDOF_ND;
    for (i = 0; i < NDIM; i++) 
    {
      bm->omega_a0[i]    = 0.0;
      bm->omega_a_tf[i]  = 0;
      bm->v_root_a0[i]   = 0.0;
      bm->v_root_a_tf[i] = 0;
    }
    }
    else{
        bm->ndof_el=18;

        READ3(IN,bm->omega_a0,%lf);
        READ3(IN,bm->omega_a_tf,%d);
        READ3(IN,bm->v_root_a0,%lf);
        READ3(IN,bm->v_root_a_tf,%d);

        for (i=0;i>NDIM;i++)
        {
            if ((bm->omega_a_tf[i] != 0) || (bm->v_root_a_tf[i] !=0))
            {
                printf("You can not set time functions for omega and v_root when using the C interface");
                exit(EXIT_FAILURE);
            }
        }

        if(bm->analysis_flag==3){
            READ1(IN,bm->nev,%d);
        }
        else
        {
            bm->nev = 0;
        }
    }


  ALLOCATE2(bm->coord        , double             , bm->nkp      , NDIM);
  ALLOCATE2(bm->member       , int                , bm->nmemb    , MEMB_CONST);
  ALLOCATE1(bm->pt_condition , struct PrescriInf  , bm->ncond_pt);
  ALLOCATE3(bm->material     , double             , bm->nmate   , bm->ndof_el - NSTRN, NSTRN);
  ALLOCATE3(bm->frame        , double             , bm->nframe  , NDIM               , NDIM);
  ALLOCATE1(bm->mb_condition , struct PrescriInf  , bm->ncond_mb);
  ALLOCATE2(bm->distr_fun    , double             , bm->ndistrfun, NSTRN);
  ALLOCATE2(bm->curvature    , double             , bm->ncurv    , NDIM);
  //ALLOCATE1(bm->time_function, struct TimeFunction, bm-> ntimefun);

  
  // Read the value of each variable
  for (i = 0; i < bm->nkp; i++) {
    READL(line, len, IN);
    frmt                 = sscanf(line, "%d %lf %lf %lf", &tmp_no, &a, &b, &c); CHKFRMT(frmt,4)
    bm->coord[tmp_no - 1][0] = a; 
    bm->coord[tmp_no - 1][1] = b;
    bm->coord[tmp_no - 1][2] = c;
  }

  for (i=0;i<bm->nmemb;i++){  
        READL(line,len,IN);
        frmt = sscanf(line,"%d",&tmp_no); CHKFRMT(frmt,1)
        frmt = sscanf(line,"%*d %d %d %d %d %d %d",&bm->member[tmp_no-1][0],&bm->member[tmp_no-1][1],&bm->member[tmp_no-1][2],&bm->member[tmp_no-1][3],&bm->member[tmp_no-1][4],&bm->member[tmp_no-1][5],&bm->member[tmp_no-1][6]); CHKFRMT(frmt,6);

    }

    for (i=0;i<bm->ncond_pt;i++){
        READL(line,len,IN);
        sscanf(line,"%d",&(bm->pt_condition[i].id));
        READL(line,len,IN);
        sscanf(line,"%d %d %d %d %d %d",&(bm->pt_condition[i].dof[0]),&(bm->pt_condition[i].dof[1]),&(bm->pt_condition[i].dof[2]),&(bm->pt_condition[i].dof[3]),&(bm->pt_condition[i].dof[4]),&(bm->pt_condition[i].dof[5]));
        READL(line,len,IN);
        sscanf(line,"%lf %lf %lf %lf %lf %lf",&(bm->pt_condition[i].value[0]),&(bm->pt_condition[i].value[1]),&(bm->pt_condition[i].value[2]),&(bm->pt_condition[i].value[3]),&(bm->pt_condition[i].value[4]),&(bm->pt_condition[i].value[5]));
        READL(line,len,IN);
        sscanf(line,"%d %d %d %d %d %d",&(bm->pt_condition[i].time_fun_no[0]),&(bm->pt_condition[i].time_fun_no[1]),&(bm->pt_condition[i].time_fun_no[2]),&(bm->pt_condition[i].time_fun_no[3]),&(bm->pt_condition[i].time_fun_no[4]),&(bm->pt_condition[i].time_fun_no[5]));
        READL(line,len,IN);
        sscanf(line,"%d %d %d %d %d %d",&(bm->pt_condition[i].follower[0]),&(bm->pt_condition[i].follower[1]),&(bm->pt_condition[i].follower[2]),&(bm->pt_condition[i].follower[3]),&(bm->pt_condition[i].follower[4]),&(bm->pt_condition[i].follower[5]));

        for(j=0;j<6;j++)
        {
            bm->pt_condition[i].value_current[j] = bm->pt_condition[i].value[j]; //the current value is initialized to be the original functional value, if not time varing it will remain the same. If time varying, it will be updated.
        }

    }

    for (i=0;i<bm->nmate;i++)
    {
        READ1(IN,tmp_no,%d);

        for (j=0; j<NSTRN; j++)
        {
            READL(line,len,IN);
            frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->material[tmp_no-1][j][0],&bm->material[tmp_no-1][j][1],&bm->material[tmp_no-1][j][2],&bm->material[tmp_no-1][j][3],&bm->material[tmp_no-1][j][4],&bm->material[tmp_no-1][j][5]); CHKFRMT(frmt,6);
        }
    

    if(bm->analysis_flag!=0){
            for (j=NSTRN;j<NSTRN+NSTRN;j++){
                READL(line,len,IN);
                frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->material[tmp_no-1][j][0],&bm->material[tmp_no-1][j][1],&bm->material[tmp_no-1][j][2],&bm->material[tmp_no-1][j][3],&bm->material[tmp_no-1][j][4],&bm->material[tmp_no-1][j][5]); CHKFRMT(frmt,6);  
            }   
        }
    }



    for(i=0;i<bm->nframe;i++){

        READ1(IN,tmp_no,%d);
        
        for(j=0;j<NDIM;j++){
            READL(line,len,IN);
            frmt = sscanf(line,"%lf %lf %lf",&bm->frame[tmp_no-1][j][0],&bm->frame[tmp_no-1][j][1],&bm->frame[tmp_no-1][j][2]); CHKFRMT(frmt,3);
            
        }
    }

    if(bm->ncond_mb>0){
        struct PrescriInf *tmp;
        for (i=0;i<bm->ncond_mb;i++)
        {
            tmp = &(bm->mb_condition[i]);
            READL(line,len,IN);
            frmt = sscanf(line,"%d",&tmp->id); CHKFRMT(frmt,1);
                
            READL(line,len,IN);
            frmt = sscanf(line,"%d %d %d %d %d %d",&tmp->dof[0],&tmp->dof[1],&tmp->dof[2],&tmp->dof[3],&tmp->dof[4],&tmp->dof[5]);

            READL(line,len,IN);
            frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&tmp->value[0],&tmp->value[1],&tmp->value[2],&tmp->value[3],&tmp->value[4],&tmp->value[5]);

            READL(line,len,IN);
            frmt = sscanf(line,"%d %d %d %d %d %d",&tmp->time_fun_no[0],&tmp->time_fun_no[1],&tmp->time_fun_no[2],&tmp->time_fun_no[3],&tmp->time_fun_no[4],&tmp->time_fun_no[5]);
            
            READL(line,len,IN);
            frmt = sscanf(line,"%d %d %d %d %d %d",&tmp->follower[0],&tmp->follower[1],&tmp->follower[2],&tmp->follower[3],&tmp->follower[4],&tmp->follower[5]);

            for (j=0;j<NSTRN;j++)
            {
                tmp->value_current[j] = tmp->value[j];
            }
        }
    }

    if(bm->ndistrfun>0){
    	for(i=0;i<bm->ndistrfun;i++)
        {
            READ1(IN,tmp_no,%d);

            READL(line,len,IN);
            frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->distr_fun[tmp_no-1][0],&bm->distr_fun[tmp_no-1][1],&bm->distr_fun[tmp_no-1][2],&bm->distr_fun[tmp_no-1][3],&bm->distr_fun[tmp_no-1][4],&bm->distr_fun[tmp_no-1][5]); CHKFRMT(frmt,6);
        }

    }


    if(bm->ncurv>0){
        
        for(i=0;i<bm->ncurv;i++)
        {
            READ1(IN,tmp_no,%d);
            READ3(IN,bm->curvature[tmp_no-1],%lf);
        }
    }

    //if(bm->analysis_flag==2){
    	READL(line,len,IN);
        frmt = sscanf(line,"%lf %lf",&bm->simu_time[0],&bm->simu_time[1]); CHKFRMT(frmt,2);
    //}

    ALLOCATE1(bm->time_function,struct TimeFunction,bm->ntimefun);
    if (bm->ntimefun>0)
    {
        printf("Unable to read timefunctions from C\n");
        exit(EXIT_FAILURE);
    }


    bm->nelem=0;
    for (i=0;i<bm->nmemb;i++)
    {
        bm->nelem += bm->member[i][5]; // total number of elements for the structure
    }  

    ALLOCATE2(bm->init_cond    , double             , bm->nelem    , 12);
    if(bm->analysis_flag==2){

        // READ INITIAL CONIDITIONS FROM THE FILE
479
        FILE *INIT = fopen("Gebt_initCond.ini","r"); 
François Trigaux's avatar
François Trigaux committed
480
481
        if (INIT==NULL)
        {
482
            printf("Cannot read %s\n","Gebt_initCond.ini");
François Trigaux's avatar
François Trigaux committed
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
            exit(EXIT_FAILURE);
        }

        for (i=0;i<bm->nelem;i++)
        {
            READL(line,len,INIT);
            frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->init_cond[i][0],&bm->init_cond[i][1],&bm->init_cond[i][2],&bm->init_cond[i][3],&bm->init_cond[i][4],&bm->init_cond[i][5]); CHKFRMT(frmt,6);
        }

        for (i=0;i<bm->nelem;i++)
        {
            READL(line,len,INIT);
            frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->init_cond[i][6],&bm->init_cond[i][7],&bm->init_cond[i][8],&bm->init_cond[i][9],&bm->init_cond[i][10],&bm->init_cond[i][11]); CHKFRMT(frmt,6);
        }
        fclose(INIT);


    }


    ALLOCATE3(bm->sol_pt       , double             , bm->nstep    , bm->nkp  , NDIM + NDOF_ND);    //for each point there are 12 variables
    ALLOCATE3(bm->sol_mb       , double             , bm->nstep    , bm->nelem, NDIM + bm->ndof_el);  // for each element, there are 18 variables

}

François Trigaux's avatar
François Trigaux committed
508
509
// Assign the twist to each of the member by changing its frame
// twist_per_L [rad/arc length] is only required if there are subdivisions to the members
510
void gebt_setTwist(Gebt *bm, double *twist)
François Trigaux's avatar
François Trigaux committed
511
512
{
    int i;
513
    double k1;
François Trigaux's avatar
François Trigaux committed
514
515
516
517
518
519
520
521
522
523
524
    for(i=0;i<bm->nframe;i++){
        bm->frame[i][0][0] = 1.0;
        bm->frame[i][0][1] = 0.0;
        bm->frame[i][0][2] = 0.0;
        bm->frame[i][1][0] = 0.0;
        bm->frame[i][1][1] = cos(twist[i]);
        bm->frame[i][1][2] = -sin(twist[i]);
        bm->frame[i][2][0] = 0.0;
        bm->frame[i][2][1] = sin(twist[i]);
        bm->frame[i][2][2] = cos(twist[i]);

525
526
527
528
529
        k1 = (twist[i+1] - twist[i])/(bm->L / ((double)bm->nmemb));
        if (fabs(k1)>1e-8)
        {
            bm->member[i][6] = i+1; // Associate a non-zero curvature to the member -- TODO: find why it does not work when curvature is zero
            bm->curvature[i][0] = k1;
530
        }
531
532
533
534
535
    }
}

// Assign the twist to each of the member by changing its frame
// twist_per_L [rad/arc length] is only required if there are subdivisions to the members
536
void gebt_setTwistFromFile(Gebt *bm, char *fname)
537
538
539
540
541
542
{
    int i,j,k;
    int idx,np;
    double coeff;
    double x,*xp,*twistp,*twist;

543
    char*   line = NULL; //don't forget to free!
544
545
546
547
548
549
550
    ssize_t read;
    int     frmt;
    size_t  len = 0;

    // Open the file containing the mass matrices if dynamic analysis
    FILE *fid = fopen("Twist.dat","r");
    if  (fid==NULL)
551
        {printf("Unable to read twist file to set the twist for the blade\n"); exit(EXIT_FAILURE);}
552
553
554
555
556
557
558
559
560
561
562
563

    // fill the vectors for interpolation 
    READ1(fid,np,%d);
    ALLOCATE1(xp,double,np);
    ALLOCATE1(twistp,double,np);
    for(k=0;k<np;k++)
    {
        READL(line,len,fid);
        frmt = sscanf(line,"%lf %lf",&xp[k],&twistp[k]); CHKFRMT(frmt,2);
    }


564
    ALLOCATE1(twist,double,bm->nkp);
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
    for (k=0;k<bm->nkp;k++)
    {

        //x = ( sqrt(bm->coord[k][0]*bm->coord[k][0] + bm->coord[k][1]*bm->coord[k][1] + bm->coord[k][2]*bm->coord[k][2]) + sqrt(bm->coord[k+1][0]*bm->coord[k+1][0] + bm->coord[k+1][1]*bm->coord[k+1][1] + bm->coord[k+1][2]*bm->coord[k+1][2]) ) / 2.0; //member coordinates
        x = ( sqrt(bm->coord[k][0]*bm->coord[k][0] + bm->coord[k][1]*bm->coord[k][1] + bm->coord[k][2]*bm->coord[k][2]));

        idx = 0;
        for(i=0;i<np;i++)
        {
            if(x>xp[i])
                idx++;
        }
    
        if (idx<=0)
        {
580
            //if (np>1) printf("Warning: in Twist Interpolation : value of xp=%f is below or equal to xp[0]=%f \n",x,xp[0]);
581
582
583
584
            twist[k] = twistp[idx];
        }
        else if (idx>=np)
        {
585
            //if (np>1) printf("Warning: in Twist Interpolation : value of xp=%f is higher than xp[np-1]=%f \n",x,xp[np-1]);
586
587
588
589
590
591
592
593
594
            twist[k] = twistp[idx-1];
        }
        else
        {
            coeff = (x-xp[idx-1])/(xp[idx]-xp[idx-1]);
            coeff = (coeff>1.0 ? 1.0 : coeff);
            twist[k] = twistp[idx]* coeff + twistp[idx-1] * (1.0-coeff);
        }
        twist[k] *= M_PI/180.0; // convert to radian
François Trigaux's avatar
François Trigaux committed
595
    }
596

François Trigaux's avatar
François Trigaux committed
597
    gebt_setTwist(bm,twist); // NOTE: 0.0 is hardcoded
598
599
600
601
602

    DEALLOCATE1(twist);
    DEALLOCATE1(twistp);
    DEALLOCATE1(xp);

603
604
    free(line);

605
    fclose(fid);
606
607
}

608
void gebt_getNodeVelocities(double **vel, Gebt *bm){
609
    int i,j;
610
    int step = bm->lastStep;
611

612
    if(step<1)
613
    {
614
        for(i=0;i<bm->nkp;i++)
615
        {
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
            for(j=0;j<NSTRN;j++)
            {
                // !!! it is vel(j,i) to ease the access from interpolation methods!
                vel[j][i] = 0.0;
            }
        }

    }
    else
    {
        for(i=0;i<bm->nkp;i++)
        {
            for(j=0;j<NSTRN;j++)
            {
                // !!! it is vel(j,i) to ease the access from interpolation methods!
                vel[j][i] = (bm->sol_pt[step][i][j+NDIM] - bm->sol_pt[step-1][i][j+NDIM]) / bm->dt;
            }
633
634
635
636
        }
    }
}

637
void gebt_getMemberVelocities(double **vel, Gebt *bm){
638
    int i,j;
639
    int step = bm->lastStep;
640

641
    if(step<1)
642
    {
643
        for(i=0;i<bm->nelem;i++)
644
        {
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
            for(j=0;j<NSTRN;j++)
            {
                // !!! it is vel(j,i) to ease the access from interpolation methods!
                vel[j][i] = bm->init_cond[i][j+NSTRN];
            }
        }
    }
    else
    {
        for(i=0;i<bm->nelem;i++)
        {
            for(j=0;j<NSTRN;j++)
            {
                // !!! it is vel(j,i) to ease the access from interpolation methods!
                vel[j][i] = (bm->sol_mb[step][i][j+NDIM] - bm->sol_mb[step-1][i][j+NDIM]) / bm->dt;
            }
661
662
663
664
665
666
667
        }
    }
}

/* disp = allocated double pointer of size (6,nkp)
   /!\ the order of is reversed!
*/ 
668
void gebt_getNodeDisplacement(double **disp, Gebt *bm){
669
    int i,j;
670
    int step = bm->lastStep;
671

672
673
674
675
676
677
678
679
680
681
682
    if(step<0)
    {
        for (i = 0; i < bm->nkp; i++) 
        {
          for (j = 0; j < NSTRN; j++) 
          {
            disp[j][i] = 0.0;
          }
        }
    }
    else
683
    {
684
685
686
      for (i = 0; i < bm->nkp; i++) 
      {
        for (j = 0; j < NSTRN; j++) 
687
        {
688
689
          // !!! it is disp(j,i) to ease the access from interpolation methods!
          disp[j][i] = bm->sol_pt[step][i][j + NDIM];
690
        }
691
      }
692
693
    }
}
694

695
696
697
/* disp = allocated double pointer of size (6,nelem)
   /!\ the order of is reversed!
*/ 
698
void gebt_getMemberDisplacement(double **disp, Gebt *bm){
699
    int i,j;
700
    int step = bm->lastStep;
701

702
    if(step<0)
703
    {
704
        for(i=0;i<bm->nelem;i++)
705
        {
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
            for(j=0;j<NSTRN;j++)
            {
                // !!! it is vel(j,i) to ease the access from interpolation methods!
                disp[j][i] = bm->init_cond[i][j];
            }
        }
    }
    else
    {
        for(i=0;i<bm->nelem;i++)
        {
            for(j=0;j<NSTRN;j++)
            {
                // !!! it is disp(j,i) to ease the access from interpolation methods!
                disp[j][i] = bm->sol_mb[step][i][j+NDIM];
            }
722
723
        }
    }
François Trigaux's avatar
François Trigaux committed
724
}
François Trigaux's avatar
François Trigaux committed
725

726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
/* Get the rotation matrix from the internal Wiener-Milenkovic parameters of GEBT. 
*/
void gebt_getRotationMatrix(double out[3][3], double c[3])
{
    double c0,fac;
    c0 = 2.0 - (c[0]*c[0] + c[1]*c[1] + c[2]*c[2])/8.0;
    fac = 1.0/(4.0-c0)/(4.0-c0);

    out[0][0] =  fac * (c0*c0 + c[0]*c[0] - c[1]*c[1] - c[2]*c[2]);
    out[0][1] =  fac * (2*(c[0]*c[1] + c0*c[2]));
    out[0][2] =  fac * (2*(c[0]*c[2]-c0*c[1]));
    out[1][0] =  fac * (2*(c[0]*c[1] - c0*c[2]));
    out[1][1] =  fac * (c0*c0 - c[0]*c[0] + c[1]*c[1] - c[2]*c[2]);
    out[1][2] =  fac * (2*(c[1]*c[2] + c0*c[0]));
    out[2][0] =  fac * (2*(c[0]*c[2] + c0*c[1]));
    out[2][1] =  fac * (2*(c[1]*c[2] - c0*c[0]));
    out[2][2] =  fac * (c0*c0 - c[0]*c[0] - c[1]*c[1] + c[2]*c[2]);

}

746
void gebt_writeSolToFile(Gebt *bm,char* fileName)
François Trigaux's avatar
François Trigaux committed
747
748
749
750
751
{
    int i,j,k;
    char fname[32];
    FILE *fid;

752
753
754
755
756
    if(bm->lastStep<0)
    {
        printf("Unable to write the solution: No time-step have been performed with bm_analysis");
        exit(EXIT_FAILURE);
    }
François Trigaux's avatar
François Trigaux committed
757

758
759
760
761
762
763
764
765
766
    //for (k=0;k<bm->nstep;k++){
    k = bm->lastStep;
    sprintf(fname,"%s.dat",fileName);
    fid = fopen(fname,"w");
    if (fid==NULL)
    {
        printf("Unable to open file %s to write the solution of the structural analysis\n",fileName);
        exit(EXIT_FAILURE);
    }
François Trigaux's avatar
François Trigaux committed
767

768
769
770
771
    fprintf(fid,"Time = %f\n",bm->t);
    for (i=0;i<bm->nkp;i++)
    {
        for(j=0;j<NDIM + NDOF_ND;j++)
François Trigaux's avatar
François Trigaux committed
772
        {
773
            fprintf(fid,"%1.8e ",bm->sol_pt[k][i][j]);
François Trigaux's avatar
François Trigaux committed
774
        }
775
776
        fprintf(fid,"\n");
    }
François Trigaux's avatar
François Trigaux committed
777

778
779
780
    for (i=0;i<bm->nelem;i++)
    {
        for(j=0;j<NDIM + bm->ndof_el;j++)
François Trigaux's avatar
François Trigaux committed
781
        {
782
            fprintf(fid,"%1.8e ",bm->sol_mb[k][i][j]);
François Trigaux's avatar
François Trigaux committed
783
        }
784
        fprintf(fid,"\n");
François Trigaux's avatar
François Trigaux committed
785
    }
786
787
    fclose(fid);
    //}
François Trigaux's avatar
François Trigaux committed
788
789
790
}


791

792
void gebt_setLoads(Gebt *bm, double *loads, int load_no)
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
{
    int i;
    for(i=0;i<bm->ncond_mb;i++)
    {
        bm->mb_condition[i].dof[load_no] = i+1;
        bm->mb_condition[i].value[load_no] = loads[i];
        bm->mb_condition[i].value_current[load_no] = loads[i];
    }

    for(i=0;i<bm->ndistrfun;i++)
    {
        bm->distr_fun[i][0] = 1.0; //Constant chebyshev polynomial
    }
}

808
void gebt_setEndLoad(Gebt *bm, double loads, int load_no)
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
{
    int i;
    for(i=0;i<bm->ncond_mb;i++)
    {
        bm->pt_condition[1].dof[load_no+NSTRN] = i+1;
        bm->pt_condition[1].value[load_no] = loads;
        bm->pt_condition[1].value_current[load_no] = loads;
    }

    for(i=0;i<bm->ndistrfun;i++)
    {
        bm->distr_fun[i][0] = 1.0; //Constant chebyshev polynomial
    }
}

824

825
void gebt_analysis(Gebt *bm)
826
827
{

828
    int i;
829
    char *error="";
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851


    // Transform every pointer >1D into 1D pointers
    RAVEL2(bm,coord,bm->nkp,NDIM,double);
    RAVEL2(bm,member,bm->nmemb,MEMB_CONST,int);
    RAVEL3(bm,material,bm->nmate,bm->ndof_el-NSTRN,NSTRN,double);
    RAVEL3(bm,sol_pt,bm->nstep,bm->nkp,NDIM+NDOF_ND,double);
    RAVEL3(bm,sol_mb,bm->nstep,bm->nelem,NDIM+bm->ndof_el,double);
    RAVEL3(bm,frame,bm->nframe,NDIM,NDIM,double);
    RAVEL2(bm,distr_fun,bm->ndistrfun,NSTRN,double);
    RAVEL2(bm,curvature,bm->ncurv,NDIM,double);
    RAVEL2(bm,init_cond,bm->nelem,12,double);
    
    //RAVEL2(bm,eigen_val,2,bm->nev+1,double);
    //RAVEL3(bm,eigen_vec_pt,bm->nev+1,bm->nkp,NDIM+NDOF_ND,double);
    //RAVEL3(bm,eigen_vec_mb,bm->nev+1,bm->nelem,NDIM+bm->ndof_el,double);

    // Empty pointers are given for the eigen values as we don't want to perform such analysis
    double *rav_eigen_val   = malloc(sizeof(double));
    double *rav_eigen_vec_pt= malloc(sizeof(double));
    double *rav_eigen_vec_mb= malloc(sizeof(double));

852
853
854
855
856
857
858
    // The material tensor is modified by fortran_analysis. Thus, we will give it a copy
    double *material_tmp = (double*) malloc(sizeof(double) * bm->nmate * (bm->ndof_el - NSTRN) * NSTRN);
    for(i=0;i<bm->nmate * (bm->ndof_el - NSTRN) * NSTRN;i++)
    {
        material_tmp[i] = rav_material[i];
    }

859
860
861
862
    // In case dt or nstep have been changed, must recompute the simu-time because fortran uses it to compute the dt. 
    bm->simu_time[0] = 0.0;
    bm->simu_time[1] = bm->nstep * bm->dt;

863
864
    // Call the fortran function
    fortran_analysis(bm->nkp,bm->nelem,bm->ndof_el,bm->nmemb,bm->ncond_pt,bm->nmate, bm->nframe,bm->ndistrfun,
865
               bm->ncurv,&rav_coord,&rav_member,&(bm->pt_condition),&material_tmp,bm->niter,bm->nstep,
866
867
               &rav_sol_pt,&rav_sol_mb,error,bm->ncond_mb,bm->ntimefun,&rav_frame,&(bm->mb_condition),&rav_distr_fun,
               &rav_curvature,bm->omega_a0,bm->omega_a_tf,bm->v_root_a0,bm->v_root_a_tf,bm->simu_time,
868
               &bm->time_function,bm->analysis_flag,&rav_init_cond,&bm->nev,&rav_eigen_val,&rav_eigen_vec_pt,&rav_eigen_vec_mb,bm->initialize);
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883

    // Transform 1D pointers to 2D pointers if necessary
    UNRAVEL2(bm,coord,bm->nkp,NDIM,double);
    UNRAVEL2(bm,member,bm->nmemb,MEMB_CONST,int);
    UNRAVEL3(bm,material,bm->nmate,bm->ndof_el-NSTRN,NSTRN,int);
    UNRAVEL3(bm,sol_pt,bm->nstep,bm->nkp,NDIM+NDOF_ND,double);
    UNRAVEL3(bm,sol_mb,bm->nstep,bm->nelem,NDIM+bm->ndof_el,double);
    UNRAVEL3(bm,frame,bm->nframe,NDIM,NDIM,double);
    UNRAVEL2(bm,distr_fun,bm->ndistrfun,NSTRN,double);
    UNRAVEL2(bm,curvature,bm->ncurv,NDIM,double);
    UNRAVEL2(bm,init_cond,bm->nelem,12,double);
    //UNRAVEL2(eigen_val,2,nev+1,double);
    //UNRAVEL3(eigen_vec_pt,nev+1,nkp,NDIM+NDOF_ND,double);
    //UNRAVEL3(eigen_vec_mb,nev+1,nelem,NDIM+ndof_el,double);

884
885
    // Set initialize to zero to perform dynamic analysis without redoing the initialization step
    bm->initialize = 0;
886
887
    bm->lastStep = bm->nstep-1;
    bm->t += bm->nstep * bm->dt;
888

889
890
891
    free(rav_eigen_val);
    free(rav_eigen_vec_mb);
    free(rav_eigen_vec_pt);
892
893
    
    free(material_tmp);
894
895
896
897
898



}

899
900
/*
This updates the initial condition, but when the analysis does its initial step, it does not work
901
void gebt_updateInitialConditions(Gebt *bm)
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
{
    int i,j;
    for (i=0;i<bm->nelem;i++)
    {
        // copy u_dot, theta_dot from the initial conditions
        for (j=0;j<NSTRN;j++)
        {
            bm->init_cond[i][j+NSTRN] = bm->init_cond[i][j];
        }
        // copy u, theta from the solution member
        for (j=0;j<NSTRN;j++)
        {
            bm->init_cond[i][j] = bm->sol_mb[bm->nstep-1][i][j+NDIM];
        }
        
    }
}
*/

#define WRITEF3(ptr,fid,type,n1,n2,n3)  for (i_=0; i_<(n1); i_++){\
                                     for (j_=0; j_<(n2); j_++){\
                                     for (k_=0; k_<(n3); k_++){\
                                      fprintf(fid,#type " ",ptr[i_][j_][k_]);}\
                                      fprintf(fid,"\n");}\
                                      fprintf(fid,"\n");}

#define WRITEF2(ptr,fid,type,n1,n2)  for (i_=0; i_<(n1); i_++){\
                                     for (j_=0; j_<(n2); j_++){\
                                      fprintf(fid,#type " ",ptr[i_][j_]);}\
                                      fprintf(fid,"\n");}

#define WRITEF1(ptr,fid,type,n1)  for (i_=0; i_<(n1); i_++){\
                                      fprintf(fid,#type " ",ptr[i_][j_]);\
                                      fprintf(fid,"\n");}

937
void gebt_writeGebtToFile(Gebt *bm,char *fname)
938
939
940
941
{
    int i,j,k;
    FILE *fid = fopen(fname,"w");

942
943
944
945
946
947
948
949
950
951
    fprintf(fid,"nkp       = %d\n",bm->nkp);
    fprintf(fid,"nelem     = %d\n",bm->nelem);
    fprintf(fid,"ndof      = %d\n",bm->ndof_el);
    fprintf(fid,"nmemb     = %d\n",bm->nmemb);
    fprintf(fid,"ncond_pt  = %d\n",bm->ncond_pt);
    fprintf(fid,"nmate     = %d\n",bm->nmate);
    fprintf(fid,"nframe    = %d\n",bm->nframe);
    fprintf(fid,"ndistrfun = %d\n",bm->ndistrfun);
    fprintf(fid,"ncurv     = %d\n",bm->ncurv);
    fprintf(fid,"Coordinates: \n");
952
    WRITEF2(bm->coord, fid, %f, bm->nkp, NDIM);
953
    fprintf(fid,"Member: \n");
954
    WRITEF2(bm->member, fid, %d, bm->nmemb, MEMB_CONST);
955
956
957
    fprintf(fid,"Material: \n");
    WRITEF3(bm->material, fid, % 1.6E, bm->nmate, bm->ndof_el - NSTRN, NSTRN);
    fprintf(fid,"Frame: \n");
958
    WRITEF3(bm->frame, fid, %f, bm->nframe, NDIM, NDIM);
959
    fprintf(fid,"Distributed Functions: \n");
960
    WRITEF2(bm->distr_fun,fid,  %f, bm->ndistrfun, NSTRN);
961
    fprintf(fid,"Curvatures: \n");
962
963
964
965
966
967
    WRITEF2(bm->curvature,fid,  %f, bm->ncurv, NDIM);

    fclose(fid);
}


968
void freeGebt(Gebt *bm)
François Trigaux's avatar
François Trigaux committed
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
{
    
    printf("Freeing the memory...\n");
    int i;
    DEALLOCATE3(bm->sol_mb,bm->nstep,bm->nelem);
    DEALLOCATE3(bm->sol_pt,bm->nstep,bm->nkp);
    DEALLOCATE2(bm->init_cond,bm->nelem);
    DEALLOCATE2(bm->curvature,bm->ncurv);
    DEALLOCATE2(bm->distr_fun,bm->ndistrfun);
    DEALLOCATE3(bm->frame,bm->nframe,NDIM);
    DEALLOCATE3(bm->material,bm->nmate,bm->ndof_el-NSTRN);
    DEALLOCATE2(bm->member,bm->nmemb);
    DEALLOCATE2(bm->coord,bm->nkp);

    // Free time-functions
    //for (i=0;i<bm->ntimefun;i++)
    //    freeTimeFunction(&time_function[i]);
986
    DEALLOCATE1(bm->time_function); // freeTF
François Trigaux's avatar
François Trigaux committed
987
988
989
990
991

    DEALLOCATE1(bm->mb_condition); // freePrescriInf
    DEALLOCATE1(bm->pt_condition); //freePrescriInf
    printf("Done!\n");
}
992
993
994
995
996
997





// Library utils
François Trigaux's avatar
François Trigaux committed
998
static void gebt_interpolateMatrix(double **out, double x, double *xp, double ***matrix, int np, int nx, int ny, int ixStart, int iyStart)
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
{
    int i,j;
    int idx = 0;
    double coeff;
    for(i=0;i<np;i++)
    {
        if(x>xp[i])
        {
            idx++;
        }
    }
    
    if (idx==0)
    {
1013
        //if (np>1){ printf("Warning: in Matrix Interpolation : value of xp=%f is below or equal to xp[0]=%f \n",x,xp[0]);}
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
        for(i=0;i<nx;i++)
        {
            for(j=0;j<ny;j++)
            {
                out[i+ixStart][j+iyStart] = matrix[idx][i][j];
            }
        }
    }
    else if (idx==np)
    {
1024
        //if (np>1) printf("Warning: in Matrix Interpolation : value of xp=%f is higher than xp[np-1]=%f \n",x,xp[np-1]);
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
        for(i=0;i<nx;i++)
        {
            for(j=0;j<ny;j++)
            {
                out[i+ixStart][j+iyStart] = matrix[idx-1][i][j];
            }
        }
    }
    else
    {
        coeff = (x-xp[idx-1])/(xp[idx]-xp[idx-1]);
        coeff = (coeff>1.0 ? 1.0 : coeff);
        for(i=0;i<nx;i++)
        {
            for(j=0;j<ny;j++)
            {
                out[i+ixStart][j+iyStart] = matrix[idx][i][j] * coeff + matrix[idx-1][i][j] * (1.0-coeff);
            }
        }
    }
}


1048

1049
static void gebt_setMaterial(Gebt *bm)
1050
1051
1052
1053
1054
1055
1056
{
    int i,j,k;
    int ncomp, nmass;
    double ***matComp, ***matMass;
    double *xcomp, *xmass;
    double x;

1057
    char*   line = NULL; //don't forget to free! 
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
    ssize_t read;
    int     frmt;
    size_t  len = 0;

    // Open the file containing the compliance matrices
    FILE *COMP = fopen("Compliance.dat","r");
    if (COMP==NULL)
        {printf("Unable to read compliance matrix file\n"); exit(EXIT_FAILURE);}
    
    // Open the file containing the mass matrices if dynamic analysis
    FILE *MASS = fopen("Mass.dat","r");
    if ((MASS==NULL) && (bm->analysis_flag!=0))
        {printf("Unable to read mass matrix file for dynamic analysis\n"); exit(EXIT_FAILURE);}
    
    // Read all the compliance matrices
    READ1(COMP,ncomp,%d);
    ALLOCATE3(matComp,double,ncomp,NSTRN,NSTRN);
    ALLOCATE1(xcomp,double,ncomp);
    for (i=0;i<ncomp;i++)
    {
        READ1(COMP,xcomp[i],%lf);
        for (j=0; j<NSTRN; j++)
        {
            READL(line,len,COMP);
            frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&matComp[i][j][0],&matComp[i][j][1],&matComp[i][j][2],&matComp[i][j][3],&matComp[i][j][4],&matComp[i][j][5]); CHKFRMT(frmt,6);
        }
    }

    // Read all the mass matrices
    if ((bm->analysis_flag!=0))
    {
        READ1(MASS,nmass,%d);
        ALLOCATE3(matMass,double,nmass,NSTRN,NSTRN);
        ALLOCATE1(xmass,double,nmass);
        for (i=0;i<nmass;i++)
        {
            READ1(MASS,xmass[i],%lf);
            for (j=0; j<NSTRN; j++)
            {
                READL(line,len,MASS);
                frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&matMass[i][j][0],&matMass[i][j][1],&matMass[i][j][2],&matMass[i][j][3],&matMass[i][j][4],&matMass[i][j][5]); CHKFRMT(frmt,6);
            }
        }
    }


    // Interpolate the matrices at the point position
    for (i=0;i<bm->nmate;i++)
    {

        // Warning: this requires that bm->nmate = bm->nkp!!
        // Position are given in arc length / L
1110
        x = sqrt(bm->coord[i][0]*bm->coord[i][0] + bm->coord[i][1]*bm->coord[i][1] + bm->coord[i][2]*bm->coord[i][2]) / bm->L;
1111
1112

        // Interpolate the material at the correct point position
François Trigaux's avatar
François Trigaux committed
1113
        gebt_interpolateMatrix(bm->material[i],x,xcomp,matComp,ncomp,NSTRN,NSTRN,0    ,0);
1114
1115
        if (bm->analysis_flag!=0) 
        {
François Trigaux's avatar
François Trigaux committed
1116
            gebt_interpolateMatrix(bm->material[i],x,xmass,matMass,nmass,NSTRN,NSTRN,NSTRN,0);
1117
        }
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127

    }

    DEALLOCATE1(xcomp);
    DEALLOCATE3(matComp,ncomp,NSTRN);
    if (bm->analysis_flag!=0) 
    {
        DEALLOCATE1(xmass);
        DEALLOCATE3(matMass,ncomp,NSTRN);
    }
1128
1129
1130

    free(line);

1131
1132
    fclose(COMP);
    fclose(MASS);
1133
}