wbox.h 10.4 KB
Newer Older
1
2
3
4
5
6
#include <complex.h> // todo: create gcc g++ compatibility. See wdata, winterp, wderiv for template
#include <stdio.h>
#include <stdlib.h>

typedef struct
{
Andrzej's avatar
Andrzej committed
7
8
9
10
11
    int ax;
    int ay;
    int az;

    int dim;
12
} wbox_insert_t;
Andrzej MakowskI's avatar
Andrzej MakowskI committed
13
14
15
16
17
18
19
20
21

typedef struct
{
    int nx;
    int ny;
    int nz;

    int dim;

Andrzej's avatar
Andrzej committed
22
23
    char datatype;

Andrzej MakowskI's avatar
Andrzej MakowskI committed
24
25
26
27
28
    void *data;
} wbox_md_t;

// SUCCESS
#define WBOX_SUCCESS_INIT EXIT_SUCCESS
29

Andrzej MakowskI's avatar
Andrzej MakowskI committed
30
#define WBOX_SUCCESS_INSERT EXIT_SUCCESS
Andrzej's avatar
Andrzej committed
31
#define WBOX_SUCCESS_INSERT_INIT EXIT_SUCCESS
32
33
#define WBOX_SUCCESS_INSERT_CHECK EXIT_SUCCESS

Andrzej MakowskI's avatar
Andrzej MakowskI committed
34
#define WBOX_SUCCESS_MERGE EXIT_SUCCESS
35

Andrzej MakowskI's avatar
Andrzej MakowskI committed
36
37
#define WBOX_SUCCESS_ROTATE EXIT_SUCCESS

Andrzej's avatar
Andrzej committed
38
39
#define WBOX_SUCCESS_PRINT EXIT_SUCCESS

Andrzej MakowskI's avatar
Andrzej MakowskI committed
40
41
// ERRORS
#define WBOX_ERR_INIT_DIM 0001
42
43
#define WBOX_ERR_INIT_DATATYPE_NOT_IMPLEMENTED 0002

Andrzej MakowskI's avatar
Andrzej MakowskI committed
44
#define WBOX_ERR_INSERT 1000
Andrzej's avatar
Andrzej committed
45
46
47
48
49
#define WBOX_ERR_INSERT_INIT_AX_MONE 1001 // Error that is produced by `wbox_insert_init()` function and is connected to the case when `nx` parameter is equal `-1`
#define WBOX_ERR_INSERT_CHECK_DIM 1002    // Error that is produed by `wbox_insert_check()` function. Dimension of small and big box is different
#define WBOX_ERR_INSERT_1D 1003
#define WBOX_ERR_INSERT_2D 1004
#define WBOX_ERR_INSERT_3D 1005
50

Andrzej MakowskI's avatar
Andrzej MakowskI committed
51
#define WBOX_ERR_MERGE 2000
52

Andrzej MakowskI's avatar
Andrzej MakowskI committed
53
54
#define WBOX_ERR_ROTATE 3000

Andrzej's avatar
Andrzej committed
55
56
#define WBOX_ERR_PRINT_DIM 4000 // Error that is produced by `wbox_print()` function and is connected to not dimensionality of the data other than 1, 2 or 3.

57
/**
Andrzej's avatar
Andrzej committed
58
 * @brief Function to initialize lattice. Function initializes the lattice.
59
 *
Andrzej's avatar
Andrzej committed
60
61
62
63
64
65
66
 * @param wbmd [out] - pointer to WBox metadata structure. Each WBox structure is responsible for only one variable, like rho_a.
 * @param nx [in] - number of lattice points in OX direction. If `<0` then return `WBOX_ERR_INIT_DIM`
 * @param ny [in] - number of lattice points in OY direction. If `<0` then dimension is `1` and only iterates over OX axis
 * @param nz [in] - number of lattice points in OZ direction. If `<0` then dimension is `2` and iterates over OX and OY axis
 * @param datatype [in] - character describing type of data. Can be 'i'nteger, 'r'eal (double), 'c'omplex (double complex).
 * @param data [in] - pointer to a data of `datatype` type.
 * @return `WBOX_SUCCESS_INIT` or `WBOX_ERR_INIT` with help description.
67
68
69
 */
int wbox_init(wbox_md_t *wbmd, const int nx, const int ny, const int nz, const char datatype, const void *data);

Andrzej's avatar
Andrzej committed
70
71
/* ***************************************************************************************** */
/* ***************************************************************************************** */
72
/**
Andrzej's avatar
Andrzej committed
73
74
75
76
77
78
79
80
81
82
83
84
85
 * @brief Function that initializes insert parameters.
 *
 * @param wbox_insert [out] - `wbox_insert_t` type that stores the infromation about the anchor.
 * @param ax [in] - anchor for NX lattice value. If `-1` then ignored and `WBOX_ERR_INSERT_INIT` is returned.
 * @param ay [in] - anchor for NY lattice value. If `-1` then ignored and `wbox_insert_1d` should be executed.
 * @param az [in] - anchor for NZ lattice value. If `-1` then ignored and `wbox_insert_2d` should be executed.
 * @return `WBOX_SUCCESS_INSERT_INIT` or `WBOX_ERR_INSERT_INIT` whith help description.
 */
int wbox_insert_init(wbox_insert_t *wbox_insert, const int ax, const int ay, const int az);

/**
 * @brief Master function that inserts data from smaller box (`wmbd`) into the bigger box(`wmbd_big`) that is anchored in `wbox_insert`.
 * Function checks the anchor placements. First checks the dimension of box and places calls adequate insert function.
86
 *
Andrzej's avatar
Andrzej committed
87
88
89
90
 * @param wbmd_small [in] - `wbox_md_t` type that stores the information about data from small box.
 * @param wbox_insert [in] - `wbox_insert_t` type that stores the information about the anchor point.
 * @param wbmd_big [out] - `wbox_md_t` type that stores the information about data from big box.
 * @return `WBOX_SUCCESS_INSERT` or `WBOX_ERR_INSERT` with help description.
91
 */
Andrzej's avatar
Andrzej committed
92
int wbox_insert(const wbox_md_t *wbmd_small, const wbox_insert_t *wbox_insert, wbox_md_t *wbmd_big);
93

Daniel Pecak's avatar
Daniel Pecak committed
94
95

/**
96
97
 * @brief Function that calculates average over the boundaries of the box (`wmbd`).
 * It works for 1D, 2D, and 3D.
Daniel Pecak's avatar
Daniel Pecak committed
98
 *
99
100
 * @param wbmd [in] - `wbox_md_t` type that stores the information about data from box.
 * @return the average value of integer data
Daniel Pecak's avatar
Daniel Pecak committed
101
 */
102
int wbox_boundary_avg_int(wbox_md_t *wbmd);
Daniel Pecak's avatar
Daniel Pecak committed
103

104
105
106
107
108
109
110
111
/**
 * @brief Function that calculates average over the boundaries of the box (`wmbd`).
 * It works for 1D, 2D, and 3D.
 *
 * @param wbmd [in] - `wbox_md_t` type that stores the information about data from box.
 * @return the average value of double data
 */
double wbox_boundary_avg_double(wbox_md_t *wbmd);
Daniel Pecak's avatar
Daniel Pecak committed
112

113
114
115
116
117
118
119
120
/**
 * @brief Function that calculates average over the boundaries of the box (`wmbd`).
 * It works for 1D, 2D, and 3D.
 *
 * @param wbmd [in] - `wbox_md_t` type that stores the information about data from box.
 * @return the average value of complex data
 */
double complex wbox_boundary_avg_complex(wbox_md_t *wbmd);
Daniel Pecak's avatar
Daniel Pecak committed
121

Daniel Pecak's avatar
Daniel Pecak committed
122

123
/**
Andrzej's avatar
Andrzej committed
124
 * @brief Function that inserts data from smaller 1D box (`wmbd`) into the 1D bigger box(`wmbd_big`) that is anchored in `wbox_insert`.
125
126
 * Function checks the anchor placements.
 *
Andrzej's avatar
Andrzej committed
127
128
129
130
 * @param wbmd_small [in] - `wbox_md_t` type that stores the information about data from small box.
 * @param wbox_insert [in] - `wbox_insert_t` type that stores the information about the anchor point.
 * @param wbmd_big [out] - `wbox_md_t` type that stores the information about data from big box.
 * @return `WBOX_SUCCESS_INSERT` or `WBOX_ERR_INSERT` with help description.
131
 */
Andrzej's avatar
Andrzej committed
132
int wbox_insert_1d(const wbox_md_t *wbmd_small, const wbox_insert_t *wbox_insert, wbox_md_t *wbmd_big);
Andrzej MakowskI's avatar
Andrzej MakowskI committed
133

134
/**
Andrzej's avatar
Andrzej committed
135
 * @brief Function that inserts data from smaller 2D box (`wmbd`) into the 2D bigger box(`wmbd_big`) that is anchored in `wbox_insert`.
136
137
 * Function checks the anchor placements.
 *
Andrzej's avatar
Andrzej committed
138
139
140
141
 * @param wbmd_small [in] - `wbox_md_t` type that stores the information about data from small box.
 * @param wbox_insert [in] - `wbox_insert_t` type that stores the information about the anchor point.
 * @param wbmd_big [out] - `wbox_md_t` type that stores the information about data from big box.
 * @return `WBOX_SUCCESS_INSERT` or `WBOX_ERR_INSERT` with help description.
142
 */
Andrzej's avatar
Andrzej committed
143
int wbox_insert_2d(const wbox_md_t *wbmd_small, const wbox_insert_t *wbox_insert, wbox_md_t *wbmd_big);
144
145

/**
Andrzej's avatar
Andrzej committed
146
147
 * @brief Function that inserts data from smaller 3D box (`wmbd`) into the 3D bigger box(`wmbd_big`) that is anchored in `wbox_insert`.
 * Function checks the anchor placements.
Andrzej's avatar
Andrzej committed
148
149
150
151
152
153
 *
 * @param wbmd_small [in] - `wbox_md_t` type that stores the information about data from small box.
 * @param wbox_insert [in] - `wbox_insert_t` type that stores the information about the anchor point.
 * @param wbmd_big [out] - `wbox_md_t` type that stores the information about data from big box.
 * @return `WBOX_SUCCESS_INSERT` or `WBOX_ERR_INSERT` with help description.
 */
Andrzej's avatar
Andrzej committed
154
int wbox_insert_3d(const wbox_md_t *wbmd_small, const wbox_insert_t *wbox_insert, wbox_md_t *wbmd_big);
155
156
157
158

/**
 * @brief Function that checks the possible errors for inserting a data from small box into big box.
 *
Andrzej's avatar
Andrzej committed
159
160
161
162
 * @param wbmd_small [in] - `wbox_md_t` type that stores the information about data from small box.
 * @param wbox_insert [in] - `wbox_insert_t` type that stores the information about the anchor point.
 * @param wbmd_big [out] - `wbox_md_t` type that stores the information about data from big box.
 * @return `WBOX_SUCCESS_INSERT_CHECK` or `WBOX_ERR_INSERT_CHECK` with help description.
163
 */
Andrzej's avatar
Andrzej committed
164
int wbox_insert_check(const wbox_md_t *wbmd_small, const wbox_insert_t *wbox_insert, const wbox_md_t *wbmd_big);
Andrzej MakowskI's avatar
Andrzej MakowskI committed
165

Andrzej's avatar
Andrzej committed
166
167
/* ***************************************************************************************** */
/* ***************************************************************************************** */
Andrzej's avatar
Andrzej committed
168
int wbox_merge(const wbox_md_t *wbmd_one, const wbox_md_t *wbmd_two, wbox_md_t *wbmd_result);
Andrzej's avatar
Andrzej committed
169
170
171
int wbox_merge_1d(const wbox_md_t *wbmd_one, const wbox_md_t *wbmd_two, wbox_md_t *wbmd_result);
int wbox_merge_2d(const wbox_md_t *wbmd_one, const wbox_md_t *wbmd_two, wbox_md_t *wbmd_result);
int wbox_merge_3d(const wbox_md_t *wbmd_one, const wbox_md_t *wbmd_two, wbox_md_t *wbmd_result);
Andrzej MakowskI's avatar
Andrzej MakowskI committed
172

Andrzej's avatar
Andrzej committed
173
174
/* ***************************************************************************************** */
/* ***************************************************************************************** */
Andrzej's avatar
Andrzej committed
175
176
int wbox_rotate_2d(wbox_md_t *wbmd);
int wbox_rotate_3d(wbox_md_t *wbmd);
Andrzej MakowskI's avatar
Andrzej MakowskI committed
177
int wbox_rotate(wbox_md_t *wbmd);
Andrzej's avatar
Andrzej committed
178
179
180

/* ***************************************************************************************** */
/* ***************************************************************************************** */
Andrzej's avatar
Andrzej committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
 * @brief Master function that prints data in terminal
 *
 * @param wbmd [in] - pointer to data that one wants to be printed
 * @param title [in] - char pointer with a title, eg. "WBOX SMALL"
 * @return `WBOX_SUCCESS_PRINT` or `WBOX_ERR_PRINT` with a help description
 */
int wbox_print(const wbox_md_t *wbmd, const char *title);

/**
 * @brief Function that prints data in terminal for 1D data
 *
 * @param wbmd [in] - pointer to data that one wants to be printed
 * @param title [in] - char pointer with a title, eg. "WBOX SMALL"
 * @return `WBOX_SUCCESS_PRINT` or `WBOX_ERR_PRINT` with a help description
 */
Andrzej's avatar
Andrzej committed
197
int wbox_print_1d(const wbox_md_t *wbmd, const char *title);
Andrzej's avatar
Andrzej committed
198
199
200
201
202
203
204
205

/**
 * @brief Function that prints data in terminal for 2D data
 *
 * @param wbmd [in] - pointer to data that one wants to be printed
 * @param title [in] - char pointer with a title, eg. "WBOX SMALL"
 * @return `WBOX_SUCCESS_PRINT` or `WBOX_ERR_PRINT` with a help description
 */
Andrzej's avatar
Andrzej committed
206
int wbox_print_2d(const wbox_md_t *wbmd, const char *title);
Andrzej's avatar
Andrzej committed
207
208
209
210
211
212
213
214

/**
 * @brief Function that prints data in terminal for 3D data
 *
 * @param wbmd [in] - pointer to data that one wants to be printed
 * @param title [in] - char pointer with a title, eg. "WBOX SMALL"
 * @return `WBOX_SUCCESS_PRINT` or `WBOX_ERR_PRINT` with a help description
 */
Andrzej's avatar
Andrzej committed
215
int wbox_print_3d(const wbox_md_t *wbmd, const char *title);
Andrzej's avatar
Andrzej committed
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

/**
 * @brief Function that prints `wbox_md_t` struct in terminal
 *
 * @param wbmd [in] - pointer to `wbox_md_t` that one wants to be printed
 * @param title [in] - char pointer with a title, eg. "WBOX SMALL"
 * @return `WBOX_SUCCESS_PRINT` or `WBOX_ERR_PRINT` with a help description
 */
int wbox_print_box_params(const wbox_md_t wbmd, const char *title);

/**
 * @brief Function that prints `wbox_insert_t` struct in terminal
 *
 * @param wb_insert [in] - pointer to `wbox_insert_t` struct that one wants to be printed
 * @return `WBOX_SUCCESS_PRINT` or `WBOX_ERR_PRINT` with a help description
 */
int wbox_print_insert_params(const wbox_insert_t wb_insert);