|
gimme-alpha 0.1
|
#include <math.h>#include <stdio.h>#include <stdlib.h>#include <CUnit/CUnit.h>#include "tests/cunit-local.h"#include <glib.h>#include "argdefaults.h"#include "matdb.h"#include "alpha_calc.h"#include "alpha_calc-suite.h"#include "wavefunction.h"
Include dependency graph for alpha_calc-suite.c:Go to the source code of this file.
Defines | |
| #define | NUM_POINTS 4096 |
| #define | MINX -10.0 |
| #define | MAXX 10.0 |
| #define | SIGMA 1.0 |
Functions | |
| double * | average_arrays (double *arrays[], int n_arrays, int array_size) |
| char * | find_left_right_of_iface (double iface, int *prev, int *next, double *x, int N) |
| void | check_iface_indices (void) |
| void | check_average_arrays (void) |
| void | avg_discrete_func_gaussian_1 (void) |
| void | avg_discrete_func_gaussian_x (void) |
| void | alpha_calc_suite_add_tests (CU_pSuite suite) |
| #define MAXX 10.0 |
Definition at line 69 of file alpha_calc-suite.c.
Referenced by avg_discrete_func_gaussian_1(), and avg_discrete_func_gaussian_x().
| #define MINX -10.0 |
Definition at line 68 of file alpha_calc-suite.c.
Referenced by avg_discrete_func_gaussian_1(), and avg_discrete_func_gaussian_x().
| #define NUM_POINTS 4096 |
Definition at line 67 of file alpha_calc-suite.c.
Referenced by avg_discrete_func_gaussian_1(), and avg_discrete_func_gaussian_x().
| #define SIGMA 1.0 |
Definition at line 70 of file alpha_calc-suite.c.
Referenced by avg_discrete_func_gaussian_1(), and avg_discrete_func_gaussian_x().
| void alpha_calc_suite_add_tests | ( | CU_pSuite | suite | ) |
Definition at line 111 of file alpha_calc-suite.c.
References avg_discrete_func_gaussian_1(), avg_discrete_func_gaussian_x(), check_average_arrays(), and check_iface_indices().
Referenced by main().
{
CU_add_test(suite, "interface_indices", check_iface_indices);
CU_add_test(suite, "check average arrays", check_average_arrays);
CU_add_test(suite, "averaging 1 with gaussian", avg_discrete_func_gaussian_1);
CU_add_test(suite, "averaging x with gaussian", avg_discrete_func_gaussian_x);
}
Here is the call graph for this function:
Here is the caller graph for this function:| double* average_arrays | ( | double * | arrays[], |
| int | n_arrays, | ||
| int | array_size | ||
| ) |
Averages n_arrays of array_size doubles.
| arrays | pointer to an array of arrays of doubles |
| n_arrays | number of arrays given |
| array_size | the size of the arrays stored in arrays. |
Definition at line 203 of file alpha_calc.c.
References unlikely.
Referenced by alpha_electric_term_mstar_nostrain(), alpha_from_del_psi2_nostrain(), alpha_interface_term_mstar_nostrain(), and check_average_arrays().
{
if(unlikely(arrays == NULL)) return NULL;
double *avg = malloc(sizeof(double)*array_size);
if(unlikely(avg == NULL)) return NULL;
if(unlikely(n_arrays < 1)) {
free(avg);
return NULL;
}
register int i;
for(i=0; i<array_size; i++) {
avg[i] = (arrays[0])[i];
//fprintf(stderr, "(arrays[0])[%d]=%g\tavg[%d]=%g\n", i, (arrays[0])[i], i, avg[i]);
}
for(i=1; i<n_arrays; i++) {
for(int j=0; j<array_size; j++) {
avg[j] += (arrays[i])[j];
//fprintf(stderr, "(arrays[%d])[%d]=%g\tavg[%d]=%g\n", i, j, (arrays[i])[j], i, avg[j]);
}
}
for(i=0; i<array_size; i++) {
avg[i] /= n_arrays;
}
return avg;
}
Here is the caller graph for this function:| void avg_discrete_func_gaussian_1 | ( | void | ) |
Definition at line 71 of file alpha_calc-suite.c.
References average_discrete_function(), CLOSE_ENOUGH, CU_FAIL_STRING, CU_PASS_STRING, MAXX, MINX, mstar_wavefunction_1d_free(), mstar_wavefunction_1d_new_gaussian(), NUM_POINTS, mstar_wavefunction_1d::points, and SIGMA.
Referenced by alpha_calc_suite_add_tests().
{
struct mstar_wavefunction_1d* wf = mstar_wavefunction_1d_new_gaussian(NUM_POINTS, MINX, MAXX, SIGMA);
CU_ASSERT(wf != NULL);
double func[NUM_POINTS];
double x[NUM_POINTS];
double err;
GString *s = g_string_new_len("", 1024);
for(int i=0; i<NUM_POINTS; i++) {func[i]=1.0, x[i] = (wf->points)[i].x;}
double result = average_discrete_function(func, x, NUM_POINTS, wf, 0, 1e-8, 1e-8, &err);
if(fabs(result - 1.0) <= fabs(CLOSE_ENOUGH)) {
g_string_printf(s, "OK: expectation value of 1.0 with gaussian wavefunc (%g) == 1.0 (err=%g", result, err);
CU_PASS_STRING(s->str);
}else{
g_string_printf(s, "FAIL: expectation value of 1.0 with gaussian wavefunc (%g) == 1.0 (err=%g", result, err);
CU_FAIL_STRING(s->str);
}
g_string_free(s, TRUE);
mstar_wavefunction_1d_free(wf);
}
Here is the call graph for this function:
Here is the caller graph for this function:| void avg_discrete_func_gaussian_x | ( | void | ) |
Definition at line 91 of file alpha_calc-suite.c.
References average_discrete_function(), CLOSE_ENOUGH, CU_FAIL_STRING, CU_PASS_STRING, MAXX, MINX, mstar_wavefunction_1d_free(), mstar_wavefunction_1d_new_gaussian(), NUM_POINTS, mstar_wavefunction_1d::points, and SIGMA.
Referenced by alpha_calc_suite_add_tests().
{
struct mstar_wavefunction_1d* wf = mstar_wavefunction_1d_new_gaussian(NUM_POINTS, MINX, MAXX, SIGMA);
CU_ASSERT(wf != NULL);
double func[NUM_POINTS];
double x[NUM_POINTS];
double err;
GString *s = g_string_new_len("", 1024);
for(int i=0; i<NUM_POINTS; i++) {x[i] = (wf->points)[i].x; func[i] = x[i];}
double result = average_discrete_function(func, x, NUM_POINTS, wf, 0, 1e-8, 1e-8, &err);
if(fabs(result - 0.0) <= fabs(CLOSE_ENOUGH)) {
g_string_printf(s, "OK: expectation value of x with gaussian wavefunc (%g) == 0.0 (err=%g)", result, err);
CU_PASS_STRING(s->str);
}else{
g_string_printf(s, "FAIL: expectation value of x with gaussian wavefunc (%g) != 0.0 (err=%g)", result, err);
CU_FAIL_STRING(s->str);
}
g_string_free(s, TRUE);
mstar_wavefunction_1d_free(wf);
}
Here is the call graph for this function:
Here is the caller graph for this function:| void check_average_arrays | ( | void | ) |
Definition at line 44 of file alpha_calc-suite.c.
References average_arrays(), CU_FAIL_STRING, and CU_PASS_STRING.
Referenced by alpha_calc_suite_add_tests().
{
double arr1[] = {0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
double arr2[] = {7.0, 3.0, -4.0, 5.0, 7.0, 12.0, 13.0, 0.0, -5.0};
double arr3[] = {7.0/2.0, 4.0/2.0, -2.0/2.0, 8.0/2.0, 11.0/2.0, 17.0/2.0, 19.0/2.0, 7.0/2.0, 3.0/2.0};
double *arrs[] = {arr1, arr2};
double *avg = average_arrays(arrs, 2, 9);
CU_ASSERT(avg != NULL);
if(avg == NULL) return;
GString *s = g_string_new_len("", 1024);
for(int i=0; i<9; i++) {
if(avg[i] == arr3[i]) {
g_string_printf(s, "OK: avg[%d](%g) == arg3[%d](%g)", i, avg[i], i, arr3[i]);
CU_PASS_STRING(s->str);
}else{
g_string_printf(s, "FAIL: avg[%d](%g) != arg3[%d](%g)", i, avg[i], i, arr3[i]);
CU_FAIL_STRING(s->str);
fprintf(stderr, "%s\n", s->str);
}
}
g_string_free(s, TRUE);
if(avg != NULL) free(avg);
}
Here is the call graph for this function:
Here is the caller graph for this function:| void check_iface_indices | ( | void | ) |
Definition at line 40 of file alpha_calc-suite.c.
Referenced by alpha_calc_suite_add_tests().
{
}
Here is the caller graph for this function:| char* find_left_right_of_iface | ( | double | iface, |
| int * | prev, | ||
| int * | next, | ||
| double * | x, | ||
| int | N | ||
| ) |
Finds the points to the left and right of the specified interface
| iface | interface point |
| prev | pointer to an int to store the index of the previous point |
| next | Same, but the next point |
| x | array of x values, assumed to be sorted from smallest to largest |
| N | number of points in the x array |
Definition at line 236 of file alpha_calc.c.
References unlikely.
Referenced by alpha_interface_term_mstar_nostrain().
{
register int i;
for(i=0; i<N; i++) {
if(x[i] >= iface) {
*prev = i-1;
if(x[i] == iface) {
//fprintf(stderr, "=(p=%i, n=%i, %g==%g [%g < %g])\n", *prev, *next, x[i], iface, x[*prev], iface);
*next = i+1;
}else{
//fprintf(stderr, ">(p=%i, n=%i, %g>%g [%g < %g])\n", *prev, *next, x[i], iface, x[*prev], iface);
*next = i;
}
break;
}
//fprintf(stderr, ".");
}
if(unlikely((i == N) || (*prev < 0) || (*next >= N))) {
//fprintf(stderr, "E\n");
if(i == N) return "specified interface not in structure";
if(*prev < 0) return "specified interface is the start of the structure";
if(*next >= N) return "specified interface is the end of the structure";
}
return NULL;
}
Here is the caller graph for this function: