wbox.h 7.26 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
38
39
#define WBOX_SUCCESS_ROTATE EXIT_SUCCESS

// ERRORS
#define WBOX_ERR_INIT_DIM 0001
40
41
#define WBOX_ERR_INIT_DATATYPE_NOT_IMPLEMENTED 0002

Andrzej MakowskI's avatar
Andrzej MakowskI committed
42
#define WBOX_ERR_INSERT 1000
Andrzej's avatar
Andrzej committed
43
44
45
46
47
#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
48

Andrzej MakowskI's avatar
Andrzej MakowskI committed
49
#define WBOX_ERR_MERGE 2000
50

Andrzej MakowskI's avatar
Andrzej MakowskI committed
51
52
#define WBOX_ERR_ROTATE 3000

53
/**
Andrzej's avatar
Andrzej committed
54
 * @brief Function to initialize lattice. Function initializes the lattice.
55
 *
Andrzej's avatar
Andrzej committed
56
57
58
59
60
61
62
 * @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.
63
64
65
 */
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
66
67
/* ***************************************************************************************** */
/* ***************************************************************************************** */
68
69
70
71
/**
 * @brief Function that inserts data from smaller 1D box (`wmbd`) into the 1D bigger box(`wmbd_big`) that is anchored in `wbox_insert`.
 * Function checks the anchor placements.
 *
Andrzej's avatar
Andrzej committed
72
73
74
75
 * @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.
76
 */
Andrzej's avatar
Andrzej committed
77
int wbox_insert_1d(const wbox_md_t *wbmd_small, const wbox_insert_t wbox_insert, wbox_md_t *wbmd_big);
78
79
80
81
82

/**
 * @brief Function that inserts data from smaller 2D box (`wmbd`) into the 2D bigger box(`wmbd_big`) that is anchored in `wbox_insert`.
 * Function checks the anchor placements.
 *
Andrzej's avatar
Andrzej committed
83
84
85
86
 * @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.
87
 */
Andrzej's avatar
Andrzej committed
88
int wbox_insert_2d(const wbox_md_t *wbmd_small, const wbox_insert_t wbox_insert, wbox_md_t *wbmd_big);
Andrzej MakowskI's avatar
Andrzej MakowskI committed
89

90
91
92
93
/**
 * @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
94
95
96
97
 * @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.
98
 */
Andrzej's avatar
Andrzej committed
99
int wbox_insert_3d(const wbox_md_t *wbmd_small, const wbox_insert_t wbox_insert, wbox_md_t *wbmd_big);
100
101
102

/**
 * @brief Master function that inserts data from smaller box (`wmbd`) into the bigger box(`wmbd_big`) that is anchored in `wbox_insert`.
Andrzej's avatar
Andrzej committed
103
104
105
106
107
108
109
110
111
112
113
 * Function checks the anchor placements. First checks the dimension of box and places calls adequate insert function.
 *
 * @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.
 */
int wbox_insert(const wbox_md_t *wbmd_small, const wbox_insert_t wbox_insert, wbox_md_t *wbmd_big);

/**
 * @brief Function that initializes insert parameters.
114
 *
Andrzej's avatar
Andrzej committed
115
116
117
118
119
 * @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 int `WBOX_SUCCESS_INSERT_INIT` or `WBOX_ERR_INSERT_INIT` whith help description.
120
 */
Andrzej's avatar
Andrzej committed
121
int wbox_insert_init(wbox_insert_t *wbox_insert, const int ax, const int ay, const int az);
122
123
124
125

/**
 * @brief Function that checks the possible errors for inserting a data from small box into big box.
 *
Andrzej's avatar
Andrzej committed
126
127
128
129
 * @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.
130
 */
Andrzej's avatar
Andrzej committed
131
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
132

Andrzej's avatar
Andrzej committed
133
134
135
136
137
/* ***************************************************************************************** */
/* ***************************************************************************************** */
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
138
139
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
140
141
int wbox_rotate_2d(wbox_md_t *wbmd);
int wbox_rotate_3d(wbox_md_t *wbmd);
Andrzej MakowskI's avatar
Andrzej MakowskI committed
142
int wbox_rotate(wbox_md_t *wbmd);
Andrzej's avatar
Andrzej committed
143
144
145
146
147
148

/* ***************************************************************************************** */
/* ***************************************************************************************** */
int wbox_print_1d(const wbox_md_t *wbmd, const char *title);
int wbox_print_2d(const wbox_md_t *wbmd, const char *title);
int wbox_print_3d(const wbox_md_t *wbmd, const char *title);