First partially-implemented functional release
[2dsolver.git] / src / 2dsolve.h
1 /*
2 * 2dsolve.h: headers, prototypes and declarations for 2dsolve
3 * Creation date: Fri Apr 13 23:15:04 2012
4 */
5
6 #ifndef _MAIN_APP_INCLUDE_H
7 #define _MAIN_APP_INCLUDE_H
8
9 #include <util.h> /* From util: Common utility library */
10 #include <wbmp.h> /* From sim-static: Built-in simulation library over SDL */
11 #include <draw.h> /* From sim-static: Built-in simulation library over SDL */
12 #include <matfile.h> /* From matlab: Utility functions for manipulating MATLAB data files */
13 #include <jit.h> /* For evaluating expressions */
14 #include <config.h> /* Goodies */
15
16 #ifdef HAVE_INLINE
17 # define INLINE static inline
18 #else
19 # define INLINE static
20 #endif
21
22 #include <gsl/gsl_vector.h>
23 #include <gsl/gsl_matrix.h>
24 #include <gsl/gsl_linalg.h>
25
26 #define PROBLEM_INCOMPLETE_NO_MATRIX 1
27 #define PROBLEM_INCOMPLETE_NO_VECTOR 2
28 #define PROBLEM_INCOMPLETE_NO_BOUNDS 3
29
30 #define SCREEN_WIDTH 640
31 #define SCREEN_HEIGHT 480
32
33 struct point
34 {
35 int index;
36 float x;
37 float y;
38 };
39
40 struct edge_desc
41 {
42 struct point *p1;
43 struct point *p2;
44 };
45
46 #define TRIANGLE_NODES 3
47
48 struct triangle
49 {
50 struct point *nodes[TRIANGLE_NODES];
51 };
52
53 struct geometry_info
54 {
55 PTR_LIST (struct point, point);
56 PTR_LIST (struct edge_desc, edge);
57 PTR_LIST (struct triangle, triangle);
58 };
59
60 #define BOUNDARY_CONDITION_DIRICHLET 0
61 #define BOUNDARY_CONDITION_NEUMANN 1
62
63 struct boundary_condition
64 {
65 int type;
66 float value;
67 };
68
69 #define A_11 0
70 #define A_12 1
71 #define A_21 2
72 #define A_22 3
73
74 struct problem2d
75 {
76 struct geometry_info *geometry;
77 struct jit_expr *a[4];
78 struct jit_expr *a0, *f, *g;
79
80 gsl_matrix *A;
81 gsl_vector *b;
82 gsl_vector *solution;
83
84 PTR_LIST (struct boundary_condition, boundary);
85
86 float x, y;
87 };
88
89 #include <triangle.h>
90
91 struct edge_desc *edge_desc_new (struct point *, struct point *);
92 struct point *point_new (float, float);
93 struct triangle *triangle_new (struct point *, struct point *, struct point *);
94 int build_matrix_and_vector (struct problem2d *);
95 struct geometry_info *geometry_load_from_matlab (const char *, const char *, const char *, const char *);
96 void geometry_destroy (struct geometry_info *);
97 int export_matrix_and_vector (struct problem2d *, FILE *);
98 void display_geometry (display_t *, struct geometry_info *, float);
99 struct problem2d *problem_get_sample_from_matlab (const char *);
100 int problem_lock (struct problem2d *);
101 int problem_is_incomplete (struct problem2d *);
102 int problem_solve (struct problem2d *);
103 void display_solution (display_t *, struct problem2d *, float);
104 #endif /* _MAIN_APP_INCLUDE_H */