|
k-dot-p 0.1
|
Classes | |
| struct | function_exp |
| struct | function_const |
| struct | function_symbol |
| struct | symbol_table_entry |
| struct | symbol_table_entry_const |
| struct | template_parameter_range |
Enumerations | |
| enum | function_op { PLUS, MINUS, MUL, DIV, EXP, CONST, COS, SIN, TAN, LOG, ACOS, ASIN, ATAN, ABS, SQRT, DOT, CROSS, NEG, OR, AND, XOR, NOT, SYMBOL } |
| enum | function_datatype { INVALID = -1, BINARY, SCALAR, VECTOR2, VECTOR3 } |
| enum | symbol_type { CONSTANT_SYMBOL } |
Functions | |
| enum function_op | function_get_op_for_builtin_function (const char *bf) |
| void | function_print_tree (struct function_const *e, GString **s, int indentation) |
| void | function_print_tree (struct function_symbol *e, GString **s, int indentation) |
| void | function_print_tree (struct function_exp *e, GString **s, int indentation) |
| GError * | evaluate_function (double *value, const struct function_exp *f, GHashTable *global_symbols, GHashTable *local_symbols) |
| enum function_datatype | get_function_datatype (struct function_exp *f, GHashTable *global_symbols, GHashTable *local_symbols) |
| struct symbol_table_entry * | get_symbol_table_entry (const char *symbol, GHashTable *global_symbols, GHashTable *local_symbols, GError **e) |
| void | add_symbol_table_entry (GHashTable *st, const char *symbol, struct symbol_table_entry *entry) |
| static void | destroy_symbol_table_entry (void *ste_) |
| static void | destroy_symbol_table_symbol (void *symbol) |
| GHashTable * | new_symbol_table () |
| void | parameter_list_init (GList *parameters) |
| bool | update_parameters_plus_check_if_done (GList *parameters) |
| GFile * | get_gfile_directory_for_template_state (const char *prefix, GList *parameters) |
| void | add_template_parameters_to_symbol_table (GHashTable *st, GList *parms) |
| char * | get_string_for_template_state (GList *parameters) |
| char * | get_header_for_template_state (GList *parameters) |
| void | free_function (struct function_const *e) |
| void | free_function (struct function_symbol *e) |
| void | free_function (struct function_exp *e) |
| PLUS | |
| MINUS | |
| MUL | |
| DIV | |
| EXP | |
| CONST | |
| COS | |
| SIN | |
| TAN | |
| LOG | |
| ACOS | |
| ASIN | |
| ATAN | |
| ABS | |
| SQRT | |
| DOT | |
| CROSS | |
| NEG | |
| OR | |
| AND | |
| XOR | |
| NOT | |
| SYMBOL |
Definition at line 34 of file function_specification.h++.
Definition at line 88 of file function_specification.h++.
{
CONSTANT_SYMBOL
//USER_FUNCTION
};
| void kdotp::libmodelxx::postprocessing::add_symbol_table_entry | ( | GHashTable * | st, |
| const char * | symbol, | ||
| struct symbol_table_entry * | entry | ||
| ) |
Definition at line 580 of file function_specification.c++.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::cartesian_grid_init().
{
/*Copy the string*/
GString* sb = g_string_new(symbol);
g_hash_table_insert(st, sb->str, entry);
g_string_free(sb, FALSE);
}
Here is the caller graph for this function:| void kdotp::libmodelxx::postprocessing::add_template_parameters_to_symbol_table | ( | GHashTable * | st, |
| GList * | parms | ||
| ) |
Definition at line 648 of file function_specification.c++.
References CONSTANT_SYMBOL, kdotp::libmodelxx::postprocessing::template_parameter_range::current_value, kdotp::libmodelxx::postprocessing::symbol_table_entry::dt, kdotp::libmodelxx::postprocessing::symbol_table_entry_const::dt, SCALAR, kdotp::libmodelxx::postprocessing::symbol_table_entry::st, kdotp::libmodelxx::postprocessing::symbol_table_entry_const::st, kdotp::libmodelxx::postprocessing::template_parameter_range::symbol, and kdotp::libmodelxx::postprocessing::symbol_table_entry_const::value.
Referenced by main().
{
struct symbol_table_entry *ste;
struct symbol_table_entry_const *stec=NULL;
struct template_parameter_range *tpm;
for(GList* ll=parms; ll!=NULL; ll=ll->next) {
tpm = (struct template_parameter_range *)ll->data;
ste = (struct symbol_table_entry*)g_hash_table_lookup(st, tpm->symbol);
if(ste == NULL) {
stec = (struct symbol_table_entry_const*)malloc(sizeof(struct symbol_table_entry_const));
if(stec == NULL) {
fprintf(stderr, "ERROR: unable to allocate new symbol table entry for symbol (%s)\n", tpm->symbol);
continue;
}
stec->st = CONSTANT_SYMBOL;
stec->dt = SCALAR;
stec->value = (double*)malloc(sizeof(double));
if(stec->value == NULL) {
fprintf(stderr, "ERROR: unable to allocate new symbol table entry value storage for symbol (%s)\n", tpm->symbol);
continue;
}
g_hash_table_insert(st, tpm->symbol, (struct symbol_table_entry*)stec);
}else{
if(ste->st != CONSTANT_SYMBOL) {
fprintf(stderr, "ERROR: symbol table entry for symbol (%s) is not a constant symbol (is %d)\n", tpm->symbol, stec->st);
continue;
}
if(ste->dt != SCALAR) {
fprintf(stderr, "ERROR: symbol table entry for symbol (%s) is not a scalar type (is %d)\n", tpm->symbol, stec->dt);
continue;
}
stec = (struct symbol_table_entry_const*)ste;
}
*(stec->value)=tpm->current_value;
}
}
Here is the caller graph for this function:| static void kdotp::libmodelxx::postprocessing::destroy_symbol_table_entry | ( | void * | ste_ | ) | [static] |
Definition at line 588 of file function_specification.c++.
References CONSTANT_SYMBOL, and kdotp::libmodelxx::postprocessing::symbol_table_entry::st.
Referenced by new_symbol_table().
{
struct symbol_table_entry *ste = (struct symbol_table_entry *)ste_;
switch(ste->st) {
case CONSTANT_SYMBOL:
free(((struct symbol_table_entry_const*)ste)->value);
break;
default:
/*we can't communicate an error, so do no further processing*/
;
}
/*Finally, free the structure itself*/
free((struct symbol_table_entry_const*)ste);
}
Here is the caller graph for this function:| static void kdotp::libmodelxx::postprocessing::destroy_symbol_table_symbol | ( | void * | symbol | ) | [static] |
Definition at line 602 of file function_specification.c++.
Referenced by new_symbol_table().
{
free(symbol);
}
Here is the caller graph for this function:| GError * kdotp::libmodelxx::postprocessing::evaluate_function | ( | double * | values, |
| const struct function_exp * | f, | ||
| GHashTable * | global_symbols, | ||
| GHashTable * | local_symbols | ||
| ) |
Evaluates a function using a set of symbol tables
| values | array to store the results in |
| f | the function to be evaluated |
| global_symbols | the global symbol table (e.g. constants, built-in template parameters), user-defined template parameters |
| local_symbols | the local symbol table (e.g. x, X) |
MUL and DIV can take scalar*vec
MUL and DIV can take scalar*vec
Definition at line 140 of file function_specification.c++.
References ABS, ACOS, AND, ASIN, ATAN, BINARY, CONST, CONSTANT_SYMBOL, COS, CROSS, DIV, DOT, kdotp::libmodelxx::postprocessing::symbol_table_entry::dt, kdp::constants::e, EXP, FUNCTION_SPECIFICATION_GERROR_DOMAIN, get_function_datatype(), get_symbol_table_entry(), INVALID, kdotp::libmodelxx::postprocessing::function_exp::l, LOG, MINUS, MUL, NEG, NOT, kdotp::libmodelxx::postprocessing::function_symbol::op, kdotp::libmodelxx::postprocessing::function_const::op, kdotp::libmodelxx::postprocessing::function_exp::op, OR, PLUS, kdotp::libmodelxx::postprocessing::function_exp::r, SCALAR, SIN, SQRT, kdotp::libmodelxx::postprocessing::symbol_table_entry::st, SYMBOL, TAN, and XOR.
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::point_is_in_shape(), and kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_point_function().
{
GError *err=NULL;
GError *e=NULL;
struct symbol_table_entry *ste;
enum function_datatype lt=INVALID, rt=INVALID;
double *l=NULL;
double *r=NULL;
/*Don't evaluate l & r if we're not actually a function_exp!!*/
//fprintf(stderr, "carteisan_evaulate_function: op=%d", f->op);
if((!((f->op == SYMBOL) ||(f->op == CONST))) && (f->l != NULL)) {
lt = get_function_datatype(f->l, global_symbols, local_symbols);
l = new double[lt];
//fprintf(stderr, "\trecursing left\n");
e = evaluate_function(l, f->l, global_symbols, local_symbols);
if(e != NULL) {
g_propagate_prefixed_error(&err, e, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: binary operator %d got error on left-hand side: ", f->op);
delete[] l;
return err;
}
} else {
lt = INVALID;
l = NULL;
}
/*Don't evaluate l & r if we're not actually a function_exp!!*/
if((!((f->op == SYMBOL) ||(f->op == CONST))) && (f->r != NULL)) {
rt = get_function_datatype(f->r, global_symbols, local_symbols);
r = new double[rt];
//fprintf(stderr, "\trecursing right\n");
e = evaluate_function(r, f->r, global_symbols, local_symbols);
if(e != NULL) {
g_propagate_prefixed_error(&err, e, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: binary operator %d got error on right-hand side: ", f->op);
if(l != NULL) delete[] l;
delete[] r;
return err;
}
} else {
rt = INVALID;
r = NULL;
}
/*
fprintf(stderr, "carteisan_evaulate_function: lt=%d rt=%d op=%d", lt, rt, f->op);
if(l != NULL) {
fprintf(stderr, " l[0]=%g", l[0]);
}else{
fprintf(stderr, " l[0]=NULL");
}
if(r != NULL) {
fprintf(stderr, " r[0]=%g", r[0]);
}else{
fprintf(stderr, " r[0]=NULL");
}
fprintf(stderr, "\n");
*/
switch(f->op) {
case PLUS:
case MINUS:
case MUL:
case DIV:
/**MUL and DIV can take scalar*vec*/
if(!(
((f->op == MUL)&&((rt == 1) || (lt == 1)))
||((f->op == DIV)&&(rt==1))
|| (rt == lt)
)) {
if(l == NULL) delete[] l;
if(r == NULL) delete[] r;
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 100, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with binary operation, left and right dimensions are not the same or a scalar * vec or vec */ scalar! (op=%d; l=%d, r=%d)", f->op, lt, rt);
}
if((rt < SCALAR) || (lt < SCALAR)) {
if(l == NULL) delete[] l;
if(r == NULL) delete[] r;
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 101, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with binary operation %d, arguments are invalid!", f->op);
}
/*Since we're iterating over rt, we need to iterate properly if
*rt is 1 but lt isn't.
*/
if((f->op == MUL) && (lt > rt)) {
for(int i=0; i<lt; i++) {
value[i] = l[i] * r[0];
//fprintf(stderr, "rt*1: %g = %g*%g\n", value[i], l[i], r[i]);
}
}else if((f->op == DIV) && (lt > rt)) {
for(int i=0; i<lt; i++) {
value[i] = l[i] / r[0];
//fprintf(stderr, "rt1/: %g = %g/%g\n", value[i], l[i], r[i]);
}
}else{
for(int i=0; i<rt; i++) {
switch(f->op) {
case PLUS:
value[i] = l[i] + r[i];
//fprintf(stderr, "%g = %g+%g\n", value[i], l[i], r[i]);
break;
case MINUS:
value[i] = l[i] - r[i];
//fprintf(stderr, "%g = %g-%g\n", value[i], l[i], r[i]);
break;
case MUL:
if(lt == 1) {
value[i] = l[0] * r[i];
//fprintf(stderr, "lt1*: %g = %g*%g\n", value[i], l[0], r[i]);
}else{
value[i] = l[i] * r[i];
//fprintf(stderr, "*: %g = %g*%g\n", value[i], l[i], r[i]);
}
break;
case DIV:
value[i] = l[i] / r[i];
//fprintf(stderr, "/: %g = %g/%g\n", value[i], l[i], r[i]);
break;
default:
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 107, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with binary operation %d, unhandled op-specific handling!", f->op);
}
}
}
break;
case CONST:
if(((struct function_const*)f)->value == NULL) {
value[0] = 0;
break;
}
if(((struct function_const*)f)->t == 0) {
value[0] = ((struct function_const*)f)->value[0];
break;
}
else for(int i=0; i<((struct function_const*)f)->t; i++) value[i] = ((struct function_const*)f)->value[i];
//fprintf(stderr, "const: value[0]=%g\n", value[0]);
break;
case COS:
case SIN:
case TAN:
case LOG:
case EXP:
case ACOS:
case ASIN:
case ATAN:
case ABS:
case SQRT:
if(rt != 1) {
if(l == NULL) delete[] l;
if(r == NULL) delete[] r;
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 102, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with builtin function %d, argument dimension %d is not 1!", f->op, rt);
}
switch(f->op) {
case COS:
value[0] = cos(r[0]);
//fprintf(stderr, "%g=cos(%g)\n", value[0], r[0]);
break;
case SIN:
value[0] = sin(r[0]);
//fprintf(stderr, "%g=sin(%g)\n", value[0], r[0]);
break;
case TAN:
value[0] = tan(r[0]);
//fprintf(stderr, "%g=tan(%g)\n", value[0], r[0]);
break;
case LOG:
value[0] = log(r[0]);
//fprintf(stderr, "%g=log(%g)\n", value[0], r[0]);
break;
case EXP:
value[0] = ::exp(r[0]);
//fprintf(stderr, "%g=exp(%g)\n", value[0], r[0]);
break;
case ACOS:
value[0] = acos(r[0]);
//fprintf(stderr, "%g=acos(%g)\n", value[0], r[0]);
break;
case ASIN:
value[0] = asin(r[0]);
//fprintf(stderr, "%g=asin(%g)\n", value[0], r[0]);
break;
case ATAN:
value[0] = atan(r[0]);
//fprintf(stderr, "%g=atan(%g)\n", value[0], r[0]);
break;
case ABS:
value[0] = fabs(r[0]);
//fprintf(stderr, "%g=abs(%g)\n", value[0], r[0]);
break;
case SQRT:
value[0] = sqrt(r[0]);
//fprintf(stderr, "%g=sqrt(%g)\n", value[0], r[0]);
break;
default:
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 107, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with builting function %d, unhandled op-specific handling!", f->op);
}
break;
case DOT:
case CROSS:
/**MUL and DIV can take scalar*vec*/
if(rt == lt) {
if(l == NULL) delete[] l;
if(r == NULL) delete[] r;
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 100, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with binary vector operation, left and right dimensions are not the same or a scalar * vec or vec */ scalar! (op=%d; l=%d, r=%d)", f->op, lt, rt);
}
if(rt < SCALAR) {
if(l == NULL) delete[] l;
if(r == NULL) delete[] r;
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 101, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with binary vector operation %d, arguments are invalid!", rt);
}
value[0] = 0;
switch(f->op) {
case DOT:
for(int i=0; i<lt; i++) value[0] += l[i]*r[i];
break;
case CROSS:
/*THIS NEEDS A CLEVER ALGO*/
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 101, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with binary vector operation %d, cross product is not yet implemented!", rt);
break;
default:
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 107, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with binary vector operation %d, unhandled op-specific handling!", f->op);
}
break;
case postprocessing::OR:
case postprocessing::AND:
case postprocessing::XOR:
if(rt == lt) {
if(l == NULL) delete[] l;
if(r == NULL) delete[] r;
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 100, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with binary binary operation, left and right dimensions are not the same scalar! (op=%d; l=%d, r=%d)", f->op, lt, rt);
}
if(rt != BINARY) {
if(l == NULL) delete[] l;
if(r == NULL) delete[] r;
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 101, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with binary binary operation %d, arguments are invalid!", rt);
}
switch(f->op) {
case OR:
value[0] = (l[0] || r[0]);
break;
case AND:
value[0] = (l[0] && r[0]);
break;
case XOR:
value[0] = ((l[0] || r[0]) && (!(l[0] && r[0])));
break;
default:
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 107, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with boolean binary operation %d, unhandled op-specific handling!", f->op);
}
break;
case postprocessing::NOT:
if(rt != BINARY) {
if(l == NULL) delete[] l;
if(r == NULL) delete[] r;
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 101, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with binary binary operation %d, arguments are invalid!", rt);
}
value[0] = !r[0];
break;
case SYMBOL:
ste = get_symbol_table_entry(((struct function_symbol*)f)->symbol, global_symbols, local_symbols, &e);
if((e != NULL) || (ste == NULL)) {
if(e == NULL) {
e = g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 100, "::kdotp::libmodelxx::function_specification.c++::evaluate_symbol: (%s) Unknown error looking up symbol in symbol tables.", (((struct function_symbol*)f)->symbol));
}
g_propagate_prefixed_error(&err, e, "::kdotp::libmodelxx::function_specification.c++::evaluate_symbol: (%s) Error looking up symbol in symbol tables.", (((struct function_symbol*)f)->symbol));
return err;
}
switch(ste->st) {
case CONSTANT_SYMBOL:
for(int i=0; i<ste->dt; i++) {
value[i]=((struct symbol_table_entry_const*)ste)->value[i];
}
break;
default:
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 100, "::kdotp::libmodelxx::function_specification.c++::evaluate_symbol: (%s) Symbol is of unknown symbol type (%d).", (((struct function_symbol*)f)->symbol), ste->st);
}
//fprintf(stderr, "symbol %s: value[0]=%g\n", ((struct function_symbol*)f)->symbol, value[0]);
break;
case NEG:
/*We can also negate a vector*/
if(rt < 1) {
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 104, "::kdotp::libmodelxx::function_specification.c++::evaluate_function: with symbol (op NEG (%d)): right-hand side is not a valid number (scalar or higher-dimension)!", f->op);
}
for(int i=0; i<rt; i++) {
value[i] = -r[i];
}
break;
default:
//fprintf(stderr, "Unknown op: %d\n", f->op);
return g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 104, "WARNING: expression operator %d not implemented!", f->op);
}
//fprintf(stderr, "exiting op(%d)\n", f->op);
return NULL;
}
Here is the call graph for this function:
Here is the caller graph for this function:| void kdotp::libmodelxx::postprocessing::free_function | ( | struct function_const * | e | ) |
Definition at line 722 of file function_specification.c++.
References kdotp::libmodelxx::postprocessing::function_const::value.
Referenced by free_function(), and kdotp::libmodelxx::grid::shape_block_free().
Here is the caller graph for this function:| void kdotp::libmodelxx::postprocessing::free_function | ( | struct function_symbol * | e | ) |
Definition at line 727 of file function_specification.c++.
References kdotp::libmodelxx::postprocessing::function_symbol::symbol.
| void kdotp::libmodelxx::postprocessing::free_function | ( | struct function_exp * | e | ) |
Definition at line 732 of file function_specification.c++.
References CONST, free_function(), kdotp::libmodelxx::postprocessing::function_exp::op, and SYMBOL.
{
switch(e->op) {
case CONST:
free_function((struct function_const*)e);
break;
case SYMBOL:
free_function((struct function_symbol*)e);
break;
default:
if(e->l != NULL) free_function(e->l);
if(e->r != NULL) free_function(e->r);
free(e);
}
}
Here is the call graph for this function:| enum function_op kdotp::libmodelxx::postprocessing::function_get_op_for_builtin_function | ( | const char * | c | ) |
get a function
| c | the builtin function to look up |
Definition at line 34 of file function_specification.c++.
References ABS, ACOS, ASIN, ATAN, COS, EXP, LOG, NOT, SIN, SQRT, and TAN.
Referenced by new_fx_func().
{
if(!g_ascii_strncasecmp("exp", bf, 3)) {
return EXP;
}else if(!g_ascii_strncasecmp("cos", bf, 3)) {
return COS;
}else if(!g_ascii_strncasecmp("sin", bf, 3)) {
return SIN;
}else if(!g_ascii_strncasecmp("tan", bf, 3)) {
return TAN;
}else if(!g_ascii_strncasecmp("acos", bf, 4)) {
return ACOS;
}else if(!g_ascii_strncasecmp("asin", bf, 4)) {
return ASIN;
}else if(!g_ascii_strncasecmp("atan", bf, 4)) {
return ATAN;
}else if(!g_ascii_strncasecmp("log", bf, 3)) {
return LOG;
}else if(!g_ascii_strncasecmp("abs", bf, 3)) {
return ABS;
}else if(!g_ascii_strncasecmp("sqrt", bf, 4)) {
return SQRT;
}else{
return NOT;
}
}
Here is the caller graph for this function:| void kdotp::libmodelxx::postprocessing::function_print_tree | ( | struct function_exp * | e, |
| GString ** | s, | ||
| int | indentation | ||
| ) |
Pretty prints a function tree to a sring you can print out. e the expression to print s a GString to which the output will be appended
Definition at line 72 of file function_specification.c++.
References ABS, ACOS, ASIN, ATAN, CONST, COS, CROSS, DIV, DOT, EXP, function_print_tree(), LOG, MINUS, MUL, NEG, kdotp::libmodelxx::postprocessing::function_symbol::op, kdotp::libmodelxx::postprocessing::function_exp::op, PLUS, SIN, SQRT, SYMBOL, and TAN.
{
g_string_append_printf(*s, "\n%05d", indentation);
for(int i=0; i<indentation; i++) {
g_string_append_printf(*s, "%s", "\t");
}
if(e == NULL) {
g_string_append_printf(*s, "%s", "[*]");
return;
}
const char* funcname = NULL;
switch(e->op) {
case CONST:
return function_print_tree((struct function_const*)e, s, indentation);
case SYMBOL:
return function_print_tree((struct function_symbol*)e, s, indentation);
case EXP:
funcname=(funcname==NULL)?"exp":funcname;
case LOG:
funcname=(funcname==NULL)?"log":funcname;
case COS:
funcname=(funcname==NULL)?"cos":funcname;
case SIN:
funcname=(funcname==NULL)?"sin":funcname;
case TAN:
funcname=(funcname==NULL)?"tan":funcname;
case ACOS:
funcname=(funcname==NULL)?"acos":funcname;
case ASIN:
funcname=(funcname==NULL)?"asin":funcname;
case ATAN:
funcname=(funcname==NULL)?"atan":funcname;
case ABS:
funcname=(funcname==NULL)?"abs":funcname;
case SQRT:
funcname=(funcname==NULL)?"sqrt":funcname;
case NEG:
funcname=(funcname==NULL)?"NEG":funcname;
/*The above have just one argument:
*NOTE that funcname will just be assigned once, when we jump in.
*/
g_string_append_printf(*s, "%s", funcname);
/*recurse!*/
function_print_tree(e->l, s, indentation+1);
return function_print_tree(e->r, s, indentation+1);
case PLUS:
funcname=(funcname==NULL)?"PLUS":funcname;
case MINUS:
funcname=(funcname==NULL)?"MINUS":funcname;
case MUL:
funcname=(funcname==NULL)?"MUL":funcname;
case DIV:
funcname=(funcname==NULL)?"DIV":funcname;
case DOT:
funcname=(funcname==NULL)?"DOT":funcname;
case CROSS:
funcname=(funcname==NULL)?"CROSS":funcname;
g_string_append_printf(*s, "%s", funcname);
/*recurse!*/
function_print_tree(e->l, s, indentation+1);
return function_print_tree(e->r, s, indentation+1);
default:
g_string_append_printf(*s, "[UNKNOWN OPERATION (%d)]", e->op);
function_print_tree(e->l, s, indentation+1);
return function_print_tree(e->r, s, indentation+1);
}
g_string_append_printf(*s, "%s", "[hit end of routine (coding error)]");
}
Here is the call graph for this function:| void kdotp::libmodelxx::postprocessing::function_print_tree | ( | struct function_const * | e, |
| GString ** | s, | ||
| int | indentation | ||
| ) |
Definition at line 60 of file function_specification.c++.
References kdotp::libmodelxx::postprocessing::function_const::t, and kdotp::libmodelxx::postprocessing::function_const::value.
Referenced by function_print_tree(), kdotp::libmodelxx::grid::make_block_from_shape(), kdotp::libmodelxx::continuous_structure::postprocess_structure(), and yyparse().
{
g_string_append_printf(*s, "%s", "const(");
for(int i=0; i<(e->t-1); i++) {
g_string_append_printf(*s, "%g,", e->value[i]);
}
g_string_append_printf(*s, "%g)", e->value[e->t-1]);
}
Here is the caller graph for this function:| void kdotp::libmodelxx::postprocessing::function_print_tree | ( | struct function_symbol * | e, |
| GString ** | s, | ||
| int | indentation | ||
| ) |
Definition at line 68 of file function_specification.c++.
References kdotp::libmodelxx::postprocessing::function_symbol::symbol.
{
g_string_append_printf(*s, "SYMBOL(%s)", e->symbol);
}
| enum function_datatype kdotp::libmodelxx::postprocessing::get_function_datatype | ( | struct function_exp * | exp, |
| GHashTable * | global_symbols, | ||
| GHashTable * | local_symbols | ||
| ) |
This gets the data type for the function
| global_symbols | the global symbol table (e.g. constants, built-in template parameters), user-defined template parameters |
| local_symbols | the local symbol table (e.g. x, X) |
| exp | function |
Definition at line 426 of file function_specification.c++.
References ABS, ACOS, AND, ASIN, ATAN, BINARY, CONST, COS, CROSS, DIV, DOT, kdotp::libmodelxx::postprocessing::symbol_table_entry::dt, kdp::constants::e, EXP, get_symbol_table_entry(), INVALID, kdotp::libmodelxx::postprocessing::function_exp::l, LOG, MINUS, MUL, NEG, NOT, kdotp::libmodelxx::postprocessing::function_symbol::op, kdotp::libmodelxx::postprocessing::function_exp::op, OR, PLUS, kdotp::libmodelxx::postprocessing::function_exp::r, SCALAR, SIN, SQRT, SYMBOL, TAN, and XOR.
Referenced by evaluate_function(), kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::point_is_in_shape(), and kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::set_point_function().
{
struct symbol_table_entry* ste;
GError *e = NULL;
enum function_datatype lt=INVALID, rt=INVALID;
if(!((f->op == SYMBOL) || (f->op == CONST))) {
if(f->l != NULL) lt = get_function_datatype(f->l, global_symbols, local_symbols);
else lt = INVALID;
if(f->r != NULL) rt = get_function_datatype(f->r, global_symbols, local_symbols);
else lt = INVALID;
}
switch(f->op) {
case PLUS:
case MINUS:
if(lt != rt) {
//fprintf(stderr, "+-: lt!=rt: INVALID\n");
return INVALID;
}
if(rt < 1) {
//fprintf(stderr, "+-: rt<1: INVALID\n");
return INVALID;
}
//fprintf(stderr, "+-: default (=rt=%d)\n", rt);
return rt;
case MUL:
if((lt < 1) || (rt < 1)) {
//fprintf(stderr, "*: lt||rt<1: INVALID\n");
return INVALID;
}
if(lt == 1) {
//fprintf(stderr, "*: lt==1: =rt=%d\n", rt);
return rt;
}
if(rt == 1) {
//fprintf(stderr, "*: rt==1: =lt=\n");
return lt;
}
if(lt != rt) {
//fprintf(stderr, "*: lt!=rt: INVALID\n");
return INVALID;
}
//fprintf(stderr, "*: default (=rt=%d)\n", rt);
return rt;
case DIV:
if((lt < 1) || (rt < 1)) {
//fprintf(stderr, "/: lt||rt<1: INVALID\n");
return INVALID;
}
if(rt == 1) {
//fprintf(stderr, "/: rt==1: =lt=%d)\n", lt);
return lt;
}
if(lt != rt) {
//fprintf(stderr, "/: lt!=rt: INVALID\n");
return INVALID;
}
//fprintf(stderr, "/: default (=rt=%d)\n", rt);
return rt;
case CONST:
//fprintf(stderr, "CONST: exp has type %d\n", ((struct function_const*)f)->t);
return ((struct function_const*)f)->t;
case COS:
case SIN:
case TAN:
case LOG:
case EXP:
case ACOS:
case ASIN:
case ATAN:
case ABS:
case SQRT:
if(lt != INVALID) {
//fprintf(stderr, "builtin_scalar_func: lt(=%d)!=INVALID: INVALID\n", lt);
return INVALID;
}
if(rt != 1) {
//fprintf(stderr, "builtin_scalar_func: rt(=%d)!=SCALAR: INVALID\n", rt);
return INVALID;
}
//fprintf(stderr, "builtin_scalar_func: SCALAR\n");
return SCALAR;
case DOT:
if((lt < 1) || (rt < 1)) {
//fprintf(stderr, "DOT: lt||rt<1: INVALID\n");
return INVALID;
}
//fprintf(stderr, "DOT: SCALAR");
return SCALAR;
case CROSS:
if((lt < 1) || (rt < 1)) {
//fprintf(stderr, "CROSS: lt||rt<1: INVALID\n");
return INVALID;
}
if(lt != rt) {
//fprintf(stderr, "CROSS: lt!=rt: INVALID\n");
return INVALID;
}
//fprintf(stderr, "CROSS: default(=rt)\n");
return rt;
case postprocessing::OR:
case postprocessing::AND:
case postprocessing::XOR:
if((lt != 0) || (rt != 0)) {
//fprintf(stderr, "|&XOR: lt||rt!=0: INVALID\n");
return INVALID;
}
//fprintf(stderr, "|&XOR: BINARY\n");
return BINARY;
case postprocessing::NOT:
if(lt != INVALID) {
//fprintf(stderr, "!: lt!=INVALID\n");
return INVALID;
}
if(rt != 0) {
//fprintf(stderr, "!: rt!=BINARY\n");
return INVALID;
}
//fprintf(stderr, "!: BINARY\n");
return BINARY;
case SYMBOL:
ste = get_symbol_table_entry(((struct function_symbol*)f)->symbol, global_symbols, local_symbols, &e);
if((e != NULL) || (ste == NULL)) {
return INVALID;
}
return ste->dt;
case NEG:
if(rt < 1) {
//fprintf(stderr, "NEG: rt<1: INVALID\n");
return INVALID;
}
//fprintf(stderr, "NEG: default (=rt=%d)\n", rt);
return rt;
default:
fprintf(stderr, "UNRECOGNIZED OP(%d): INVALID\n", f->op);
return INVALID;
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| GFile * kdotp::libmodelxx::postprocessing::get_gfile_directory_for_template_state | ( | const char * | prefix, |
| GList * | parameters | ||
| ) |
Definition at line 626 of file function_specification.c++.
Referenced by main().
{
GString *s;
if(prefix == NULL) {
s = g_string_new("./");
}else{
s = g_string_new(prefix);
}
if(parameters != NULL) {
s = g_string_append(s, ((struct template_parameter_range*)parameters->data)->symbol);
g_string_append_printf(s, "=%g", ((struct template_parameter_range*)parameters->data)->current_value);
/*We started with the first so that we can prefix the string with an underscore.*/
if(parameters->next!=NULL) {
for(GList* ll = parameters->next; ll!=NULL; ll=ll->next) {
g_string_append_printf(s, "_%s=%g", ((struct template_parameter_range*)ll->data)->symbol, ((struct template_parameter_range*)ll->data)->current_value);
}
}
}
GFile *f = g_file_new_for_commandline_arg(s->str);
g_string_free(s, TRUE);
return f;
}
Here is the caller graph for this function:| char * kdotp::libmodelxx::postprocessing::get_header_for_template_state | ( | GList * | parameters | ) |
Definition at line 703 of file function_specification.c++.
References str.
Referenced by main().
{
GString *s = g_string_new("");
if(parameters == NULL) {
char *str = s->str;
g_string_free(s, FALSE);
return str;
}
s = g_string_append(s, ((struct template_parameter_range*)parameters->data)->symbol);
/*We started with the first so that we can prefix the string with an underscore.*/
if(parameters->next!=NULL) {
for(GList* ll = parameters->next; ll!=NULL; ll=ll->next) {
g_string_append_printf(s, "\t%s", ((struct template_parameter_range*)ll->data)->symbol);
}
}
char *str = s->str;
g_string_free(s, FALSE);
return str;
}
Here is the caller graph for this function:| char * kdotp::libmodelxx::postprocessing::get_string_for_template_state | ( | GList * | parameters | ) |
Definition at line 684 of file function_specification.c++.
References str.
Referenced by main().
{
GString *s = g_string_new("");
if(parameters == NULL) {
char *str = s->str;
g_string_free(s, FALSE);
return str;
}
g_string_append_printf(s, "%g", ((struct template_parameter_range*)parameters->data)->current_value);
/*We started with the first so that we can prefix the string with an underscore.*/
if(parameters->next!=NULL) {
for(GList* ll = parameters->next; ll!=NULL; ll=ll->next) {
g_string_append_printf(s, "\t%g", ((struct template_parameter_range*)ll->data)->current_value);
}
}
char *str = s->str;
g_string_free(s, FALSE);
return str;
}
Here is the caller graph for this function:| struct symbol_table_entry * kdotp::libmodelxx::postprocessing::get_symbol_table_entry | ( | const char * | symbol, |
| GHashTable * | global_symbols, | ||
| GHashTable * | local_symbols, | ||
| GError ** | e | ||
| ) | [read] |
Definition at line 563 of file function_specification.c++.
References FUNCTION_SPECIFICATION_GERROR_DOMAIN.
Referenced by evaluate_function(), and get_function_datatype().
{
struct symbol_table_entry *ste_global = NULL;
if(global_symbols != NULL) ste_global = (struct symbol_table_entry *)g_hash_table_lookup(global_symbols, symbol);
struct symbol_table_entry *ste_local = NULL;
if(local_symbols != NULL) ste_local = (struct symbol_table_entry *)g_hash_table_lookup(local_symbols, symbol);
if((ste_global != NULL) && (ste_local != NULL)) {
*e = g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 100, "::kdotp::libmodelxx::function_specification.c++::get_symbol_table_entry: symbol (%s) defined both locally and globally!", symbol);
return NULL;
}
if((ste_global == NULL) && (ste_local == NULL)) {
*e = g_error_new(FUNCTION_SPECIFICATION_GERROR_DOMAIN, 100, "::kdotp::libmodelxx::function_specification.c++::get_symbol_table_entry: symbol (%s) not defined.", symbol);
return NULL;
}
if(ste_global != NULL) return ste_global;
return ste_local;
}
Here is the caller graph for this function:| GHashTable * kdotp::libmodelxx::postprocessing::new_symbol_table | ( | ) |
Definition at line 606 of file function_specification.c++.
References destroy_symbol_table_entry(), and destroy_symbol_table_symbol().
Referenced by kdotp::libmodelxx::grid::cartesian_grid< libmodelxx::structure::material *, 1, 1 >::cartesian_grid_init(), and main().
{
return (GHashTable*)g_hash_table_new_full(g_str_hash, g_str_equal, destroy_symbol_table_symbol, destroy_symbol_table_entry);
}
Here is the call graph for this function:
Here is the caller graph for this function:| void kdotp::libmodelxx::postprocessing::parameter_list_init | ( | GList * | parameters | ) |
Definition at line 610 of file function_specification.c++.
Referenced by main().
{
/*Initialize the loop over the template parameters*/
for(GList* ll = parameters; ll!=NULL; ll=ll->next) ((struct template_parameter_range*)ll->data)->current_value = ((struct template_parameter_range*)ll->data)->from;
}
Here is the caller graph for this function:| bool kdotp::libmodelxx::postprocessing::update_parameters_plus_check_if_done | ( | GList * | parameters | ) |
Definition at line 615 of file function_specification.c++.
Referenced by main().
{
for(GList* ll=parameters; ll!=NULL; ll=ll->next) {
((struct template_parameter_range*)ll->data)->current_value += ((struct template_parameter_range*)ll->data)->stepsize;
if(((struct template_parameter_range*)ll->data)->current_value <= ((struct template_parameter_range*)ll->data)->to) return false;
/*If we reach this point, the current value is greater than the stop value. We need to reset this
* value and then loop around to the next value to increment.*/
((struct template_parameter_range*)ll->data)->current_value = ((struct template_parameter_range*)ll->data)->from;
}
return true;
}
Here is the caller graph for this function: