|
gimme-alpha 0.1
|
00001 /* 00002 * matdb: generic materials database information. 00003 00004 Copyright (C) 2008 Joseph Pingenot 00005 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU Affero General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU Affero General Public License for more details. 00015 00016 You should have received a copy of the GNU Affero General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 */ 00020 00021 #ifndef MATDB_H_ 00022 #define MATDB_H_ 00023 00024 #include <glib-2.0/glib.h> 00025 #include <libcommon/gcc_hints.h> 00026 00027 enum material_type { 00028 SIMPLE, 00029 ALLOY 00030 }; 00031 00032 /*Generic material; has a type and storage. 00033 *If type is SIMPLE, storage is a pointer to the properties hash. 00034 *If type is ALLOY, storage is alloy_storage 00035 */ 00036 struct material { 00037 enum material_type type; 00038 GString* name; 00039 void* storage; 00040 }; 00041 00042 /*This contains the percentage of mat1, mat1 and mat2, and a *copy* of the 00043 *properties for this percentage. 00044 */ 00045 struct alloy_storage { 00046 GString *mat1; 00047 GString *mat2; 00048 double x; 00049 GHashTable *ppts; 00050 }; 00051 00052 /* 00053 *materials is a hash of matdb_materials, indexed by material name. 00054 *bowings is indexed by material 1, which contains 00055 * hashes which are indexed by material2, which contains 00056 * hashes of matdb_bowing structures. 00057 */ 00058 struct matdb { 00059 GHashTable *materials; 00060 GHashTable *bowings; 00061 }; 00062 00063 struct matdb* matdb_new(); 00064 00065 void matdb_destroy(struct matdb* mdb); 00066 00067 void print_matdb(const struct matdb *mdb); 00068 00069 double get_param(const struct matdb *mdb, const char* mat1, const char* mat2, double x, const char* param, int *err); 00070 00071 double get_material_param(const struct matdb *mdb, const char* mat, const char* param, int *err); 00072 00073 double get_alloy_param(const struct matdb *mdb, const char* mat1, const char* mat2, double x, const char* param, int *err); 00074 00075 void set_material_param(struct matdb *mdb, const char* mat, const char* param, double value, int* err); 00076 00077 /*NOTE: To ensure db consistency, paramerty *MUST* be set in both mat1 00078 and mat2 *BEFORE* the bowing param can be set.*/ 00079 void set_bowing_param(struct matdb *mdb, const char* mat1, const char* mat2, const char* param, double value, int *err); 00080 00081 /*Canonicalizes the alloy, i.e. arranges mat1, mat2 in alphabetical 00082 *order. In order to ensure coherence between the resulting string 00083 *and mat1, mat2, and x, pointers to where mat1 and mat2 and x are 00084 *stored are given, so that mat1 and mat2 can be safely assumed to be 00085 *canonicalized and thereafter safely used. 00086 */ 00087 GString* canonicalize_alloy(char **mat1, char **mat2, double *x); 00088 void canonicalize_alloy_args(char **mat1, char **mat2, double *x); 00089 00090 double ___always_inline alloy_linear(double m1, double m2, double x) { 00091 return m1 + (m2-m1)*x; 00092 } 00093 00094 double ___always_inline alloy_bowed(double m1, double m2, double bow, double x) { 00095 return m1 + (m2-m1)*x + bow*x*(1-x); 00096 } 00097 00098 #endif