lattice1d-insert.c 2.41 KB
Newer Older
Andrzej's avatar
Andrzej committed
1
#include <complex.h>
Andrzej's avatar
Andrzej committed
2
#include <math.h>
Andrzej's avatar
Andrzej committed
3
4
5
6
7
8
9
10
11
12
13

#include "wbox.h"

#define cppmallocl(pointer, size, type)                                     \
    if ((pointer = (type *)malloc((size) * sizeof(type))) == NULL)          \
    {                                                                       \
        fprintf(stderr, "ERROR: cannot malloc()! Exiting!\n");              \
        fprintf(stderr, "ERROR: file=`%s`, line=%d\n", __FILE__, __LINE__); \
        return -1;                                                          \
    }

Andrzej's avatar
Andrzej committed
14
15
16
17
18
19
20
21
double gaussian_1d(const int ix, const int nx)
{
#define SQRT_2PI1 2.506628274631
    const double sigma = (double)sqrt(nx) * 0.2;
    const int shift = (double)(nx - 1) / 2.;
    return 4. / (sigma * SQRT_2PI1) * exp(-0.5 * pow((double)(ix - shift), 2.) / (sigma * sigma));
}

Andrzej's avatar
Andrzej committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
int main()
{
    wbox_md_t wbmd_small;    // WBox variable that store information of SMALL box
    wbox_md_t wbmd_big;      // WBox variable that store information of BIG box
    wbox_insert_t wb_insert; // WBox variable that stores information about the ANCHOR of SMALL to BIG box

    int nxs = 10, nys = -1, nzs = -1; // LATTICE parameters of SMALL box
    int nxb = 20, nyb = -1, nzb = -1; // LATTICE parameters of BIG box
    int ax = 0, ay = -1, az = -1;     // ANCHOR parameters in `units` of BIG box. Iteration is aq: 0-> nqb-nqs, here `q` is a cartesian coordinate X, Y or Z

    double *wdata_small; // Pointer to SMALL box variable
    double *wdata_big;   // Pointer to BIG box variable

    // MEMORY ALLOCATION
    cppmallocl(wdata_small, nxs, double);
    cppmallocl(wdata_big, nxb, double);

    // Fill data in SMALL box
    for (size_t ixs = 0; ixs < nxs; ixs++)
Andrzej's avatar
Andrzej committed
41
        wdata_small[ixs] = gaussian_1d(ixs, nxs);
Andrzej's avatar
Andrzej committed
42
43
44
45
46
47
48
49

    // WBox initialization. See `wbox_init()` description
    wbox_init(&wbmd_small, nxs, nys, nzs, 'R', wdata_small);
    wbox_init(&wbmd_big, nxb, nyb, nzb, 'r', wdata_big);

    // WBox insert initialization. See `wbox_insert_init()` description
    wbox_insert_init(&wb_insert, ax, ay, az);

Andrzej's avatar
Andrzej committed
50
51
    // PRINT WBox STRUCT
    wbox_print_box_params(wbmd_small, "WBOX SMALL");
Andrzej's avatar
Andrzej committed
52
    wbox_print_box_params(wbmd_big, "WBOX BIG");
Andrzej's avatar
Andrzej committed
53

Andrzej's avatar
Andrzej committed
54
55
    // PRINT WBox_Insert STRUCT
    wbox_print_insert_params(wb_insert);
Andrzej's avatar
Andrzej committed
56
57

    // Insert SMALL box into BIG box
Andrzej's avatar
Andrzej committed
58
    wbox_insert(&wbmd_small, &wb_insert, &wbmd_big);
Andrzej's avatar
Andrzej committed
59
60

    /* PRINTS for checks. */
Andrzej's avatar
Andrzej committed
61
62
    wbox_print(&wbmd_small, "WBOX SMALL");
    wbox_print(&wbmd_big, "WBOX BIG");
Andrzej's avatar
Andrzej committed
63
64
65

    return EXIT_SUCCESS;
}