source: trunk/anuga_work/development/2010-projects/anuga_1d/sqpipe/sqpipe_dual_fixed_width_a_d.h @ 8236

Last change on this file since 8236 was 8236, checked in by paul, 13 years ago

Implemented generic solver and several versions of square pipe domain

File size: 10.2 KB
Line 
1#include "sqpipe.h"
2
3/**********************************************************
4Square pipe dual fixed width quantity class
5**********************************************************/
6
7struct sqpipe_dual_fixed_width_a_d_quantity {
8  struct sqpipe_quantity super;
9  long state;
10};
11
12// Construction
13void sqpipe_dual_fixed_width_a_d_quantity_init (struct sqpipe_dual_fixed_width_a_d_quantity *q);
14struct sqpipe_dual_fixed_width_a_d_quantity *sqpipe_dual_fixed_width_a_d_quantity_new();
15
16// Destruction
17
18// Methods
19double* sqpipe_dual_fixed_width_a_d_quantity_flux_formula (struct quantity *q, double normal, struct params *p, double *quantityflux);
20double sqpipe_dual_fixed_width_a_d_quantity_sound_speed (struct quantity *q, struct params *p);
21double sqpipe_dual_fixed_width_a_d_quantity_get_conserved (struct quantity *q, int k, double normal);
22
23// Implementation
24double* 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
32double 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
40double 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
58void 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
74struct 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/**********************************************************
85Square pipe dual fixed width edge class
86**********************************************************/
87struct sqpipe_dual_fixed_width_a_d_edge {
88  struct sqpipe_edge super;
89};
90
91// Construction
92void sqpipe_dual_fixed_width_a_d_edge_init (struct sqpipe_dual_fixed_width_a_d_edge *e);
93struct 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
101void 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
105struct 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/**********************************************************
120Square pipe dual fixed width cell class
121**********************************************************/
122struct sqpipe_dual_fixed_width_a_d_cell {
123  struct sqpipe_cell super;
124
125  long state;
126};
127
128// Construction
129void sqpipe_dual_fixed_width_a_d_cell_init (struct sqpipe_dual_fixed_width_a_d_cell *e);
130struct sqpipe_dual_fixed_width_a_d_cell *sqpipe_dual_fixed_width_a_d_cell_new();
131
132// Destruction
133
134// Methods
135double* sqpipe_dual_fixed_width_a_d_cell_forcing_terms (struct cell *c, struct params *p, double *cellforce);
136
137// Implementation
138double* 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
146void 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
162struct 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/**********************************************************
182Square pipe dual fixed width quantities class
183**********************************************************/
184struct sqpipe_dual_fixed_width_a_d_quantities {
185  struct sqpipe_quantities super;
186};
187
188// Construction
189void sqpipe_dual_fixed_width_a_d_quantities_init (struct sqpipe_dual_fixed_width_a_d_quantities *q);
190struct sqpipe_dual_fixed_width_a_d_quantities *sqpipe_dual_fixed_width_a_d_quantities_new();
191
192// Destruction
193
194// Methods
195void sqpipe_dual_fixed_width_a_d_quantities_update (struct quantities *qs, double *flux, int k);
196
197
198// Implementation
199void 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
205void 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
218struct 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/**********************************************************
229Square pipe free surface fixed width domain class
230**********************************************************/
231
232struct sqpipe_dual_fixed_width_a_d_domain {
233  struct sqpipe_domain super;
234  long *state;
235};
236
237// Construction
238void sqpipe_dual_fixed_width_a_d_domain_init (struct sqpipe_dual_fixed_width_a_d_domain *d);
239struct sqpipe_dual_fixed_width_a_d_domain *sqpipe_dual_fixed_width_a_d_domain_new();
240
241// Destruction
242
243// Methods
244struct edge* sqpipe_dual_fixed_width_a_d_domain_new_edge(struct domain *d);
245struct cell* sqpipe_dual_fixed_width_a_d_domain_new_cell(struct domain *d);
246struct cell* sqpipe_dual_fixed_width_a_d_domain_get_cell(struct domain *D, int k, struct cell *c);
247
248// Implementation
249struct 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
255struct 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
260struct 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
277void 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
294struct 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/**********************************************************/
Note: See TracBrowser for help on using the repository browser.