|
k-dot-p 0.1
|
#include <cartesian_grid.h++>
Inheritance diagram for kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >:Classes | |
| struct | cartesian_set_function_callback_data |
| struct | dump_foreach_callback_privdat |
| struct | ezstruct |
Public Types | |
| typedef GError *(* | set_points_callback )(T *location, void *data) |
| typedef GError *(* | get_point_value_from_double_callback )(T *location, double *value, int dim, void *data) |
| typedef GError *(* | set_point_function_callback_d )(double *x, int dim, T *location, void *data) |
| typedef GError *(* | set_point_function_callback_i )(unsigned int *X, int dim, T *location, void *data) |
Public Member Functions | |
| cartesian_grid (const unsigned *box_size, const double *site_length, long unsigned bufflen, const T *data_buffer) | |
| cartesian_grid (const T *indices, long unsigned n_indices, const cartesian_grid< long unsigned, D, Nc > *indexed_grid) | |
| cartesian_grid (GList *box_size, GList *site_length, T def_value) | |
| cartesian_grid (const unsigned *box_size, const double *site_length, T def_value) | |
| void | cartesian_grid_init (const unsigned *box_size, const double *site_length, T *def_value, const T *buffer, const T *indices, long unsigned n_indices, const cartesian_grid< long unsigned, D, Nc > *indexed_grid) |
| GError * | set_points (const struct shape_tree *st, set_points_callback spcb, GHashTable *global_symbols, void *privdat=NULL) |
| GError * | set_points (const struct shape_tree *st, postprocessing::function_exp *exp, GHashTable *global_symbol_table, get_point_value_from_double_callback cb, void *privdat=NULL) |
| GError * | set_points (const struct shape_tree *st, set_point_function_callback_d dcb, set_point_function_callback_i icb, GHashTable *global_symbols, void *privdat=NULL) |
| GError * | for_each_point (GError *(*thing_to_do)(unsigned *X, double *x, unsigned c, unsigned dim, T *location, void *privdat), void *privdat=NULL) |
| int | set_points (const struct shape_tree *st, T *val, GHashTable *global_symbols) |
| void | point_index_to_realspace (const unsigned int *X, double *x) const |
| long unsigned int | point_index_to_storage_index (const unsigned int *X, unsigned int c=0) const |
| bool | point_is_in_tree (const double *x, const struct shape_tree *st, GHashTable *global_syms) const |
| bool | point_is_in_shape (const double *x, const struct shape_block *b, GHashTable *global_syms) const |
| long unsigned | get_index_for_component_and_store_if_new (GList **comps, bool(*is_same)(T *a, T *b), T *comp) |
| GError * | create_indexed_unique_component_grid (T **indices, long unsigned *n_indices, cartesian_grid< long unsigned, D, Nc > **indexed_grid, bool(*is_same)(T *a, T *b)) |
| GError * | dump (GOutputStream *gos, char *(*t_to_string)(T *)) |
| GError * | dump_indexed (GOutputStream *gos, bool(*is_same)(T *a, T *b), char *(*t_to_string)(T *)) |
| void | set_point (unsigned *X, T *val, unsigned c=0) |
| void | set_point (unsigned *X, T &val, unsigned c=0) |
| void | set_point_ (unsigned *X, T &val, unsigned c=0) |
| void | get_point (unsigned *X, T **store_pointer, unsigned c=0) |
| T * | get_point_r (unsigned *X, unsigned c=0) |
Static Public Member Functions | |
| static GError * | set_point_function_callback_d_imp (double *x, int dim, T *location, void *data) |
| static GError * | set_point_function (double *x, int dee, T *location, void *privdat) |
| static GError * | dump_foreach_callback (unsigned *X, double *x, unsigned c, unsigned dim, T *location, void *privdat) |
Public Attributes | |
| unsigned int | L [D] |
| double | a [D] |
| long unsigned int | num_pts |
| T * | data |
| struct::kdotp::libmodelxx::postprocessing::symbol_table_entry_const | ste_x |
| GHashTable * | st_x |
| struct::kdotp::libmodelxx::postprocessing::symbol_table_entry_const | ste_X |
| GHashTable * | st_X |
Private Member Functions | |
| cartesian_grid () | |
| cartesian_grid (const cartesian_grid &g) | |
| cartesian_grid | operator= (const cartesian_grid &g) |
Definition at line 45 of file cartesian_grid.h++.
| typedef GError*(* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::get_point_value_from_double_callback)(T *location, double *value, int dim, void *data) |
This is a function pointer used whne using a builtin callback, in order to determine the actual value of T from a double-precision value (i.e. the value of the function at that point.
Definition at line 54 of file cartesian_grid.h++.
| typedef GError*(* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_point_function_callback_d)(double *x, int dim, T *location, void *data) |
This is used to set a location based upon a position-dependent function. x is a vector to the location in the global coordinate system location is a pointer to the storage at this point
Definition at line 60 of file cartesian_grid.h++.
| typedef GError*(* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_point_function_callback_i)(unsigned int *X, int dim, T *location, void *data) |
This is used to set a location based upon a position-dependent function. X is a vector to the location in grid sites location is a pointer to the storage at this point
Definition at line 66 of file cartesian_grid.h++.
| typedef GError*(* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_points_callback)(T *location, void *data) |
This function pointer is used to do something at each point, e.g. set a member of the struct at location.
Definition at line 50 of file cartesian_grid.h++.
| kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::cartesian_grid | ( | const unsigned * | box_size, |
| const double * | site_length, | ||
| long unsigned | bufflen, | ||
| const T * | data_buffer | ||
| ) | [inline] |
This is used when restoring from a buffer (e.g. HDF5)
Definition at line 69 of file cartesian_grid.h++.
{
catesian_grid_init(box_size, site_length, NULL, data_buffer, NULL, 0, NULL);
}
| kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::cartesian_grid | ( | const T * | indices, |
| long unsigned | n_indices, | ||
| const cartesian_grid< long unsigned, D, Nc > * | indexed_grid | ||
| ) | [inline] |
This is used when restoring from an indexed grid
Definition at line 73 of file cartesian_grid.h++.
{
catesian_grid_init(indexed_grid->L, indexed_grid->a, NULL, NULL, indices, n_indices, indexed_grid);
}
| kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::cartesian_grid | ( | GList * | box_size, |
| GList * | site_length, | ||
| T | def_value | ||
| ) | [inline] |
Definition at line 77 of file cartesian_grid.h++.
{
unsigned ell[D];
double ay[D];
unsigned int d;
GList *b;
GList *a_l;
for(d=0, b=(box_size), a_l=(site_length); d<D; d++, a_l=(a_l->next), b=(b->next)) {
if(b == NULL) {fprintf(stderr, "kdotp::libmodelxx::grid::cartesian_grid::cartesian_grid(const struct grid*): Too few box sizes given for the dimension (gave %d, dimension is =%d). Fix your grid(){} information!\n", d, D); exit(1);}
if(a_l == NULL) {fprintf(stderr, "kdotp::libmodelxx::grid::cartesian_grid::cartesian_grid(const struct grid*): Too few site lengths given for the dimension (gave %d, dimension is =%d). Fix your grid(){} information!\n", d, D); exit(2);}
ell[d] = *(int*)(b->data);
ay[d] = *(double*)(a_l->data);
}
cartesian_grid_init(ell, ay, &def_value, NULL, NULL, 0, NULL);
}
| kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::cartesian_grid | ( | const unsigned * | box_size, |
| const double * | site_length, | ||
| T | def_value | ||
| ) | [inline] |
Definition at line 92 of file cartesian_grid.h++.
{
cartesian_grid_init(box_size, site_length, &def_value, NULL, NULL, 0, NULL);
}
| kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::cartesian_grid | ( | ) | [inline, private] |
Definition at line 756 of file cartesian_grid.h++.
{}
| kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::cartesian_grid | ( | const cartesian_grid< T, D, Nc > & | g | ) | [inline, private] |
Definition at line 757 of file cartesian_grid.h++.
{}
| void kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::cartesian_grid_init | ( | const unsigned * | box_size, |
| const double * | site_length, | ||
| T * | def_value, | ||
| const T * | buffer, | ||
| const T * | indices, | ||
| long unsigned | n_indices, | ||
| const cartesian_grid< long unsigned, D, Nc > * | indexed_grid | ||
| ) | [inline] |
This is the central constructor (but an init method) since constructors can't call each other
Definition at line 97 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::cartesian_grid().
{
num_pts = 1;
unsigned int d;
for(d=0; d<D; d++) {
L[d] = box_size[d];
a[d] = site_length[d];
if(a[d] < 0.0) {fprintf(stderr, "kdotp::libmodelxx::grid::cartesian_grid::cartesian_grid_init(const struct grid*): negative site length given (%f) Fix your grid(){} information!\n", a[d]); exit(3);}
if(L[d] < 0) {fprintf(stderr, "kdotp::libmodelxx::grid::cartesian_grid::cartesian_grid_init(const struct grid*): negative box size given (%d) Fix your grid(){} information!\n", L[d]); exit(4);}
num_pts *= L[d];
//fprintf(stderr, "L[%d]=%d num_pts=%lu\n", d, L[d], num_pts);
}
if((indexed_grid != NULL) && (indexed_grid->num_pts != num_pts)) {
fprintf(stderr, "kdotp::libmodelxx::grid::cartesian_grid::cartesian_grid_init(const struct grid*): indexed grid data size (%lu) not the same as the target's size (%lu)\n", indexed_grid->num_pts, num_pts);
exit(4);
}
data = (T*)malloc(num_pts*Nc*sizeof(T));
/*The grid is now allocated; we now need to set up the structure.*/
for(long unsigned i=0; i<num_pts; i++) {
if(def_value != NULL) {
data[i] = *def_value;
}else if(buffer != NULL) {
data[i] = buffer[i];
}else{
//if(unlikely(indexed_grid->data[i] >= n_indices)) {
if(indexed_grid->data[i] >= n_indices) {
fprintf(stderr, "kdotp::libmodelxx::grid::cartesian_grid::cartesian_grid_init(const struct grid*): invalid index in the index array (%lu)\n", indexed_grid->data[i]); exit(4);
}
data[i] = indices[indexed_grid->data[i]];
}
}
/*Set up ste_x, ste_X, and the respective local symbol tables to save several operations per unit.*/
switch(D) {
case 1:
ste_x.dt=::kdotp::libmodelxx::postprocessing::SCALAR;
break;
case 2:
ste_x.dt=::kdotp::libmodelxx::postprocessing::VECTOR2;
break;
case 3:
ste_x.dt=::kdotp::libmodelxx::postprocessing::VECTOR3;
break;
default:
ste_x.dt=::kdotp::libmodelxx::postprocessing::INVALID;
};
ste_X.dt=ste_x.dt;
ste_x.value = ste_X.value = NULL;
ste_X.st=ste_x.st=::kdotp::libmodelxx::postprocessing::CONSTANT_SYMBOL;
st_x = ::kdotp::libmodelxx::postprocessing::new_symbol_table();
st_X = ::kdotp::libmodelxx::postprocessing::new_symbol_table();
add_symbol_table_entry(st_x, "x", (struct ::kdotp::libmodelxx::postprocessing::symbol_table_entry*)&ste_x);
add_symbol_table_entry(st_X, "X", (struct ::kdotp::libmodelxx::postprocessing::symbol_table_entry*)&ste_X);
}
Here is the caller graph for this function:| GError* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::create_indexed_unique_component_grid | ( | T ** | indices, |
| long unsigned * | n_indices, | ||
| cartesian_grid< long unsigned, D, Nc > ** | indexed_grid, | ||
| bool(*)(T *a, T *b) | is_same | ||
| ) | [inline] |
Create a new grid which contains unique component indices. The initial use case for this is creating an integer-based material map. We then have an array of materials and a grid of material assignments.
| indices | pointer to a place to store an array of type T (the final array; the index stored in the grid is the array index to get the component |
| n_indices | number of T's stored in the indices array |
| indexed_grid | pointer to a new, identically-spec'ed Cartesian grid, but with indices into the component array instead of component. |
| is_same | callback to compare to items (return true if same, false otherwise) |
Definition at line 570 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::dump_indexed().
{
*indexed_grid = new cartesian_grid<long unsigned, D, Nc>(L, a, 0);
/*The easy way to do this is not to care about our location (it's really irrelevant; we only care about whether or not this component is unique or not.*/
/*List of the unique components.*/
GList *components = NULL;
for(long unsigned i=0; i<num_pts; i++) {
((*indexed_grid)->data)[i] = get_index_for_component_and_store_if_new(&components, is_same, &(data[i]));
}
*n_indices = g_list_length(components);
*indices = (T*)malloc(sizeof(T)*(*n_indices));
if(*indices == NULL) {
return g_error_new(CARTESIAN_GRID_GERROR_DOMAIN, 200, "kdotp::libkdotp::libmodelxx::grid::cartesian_grid::create_indexed_unique_component_grid: failed to allocate storage for the index array");
}
GList *l;
long unsigned i=0;
for(l=components, i=0; l!=NULL; l=l->next, i++) {
(*indices)[i] = *(T*)(l->data);
}
g_list_free(components);
return NULL;
}
Here is the caller graph for this function:| GError* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::dump | ( | GOutputStream * | gos, |
| char *(*)(T *) | t_to_string | ||
| ) | [inline] |
Dumps the grid to a file (gfos) in ASCII.
| gos | GOutputStream to write to. |
| t_to_string | callback to convert T to a string. |
Definition at line 624 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::dump_indexed().
{
struct dump_foreach_callback_privdat dcp = {gos, t_to_string, NULL};
dcp.s = g_string_new("");
/*Write the header.*/
GError *e = NULL;
gsize bytes_written;
GString *s = g_string_new("#Grid dimensions:\n");
if(!g_output_stream_write_all(gos, s->str, s->len, &bytes_written, NULL, &e)) {
GError *err=NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::grid::cartesian_grid.h++::dump: error writing header.\n");
return err;
}
g_string_printf(s, "%u", D);
for(unsigned d=0; d<D; d++) {
g_string_append_printf(s, "\t%u\t%g", L[d], a[d]);
}
g_string_append_printf(s, "\t%u\n", Nc);
if(!g_output_stream_write_all(gos, s->str, s->len, &bytes_written, NULL, &e)) {
GError *err=NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::grid::cartesian_grid.h++::dump: error writing header.\n");
return err;
}
s = g_string_assign(s, "#");
for(unsigned d=0; d<D; d++) {
g_string_append_printf(s, "X%u\tx%u\t", d, d);
}
s = g_string_append(s, "\n");
if(!g_output_stream_write_all(gos, s->str, s->len, &bytes_written, NULL, &e)) {
GError *err=NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::grid::cartesian_grid.h++::dump: error writing header.\n");
return err;
}
e = for_each_point(dump_foreach_callback, (void*)(&dcp));
g_string_free(s, TRUE);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::grid::cartesian_grid.h++::dump: error writing grid data.\n");
return err;
}
return NULL;
}
Here is the caller graph for this function:| static GError* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::dump_foreach_callback | ( | unsigned * | X, |
| double * | x, | ||
| unsigned | c, | ||
| unsigned | dim, | ||
| T * | location, | ||
| void * | privdat | ||
| ) | [inline, static] |
Definition at line 600 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::dump().
{
struct dump_foreach_callback_privdat *cbp = (struct dump_foreach_callback_privdat*)privdat;
g_string_printf(cbp->s, "%u\t%g\t", X[0], x[0]);
for(unsigned d=1; d<dim; d++) {
g_string_append_printf(cbp->s, "%u\t%g\t", X[d], x[d]);
}
char* data = cbp->t_to_string(location);
g_string_append_printf(cbp->s, "%u\t%s\n", c, data);
free(data);
GError *e=NULL;
gsize bytes_written;
//fprintf(stderr, "str=%s\n", cbp->s->str);
if(!g_output_stream_write_all(cbp->gos, cbp->s->str, cbp->s->len, &bytes_written, NULL, &e)) {
GError *err=NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::grid::cartesian_grid.h++::dump: error writing line (%s). ", cbp->s->str);
return err;
}
return NULL;
}
Here is the caller graph for this function:| GError* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::dump_indexed | ( | GOutputStream * | gos, |
| bool(*)(T *a, T *b) | is_same, | ||
| char *(*)(T *) | t_to_string | ||
| ) | [inline] |
Like dump, but dumps an *indexed* version.
Definition at line 667 of file cartesian_grid.h++.
{
T* indices;
long unsigned n_indices;
cartesian_grid<long unsigned, D, Nc>* indexed_grid;
GError *e=NULL;
e = create_indexed_unique_component_grid(&indices, &n_indices, &indexed_grid, is_same);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::grid::cartesian_grid.h++::dump_indexed: error getting indexed grid.\n");
return err;
}
GString *s = g_string_new("#material assignments:\n");
g_string_append_printf(s, "%lu\n", n_indices);
gsize bytes_written;
if(!g_output_stream_write_all(gos, s->str, s->len, &bytes_written, NULL, &e)) {
GError *err=NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::grid::cartesian_grid.h++::dump_indexed: error writing header.\n");
free(indices);
delete indexed_grid;
return err;
}
for(long unsigned i=0; i<n_indices; i++) {
char* rstr;
g_string_printf(s, "%s\n", rstr=t_to_string(&(indices[i])));
if(!g_output_stream_write_all(gos, s->str, s->len, &bytes_written, NULL, &e)) {
GError *err=NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::grid::cartesian_grid.h++::dump_indexed: error writing material %lu (%s).\n", i, rstr);
free(indices);
free(rstr);
delete indexed_grid;
return err;
}
//fprintf(stderr, "index %lu: %s\n", i, rstr);
free(rstr);
}
e=indexed_grid->dump(gos, long_unsigned_to_string);
if(e != NULL) {
GError *err=NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::grid::cartesian_grid.h++::dump_indexed: error dumping index grid.\n");
free(indices);
delete indexed_grid;
return err;
}
free(indices);
delete indexed_grid;
return NULL;
}
| GError* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::for_each_point | ( | GError *(*)(unsigned *X, double *x, unsigned c, unsigned dim, T *location, void *privdat) | thing_to_do, |
| void * | privdat = NULL |
||
| ) | [inline] |
Definition at line 309 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::dump().
{
/*X is the integer location*/
unsigned int X[D];
/*x is the floating-point location*/
double x[D];
unsigned int d;
for(d=0; d<D; d++) X[d]=0;
/*X[0] is the lowest dimension; X[D-1] is the lowest
*Here's the idea: X can be viewed as an integer number with
* a digit-dependent basis. The algorithm:
*1) carry is set to 0 going into the loop
*2) When the counter is updated, carry will be set to 0,
* unless the last "digit" overflows, in which case carry stays 1.
*3) If carry is still 1 coming out of the X update, we're done.
*/
GError *e = NULL;
unsigned int carry=0;
unsigned int c;
while(carry == 0) {
point_index_to_realspace(X, x);
//fprintf(stderr, "Y");
/*Note that this for loop can likely be unrolled.
*The if statement should be compiled out; it'll never
*change at runtime.
*/
for(c=0; c<Nc; c++) {
if(Nc == 1) {
e = thing_to_do(X, x, 0, D, &data[point_index_to_storage_index(X)], privdat);
}else{
e = thing_to_do(X, x, c, D, &data[point_index_to_storage_index(X, c)], privdat);
}
if(e != NULL) {
GError *err = NULL;
GString *s = g_string_new("");
GString *S = g_string_new("");
for(unsigned int i=0; i<D; i++) {
g_string_append_printf(s, " %g", x[i]);
g_string_append_printf(S, " %u", X[i]);
}
g_propagate_prefixed_error(&err, e, "kdotp::libmodeling::grid::cartesian_grid::set_points<full>: Got error evaluating point %s (grid site %s) c=%u: ", s->str, S->str, c);
g_string_free(s, TRUE);
g_string_free(S, TRUE);
return err;
}
}
/*Now update our point.*/
carry=1;
/*We should exit this loop with carry=0 unless we incremented past the end of the final dimension (i.e. we'd need to carry into the D+1 dimension*/
for(d=0; ((d<D)&&(carry==1)); d++) {
//fprintf(stderr, "%d->", X[d]);
X[d] += carry;
//fprintf(stderr, "%d/", X[d]);
if(X[d] >= L[d]) {
X[d] = 0;
carry = 1;
}else{
carry = 0;
}
}
//fprintf(stderr, "\n");
}
return NULL;
}
Here is the caller graph for this function:| long unsigned kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::get_index_for_component_and_store_if_new | ( | GList ** | comps, |
| bool(*)(T *a, T *b) | is_same, | ||
| T * | comp | ||
| ) | [inline] |
helper function for create_indexed_unique_component_grid
Definition at line 553 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::create_indexed_unique_component_grid().
{
long unsigned index=0;
for(GList* l=*comps; l != NULL; l=l->next, index++) {
if(is_same(comp, (T*)l->data)) {
return index;
}
}
*comps = g_list_append(*comps, comp);
return index;
}
Here is the caller graph for this function:| void kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::get_point | ( | unsigned * | X, |
| T ** | store_pointer, | ||
| unsigned | c = 0 |
||
| ) | [inline] |
Sets a point in the grid, by grid site
Definition at line 733 of file cartesian_grid.h++.
{
*store_pointer = &data[point_index_to_storage_index(X, c)];
}
| T* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::get_point_r | ( | unsigned * | X, |
| unsigned | c = 0 |
||
| ) | [inline] |
same as get_point, but returns the pointer instead
Definition at line 739 of file cartesian_grid.h++.
Referenced by kdotp::libmetacalc::optimizer::digital_alloy_optimizer_1d::digital_alloy_optimizer_1d(), kdotp::libmetacalc::optimizer::digital_alloy_optimizer_1d_mpi::digital_alloy_optimizer_1d_mpi(), and kdotp::libmetacalc::optimizer::continuous_alloy_optimizer_1d::set_block().
{
return &data[point_index_to_storage_index(X, c)];
}
Here is the caller graph for this function:| cartesian_grid kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::operator= | ( | const cartesian_grid< T, D, Nc > & | g | ) | [inline, private] |
Definition at line 758 of file cartesian_grid.h++.
{return *this;}
| void kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::point_index_to_realspace | ( | const unsigned int * | X, |
| double * | x | ||
| ) | const [inline] |
Covert a point within the grid from index to realspace
| X | integer array of size D, holding the grid indices |
| x | double array of size D, to hold the position |
Definition at line 438 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::for_each_point(), main(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_points(), and write_raw_bands_file().
{
unsigned int d;
for(d=0; d<D; d++) {
/*Formulated to put 0 in the center of the grid*/
x[d] = (double(X[d]) - double(L[d])/2.0)*a[d];
}
}
Here is the caller graph for this function:| long unsigned int kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::point_index_to_storage_index | ( | const unsigned int * | X, |
| unsigned int | c = 0 |
||
| ) | const [inline] |
Covert a point (index-based) to a location within storage
| X | integer array of size D, holding the grid indices. |
| c | component number (default is 0; saves a save/load if there's just one!) |
Definition at line 452 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::for_each_point(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::get_point(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::get_point_r(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_point(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_point_(), and kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_points().
{
unsigned int d;
/*We initialize with c, the component, already done.*/
unsigned long int block_offset = Nc;
unsigned long int index = c;
for(d=0; d<D; d++) {
index += X[d]*block_offset;
block_offset *= L[d];
}
return index;
}
Here is the caller graph for this function:| bool kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::point_is_in_shape | ( | const double * | x, |
| const struct shape_block * | b, | ||
| GHashTable * | global_syms | ||
| ) | const [inline] |
Determines if a point is within the given shape.
Definition at line 504 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::point_is_in_tree().
{
/*Check if the point lies within the box (dist to center
* less than half edge length, for each edge.*/
//fprintf(stderr, "piis: x[%d]=%g center[%d]=%g L[%d]=%g\n", d, x[d], d, (b->center)[d], d, (b->L)[d]);
/*fprintf(stderr, "point_is_in_shape: %g: center=%g L=%g x-center=%g L/2=%g: ", x[d], b->center[d], b->L[d], fabs(x[d] - b->center[d]), fabs(b->L[d]/2.0));*/
double center[D];
double L[D];
if(get_function_datatype(b->center, global_syms, NULL) != D) {
return false;
}
if(get_function_datatype(b->L, global_syms, NULL) != D) {
return false;
}
GError *e = evaluate_function(center, b->center, global_syms, NULL);
if(e != NULL) {
fprintf(stderr, "ERROR evaluating center function for block shape: %s", e->message);
g_error_free(e);
return false;
}
e = evaluate_function(L, b->L, global_syms, NULL);
if(e != NULL) {
fprintf(stderr, "ERROR evaluating size function for block shape: %s", e->message);
g_error_free(e);
return false;
}
for(unsigned int d = 0; d<D; d++) {
switch (b->type) {
case BLOCK:
if(!(fabs(x[d] - (center)[d]) <= fabs((L)[d]/2.0))) {
return false;
}
break;
case ABSBLOCK:
if(center[d] > L[d]) {
if(!((x[d] >= L[d]) && (x[d] <= center[d]))) return false;
}else{
if(!((x[d] <= L[d]) && (x[d] >= center[d]))) return false;
}
break;
default:
fprintf(stderr, "ERROR in point_is_in_shape (block argument): block isn't a block or an absblock?! (is %d).\n", b->type);
return false;
}
}
/*fprintf(stderr, "TRUE\n");*/
return true;
}
Here is the caller graph for this function:| bool kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::point_is_in_tree | ( | const double * | x, |
| const struct shape_tree * | st, | ||
| GHashTable * | global_syms | ||
| ) | const [inline] |
Definition at line 464 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::point_is_in_tree(), and kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_points().
{
bool l, r;
switch(st->op) {
case OR:
return point_is_in_tree(x, st->l, global_syms) || point_is_in_tree(x, st->r, global_syms);
case XOR:
l = point_is_in_tree(x, st->l, global_syms);
r = point_is_in_tree(x, st->r, global_syms);
return (l || r) && (!(l && r));
case AND:
return point_is_in_tree(x, st->l, global_syms) && point_is_in_tree(x, st->r, global_syms);
case NOT:
return !point_is_in_tree(x, st->l, global_syms);
case LEAF:
break;
default:
fprintf(stderr, "kdotp::libmodelxx::grid::cartesian_grid::point_is_in_tree: unknown shape tree operation %d. Assuming point NOT in tree.\n", st->op);
return false;
}
/*This code only executes if we are in a leaf*/
struct shape* s = (struct shape*)st;
switch(s->type) {
case GLOBAL:
/*A "global" shape is everywhere.*/
return true;
case BLOCK:
return point_is_in_shape(x, (struct shape_block*)(s), global_syms);
case ABSBLOCK:
return point_is_in_shape(x, (struct shape_block*)(s), global_syms);
default:
fprintf(stderr, "kdotp::libmodelxx::grid::cartesian_grid::point_is_in_tree: unknown shape type %d. Assuming point NOT in tree.\n", s->type);
return false;
}
/*If we've hit this point, we've gone too far.*/
return false;
}
Here is the caller graph for this function:| void kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_point | ( | unsigned * | X, |
| T * | val, | ||
| unsigned | c = 0 |
||
| ) | [inline] |
Sets a point in the grid, by grid site
Definition at line 718 of file cartesian_grid.h++.
Referenced by kdotp::libmetacalc::optimizer::digital_alloy_optimizer_1d_mpi::set_block(), kdotp::libmetacalc::optimizer::digital_alloy_optimizer_1d::set_block(), and kdotp::libmetacalc::optimizer::continuous_alloy_optimizer_1d::set_block().
{
data[point_index_to_storage_index(X, c)] = *val;
}
Here is the caller graph for this function:| void kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_point | ( | unsigned * | X, |
| T & | val, | ||
| unsigned | c = 0 |
||
| ) | [inline] |
Definition at line 721 of file cartesian_grid.h++.
{
data[point_index_to_storage_index(X, c)] = val;
}
| void kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_point_ | ( | unsigned * | X, |
| T & | val, | ||
| unsigned | c = 0 |
||
| ) | [inline] |
Definition at line 724 of file cartesian_grid.h++.
{
data[point_index_to_storage_index(X, c)] = val;
}
| static GError* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_point_function | ( | double * | x, |
| int | dee, | ||
| T * | location, | ||
| void * | privdat | ||
| ) | [inline, static] |
Definition at line 189 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_points().
{
struct cartesian_set_function_callback_data* d = (struct cartesian_set_function_callback_data*)privdat;
get_point_value_from_double_callback cb = d->cb;
int dim = get_function_datatype(d->exp, ((struct cartesian_set_function_callback_data*)privdat)->global_symbol_table, ((struct cartesian_set_function_callback_data*)privdat)->local_symbol_table);
if(dim < 0) return g_error_new(CARTESIAN_GRID_GERROR_DOMAIN, 200, "kdotp::libkdotp::libmodelxx::grid::cartesian_grid::set_point_function: got invalid dimension from function datatype: %d", dim);
if(dim < 1) dim = 1;
double* value = new double[dim];
GError *e = NULL;
/*Set the x value.*/
((struct cartesian_set_function_callback_data*)privdat)->ste_x->value = x;
if((e=evaluate_function(value, d->exp, ((struct cartesian_set_function_callback_data*)privdat)->global_symbol_table, ((struct cartesian_set_function_callback_data*)privdat)->local_symbol_table)) != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libkdotp::libmodelxx::grid::cartesian_grid::set_point_function: got error when evaluating function.");
delete[] value;
return err;
}
e= NULL;
e = (*cb)(location, value, dim, d->privdat);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libkdotp::libmodelxx::grid::cartesian_grid::set_point_function: got error when setting material.");
delete[] value;
return err;
}
fprintf(stderr, "x=%g->location=%p\n", x[0], (void*)location);
delete[] value;
return NULL;
}
Here is the caller graph for this function:| static GError* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_point_function_callback_d_imp | ( | double * | x, |
| int | dim, | ||
| T * | location, | ||
| void * | data | ||
| ) | [inline, static] |
Definition at line 162 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_points().
{
struct ezstruct* ezs = (struct ezstruct*)data;
return ezs->spcb(location, ezs->privdat);
}
Here is the caller graph for this function:| GError* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_points | ( | const struct shape_tree * | st, |
| set_points_callback | spcb, | ||
| GHashTable * | global_symbols, | ||
| void * | privdat = NULL |
||
| ) | [inline] |
Definition at line 166 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_points().
{
struct ezstruct ezs = {spcb, privdat};
return set_points(st, &set_point_function_callback_d_imp, NULL, global_symbols, &ezs);
}
Here is the caller graph for this function:| GError* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_points | ( | const struct shape_tree * | st, |
| postprocessing::function_exp * | exp, | ||
| GHashTable * | global_symbol_table, | ||
| get_point_value_from_double_callback | cb, | ||
| void * | privdat = NULL |
||
| ) | [inline] |
Set all components at the points that are in the shape defined by the tree.
| st* | pointer to the shape tree |
| T* | pointer to an Nc-size array of values to be set |
Definition at line 224 of file cartesian_grid.h++.
{
struct cartesian_set_function_callback_data csf = {exp, cb, global_symbol_table, st_x, &ste_x, privdat};
return set_points(st, &set_point_function, NULL, global_symbol_table, &csf);
}
| int kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_points | ( | const struct shape_tree * | st, |
| T * | val, | ||
| GHashTable * | global_symbols | ||
| ) | [inline] |
Set all components at the points that are in the shape defined by the tree.
| st* | pointer to the shape tree |
| T* | pointer to an Nc-size array of values to be set |
Definition at line 380 of file cartesian_grid.h++.
{
/*X is the integer location*/
unsigned int X[D];
/*x is the floating-point location*/
double x[D];
unsigned int d;
for(d=0; d<D; d++) X[d]=0;
/*X[0] is the lowest dimension; X[D-1] is the lowest
*Here's the idea: X can be viewed as an integer number with
* a digit-dependent basis. The algorithm:
*1) carry is set to 0 going into the loop
*2) When the counter is updated, carry will be set to 0,
* unless the last "digit" overflows, in which case carry stays 1.
*3) If carry is still 1 coming out of the X update, we're done.
*/
unsigned int carry=0;
unsigned int c;
while(carry == 0) {
point_index_to_realspace(X, x);
if(point_is_in_tree(x, st, global_symbols)) {
//fprintf(stderr, "Y");
/*Note that this for loop can likely be unrolled.
*The if statement should be compiled out; it'll never
*change at runtime.
*/
for(c=0; c<Nc; c++) {
if(Nc == 1) {
data[point_index_to_storage_index(X)] = val[c];
}else{
data[point_index_to_storage_index(X, c)] = val[c];
}
}
//}else{
//fprintf(stderr, "N");
}
/*Now update our point.*/
carry=1;
for(d=0; ((d<D)&&(carry==1)); d++) {
//fprintf(stderr, "%d->", X[d]);
X[d] += carry;
//fprintf(stderr, "%d/", X[d]);
if(X[d] >= L[d]) {
X[d] = 0;
carry = 1;
}else{
carry = 0;
}
}
//fprintf(stderr, "\n");
}
return 0;
}
| GError* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::set_points | ( | const struct shape_tree * | st, |
| set_point_function_callback_d | dcb, | ||
| set_point_function_callback_i | icb, | ||
| GHashTable * | global_symbols, | ||
| void * | privdat = NULL |
||
| ) | [inline] |
Definition at line 229 of file cartesian_grid.h++.
{
/*X is the integer location*/
unsigned int X[D];
/*x is the floating-point location*/
double x[D];
unsigned int d;
for(d=0; d<D; d++) X[d]=0;
/*X[0] is the lowest dimension; X[D-1] is the lowest
*Here's the idea: X can be viewed as an integer number with
* a digit-dependent basis. The algorithm:
*1) carry is set to 0 going into the loop
*2) When the counter is updated, carry will be set to 0,
* unless the last "digit" overflows, in which case carry stays 1.
*3) If carry is still 1 coming out of the X update, we're done.
*/
GError *e = NULL;
unsigned int carry=0;
unsigned int c;
while(carry == 0) {
point_index_to_realspace(X, x);
if(point_is_in_tree(x, st, global_symbols)) {
//fprintf(stderr, "Y");
/*Note that this for loop can likely be unrolled.
*The if statement should be compiled out; it'll never
*change at runtime.
*/
for(c=0; c<Nc; c++) {
if(Nc == 1) {
if(dcb != NULL) {
e = dcb(x, D, &data[point_index_to_storage_index(X)], privdat);
}else{
e = icb(X, D, &data[point_index_to_storage_index(X)], privdat);
}
}else{
if(dcb != NULL) {
e = dcb(x, D, &data[point_index_to_storage_index(X, c)], privdat);
}else{
e = icb(X, D, &data[point_index_to_storage_index(X, c)], privdat);
}
}
if(e != NULL) {
GError *err = NULL;
GString *s = g_string_new("");
GString *S = g_string_new("");
for(unsigned int i=0; i<D; i++) {
g_string_append_printf(s, " %g", x[i]);
g_string_append_printf(S, " %u", X[i]);
}
g_propagate_prefixed_error(&err, e, "kdotp::libmodeling::grid::cartesian_grid::set_points<full>: Got error evaluating point %s (grid site %s) c=%u: ", s->str, S->str, c);
g_string_free(s, TRUE);
g_string_free(S, TRUE);
return err;
}
}
//}else{
//fprintf(stderr, "N");
}
/*Now update our point.*/
carry=1;
for(d=0; ((d<D)&&(carry==1)); d++) {
//fprintf(stderr, "%d->", X[d]);
X[d] += carry;
//fprintf(stderr, "%d/", X[d]);
if(X[d] >= L[d]) {
X[d] = 0;
carry = 1;
}else{
carry = 0;
}
}
//fprintf(stderr, "\n");
}
return 0;
}
| double kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::a[D] |
Definition at line 746 of file cartesian_grid.h++.
Referenced by kdotp::libkdotp::hamiltonian::cartesian_effective_mass::cartesian_effective_mass(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::cartesian_grid(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::cartesian_grid_init(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::create_indexed_unique_component_grid(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::dump(), and kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::point_index_to_realspace().
| T* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::data |
Definition at line 749 of file cartesian_grid.h++.
Referenced by kdotp::libkdotp::hamiltonian::cartesian_8band::cartesian_8band(), kdotp::libkdotp::hamiltonian::cartesian_effective_mass::cartesian_effective_mass(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::cartesian_grid_init(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::create_indexed_unique_component_grid(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::dump_foreach_callback(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::for_each_point(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::get_point(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::get_point_r(), main(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_point(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_point_(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_points(), kdotp::libkdotp::hamiltonian::store_reduced_material_parameters(), and write_raw_bands_file().
| unsigned int kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::L[D] |
Definition at line 744 of file cartesian_grid.h++.
Referenced by calculate_alpha_for_structure(), kdotp::libkdotp::hamiltonian::cartesian_8band::cartesian_8band(), kdotp::libkdotp::hamiltonian::cartesian_effective_mass::cartesian_effective_mass(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::cartesian_grid(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::cartesian_grid_init(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::create_indexed_unique_component_grid(), kdotp::libmetacalc::optimizer::digital_alloy_optimizer_1d::digital_alloy_optimizer_1d(), kdotp::libmetacalc::optimizer::digital_alloy_optimizer_1d_mpi::digital_alloy_optimizer_1d_mpi(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::dump(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::for_each_point(), main(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::point_index_to_realspace(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::point_index_to_storage_index(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::point_is_in_shape(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_points(), kdotp::libkdotp::hamiltonian::store_reduced_material_parameters(), and write_raw_bands_file().
| long unsigned int kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::num_pts |
| GHashTable* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::st_X |
Definition at line 753 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::cartesian_grid_init().
| GHashTable* kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::st_x |
| struct ::kdotp::libmodelxx::postprocessing::symbol_table_entry_const kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::ste_X |
Definition at line 752 of file cartesian_grid.h++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::cartesian_grid_init().
| struct ::kdotp::libmodelxx::postprocessing::symbol_table_entry_const kdotp::libmodelxx::grid::cartesian_grid< T, D, Nc >::ste_x |