New object GfsMapFunction
darcs-hash:20091007210854-d4795-0ce9f0c827dd8b064fe04d97c08f39ecab6ff491.gz
Stephane Popinet
14 years ago
131 | 131 | GTS_OBJECT_CLASS (klass)->read = gfs_map_projection_read; |
132 | 132 | GTS_OBJECT_CLASS (klass)->write = gfs_map_projection_write; |
133 | 133 | GTS_OBJECT_CLASS (klass)->destroy = gfs_map_projection_destroy; |
134 | GFS_MAP_CLASS (klass)->transform = projection_transform; | |
135 | GFS_MAP_CLASS (klass)->inverse = projection_inverse; | |
136 | 134 | } |
137 | 135 | |
138 | 136 | static void gfs_map_projection_init (GfsMapProjection * object) |
142 | 140 | object->lat = -41.288889; |
143 | 141 | object->angle = 0.; object->cosa = 1.; object->sina = 0.; |
144 | 142 | object->pj = NULL; |
143 | GFS_MAP (object)->transform = projection_transform; | |
144 | GFS_MAP (object)->inverse = projection_inverse; | |
145 | 145 | } |
146 | 146 | |
147 | 147 | GfsMapClass * gfs_map_projection_class (void) |
42 | 42 | #include "moving.h" |
43 | 43 | #include "river.h" |
44 | 44 | #include "balance.h" |
45 | #include "map.h" | |
45 | 46 | |
46 | 47 | #include "modules.h" |
47 | 48 | |
228 | 229 | gfs_output_streamline_class (), |
229 | 230 | gfs_output_ppm_class (), |
230 | 231 | |
232 | gfs_map_class (), | |
233 | gfs_map_function_class (), | |
234 | ||
231 | 235 | NULL}; |
232 | 236 | |
233 | 237 | guint n = 0; |
17 | 17 | */ |
18 | 18 | |
19 | 19 | #include "map.h" |
20 | #include "variable.h" | |
21 | #include "utils.h" | |
22 | 20 | |
23 | 21 | /* GfsMap: Object */ |
24 | 22 | |
55 | 53 | fprintf (fp, "%s", o->klass->info.name); |
56 | 54 | } |
57 | 55 | |
58 | static void identity (GfsMap * map, const FttVector * src, FttVector * dest) | |
59 | { | |
60 | *dest = *src; | |
61 | } | |
62 | ||
63 | 56 | static void gfs_map_class_init (GfsMapClass * klass) |
64 | 57 | { |
65 | 58 | GTS_OBJECT_CLASS (klass)->read = gfs_map_read; |
66 | 59 | GTS_OBJECT_CLASS (klass)->write = gfs_map_write; |
67 | GFS_MAP_CLASS (klass)->transform = GFS_MAP_CLASS (klass)->inverse = identity; | |
60 | } | |
61 | ||
62 | static void identity (GfsMap * map, const FttVector * src, FttVector * dest) | |
63 | { | |
64 | *dest = *src; | |
65 | } | |
66 | ||
67 | static void gfs_map_init (GfsMap * map) | |
68 | { | |
69 | map->transform = map->inverse = identity; | |
68 | 70 | } |
69 | 71 | |
70 | 72 | GfsMapClass * gfs_map_class (void) |
77 | 79 | sizeof (GfsMap), |
78 | 80 | sizeof (GfsMapClass), |
79 | 81 | (GtsObjectClassInitFunc) gfs_map_class_init, |
80 | (GtsObjectInitFunc) NULL, | |
82 | (GtsObjectInitFunc) gfs_map_init, | |
81 | 83 | (GtsArgSetFunc) NULL, |
82 | 84 | (GtsArgGetFunc) NULL |
83 | 85 | }; |
87 | 89 | |
88 | 90 | return klass; |
89 | 91 | } |
92 | ||
93 | /* GfsMapFunction: Object */ | |
94 | ||
95 | static void gfs_map_function_read (GtsObject ** o, GtsFile * fp) | |
96 | { | |
97 | (* GTS_OBJECT_CLASS (gfs_map_function_class ())->parent_class->read) (o, fp); | |
98 | if (fp->type == GTS_ERROR) | |
99 | return; | |
100 | ||
101 | if (fp->type != '{') { | |
102 | gts_file_error (fp, "expecting an opening brace"); | |
103 | return; | |
104 | } | |
105 | fp->scope_max++; | |
106 | gts_file_next_token (fp); | |
107 | while (fp->type != GTS_ERROR && fp->type != '}') { | |
108 | if (fp->type == '\n') { | |
109 | gts_file_next_token (fp); | |
110 | continue; | |
111 | } | |
112 | if (fp->type != GTS_STRING) { | |
113 | gts_file_error (fp, "expecting a keyword"); | |
114 | return; | |
115 | } | |
116 | else { | |
117 | static gchar name[3][3] = { "x:", "y:", "z:" }; | |
118 | FttComponent c; | |
119 | for (c = 0; c < FTT_DIMENSION; c++) | |
120 | if (!strcmp (fp->token->str, name[c])) | |
121 | break; | |
122 | if (c == FTT_DIMENSION) { | |
123 | gts_file_error (fp, "unknown keyword '%s'", fp->token->str); | |
124 | return; | |
125 | } | |
126 | gts_file_next_token (fp); | |
127 | ||
128 | GfsMapFunction * map = GFS_MAP_FUNCTION (*o); | |
129 | if (!map->inverse[c]) | |
130 | map->inverse[c] = gfs_function_new (gfs_function_map_class (), 0.); | |
131 | gfs_function_read (map->inverse[c], gfs_object_simulation (*o), fp); | |
132 | if (fp->type == GTS_ERROR) | |
133 | return; | |
134 | ||
135 | if (fp->type != '\n') { | |
136 | gts_file_error (fp, "expecting new line"); | |
137 | return; | |
138 | } | |
139 | while (fp->type == '\n') | |
140 | gts_file_next_token (fp); | |
141 | ||
142 | if (!map->transform[c]) | |
143 | map->transform[c] = gfs_function_new (gfs_function_map_class (), 0.); | |
144 | gfs_function_read (map->transform[c], gfs_object_simulation (*o), fp); | |
145 | if (fp->type == GTS_ERROR) | |
146 | return; | |
147 | } | |
148 | } | |
149 | if (fp->type != '}') { | |
150 | gts_file_error (fp, "expecting a closing brace"); | |
151 | return; | |
152 | } | |
153 | fp->scope_max--; | |
154 | gts_file_next_token (fp); | |
155 | } | |
156 | ||
157 | static void gfs_map_function_write (GtsObject * o, FILE * fp) | |
158 | { | |
159 | (* GTS_OBJECT_CLASS (gfs_map_function_class ())->parent_class->write) (o, fp); | |
160 | fputs (" {\n", fp); | |
161 | GfsMapFunction * map = GFS_MAP_FUNCTION (o); | |
162 | static gchar name[3][5] = { " x:", " y:", " z:" }; | |
163 | FttComponent c; | |
164 | for (c = 0; c < FTT_DIMENSION; c++) | |
165 | if (map->transform[c]) { | |
166 | fputs (name[c], fp); | |
167 | gfs_function_write (map->inverse[c], fp); | |
168 | fputs ("\n ", fp); | |
169 | gfs_function_write (map->transform[c], fp); | |
170 | fputc ('\n', fp); | |
171 | } | |
172 | fputc ('}', fp); | |
173 | } | |
174 | ||
175 | static void gfs_map_function_destroy (GtsObject * o) | |
176 | { | |
177 | GfsMapFunction * map = GFS_MAP_FUNCTION (o); | |
178 | FttComponent c; | |
179 | ||
180 | for (c = 0; c < FTT_DIMENSION; c++) { | |
181 | if (map->transform[c]) | |
182 | gts_object_destroy (GTS_OBJECT (map->transform[c])); | |
183 | if (map->inverse[c]) | |
184 | gts_object_destroy (GTS_OBJECT (map->inverse[c])); | |
185 | } | |
186 | ||
187 | (* GTS_OBJECT_CLASS (gfs_map_function_class ())->parent_class->destroy) (o); | |
188 | } | |
189 | ||
190 | static void gfs_map_function_class_init (GfsMapClass * klass) | |
191 | { | |
192 | GTS_OBJECT_CLASS (klass)->read = gfs_map_function_read; | |
193 | GTS_OBJECT_CLASS (klass)->write = gfs_map_function_write; | |
194 | GTS_OBJECT_CLASS (klass)->destroy = gfs_map_function_destroy; | |
195 | } | |
196 | ||
197 | static void map_function_transform (GfsMap * map, const FttVector * src, FttVector * dest) | |
198 | { | |
199 | GfsMapFunction * mf = GFS_MAP_FUNCTION (map); | |
200 | FttComponent c; | |
201 | for (c = 0; c < FTT_DIMENSION; c++) | |
202 | if (mf->transform[c]) | |
203 | (&dest->x)[c] = gfs_function_spatial_value (mf->transform[c], src); | |
204 | else | |
205 | (&dest->x)[c] = (&src->x)[c]; | |
206 | } | |
207 | ||
208 | static void map_function_inverse (GfsMap * map, const FttVector * src, FttVector * dest) | |
209 | { | |
210 | GfsMapFunction * mf = GFS_MAP_FUNCTION (map); | |
211 | FttComponent c; | |
212 | for (c = 0; c < FTT_DIMENSION; c++) | |
213 | if (mf->inverse[c]) | |
214 | (&dest->x)[c] = gfs_function_spatial_value (mf->inverse[c], src); | |
215 | else | |
216 | (&dest->x)[c] = (&src->x)[c]; | |
217 | } | |
218 | ||
219 | static void gfs_map_function_init (GfsMap * map) | |
220 | { | |
221 | map->transform = map_function_transform; | |
222 | map->inverse = map_function_inverse; | |
223 | } | |
224 | ||
225 | GfsMapClass * gfs_map_function_class (void) | |
226 | { | |
227 | static GfsMapClass * klass = NULL; | |
228 | ||
229 | if (klass == NULL) { | |
230 | GtsObjectClassInfo gfs_map_function_info = { | |
231 | "GfsMapFunction", | |
232 | sizeof (GfsMapFunction), | |
233 | sizeof (GfsMapClass), | |
234 | (GtsObjectClassInitFunc) gfs_map_function_class_init, | |
235 | (GtsObjectInitFunc) gfs_map_function_init, | |
236 | (GtsArgSetFunc) NULL, | |
237 | (GtsArgGetFunc) NULL | |
238 | }; | |
239 | klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_map_class ()), &gfs_map_function_info); | |
240 | } | |
241 | ||
242 | return klass; | |
243 | } |
23 | 23 | extern "C" { |
24 | 24 | #endif /* __cplusplus */ |
25 | 25 | |
26 | #include "ftt.h" | |
26 | #include "variable.h" | |
27 | #include "utils.h" | |
27 | 28 | |
28 | 29 | /* GfsMap: Header */ |
29 | 30 | |
33 | 34 | /*< private >*/ |
34 | 35 | GtsSListContainee parent; |
35 | 36 | |
37 | void (* transform) (GfsMap * map, const FttVector * src, FttVector * dest); | |
38 | void (* inverse) (GfsMap * map, const FttVector * src, FttVector * dest); | |
36 | 39 | /*< public >*/ |
37 | 40 | }; |
38 | 41 | |
43 | 46 | GtsSListContaineeClass parent_class; |
44 | 47 | |
45 | 48 | /*< public >*/ |
46 | void (* transform) (GfsMap * map, const FttVector * src, FttVector * dest); | |
47 | void (* inverse) (GfsMap * map, const FttVector * src, FttVector * dest); | |
48 | 49 | }; |
49 | 50 | |
50 | 51 | #define GFS_MAP(obj) GTS_OBJECT_CAST (obj,\ |
58 | 59 | |
59 | 60 | GfsMapClass * gfs_map_class (void); |
60 | 61 | |
62 | /* GfsMapFunction: Header */ | |
63 | ||
64 | typedef struct _GfsMapFunction GfsMapFunction; | |
65 | ||
66 | struct _GfsMapFunction { | |
67 | /*< private >*/ | |
68 | GfsMap parent; | |
69 | ||
70 | /*< public >*/ | |
71 | GfsFunction * transform[FTT_DIMENSION], * inverse[FTT_DIMENSION]; | |
72 | }; | |
73 | ||
74 | #define GFS_MAP_FUNCTION(obj) GTS_OBJECT_CAST (obj,\ | |
75 | GfsMapFunction,\ | |
76 | gfs_map_function_class ()) | |
77 | #define GFS_IS_MAP_FUNCTION(obj) (gts_object_is_from_class (obj,\ | |
78 | gfs_map_function_class ())) | |
79 | ||
80 | GfsMapClass * gfs_map_function_class (void); | |
81 | ||
61 | 82 | #ifdef __cplusplus |
62 | 83 | } |
63 | 84 | #endif /* __cplusplus */ |
1650 | 1650 | |
1651 | 1651 | GSList * i = sim->maps->items; |
1652 | 1652 | while (i) { |
1653 | GtsObject * o = i->data; | |
1654 | (* GFS_MAP_CLASS (o->klass)->transform) (i->data, p, p); | |
1653 | (* GFS_MAP (i->data)->transform) (i->data, p, p); | |
1655 | 1654 | i = i->next; |
1656 | 1655 | } |
1657 | 1656 | FttComponent c; |
1677 | 1676 | (&p->x)[c] *= sim->physical_params.L/(&GFS_DOMAIN (sim)->lambda.x)[c]; |
1678 | 1677 | GSList * i = sim->maps->items; |
1679 | 1678 | while (i) { |
1680 | GtsObject * o = i->data; | |
1681 | (* GFS_MAP_CLASS (o->klass)->inverse) (i->data, p, p); | |
1679 | (* GFS_MAP (i->data)->inverse) (i->data, p, p); | |
1682 | 1680 | i = i->next; |
1683 | 1681 | } |
1684 | 1682 | } |
197 | 197 | GfsVariable * v; |
198 | 198 | GfsDerivedVariable * dv; |
199 | 199 | gdouble val; |
200 | gboolean spatial, constant; | |
200 | gboolean spatial, constant, nomap; | |
201 | 201 | GtsFile fpd; |
202 | 202 | gdouble units; |
203 | 203 | }; |
1143 | 1143 | * |
1144 | 1144 | * Returns: the value of function @f at location @p. |
1145 | 1145 | */ |
1146 | gdouble gfs_function_spatial_value (GfsFunction * f, FttVector * p) | |
1146 | gdouble gfs_function_spatial_value (GfsFunction * f, const FttVector * p) | |
1147 | 1147 | { |
1148 | 1148 | g_return_val_if_fail (f != NULL, 0.); |
1149 | 1149 | g_return_val_if_fail (GFS_IS_FUNCTION_SPATIAL (f), 0.); |
1154 | 1154 | GfsSimulation * sim = gfs_object_simulation (f); |
1155 | 1155 | FttVector q = *p; |
1156 | 1156 | check_for_deferred_compilation (f); |
1157 | gfs_simulation_map_inverse (sim, &q); | |
1157 | if (!f->nomap) | |
1158 | gfs_simulation_map_inverse (sim, &q); | |
1158 | 1159 | dimensional = (* (GfsFunctionSpatialFunc) f->f) (q.x, q.y, q.z, sim->time.t); |
1159 | 1160 | } |
1160 | 1161 | else |
1173 | 1174 | object->f = (GfsFunctionFunc) func; |
1174 | 1175 | |
1175 | 1176 | return object; |
1177 | } | |
1178 | ||
1179 | /* GfsFunctionMap: object */ | |
1180 | ||
1181 | static void gfs_function_map_init (GfsFunction * f) | |
1182 | { | |
1183 | f->nomap = TRUE; | |
1184 | } | |
1185 | ||
1186 | GfsFunctionClass * gfs_function_map_class (void) | |
1187 | { | |
1188 | static GfsFunctionClass * klass = NULL; | |
1189 | ||
1190 | if (klass == NULL) { | |
1191 | GtsObjectClassInfo gfs_function_info = { | |
1192 | "GfsFunctionMap", | |
1193 | sizeof (GfsFunction), | |
1194 | sizeof (GfsFunctionClass), | |
1195 | (GtsObjectClassInitFunc) NULL, | |
1196 | (GtsObjectInitFunc) gfs_function_map_init, | |
1197 | (GtsArgSetFunc) NULL, | |
1198 | (GtsArgGetFunc) NULL | |
1199 | }; | |
1200 | klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_function_spatial_class ()), | |
1201 | &gfs_function_info); | |
1202 | } | |
1203 | ||
1204 | return klass; | |
1176 | 1205 | } |
1177 | 1206 | |
1178 | 1207 | /* GfsFunctionConstant: object */ |
134 | 134 | GfsFunctionClass * gfs_function_spatial_class (void); |
135 | 135 | GfsFunction * gfs_function_spatial_new (GfsFunctionClass * klass, |
136 | 136 | GfsFunctionSpatialFunc func); |
137 | gdouble gfs_function_spatial_value (GfsFunction * f, FttVector * p); | |
137 | gdouble gfs_function_spatial_value (GfsFunction * f, const FttVector * p); | |
138 | ||
139 | /* GfsFunctionMap: Header */ | |
140 | ||
141 | #define GFS_IS_FUNCTION_MAP(obj) (gts_object_is_from_class (obj,\ | |
142 | gfs_function_map_class ())) | |
143 | ||
144 | GfsFunctionClass * gfs_function_map_class (void); | |
138 | 145 | |
139 | 146 | /* GfsFunctionConstant: Header */ |
140 | 147 |