TheBoussinesqModel  3.2.1
 All Data Structures Files Functions Variables Typedefs Macros Pages
tensors3D.c
Go to the documentation of this file.
1 #include "turtle.h"
2 #include "tensor3D.h"
3 /* Note that depth is the first indices and that the indices were pernutated
4 with respect to NR */
5 
6 /*-----------------------------------------------------------------------*/
7 
8 
9 double ***d3tensor( long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
10 
11 {
12 
13 long i,j,nrow=nrh-nrl+1, ncol=nch-ncl+1, ndep=ndh-ndl+1;
14 double ***t;
15 
16 
17 t=(double ***)malloc((size_t)((nrow*ncol+NR_END)*sizeof(double**)));
18 
19 if(!t) t_error("Allocation failure of a double tensor pointers");
20 t+=NR_END;
21 t-=nrl;
22 
23 t[nrl]=(double **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(double)));
24 if(!t[nrl]) t_error("Allocation failure in a double tensors rows pointer" );
25 t[nrl]+=NR_END;
26 t[nrl]-=ncl;
27 
28 t[nrl][ncl]=(double *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(double)));
29 if(!t[nrl][ncl]) t_error("Allocation failure in a double tensor colunmns pointer");
30 
31 t[nrl][ncl]+=NR_END;
32 t[nrl][ncl]-=ndl;
33 
34 
35 for(j=ncl+1;j<=nch; j++) t[nrl][j]=t[nrl][j-1]+ndep;
36 for(i=nrl+1;i<=nrh;i++){
37  t[i]=t[i-1]+ncol;
38  t[i][ncl]=t[i-1][ncl]+ncol*ndep;
39  for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
40 
41 
42 }
43 
44 return t;
45 
46 
47 }
48 
49 
50 /*-----------------------------------------------------------------------*/
51 
52 
53 DOUBLETENSOR *new_doubletensor(long ndh,long nrh,long nch)
54 
55 
56 {
57 
58 DOUBLETENSOR *m;
59 
60  m=(DOUBLETENSOR *)malloc(sizeof(DOUBLETENSOR));
61  if (!m) t_error("allocation failure in new_doubletensor()");
63  m->nrl=NL;
64  m->nrh=nrh;
65  m->ncl=NL;
66  m->nch=nch;
67  m->ndl=NL;
68  m->ndh=ndh;
69 
70 
71  m->co=d3tensor(1,ndh,1,nrh,1,nch);
72 
73 
74  return m;
75 
76 
77 }
78 
79 
80 /*-----------------------------------------------------------------------*/
81 
82 
83 void free_d3tensor(double ***t,long ndl, long nrl, long ncl)
84 
85 {
86 ncl=0;
87 free((FREE_ARG) (t[ndl][nrl]+ndl-NR_END));
88 
89 free((FREE_ARG) (t[ndl]+nrl-NR_END));
90 free((FREE_ARG) (t+ndl-NR_END));
91 
92 }
93 
94 /*-----------------------------------------------------------------------*/
95 
96 
98 
99 {
100 
101 
102  if(m==NULL || m->co==NULL){
103  t_error("This matrix was never allocated");
104  }else if(m->isdynamic==1){
105 
106  free_d3tensor(m->co,NL,NL,NL);
107  m->isdynamic=m->nrl=m->ncl=m->nrh=m->nch=m->ndl=m->ndh=-1;
108  free(m);
109 
110  return;
111 
112  }else{
113  printf("\nWarning::An attemp was made to free a non dynamic tensor\n");
114 
115  }
116 
117 
118 }
119 
120 
121 
122 /*---------------------------------------------------------------------------*/
124 
125 {
126 
127 long i,j,k;
128 
129 if(L!=NULL){
130  if(L->isdynamic==1){
131  for(k=1;k<=L->ndh;k++){
132  for(i=1;i<=L->nrh;i++){
133  for(j=1;j<=L->nch;j++){
134  L->co[k][i][j]=sign;
135 
136  }
137  }
138  }
139  }else{
140  t_error("This tensor was no properly allocated");
141  }
142 }else {
143  t_error("A null tensor was addressed");
144 }
145 }
146 
147 
148 
149 
150 
151 
152 
153