1 | #include "sqpipe.h" |
---|
2 | |
---|
3 | /********************************************************** |
---|
4 | Square pipe dual fixed width quantity class |
---|
5 | **********************************************************/ |
---|
6 | |
---|
7 | struct sqpipe_dual_fixed_width_a_d_quantity { |
---|
8 | struct sqpipe_quantity super; |
---|
9 | long state; |
---|
10 | }; |
---|
11 | |
---|
12 | // Construction |
---|
13 | void sqpipe_dual_fixed_width_a_d_quantity_init (struct sqpipe_dual_fixed_width_a_d_quantity *q); |
---|
14 | struct sqpipe_dual_fixed_width_a_d_quantity *sqpipe_dual_fixed_width_a_d_quantity_new(); |
---|
15 | |
---|
16 | // Destruction |
---|
17 | |
---|
18 | // Methods |
---|
19 | double* sqpipe_dual_fixed_width_a_d_quantity_flux_formula (struct quantity *q, double normal, struct params *p, double *quantityflux); |
---|
20 | double sqpipe_dual_fixed_width_a_d_quantity_sound_speed (struct quantity *q, struct params *p); |
---|
21 | double sqpipe_dual_fixed_width_a_d_quantity_get_conserved (struct quantity *q, int k, double normal); |
---|
22 | |
---|
23 | // Implementation |
---|
24 | double* sqpipe_dual_fixed_width_a_d_quantity_flux_formula (struct quantity *q, double normal, struct params *p, double *quantityflux) { |
---|
25 | if (((struct sqpipe_dual_fixed_width_a_d_quantity *)q)->state == 0) { |
---|
26 | return sqpipe_quantity_free_surface_flux_formula(q, normal, p, quantityflux); |
---|
27 | } else { |
---|
28 | return sqpipe_quantity_pressurised_flux_formula(q, normal, p, quantityflux); |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | double sqpipe_dual_fixed_width_a_d_quantity_sound_speed (struct quantity *q, struct params *p) { |
---|
33 | if (((struct sqpipe_dual_fixed_width_a_d_quantity *)q)->state == 0) { |
---|
34 | return sqpipe_quantity_free_surface_sound_speed(q, p); |
---|
35 | } else { |
---|
36 | return sqpipe_quantity_pressurised_sound_speed(q, p); |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | double sqpipe_dual_fixed_width_a_d_quantity_get_conserved (struct quantity *q, int k, double normal) { |
---|
41 | struct sqpipe_quantity *p = (struct sqpipe_quantity*) q; |
---|
42 | double c; |
---|
43 | |
---|
44 | switch (k) { |
---|
45 | case 0: |
---|
46 | c = p->a; |
---|
47 | break; |
---|
48 | case 1: |
---|
49 | // This should be normal^2 p->d and normal is +/- 1 |
---|
50 | c = p->d; |
---|
51 | break; |
---|
52 | default: |
---|
53 | c = 0; |
---|
54 | } |
---|
55 | return c; |
---|
56 | } |
---|
57 | |
---|
58 | void sqpipe_dual_fixed_width_a_d_quantity_init (struct sqpipe_dual_fixed_width_a_d_quantity *q) { |
---|
59 | struct sqpipe_quantity *p = (struct sqpipe_quantity *)q; |
---|
60 | |
---|
61 | sqpipe_quantity_init(p); |
---|
62 | |
---|
63 | static struct quantity_vtable vtable = { |
---|
64 | &sqpipe_dual_fixed_width_a_d_quantity_flux_formula, |
---|
65 | &sqpipe_dual_fixed_width_a_d_quantity_sound_speed, |
---|
66 | &sqpipe_dual_fixed_width_a_d_quantity_get_conserved, |
---|
67 | &sqpipe_quantity_destroy |
---|
68 | }; |
---|
69 | p->super.vtable = &vtable; |
---|
70 | |
---|
71 | ((struct sqpipe_dual_fixed_width_a_d_quantity *)p)->state = 0; |
---|
72 | } |
---|
73 | |
---|
74 | struct sqpipe_dual_fixed_width_a_d_quantity *sqpipe_dual_fixed_width_a_d_quantity_new() { |
---|
75 | struct sqpipe_dual_fixed_width_a_d_quantity *p = malloc(sizeof(struct sqpipe_dual_fixed_width_a_d_quantity)); |
---|
76 | |
---|
77 | sqpipe_dual_fixed_width_a_d_quantity_init(p); |
---|
78 | |
---|
79 | return p; |
---|
80 | } |
---|
81 | /**********************************************************/ |
---|
82 | |
---|
83 | |
---|
84 | /********************************************************** |
---|
85 | Square pipe dual fixed width edge class |
---|
86 | **********************************************************/ |
---|
87 | struct sqpipe_dual_fixed_width_a_d_edge { |
---|
88 | struct sqpipe_edge super; |
---|
89 | }; |
---|
90 | |
---|
91 | // Construction |
---|
92 | void sqpipe_dual_fixed_width_a_d_edge_init (struct sqpipe_dual_fixed_width_a_d_edge *e); |
---|
93 | struct sqpipe_dual_fixed_width_a_d_edge *sqpipe_dual_fixed_width_a_d_edge_new(); |
---|
94 | |
---|
95 | // Destruction |
---|
96 | |
---|
97 | // Methods |
---|
98 | |
---|
99 | // Implementation |
---|
100 | |
---|
101 | void sqpipe_dual_fixed_width_a_d_edge_init (struct sqpipe_dual_fixed_width_a_d_edge *q) { |
---|
102 | sqpipe_edge_init((struct sqpipe_edge *)q); |
---|
103 | } |
---|
104 | |
---|
105 | struct sqpipe_dual_fixed_width_a_d_edge *sqpipe_dual_fixed_width_a_d_edge_new() { |
---|
106 | struct sqpipe_dual_fixed_width_a_d_edge *e = (struct sqpipe_dual_fixed_width_a_d_edge *) sqpipe_edge_new(); |
---|
107 | |
---|
108 | sqpipe_dual_fixed_width_a_d_edge_init(e); |
---|
109 | |
---|
110 | // Create inner and outer quantities |
---|
111 | ((struct edge *)e)->qin = (struct quantity *)sqpipe_dual_fixed_width_a_d_quantity_new(); |
---|
112 | ((struct edge *)e)->qout = (struct quantity *)sqpipe_dual_fixed_width_a_d_quantity_new(); |
---|
113 | |
---|
114 | return e; |
---|
115 | } |
---|
116 | /**********************************************************/ |
---|
117 | |
---|
118 | |
---|
119 | /********************************************************** |
---|
120 | Square pipe dual fixed width cell class |
---|
121 | **********************************************************/ |
---|
122 | struct sqpipe_dual_fixed_width_a_d_cell { |
---|
123 | struct sqpipe_cell super; |
---|
124 | |
---|
125 | long state; |
---|
126 | }; |
---|
127 | |
---|
128 | // Construction |
---|
129 | void sqpipe_dual_fixed_width_a_d_cell_init (struct sqpipe_dual_fixed_width_a_d_cell *e); |
---|
130 | struct sqpipe_dual_fixed_width_a_d_cell *sqpipe_dual_fixed_width_a_d_cell_new(); |
---|
131 | |
---|
132 | // Destruction |
---|
133 | |
---|
134 | // Methods |
---|
135 | double* sqpipe_dual_fixed_width_a_d_cell_forcing_terms (struct cell *c, struct params *p, double *cellforce); |
---|
136 | |
---|
137 | // Implementation |
---|
138 | double* sqpipe_dual_fixed_width_a_d_cell_forcing_terms (struct cell *c, struct params *p, double *cellforce) { |
---|
139 | if (((struct sqpipe_dual_fixed_width_a_d_cell *)c)->state == 0) { |
---|
140 | return sqpipe_cell_free_surface_forcing_terms(c, p, cellforce); |
---|
141 | } else { |
---|
142 | return sqpipe_cell_pressurised_forcing_terms(c, p, cellforce); |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | void sqpipe_dual_fixed_width_a_d_cell_init (struct sqpipe_dual_fixed_width_a_d_cell *q) { |
---|
147 | struct sqpipe_cell *p = (struct sqpipe_cell *) q; |
---|
148 | |
---|
149 | sqpipe_cell_init(p); |
---|
150 | |
---|
151 | static struct cell_vtable vtable = { |
---|
152 | &cell_flux_function_generic, |
---|
153 | &sqpipe_cell_extreme_sound_speeds, |
---|
154 | &sqpipe_dual_fixed_width_a_d_cell_forcing_terms, |
---|
155 | &sqpipe_cell_destroy |
---|
156 | }; |
---|
157 | p->super.vtable = &vtable; |
---|
158 | |
---|
159 | ((struct sqpipe_dual_fixed_width_a_d_cell *)p)->state = 0; |
---|
160 | } |
---|
161 | |
---|
162 | struct sqpipe_dual_fixed_width_a_d_cell *sqpipe_dual_fixed_width_a_d_cell_new() { |
---|
163 | int i; |
---|
164 | struct sqpipe_dual_fixed_width_a_d_cell *c = malloc(sizeof(struct sqpipe_dual_fixed_width_a_d_cell)); |
---|
165 | |
---|
166 | // Allocate memory for a length 2 array of pointers to edges |
---|
167 | ((struct cell *)c)->edges = (struct edge **) malloc(2 * sizeof(struct sqpipe_edge *)); |
---|
168 | |
---|
169 | sqpipe_dual_fixed_width_a_d_cell_init(c); |
---|
170 | |
---|
171 | // Create edges |
---|
172 | for (i=0; i<((struct cell *)c)->num_edges; i++) { |
---|
173 | ((struct cell *)c)->edges[i] = (struct edge *) sqpipe_dual_fixed_width_a_d_edge_new(); |
---|
174 | } |
---|
175 | |
---|
176 | return c; |
---|
177 | } |
---|
178 | /**********************************************************/ |
---|
179 | |
---|
180 | |
---|
181 | /********************************************************** |
---|
182 | Square pipe dual fixed width quantities class |
---|
183 | **********************************************************/ |
---|
184 | struct sqpipe_dual_fixed_width_a_d_quantities { |
---|
185 | struct sqpipe_quantities super; |
---|
186 | }; |
---|
187 | |
---|
188 | // Construction |
---|
189 | void sqpipe_dual_fixed_width_a_d_quantities_init (struct sqpipe_dual_fixed_width_a_d_quantities *q); |
---|
190 | struct sqpipe_dual_fixed_width_a_d_quantities *sqpipe_dual_fixed_width_a_d_quantities_new(); |
---|
191 | |
---|
192 | // Destruction |
---|
193 | |
---|
194 | // Methods |
---|
195 | void sqpipe_dual_fixed_width_a_d_quantities_update (struct quantities *qs, double *flux, int k); |
---|
196 | |
---|
197 | |
---|
198 | // Implementation |
---|
199 | void sqpipe_dual_fixed_width_a_d_quantities_update (struct quantities *qs, double *flux, int k) { |
---|
200 | struct sqpipe_quantities *ps = (struct sqpipe_quantities *) qs; |
---|
201 | ps->a[k] = flux[0]; |
---|
202 | ps->d[k] = flux[1]; |
---|
203 | } |
---|
204 | |
---|
205 | void sqpipe_dual_fixed_width_a_d_quantities_init (struct sqpipe_dual_fixed_width_a_d_quantities *q) { |
---|
206 | struct sqpipe_quantities *p = (struct sqpipe_quantities *)q; |
---|
207 | |
---|
208 | sqpipe_quantities_init(p); |
---|
209 | |
---|
210 | static struct quantities_vtable vtable = { |
---|
211 | &sqpipe_quantities_get_quantity, |
---|
212 | &sqpipe_dual_fixed_width_a_d_quantities_update, |
---|
213 | &sqpipe_quantities_destroy |
---|
214 | }; |
---|
215 | p->super.vtable = &vtable; |
---|
216 | } |
---|
217 | |
---|
218 | struct sqpipe_dual_fixed_width_a_d_quantities *sqpipe_dual_fixed_width_a_d_quantities_new() { |
---|
219 | struct sqpipe_dual_fixed_width_a_d_quantities *p = (struct sqpipe_dual_fixed_width_a_d_quantities *) sqpipe_quantities_new(); |
---|
220 | |
---|
221 | sqpipe_dual_fixed_width_a_d_quantities_init(p); |
---|
222 | |
---|
223 | return p; |
---|
224 | } |
---|
225 | /**********************************************************/ |
---|
226 | |
---|
227 | |
---|
228 | /********************************************************** |
---|
229 | Square pipe free surface fixed width domain class |
---|
230 | **********************************************************/ |
---|
231 | |
---|
232 | struct sqpipe_dual_fixed_width_a_d_domain { |
---|
233 | struct sqpipe_domain super; |
---|
234 | long *state; |
---|
235 | }; |
---|
236 | |
---|
237 | // Construction |
---|
238 | void sqpipe_dual_fixed_width_a_d_domain_init (struct sqpipe_dual_fixed_width_a_d_domain *d); |
---|
239 | struct sqpipe_dual_fixed_width_a_d_domain *sqpipe_dual_fixed_width_a_d_domain_new(); |
---|
240 | |
---|
241 | // Destruction |
---|
242 | |
---|
243 | // Methods |
---|
244 | struct edge* sqpipe_dual_fixed_width_a_d_domain_new_edge(struct domain *d); |
---|
245 | struct cell* sqpipe_dual_fixed_width_a_d_domain_new_cell(struct domain *d); |
---|
246 | struct cell* sqpipe_dual_fixed_width_a_d_domain_get_cell(struct domain *D, int k, struct cell *c); |
---|
247 | |
---|
248 | // Implementation |
---|
249 | struct edge* sqpipe_dual_fixed_width_a_d_domain_new_edge(struct domain *d) { |
---|
250 | struct edge *e = (struct edge*) sqpipe_dual_fixed_width_a_d_edge_new(); |
---|
251 | |
---|
252 | return e; |
---|
253 | } |
---|
254 | |
---|
255 | struct cell* sqpipe_dual_fixed_width_a_d_domain_new_cell(struct domain *d) { |
---|
256 | struct cell *c = (struct cell*) sqpipe_dual_fixed_width_a_d_cell_new(); |
---|
257 | return c; |
---|
258 | } |
---|
259 | |
---|
260 | struct cell* sqpipe_dual_fixed_width_a_d_domain_get_cell(struct domain *D, int k, struct cell *c) { |
---|
261 | struct sqpipe_dual_fixed_width_a_d_cell *sc = (struct sqpipe_dual_fixed_width_a_d_cell *) c; |
---|
262 | struct sqpipe_dual_fixed_width_a_d_domain *sD = (struct sqpipe_dual_fixed_width_a_d_domain *) D; |
---|
263 | int i; |
---|
264 | |
---|
265 | c = domain_get_cell_generic(D, k, c); |
---|
266 | |
---|
267 | // Set state |
---|
268 | sc->state = sD->state[k]; |
---|
269 | for (i = 0; i<c->num_edges; i++) { |
---|
270 | ((struct sqpipe_dual_fixed_width_a_d_quantity *)(c->edges[i]->qin))->state = sc->state; |
---|
271 | ((struct sqpipe_dual_fixed_width_a_d_quantity *)(c->edges[i]->qout))->state = sc->state; |
---|
272 | } |
---|
273 | |
---|
274 | return c; |
---|
275 | } |
---|
276 | |
---|
277 | void sqpipe_dual_fixed_width_a_d_domain_init (struct sqpipe_dual_fixed_width_a_d_domain *d) { |
---|
278 | struct sqpipe_domain *p = (struct sqpipe_domain *)d; |
---|
279 | |
---|
280 | sqpipe_domain_init(p); |
---|
281 | |
---|
282 | static struct domain_vtable vtable = { |
---|
283 | &sqpipe_dual_fixed_width_a_d_domain_new_edge, |
---|
284 | &sqpipe_dual_fixed_width_a_d_domain_new_cell, |
---|
285 | &domain_compute_fluxes_generic, |
---|
286 | &sqpipe_dual_fixed_width_a_d_domain_get_cell, |
---|
287 | &sqpipe_domain_destroy |
---|
288 | }; |
---|
289 | p->super.vtable = &vtable; |
---|
290 | |
---|
291 | ((struct sqpipe_dual_fixed_width_a_d_domain *)p)->state = NULL; |
---|
292 | } |
---|
293 | |
---|
294 | struct sqpipe_dual_fixed_width_a_d_domain *sqpipe_dual_fixed_width_a_d_domain_new() { |
---|
295 | struct sqpipe_dual_fixed_width_a_d_domain *d = (struct sqpipe_dual_fixed_width_a_d_domain *) sqpipe_domain_new(); |
---|
296 | |
---|
297 | sqpipe_dual_fixed_width_a_d_domain_init(d); |
---|
298 | |
---|
299 | ((struct domain *) d)->vertex_values = (struct quantities *) sqpipe_dual_fixed_width_a_d_quantities_new(); |
---|
300 | ((struct domain *) d)->boundary_values = (struct quantities *) sqpipe_dual_fixed_width_a_d_quantities_new(); |
---|
301 | ((struct domain *) d)->explicit_update = (struct quantities *) sqpipe_dual_fixed_width_a_d_quantities_new(); |
---|
302 | |
---|
303 | return d; |
---|
304 | } |
---|
305 | /**********************************************************/ |
---|