1 /* init.C */
2
3 #include "../Coords.h"
4
5 /*--------------------------------------------------------------------*/
6 /*
7 ---------------------------------------------------
8 initialize the object, storage freed if repeat call
9
10 created -- 95dec17, cca
11 ---------------------------------------------------
12 */
13 void
Coords_init(Coords * coords,int type,int ndim,int ncoor)14 Coords_init (
15 Coords *coords,
16 int type,
17 int ndim,
18 int ncoor
19 ) {
20 /*
21 ---------------
22 check the input
23 ---------------
24 */
25 if ( coords == NULL
26 || !(type == COORDS_BY_TUPLE || type == COORDS_BY_COORD)
27 || ndim < 1 || ncoor <= 0 ) {
28 fprintf(stderr, "\n fatal error in Coords_init(%p,%d,%d,%d)"
29 "\n bad input\n", coords, type, ndim, ncoor) ;
30 exit(-1) ;
31 }
32 /*
33 --------------
34 clear the data
35 --------------
36 */
37 Coords_clearData(coords) ;
38 /*
39 -------------------
40 set the data fields
41 -------------------
42 */
43 coords->type = type ;
44 coords->ndim = ndim ;
45 coords->ncoor = ncoor ;
46 coords->coors = FVinit(ndim*ncoor, 0.0) ;
47
48 return ; }
49
50 /*--------------------------------------------------------------------*/
51 /*
52 ----------------------------------------------------------
53 purpose -- initialize a 9-point operator on a n1 x n2 grid
54
55 input --
56
57 bbox -- bounding box
58 bbox[0] -- x southwest
59 bbox[1] -- y southwest
60 bbox[2] -- x northeast
61 bbox[3] -- y northeast
62 Type -- type of object
63 n1 -- # of grid points in first direction
64 n2 -- # of grid points in second direction
65 ncomp -- # of components per grid point
66
67 created -- 95dec17, cca
68 ----------------------------------------------------------
69 */
70 void
Coords_init9P(Coords * coords,float bbox[],int type,int n1,int n2,int ncomp)71 Coords_init9P (
72 Coords *coords,
73 float bbox[],
74 int type,
75 int n1,
76 int n2,
77 int ncomp
78 ) {
79 int i, idof, j, k ;
80 float deltax, deltay ;
81 float *x, *y ;
82 /*
83 ---------------
84 check the input
85 ---------------
86 */
87 if ( coords == NULL || bbox == NULL
88 || !(type == COORDS_BY_TUPLE || type == COORDS_BY_COORD)
89 || n1 <= 0 || n2 <= 0 || ncomp <= 0 ) {
90 fprintf(stderr, "\n fatal error in Coords_init9P(%p,%p,%d,%d,%d,%d)"
91 "\n bad input\n", coords, bbox, type, n1, n2, ncomp) ;
92 exit(-1) ;
93 }
94 /*
95 ---------------------
96 initialize the object
97 ---------------------
98 */
99 Coords_init(coords, type, 2, n1*n2) ;
100 /*
101 --------------------
102 fill the coordinates
103 --------------------
104 */
105 deltax = (bbox[2] - bbox[0]) / (n1-1) ;
106 deltay = (bbox[3] - bbox[1]) / (n2-1) ;
107 switch ( type ) {
108 case COORDS_BY_TUPLE :
109 x = coords->coors ;
110 y = coords->coors + 1 ;
111 for ( j = 0, idof = 0 ; j < n2 ; j++ ) {
112 for ( i = 0 ; i < n1 ; i++ ) {
113 for ( k = 0 ; k < ncomp ; k++, idof += 2 ) {
114 x[idof] = bbox[0] + deltax*i ;
115 y[idof] = bbox[1] + deltay*j ;
116 }
117 }
118 }
119 break ;
120 case COORDS_BY_COORD :
121 x = coords->coors ;
122 y = coords->coors + n1*n2 ;
123 for ( j = 0, idof = 0 ; j < n2 ; j++ ) {
124 for ( i = 0 ; i < n1 ; i++ ) {
125 for ( k = 0 ; k < ncomp ; k++, idof++ ) {
126 x[idof] = bbox[0] + deltax*i ;
127 y[idof] = bbox[1] + deltay*j ;
128 }
129 }
130 }
131 break ;
132 }
133 return ; }
134
135 /*--------------------------------------------------------------------*/
136 /*
137 ----------------------------------------------------------------
138 purpose -- initialize a 27-point operator on a n1 x n2 x n3 grid
139
140 input --
141
142 bbox -- bounding box
143 bbox[0] -- x southwest bottom
144 bbox[1] -- y southwest bottom
145 bbox[2] -- z southwest bottom
146 bbox[3] -- x northeast top
147 bbox[4] -- y northeast top
148 bbox[5] -- z northeast top
149 Type -- type of object
150 n1 -- # of grid points in first direction
151 n2 -- # of grid points in second direction
152 n3 -- # of grid points in third direction
153 ncomp -- # of components per grid point
154
155 created -- 95dec17, cca
156 ----------------------------------------------------------------
157 */
158 void
Coords_init27P(Coords * coords,float bbox[],int type,int n1,int n2,int n3,int ncomp)159 Coords_init27P (
160 Coords *coords,
161 float bbox[],
162 int type,
163 int n1,
164 int n2,
165 int n3,
166 int ncomp
167 ) {
168 int i, idof, j, k, l ;
169 float deltax, deltay, deltaz ;
170 float *x, *y, *z ;
171 /*
172 ---------------
173 check the input
174 ---------------
175 */
176 if ( coords == NULL || bbox == NULL
177 || !(type == COORDS_BY_TUPLE || type == COORDS_BY_COORD)
178 || n1 <= 0 || n2 <= 0 || n3 <= 0 || ncomp <= 0 ) {
179 fprintf(stderr,
180 "\n fatal error in Coords_init27P(%p,%p,%d,%d,%d,%d,%d)"
181 "\n bad input\n", coords, bbox, type, n1, n2, n3, ncomp) ;
182 exit(-1) ;
183 }
184 /*
185 ---------------------
186 initialize the object
187 ---------------------
188 */
189 Coords_init(coords, type, 3, n1*n2*n3) ;
190 /*
191 --------------------
192 fill the coordinates
193 --------------------
194 */
195 deltax = (bbox[3] - bbox[0]) / (n1-1) ;
196 deltay = (bbox[4] - bbox[1]) / (n2-1) ;
197 deltaz = (bbox[5] - bbox[2]) / (n3-1) ;
198 switch ( type ) {
199 case COORDS_BY_TUPLE :
200 x = coords->coors ;
201 y = coords->coors + 1 ;
202 z = coords->coors + 2 ;
203 for ( k = 0, idof = 0 ; k < n3 ; k++ ) {
204 for ( j = 0 ; j < n2 ; j++ ) {
205 for ( i = 0 ; i < n1 ; i++ ) {
206 for ( l = 0 ; l < ncomp ; l++, idof += 3 ) {
207 x[idof] = bbox[0] + deltax*i ;
208 y[idof] = bbox[1] + deltay*j ;
209 z[idof] = bbox[2] + deltaz*k ;
210 }
211 }
212 }
213 }
214 break ;
215 case COORDS_BY_COORD :
216 x = coords->coors ;
217 y = coords->coors + coords->ncoor ;
218 z = coords->coors + 2*coords->ncoor ;
219 for ( k = 0, idof = 0 ; k < n3 ; k++ ) {
220 for ( j = 0 ; j < n2 ; j++ ) {
221 for ( i = 0 ; i < n1 ; i++ ) {
222 for ( l = 0 ; l < ncomp ; l++, idof++ ) {
223 x[idof] = bbox[0] + deltax*i ;
224 y[idof] = bbox[1] + deltay*j ;
225 z[idof] = bbox[2] + deltaz*k ;
226 }
227 }
228 }
229 }
230 break ;
231 }
232 return ; }
233
234 /*--------------------------------------------------------------------*/
235