source: trunk/anuga_work/development/2010-projects/anuga_1d/sqpipe/sqpipe_default.h @ 8274

Last change on this file since 8274 was 8274, checked in by paul, 12 years ago

Fixed loss of mass in sqpipe and rearranged code a little

File size: 5.5 KB
Line 
1#include "sqpipe.h"
2
3/**********************************************************
4Square pipe default quantity class
5**********************************************************/
6
7struct sqpipe_default_quantity {
8  struct sqpipe_quantity super;
9};
10
11// Construction
12void sqpipe_default_quantity_init (struct sqpipe_default_quantity *q);
13struct sqpipe_default_quantity *sqpipe_default_quantity_new();
14
15// Destruction
16
17// Methods
18
19// Implementation
20void sqpipe_default_quantity_init (struct sqpipe_default_quantity *q) {
21  struct sqpipe_quantity *p = (struct sqpipe_quantity *)q;
22
23  sqpipe_quantity_init(p); 
24}
25
26struct sqpipe_default_quantity *sqpipe_default_quantity_new() {
27  struct sqpipe_default_quantity *p = malloc(sizeof(struct sqpipe_default_quantity));
28
29  sqpipe_default_quantity_init(p);
30
31  return p;
32}
33/**********************************************************/
34
35
36/**********************************************************
37Square pipe default edge class
38**********************************************************/
39struct sqpipe_default_edge {
40  struct sqpipe_edge super;
41};
42
43// Construction
44void sqpipe_default_edge_init (struct sqpipe_default_edge *e);
45struct sqpipe_default_edge *sqpipe_default_edge_new();
46
47// Destruction
48
49// Methods
50
51// Implementation
52void sqpipe_default_edge_init (struct sqpipe_default_edge *q) {
53  sqpipe_edge_init((struct sqpipe_edge *)q);
54}
55
56struct sqpipe_default_edge *sqpipe_default_edge_new() {
57  struct sqpipe_default_edge *e = (struct sqpipe_default_edge *) sqpipe_edge_new();
58
59  sqpipe_default_edge_init(e);
60
61  // Create inner and outer quantities
62  ((struct edge *)e)->qin = (struct quantity *)sqpipe_default_quantity_new();
63  ((struct edge *)e)->qout = (struct quantity *)sqpipe_default_quantity_new();
64 
65  return e;
66}
67/**********************************************************/
68
69
70/**********************************************************
71Square pipe default cell class
72**********************************************************/
73struct sqpipe_default_cell {
74  struct sqpipe_cell super;
75};
76
77// Construction
78void sqpipe_default_cell_init (struct sqpipe_default_cell *e);
79struct sqpipe_default_cell *sqpipe_default_cell_new();
80
81// Destruction
82
83// Methods
84
85// Implementation
86void sqpipe_default_cell_init (struct sqpipe_default_cell *c) {
87  struct sqpipe_cell *p = (struct sqpipe_cell *) c;
88
89  sqpipe_cell_init(p);
90}
91
92struct sqpipe_default_cell *sqpipe_default_cell_new() {
93  int i;
94  struct sqpipe_default_cell *c = malloc(sizeof(struct sqpipe_default_cell));
95
96  // Allocate memory for a length 2 array of pointers to edges
97  ((struct cell *)c)->edges = (struct edge  **) malloc(2 * sizeof(struct sqpipe_edge *));
98
99  sqpipe_default_cell_init(c);
100
101  // Create edges
102  for (i=0; i<((struct cell *)c)->num_edges; i++) {
103    ((struct cell *)c)->edges[i] = (struct edge *) sqpipe_default_edge_new();
104  }
105
106  return c;
107}
108/**********************************************************/
109
110
111/**********************************************************
112Square pipe default quantities class
113**********************************************************/
114struct sqpipe_default_quantities {
115  struct sqpipe_quantities super;
116};
117
118// Construction
119void sqpipe_default_quantities_init (struct sqpipe_default_quantities *q);
120struct sqpipe_default_quantities *sqpipe_default_quantities_new();
121
122// Destruction
123
124// Methods
125
126// Implementation
127void sqpipe_default_quantities_init (struct sqpipe_default_quantities *q) {
128  struct sqpipe_quantities *p = (struct sqpipe_quantities *)q;
129
130  sqpipe_quantities_init(p);
131}
132
133struct sqpipe_default_quantities *sqpipe_default_quantities_new() {
134  struct sqpipe_default_quantities *p = (struct sqpipe_default_quantities *) sqpipe_quantities_new();
135
136  sqpipe_default_quantities_init(p);
137
138  return p;
139}
140/**********************************************************/
141
142
143/**********************************************************
144Square pipe default domain class
145**********************************************************/
146
147struct sqpipe_default_domain {
148  struct sqpipe_domain super;
149};
150
151// Construction
152void sqpipe_default_domain_init (struct sqpipe_default_domain *d);
153struct sqpipe_default_domain *sqpipe_default_domain_new();
154
155// Destruction
156
157// Methods
158struct edge* sqpipe_default_domain_new_edge(struct domain *d);
159struct cell* sqpipe_default_domain_new_cell(struct domain *d);
160
161// Implementation
162struct edge* sqpipe_default_domain_new_edge(struct domain *d) {
163  struct edge *e = (struct edge*) sqpipe_default_edge_new();
164
165  return e;
166}
167
168struct cell* sqpipe_default_domain_new_cell(struct domain *d) {
169  struct cell *c = (struct cell*) sqpipe_default_cell_new();
170  return c;
171}
172
173void sqpipe_default_domain_init (struct sqpipe_default_domain *d) {
174  struct sqpipe_domain *p = (struct sqpipe_domain *)d;
175
176  sqpipe_domain_init(p);
177
178  static struct domain_vtable vtable = {
179    &sqpipe_default_domain_new_edge,
180    &sqpipe_default_domain_new_cell,
181    &domain_compute_fluxes_cells_generic,
182    &sqpipe_domain_get_cell,
183    &sqpipe_domain_destroy
184  };
185  p->super.vtable = &vtable;
186}
187
188struct sqpipe_default_domain *sqpipe_default_domain_new() {
189  struct sqpipe_default_domain *d = (struct sqpipe_default_domain *) sqpipe_domain_new();
190
191  sqpipe_default_domain_init(d);
192
193  ((struct domain *) d)->vertex_values = (struct quantities *) sqpipe_default_quantities_new();
194  ((struct domain *) d)->boundary_values = (struct quantities *) sqpipe_default_quantities_new();
195  ((struct domain *) d)->explicit_update = (struct quantities *) sqpipe_default_quantities_new();
196
197  return d;
198}
199/**********************************************************/
Note: See TracBrowser for help on using the repository browser.